Standardize on camelCase in utils
This commit is contained in:
parent
80187d158c
commit
8b0034ee84
|
|
@ -9,14 +9,14 @@
|
||||||
|
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
|
||||||
let show_help = process.argv.length === 2;
|
let showHelp = process.argv.length === 2;
|
||||||
let filename;
|
let filename;
|
||||||
|
|
||||||
for (let i = 2; i < process.argv.length; ++i) {
|
for (let i = 2; i < process.argv.length; ++i) {
|
||||||
switch (process.argv[i]) {
|
switch (process.argv[i]) {
|
||||||
case "--help":
|
case "--help":
|
||||||
case "-h":
|
case "-h":
|
||||||
show_help = true;
|
showHelp = true;
|
||||||
break;
|
break;
|
||||||
case "--file":
|
case "--file":
|
||||||
case "-f":
|
case "-f":
|
||||||
|
|
@ -26,11 +26,11 @@ for (let i = 2; i < process.argv.length; ++i) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!filename) {
|
if (!filename) {
|
||||||
show_help = true;
|
showHelp = true;
|
||||||
console.log("Error: No filename specified\n");
|
console.log("Error: No filename specified\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (show_help) {
|
if (showHelp) {
|
||||||
console.log("Parses a *nix keysymdef.h to generate Unicode code point mappings");
|
console.log("Parses a *nix keysymdef.h to generate Unicode code point mappings");
|
||||||
console.log("Usage: node parse.js [options] filename:");
|
console.log("Usage: node parse.js [options] filename:");
|
||||||
console.log(" -h [ --help ] Produce this help message");
|
console.log(" -h [ --help ] Produce this help message");
|
||||||
|
|
|
||||||
|
|
@ -22,31 +22,31 @@ const paths = {
|
||||||
core: path.resolve(__dirname, '..', 'core'),
|
core: path.resolve(__dirname, '..', 'core'),
|
||||||
app: path.resolve(__dirname, '..', 'app'),
|
app: path.resolve(__dirname, '..', 'app'),
|
||||||
vendor: path.resolve(__dirname, '..', 'vendor'),
|
vendor: path.resolve(__dirname, '..', 'vendor'),
|
||||||
out_dir_base: path.resolve(__dirname, '..', 'build'),
|
outDirBase: path.resolve(__dirname, '..', 'build'),
|
||||||
lib_dir_base: path.resolve(__dirname, '..', 'lib'),
|
libDirBase: path.resolve(__dirname, '..', 'lib'),
|
||||||
};
|
};
|
||||||
|
|
||||||
const no_copy_files = new Set([
|
const noCopyFiles = new Set([
|
||||||
// skip these -- they don't belong in the processed application
|
// skip these -- they don't belong in the processed application
|
||||||
path.join(paths.vendor, 'sinon.js'),
|
path.join(paths.vendor, 'sinon.js'),
|
||||||
path.join(paths.vendor, 'browser-es-module-loader'),
|
path.join(paths.vendor, 'browser-es-module-loader'),
|
||||||
path.join(paths.app, 'images', 'icons', 'Makefile'),
|
path.join(paths.app, 'images', 'icons', 'Makefile'),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const only_legacy_scripts = new Set([
|
const onlyLegacyScripts = new Set([
|
||||||
path.join(paths.vendor, 'promise.js'),
|
path.join(paths.vendor, 'promise.js'),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const no_transform_files = new Set([
|
const noTransformFiles = new Set([
|
||||||
// don't transform this -- we want it imported as-is to properly catch loading errors
|
// don't transform this -- we want it imported as-is to properly catch loading errors
|
||||||
path.join(paths.app, 'error-handler.js'),
|
path.join(paths.app, 'error-handler.js'),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
no_copy_files.forEach(file => no_transform_files.add(file));
|
noCopyFiles.forEach(file => noTransformFiles.add(file));
|
||||||
|
|
||||||
// util.promisify requires Node.js 8.x, so we have our own
|
// util.promisify requires Node.js 8.x, so we have our own
|
||||||
function promisify(original) {
|
function promisify(original) {
|
||||||
return function promise_wrap() {
|
return function promiseWrap() {
|
||||||
const args = Array.prototype.slice.call(arguments);
|
const args = Array.prototype.slice.call(arguments);
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
original.apply(this, args.concat((err, value) => {
|
original.apply(this, args.concat((err, value) => {
|
||||||
|
|
@ -72,10 +72,10 @@ const babelTransformFile = promisify(babel.transformFile);
|
||||||
|
|
||||||
// walkDir *recursively* walks directories trees,
|
// walkDir *recursively* walks directories trees,
|
||||||
// calling the callback for all normal files found.
|
// calling the callback for all normal files found.
|
||||||
function walkDir(base_path, cb, filter) {
|
function walkDir(basePath, cb, filter) {
|
||||||
return readdir(base_path)
|
return readdir(basePath)
|
||||||
.then((files) => {
|
.then((files) => {
|
||||||
const paths = files.map(filename => path.join(base_path, filename));
|
const paths = files.map(filename => path.join(basePath, filename));
|
||||||
return Promise.all(paths.map(filepath => lstat(filepath)
|
return Promise.all(paths.map(filepath => lstat(filepath)
|
||||||
.then((stats) => {
|
.then((stats) => {
|
||||||
if (filter !== undefined && !filter(filepath, stats)) return;
|
if (filter !== undefined && !filter(filepath, stats)) return;
|
||||||
|
|
@ -87,157 +87,157 @@ function walkDir(base_path, cb, filter) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function transform_html(legacy_scripts, only_legacy) {
|
function transformHtml(legacyScripts, onlyLegacy) {
|
||||||
// write out the modified vnc.html file that works with the bundle
|
// write out the modified vnc.html file that works with the bundle
|
||||||
const src_html_path = path.resolve(__dirname, '..', 'vnc.html');
|
const srcHtmlPath = path.resolve(__dirname, '..', 'vnc.html');
|
||||||
const out_html_path = path.resolve(paths.out_dir_base, 'vnc.html');
|
const outHtmlPath = path.resolve(paths.outDirBase, 'vnc.html');
|
||||||
return readFile(src_html_path)
|
return readFile(srcHtmlPath)
|
||||||
.then((contents_raw) => {
|
.then((contentsRaw) => {
|
||||||
let contents = contents_raw.toString();
|
let contents = contentsRaw.toString();
|
||||||
|
|
||||||
const start_marker = '<!-- begin scripts -->\n';
|
const startMarker = '<!-- begin scripts -->\n';
|
||||||
const end_marker = '<!-- end scripts -->';
|
const endMarker = '<!-- end scripts -->';
|
||||||
const start_ind = contents.indexOf(start_marker) + start_marker.length;
|
const startInd = contents.indexOf(startMarker) + startMarker.length;
|
||||||
const end_ind = contents.indexOf(end_marker, start_ind);
|
const endInd = contents.indexOf(endMarker, startInd);
|
||||||
|
|
||||||
let new_script = '';
|
let newScript = '';
|
||||||
|
|
||||||
if (only_legacy) {
|
if (onlyLegacy) {
|
||||||
// Only legacy version, so include things directly
|
// Only legacy version, so include things directly
|
||||||
for (let i = 0;i < legacy_scripts.length;i++) {
|
for (let i = 0;i < legacyScripts.length;i++) {
|
||||||
new_script += ` <script src="${legacy_scripts[i]}"></script>\n`;
|
newScript += ` <script src="${legacyScripts[i]}"></script>\n`;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Otherwise include both modules and legacy fallbacks
|
// Otherwise include both modules and legacy fallbacks
|
||||||
new_script += ' <script type="module" crossorigin="anonymous" src="app/ui.js"></script>\n';
|
newScript += ' <script type="module" crossorigin="anonymous" src="app/ui.js"></script>\n';
|
||||||
for (let i = 0;i < legacy_scripts.length;i++) {
|
for (let i = 0;i < legacyScripts.length;i++) {
|
||||||
new_script += ` <script nomodule src="${legacy_scripts[i]}"></script>\n`;
|
newScript += ` <script nomodule src="${legacyScripts[i]}"></script>\n`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
contents = contents.slice(0, start_ind) + `${new_script}\n` + contents.slice(end_ind);
|
contents = contents.slice(0, startInd) + `${newScript}\n` + contents.slice(endInd);
|
||||||
|
|
||||||
return contents;
|
return contents;
|
||||||
})
|
})
|
||||||
.then((contents) => {
|
.then((contents) => {
|
||||||
console.log(`Writing ${out_html_path}`);
|
console.log(`Writing ${outHtmlPath}`);
|
||||||
return writeFile(out_html_path, contents);
|
return writeFile(outHtmlPath, contents);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function make_lib_files(import_format, source_maps, with_app_dir, only_legacy) {
|
function makeLibFiles(importFormat, sourceMaps, withAppDir, onlyLegacy) {
|
||||||
if (!import_format) {
|
if (!importFormat) {
|
||||||
throw new Error("you must specify an import format to generate compiled noVNC libraries");
|
throw new Error("you must specify an import format to generate compiled noVNC libraries");
|
||||||
} else if (!SUPPORTED_FORMATS.has(import_format)) {
|
} else if (!SUPPORTED_FORMATS.has(importFormat)) {
|
||||||
throw new Error(`unsupported output format "${import_format}" for import/export -- only ${Array.from(SUPPORTED_FORMATS)} are supported`);
|
throw new Error(`unsupported output format "${importFormat}" for import/export -- only ${Array.from(SUPPORTED_FORMATS)} are supported`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// NB: we need to make a copy of babel_opts, since babel sets some defaults on it
|
// NB: we need to make a copy of babelOpts, since babel sets some defaults on it
|
||||||
const babel_opts = () => ({
|
const babelOpts = () => ({
|
||||||
plugins: [],
|
plugins: [],
|
||||||
presets: [
|
presets: [
|
||||||
[ '@babel/preset-env',
|
[ '@babel/preset-env',
|
||||||
{ targets: 'ie >= 11',
|
{ targets: 'ie >= 11',
|
||||||
modules: import_format } ]
|
modules: importFormat } ]
|
||||||
],
|
],
|
||||||
ast: false,
|
ast: false,
|
||||||
sourceMaps: source_maps,
|
sourceMaps: sourceMaps,
|
||||||
});
|
});
|
||||||
|
|
||||||
// No point in duplicate files without the app, so force only converted files
|
// No point in duplicate files without the app, so force only converted files
|
||||||
if (!with_app_dir) {
|
if (!withAppDir) {
|
||||||
only_legacy = true;
|
onlyLegacy = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
let in_path;
|
let inPath;
|
||||||
let out_path_base;
|
let outPathBase;
|
||||||
if (with_app_dir) {
|
if (withAppDir) {
|
||||||
out_path_base = paths.out_dir_base;
|
outPathBase = paths.outDirBase;
|
||||||
in_path = paths.main;
|
inPath = paths.main;
|
||||||
} else {
|
} else {
|
||||||
out_path_base = paths.lib_dir_base;
|
outPathBase = paths.libDirBase;
|
||||||
}
|
}
|
||||||
const legacy_path_base = only_legacy ? out_path_base : path.join(out_path_base, 'legacy');
|
const legacyPathBase = onlyLegacy ? outPathBase : path.join(outPathBase, 'legacy');
|
||||||
|
|
||||||
fse.ensureDirSync(out_path_base);
|
fse.ensureDirSync(outPathBase);
|
||||||
|
|
||||||
const helpers = require('./use_require_helpers');
|
const helpers = require('./use_require_helpers');
|
||||||
const helper = helpers[import_format];
|
const helper = helpers[importFormat];
|
||||||
|
|
||||||
const outFiles = [];
|
const outFiles = [];
|
||||||
const legacyFiles = [];
|
const legacyFiles = [];
|
||||||
|
|
||||||
const handleDir = (js_only, vendor_rewrite, in_path_base, filename) => Promise.resolve()
|
const handleDir = (jsOnly, vendorRewrite, inPathBase, filename) => Promise.resolve()
|
||||||
.then(() => {
|
.then(() => {
|
||||||
const out_path = path.join(out_path_base, path.relative(in_path_base, filename));
|
const outPath = path.join(outPathBase, path.relative(inPathBase, filename));
|
||||||
const legacy_path = path.join(legacy_path_base, path.relative(in_path_base, filename));
|
const legacyPath = path.join(legacyPathBase, path.relative(inPathBase, filename));
|
||||||
|
|
||||||
if (path.extname(filename) !== '.js') {
|
if (path.extname(filename) !== '.js') {
|
||||||
if (!js_only) {
|
if (!jsOnly) {
|
||||||
console.log(`Writing ${out_path}`);
|
console.log(`Writing ${outPath}`);
|
||||||
return copy(filename, out_path);
|
return copy(filename, outPath);
|
||||||
}
|
}
|
||||||
return; // skip non-javascript files
|
return; // skip non-javascript files
|
||||||
}
|
}
|
||||||
|
|
||||||
if (no_transform_files.has(filename)) {
|
if (noTransformFiles.has(filename)) {
|
||||||
return ensureDir(path.dirname(out_path))
|
return ensureDir(path.dirname(outPath))
|
||||||
.then(() => {
|
.then(() => {
|
||||||
console.log(`Writing ${out_path}`);
|
console.log(`Writing ${outPath}`);
|
||||||
return copy(filename, out_path);
|
return copy(filename, outPath);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (only_legacy_scripts.has(filename)) {
|
if (onlyLegacyScripts.has(filename)) {
|
||||||
legacyFiles.push(legacy_path);
|
legacyFiles.push(legacyPath);
|
||||||
return ensureDir(path.dirname(legacy_path))
|
return ensureDir(path.dirname(legacyPath))
|
||||||
.then(() => {
|
.then(() => {
|
||||||
console.log(`Writing ${legacy_path}`);
|
console.log(`Writing ${legacyPath}`);
|
||||||
return copy(filename, legacy_path);
|
return copy(filename, legacyPath);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return Promise.resolve()
|
return Promise.resolve()
|
||||||
.then(() => {
|
.then(() => {
|
||||||
if (only_legacy) {
|
if (onlyLegacy) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
return ensureDir(path.dirname(out_path))
|
return ensureDir(path.dirname(outPath))
|
||||||
.then(() => {
|
.then(() => {
|
||||||
console.log(`Writing ${out_path}`);
|
console.log(`Writing ${outPath}`);
|
||||||
return copy(filename, out_path);
|
return copy(filename, outPath);
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.then(() => ensureDir(path.dirname(legacy_path)))
|
.then(() => ensureDir(path.dirname(legacyPath)))
|
||||||
.then(() => {
|
.then(() => {
|
||||||
const opts = babel_opts();
|
const opts = babelOpts();
|
||||||
if (helper && helpers.optionsOverride) {
|
if (helper && helpers.optionsOverride) {
|
||||||
helper.optionsOverride(opts);
|
helper.optionsOverride(opts);
|
||||||
}
|
}
|
||||||
// Adjust for the fact that we move the core files relative
|
// Adjust for the fact that we move the core files relative
|
||||||
// to the vendor directory
|
// to the vendor directory
|
||||||
if (vendor_rewrite) {
|
if (vendorRewrite) {
|
||||||
opts.plugins.push(["import-redirect",
|
opts.plugins.push(["import-redirect",
|
||||||
{"root": legacy_path_base,
|
{"root": legacyPathBase,
|
||||||
"redirect": { "vendor/(.+)": "./vendor/$1"}}]);
|
"redirect": { "vendor/(.+)": "./vendor/$1"}}]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return babelTransformFile(filename, opts)
|
return babelTransformFile(filename, opts)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
console.log(`Writing ${legacy_path}`);
|
console.log(`Writing ${legacyPath}`);
|
||||||
const {map} = res;
|
const {map} = res;
|
||||||
let {code} = res;
|
let {code} = res;
|
||||||
if (source_maps === true) {
|
if (sourceMaps === true) {
|
||||||
// append URL for external source map
|
// append URL for external source map
|
||||||
code += `\n//# sourceMappingURL=${path.basename(legacy_path)}.map\n`;
|
code += `\n//# sourceMappingURL=${path.basename(legacyPath)}.map\n`;
|
||||||
}
|
}
|
||||||
outFiles.push(`${legacy_path}`);
|
outFiles.push(`${legacyPath}`);
|
||||||
return writeFile(legacy_path, code)
|
return writeFile(legacyPath, code)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
if (source_maps === true || source_maps === 'both') {
|
if (sourceMaps === true || sourceMaps === 'both') {
|
||||||
console.log(` and ${legacy_path}.map`);
|
console.log(` and ${legacyPath}.map`);
|
||||||
outFiles.push(`${legacy_path}.map`);
|
outFiles.push(`${legacyPath}.map`);
|
||||||
return writeFile(`${legacy_path}.map`, JSON.stringify(map));
|
return writeFile(`${legacyPath}.map`, JSON.stringify(map));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
@ -246,45 +246,45 @@ function make_lib_files(import_format, source_maps, with_app_dir, only_legacy) {
|
||||||
|
|
||||||
Promise.resolve()
|
Promise.resolve()
|
||||||
.then(() => {
|
.then(() => {
|
||||||
const handler = handleDir.bind(null, true, false, in_path || paths.main);
|
const handler = handleDir.bind(null, true, false, inPath || paths.main);
|
||||||
const filter = (filename, stats) => !no_copy_files.has(filename);
|
const filter = (filename, stats) => !noCopyFiles.has(filename);
|
||||||
return walkDir(paths.vendor, handler, filter);
|
return walkDir(paths.vendor, handler, filter);
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
const handler = handleDir.bind(null, true, !in_path, in_path || paths.core);
|
const handler = handleDir.bind(null, true, !inPath, inPath || paths.core);
|
||||||
const filter = (filename, stats) => !no_copy_files.has(filename);
|
const filter = (filename, stats) => !noCopyFiles.has(filename);
|
||||||
return walkDir(paths.core, handler, filter);
|
return walkDir(paths.core, handler, filter);
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
if (!with_app_dir) return;
|
if (!withAppDir) return;
|
||||||
const handler = handleDir.bind(null, false, false, in_path);
|
const handler = handleDir.bind(null, false, false, inPath);
|
||||||
const filter = (filename, stats) => !no_copy_files.has(filename);
|
const filter = (filename, stats) => !noCopyFiles.has(filename);
|
||||||
return walkDir(paths.app, handler, filter);
|
return walkDir(paths.app, handler, filter);
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
if (!with_app_dir) return;
|
if (!withAppDir) return;
|
||||||
|
|
||||||
if (!helper || !helper.appWriter) {
|
if (!helper || !helper.appWriter) {
|
||||||
throw new Error(`Unable to generate app for the ${import_format} format!`);
|
throw new Error(`Unable to generate app for the ${importFormat} format!`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const out_app_path = path.join(legacy_path_base, 'app.js');
|
const outAppPath = path.join(legacyPathBase, 'app.js');
|
||||||
console.log(`Writing ${out_app_path}`);
|
console.log(`Writing ${outAppPath}`);
|
||||||
return helper.appWriter(out_path_base, legacy_path_base, out_app_path)
|
return helper.appWriter(outPathBase, legacyPathBase, outAppPath)
|
||||||
.then((extra_scripts) => {
|
.then((extraScripts) => {
|
||||||
let legacy_scripts = [];
|
let legacyScripts = [];
|
||||||
|
|
||||||
legacyFiles.forEach((file) => {
|
legacyFiles.forEach((file) => {
|
||||||
let rel_file_path = path.relative(out_path_base, file);
|
let relFilePath = path.relative(outPathBase, file);
|
||||||
legacy_scripts.push(rel_file_path);
|
legacyScripts.push(relFilePath);
|
||||||
});
|
});
|
||||||
|
|
||||||
legacy_scripts = legacy_scripts.concat(extra_scripts);
|
legacyScripts = legacyScripts.concat(extraScripts);
|
||||||
|
|
||||||
let rel_app_path = path.relative(out_path_base, out_app_path);
|
let relAppPath = path.relative(outPathBase, outAppPath);
|
||||||
legacy_scripts.push(rel_app_path);
|
legacyScripts.push(relAppPath);
|
||||||
|
|
||||||
transform_html(legacy_scripts, only_legacy);
|
transformHtml(legacyScripts, onlyLegacy);
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
if (!helper.removeModules) return;
|
if (!helper.removeModules) return;
|
||||||
|
|
@ -292,15 +292,15 @@ function make_lib_files(import_format, source_maps, with_app_dir, only_legacy) {
|
||||||
return Promise.all(outFiles.map((filepath) => {
|
return Promise.all(outFiles.map((filepath) => {
|
||||||
unlink(filepath)
|
unlink(filepath)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
// Try to clean up any empty directories if this
|
// Try to clean up any empty directories if
|
||||||
// was the last file in there
|
// this was the last file in there
|
||||||
const rmdir_r = dir =>
|
const rmdirR = dir =>
|
||||||
rmdir(dir)
|
rmdir(dir)
|
||||||
.then(() => rmdir_r(path.dirname(dir)))
|
.then(() => rmdirR(path.dirname(dir)))
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
// Assume the error was ENOTEMPTY and ignore it
|
// Assume the error was ENOTEMPTY and ignore it
|
||||||
});
|
});
|
||||||
return rmdir_r(path.dirname(filepath));
|
return rmdirR(path.dirname(filepath));
|
||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
|
@ -312,11 +312,11 @@ function make_lib_files(import_format, source_maps, with_app_dir, only_legacy) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (program.clean) {
|
if (program.clean) {
|
||||||
console.log(`Removing ${paths.lib_dir_base}`);
|
console.log(`Removing ${paths.libDirBase}`);
|
||||||
fse.removeSync(paths.lib_dir_base);
|
fse.removeSync(paths.libDirBase);
|
||||||
|
|
||||||
console.log(`Removing ${paths.out_dir_base}`);
|
console.log(`Removing ${paths.outDirBase}`);
|
||||||
fse.removeSync(paths.out_dir_base);
|
fse.removeSync(paths.outDirBase);
|
||||||
}
|
}
|
||||||
|
|
||||||
make_lib_files(program.as, program.withSourceMaps, program.withApp, program.onlyLegacy);
|
makeLibFiles(program.as, program.withSourceMaps, program.withApp, program.onlyLegacy);
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ const path = require('path');
|
||||||
|
|
||||||
// util.promisify requires Node.js 8.x, so we have our own
|
// util.promisify requires Node.js 8.x, so we have our own
|
||||||
function promisify(original) {
|
function promisify(original) {
|
||||||
return function promise_wrap() {
|
return function promiseWrap() {
|
||||||
const args = Array.prototype.slice.call(arguments);
|
const args = Array.prototype.slice.call(arguments);
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
original.apply(this, args.concat((err, value) => {
|
original.apply(this, args.concat((err, value) => {
|
||||||
|
|
@ -19,39 +19,39 @@ const writeFile = promisify(fs.writeFile);
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
'amd': {
|
'amd': {
|
||||||
appWriter: (base_out_path, script_base_path, out_path) => {
|
appWriter: (baseOutPath, scriptBasePath, outPath) => {
|
||||||
// setup for requirejs
|
// setup for requirejs
|
||||||
const ui_path = path.relative(base_out_path,
|
const uiPath = path.relative(baseOutPath,
|
||||||
path.join(script_base_path, 'app', 'ui'));
|
path.join(scriptBasePath, 'app', 'ui'));
|
||||||
return writeFile(out_path, `requirejs(["${ui_path}"], function (ui) {});`)
|
return writeFile(outPath, `requirejs(["${uiPath}"], function (ui) {});`)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
console.log(`Please place RequireJS in ${path.join(script_base_path, 'require.js')}`);
|
console.log(`Please place RequireJS in ${path.join(scriptBasePath, 'require.js')}`);
|
||||||
const require_path = path.relative(base_out_path,
|
const requirePath = path.relative(baseOutPath,
|
||||||
path.join(script_base_path, 'require.js'));
|
path.join(scriptBasePath, 'require.js'));
|
||||||
return [ require_path ];
|
return [ requirePath ];
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
'commonjs': {
|
'commonjs': {
|
||||||
appWriter: (base_out_path, script_base_path, out_path) => {
|
appWriter: (baseOutPath, scriptBasePath, outPath) => {
|
||||||
const browserify = require('browserify');
|
const browserify = require('browserify');
|
||||||
const b = browserify(path.join(script_base_path, 'app/ui.js'), {});
|
const b = browserify(path.join(scriptBasePath, 'app/ui.js'), {});
|
||||||
return promisify(b.bundle).call(b)
|
return promisify(b.bundle).call(b)
|
||||||
.then(buf => writeFile(out_path, buf))
|
.then(buf => writeFile(outPath, buf))
|
||||||
.then(() => []);
|
.then(() => []);
|
||||||
},
|
},
|
||||||
removeModules: true,
|
removeModules: true,
|
||||||
},
|
},
|
||||||
'systemjs': {
|
'systemjs': {
|
||||||
appWriter: (base_out_path, script_base_path, out_path) => {
|
appWriter: (baseOutPath, scriptBasePath, outPath) => {
|
||||||
const ui_path = path.relative(base_out_path,
|
const uiPath = path.relative(baseOutPath,
|
||||||
path.join(script_base_path, 'app', 'ui.js'));
|
path.join(scriptBasePath, 'app', 'ui.js'));
|
||||||
return writeFile(out_path, `SystemJS.import("${ui_path}");`)
|
return writeFile(outPath, `SystemJS.import("${uiPath}");`)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
console.log(`Please place SystemJS in ${path.join(script_base_path, 'system-production.js')}`);
|
console.log(`Please place SystemJS in ${path.join(scriptBasePath, 'system-production.js')}`);
|
||||||
const systemjs_path = path.relative(base_out_path,
|
const systemjsPath = path.relative(baseOutPath,
|
||||||
path.join(script_base_path, 'system-production.js'));
|
path.join(scriptBasePath, 'system-production.js'));
|
||||||
return [ systemjs_path ];
|
return [ systemjsPath ];
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue