restructured build.ts and added a helpcommand
This commit is contained in:
114
lib/build.js
114
lib/build.js
@@ -8,7 +8,8 @@ const fs_1 = require("fs");
|
|||||||
const paths_1 = require("./paths");
|
const paths_1 = require("./paths");
|
||||||
const readmeta_1 = __importDefault(require("./readmeta"));
|
const readmeta_1 = __importDefault(require("./readmeta"));
|
||||||
const prettier_1 = require("prettier");
|
const prettier_1 = require("prettier");
|
||||||
function default_1(name, watchCallback, PrettierConfig, CLIArgs) {
|
const main_1 = require("./main");
|
||||||
|
function default_1(name, watchCallback) {
|
||||||
//read meta file
|
//read meta file
|
||||||
let [metaJson, metaString] = (0, readmeta_1.default)(name);
|
let [metaJson, metaString] = (0, readmeta_1.default)(name);
|
||||||
let pathDist = (0, paths_1.DistPath)(name);
|
let pathDist = (0, paths_1.DistPath)(name);
|
||||||
@@ -19,7 +20,7 @@ function default_1(name, watchCallback, PrettierConfig, CLIArgs) {
|
|||||||
platform: 'node',
|
platform: 'node',
|
||||||
format: 'esm',
|
format: 'esm',
|
||||||
bundle: true,
|
bundle: true,
|
||||||
minify: CLIArgs.minify,
|
minify: main_1.CLIArgs.minify,
|
||||||
define: {
|
define: {
|
||||||
UserScriptName: `'${metaJson.name}'`,
|
UserScriptName: `'${metaJson.name}'`,
|
||||||
UserScriptNamespace: `'${metaJson.namespace}'`,
|
UserScriptNamespace: `'${metaJson.namespace}'`,
|
||||||
@@ -29,66 +30,44 @@ function default_1(name, watchCallback, PrettierConfig, CLIArgs) {
|
|||||||
UserScriptHomepageURL: `'${metaJson.homepageURL}'`,
|
UserScriptHomepageURL: `'${metaJson.homepageURL}'`,
|
||||||
},
|
},
|
||||||
}, result => {
|
}, result => {
|
||||||
let error = runPostEsbuild(name, result, metaString, CLIArgs, PrettierConfig);
|
let error = postBuild(name, result, metaString);
|
||||||
watchCallback(metaJson, error);
|
watchCallback(metaJson, error);
|
||||||
}, CLIArgs);
|
});
|
||||||
let error = runPostEsbuild(name, result, metaString, CLIArgs, PrettierConfig);
|
let error = postBuild(name, result, metaString);
|
||||||
return [metaJson, error];
|
return [metaJson, error];
|
||||||
}
|
}
|
||||||
exports.default = default_1;
|
exports.default = default_1;
|
||||||
function doErrorFile(pathError, pathOutFile, error) {
|
function runEsbuild(opts, watchCallback) {
|
||||||
if (error !== null) {
|
|
||||||
(0, fs_1.writeFileSync)(pathError, `${new Date().toISOString()}\n\n${error}`);
|
|
||||||
if ((0, fs_1.existsSync)(pathOutFile)) {
|
|
||||||
(0, fs_1.unlinkSync)(pathOutFile);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if ((0, fs_1.existsSync)(pathError)) {
|
|
||||||
(0, fs_1.unlinkSync)(pathError);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
function runEsbuild(opts, watchCallback, CLIArgs) {
|
|
||||||
opts.write = false;
|
opts.write = false;
|
||||||
if (CLIArgs.watch) {
|
if (main_1.CLIArgs.watch) {
|
||||||
opts.watch = {
|
opts.watch = {
|
||||||
onRebuild(err, res) {
|
onRebuild(err, res) {
|
||||||
if (err) {
|
watchCallback(getResult(err, res));
|
||||||
watchCallback({
|
|
||||||
content: null,
|
|
||||||
error: err.message,
|
|
||||||
errorRaw: err,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else if (res) {
|
|
||||||
let content = '';
|
|
||||||
if (res.outputFiles && res.outputFiles.length > 0) {
|
|
||||||
content = res.outputFiles[0].text;
|
|
||||||
}
|
|
||||||
if (content === '') {
|
|
||||||
watchCallback({
|
|
||||||
content: null,
|
|
||||||
error: 'No output',
|
|
||||||
});
|
|
||||||
}
|
|
||||||
watchCallback({
|
|
||||||
content,
|
|
||||||
error: null,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
watchCallback({
|
|
||||||
content: null,
|
|
||||||
error: 'No result',
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
let res = (0, esbuild_1.buildSync)(opts);
|
let res = (0, esbuild_1.buildSync)(opts);
|
||||||
|
return getResult(null, res);
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
return getResult(err, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function getResult(error, result) {
|
||||||
|
if (error) {
|
||||||
|
return {
|
||||||
|
content: null,
|
||||||
|
error: error.message,
|
||||||
|
errorRaw: error,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
else if (result) {
|
||||||
let content = '';
|
let content = '';
|
||||||
if (res.outputFiles && res.outputFiles.length > 0) {
|
if (result.outputFiles && result.outputFiles.length > 0) {
|
||||||
content = clearFilenameComments(res.outputFiles[0].text);
|
content = result.outputFiles[0].text;
|
||||||
|
if (!main_1.CLIArgs.srccomment)
|
||||||
|
content = clearFilenameComments(content);
|
||||||
}
|
}
|
||||||
if (content === '') {
|
if (content === '') {
|
||||||
return {
|
return {
|
||||||
@@ -101,37 +80,54 @@ function runEsbuild(opts, watchCallback, CLIArgs) {
|
|||||||
error: null,
|
error: null,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
catch (err) {
|
else {
|
||||||
return {
|
return {
|
||||||
content: null,
|
content: null,
|
||||||
error: err.message,
|
error: 'No result',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function runPostEsbuild(name, result, metaString, CLIArgs, PrettierConfig) {
|
function clearFilenameComments(content) {
|
||||||
|
let regexp = new RegExp(`//\\s*${paths_1.ScriptBase}/.*(?:\\n|$)`, 'g');
|
||||||
|
return content.replace(regexp, '');
|
||||||
|
}
|
||||||
|
function postBuild(name, result, metaString) {
|
||||||
let error = null;
|
let error = null;
|
||||||
let path = (0, paths_1.ScriptPath)(name);
|
let path = (0, paths_1.ScriptPath)(name);
|
||||||
let pathDist = (0, paths_1.DistPath)(name);
|
let pathDist = (0, paths_1.DistPath)(name);
|
||||||
|
let PrettierConfig = prettier_1.resolveConfig.sync(path.dir) || {};
|
||||||
if (result.error) {
|
if (result.error) {
|
||||||
console.error(name, result.errorRaw || result.error);
|
console.error(name, result.errorRaw || result.error);
|
||||||
error = result.error;
|
error = result.error;
|
||||||
}
|
}
|
||||||
else if (result.content) {
|
else if (result.content) {
|
||||||
let content = metaString + result.content;
|
let content = metaString + result.content;
|
||||||
if (CLIArgs.prettier) {
|
if (main_1.CLIArgs.prettier) {
|
||||||
content = (0, prettier_1.format)(content, PrettierConfig);
|
content = (0, prettier_1.format)(content, {
|
||||||
|
...PrettierConfig,
|
||||||
|
parser: 'babel',
|
||||||
|
});
|
||||||
}
|
}
|
||||||
(0, fs_1.writeFileSync)(pathDist, content);
|
(0, fs_1.writeFileSync)(pathDist, content);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
console.error(name, 'No output');
|
console.error(name, 'No output');
|
||||||
}
|
}
|
||||||
doErrorFile(path.error, pathDist, error);
|
doErrorFile(name, error);
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
//remove all filename comments
|
function doErrorFile(name, error) {
|
||||||
function clearFilenameComments(content) {
|
let path = (0, paths_1.ScriptPath)(name);
|
||||||
let regexp = new RegExp(`//\\s*${paths_1.ScriptBase}/.*(?:\\n|$)`, 'g');
|
let outfile = (0, paths_1.DistPath)(name);
|
||||||
return content.replace(regexp, '');
|
let content = `${new Date().toISOString()}\n\n${error}`;
|
||||||
|
if (error !== null) {
|
||||||
|
(0, fs_1.writeFileSync)(path.error, content);
|
||||||
|
if ((0, fs_1.existsSync)(outfile)) {
|
||||||
|
(0, fs_1.unlinkSync)(outfile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if ((0, fs_1.existsSync)(path.error)) {
|
||||||
|
(0, fs_1.unlinkSync)(path.error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//# sourceMappingURL=build.js.map
|
//# sourceMappingURL=build.js.map
|
||||||
@@ -1 +1 @@
|
|||||||
{"version":3,"file":"build.js","sourceRoot":"","sources":["../src/build.ts"],"names":[],"mappings":";;;;;AAAA,qCAA+D;AAC/D,2BAA0D;AAC1D,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
@@ -1,19 +1,76 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||||
|
if (k2 === undefined) k2 = k;
|
||||||
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||||
|
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||||
|
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||||
|
}
|
||||||
|
Object.defineProperty(o, k2, desc);
|
||||||
|
}) : (function(o, m, k, k2) {
|
||||||
|
if (k2 === undefined) k2 = k;
|
||||||
|
o[k2] = m[k];
|
||||||
|
}));
|
||||||
|
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||||
|
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||||
|
}) : function(o, v) {
|
||||||
|
o["default"] = v;
|
||||||
|
});
|
||||||
|
var __importStar = (this && this.__importStar) || function (mod) {
|
||||||
|
if (mod && mod.__esModule) return mod;
|
||||||
|
var result = {};
|
||||||
|
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||||
|
__setModuleDefault(result, mod);
|
||||||
|
return result;
|
||||||
|
};
|
||||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
exports.CLIArgs = void 0;
|
||||||
const fs_1 = require("fs");
|
const fs_1 = require("fs");
|
||||||
const command_line_args_1 = __importDefault(require("command-line-args"));
|
const command_line_args_1 = __importDefault(require("command-line-args"));
|
||||||
const prettier_1 = require("prettier");
|
|
||||||
const paths_1 = require("./paths");
|
const paths_1 = require("./paths");
|
||||||
const readmefile_1 = require("./readmefile");
|
const readmefile_1 = require("./readmefile");
|
||||||
const build_1 = __importDefault(require("./build"));
|
const build_1 = __importDefault(require("./build"));
|
||||||
const CLIArgs = (0, command_line_args_1.default)([
|
const Path = __importStar(require("path"));
|
||||||
|
exports.CLIArgs = (0, command_line_args_1.default)([
|
||||||
{ name: 'watch', alias: 'w', type: Boolean, defaultValue: false },
|
{ name: 'watch', alias: 'w', type: Boolean, defaultValue: false },
|
||||||
{ name: 'minify', alias: 'm', type: Boolean, defaultValue: false },
|
{ name: 'minify', alias: 'm', type: Boolean, defaultValue: false },
|
||||||
{ name: 'prettier', alias: 'p', type: Boolean, defaultValue: false },
|
{ name: 'prettier', alias: 'p', type: Boolean, defaultValue: false },
|
||||||
|
{ name: 'srccomment', alias: 's', type: Boolean, defaultValue: false },
|
||||||
|
{ name: 'help', alias: 'h', type: Boolean, defaultValue: false },
|
||||||
]);
|
]);
|
||||||
|
if (exports.CLIArgs.help) {
|
||||||
|
let command = '<command>';
|
||||||
|
if (process.argv.length > 0) {
|
||||||
|
command = Path.parse(process.argv[0]).name;
|
||||||
|
}
|
||||||
|
if (command.toLowerCase() === 'node' && process.argv.length > 1) {
|
||||||
|
let path = Path.relative(process.cwd(), process.argv[1]) || '.';
|
||||||
|
command = `${command} ${path}`;
|
||||||
|
}
|
||||||
|
console.log(`
|
||||||
|
Usage: ${command} [options]
|
||||||
|
|
||||||
|
options:
|
||||||
|
--watch
|
||||||
|
alias: -w
|
||||||
|
automatically recompile on save
|
||||||
|
--minify
|
||||||
|
alias: -m
|
||||||
|
minify output files
|
||||||
|
--prettier
|
||||||
|
alias: -p
|
||||||
|
prettify output files
|
||||||
|
--srccomment
|
||||||
|
alias: -s
|
||||||
|
include src file path comments in the output files, i.e. // scripts/example/main.ts
|
||||||
|
--help
|
||||||
|
alias: -h
|
||||||
|
show this help message
|
||||||
|
`);
|
||||||
|
process.exit(0);
|
||||||
|
}
|
||||||
//if package.json doesn't exist then there is no point in continuing
|
//if package.json doesn't exist then there is no point in continuing
|
||||||
if (!(0, fs_1.existsSync)('package.json') || !(0, fs_1.lstatSync)('package.json').isFile()) {
|
if (!(0, fs_1.existsSync)('package.json') || !(0, fs_1.lstatSync)('package.json').isFile()) {
|
||||||
console.error('package.json not found, unwilling to run');
|
console.error('package.json not found, unwilling to run');
|
||||||
@@ -21,14 +78,6 @@ if (!(0, fs_1.existsSync)('package.json') || !(0, fs_1.lstatSync)('package.json'
|
|||||||
}
|
}
|
||||||
//delete compiled scripts
|
//delete compiled scripts
|
||||||
(0, fs_1.readdirSync)(paths_1.DistBase).forEach(file => (0, fs_1.unlinkSync)(`${paths_1.DistBase}/${file}`));
|
(0, fs_1.readdirSync)(paths_1.DistBase).forEach(file => (0, fs_1.unlinkSync)(`${paths_1.DistBase}/${file}`));
|
||||||
//read prettierrc file and make sure `babel` is the configured parser
|
|
||||||
const PrettierConfig = (() => {
|
|
||||||
let config = prettier_1.resolveConfig.sync(process.cwd()) || {};
|
|
||||||
return {
|
|
||||||
...config,
|
|
||||||
parser: 'babel',
|
|
||||||
};
|
|
||||||
})();
|
|
||||||
//compile scripts
|
//compile scripts
|
||||||
let scripts = (0, fs_1.readdirSync)(paths_1.ScriptBase);
|
let scripts = (0, fs_1.readdirSync)(paths_1.ScriptBase);
|
||||||
let scriptMeta = [];
|
let scriptMeta = [];
|
||||||
@@ -45,11 +94,11 @@ for (let name of scripts) {
|
|||||||
console.log('WATCH', name, meta.version);
|
console.log('WATCH', name, meta.version);
|
||||||
(0, readmefile_1.updateReadmeFile)(scriptMeta);
|
(0, readmefile_1.updateReadmeFile)(scriptMeta);
|
||||||
}
|
}
|
||||||
let [meta, error] = (0, build_1.default)(name, postWatchUpdate, PrettierConfig, CLIArgs);
|
let [meta, error] = (0, build_1.default)(name, postWatchUpdate);
|
||||||
scriptMeta[id] = { meta, error };
|
scriptMeta[id] = { meta, error };
|
||||||
console.log(name, meta.version);
|
console.log(name, meta.version);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
(0, readmefile_1.updateReadmeFile)(scriptMeta);
|
(0, readmefile_1.updateReadmeFile)(scriptMeta);
|
||||||
console.log(`\nFinished Compiling\n${CLIArgs.watch ? 'Listening for Changes\n' : ''}`);
|
console.log(`\nFinished Compiling\n${exports.CLIArgs.watch ? 'Listening for Changes\n' : ''}`);
|
||||||
//# sourceMappingURL=main.js.map
|
//# sourceMappingURL=main.js.map
|
||||||
@@ -1 +1 @@
|
|||||||
{"version":3,"file":"main.js","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":";;;;;AAAA,2BAAmE;AACnE,0EAA+C;AAC/C,uCAAwC;AACxC,mCAA0D;AAC1D,6CAA2D;AAC3D,oDAA8B;AAS9B,MAAM,OAAO,GAAG,IAAA,2BAAe,EAAC;IAC5B,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE,YAAY,EAAE,KAAK,EAAE;IACjE,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE,YAAY,EAAE,KAAK,EAAE;IAClE,EAAE,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE,YAAY,EAAE,KAAK,EAAE;CACvE,CAAY,CAAA;AAEb,oEAAoE;AACpE,IAAI,CAAC,IAAA,eAAU,EAAC,cAAc,CAAC,IAAI,CAAC,IAAA,cAAS,EAAC,cAAc,CAAC,CAAC,MAAM,EAAE,EAAE;IACpE,OAAO,CAAC,KAAK,CAAC,0CAA0C,CAAC,CAAA;IACzD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;CAClB;AAED,yBAAyB;AACzB,IAAA,gBAAW,EAAC,gBAAQ,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,IAAA,eAAU,EAAC,GAAG,gBAAQ,IAAI,IAAI,EAAE,CAAC,CAAC,CAAA;A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AAA,UAAU,cAKrB;AAEK,MAAM,QAAQ,GAAG,CAAC,IAAY,EAAE,EAAE,CAAC,GAAG,gBAAQ,IAAI,IAAI,UAAU,CAAA;AAA1D,QAAA,QAAQ,YAAkD"}
|
||||||
@@ -46,4 +46,7 @@ Root
|
|||||||
--prettier
|
--prettier
|
||||||
alias: -p
|
alias: -p
|
||||||
prettify output files
|
prettify output files
|
||||||
|
--srccomment
|
||||||
|
alias: -s
|
||||||
|
include src file path comments in the output files, i.e. // scripts/example/main.ts
|
||||||
```
|
```
|
||||||
|
|||||||
137
src/build.ts
137
src/build.ts
@@ -1,16 +1,14 @@
|
|||||||
import { buildSync, BuildFailure, BuildOptions } from 'esbuild'
|
import { buildSync, BuildFailure, BuildOptions, BuildResult } from 'esbuild'
|
||||||
import { existsSync, writeFileSync, unlinkSync } from 'fs'
|
import { existsSync, writeFileSync, unlinkSync } from 'fs'
|
||||||
import { DistPath, ScriptBase, ScriptPath } from './paths'
|
import { DistPath, ScriptBase, ScriptPath } from './paths'
|
||||||
import { UserScriptMetaFull } from './types'
|
import { UserScriptMetaFull } from './types'
|
||||||
import readMeta from './readmeta'
|
import readMeta from './readmeta'
|
||||||
import { format, Options } from 'prettier'
|
import { format, resolveConfig } from 'prettier'
|
||||||
import { CLIArgs } from './main'
|
import { CLIArgs } from './main'
|
||||||
|
|
||||||
export default function (
|
export default function (
|
||||||
name: string,
|
name: string,
|
||||||
watchCallback: (meta: UserScriptMetaFull, error: string | null) => void,
|
watchCallback: (meta: UserScriptMetaFull, error: string | null) => void
|
||||||
PrettierConfig: Options,
|
|
||||||
CLIArgs: CLIArgs
|
|
||||||
): [UserScriptMetaFull, string | null] {
|
): [UserScriptMetaFull, string | null] {
|
||||||
//read meta file
|
//read meta file
|
||||||
let [metaJson, metaString] = readMeta(name)
|
let [metaJson, metaString] = readMeta(name)
|
||||||
@@ -39,45 +37,16 @@ export default function (
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
result => {
|
result => {
|
||||||
let error = runPostEsbuild(
|
let error = postBuild(name, result, metaString)
|
||||||
name,
|
|
||||||
result,
|
|
||||||
metaString,
|
|
||||||
CLIArgs,
|
|
||||||
PrettierConfig
|
|
||||||
)
|
|
||||||
watchCallback(metaJson, error)
|
watchCallback(metaJson, error)
|
||||||
},
|
}
|
||||||
CLIArgs
|
|
||||||
)
|
)
|
||||||
|
|
||||||
let error = runPostEsbuild(
|
let error = postBuild(name, result, metaString)
|
||||||
name,
|
|
||||||
result,
|
|
||||||
metaString,
|
|
||||||
CLIArgs,
|
|
||||||
PrettierConfig
|
|
||||||
)
|
|
||||||
|
|
||||||
return [metaJson, error]
|
return [metaJson, error]
|
||||||
}
|
}
|
||||||
|
|
||||||
function doErrorFile(
|
|
||||||
pathError: string,
|
|
||||||
pathOutFile: string,
|
|
||||||
error: string | null
|
|
||||||
) {
|
|
||||||
if (error !== null) {
|
|
||||||
writeFileSync(pathError, `${new Date().toISOString()}\n\n${error}`)
|
|
||||||
|
|
||||||
if (existsSync(pathOutFile)) {
|
|
||||||
unlinkSync(pathOutFile)
|
|
||||||
}
|
|
||||||
} else if (existsSync(pathError)) {
|
|
||||||
unlinkSync(pathError)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
interface RunEsbuildResult {
|
interface RunEsbuildResult {
|
||||||
content: string | null
|
content: string | null
|
||||||
error: string | null
|
error: string | null
|
||||||
@@ -86,49 +55,37 @@ interface RunEsbuildResult {
|
|||||||
|
|
||||||
function runEsbuild(
|
function runEsbuild(
|
||||||
opts: BuildOptions,
|
opts: BuildOptions,
|
||||||
watchCallback: (result: RunEsbuildResult) => void,
|
watchCallback: (result: RunEsbuildResult) => void
|
||||||
CLIArgs: CLIArgs
|
|
||||||
): RunEsbuildResult {
|
): RunEsbuildResult {
|
||||||
opts.write = false
|
opts.write = false
|
||||||
if (CLIArgs.watch) {
|
if (CLIArgs.watch) {
|
||||||
opts.watch = {
|
opts.watch = {
|
||||||
onRebuild(err, res) {
|
onRebuild(err, res) {
|
||||||
if (err) {
|
watchCallback(getResult(err, res))
|
||||||
watchCallback({
|
|
||||||
content: null,
|
|
||||||
error: (err as BuildFailure).message,
|
|
||||||
errorRaw: err,
|
|
||||||
})
|
|
||||||
} else if (res) {
|
|
||||||
let content = ''
|
|
||||||
if (res.outputFiles && res.outputFiles.length > 0) {
|
|
||||||
content = res.outputFiles[0].text
|
|
||||||
}
|
|
||||||
if (content === '') {
|
|
||||||
watchCallback({
|
|
||||||
content: null,
|
|
||||||
error: 'No output',
|
|
||||||
})
|
|
||||||
}
|
|
||||||
watchCallback({
|
|
||||||
content,
|
|
||||||
error: null,
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
watchCallback({
|
|
||||||
content: null,
|
|
||||||
error: 'No result',
|
|
||||||
})
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let res = buildSync(opts)
|
let res = buildSync(opts)
|
||||||
|
return getResult(null, res)
|
||||||
|
} catch (err) {
|
||||||
|
return getResult(err as BuildFailure, null)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function getResult(error: BuildFailure | null, result: BuildResult | null) {
|
||||||
|
if (error) {
|
||||||
|
return {
|
||||||
|
content: null,
|
||||||
|
error: (error as BuildFailure).message,
|
||||||
|
errorRaw: error,
|
||||||
|
}
|
||||||
|
} else if (result) {
|
||||||
let content = ''
|
let content = ''
|
||||||
if (res.outputFiles && res.outputFiles.length > 0) {
|
if (result.outputFiles && result.outputFiles.length > 0) {
|
||||||
content = clearFilenameComments(res.outputFiles[0].text)
|
content = result.outputFiles[0].text
|
||||||
|
if (!CLIArgs.srccomment) content = clearFilenameComments(content)
|
||||||
}
|
}
|
||||||
if (content === '') {
|
if (content === '') {
|
||||||
return {
|
return {
|
||||||
@@ -140,45 +97,59 @@ function runEsbuild(
|
|||||||
content,
|
content,
|
||||||
error: null,
|
error: null,
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} else {
|
||||||
return {
|
return {
|
||||||
content: null,
|
content: null,
|
||||||
error: (err as BuildFailure).message,
|
error: 'No result',
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function runPostEsbuild(
|
function clearFilenameComments(content: string): string {
|
||||||
name: string,
|
let regexp = new RegExp(`//\\s*${ScriptBase}/.*(?:\\n|$)`, 'g')
|
||||||
result: RunEsbuildResult,
|
return content.replace(regexp, '')
|
||||||
metaString: string,
|
}
|
||||||
CLIArgs: CLIArgs,
|
|
||||||
PrettierConfig: Options
|
function postBuild(name: string, result: RunEsbuildResult, metaString: string) {
|
||||||
) {
|
|
||||||
let error: string | null = null
|
let error: string | null = null
|
||||||
let path = ScriptPath(name)
|
let path = ScriptPath(name)
|
||||||
let pathDist = DistPath(name)
|
let pathDist = DistPath(name)
|
||||||
|
|
||||||
|
let PrettierConfig = resolveConfig.sync(path.dir) || {}
|
||||||
|
|
||||||
if (result.error) {
|
if (result.error) {
|
||||||
console.error(name, result.errorRaw || result.error)
|
console.error(name, result.errorRaw || result.error)
|
||||||
error = result.error
|
error = result.error
|
||||||
} else if (result.content) {
|
} else if (result.content) {
|
||||||
let content = metaString + result.content
|
let content = metaString + result.content
|
||||||
if (CLIArgs.prettier) {
|
if (CLIArgs.prettier) {
|
||||||
content = format(content, PrettierConfig)
|
content = format(content, {
|
||||||
|
...PrettierConfig,
|
||||||
|
parser: 'babel',
|
||||||
|
})
|
||||||
}
|
}
|
||||||
writeFileSync(pathDist, content)
|
writeFileSync(pathDist, content)
|
||||||
} else {
|
} else {
|
||||||
console.error(name, 'No output')
|
console.error(name, 'No output')
|
||||||
}
|
}
|
||||||
|
|
||||||
doErrorFile(path.error, pathDist, error)
|
doErrorFile(name, error)
|
||||||
|
|
||||||
return error
|
return error
|
||||||
}
|
}
|
||||||
|
|
||||||
//remove all filename comments
|
function doErrorFile(name: string, error: string | null) {
|
||||||
function clearFilenameComments(content: string): string {
|
let path = ScriptPath(name)
|
||||||
let regexp = new RegExp(`//\\s*${ScriptBase}/.*(?:\\n|$)`, 'g')
|
let outfile = DistPath(name)
|
||||||
return content.replace(regexp, '')
|
|
||||||
|
let content = `${new Date().toISOString()}\n\n${error}`
|
||||||
|
|
||||||
|
if (error !== null) {
|
||||||
|
writeFileSync(path.error, content)
|
||||||
|
if (existsSync(outfile)) {
|
||||||
|
unlinkSync(outfile)
|
||||||
|
}
|
||||||
|
} else if (existsSync(path.error)) {
|
||||||
|
unlinkSync(path.error)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
61
src/main.ts
61
src/main.ts
@@ -1,22 +1,59 @@
|
|||||||
import { existsSync, lstatSync, readdirSync, unlinkSync } from 'fs'
|
import { existsSync, lstatSync, readdirSync, unlinkSync } from 'fs'
|
||||||
import commandLineArgs from 'command-line-args'
|
import commandLineArgs from 'command-line-args'
|
||||||
import { resolveConfig } from 'prettier'
|
|
||||||
import { DistBase, ScriptBase, ScriptPath } from './paths'
|
import { DistBase, ScriptBase, ScriptPath } from './paths'
|
||||||
import { readmeData, updateReadmeFile } from './readmefile'
|
import { readmeData, updateReadmeFile } from './readmefile'
|
||||||
import runBuild from './build'
|
import runBuild from './build'
|
||||||
import { UserScriptMetaFull } from './types'
|
import { UserScriptMetaFull } from './types'
|
||||||
|
import * as Path from 'path'
|
||||||
|
|
||||||
export interface CLIArgs {
|
export interface CLIArgsT {
|
||||||
watch: boolean
|
watch: boolean
|
||||||
minify: boolean
|
minify: boolean
|
||||||
prettier: boolean
|
prettier: boolean
|
||||||
|
srccomment: boolean
|
||||||
|
help: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
const CLIArgs = commandLineArgs([
|
export const CLIArgs = commandLineArgs([
|
||||||
{ name: 'watch', alias: 'w', type: Boolean, defaultValue: false },
|
{ name: 'watch', alias: 'w', type: Boolean, defaultValue: false },
|
||||||
{ name: 'minify', alias: 'm', type: Boolean, defaultValue: false },
|
{ name: 'minify', alias: 'm', type: Boolean, defaultValue: false },
|
||||||
{ name: 'prettier', alias: 'p', type: Boolean, defaultValue: false },
|
{ name: 'prettier', alias: 'p', type: Boolean, defaultValue: false },
|
||||||
]) as CLIArgs
|
{ name: 'srccomment', alias: 's', type: Boolean, defaultValue: false },
|
||||||
|
{ name: 'help', alias: 'h', type: Boolean, defaultValue: false },
|
||||||
|
]) as CLIArgsT
|
||||||
|
|
||||||
|
if (CLIArgs.help) {
|
||||||
|
let command = '<command>'
|
||||||
|
if (process.argv.length > 0) {
|
||||||
|
command = Path.parse(process.argv[0]).name
|
||||||
|
}
|
||||||
|
if (command.toLowerCase() === 'node' && process.argv.length > 1) {
|
||||||
|
let path = Path.relative(process.cwd(), process.argv[1]) || '.'
|
||||||
|
command = `${command} ${path}`
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(`
|
||||||
|
Usage: ${command} [options]
|
||||||
|
|
||||||
|
options:
|
||||||
|
--watch
|
||||||
|
alias: -w
|
||||||
|
automatically recompile on save
|
||||||
|
--minify
|
||||||
|
alias: -m
|
||||||
|
minify output files
|
||||||
|
--prettier
|
||||||
|
alias: -p
|
||||||
|
prettify output files
|
||||||
|
--srccomment
|
||||||
|
alias: -s
|
||||||
|
include src file path comments in the output files, i.e. // scripts/example/main.ts
|
||||||
|
--help
|
||||||
|
alias: -h
|
||||||
|
show this help message
|
||||||
|
`)
|
||||||
|
process.exit(0)
|
||||||
|
}
|
||||||
|
|
||||||
//if package.json doesn't exist then there is no point in continuing
|
//if package.json doesn't exist then there is no point in continuing
|
||||||
if (!existsSync('package.json') || !lstatSync('package.json').isFile()) {
|
if (!existsSync('package.json') || !lstatSync('package.json').isFile()) {
|
||||||
@@ -27,15 +64,6 @@ if (!existsSync('package.json') || !lstatSync('package.json').isFile()) {
|
|||||||
//delete compiled scripts
|
//delete compiled scripts
|
||||||
readdirSync(DistBase).forEach(file => unlinkSync(`${DistBase}/${file}`))
|
readdirSync(DistBase).forEach(file => unlinkSync(`${DistBase}/${file}`))
|
||||||
|
|
||||||
//read prettierrc file and make sure `babel` is the configured parser
|
|
||||||
const PrettierConfig = (() => {
|
|
||||||
let config = resolveConfig.sync(process.cwd()) || {}
|
|
||||||
return {
|
|
||||||
...config,
|
|
||||||
parser: 'babel',
|
|
||||||
}
|
|
||||||
})()
|
|
||||||
|
|
||||||
//compile scripts
|
//compile scripts
|
||||||
let scripts = readdirSync(ScriptBase)
|
let scripts = readdirSync(ScriptBase)
|
||||||
let scriptMeta: readmeData[] = []
|
let scriptMeta: readmeData[] = []
|
||||||
@@ -61,12 +89,7 @@ for (let name of scripts) {
|
|||||||
updateReadmeFile(scriptMeta)
|
updateReadmeFile(scriptMeta)
|
||||||
}
|
}
|
||||||
|
|
||||||
let [meta, error] = runBuild(
|
let [meta, error] = runBuild(name, postWatchUpdate)
|
||||||
name,
|
|
||||||
postWatchUpdate,
|
|
||||||
PrettierConfig,
|
|
||||||
CLIArgs
|
|
||||||
)
|
|
||||||
scriptMeta[id] = { meta, error }
|
scriptMeta[id] = { meta, error }
|
||||||
|
|
||||||
console.log(name, meta.version)
|
console.log(name, meta.version)
|
||||||
|
|||||||
@@ -7,7 +7,13 @@ export const SupportUrl = `${BaseUrl}/issues`
|
|||||||
export const FileUrl = (name: string) =>
|
export const FileUrl = (name: string) =>
|
||||||
`${BaseUrl}/raw/branch/${RemoteBranch}/${DistBase}/${name}.user.js`
|
`${BaseUrl}/raw/branch/${RemoteBranch}/${DistBase}/${name}.user.js`
|
||||||
|
|
||||||
export const ScriptPath = (name: string) => ({
|
export interface ScriptPathT {
|
||||||
|
dir: `${string}/${string}`
|
||||||
|
main: `${string}/${string}/main.ts`
|
||||||
|
meta: `${string}/${string}/meta.json`
|
||||||
|
error: `${string}/${string}/error.log`
|
||||||
|
}
|
||||||
|
export const ScriptPath = (name: string): ScriptPathT => ({
|
||||||
dir: `${ScriptBase}/${name}`,
|
dir: `${ScriptBase}/${name}`,
|
||||||
main: `${ScriptBase}/${name}/main.ts`,
|
main: `${ScriptBase}/${name}/main.ts`,
|
||||||
meta: `${ScriptBase}/${name}/meta.json`,
|
meta: `${ScriptBase}/${name}/meta.json`,
|
||||||
|
|||||||
Reference in New Issue
Block a user