better cli arg supper
This commit is contained in:
64
lib/build.js
64
lib/build.js
@@ -8,10 +8,9 @@ const fs_1 = require("fs");
|
||||
const paths_1 = require("./paths");
|
||||
const readmeta_1 = __importDefault(require("./readmeta"));
|
||||
const prettier_1 = require("prettier");
|
||||
function default_1(name, watchCallback = false, PrettierConfig) {
|
||||
function default_1(name, watchCallback, PrettierConfig, CLIArgs) {
|
||||
//read meta file
|
||||
let [metaJson, metaString] = (0, readmeta_1.default)(name);
|
||||
let path = (0, paths_1.ScriptPath)(name);
|
||||
let pathDist = (0, paths_1.DistPath)(name);
|
||||
let result = runEsbuild({
|
||||
entryPoints: [(0, paths_1.ScriptPath)(name).main],
|
||||
@@ -20,7 +19,7 @@ function default_1(name, watchCallback = false, PrettierConfig) {
|
||||
platform: 'node',
|
||||
format: 'esm',
|
||||
bundle: true,
|
||||
minify: false,
|
||||
minify: CLIArgs.minify,
|
||||
define: {
|
||||
UserScriptName: `'${metaJson.name}'`,
|
||||
UserScriptNamespace: `'${metaJson.namespace}'`,
|
||||
@@ -30,36 +29,10 @@ function default_1(name, watchCallback = false, PrettierConfig) {
|
||||
UserScriptHomepageURL: `'${metaJson.homepageURL}'`,
|
||||
},
|
||||
}, result => {
|
||||
let error = null;
|
||||
if (result.error) {
|
||||
console.error(name, result.errorRaw || result.error);
|
||||
error = result.error;
|
||||
}
|
||||
else if (result.content) {
|
||||
let content = (0, prettier_1.format)(metaString + result.content, PrettierConfig === null ? undefined : PrettierConfig);
|
||||
(0, fs_1.writeFileSync)(pathDist, content);
|
||||
}
|
||||
else {
|
||||
console.error(name, 'No output');
|
||||
}
|
||||
doErrorFile(path.error, pathDist, error);
|
||||
if (watchCallback !== false) {
|
||||
watchCallback(metaJson, error);
|
||||
}
|
||||
}, watchCallback !== false);
|
||||
let error = null;
|
||||
if (result.error) {
|
||||
console.error(name, result.errorRaw || result.error);
|
||||
error = result.error;
|
||||
}
|
||||
else if (result.content) {
|
||||
let content = (0, prettier_1.format)(metaString + result.content, PrettierConfig === null ? undefined : PrettierConfig);
|
||||
(0, fs_1.writeFileSync)(pathDist, content);
|
||||
}
|
||||
else {
|
||||
console.error(name, 'No output');
|
||||
}
|
||||
doErrorFile(path.error, pathDist, error);
|
||||
let error = runPostEsbuild(name, result, metaString, CLIArgs, PrettierConfig);
|
||||
watchCallback(metaJson, error);
|
||||
}, CLIArgs);
|
||||
let error = runPostEsbuild(name, result, metaString, CLIArgs, PrettierConfig);
|
||||
return [metaJson, error];
|
||||
}
|
||||
exports.default = default_1;
|
||||
@@ -74,9 +47,9 @@ function doErrorFile(pathError, pathOutFile, error) {
|
||||
(0, fs_1.unlinkSync)(pathError);
|
||||
}
|
||||
}
|
||||
function runEsbuild(opts, watchCallback, toWatch = false) {
|
||||
function runEsbuild(opts, watchCallback, CLIArgs) {
|
||||
opts.write = false;
|
||||
if (toWatch) {
|
||||
if (CLIArgs.watch) {
|
||||
opts.watch = {
|
||||
onRebuild(err, res) {
|
||||
if (err) {
|
||||
@@ -135,6 +108,27 @@ function runEsbuild(opts, watchCallback, toWatch = false) {
|
||||
};
|
||||
}
|
||||
}
|
||||
function runPostEsbuild(name, result, metaString, CLIArgs, PrettierConfig) {
|
||||
let error = null;
|
||||
let path = (0, paths_1.ScriptPath)(name);
|
||||
let pathDist = (0, paths_1.DistPath)(name);
|
||||
if (result.error) {
|
||||
console.error(name, result.errorRaw || result.error);
|
||||
error = result.error;
|
||||
}
|
||||
else if (result.content) {
|
||||
let content = metaString + result.content;
|
||||
if (CLIArgs.prettier) {
|
||||
content = (0, prettier_1.format)(content, PrettierConfig === null ? undefined : PrettierConfig);
|
||||
}
|
||||
(0, fs_1.writeFileSync)(pathDist, content);
|
||||
}
|
||||
else {
|
||||
console.error(name, 'No output');
|
||||
}
|
||||
doErrorFile(path.error, pathDist, error);
|
||||
return error;
|
||||
}
|
||||
//remove all filename comments
|
||||
function clearFilenameComments(content) {
|
||||
let regexp = new RegExp(`//\\s*${paths_1.ScriptBase}/.*(?:\\n|$)`, 'g');
|
||||
|
||||
Reference in New Issue
Block a user