mirror of
https://github.com/FoggedLens/iD.git
synced 2026-02-13 01:02:58 +00:00
promisify build steps
This commit is contained in:
24
build_css.js
24
build_css.js
@@ -9,14 +9,26 @@ module.exports = function buildCSS(isDevelopment) {
|
||||
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);
|
||||
return concatFilesProm('css/**/*.css', 'dist/iD.css')
|
||||
.then(function () {
|
||||
console.timeEnd(colors.green('css built'));
|
||||
building = false;
|
||||
building = false;
|
||||
})
|
||||
.catch(function (err) {
|
||||
console.error(err);
|
||||
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();
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -68,34 +68,33 @@ module.exports = function buildData(isDevelopment) {
|
||||
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));
|
||||
var tasks = [
|
||||
writeFileProm(
|
||||
'data/presets/categories.json',
|
||||
JSON.stringify({ categories: categories }, null, 4)
|
||||
),
|
||||
writeFileProm(
|
||||
'data/presets/fields.json',
|
||||
JSON.stringify({ fields: fields }, null, 4)
|
||||
),
|
||||
writeFileProm(
|
||||
'data/presets/presets.json',
|
||||
JSON.stringify({ presets: presets }, null, 4)
|
||||
),
|
||||
writeFileProm('data/presets.yaml', translationsToYAML(translations)),
|
||||
writeFileProm('data/taginfo.json', JSON.stringify(taginfo, null, 4)),
|
||||
writeEnJson(tstrings)
|
||||
];
|
||||
|
||||
// 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;
|
||||
return Promise.all(tasks)
|
||||
.then(function () {
|
||||
console.timeEnd(colors.green('data built'));
|
||||
building = false;
|
||||
})
|
||||
.catch(function (err) {
|
||||
console.error(err);
|
||||
process.exit(1);
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
@@ -364,3 +363,44 @@ function translationsToYAML(translations) {
|
||||
return YAML.safeDump({ en: { presets: translations }}, { sortKeys: commentFirst, lineWidth: -1 })
|
||||
.replace(/\'.*#\':/g, '#');
|
||||
}
|
||||
|
||||
function writeEnJson(tstrings) {
|
||||
var readCoreYaml = readFileProm('data/core.yaml', 'utf8');
|
||||
var readImagery = readFileProm(
|
||||
'node_modules/editor-layer-index/i18n/en.yaml',
|
||||
'utf8'
|
||||
);
|
||||
|
||||
return Promise.all([readCoreYaml, readImagery]).then(function(data) {
|
||||
var core = YAML.load(data[0]);
|
||||
var imagery = YAML.load(data[1]);
|
||||
var en = _.merge(core, { en: { presets: tstrings } }, imagery);
|
||||
return writeFileProm(
|
||||
'dist/locales/en.json',
|
||||
JSON.stringify(en, null, 4)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
function writeFileProm(path, content) {
|
||||
return new Promise(function(res, rej) {
|
||||
fs.writeFile(path, content, function(err) {
|
||||
if (err) {
|
||||
return rej(err);
|
||||
}
|
||||
res();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function readFileProm(path, options) {
|
||||
return new Promise(function(res, rej) {
|
||||
fs.readFile(path, options, function(err, data) {
|
||||
if (err) {
|
||||
return rej(err);
|
||||
}
|
||||
res(data);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
64
build_src.js
64
build_src.js
@@ -1,4 +1,3 @@
|
||||
|
||||
var fs = require('fs');
|
||||
var rollup = require('rollup');
|
||||
var nodeResolve = require('rollup-plugin-node-resolve');
|
||||
@@ -12,40 +11,49 @@ module.exports = function buildSrc(isDevelopment) {
|
||||
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'));
|
||||
|
||||
building = true;
|
||||
|
||||
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
|
||||
return rollup
|
||||
.rollup({
|
||||
entry: './modules/id.js',
|
||||
plugins: [
|
||||
nodeResolve({
|
||||
jsnext: true,
|
||||
main: true,
|
||||
browser: false
|
||||
}),
|
||||
commonjs(),
|
||||
json()
|
||||
],
|
||||
cache: cache
|
||||
})
|
||||
.then(function(bundle) {
|
||||
cache = bundle;
|
||||
return bundle.write({
|
||||
format: 'iife',
|
||||
dest: 'dist/iD.js',
|
||||
sourceMap: true,
|
||||
useStrict: false
|
||||
});
|
||||
})
|
||||
.then(function() {
|
||||
building = false;
|
||||
console.timeEnd(colors.green('src built'));
|
||||
})
|
||||
.catch(function(err) {
|
||||
building = false;
|
||||
cache = undefined;
|
||||
console.error(err);
|
||||
process.exit(1);
|
||||
});
|
||||
building = false;
|
||||
cache = bundle;
|
||||
console.timeEnd(colors.green('src built'));
|
||||
}, function(err) {
|
||||
building = false;
|
||||
cache = undefined;
|
||||
console.error(err);
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -11,8 +11,11 @@ var buildData = require('./build_data')(isDevelopment);
|
||||
var buildSrc = require('./build_src')(isDevelopment);
|
||||
var buildCSS = require('./build_css')(isDevelopment);
|
||||
|
||||
buildData();
|
||||
buildSrc();
|
||||
buildData()
|
||||
.then(function () {
|
||||
return buildSrc();
|
||||
});
|
||||
|
||||
buildCSS();
|
||||
|
||||
if (isDevelopment) {
|
||||
@@ -35,9 +38,11 @@ if (isDevelopment) {
|
||||
],
|
||||
function(err, watcher) {
|
||||
watcher.on('all', function() {
|
||||
buildData();
|
||||
// need to recompute js files when data changes
|
||||
buildSrc();
|
||||
buildData()
|
||||
.then(function () {
|
||||
// need to recompute js files when data changes
|
||||
buildSrc();
|
||||
});
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user