Compare commits
63 Commits
43d31fdffb
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3ba1113d2f | ||
|
|
11cea55569 | ||
| ad5f5a3c15 | |||
| 8247860806 | |||
| 9c4fe7d3ea | |||
| ec24ba6c3e | |||
| d95a5533b1 | |||
| 302b8feee4 | |||
| 7df811852d | |||
| d249b02def | |||
| 5de6a97dbd | |||
| 7e67128abe | |||
| 806a82baae | |||
| ab8ef4ff5b | |||
| bf50d06d60 | |||
| 1b4cb233e5 | |||
| c9183d3022 | |||
| 7e24370186 | |||
| 83570d9535 | |||
| 29b40b4e43 | |||
| d00ddeb1e1 | |||
| c51ca65751 | |||
| a10a35d662 | |||
| 85ff5851b5 | |||
| 3dbb7f1066 | |||
| 0f9abb3e0e | |||
| 2c80f37bed | |||
| 6afcf5fdba | |||
| 6b5bf9783c | |||
| ba1ca2fc83 | |||
| e8de01b48a | |||
| 57f7599739 | |||
| 6e881ebd6f | |||
| 6d4f4c57bc | |||
| 5c29ba1ef2 | |||
| 78e9531e83 | |||
| 74904d1c0f | |||
| 3fdb3ad110 | |||
| 6b0b604008 | |||
| ac80b81129 | |||
| 05d11f11ec | |||
| 55f2a7461a | |||
| f0c3f7db1a | |||
| 588ee08d10 | |||
| afa8797823 | |||
| 789abd61d3 | |||
| 95ec0c42f6 | |||
| 2490236af3 | |||
| 4fb2f7745e | |||
| 964ef4425b | |||
| 5926e541a7 | |||
| e15b0bf785 | |||
| 5267391689 | |||
| 9bc0579b3b | |||
| b2392c5784 | |||
| 90a3fa9f4b | |||
| b48f40e61f | |||
| 69d8ee884e | |||
| ffe6969889 | |||
| 1884c2b8e9 | |||
| f23789fc22 | |||
| 4514fb86c7 | |||
| 4fdf72cca8 |
@@ -1 +1,2 @@
|
|||||||
lib/*
|
lib/*
|
||||||
|
pnpm-lock.yaml
|
||||||
130
lib/build.js
Normal file
130
lib/build.js
Normal file
@@ -0,0 +1,130 @@
|
|||||||
|
"use strict";
|
||||||
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||||
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||||
|
};
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
exports.default = runBuild;
|
||||||
|
const esbuild_1 = require("esbuild");
|
||||||
|
const readmeta_1 = __importDefault(require("./readmeta"));
|
||||||
|
const prettier_1 = require("prettier");
|
||||||
|
const main_1 = require("./main");
|
||||||
|
const promises_1 = require("fs/promises");
|
||||||
|
async function runBuild(name) {
|
||||||
|
//read meta file
|
||||||
|
const { meta, metaString } = (0, readmeta_1.default)(name);
|
||||||
|
const paths = main_1.AllPaths.script(name);
|
||||||
|
const result = await runEsbuild({
|
||||||
|
entryPoints: [paths.main],
|
||||||
|
outfile: paths.dist,
|
||||||
|
target: 'esnext',
|
||||||
|
platform: 'node',
|
||||||
|
format: 'esm',
|
||||||
|
bundle: true,
|
||||||
|
minify: main_1.CLIArgs.minify,
|
||||||
|
define: {
|
||||||
|
UserScriptName: `'${meta.name}'`,
|
||||||
|
UserScriptNamespace: `'${meta.namespace}'`,
|
||||||
|
UserScriptVersion: `'${meta.version}'`,
|
||||||
|
UserScriptDownloadURL: `'${meta.downloadURL}'`,
|
||||||
|
UserScriptSupportURL: `'${meta.supportURL}'`,
|
||||||
|
UserScriptHomepageURL: `'${meta.homepageURL}'`,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const error = await postBuild(name, result, metaString);
|
||||||
|
return {
|
||||||
|
meta,
|
||||||
|
error,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
async function runEsbuild(opts) {
|
||||||
|
opts.write = false;
|
||||||
|
try {
|
||||||
|
const res = await (0, esbuild_1.build)(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 = '';
|
||||||
|
if (result.outputFiles && result.outputFiles.length > 0) {
|
||||||
|
content = result.outputFiles[0].text;
|
||||||
|
if (!main_1.CLIArgs.srccomment)
|
||||||
|
content = clearFilenameComments(content);
|
||||||
|
}
|
||||||
|
if (content === '') {
|
||||||
|
return {
|
||||||
|
content: null,
|
||||||
|
error: 'No output',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
content,
|
||||||
|
error: null,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return {
|
||||||
|
content: null,
|
||||||
|
error: 'No result',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function clearFilenameComments(content) {
|
||||||
|
const regexp = new RegExp(`//\\s*${main_1.AllPaths.base.in}/.*(?:\\n|$)`, 'g');
|
||||||
|
return content.replace(regexp, '');
|
||||||
|
}
|
||||||
|
async function postBuild(name, result, metaString) {
|
||||||
|
let error = null;
|
||||||
|
const paths = main_1.AllPaths.script(name);
|
||||||
|
const PrettierConfig = (await (0, prettier_1.resolveConfig)(paths.dir)) ?? {};
|
||||||
|
if (result.error) {
|
||||||
|
console.error(name, result.errorRaw || result.error);
|
||||||
|
error = result.error;
|
||||||
|
}
|
||||||
|
else if (result.content) {
|
||||||
|
let content = metaString + result.content;
|
||||||
|
if (main_1.CLIArgs.prettier) {
|
||||||
|
content = await (0, prettier_1.format)(content, {
|
||||||
|
...PrettierConfig,
|
||||||
|
parser: 'babel',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
await (0, promises_1.writeFile)(paths.dist, content);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
console.error(name, 'No output');
|
||||||
|
}
|
||||||
|
await doErrorFile(name, error);
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
async function doErrorFile(name, error) {
|
||||||
|
const paths = main_1.AllPaths.script(name);
|
||||||
|
const content = `${new Date().toISOString()}\n\n${error}`;
|
||||||
|
if (error !== null) {
|
||||||
|
await (0, promises_1.writeFile)(paths.error, content);
|
||||||
|
if (await existsFile(paths.dist)) {
|
||||||
|
await (0, promises_1.unlink)(paths.dist);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (await existsFile(paths.error)) {
|
||||||
|
await (0, promises_1.unlink)(paths.error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function existsFile(path) {
|
||||||
|
return new Promise(resolve => {
|
||||||
|
(0, promises_1.stat)(path)
|
||||||
|
.then(() => resolve(true))
|
||||||
|
.catch(() => resolve(false));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
//# sourceMappingURL=build.js.map
|
||||||
1
lib/build.js.map
Normal file
1
lib/build.js.map
Normal file
@@ -0,0 +1 @@
|
|||||||
|
{"version":3,"file":"build.js","sourceRoot":"","sources":["../src/build.ts"],"names":[],"mappings":";;;;;AAYA,2BAiCC;AA7CD,qCAAwE;AAExE,0DAAiC;AACjC,uCAAgD;AAChD,iCAA0C;AAC1C,0CAAqD;AAOtC,KAAK,UAAU,QAAQ,CAAC,IAAY;IAC/C,gBAAgB;IAChB,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,GAAG,IAAA,kBAAQ,EAAC,IAAI,CAAC,CAAA;IAC3C,MAAM,KAAK,GAAG,eAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;IAEnC,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC;QAC5B,WAAW,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC;QACzB,OAAO,EAAE,KAAK,CAAC,IAAI;QAEnB,MAAM,EAAE,QAAQ;QAChB,QAAQ,EAAE,MAAM;QAChB,MAAM,EAAE,KAAK;QAEb,MAAM,EAAE,IAAI;QACZ,MAAM,EAAE,cAAO,CAAC,MAAM;QAEtB,MAAM,EAAE;YACJ,cAAc,EAAE,IAAI,IAAI,CAAC,IAAI,GAAG;YAChC,mBAAmB,EAAE,IAAI,IAAI,CAAC,SAAS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js
@@ -1,50 +1,185 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
"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 () {
|
||||||
|
var ownKeys = function(o) {
|
||||||
|
ownKeys = Object.getOwnPropertyNames || function (o) {
|
||||||
|
var ar = [];
|
||||||
|
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
||||||
|
return ar;
|
||||||
|
};
|
||||||
|
return ownKeys(o);
|
||||||
|
};
|
||||||
|
return function (mod) {
|
||||||
|
if (mod && mod.__esModule) return mod;
|
||||||
|
var result = {};
|
||||||
|
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
||||||
|
__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 });
|
||||||
const esbuild_1 = require("esbuild");
|
exports.AllPaths = exports.CLIArgs = void 0;
|
||||||
const fs_1 = require("fs");
|
const fs_1 = require("fs");
|
||||||
const paths_1 = require("./paths");
|
const command_line_args_1 = __importDefault(require("command-line-args"));
|
||||||
const readmeta_1 = __importDefault(require("./readmeta"));
|
const readmefile_1 = require("./readmefile");
|
||||||
async function compileProject(name) {
|
const build_1 = __importDefault(require("./build"));
|
||||||
//read meta file
|
const Path = __importStar(require("path"));
|
||||||
let [metaJson, metaString] = readmeta_1.default(name);
|
const paths_1 = __importDefault(require("./paths"));
|
||||||
let outPath = paths_1.DistPath(name);
|
exports.CLIArgs = (0, command_line_args_1.default)([
|
||||||
await esbuild_1.build({
|
{ name: 'watch', alias: 'w', type: Boolean, defaultValue: false },
|
||||||
entryPoints: [paths_1.ScriptPath(name).main],
|
{ name: 'minify', alias: 'm', type: Boolean, defaultValue: false },
|
||||||
outfile: outPath,
|
{ name: 'prettier', alias: 'p', type: Boolean, defaultValue: false },
|
||||||
target: 'esnext',
|
{ name: 'srccomment', alias: 'c', type: Boolean, defaultValue: false },
|
||||||
platform: 'node',
|
{ name: 'readme', alias: 'r', type: Boolean, defaultValue: false },
|
||||||
format: 'esm',
|
{ name: 'url', alias: 'u', type: String, defaultValue: '' },
|
||||||
bundle: true,
|
{ name: 'supporturl', alias: 's', type: String, defaultValue: '' },
|
||||||
minify: false,
|
{ name: 'homepageurl', alias: 'U', type: String, defaultValue: '' },
|
||||||
define: {
|
{ name: 'remotebranch', alias: 'b', type: String, defaultValue: '' },
|
||||||
UserScriptName: `'${metaJson.name}'`,
|
{ name: 'in', alias: 'i', type: String, defaultValue: 'scripts' },
|
||||||
UserScriptNamespace: `'${metaJson.namespace}'`,
|
{ name: 'out', alias: 'o', type: String, defaultValue: 'dist' },
|
||||||
UserScriptVersion: `'${metaJson.version}'`,
|
{ name: 'help', alias: 'h', type: Boolean },
|
||||||
UserScriptDownloadURL: `'${metaJson.downloadURL}'`,
|
]);
|
||||||
UserScriptSupportURL: `'${metaJson.supportURL}'`,
|
exports.AllPaths = (0, paths_1.default)({
|
||||||
UserScriptHomepageURL: `'${metaJson.homepageURL}'`,
|
baseUrl: exports.CLIArgs.url || '',
|
||||||
},
|
supportUrl: exports.CLIArgs.supporturl || '',
|
||||||
|
homepageUrl: exports.CLIArgs.homepageurl || '',
|
||||||
|
remoteBranch: exports.CLIArgs.remotebranch || '',
|
||||||
|
inBase: exports.CLIArgs.in || 'scripts',
|
||||||
|
outBase: exports.CLIArgs.out || 'dist',
|
||||||
});
|
});
|
||||||
//add UserScript header
|
if (exports.CLIArgs.help) {
|
||||||
let content = fs_1.readFileSync(outPath).toString();
|
let command = '<command>';
|
||||||
fs_1.writeFileSync(outPath, metaString + content);
|
if (process.argv.length > 0) {
|
||||||
|
command = Path.parse(process.argv[0]).name;
|
||||||
}
|
}
|
||||||
if (!fs_1.lstatSync('package.json').isFile()) {
|
if (command.toLowerCase() === 'node' && process.argv.length > 1) {
|
||||||
|
const path = Path.relative(process.cwd(), process.argv[1]) || '.';
|
||||||
|
command = `${command} ${path}`;
|
||||||
|
}
|
||||||
|
console.log(`
|
||||||
|
Usage: ${command} [options]
|
||||||
|
|
||||||
|
options:
|
||||||
|
--watch
|
||||||
|
alias: -w
|
||||||
|
default: false
|
||||||
|
automatically recompile on save
|
||||||
|
--minify
|
||||||
|
alias: -m
|
||||||
|
default: false
|
||||||
|
minify output files
|
||||||
|
--prettier
|
||||||
|
alias: -p
|
||||||
|
default: false
|
||||||
|
prettify output files
|
||||||
|
--srccomment
|
||||||
|
alias: -c
|
||||||
|
default: false
|
||||||
|
include src file path comments in the output files, i.e. // scripts/example/main.ts
|
||||||
|
--readme
|
||||||
|
alias: -r
|
||||||
|
default: false
|
||||||
|
update the readme.md file in your directory to include links to each userscript
|
||||||
|
|
||||||
|
--url <url>
|
||||||
|
alias: -u <url>
|
||||||
|
default: ""
|
||||||
|
the base for urls used in the meta comments for @downloadURL
|
||||||
|
--supporturl <url>
|
||||||
|
alias: -s <url>
|
||||||
|
default: ""
|
||||||
|
the support url used in the meta comments for @supportURL
|
||||||
|
--homepageurl <url>
|
||||||
|
alias: -U <url>
|
||||||
|
default: ""
|
||||||
|
the support url used in the meta comments for @homepageURL
|
||||||
|
--remotebranch <name>
|
||||||
|
alias: -b <name>
|
||||||
|
default: ""
|
||||||
|
if included, the included base url will be treated as a git repo, and the support url is not required
|
||||||
|
--in
|
||||||
|
alias: -i
|
||||||
|
default: "scripts"
|
||||||
|
include src file path comments in the output files, i.e. // scripts/example/main.ts
|
||||||
|
--out
|
||||||
|
alias: -o
|
||||||
|
default: "dist"
|
||||||
|
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 (!(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');
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
//delete compiled scripts
|
//delete compiled scripts or create output folder if it doesnt exist
|
||||||
fs_1.readdirSync(paths_1.DistBase).forEach(file => fs_1.unlinkSync(`${paths_1.DistBase}/${file}`));
|
if (!(0, fs_1.existsSync)(exports.AllPaths.base.out)) {
|
||||||
//compile scripts
|
(0, fs_1.mkdirSync)(exports.AllPaths.base.out);
|
||||||
fs_1.readdirSync(paths_1.ScriptBase).forEach(name => {
|
|
||||||
let path = paths_1.ScriptPath(name);
|
|
||||||
if (!name.endsWith('_') &&
|
|
||||||
fs_1.lstatSync(path.dir).isDirectory() &&
|
|
||||||
fs_1.lstatSync(path.main).isFile()) {
|
|
||||||
compileProject(name);
|
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
(0, fs_1.readdirSync)(exports.AllPaths.base.out).forEach(file => (0, fs_1.unlinkSync)(`${exports.AllPaths.base.out}/${file}`));
|
||||||
|
}
|
||||||
|
//compile scripts
|
||||||
|
async function doCompile() {
|
||||||
|
const scripts = (0, fs_1.readdirSync)(exports.AllPaths.base.in);
|
||||||
|
const scriptMeta = [];
|
||||||
|
for (const name of scripts) {
|
||||||
|
const path = exports.AllPaths.script(name);
|
||||||
|
if (!name.endsWith('_') &&
|
||||||
|
(0, fs_1.existsSync)(path.dir) &&
|
||||||
|
(0, fs_1.lstatSync)(path.dir).isDirectory() &&
|
||||||
|
(0, fs_1.existsSync)(path.main) &&
|
||||||
|
(0, fs_1.lstatSync)(path.main).isFile()) {
|
||||||
|
const id = scriptMeta.length;
|
||||||
|
scriptMeta[id] = await (0, build_1.default)(name);
|
||||||
|
console.log(name, scriptMeta[id].meta.version);
|
||||||
|
var running = false;
|
||||||
|
async function update(eventName) {
|
||||||
|
if (running) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
running = true;
|
||||||
|
scriptMeta[id] = await (0, build_1.default)(name);
|
||||||
|
console.log(`WATCH ${eventName}`, name, scriptMeta[id].meta.version);
|
||||||
|
if (exports.CLIArgs.readme)
|
||||||
|
(0, readmefile_1.updateReadmeFile)(scriptMeta);
|
||||||
|
running = false;
|
||||||
|
}
|
||||||
|
if (exports.CLIArgs.watch) {
|
||||||
|
const chokidar = await import('chokidar');
|
||||||
|
chokidar.watch(path.dir).on('all', update);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return scriptMeta;
|
||||||
|
}
|
||||||
|
doCompile().then(scriptMeta => {
|
||||||
|
if (exports.CLIArgs.readme)
|
||||||
|
(0, readmefile_1.updateReadmeFile)(scriptMeta);
|
||||||
|
console.log(`\nFinished Compiling\n${exports.CLIArgs.watch ? 'Listening for Changes\n' : ''}`);
|
||||||
});
|
});
|
||||||
//# sourceMappingURL=main.js.map
|
//# sourceMappingUR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C,OAAO,CAAC,GAAG,CACP,SAAS,SAAS,EAAE,EACpB,IAAI,EACJ,UAAU,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,OAAO,CAC9B,CAAA;gBAED,IAAI,eAAO,CAAC,MAAM;oBAAE,IAAA,6BAAgB,EAAC,UAAU,CAAC,CAAA;gBAChD,OAAO,GAAG,KAAK,CAAA;YACnB,CAAC;YAED,IAAI,eAAO,CAAC,KAAK,EAAE,CAAC;gBAChB,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,UAAU,CAAC,CAAA;gBACzC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC,CAAA;YAC9C,CAAC;QACL,CAAC;IACL,CAAC;IACD,OAAO,UAAU,CAAA;AACrB,CAAC;AAED,SAAS,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE;IAC1B,IAAI,eAAO,CAAC,MAAM;QAAE,IAAA,6BAAgB,EAAC,UAAU,CAAC,CAAA;IAEhD,OAAO,CAAC,GAAG,CACP,yBACI,eAAO,CAAC,KAAK,CAAC,CAAC,CAAC,yBAAyB,CAAC,CAAC,CAAC,EAChD,EAAE,CACL,CAAA;AACL,CAAC,CAAC,CAAA"}
|
||||||
48
lib/paths.js
48
lib/paths.js
@@ -1,19 +1,35 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
exports.DistPath = exports.ScriptPath = exports.FileUrl = exports.SupportUrl = exports.DistBase = exports.ScriptBase = exports.RemoteBranch = exports.BaseUrl = void 0;
|
exports.default = getAllPaths;
|
||||||
exports.BaseUrl = `https://git.zomo.dev/zomo/browser-scripts`;
|
function getAllPaths({ baseUrl, supportUrl, homepageUrl, remoteBranch, inBase, outBase, }) {
|
||||||
exports.RemoteBranch = 'main';
|
// generate links for remote git server
|
||||||
exports.ScriptBase = 'scripts';
|
if (baseUrl != '' && remoteBranch != '') {
|
||||||
exports.DistBase = 'dist';
|
if (supportUrl == '') {
|
||||||
exports.SupportUrl = `${exports.BaseUrl}/issues`;
|
supportUrl = `${baseUrl}/issues`;
|
||||||
const FileUrl = (name) => `${exports.BaseUrl}/raw/branch/${exports.RemoteBranch}/${exports.DistBase}/${name}.user.js`;
|
}
|
||||||
exports.FileUrl = FileUrl;
|
if (homepageUrl == '') {
|
||||||
const ScriptPath = (name) => ({
|
homepageUrl = baseUrl;
|
||||||
dir: `${exports.ScriptBase}/${name}`,
|
}
|
||||||
main: `${exports.ScriptBase}/${name}/main.ts`,
|
baseUrl = `${baseUrl}/raw/branch/${remoteBranch}/${outBase}`;
|
||||||
meta: `${exports.ScriptBase}/${name}/meta.json`,
|
}
|
||||||
});
|
return {
|
||||||
exports.ScriptPath = ScriptPath;
|
base: {
|
||||||
const DistPath = (name) => `${exports.DistBase}/${name}.user.js`;
|
in: inBase,
|
||||||
exports.DistPath = DistPath;
|
out: outBase,
|
||||||
|
},
|
||||||
|
url: {
|
||||||
|
home: homepageUrl,
|
||||||
|
base: baseUrl,
|
||||||
|
support: supportUrl,
|
||||||
|
},
|
||||||
|
script: (name) => ({
|
||||||
|
dir: `${inBase}/${name}`,
|
||||||
|
main: `${inBase}/${name}/main.ts`,
|
||||||
|
meta: `${inBase}/${name}/meta.json`,
|
||||||
|
error: `${inBase}/${name}/error.log`,
|
||||||
|
dist: `${outBase}/${name}.user.js`,
|
||||||
|
url: `${baseUrl}/${name}.user.js`,
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
}
|
||||||
//# sourceMappingURL=paths.js.map
|
//# sourceMappingURL=paths.js.map
|
||||||
@@ -1 +1 @@
|
|||||||
{"version":3,"file":"paths.js","sourceRoot":"","sources":["../src/paths.ts"],"names":[],"mappings":";;;AAAa,QAAA,OAAO,GAAG,2CAA2C,CAAA;AACrD,QAAA,YAAY,GAAG,MAAM,CAAA;AACrB,QAAA,UAAU,GAAG,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,IAAI,EAAE,WAAW;YACjB,IAAI,EAAE,OAAO;YACb,OAAO,EAAE,UAAU;SACtB;QACD,MAAM,EAAE,CAAC,IAAY,EAAe,EAAE,CAAC,CAAC;YACpC,GAAG,EAAE,GAAG,MAAM,IAAI,IAAI,EAAE;YACxB,IAAI,EAAE,GAAG,MAAM,IAAI,IAAI,UAAU;YACjC,IAAI,EAAE,GAAG,MAAM,IAAI,IAAI,YAAY;YACnC,KAAK,EAAE,GAAG,MAAM,IAAI,IAAI,YAAY;YACpC,IAAI,EAAE,GAAG,OAAO,IAAI,IAAI,UAAU;YAClC,GAAG,EAAE,GAAG,OAAO,IAAI,IAAI,UAAU;SACpC,CAAC;KACL,CAAA;AACL,CAAC"}
|
||||||
90
lib/readmefile.js
Normal file
90
lib/readmefile.js
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
exports.updateReadmeFile = updateReadmeFile;
|
||||||
|
const fs_1 = require("fs");
|
||||||
|
function updateReadmeFile(fileList) {
|
||||||
|
const readmeFile = getReadmeFileName();
|
||||||
|
if (readmeFile !== null) {
|
||||||
|
const [readmeStart, readmeEnd] = readReadmeFile(readmeFile);
|
||||||
|
const installLinks = fileList.map(readmeDataToString).join('\n');
|
||||||
|
const installLinksAll = `<!-- START INSTALL LINKS -->
|
||||||
|
## Installs
|
||||||
|
|
||||||
|
${installLinks}
|
||||||
|
<!-- END INSTALL LINKS -->`;
|
||||||
|
const content = readmeStart + installLinksAll + readmeEnd;
|
||||||
|
(0, fs_1.writeFileSync)(readmeFile, content);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function readmeDataErrorString(error) {
|
||||||
|
if (error === null)
|
||||||
|
return '';
|
||||||
|
error = error
|
||||||
|
.split('\n')
|
||||||
|
.map(line => ` ${line}`)
|
||||||
|
.join('\n');
|
||||||
|
return `\n\n${error}`;
|
||||||
|
}
|
||||||
|
function arrayify(val) {
|
||||||
|
const newval = Array.isArray(val) ? val : [val];
|
||||||
|
return newval.map(v => v.trim()).filter(v => v);
|
||||||
|
}
|
||||||
|
function readmeDataMatches(meta) {
|
||||||
|
const matches = arrayify(meta.match).map(v => '`' + v + '`');
|
||||||
|
const matchesStr = `
|
||||||
|
- ${matches.join(',')}`;
|
||||||
|
if (matches.length === 0) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
const excludes = arrayify(meta.excludematch).map(v => '`' + v + '`');
|
||||||
|
const excludesStr = `
|
||||||
|
- excluding: ${excludes.join(',')}`;
|
||||||
|
if (excludes.length === 0) {
|
||||||
|
return matchesStr;
|
||||||
|
}
|
||||||
|
return matchesStr + excludesStr;
|
||||||
|
}
|
||||||
|
function readmeDataToString(results) {
|
||||||
|
const { meta, error } = results;
|
||||||
|
const errStr = error !== null ? '~~' : '';
|
||||||
|
const errMsg = readmeDataErrorString(error);
|
||||||
|
const matchesStr = readmeDataMatches(meta);
|
||||||
|
return `
|
||||||
|
- ${errStr}[${meta.name}](${meta.downloadURL})${errStr}${errMsg}
|
||||||
|
- **${meta.namespace}** v${meta.version}${matchesStr}
|
||||||
|
- ${meta.description}
|
||||||
|
`.trim();
|
||||||
|
}
|
||||||
|
function getReadmeFileName() {
|
||||||
|
const files = (0, fs_1.readdirSync)('.');
|
||||||
|
for (const name of files) {
|
||||||
|
if (/^readme\.md$/i.test(name)) {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
function readReadmeFile(readmeFile) {
|
||||||
|
const content = (0, fs_1.readFileSync)(readmeFile).toString();
|
||||||
|
const regex = /<!-- START INSTALL LINKS -->(?:.|\n)*?<!-- END INSTALL LINKS -->/;
|
||||||
|
const index = regex.exec(content)?.index;
|
||||||
|
let contentPre = '', contentPost = '';
|
||||||
|
if (index === undefined) {
|
||||||
|
contentPre = content;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
const content_replace = content.replace(regex, '');
|
||||||
|
contentPre = content_replace.slice(0, index);
|
||||||
|
contentPost = content_replace.slice(index);
|
||||||
|
}
|
||||||
|
if (contentPre.trimEnd().length === 0)
|
||||||
|
contentPre = '';
|
||||||
|
else
|
||||||
|
contentPre = contentPre.trimEnd() + '\n\n';
|
||||||
|
if (contentPost.trimStart().length === 0)
|
||||||
|
contentPost = '\n';
|
||||||
|
else
|
||||||
|
contentPost = '\n\n' + contentPost.trimStart();
|
||||||
|
return [contentPre, contentPost];
|
||||||
|
}
|
||||||
|
//# sourceMappingURL=readmefile.js.map
|
||||||
1
lib/readmefile.js.map
Normal file
1
lib/readmefile.js.map
Normal file
@@ -0,0 +1 @@
|
|||||||
|
{"version":3,"file":"readmefile.js","sourceRoot":"","sources":["../src/readmefile.ts"],"names":[],"mappings":";;AAIA,4CAgBC;AApBD,2BAA6D;AAI7D,SAAgB,gBAAgB,CAAC,QAA0B;IACvD,MAAM,UAAU,GAAG,iBAAiB,EAAE,CAAA;IACtC,IAAI,UAAU,KAAK,IAAI,EAAE,CAAC;QACtB,MAAM,CAAC,WAAW,EAAE,SAAS,CAAC,GAAG,cAAc,CAAC,UAAU,CAAC,CAAA;QAE3D,MAAM,YAAY,GAAG,QAAQ,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAEhE,MAAM,eAAe,GAAG;;;EAG9B,YAAY;2BACa,CAAA;QAEnB,MAAM,OAAO,GAAG,WAAW,GAAG,eAAe,GAAG,SAAS,CAAA;QACzD,IAAA,kBAAa,EAAC,UAAU,EAAE,OAAO,CAAC,CAAA;IACtC,CAAC;AACL,CAAC;AAED,SAAS,qBAAqB,CAAC,KAAoB;IAC/C,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,EAAE,CAAA;IAC7B,KAAK,GAAG,KAAK;SACR,KAAK,CAAC,IAAI,CAAC;SACX,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,IAAI,EAAE,CAAC;SAC1B,IAAI,CAAC,IAAI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AAC,KAAK,CAAC,CAAA;IAC9C,CAAC;IAED,IAAI,UAAU,CAAC,OAAO,EAAE,CAAC,MAAM,KAAK,CAAC;QAAE,UAAU,GAAG,EAAE,CAAA;;QACjD,UAAU,GAAG,UAAU,CAAC,OAAO,EAAE,GAAG,MAAM,CAAA;IAE/C,IAAI,WAAW,CAAC,SAAS,EAAE,CAAC,MAAM,KAAK,CAAC;QAAE,WAAW,GAAG,IAAI,CAAA;;QACvD,WAAW,GAAG,MAAM,GAAG,WAAW,CAAC,SAAS,EAAE,CAAA;IAEnD,OAAO,CAAC,UAAU,EAAE,WAAW,CAAC,CAAA;AACpC,CAAC"}
|
||||||
@@ -1,8 +1,11 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
exports.default = readMeta;
|
||||||
const fs_1 = require("fs");
|
const fs_1 = require("fs");
|
||||||
const paths_1 = require("./paths");
|
const main_1 = require("./main");
|
||||||
function default_1(name) {
|
function readMeta(name) {
|
||||||
|
const paths = main_1.AllPaths.script(name);
|
||||||
|
const urls = main_1.AllPaths.url;
|
||||||
var meta = {
|
var meta = {
|
||||||
name: name,
|
name: name,
|
||||||
namespace: 'zomo.dev',
|
namespace: 'zomo.dev',
|
||||||
@@ -17,18 +20,18 @@ function default_1(name) {
|
|||||||
noframes: false,
|
noframes: false,
|
||||||
grant: '',
|
grant: '',
|
||||||
injectinto: '',
|
injectinto: '',
|
||||||
downloadURL: paths_1.FileUrl(name),
|
downloadURL: paths.url,
|
||||||
supportURL: paths_1.SupportUrl,
|
supportURL: urls.support,
|
||||||
homepageURL: paths_1.BaseUrl,
|
homepageURL: urls.home,
|
||||||
unwrap: false,
|
unwrap: false,
|
||||||
};
|
};
|
||||||
let metaPath = paths_1.ScriptPath(name).meta;
|
const metaPath = paths.meta;
|
||||||
if (fs_1.lstatSync(metaPath).isFile()) {
|
if ((0, fs_1.existsSync)(metaPath) && (0, fs_1.lstatSync)(metaPath).isFile()) {
|
||||||
try {
|
try {
|
||||||
let args = JSON.parse(fs_1.readFileSync(metaPath).toString());
|
const args = JSON.parse((0, fs_1.readFileSync)(metaPath).toString());
|
||||||
let key;
|
let key;
|
||||||
for (key in meta) {
|
for (key in meta) {
|
||||||
let val = args[key];
|
const val = args[key];
|
||||||
//cases where the value is empty
|
//cases where the value is empty
|
||||||
if (val === undefined)
|
if (val === undefined)
|
||||||
continue;
|
continue;
|
||||||
@@ -50,12 +53,12 @@ function default_1(name) {
|
|||||||
injectinto: 'inject-into',
|
injectinto: 'inject-into',
|
||||||
excludematch: 'exclude-match',
|
excludematch: 'exclude-match',
|
||||||
};
|
};
|
||||||
return [
|
return {
|
||||||
meta,
|
meta,
|
||||||
`// ==UserScript==
|
metaString: `// ==UserScript==
|
||||||
${Object.keys(meta)
|
${Object.keys(meta)
|
||||||
.filter(key => {
|
.filter(key => {
|
||||||
let val = meta[key];
|
const val = meta[key];
|
||||||
if (val === undefined)
|
if (val === undefined)
|
||||||
return false;
|
return false;
|
||||||
if (val === false)
|
if (val === false)
|
||||||
@@ -65,28 +68,40 @@ ${Object.keys(meta)
|
|||||||
return true;
|
return true;
|
||||||
})
|
})
|
||||||
.map(key => {
|
.map(key => {
|
||||||
let val = meta[key];
|
const val = meta[key];
|
||||||
let key_str = key in keyConversion
|
let key_str = key in keyConversion
|
||||||
? keyConversion[key]
|
? keyConversion[key]
|
||||||
: key;
|
: key;
|
||||||
key_str = key_str.padStart(12, ' ');
|
key_str = key_str.padEnd(12, ' ');
|
||||||
if (typeof val === 'boolean') {
|
if (typeof val === 'boolean') {
|
||||||
|
//bool
|
||||||
if (val)
|
if (val)
|
||||||
return `// @${key_str}`;
|
return `// @${key_str}`;
|
||||||
}
|
}
|
||||||
else if (typeof val === 'string') {
|
else if (typeof val === 'string') {
|
||||||
|
//string
|
||||||
return `// @${key_str} ${val}`;
|
return `// @${key_str} ${val}`;
|
||||||
}
|
}
|
||||||
else if (Array.isArray(val)) {
|
else if (Array.isArray(val)) {
|
||||||
|
//multiple
|
||||||
return val.map(v => `// @${key_str} ${v}`).join('\n');
|
return val.map(v => `// @${key_str} ${v}`).join('\n');
|
||||||
}
|
}
|
||||||
|
else if (typeof val === 'object') {
|
||||||
|
//multilingual
|
||||||
|
const langs = val;
|
||||||
|
return Object.keys(langs)
|
||||||
|
.map(lang => {
|
||||||
|
const langStr = lang === 'default' ? '' : `:${lang}`;
|
||||||
|
return `// @${key_str}${langStr} ${langs[lang]}`;
|
||||||
|
})
|
||||||
|
.join('\n');
|
||||||
|
}
|
||||||
return '';
|
return '';
|
||||||
})
|
})
|
||||||
.filter(l => l.length)
|
.filter(l => l.length)
|
||||||
.join('\n')}
|
.join('\n')}
|
||||||
// ==/UserScript==
|
// ==/UserScript==
|
||||||
`,
|
`,
|
||||||
];
|
};
|
||||||
}
|
}
|
||||||
exports.default = default_1;
|
|
||||||
//# sourceMappingURL=readmeta.js.map
|
//# sourceMappingURL=readmeta.js.map
|
||||||
@@ -1 +1 @@
|
|||||||
{"version":3,"file":"readmeta.js","sourceRoot":"","sources":["../src/readmeta.ts"],"names":[],"mappings":";;AAAA,2BAA4C;AAC5C,mCAAkE;AAGlE,mBAAyB,IAAY;IACjC,IAAI,IAAI,GAAqB;QACzB,IAAI,EAAE,IAAI;QACV,SAAS,EAAE,UAAU;QACrB,KAAK,EAAE,EAAE;QACT,YAAY,EAAE,EAAE;QAChB,OAAO,EAAE,OAAO;QAChB,WAAW,EAAE,EAAE;QACf,IAAI,EAAE,EAAE;QACR,OAAO,EAAE,EAAE;QACX,QAAQ,EAAE,EAAE;QACZ,KAAK,EAAE,EAAE;QACT,QAAQ,EAAE,KAAK;QACf,KAAK,EAAE,EAAE;QACT,UAAU,EAAE,EAAE;QACd,WAAW,EAAE,eAAO,CAAC,IAAI,CAAC;QAC1B,UAAU,EAAE,kBAAU;QACtB,WAAW,EAAE,eAAO;QACpB,MAAM,EAAE,KAAK;KAChB,CAAA;IA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A;gBACjB,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC;qBACpB,GAAG,CAAC,IAAI,CAAC,EAAE;oBACR,MAAM,OAAO,GAAG,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,IAAI,EAAE,CAAA;oBACpD,OAAO,OAAO,OAAO,GAAG,OAAO,IAAI,KAAK,CAAC,IAAI,CAAC,EAAE,CAAA;gBACpD,CAAC,CAAC;qBACD,IAAI,CAAC,IAAI,CAAC,CAAA;YACnB,CAAC;YAED,OAAO,EAAE,CAAA;QACb,CAAC,CAAC;aACD,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC;aACrB,IAAI,CAAC,IAAI,CAAC;;CAEd;KACI,CAAA;AACL,CAAC"}
|
||||||
@@ -1,103 +1,123 @@
|
|||||||
{
|
{
|
||||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
"$schema": "http://json-schema.org/draft-04/schema",
|
||||||
|
"$id": "https://git.zomo.dev/zomo/browser-scripts-builder/raw/branch/main/meta.schema.json",
|
||||||
"title": "UserScriptMeta",
|
"title": "UserScriptMeta",
|
||||||
|
"description": "UserScript metadata fields, from https://violentmonkey.github.io/api/metadata-block/",
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
|
"$schema": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "Read https://violentmonkey.github.io/api/metadata-block/ for more examples and information about metadata"
|
||||||
|
},
|
||||||
"name": {
|
"name": {
|
||||||
"description": "Script Name",
|
"description": "The name of the script, shown in script list and menus",
|
||||||
|
"type": ["string", "object"],
|
||||||
|
"properties": {
|
||||||
|
"default": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"additionalProperties": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
|
"required": ["default"]
|
||||||
|
},
|
||||||
"namespace": {
|
"namespace": {
|
||||||
"description": "Author namespace",
|
"description": "The combination of namespace and name is the unique identifier for a userscript",
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
"match": {
|
"match": {
|
||||||
"description": "",
|
"description": "Define rules to decide whether a script should be executed",
|
||||||
"type": ["string", "array"],
|
"type": ["string", "array"],
|
||||||
"minItems": 1,
|
|
||||||
"uniqueItems": true,
|
"uniqueItems": true,
|
||||||
"items": {
|
"items": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"excludematch": {
|
"excludematch": {
|
||||||
"description": "",
|
"description": "Define rules to decide whether a script should be executed",
|
||||||
"type": ["string", "array"],
|
"type": ["string", "array"],
|
||||||
"minItems": 1,
|
|
||||||
"uniqueItems": true,
|
"uniqueItems": true,
|
||||||
"items": {
|
"items": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"version": {
|
"version": {
|
||||||
"description": "",
|
"description": "Version of the script, it can be used to check if a script has new versions",
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
"description": {
|
"description": {
|
||||||
"description": "",
|
"description": "A brief summary to describe the script",
|
||||||
|
"type": ["string", "object"],
|
||||||
|
"properties": {
|
||||||
|
"default": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"additionalProperties": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
|
"required": ["default"]
|
||||||
|
},
|
||||||
"icon": {
|
"icon": {
|
||||||
"description": "",
|
"description": "Specify an icon for the script",
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
"description": "",
|
"description": "Require another script to execute before the current one\n\nThe value is the URL to the required script, which may be relative to the URL the script is being installed from",
|
||||||
"type": ["string", "array"],
|
"type": ["string", "array"],
|
||||||
"minItems": 1,
|
|
||||||
"uniqueItems": true,
|
"uniqueItems": true,
|
||||||
"items": {
|
"items": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"resource": {
|
"resource": {
|
||||||
"description": "",
|
"description": "Static resources that can be accessed in the script by GM_getResourceText and GM_getResourceURL\n\nThe value is composed of two parts, joined with one or more white spaces\n\nThe first part is the name of the resource, no white space is allowed in it\n\nThe second part is the URL to the resource, which may be relative to the URL the script is being installed from",
|
||||||
"type": ["string", "array"],
|
"type": ["string", "array"],
|
||||||
"minItems": 1,
|
|
||||||
"uniqueItems": true,
|
"uniqueItems": true,
|
||||||
"items": {
|
"items": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"runat": {
|
"runat": {
|
||||||
"description": "",
|
"description": "Decide when the script will execute\n\ndocument-end: (default) The script executes when DOMContentLoaded is fired\n\ndocument-start: The script executes as soon as possible\n\ndocument-idle: The script executes after DOMContentLoaded is fired, ensuring other resources like images are loaded",
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"enum": ["document-start", "document-end", "document-idle"]
|
"enum": ["document-end", "document-idle", "document-start"]
|
||||||
},
|
},
|
||||||
"noframes": {
|
"noframes": {
|
||||||
"description": "",
|
"description": "When present, the script will execute only in top level document, but not in nested frames",
|
||||||
"type": "boolean"
|
"type": "boolean"
|
||||||
},
|
},
|
||||||
"grant": {
|
"grant": {
|
||||||
"description": "",
|
"description": "Specify which special APIs should be granted and can be used when the script executes\n\nIf nothing is present, \"none\" is assumed\n\nAny GM_ or GM. function used, including window.close and window.focus",
|
||||||
"type": ["string", "array"],
|
"type": ["string", "array"],
|
||||||
"minItems": 1,
|
|
||||||
"uniqueItems": true,
|
"uniqueItems": true,
|
||||||
"items": {
|
"items": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"injectinto": {
|
"injectinto": {
|
||||||
"description": "",
|
"description": "Decide which context the script will be injected into\n\npage: Inject into context of the web page\nIn this mode, unsafeWindow refers to the window object, allowing the script to access JavaScript objects of the web page, just like normal page scripts can\n\ncontent: Inject into context of content scripts.\nIn this mode, unsafeWindow refers to the global object in content script. As a result, the script can access and modify the page's DOM, but cannot access JavaScript objects of the web page.\n\nauto: Try to inject into context of the web page. If blocked by CSP rules, inject as a content script.",
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"enum": ["page", "content", "auto"]
|
"enum": ["page", "content", "auto"]
|
||||||
},
|
},
|
||||||
"downloadURL": {
|
"downloadURL": {
|
||||||
"description": "",
|
"description": "The URL the script can be downloaded from",
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
"supportURL": {
|
"supportURL": {
|
||||||
"description": "",
|
"description": "If supplied, the question mark icon in the user scripts list will link to this.",
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
"homepageURL": {
|
"homepageURL": {
|
||||||
"description": "",
|
"description": "If supplied, the home icon in the user scripts list will link to this.",
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
"unwrap": {
|
"unwrap": {
|
||||||
"description": "",
|
"description": "If supplied, the script will be injected as is into the global scope of the page, i.e. without our standard wrapper like window.VMxxx=function(){...}.\n\nThe @grant key is ignored so the script won't have access to GM.* or GM_* API. ",
|
||||||
"type": "boolean"
|
"type": "boolean"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"additionalProperties": false,
|
||||||
"required": ["name", "namespace", "version"]
|
"required": ["name", "namespace", "version"]
|
||||||
}
|
}
|
||||||
|
|||||||
20
package.json
20
package.json
@@ -1,15 +1,15 @@
|
|||||||
{
|
{
|
||||||
"name": "browser-scripts-builder",
|
"name": "browser-scripts-builder",
|
||||||
"version": "1.0.0",
|
"version": "1.1.7",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "./lib/main.mjs",
|
"main": "./lib/main.js",
|
||||||
"module": "./lib/main.mjs",
|
"module": "./lib/main.js",
|
||||||
"bin": {
|
"bin": {
|
||||||
"bsbuild": "./lib/main.js"
|
"bsbuild": "./lib/main.js"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"prettier": "prettier --write .",
|
"prettier": "prettier --write .",
|
||||||
"build": "npm run prettier && tsc",
|
"build": "npm run prettier && tsc && node -e \"(async () => { const p = 'lib/main.js'; await fs.promises.writeFile(p, '#!/usr/bin/env node\\n' + await fs.promises.readFile(p)); await fs.promises.chmod(p, 754); })()\"",
|
||||||
"test": "node ./test/test.mjs"
|
"test": "node ./test/test.mjs"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
@@ -19,11 +19,15 @@
|
|||||||
"author": "",
|
"author": "",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"esbuild": "^0.14.42"
|
"chokidar": "^5.0.0",
|
||||||
|
"command-line-args": "^6.0.1",
|
||||||
|
"esbuild": "^0.27.1",
|
||||||
|
"prettier": "^3.7.4"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "^17.0.40",
|
"@types/command-line-args": "^5.2.3",
|
||||||
"eslint": "^8.17.0",
|
"@types/node": "^25.0.0",
|
||||||
"prettier": "^2.6.2"
|
"eslint": "^9.39.1",
|
||||||
|
"typescript": "^5.9.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
1827
pnpm-lock.yaml
generated
1827
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
66
readme.md
66
readme.md
@@ -4,6 +4,8 @@ builder for [browser-scripts](https://git.zomo.dev/zomo/browser-scripts)
|
|||||||
|
|
||||||
## Source File Structure
|
## Source File Structure
|
||||||
|
|
||||||
|
note: if `package.json` is not present, running the command is presumed to be a mistake and will refuse to run
|
||||||
|
|
||||||
```text
|
```text
|
||||||
Root
|
Root
|
||||||
├───<package.json/etc>
|
├───<package.json/etc>
|
||||||
@@ -23,3 +25,67 @@ Root
|
|||||||
└───dist
|
└───dist
|
||||||
└───[each script folder].user.js
|
└───[each script folder].user.js
|
||||||
```
|
```
|
||||||
|
|
||||||
|
if there is an error compiling a file, an `error.log` will be placed inside the source folder:
|
||||||
|
|
||||||
|
```text
|
||||||
|
Root
|
||||||
|
├───<package.json/etc>
|
||||||
|
└───scripts
|
||||||
|
└───[each script folder]
|
||||||
|
└───error.log
|
||||||
|
```
|
||||||
|
|
||||||
|
## Command Line Options
|
||||||
|
|
||||||
|
```text
|
||||||
|
--watch
|
||||||
|
alias: -w
|
||||||
|
default: false
|
||||||
|
automatically recompile on save
|
||||||
|
--minify
|
||||||
|
alias: -m
|
||||||
|
default: false
|
||||||
|
minify output files
|
||||||
|
--prettier
|
||||||
|
alias: -p
|
||||||
|
default: false
|
||||||
|
prettify output files
|
||||||
|
--srccomment
|
||||||
|
alias: -c
|
||||||
|
default: false
|
||||||
|
include src file path comments in the output files, i.e. // scripts/example/main.ts
|
||||||
|
--readme
|
||||||
|
alias: -r
|
||||||
|
default: false
|
||||||
|
update the readme.md file in your directory to include links to each userscript
|
||||||
|
|
||||||
|
--url <url>
|
||||||
|
alias: -u <url>
|
||||||
|
default: ""
|
||||||
|
the base for urls used in the meta comments for @downloadURL
|
||||||
|
--supporturl <url>
|
||||||
|
alias: -s <url>
|
||||||
|
default: ""
|
||||||
|
the support url used in the meta comments for @supportURL
|
||||||
|
--homepageurl <url>
|
||||||
|
alias: -U <url>
|
||||||
|
default: ""
|
||||||
|
the support url used in the meta comments for @homepageURL
|
||||||
|
--remotebranch <name>
|
||||||
|
alias: -b <name>
|
||||||
|
default: ""
|
||||||
|
if included, the included base url will be treated as a git repo, and the support url is not required
|
||||||
|
--in
|
||||||
|
alias: -i
|
||||||
|
default: "scripts"
|
||||||
|
include src file path comments in the output files, i.e. // scripts/example/main.ts
|
||||||
|
--out
|
||||||
|
alias: -o
|
||||||
|
default: "dist"
|
||||||
|
include src file path comments in the output files, i.e. // scripts/example/main.ts
|
||||||
|
|
||||||
|
--help
|
||||||
|
alias: -h
|
||||||
|
show this help message
|
||||||
|
```
|
||||||
|
|||||||
153
src/build.ts
Normal file
153
src/build.ts
Normal file
@@ -0,0 +1,153 @@
|
|||||||
|
import { BuildFailure, BuildOptions, BuildResult, build } from 'esbuild'
|
||||||
|
import { UserScriptMetaFull } from './types'
|
||||||
|
import readMeta from './readmeta'
|
||||||
|
import { format, resolveConfig } from 'prettier'
|
||||||
|
import { AllPaths, CLIArgs } from './main'
|
||||||
|
import { writeFile, stat, unlink } from 'fs/promises'
|
||||||
|
|
||||||
|
export interface runBuildResult {
|
||||||
|
meta: UserScriptMetaFull
|
||||||
|
error: string | null
|
||||||
|
}
|
||||||
|
|
||||||
|
export default async function runBuild(name: string) {
|
||||||
|
//read meta file
|
||||||
|
const { meta, metaString } = readMeta(name)
|
||||||
|
const paths = AllPaths.script(name)
|
||||||
|
|
||||||
|
const result = await runEsbuild({
|
||||||
|
entryPoints: [paths.main],
|
||||||
|
outfile: paths.dist,
|
||||||
|
|
||||||
|
target: 'esnext',
|
||||||
|
platform: 'node',
|
||||||
|
format: 'esm',
|
||||||
|
|
||||||
|
bundle: true,
|
||||||
|
minify: CLIArgs.minify,
|
||||||
|
|
||||||
|
define: {
|
||||||
|
UserScriptName: `'${meta.name}'`,
|
||||||
|
UserScriptNamespace: `'${meta.namespace}'`,
|
||||||
|
UserScriptVersion: `'${meta.version}'`,
|
||||||
|
|
||||||
|
UserScriptDownloadURL: `'${meta.downloadURL}'`,
|
||||||
|
UserScriptSupportURL: `'${meta.supportURL}'`,
|
||||||
|
UserScriptHomepageURL: `'${meta.homepageURL}'`,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const error = await postBuild(name, result, metaString)
|
||||||
|
|
||||||
|
return {
|
||||||
|
meta,
|
||||||
|
error,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
interface RunEsbuildResult {
|
||||||
|
content: string | null
|
||||||
|
error: string | null
|
||||||
|
errorRaw?: BuildFailure
|
||||||
|
}
|
||||||
|
|
||||||
|
async function runEsbuild(opts: BuildOptions): Promise<RunEsbuildResult> {
|
||||||
|
opts.write = false
|
||||||
|
|
||||||
|
try {
|
||||||
|
const res = await build(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 = ''
|
||||||
|
if (result.outputFiles && result.outputFiles.length > 0) {
|
||||||
|
content = result.outputFiles[0].text
|
||||||
|
if (!CLIArgs.srccomment) content = clearFilenameComments(content)
|
||||||
|
}
|
||||||
|
if (content === '') {
|
||||||
|
return {
|
||||||
|
content: null,
|
||||||
|
error: 'No output',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
content,
|
||||||
|
error: null,
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
content: null,
|
||||||
|
error: 'No result',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function clearFilenameComments(content: string): string {
|
||||||
|
const regexp = new RegExp(`//\\s*${AllPaths.base.in}/.*(?:\\n|$)`, 'g')
|
||||||
|
return content.replace(regexp, '')
|
||||||
|
}
|
||||||
|
|
||||||
|
async function postBuild(
|
||||||
|
name: string,
|
||||||
|
result: RunEsbuildResult,
|
||||||
|
metaString: string
|
||||||
|
) {
|
||||||
|
let error: string | null = null
|
||||||
|
const paths = AllPaths.script(name)
|
||||||
|
|
||||||
|
const PrettierConfig = (await resolveConfig(paths.dir)) ?? {}
|
||||||
|
|
||||||
|
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 = await format(content, {
|
||||||
|
...PrettierConfig,
|
||||||
|
parser: 'babel',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
await writeFile(paths.dist, content)
|
||||||
|
} else {
|
||||||
|
console.error(name, 'No output')
|
||||||
|
}
|
||||||
|
|
||||||
|
await doErrorFile(name, error)
|
||||||
|
|
||||||
|
return error
|
||||||
|
}
|
||||||
|
|
||||||
|
async function doErrorFile(name: string, error: string | null) {
|
||||||
|
const paths = AllPaths.script(name)
|
||||||
|
|
||||||
|
const content = `${new Date().toISOString()}\n\n${error}`
|
||||||
|
|
||||||
|
if (error !== null) {
|
||||||
|
await writeFile(paths.error, content)
|
||||||
|
if (await existsFile(paths.dist)) {
|
||||||
|
await unlink(paths.dist)
|
||||||
|
}
|
||||||
|
} else if (await existsFile(paths.error)) {
|
||||||
|
await unlink(paths.error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function existsFile(path: string): Promise<boolean> {
|
||||||
|
return new Promise(resolve => {
|
||||||
|
stat(path)
|
||||||
|
.then(() => resolve(true))
|
||||||
|
.catch(() => resolve(false))
|
||||||
|
})
|
||||||
|
}
|
||||||
214
src/main.ts
214
src/main.ts
@@ -1,64 +1,190 @@
|
|||||||
import { build } from 'esbuild'
|
import { existsSync, lstatSync, mkdirSync, readdirSync, unlinkSync } from 'fs'
|
||||||
import {
|
import commandLineArgs from 'command-line-args'
|
||||||
lstatSync,
|
import { updateReadmeFile } from './readmefile'
|
||||||
readdirSync,
|
import runBuild, { runBuildResult } from './build'
|
||||||
readFileSync,
|
import * as Path from 'path'
|
||||||
unlinkSync,
|
import getAllPaths from './paths'
|
||||||
writeFileSync,
|
|
||||||
} from 'fs'
|
|
||||||
import { DistBase, DistPath, ScriptBase, ScriptPath } from './paths'
|
|
||||||
import readMeta from './readmeta'
|
|
||||||
|
|
||||||
async function compileProject(name: string) {
|
export interface CLIArgsT {
|
||||||
//read meta file
|
watch: boolean
|
||||||
let [metaJson, metaString] = readMeta(name)
|
minify: boolean
|
||||||
let outPath = DistPath(name)
|
prettier: boolean
|
||||||
|
srccomment: boolean
|
||||||
|
readme: boolean
|
||||||
|
|
||||||
await build({
|
url?: string
|
||||||
entryPoints: [ScriptPath(name).main],
|
supporturl?: string
|
||||||
outfile: outPath,
|
homepageurl?: string
|
||||||
|
remotebranch?: string
|
||||||
|
in?: string
|
||||||
|
out?: string
|
||||||
|
|
||||||
target: 'esnext',
|
help?: boolean
|
||||||
platform: 'node',
|
|
||||||
format: 'esm',
|
|
||||||
|
|
||||||
bundle: true,
|
src?: string
|
||||||
minify: false,
|
|
||||||
|
|
||||||
define: {
|
|
||||||
UserScriptName: `'${metaJson.name}'`,
|
|
||||||
UserScriptNamespace: `'${metaJson.namespace}'`,
|
|
||||||
UserScriptVersion: `'${metaJson.version}'`,
|
|
||||||
|
|
||||||
UserScriptDownloadURL: `'${metaJson.downloadURL}'`,
|
|
||||||
UserScriptSupportURL: `'${metaJson.supportURL}'`,
|
|
||||||
UserScriptHomepageURL: `'${metaJson.homepageURL}'`,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
//add UserScript header
|
|
||||||
let content = readFileSync(outPath).toString()
|
|
||||||
|
|
||||||
writeFileSync(outPath, metaString + content)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!lstatSync('package.json').isFile()) {
|
export const CLIArgs = commandLineArgs([
|
||||||
|
{ name: 'watch', alias: 'w', type: Boolean, defaultValue: false },
|
||||||
|
{ name: 'minify', alias: 'm', type: Boolean, defaultValue: false },
|
||||||
|
{ name: 'prettier', alias: 'p', type: Boolean, defaultValue: false },
|
||||||
|
{ name: 'srccomment', alias: 'c', type: Boolean, defaultValue: false },
|
||||||
|
{ name: 'readme', alias: 'r', type: Boolean, defaultValue: false },
|
||||||
|
|
||||||
|
{ name: 'url', alias: 'u', type: String, defaultValue: '' },
|
||||||
|
{ name: 'supporturl', alias: 's', type: String, defaultValue: '' },
|
||||||
|
{ name: 'homepageurl', alias: 'U', type: String, defaultValue: '' },
|
||||||
|
{ name: 'remotebranch', alias: 'b', type: String, defaultValue: '' },
|
||||||
|
{ name: 'in', alias: 'i', type: String, defaultValue: 'scripts' },
|
||||||
|
{ name: 'out', alias: 'o', type: String, defaultValue: 'dist' },
|
||||||
|
|
||||||
|
{ name: 'help', alias: 'h', type: Boolean },
|
||||||
|
]) as CLIArgsT
|
||||||
|
|
||||||
|
export const AllPaths = getAllPaths({
|
||||||
|
baseUrl: CLIArgs.url || '',
|
||||||
|
supportUrl: CLIArgs.supporturl || '',
|
||||||
|
homepageUrl: CLIArgs.homepageurl || '',
|
||||||
|
remoteBranch: CLIArgs.remotebranch || '',
|
||||||
|
inBase: CLIArgs.in || 'scripts',
|
||||||
|
outBase: CLIArgs.out || 'dist',
|
||||||
|
})
|
||||||
|
|
||||||
|
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) {
|
||||||
|
const path = Path.relative(process.cwd(), process.argv[1]) || '.'
|
||||||
|
command = `${command} ${path}`
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(`
|
||||||
|
Usage: ${command} [options]
|
||||||
|
|
||||||
|
options:
|
||||||
|
--watch
|
||||||
|
alias: -w
|
||||||
|
default: false
|
||||||
|
automatically recompile on save
|
||||||
|
--minify
|
||||||
|
alias: -m
|
||||||
|
default: false
|
||||||
|
minify output files
|
||||||
|
--prettier
|
||||||
|
alias: -p
|
||||||
|
default: false
|
||||||
|
prettify output files
|
||||||
|
--srccomment
|
||||||
|
alias: -c
|
||||||
|
default: false
|
||||||
|
include src file path comments in the output files, i.e. // scripts/example/main.ts
|
||||||
|
--readme
|
||||||
|
alias: -r
|
||||||
|
default: false
|
||||||
|
update the readme.md file in your directory to include links to each userscript
|
||||||
|
|
||||||
|
--url <url>
|
||||||
|
alias: -u <url>
|
||||||
|
default: ""
|
||||||
|
the base for urls used in the meta comments for @downloadURL
|
||||||
|
--supporturl <url>
|
||||||
|
alias: -s <url>
|
||||||
|
default: ""
|
||||||
|
the support url used in the meta comments for @supportURL
|
||||||
|
--homepageurl <url>
|
||||||
|
alias: -U <url>
|
||||||
|
default: ""
|
||||||
|
the support url used in the meta comments for @homepageURL
|
||||||
|
--remotebranch <name>
|
||||||
|
alias: -b <name>
|
||||||
|
default: ""
|
||||||
|
if included, the included base url will be treated as a git repo, and the support url is not required
|
||||||
|
--in
|
||||||
|
alias: -i
|
||||||
|
default: "scripts"
|
||||||
|
include src file path comments in the output files, i.e. // scripts/example/main.ts
|
||||||
|
--out
|
||||||
|
alias: -o
|
||||||
|
default: "dist"
|
||||||
|
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 (!existsSync('package.json') || !lstatSync('package.json').isFile()) {
|
||||||
console.error('package.json not found, unwilling to run')
|
console.error('package.json not found, unwilling to run')
|
||||||
process.exit(1)
|
process.exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
//delete compiled scripts
|
//delete compiled scripts or create output folder if it doesnt exist
|
||||||
readdirSync(DistBase).forEach(file => unlinkSync(`${DistBase}/${file}`))
|
if (!existsSync(AllPaths.base.out)) {
|
||||||
|
mkdirSync(AllPaths.base.out)
|
||||||
|
} else {
|
||||||
|
readdirSync(AllPaths.base.out).forEach(file =>
|
||||||
|
unlinkSync(`${AllPaths.base.out}/${file}`)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
//compile scripts
|
//compile scripts
|
||||||
readdirSync(ScriptBase).forEach(name => {
|
async function doCompile() {
|
||||||
let path = ScriptPath(name)
|
const scripts = readdirSync(AllPaths.base.in)
|
||||||
|
const scriptMeta: runBuildResult[] = []
|
||||||
|
|
||||||
|
for (const name of scripts) {
|
||||||
|
const path = AllPaths.script(name)
|
||||||
|
|
||||||
if (
|
if (
|
||||||
!name.endsWith('_') &&
|
!name.endsWith('_') &&
|
||||||
|
existsSync(path.dir) &&
|
||||||
lstatSync(path.dir).isDirectory() &&
|
lstatSync(path.dir).isDirectory() &&
|
||||||
|
existsSync(path.main) &&
|
||||||
lstatSync(path.main).isFile()
|
lstatSync(path.main).isFile()
|
||||||
) {
|
) {
|
||||||
compileProject(name)
|
const id = scriptMeta.length
|
||||||
|
|
||||||
|
scriptMeta[id] = await runBuild(name)
|
||||||
|
console.log(name, scriptMeta[id].meta.version)
|
||||||
|
|
||||||
|
var running = false
|
||||||
|
async function update(eventName: string) {
|
||||||
|
if (running) {
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
running = true
|
||||||
|
|
||||||
|
scriptMeta[id] = await runBuild(name)
|
||||||
|
console.log(
|
||||||
|
`WATCH ${eventName}`,
|
||||||
|
name,
|
||||||
|
scriptMeta[id].meta.version
|
||||||
|
)
|
||||||
|
|
||||||
|
if (CLIArgs.readme) updateReadmeFile(scriptMeta)
|
||||||
|
running = false
|
||||||
|
}
|
||||||
|
|
||||||
|
if (CLIArgs.watch) {
|
||||||
|
const chokidar = await import('chokidar')
|
||||||
|
chokidar.watch(path.dir).on('all', update)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return scriptMeta
|
||||||
|
}
|
||||||
|
|
||||||
|
doCompile().then(scriptMeta => {
|
||||||
|
if (CLIArgs.readme) updateReadmeFile(scriptMeta)
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
`\nFinished Compiling\n${
|
||||||
|
CLIArgs.watch ? 'Listening for Changes\n' : ''
|
||||||
|
}`
|
||||||
|
)
|
||||||
})
|
})
|
||||||
|
|||||||
68
src/paths.ts
68
src/paths.ts
@@ -1,16 +1,58 @@
|
|||||||
export const BaseUrl = `https://git.zomo.dev/zomo/browser-scripts`
|
export interface ScriptPathT {
|
||||||
export const RemoteBranch = 'main'
|
dir: `${string}/${string}`
|
||||||
export const ScriptBase = 'scripts'
|
main: `${string}/${string}/main.ts`
|
||||||
export const DistBase = 'dist'
|
meta: `${string}/${string}/meta.json`
|
||||||
|
error: `${string}/${string}/error.log`
|
||||||
|
dist: `${string}/${string}.user.js`
|
||||||
|
url: `${string}/${string}.user.js`
|
||||||
|
}
|
||||||
|
|
||||||
export const SupportUrl = `${BaseUrl}/issues`
|
export interface getAllPathsOps {
|
||||||
export const FileUrl = (name: string) =>
|
baseUrl: string
|
||||||
`${BaseUrl}/raw/branch/${RemoteBranch}/${DistBase}/${name}.user.js`
|
supportUrl: string
|
||||||
|
homepageUrl: string
|
||||||
|
remoteBranch: string
|
||||||
|
inBase: string
|
||||||
|
outBase: string
|
||||||
|
}
|
||||||
|
|
||||||
export const ScriptPath = (name: string) => ({
|
export default function getAllPaths({
|
||||||
dir: `${ScriptBase}/${name}`,
|
baseUrl,
|
||||||
main: `${ScriptBase}/${name}/main.ts`,
|
supportUrl,
|
||||||
meta: `${ScriptBase}/${name}/meta.json`,
|
homepageUrl,
|
||||||
})
|
remoteBranch,
|
||||||
|
inBase,
|
||||||
|
outBase,
|
||||||
|
}: getAllPathsOps) {
|
||||||
|
// generate links for remote git server
|
||||||
|
if (baseUrl != '' && remoteBranch != '') {
|
||||||
|
if (supportUrl == '') {
|
||||||
|
supportUrl = `${baseUrl}/issues`
|
||||||
|
}
|
||||||
|
|
||||||
export const DistPath = (name: string) => `${DistBase}/${name}.user.js`
|
if (homepageUrl == '') {
|
||||||
|
homepageUrl = baseUrl
|
||||||
|
}
|
||||||
|
baseUrl = `${baseUrl}/raw/branch/${remoteBranch}/${outBase}`
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
base: {
|
||||||
|
in: inBase,
|
||||||
|
out: outBase,
|
||||||
|
},
|
||||||
|
url: {
|
||||||
|
home: homepageUrl,
|
||||||
|
base: baseUrl,
|
||||||
|
support: supportUrl,
|
||||||
|
},
|
||||||
|
script: (name: string): ScriptPathT => ({
|
||||||
|
dir: `${inBase}/${name}`,
|
||||||
|
main: `${inBase}/${name}/main.ts`,
|
||||||
|
meta: `${inBase}/${name}/meta.json`,
|
||||||
|
error: `${inBase}/${name}/error.log`,
|
||||||
|
dist: `${outBase}/${name}.user.js`,
|
||||||
|
url: `${baseUrl}/${name}.user.js`,
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
105
src/readmefile.ts
Normal file
105
src/readmefile.ts
Normal file
@@ -0,0 +1,105 @@
|
|||||||
|
import { readdirSync, readFileSync, writeFileSync } from 'fs'
|
||||||
|
import { runBuildResult } from './build'
|
||||||
|
import { UserScriptMetaFull, UserScriptMetaMultiple } from './types'
|
||||||
|
|
||||||
|
export function updateReadmeFile(fileList: runBuildResult[]) {
|
||||||
|
const readmeFile = getReadmeFileName()
|
||||||
|
if (readmeFile !== null) {
|
||||||
|
const [readmeStart, readmeEnd] = readReadmeFile(readmeFile)
|
||||||
|
|
||||||
|
const installLinks = fileList.map(readmeDataToString).join('\n')
|
||||||
|
|
||||||
|
const installLinksAll = `<!-- START INSTALL LINKS -->
|
||||||
|
## Installs
|
||||||
|
|
||||||
|
${installLinks}
|
||||||
|
<!-- END INSTALL LINKS -->`
|
||||||
|
|
||||||
|
const content = readmeStart + installLinksAll + readmeEnd
|
||||||
|
writeFileSync(readmeFile, content)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function readmeDataErrorString(error: string | null): string {
|
||||||
|
if (error === null) return ''
|
||||||
|
error = error
|
||||||
|
.split('\n')
|
||||||
|
.map(line => ` ${line}`)
|
||||||
|
.join('\n')
|
||||||
|
return `\n\n${error}`
|
||||||
|
}
|
||||||
|
|
||||||
|
function arrayify(val: UserScriptMetaMultiple): string[] {
|
||||||
|
const newval = Array.isArray(val) ? val : [val]
|
||||||
|
return newval.map(v => v.trim()).filter(v => v)
|
||||||
|
}
|
||||||
|
|
||||||
|
function readmeDataMatches(meta: UserScriptMetaFull): string {
|
||||||
|
const matches = arrayify(meta.match).map(v => '`' + v + '`')
|
||||||
|
const matchesStr = `
|
||||||
|
- ${matches.join(',')}`
|
||||||
|
|
||||||
|
if (matches.length === 0) {
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
|
||||||
|
const excludes = arrayify(meta.excludematch).map(v => '`' + v + '`')
|
||||||
|
const excludesStr = `
|
||||||
|
- excluding: ${excludes.join(',')}`
|
||||||
|
|
||||||
|
if (excludes.length === 0) {
|
||||||
|
return matchesStr
|
||||||
|
}
|
||||||
|
|
||||||
|
return matchesStr + excludesStr
|
||||||
|
}
|
||||||
|
|
||||||
|
function readmeDataToString(results: runBuildResult): string {
|
||||||
|
const { meta, error } = results
|
||||||
|
const errStr = error !== null ? '~~' : ''
|
||||||
|
const errMsg = readmeDataErrorString(error)
|
||||||
|
const matchesStr = readmeDataMatches(meta)
|
||||||
|
|
||||||
|
return `
|
||||||
|
- ${errStr}[${meta.name}](${meta.downloadURL})${errStr}${errMsg}
|
||||||
|
- **${meta.namespace}** v${meta.version}${matchesStr}
|
||||||
|
- ${meta.description}
|
||||||
|
`.trim()
|
||||||
|
}
|
||||||
|
|
||||||
|
function getReadmeFileName(): string | null {
|
||||||
|
const files = readdirSync('.')
|
||||||
|
for (const name of files) {
|
||||||
|
if (/^readme\.md$/i.test(name)) {
|
||||||
|
return name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
function readReadmeFile(readmeFile: string): [string, string] {
|
||||||
|
const content = readFileSync(readmeFile).toString()
|
||||||
|
|
||||||
|
const regex =
|
||||||
|
/<!-- START INSTALL LINKS -->(?:.|\n)*?<!-- END INSTALL LINKS -->/
|
||||||
|
const index = regex.exec(content)?.index
|
||||||
|
|
||||||
|
let contentPre = '',
|
||||||
|
contentPost = ''
|
||||||
|
|
||||||
|
if (index === undefined) {
|
||||||
|
contentPre = content
|
||||||
|
} else {
|
||||||
|
const content_replace = content.replace(regex, '')
|
||||||
|
contentPre = content_replace.slice(0, index)
|
||||||
|
contentPost = content_replace.slice(index)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (contentPre.trimEnd().length === 0) contentPre = ''
|
||||||
|
else contentPre = contentPre.trimEnd() + '\n\n'
|
||||||
|
|
||||||
|
if (contentPost.trimStart().length === 0) contentPost = '\n'
|
||||||
|
else contentPost = '\n\n' + contentPost.trimStart()
|
||||||
|
|
||||||
|
return [contentPre, contentPost]
|
||||||
|
}
|
||||||
@@ -1,9 +1,21 @@
|
|||||||
import { lstatSync, readFileSync } from 'fs'
|
import { existsSync, lstatSync, readFileSync } from 'fs'
|
||||||
import { BaseUrl, FileUrl, ScriptPath, SupportUrl } from './paths'
|
import { AllPaths } from './main'
|
||||||
import { UserDataMeta, UserDataMetaFull, UserDataMetaPartial } from './types'
|
import {
|
||||||
|
UserScriptMeta,
|
||||||
|
UserScriptMetaFull,
|
||||||
|
UserScriptMetaPartial,
|
||||||
|
} from './types'
|
||||||
|
|
||||||
export default function (name: string): [UserDataMetaFull, string] {
|
export default interface readMeta {
|
||||||
var meta: UserDataMetaFull = {
|
meta: UserScriptMetaFull
|
||||||
|
metaString: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function readMeta(name: string) {
|
||||||
|
const paths = AllPaths.script(name)
|
||||||
|
const urls = AllPaths.url
|
||||||
|
|
||||||
|
var meta: UserScriptMetaFull = {
|
||||||
name: name,
|
name: name,
|
||||||
namespace: 'zomo.dev',
|
namespace: 'zomo.dev',
|
||||||
match: '',
|
match: '',
|
||||||
@@ -17,23 +29,23 @@ export default function (name: string): [UserDataMetaFull, string] {
|
|||||||
noframes: false,
|
noframes: false,
|
||||||
grant: '',
|
grant: '',
|
||||||
injectinto: '',
|
injectinto: '',
|
||||||
downloadURL: FileUrl(name),
|
downloadURL: paths.url,
|
||||||
supportURL: SupportUrl,
|
supportURL: urls.support,
|
||||||
homepageURL: BaseUrl,
|
homepageURL: urls.home,
|
||||||
unwrap: false,
|
unwrap: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
let metaPath = ScriptPath(name).meta
|
const metaPath = paths.meta
|
||||||
|
|
||||||
if (lstatSync(metaPath).isFile()) {
|
if (existsSync(metaPath) && lstatSync(metaPath).isFile()) {
|
||||||
try {
|
try {
|
||||||
let args: UserDataMetaPartial = JSON.parse(
|
const args: UserScriptMetaPartial = JSON.parse(
|
||||||
readFileSync(metaPath).toString()
|
readFileSync(metaPath).toString()
|
||||||
)
|
)
|
||||||
|
|
||||||
let key: keyof UserDataMeta
|
let key: keyof UserScriptMeta
|
||||||
for (key in meta) {
|
for (key in meta) {
|
||||||
let val = args[key]
|
const val = args[key]
|
||||||
|
|
||||||
//cases where the value is empty
|
//cases where the value is empty
|
||||||
if (val === undefined) continue
|
if (val === undefined) continue
|
||||||
@@ -56,31 +68,43 @@ export default function (name: string): [UserDataMetaFull, string] {
|
|||||||
excludematch: 'exclude-match',
|
excludematch: 'exclude-match',
|
||||||
}
|
}
|
||||||
|
|
||||||
return [
|
return {
|
||||||
meta,
|
meta,
|
||||||
`// ==UserScript==
|
metaString: `// ==UserScript==
|
||||||
${(Object.keys(meta) as Array<keyof UserDataMetaFull>)
|
${(Object.keys(meta) as Array<keyof UserScriptMetaFull>)
|
||||||
.filter(key => {
|
.filter(key => {
|
||||||
let val = meta[key]
|
const val = meta[key]
|
||||||
if (val === undefined) return false
|
if (val === undefined) return false
|
||||||
if (val === false) return false
|
if (val === false) return false
|
||||||
if (val === '') return false
|
if (val === '') return false
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
.map(key => {
|
.map(key => {
|
||||||
let val = meta[key]
|
const val = meta[key]
|
||||||
let key_str =
|
let key_str: string =
|
||||||
key in keyConversion
|
key in keyConversion
|
||||||
? keyConversion[key as keyof typeof keyConversion]
|
? keyConversion[key as keyof typeof keyConversion]
|
||||||
: key
|
: key
|
||||||
key_str = key_str.padEnd(12, ' ')
|
key_str = key_str.padEnd(12, ' ')
|
||||||
|
|
||||||
if (typeof val === 'boolean') {
|
if (typeof val === 'boolean') {
|
||||||
|
//bool
|
||||||
if (val) return `// @${key_str}`
|
if (val) return `// @${key_str}`
|
||||||
} else if (typeof val === 'string') {
|
} else if (typeof val === 'string') {
|
||||||
|
//string
|
||||||
return `// @${key_str} ${val}`
|
return `// @${key_str} ${val}`
|
||||||
} else if (Array.isArray(val)) {
|
} else if (Array.isArray(val)) {
|
||||||
|
//multiple
|
||||||
return val.map(v => `// @${key_str} ${v}`).join('\n')
|
return val.map(v => `// @${key_str} ${v}`).join('\n')
|
||||||
|
} else if (typeof val === 'object') {
|
||||||
|
//multilingual
|
||||||
|
const langs = val
|
||||||
|
return Object.keys(langs)
|
||||||
|
.map(lang => {
|
||||||
|
const langStr = lang === 'default' ? '' : `:${lang}`
|
||||||
|
return `// @${key_str}${langStr} ${langs[lang]}`
|
||||||
|
})
|
||||||
|
.join('\n')
|
||||||
}
|
}
|
||||||
|
|
||||||
return ''
|
return ''
|
||||||
@@ -89,5 +113,5 @@ ${(Object.keys(meta) as Array<keyof UserDataMetaFull>)
|
|||||||
.join('\n')}
|
.join('\n')}
|
||||||
// ==/UserScript==
|
// ==/UserScript==
|
||||||
`,
|
`,
|
||||||
]
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
42
src/types.ts
42
src/types.ts
@@ -1,16 +1,24 @@
|
|||||||
export interface UserDataMetaPartial {
|
export type UserScriptMetaMultilingual =
|
||||||
name?: string
|
| string
|
||||||
|
| {
|
||||||
|
default: string
|
||||||
|
[lang: string]: string
|
||||||
|
}
|
||||||
|
export type UserScriptMetaMultiple = string | string[]
|
||||||
|
|
||||||
|
export interface UserScriptMetaPartial {
|
||||||
|
name?: UserScriptMetaMultilingual
|
||||||
namespace?: string
|
namespace?: string
|
||||||
match?: string | string[]
|
match?: UserScriptMetaMultiple
|
||||||
excludematch?: string | string[]
|
excludematch?: UserScriptMetaMultiple
|
||||||
version?: string
|
version?: string
|
||||||
description?: string
|
description?: UserScriptMetaMultilingual
|
||||||
icon?: string
|
icon?: string
|
||||||
require?: string | string[]
|
require?: UserScriptMetaMultiple
|
||||||
resource?: string | string[]
|
resource?: UserScriptMetaMultiple
|
||||||
runat?: 'document-start' | 'document-end' | 'document-idle' | ''
|
runat?: 'document-start' | 'document-end' | 'document-idle' | ''
|
||||||
noframes?: boolean
|
noframes?: boolean
|
||||||
grant?: string | string[]
|
grant?: UserScriptMetaMultiple
|
||||||
injectinto?: 'page' | 'content' | 'auto' | ''
|
injectinto?: 'page' | 'content' | 'auto' | ''
|
||||||
downloadURL?: string
|
downloadURL?: string
|
||||||
supportURL?: string
|
supportURL?: string
|
||||||
@@ -18,8 +26,8 @@ export interface UserDataMetaPartial {
|
|||||||
unwrap?: boolean
|
unwrap?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface UserDataMeta extends UserDataMetaPartial {
|
export interface UserScriptMeta extends UserScriptMetaPartial {
|
||||||
name: string
|
name: UserScriptMetaMultilingual
|
||||||
namespace: string
|
namespace: string
|
||||||
version: string
|
version: string
|
||||||
downloadURL: string
|
downloadURL: string
|
||||||
@@ -27,16 +35,16 @@ export interface UserDataMeta extends UserDataMetaPartial {
|
|||||||
homepageURL: string
|
homepageURL: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface UserDataMetaFull extends UserDataMeta {
|
export interface UserScriptMetaFull extends UserScriptMeta {
|
||||||
match: string | string[]
|
match: UserScriptMetaMultiple
|
||||||
excludematch: string | string[]
|
excludematch: UserScriptMetaMultiple
|
||||||
description: string
|
description: UserScriptMetaMultilingual
|
||||||
icon: string
|
icon: string
|
||||||
require: string | string[]
|
require: UserScriptMetaMultiple
|
||||||
resource: string | string[]
|
resource: UserScriptMetaMultiple
|
||||||
runat: 'document-start' | 'document-end' | 'document-idle' | ''
|
runat: 'document-start' | 'document-end' | 'document-idle' | ''
|
||||||
noframes: boolean
|
noframes: boolean
|
||||||
grant: string | string[]
|
grant: UserScriptMetaMultiple
|
||||||
injectinto: 'page' | 'content' | 'auto' | ''
|
injectinto: 'page' | 'content' | 'auto' | ''
|
||||||
unwrap: boolean
|
unwrap: boolean
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
// TODO add tests
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"target": "es2020",
|
"target": "es2020",
|
||||||
"module": "commonjs",
|
"module": "node16",
|
||||||
"esModuleInterop": true,
|
"esModuleInterop": true,
|
||||||
"forceConsistentCasingInFileNames": true,
|
"forceConsistentCasingInFileNames": true,
|
||||||
"skipLibCheck": true,
|
"skipLibCheck": true,
|
||||||
@@ -12,6 +12,6 @@
|
|||||||
"sourceMap": true,
|
"sourceMap": true,
|
||||||
"rootDir": "./src",
|
"rootDir": "./src",
|
||||||
"outDir": "./lib",
|
"outDir": "./lib",
|
||||||
"moduleResolution": "node"
|
"moduleResolution": "node16"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user