Modernize build scripts, working towards multiple rollup targets

This commit is contained in:
Bryan Housel
2019-11-05 15:40:17 -05:00
parent 71bfeb5a9f
commit 263c3ad081
7 changed files with 867 additions and 840 deletions
+32
View File
@@ -0,0 +1,32 @@
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.all([buildCSS(), buildBundle()])
.then(() => {
_currBuild = null;
})
.catch((err) => {
console.error(err);
_currBuild = null;
process.exit(1);
});
};
function buildBundle() {
return buildData();
// .then(() => buildSrc());
}
module.exports = buildAll;
+41 -27
View File
@@ -3,36 +3,50 @@ const colors = require('colors/safe');
const concat = require('concat-files');
const glob = require('glob');
let _currBuild = null;
module.exports = function buildCSS() {
var isBuilding = false;
return function () {
if (isBuilding) return;
// if called directly, do the thing.
buildCSS();
console.log('building css');
console.time(colors.green('css built'));
isBuilding = true;
return concatFilesProm('css/**/*.css', 'dist/iD.css')
.then(function () {
console.timeEnd(colors.green('css built'));
isBuilding = false;
})
.catch(function (err) {
console.error(err);
process.exit(1);
});
};
function buildCSS() {
if (_currBuild) return _currBuild;
console.log('building css');
console.time(colors.green('css built'));
return _currBuild =
doGlob('css/**/*.css')
.then((files) => doConcat(files, 'dist/iD.css'))
.then(() => {
console.timeEnd(colors.green('css built'));
_currBuild = null;
})
.catch((err) => {
console.error(err);
_currBuild = null;
process.exit(1);
});
};
function concatFilesProm(globPath, output) {
return new Promise(function (res, rej) {
glob(globPath, function (er, files) {
if (er) return rej(er);
concat(files, output, function (err) {
if (err) return rej(err);
res();
});
});
function doGlob(pattern) {
return new Promise((resolve, reject) => {
glob(pattern, (err, files) => {
if (err) return reject(err);
resolve(files);
});
}
});
};
function doConcat(files, output) {
return new Promise((resolve, reject) => {
concat(files, output, (err) => {
if (err) return reject(err);
resolve();
});
});
};
module.exports = buildCSS;
+685 -696
View File
File diff suppressed because it is too large Load Diff
+55 -55
View File
@@ -8,65 +8,65 @@ const rollup = require('rollup');
const shell = require('shelljs');
//const visualizer = require('rollup-plugin-visualizer');
let _isBuilding = false;
module.exports = function buildSrc() {
var isBuilding = false;
return function () {
if (_isBuilding) return;
return function () {
if (isBuilding) return;
// Start clean
shell.rm('-f', [
//'docs/statistics.html',
'dist/iD.js',
'dist/iD.js.map'
]);
// Start clean
shell.rm('-f', [
//'docs/statistics.html',
'dist/iD.js',
'dist/iD.js.map'
]);
console.log('building src');
console.time(colors.green('src built'));
console.log('building src');
console.time(colors.green('src built'));
_isBuilding = true;
isBuilding = true;
return rollup
.rollup({
input: './modules/id.js',
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(function (bundle) {
return bundle.write({
format: 'iife',
file: 'dist/iD.js',
sourcemap: true,
strict: false
});
})
.then(function () {
isBuilding = false;
console.timeEnd(colors.green('src built'));
})
.catch(function (err) {
isBuilding = false;
console.error(err);
process.exit(1);
});
};
return rollup
.rollup({
input: './modules/id.js',
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
});
})
.then(() => {
_isBuilding = false;
console.timeEnd(colors.green('src built'));
})
.catch((err) => {
_isBuilding = false;
console.error(err);
process.exit(1);
});
};
};
-60
View File
@@ -1,60 +0,0 @@
/* eslint-disable no-console */
const colors = require('colors/safe');
const gaze = require('gaze');
const StaticServer = require('static-server');
const isDevelopment = process.argv[2] === 'develop';
const buildData = require('./build_data')(isDevelopment);
const buildSrc = require('./build_src')(isDevelopment);
const buildCSS = require('./build_css')(isDevelopment);
buildData()
.then(function () {
return buildSrc();
});
buildCSS();
if (isDevelopment) {
gaze(['css/**/*.css'], function(err, watcher) {
watcher.on('all', function() {
buildCSS();
});
});
gaze([
'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'
],
function(err, watcher) {
watcher.on('all', function() {
buildData()
.then(function () {
// need to recompute js files when data changes
buildSrc();
});
});
}
);
gaze(['modules/**/*.js'], function(err, watcher) {
watcher.on('all', function() {
buildSrc();
});
});
const server = new StaticServer({ rootPath: __dirname, port: 8080, followSymlink: true });
server.start(function () {
console.log(colors.yellow('Listening on ' + server.port));
});
}
+3 -2
View File
@@ -11,7 +11,7 @@
"license": "ISC",
"scripts": {
"all": "npm-run-all -s clean build dist",
"build": "node development_server.js",
"build": "node build.js",
"clean": "shx rm -f dist/*.js dist/*.map dist/*.css dist/img/*.svg",
"dist": "npm-run-all -p dist:**",
"dist:mapillary": "shx mkdir -p dist/mapillary-js && shx cp -R node_modules/mapillary-js/dist/* dist/mapillary-js/",
@@ -27,7 +27,7 @@
"dist:svg:temaki": "svg-sprite --symbol --symbol-dest . --shape-id-generator \"temaki-%s\" --symbol-sprite dist/img/temaki-sprite.svg node_modules/temaki/icons/*.svg",
"imagery": "node data/update_imagery",
"lint": "eslint *.js test/spec modules",
"start": "node development_server.js develop",
"start": "node server.js",
"phantom": "phantomjs --web-security=no node_modules/mocha-phantomjs-core/mocha-phantomjs-core.js test/phantom.html spec",
"test": "npm-run-all -s lint build test:**",
"test:phantom": "phantomjs --web-security=no node_modules/mocha-phantomjs-core/mocha-phantomjs-core.js test/index.html spec",
@@ -62,6 +62,7 @@
"@fortawesome/free-regular-svg-icons": "^5.11.2",
"@fortawesome/free-solid-svg-icons": "^5.11.2",
"@mapbox/maki": "^6.0.0",
"@rollup/plugin-buble": "^0.20.0",
"chai": "^4.1.0",
"cldr-core": "36.0.0",
"cldr-localenames-full": "36.0.0",
+51
View File
@@ -0,0 +1,51 @@
/* eslint-disable no-console */
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'
];
buildAll()
.then(() => startServer());
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));
});
};