diff --git a/build.js b/build.js deleted file mode 100644 index f596a26b5..000000000 --- a/build.js +++ /dev/null @@ -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; diff --git a/build_css.js b/build_css.js index 02b8e4b5b..d2f1b679b 100644 --- a/build_css.js +++ b/build_css.js @@ -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; \ No newline at end of file diff --git a/build_data.js b/build_data.js index a67ac7b6a..ec8745474 100644 --- a/build_data.js +++ b/build_data.js @@ -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; diff --git a/build_src.js b/build_src.js deleted file mode 100644 index e5b3aa0f4..000000000 --- a/build_src.js +++ /dev/null @@ -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; diff --git a/package.json b/package.json index 61fa21695..63885bd42 100644 --- a/package.json +++ b/package.json @@ -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" diff --git a/server.js b/server.js index fc62fd981..4835102ea 100644 --- a/server.js +++ b/server.js @@ -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)); +});