more changes to build scripts

- drop `build_src.js` and `build.js`
  - now we'll use rollup configs for all src building
- add `npm run build:css` and `npm run build:data`
- watcher now only watches for css file changes
  - src and data rebuilds are too slow to reasonably do "live"
- fix `build_css.js` and `build_data.js` to either exec or export
This commit is contained in:
Bryan Housel
2020-01-22 12:21:36 -05:00
parent 019a938255
commit 5f9a9864d8
6 changed files with 29 additions and 178 deletions

View File

@@ -1,28 +0,0 @@
/* eslint-disable no-console */
const buildData = require('./build_data');
const buildSrc = require('./build_src');
const buildCSS = require('./build_css');
let _currBuild = null;
// if called directly, do the thing.
buildAll();
function buildAll() {
if (_currBuild) return _currBuild;
return _currBuild =
Promise.resolve()
.then(() => buildCSS())
.then(() => buildData())
.then(() => buildSrc())
.then(() => _currBuild = null)
.catch((err) => {
console.error(err);
_currBuild = null;
process.exit(1);
});
}
module.exports = buildAll;

View File

@@ -5,6 +5,13 @@ const glob = require('glob');
let _currBuild = null;
// if called directly, do the thing.
if (process.argv[1].indexOf('build_css.js') > -1) {
buildCSS();
} else {
module.exports = buildCSS;
}
function buildCSS() {
if (_currBuild) return _currBuild;
@@ -52,5 +59,3 @@ function doConcat(files, output) {
});
}
module.exports = buildCSS;

View File

@@ -25,6 +25,14 @@ const request = require('request').defaults({ maxSockets: 1 });
let _currBuild = null;
// if called directly, do the thing.
if (process.argv[1].indexOf('build_data.js') > -1) {
buildData();
} else {
module.exports = buildCSS;
}
function buildData() {
if (_currBuild) return _currBuild;

View File

@@ -1,100 +0,0 @@
/* eslint-disable no-console */
const colors = require('colors/safe');
const commonjs = require('@rollup/plugin-commonjs');
const includePaths = require('rollup-plugin-includepaths');
const json = require('@rollup/plugin-json');
const nodeResolve = require('@rollup/plugin-node-resolve');
const rollup = require('rollup');
const shell = require('shelljs');
// const visualizer = require('rollup-plugin-visualizer');
let _currBuild = null;
function buildSrc() {
if (_currBuild) return _currBuild;
const START = '🏗 ' + colors.yellow('Building source...');
const END = '👍 ' + colors.green('source built');
console.log('');
console.log(START);
console.time(END);
return _currBuild =
Promise.resolve()
.then(() => buildBundle())
.then(() => {
console.timeEnd(END);
console.log('');
_currBuild = null;
})
.catch((err) => {
console.error(err);
console.log('');
_currBuild = null;
process.exit(1);
});
}
function buildBundle() {
console.log('📦 ' + colors.yellow('Bundling JavaScript...'));
// Start clean
shell.rm('-f', [
'dist/iD.js',
'dist/iD.js.map',
// 'docs/statistics.html'
]);
let prom =
rollup.rollup({
input: './modules/id.js',
onwarn: onWarn,
plugins: [
includePaths({
paths: ['node_modules/d3/node_modules'], // npm2 or windows
include: {
'martinez-polygon-clipping': 'node_modules/martinez-polygon-clipping/dist/martinez.umd.js'
}
}),
nodeResolve({
mainFields: ['module', 'main'],
browser: false,
dedupe: ['object-inspect']
}),
commonjs(),
json({ indent: '' })
// viz causes src build to take about 3x longer; skip
// visualizer({
// filename: 'docs/statistics.html',
// sourcemap: true
// })
]
})
.then((bundle) => {
return bundle.write({
format: 'iife',
file: 'dist/iD.js',
sourcemap: true,
strict: false
});
});
return prom;
}
function onWarn(warning, warn) {
// skip certain warnings
if (warning.code === 'CIRCULAR_DEPENDENCY') return;
if (warning.code === 'EVAL') return;
// Use default for everything else
console.log(colors.yellow(warning.code));
warn(warning);
}
module.exports = buildSrc;

View File

@@ -10,9 +10,9 @@
],
"license": "ISC",
"scripts": {
"all": "npm-run-all -s clean build build:legacy dist",
"build": "node --max-old-space-size=4096 build.js",
"build:all": "npm-run-all -s build:development",
"all": "npm-run-all -s clean build:css build:data build:dev build:legacy dist",
"build:css": "node build_css.js",
"build:data": "node build_data.js",
"build:dev": "rollup --config config/rollup.config.dev.js",
"build:legacy": "rollup --config config/rollup.config.legacy.js",
"build:stats": "rollup --config config/rollup.config.stats.js",
@@ -31,8 +31,9 @@
"dist:svg:temaki": "svg-sprite --symbol --symbol-dest . --shape-id-generator \"temaki-%s\" --symbol-sprite dist/img/temaki-sprite.svg node_modules/@ideditor/temaki/icons/*.svg",
"imagery": "node data/update_imagery",
"lint": "eslint *.js test/spec modules",
"start": "node --max-old-space-size=4096 server.js",
"test": "npm-run-all -s lint build:legacy test:**",
"start": "npm-run-all -s build:css build:data build:dev start:server",
"start:server": "node server.js",
"test": "npm-run-all -s lint build:css build:data build:legacy test:**",
"test:phantom": "phantomjs --web-security=no node_modules/mocha-phantomjs-core/mocha-phantomjs-core.js test/phantom.html spec",
"test:iD": "phantomjs --web-security=no node_modules/mocha-phantomjs-core/mocha-phantomjs-core.js test/index.html spec",
"translations": "node data/update_locales"

View File

@@ -3,49 +3,14 @@ const colors = require('colors/safe');
const gaze = require('gaze');
const StaticServer = require('static-server');
const buildAll = require('./build');
const buildData = require('./build_data');
const buildSrc = require('./build_src');
const buildCSS = require('./build_css');
const CSSFILES = ['css/**/*.css'];
const SRCFILES = ['modules/**/*.js'];
const DATAFILES = [
'data/**/*.{js,json}',
'data/core.yaml',
// ignore the output files of `buildData`
'!data/presets/categories.json',
'!data/presets/fields.json',
'!data/presets/presets.json',
'!data/presets.yaml',
'!data/taginfo.json',
'!data/territory-languages.json',
'!dist/locales/en.json'
];
const buildCSS = require('./build_css.js');
buildAll()
.then(() => startServer());
gaze(['css/**/*.css'], (err, watcher) => {
watcher.on('all', () => buildCSS());
});
function startServer() {
gaze(CSSFILES, (err, watcher) => {
watcher.on('all', () => buildCSS());
});
gaze(DATAFILES, (err, watcher) => {
watcher.on('all', () => {
buildData()
.then(() => buildSrc());
});
});
gaze(SRCFILES, (err, watcher) => {
watcher.on('all', () => buildSrc());
});
const server = new StaticServer({ rootPath: __dirname, port: 8080, followSymlink: true });
server.start(() => {
console.log(colors.yellow('Listening on ' + server.port));
});
}
const server = new StaticServer({ rootPath: __dirname, port: 8080, followSymlink: true });
server.start(() => {
console.log(colors.yellow('Listening on ' + server.port));
});