Chore(scripts): Remove jake dependency and use NPM scripts instead (#5828)

* run `docs` via npm

* add shebang line to integrity.js, so npm will resolve node binary automatically

* remove unnecessary build-jake npm script

* add test.js script as replacement of Jakefile.js

* remove Jakefile, remove jake from devDependencies

* update docs

* move scripts to separate directory

* change shebang line from nodejs to js

* change shebang line from js to node

* update docs

* use Karma cli instead of custom test script

* add pretest and test-nolint scripts, remove lint scripts from travis.ci

Run linting scripts in pretest script, this way test script will automatically trigger code linting.

Add test-nolint script to have possibility to run tests without triggering pretest script with linting. This is useful when running tests in different browsers and tere's no sense to lint code more than one time

* replace shebang lines with node executable in npm scripts

* remove note about nodejs symlink in CONTRIBUTING.md
This commit is contained in:
Andrew
2018-02-05 08:15:32 +01:00
committed by ghybs
parent be8899c0e4
commit e3b049cefd
9 changed files with 37 additions and 131 deletions

View File

@ -20,6 +20,8 @@ env:
XW1hzORAtSpTgTKkQwel5gRMDy6SotzeSRsVV2jQCn46VIMx8G/J5nOI+ImL
yeoH12PhCR0h39dM7mq8TYJo5DHwvbotI5nQhpMruSt8eMFbym8nGiqQh806
fSJXkxmQ4MAjUdNFDIirBHhdZme8q3PueFzJ+5odFMvPGn/aITQ=
script:
- npm test
after_success:
- npm run build
- cd dist && zip -x .DS_Store -r leaflet.zip . && cd ..

View File

@ -68,8 +68,9 @@ please consider submitting another pull request with the corresponding [document
### Setting up the Build System
The Leaflet build system uses [Node](http://nodejs.org/), and the [Jake](http://jakejs.com/) Javascript build tool.
To set up the Leaflet build system, install Node then run the following commands in the project root to install dependencies:
The Leaflet build system uses [NodeJS](http://nodejs.org/).
To set up the Leaflet build system, install [NodeJS](https://nodejs.org/).
Then run the following commands in the project root to install dependencies:
```
npm install
@ -125,13 +126,13 @@ install [PhantomJS](http://phantomjs.org/) (and make sure it's in your `PATH`),
then run:
```
npm run test
npm test
```
To run all the tests in actual browsers at the same time, you can do:
```
npm run test -- --ff --chrome --safari --ie
npm test -- --browsers Firefox,Chrome,Safari,IE
```
To run the tests in a browser manually, open `spec/index.html`.
@ -141,7 +142,7 @@ To run the tests in a browser manually, open `spec/index.html`.
To generate a detailed report about test coverage (which helps tremendously when working on test improvements), run:
```
npm run test -- --cov
npm test -- --cov
```
After that, open `coverage/<environment>/index.html` in a browser to see the report.

View File

@ -1,107 +0,0 @@
/*
Leaflet building, testing and linting scripts.
To use, install Node, then run the following commands in the project root:
npm install -g jake
npm install
To check the code for errors and build Leaflet from source, run "jake".
To run the tests, run "jake test". To build the documentation, run "jake docs".
For a custom build, open build/build.html in the browser and follow the instructions.
*/
var buildDocs = require('./build/docs'),
git = require('git-rev-sync'),
path = require('path');
function hint(msg, args) {
return function () {
console.log(msg);
jake.exec('node node_modules/eslint/bin/eslint.js ' + args,
{printStdout: true}, function () {
console.log('\tCheck passed.\n');
complete();
});
};
}
// Returns the version string in package.json, plus a semver build metadata if
// this is not an official release
function calculateVersion(officialRelease) {
var version = require('./package.json').version;
if (officialRelease) {
return version;
} else {
return version + '+' + git.short();
}
}
desc('Check Leaflet source for errors with ESLint');
task('lint', {async: true}, hint('Checking for JS errors...', 'src'));
desc('Check Leaflet specs source for errors with ESLint');
task('lintspec', {async: true}, hint('Checking for specs JS errors...', 'spec/suites'));
desc('Run PhantomJS tests');
task('test', ['lint', 'lintspec'], {async: true}, function () {
var karma = require('karma'),
testConfig = {configFile : path.join(__dirname, './spec/karma.conf.js')};
testConfig.browsers = ['PhantomJSCustom'];
function isArgv(optName) {
return process.argv.indexOf(optName) !== -1;
}
if (isArgv('--chrome')) {
testConfig.browsers.push('Chrome');
}
if (isArgv('--safari')) {
testConfig.browsers.push('Safari');
}
if (isArgv('--ff')) {
testConfig.browsers.push('Firefox');
}
if (isArgv('--ie')) {
testConfig.browsers.push('IE');
}
if (isArgv('--cov')) {
testConfig.preprocessors = {
'src/**/*.js': 'coverage'
};
testConfig.coverageReporter = {
type : 'html',
dir : 'coverage/'
};
testConfig.reporters = ['coverage'];
}
console.log('Running tests...');
var server = new karma.Server(testConfig, function(exitCode) {
if (!exitCode) {
console.log('\tTests ran successfully.\n');
complete();
} else {
process.exit(exitCode);
}
});
server.start();
});
desc('Build documentation');
task('docs', {}, function() {
buildDocs();
});
task('default', ['test', 'build']);
jake.addListener('complete', function () {
process.exit();
});

7
build/docs.js Normal file → Executable file
View File

@ -1,4 +1,3 @@
var packageDef = require('../package.json');
function buildDocs() {
@ -34,4 +33,8 @@ function buildDocs() {
fs.writeFileSync('dist/reference-' + packageDef.version + '.html', out);
}
module.exports = buildDocs;
if (require.main === module) {
buildDocs();
} else {
module.exports = buildDocs;
}

View File

@ -1,4 +1,3 @@
// This script calculates the integrity hashes of the files in dist/ , and
// **overwrites** the values in the documentation.

View File

@ -1,4 +1,4 @@
exclude: [build, debug, node_modules, spec, src, CNAME, Jakefile.js, reference-tpl.html, CHANGELOG.md, README.md, LICENSE, DOCS-TODO.md]
exclude: [build, debug, node_modules, spec, src, CNAME, reference-tpl.html, CHANGELOG.md, README.md, LICENSE, DOCS-TODO.md]
markdown: kramdown

View File

@ -89,10 +89,10 @@ which installs easily and works well across all major platforms.
Here are the steps to set it up:
1. [Download and install Node](http://nodejs.org)
2. Run the following commands in the command line:
2. Run the following command in the command line:
<pre><code>npm install</code></pre>
Now that you have everything installed, from inside the Leaflet directory, run:
<pre><code>npm run build</code></pre>
Now that you have everything installed, run `npm run build` inside the Leaflet directory.
This will combine and compress the Leaflet source files, saving the build to the `dist` folder.

View File

@ -7,7 +7,6 @@
"eslint-config-mourner": "^2.0.1",
"git-rev-sync": "^1.8.0",
"happen": "~0.3.2",
"jake": "~8.0.12",
"karma": "^1.3.0",
"karma-chrome-launcher": "^2.0.0",
"karma-coverage": "~1.1.1",
@ -40,18 +39,19 @@
"!dist/leaflet.zip"
],
"scripts": {
"docs": "jake docs",
"test-jake": "jake test",
"test": "jake test",
"build-jake": "jake build",
"docs": "node ./build/docs.js",
"pretest": "npm run lint && npm run lint-spec",
"test": "npm run test-nolint",
"test-nolint": "karma start ./spec/karma.conf.js",
"build": "npm run rollup && npm run uglify",
"release": "./build/publish.sh",
"lint": "eslint src; eslint spec/suites",
"lintfix": "eslint src --fix; eslint spec/suites --fix; ",
"lint": "eslint src",
"lint-spec": "eslint spec/suites",
"lintfix": "eslint src --fix; eslint spec/suites --fix;",
"rollup": "rollup -c build/rollup-config.js",
"watch": "rollup -w -c build/rollup-watch-config.js",
"uglify": "uglifyjs dist/leaflet-src.js -c -m -o dist/leaflet.js --source-map filename=dist/leaflet.js.map --in-source-map dist/leaflet-src.js.map --source-map-url leaflet.js.map --comments",
"integrity": "nodejs ./build/integrity.js"
"integrity": "node ./build/integrity.js"
},
"eslintConfig": {
"root": true,

View File

@ -25,6 +25,14 @@ module.exports = function (config) {
{pattern: "dist/images/*.png", included: false, serve: true}
];
var preprocessors = {};
if (config.cov) {
preprocessors['src/**/*.js'] = ['coverage'];
}
preprocessors['src/Leaflet.js'] = ['rollup'];
config.set({
// base path, that will be used to resolve files and exclude
basePath: '../',
@ -51,9 +59,7 @@ module.exports = function (config) {
exclude: [],
// Rollup the ES6 Leaflet sources into just one file, before tests
preprocessors: {
'src/Leaflet.js': ['rollup']
},
preprocessors: preprocessors,
rollupPreprocessor: {
plugins: [
json()
@ -65,7 +71,9 @@ module.exports = function (config) {
// test results reporter to use
// possible values: 'dots', 'progress', 'junit', 'growl', 'coverage'
reporters: ['dots'],
reporters: config.cov ? ['dots', 'coverage'] : ['dots'],
coverageReporter: config.cov ? {type : 'html', dir : 'coverage/'} : null,
// web server port
port: 9876,