Separate build steps

This commit is contained in:
Kushan Joshi
2017-09-22 19:12:48 +05:30
parent 2d583a9400
commit 9b008a32a1
7 changed files with 189 additions and 3693 deletions
-42
View File
@@ -1,42 +0,0 @@
# test directories
__tests__
test
tests
powered-test
# asset directories
docs
doc
website
images
assets
# examples
example
examples
# code coverage directories
coverage
.nyc_output
# build scripts
Makefile
Gulpfile.js
Gruntfile.js
# configs
.tern-project
.gitattributes
.editorconfig
.*ignore
.eslintrc
.jshintrc
.flowconfig
.documentup.json
.yarn-metadata.json
.*.yml
*.yml
# misc
*.gz
*.md
+22
View File
@@ -0,0 +1,22 @@
var glob = require('glob');
var concat = require('concat-files');
var colors = require('colors/safe');
module.exports = function buildCSS(isDevelopment) {
var building = false;
return function () {
if (building) return;
console.log('building css');
console.time(colors.green('css built'));
building = true;
glob('css/**/*.css', function (er, files) {
if (er) console.error(er);
concat(files, 'dist/iD.css', function (err) {
if (err) console.error(err);
console.timeEnd(colors.green('css built'));
building = false;
});
});
};
};
+88 -62
View File
@@ -7,72 +7,98 @@ const jsonschema = require('jsonschema');
const path = require('path');
const shell = require('shelljs');
const YAML = require('js-yaml');
var colors = require('colors/safe');
const fieldSchema = require('./data/presets/schema/field.json');
const presetSchema = require('./data/presets/schema/preset.json');
const suggestions = require('name-suggestion-index/name-suggestions.json');
module.exports = function buildData(isDevelopment) {
var building;
return function() {
// Note: even though this function is sync adding
// the `building` variable for consistency and future proofing
if (building) return;
building = true;
console.log('building data');
console.time(colors.green('data built'));
// Create symlinks if necessary.. { 'target': 'source' }
const symlinks = {
'land.html': 'dist/land.html',
'img': 'dist/img',
// Create symlinks if necessary.. { 'target': 'source' }
const symlinks = {
'land.html': 'dist/land.html',
img: 'dist/img'
};
for (var target of Object.keys(symlinks)) {
if (!shell.test('-L', target)) {
console.log(
`Creating symlink: ${target} -> ${symlinks[target]}`
);
shell.ln('-sf', symlinks[target], target);
}
}
// Translation strings
var tstrings = {
categories: {},
fields: {},
presets: {}
};
// Start clean
shell.rm('-f', [
'data/presets/categories.json',
'data/presets/fields.json',
'data/presets/presets.json',
'data/presets.yaml',
'data/taginfo.json',
'dist/locales/en.json'
]);
var categories = generateCategories(tstrings);
var fields = generateFields(tstrings);
var presets = generatePresets(tstrings);
var defaults = read('data/presets/defaults.json');
var translations = generateTranslations(fields, presets, tstrings);
var taginfo = generateTaginfo(presets);
// Additional consistency checks
validateCategoryPresets(categories, presets);
validatePresetFields(presets, fields);
validateDefaults(defaults, categories, presets);
// Save individual data files
fs.writeFileSync(
'data/presets/categories.json',
JSON.stringify({ categories: categories }, null, 4)
);
fs.writeFileSync(
'data/presets/fields.json',
JSON.stringify({ fields: fields }, null, 4)
);
fs.writeFileSync(
'data/presets/presets.json',
JSON.stringify({ presets: presets }, null, 4)
);
fs.writeFileSync('data/presets.yaml', translationsToYAML(translations));
fs.writeFileSync('data/taginfo.json', JSON.stringify(taginfo, null, 4));
// Push changes from data/core.yaml into en.json
var core = YAML.load(fs.readFileSync('data/core.yaml', 'utf8'));
var imagery = YAML.load(
fs.readFileSync(
'node_modules/editor-layer-index/i18n/en.yaml',
'utf8'
)
);
var en = _.merge(core, { en: { presets: tstrings } }, imagery);
fs.writeFileSync('dist/locales/en.json', JSON.stringify(en, null, 4));
console.timeEnd(colors.green('data built'));
building = false;
};
};
for (var target of Object.keys(symlinks)) {
if (!shell.test('-L', target)) {
console.log(`Creating symlink: ${target} -> ${symlinks[target]}`);
shell.ln('-sf', symlinks[target], target);
}
}
// Translation strings
var tstrings = {
categories: {},
fields: {},
presets: {}
};
// Start clean
shell.rm('-f', [
'data/presets/categories.json',
'data/presets/fields.json',
'data/presets/presets.json',
'data/presets.yaml',
'data/taginfo.json',
'dist/locales/en.json'
]);
var categories = generateCategories();
var fields = generateFields();
var presets = generatePresets();
var defaults = read('data/presets/defaults.json');
var translations = generateTranslations(fields, presets);
var taginfo = generateTaginfo(presets);
// Additional consistency checks
validateCategoryPresets(categories, presets);
validatePresetFields(presets, fields);
validateDefaults(defaults, categories, presets);
// Save individual data files
fs.writeFileSync('data/presets/categories.json', JSON.stringify({ categories: categories }, null, 4));
fs.writeFileSync('data/presets/fields.json', JSON.stringify({ fields: fields }, null, 4));
fs.writeFileSync('data/presets/presets.json', JSON.stringify({ presets: presets }, null, 4));
fs.writeFileSync('data/presets.yaml', translationsToYAML(translations));
fs.writeFileSync('data/taginfo.json', JSON.stringify(taginfo, null, 4));
// Push changes from data/core.yaml into en.json
var core = YAML.load(fs.readFileSync('data/core.yaml', 'utf8'));
var imagery = YAML.load(fs.readFileSync('node_modules/editor-layer-index/i18n/en.yaml', 'utf8'));
var en = _.merge(core, { en: { presets: tstrings }}, imagery);
fs.writeFileSync('dist/locales/en.json', JSON.stringify(en, null, 4));
// process.exit();
function read(f) {
return JSON.parse(fs.readFileSync(f, 'utf8'));
}
@@ -92,7 +118,7 @@ function validate(file, instance, schema) {
}
}
function generateCategories() {
function generateCategories(tstrings) {
var categories = {};
glob.sync(__dirname + '/data/presets/categories/*.json').forEach(function(file) {
var field = read(file),
@@ -105,7 +131,7 @@ function generateCategories() {
return categories;
}
function generateFields() {
function generateFields(tstrings) {
var fields = {};
glob.sync(__dirname + '/data/presets/fields/**/*.json').forEach(function(file) {
var field = read(file),
@@ -185,7 +211,7 @@ function stripLeadingUnderscores(str) {
return str.split('/').map(function(s) { return s.replace(/^_/,''); }).join('/');
}
function generatePresets() {
function generatePresets(tstrings) {
var presets = {};
glob.sync(__dirname + '/data/presets/presets/**/*.json').forEach(function(file) {
@@ -206,7 +232,7 @@ function generatePresets() {
}
function generateTranslations(fields, presets) {
function generateTranslations(fields, presets, tstrings) {
var translations = _.cloneDeep(tstrings);
_.forEach(translations.fields, function(field, id) {
+55
View File
@@ -0,0 +1,55 @@
var fs = require('fs');
var rollup = require('rollup');
var nodeResolve = require('rollup-plugin-node-resolve');
var commonjs = require('rollup-plugin-commonjs');
var json = require('rollup-plugin-json');
var colors = require('colors/safe');
module.exports = function buildSrc(isDevelopment) {
var cache;
var building = false;
return function() {
if (building) return;
// Start clean
unlink('dist/iD.js');
unlink('dist/iD.js.map');
building = true;
console.log('building src');
console.time(colors.green('src built'));
rollup.rollup({
entry: './modules/id.js',
plugins: [
nodeResolve({
jsnext: true, main: true, browser: false
}),
commonjs(),
json()
],
cache: cache
}).then(function (bundle) {
bundle.write({
format: 'iife',
dest: 'dist/iD.js',
sourceMap: true,
useStrict: false
});
building = false;
cache = bundle;
console.timeEnd(colors.green('src built'));
}, function(err) {
building = false;
cache = undefined;
console.error(err);
});
};
};
function unlink(f) {
try { fs.unlinkSync(f); } catch (e) { /* noop */ }
}
+20 -84
View File
@@ -1,51 +1,36 @@
/* eslint-disable no-console */
var fs = require('fs');
var rollup = require('rollup');
var nodeResolve = require('rollup-plugin-node-resolve');
var commonjs = require('rollup-plugin-commonjs');
var json = require('rollup-plugin-json');
var http = require('http');
var gaze = require('gaze');
var ecstatic = require('ecstatic');
var glob = require('glob');
var concat = require('concat-files');
function makeCSS() {
glob('css/**/*.css', function (er, files) {
if (er) console.error(er);
concat(files, 'dist/iD.css', function (err) {
if (err) console.error(err);
console.log('css built');
});
});
}
var building = false;
var cache;
var colors = require('colors/safe');
var isDevelopment = process.argv[2] === 'develop';
if (isDevelopment) {
build();
makeCSS();
var buildData = require('./build_data')(isDevelopment);
var buildSrc = require('./build_src')(isDevelopment);
var buildCSS = require('./build_css')(isDevelopment);
buildData();
buildSrc();
buildCSS();
if (isDevelopment) {
gaze(['css/**/*.css'], function(err, watcher) {
watcher.on('all', function() {
makeCSS();
buildCSS();
});
});
// gaze(['data/**/*.{js,json}'], function(err, watcher) {
// watcher.on('all', function() {
// build();
// });
// });
gaze(['modules/**/*.js', 'data/**/*.{js,json}'], function(err, watcher) {
gaze(['data/**/*.{js,json}'], function(err, watcher) {
watcher.on('all', function() {
build();
buildData();
});
});
gaze(['modules/**/*.js'], function(err, watcher) {
watcher.on('all', function() {
buildSrc();
});
});
@@ -53,54 +38,5 @@ if (isDevelopment) {
ecstatic({ root: __dirname, cache: 0 })
).listen(8080);
console.log('Listening on :8080');
} else {
build();
makeCSS();
}
function unlink(f) {
try { fs.unlinkSync(f); } catch (e) { /* noop */ }
}
function build() {
if (building) return;
// Start clean
unlink('dist/iD.js');
unlink('dist/iD.js.map');
building = true;
console.log('Rebuilding');
console.time('Rebuilt');
rollup.rollup({
entry: './modules/id.js',
plugins: [
nodeResolve({
jsnext: true, main: true, browser: false
}),
commonjs(),
json()
],
cache: cache
}).then(function (bundle) {
bundle.write({
format: 'iife',
dest: 'dist/iD.js',
sourceMap: true,
useStrict: false
});
building = false;
cache = bundle;
console.timeEnd('Rebuilt');
}, function(err) {
building = false;
cache = undefined;
console.error(err);
});
}
console.log(colors.red('Listening on :8080'));
}
+4 -3
View File
@@ -11,7 +11,7 @@
"license": "ISC",
"scripts": {
"all": "npm-run-all -s clean build dist",
"build": "node build.js && node development_server.js",
"build": "node development_server.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/",
@@ -26,13 +26,14 @@
"translations": "node data/update_locales"
},
"dependencies": {
"@mapbox/sexagesimal": "1.1.0",
"@mapbox/togeojson": "0.16.0",
"colors": "^1.1.2",
"diacritics": "1.3.0",
"lodash": "4.17.4",
"marked": "0.3.6",
"osm-auth": "1.0.2",
"rbush": "2.0.1",
"@mapbox/sexagesimal": "1.1.0",
"@mapbox/togeojson": "0.16.0",
"wmf-sitematrix": "0.1.4"
},
"devDependencies": {
-3502
View File
File diff suppressed because it is too large Load Diff