Compare commits
63 Commits
f4a67f2d1a
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 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 | |||
| 43d31fdffb | |||
| daaaf1c405 |
@@ -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 });
|
||||
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
|
||||
let { meta, metaString } = (0, readmeta_1.default)(name);
|
||||
let paths = main_1.AllPaths.script(name);
|
||||
let 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}'`,
|
||||
},
|
||||
});
|
||||
let error = await postBuild(name, result, metaString);
|
||||
return {
|
||||
meta,
|
||||
error,
|
||||
};
|
||||
}
|
||||
exports.default = runBuild;
|
||||
async function runEsbuild(opts) {
|
||||
opts.write = false;
|
||||
try {
|
||||
let 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) {
|
||||
let regexp = new RegExp(`//\\s*${main_1.AllPaths.base.in}/.*(?:\\n|$)`, 'g');
|
||||
return content.replace(regexp, '');
|
||||
}
|
||||
async function postBuild(name, result, metaString) {
|
||||
let error = null;
|
||||
let paths = main_1.AllPaths.script(name);
|
||||
let 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) {
|
||||
let paths = main_1.AllPaths.script(name);
|
||||
let 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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,EAAE,CAAA;IAEvD,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QACjB,MAAM,IAAA,oBAAS,EAAC,KAAK,CAAC,KAAK,EAAE,OAAO,CAAC,CAAA;QACrC,IAAI,MAAM,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;YAC/B,MAAM,IAAA,iBAAM,EAAC,KAAK,CAAC,IAAI,CAAC,CAAA;QAC5B,CAAC;IACL,CAAC;SAAM,IAAI,MAAM,UAAU,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;QACvC,MAAM,IAAA,iBAAM,EAAC,KAAK,CAAC,KAAK,CAAC,CAAA;IAC7B,CAAC;AACL,CAAC;AAED,SAAS,UAAU,CAAC,IAAY;IAC5B,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE;QACzB,IAAA,eAAI,EAAC,IAAI,CAAC;aACL,IAAI,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;aACzB,KAAK,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAA;IACpC,CAAC,CAAC,CAAA;AACN,CAAC"}
|
||||
197
lib/main.js
197
lib/main.js
@@ -1,50 +1,175 @@
|
||||
#!/usr/bin/env node
|
||||
"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) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const esbuild_1 = require("esbuild");
|
||||
exports.AllPaths = exports.CLIArgs = void 0;
|
||||
const fs_1 = require("fs");
|
||||
const paths_1 = require("./paths");
|
||||
const readmeta_1 = __importDefault(require("./readmeta"));
|
||||
async function compileProject(name) {
|
||||
//read meta file
|
||||
let [metaJson, metaString] = readmeta_1.default(name);
|
||||
let outPath = paths_1.DistPath(name);
|
||||
await esbuild_1.build({
|
||||
entryPoints: [paths_1.ScriptPath(name).main],
|
||||
outfile: outPath,
|
||||
target: 'esnext',
|
||||
platform: 'node',
|
||||
format: 'esm',
|
||||
bundle: true,
|
||||
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 = fs_1.readFileSync(outPath).toString();
|
||||
fs_1.writeFileSync(outPath, metaString + content);
|
||||
const command_line_args_1 = __importDefault(require("command-line-args"));
|
||||
const readmefile_1 = require("./readmefile");
|
||||
const build_1 = __importDefault(require("./build"));
|
||||
const Path = __importStar(require("path"));
|
||||
const paths_1 = __importDefault(require("./paths"));
|
||||
const chokidar = __importStar(require("chokidar"));
|
||||
exports.CLIArgs = (0, command_line_args_1.default)([
|
||||
{ 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 },
|
||||
]);
|
||||
exports.AllPaths = (0, paths_1.default)({
|
||||
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',
|
||||
});
|
||||
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
|
||||
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 (!fs_1.lstatSync('package.json').isFile()) {
|
||||
//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');
|
||||
process.exit(1);
|
||||
}
|
||||
//delete compiled scripts
|
||||
fs_1.readdirSync(paths_1.DistBase).forEach(file => fs_1.unlinkSync(`${paths_1.DistBase}/${file}`));
|
||||
//delete compiled scripts or create output folder if it doesnt exist
|
||||
if (!(0, fs_1.existsSync)(exports.AllPaths.base.out)) {
|
||||
(0, fs_1.mkdirSync)(exports.AllPaths.base.out);
|
||||
}
|
||||
else {
|
||||
(0, fs_1.readdirSync)(exports.AllPaths.base.out).forEach(file => (0, fs_1.unlinkSync)(`${exports.AllPaths.base.out}/${file}`));
|
||||
}
|
||||
//compile scripts
|
||||
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);
|
||||
async function doCompile() {
|
||||
let scripts = (0, fs_1.readdirSync)(exports.AllPaths.base.in);
|
||||
let scriptMeta = [];
|
||||
for (let name of scripts) {
|
||||
let 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()) {
|
||||
let 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) {
|
||||
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
|
||||
@@ -1 +1 @@
|
||||
{"version":3,"file":"main.js","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":";;;;;AAAA,qCAA+B;AAC/B,2BAMW;AACX,mCAAoE;AACpE,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AAC,MAAM;oBAAE,IAAA,6BAAgB,EAAC,UAAU,CAAC,CAAA;gBAChD,OAAO,GAAG,KAAK,CAAA;YACnB,CAAC;YAED,IAAI,eAAO,CAAC,KAAK,EAAE,CAAC;gBAChB,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";
|
||||
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.BaseUrl = `https://git.zomo.dev/zomo/browser-scripts`;
|
||||
exports.RemoteBranch = 'main';
|
||||
exports.ScriptBase = 'scripts';
|
||||
exports.DistBase = 'dist';
|
||||
exports.SupportUrl = `${exports.BaseUrl}/issues`;
|
||||
const FileUrl = (name) => `${exports.BaseUrl}/raw/branch/${exports.RemoteBranch}/${exports.DistBase}/${name}.user.js`;
|
||||
exports.FileUrl = FileUrl;
|
||||
const ScriptPath = (name) => ({
|
||||
dir: `${exports.ScriptBase}/${name}`,
|
||||
main: `${exports.ScriptBase}/${name}/main.ts`,
|
||||
meta: `${exports.ScriptBase}/${name}/meta.json`,
|
||||
});
|
||||
exports.ScriptPath = ScriptPath;
|
||||
const DistPath = (name) => `${exports.DistBase}/${name}.user.js`;
|
||||
exports.DistPath = DistPath;
|
||||
function getAllPaths({ baseUrl, supportUrl, homepageUrl, remoteBranch, inBase, outBase, }) {
|
||||
// generate links for remote git server
|
||||
if (baseUrl != '' && remoteBranch != '') {
|
||||
if (supportUrl == '') {
|
||||
supportUrl = `${baseUrl}/issues`;
|
||||
}
|
||||
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) => ({
|
||||
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`,
|
||||
}),
|
||||
};
|
||||
}
|
||||
exports.default = getAllPaths;
|
||||
//# 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,SAAS,CAAA;AACtB,QAAA,QAAQ,GAAG,MAAM,CAAA;AAEjB,QAAA,UAAU,GAAG,GAAG,eAAO,SAAS,CAAA;AACtC,MAAM,OAAO,GAAG,CAAC,IAAY,EAAE,EAAE,CACpC,GAAG,eAAO,eAAe,oBAAY,IAAI,gBAAQ,IAAI,IAAI,UAAU,CAAA;AAD1D,QAAA,OAAO,WACmD;AAEhE,MAAM,UAAU,GAAG,CAAC,IAAY,EAAE,EAAE,CAAC,C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,YAAY;YACpC,IAAI,EAAE,GAAG,OAAO,IAAI,IAAI,UAAU;YAClC,GAAG,EAAE,GAAG,OAAO,IAAI,IAAI,UAAU;SACpC,CAAC;KACL,CAAA;AACL,CAAC;AAvCD,8BAuCC"}
|
||||
71
lib/readmefile.js
Normal file
71
lib/readmefile.js
Normal file
@@ -0,0 +1,71 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.updateReadmeFile = void 0;
|
||||
const fs_1 = require("fs");
|
||||
function updateReadmeFile(fileList) {
|
||||
let readmeFile = getReadmeFileName();
|
||||
if (readmeFile !== null) {
|
||||
let [readmeStart, readmeEnd] = readReadmeFile(readmeFile);
|
||||
let installLinks = fileList.map(readmeDataToString).join('\n');
|
||||
let installLinksAll = `<!-- START INSTALL LINKS -->
|
||||
## Installs
|
||||
|
||||
${installLinks}
|
||||
<!-- END INSTALL LINKS -->`;
|
||||
let content = readmeStart + installLinksAll + readmeEnd;
|
||||
(0, fs_1.writeFileSync)(readmeFile, content);
|
||||
}
|
||||
}
|
||||
exports.updateReadmeFile = updateReadmeFile;
|
||||
function readmeDataErrorString(error) {
|
||||
if (error === null)
|
||||
return '';
|
||||
error = error
|
||||
.split('\n')
|
||||
.map(line => ` ${line}`)
|
||||
.join('\n');
|
||||
return `\n\n${error}`;
|
||||
}
|
||||
function readmeDataToString(results) {
|
||||
let { meta, error } = results;
|
||||
let errStr = error !== null ? '~~' : '';
|
||||
let errMsg = readmeDataErrorString(error);
|
||||
return `
|
||||
- ${errStr}[${meta.name}](${meta.downloadURL})${errStr}${errMsg}
|
||||
- ${meta.namespace} ${meta.version}
|
||||
- ${meta.description}
|
||||
`.trim();
|
||||
}
|
||||
function getReadmeFileName() {
|
||||
let files = (0, fs_1.readdirSync)('.');
|
||||
for (let 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 {
|
||||
let 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":";;;AAAA,2BAA6D;AAG7D,SAAgB,gBAAgB,CAAC,QAA0B;IACvD,IAAI,UAAU,GAAG,iBAAiB,EAAE,CAAA;IACpC,IAAI,UAAU,KAAK,IAAI,EAAE,CAAC;QACtB,IAAI,CAAC,WAAW,EAAE,SAAS,CAAC,GAAG,cAAc,CAAC,UAAU,CAAC,CAAA;QAEzD,IAAI,YAAY,GAAG,QAAQ,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAE9D,IAAI,eAAe,GAAG;;;EAG5B,YAAY;2BACa,CAAA;QAEnB,IAAI,OAAO,GAAG,WAAW,GAAG,eAAe,GAAG,SAAS,CAAA;QACvD,IAAA,kBAAa,EAAC,UAAU,EAAE,OAAO,CAAC,CAAA;IACtC,CAAC;AACL,CAAC;AAhBD,4CAgBC;AAED,SAAS,qBAAqB,CAAC,KAAoB;IAC/C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EAAE,EACf,WAAW,GAAG,EAAE,CAAA;IAEpB,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACtB,UAAU,GAAG,OAAO,CAAA;IACxB,CAAC;SAAM,CAAC;QACJ,IAAI,eAAe,GAAG,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAA;QAChD,UAAU,GAAG,eAAe,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAA;QAC5C,WAAW,GAAG,eAAe,CAAC,KAAK,CAAC,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,10 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const fs_1 = require("fs");
|
||||
const paths_1 = require("./paths");
|
||||
function default_1(name) {
|
||||
const main_1 = require("./main");
|
||||
function readMeta(name) {
|
||||
let paths = main_1.AllPaths.script(name);
|
||||
let urls = main_1.AllPaths.url;
|
||||
var meta = {
|
||||
name: name,
|
||||
namespace: 'zomo.dev',
|
||||
@@ -17,15 +19,15 @@ function default_1(name) {
|
||||
noframes: false,
|
||||
grant: '',
|
||||
injectinto: '',
|
||||
downloadURL: paths_1.FileUrl(name),
|
||||
supportURL: paths_1.SupportUrl,
|
||||
homepageURL: paths_1.BaseUrl,
|
||||
downloadURL: paths.url,
|
||||
supportURL: urls.support,
|
||||
homepageURL: urls.home,
|
||||
unwrap: false,
|
||||
};
|
||||
let metaPath = paths_1.ScriptPath(name).meta;
|
||||
if (fs_1.lstatSync(metaPath).isFile()) {
|
||||
let metaPath = paths.meta;
|
||||
if ((0, fs_1.existsSync)(metaPath) && (0, fs_1.lstatSync)(metaPath).isFile()) {
|
||||
try {
|
||||
let args = JSON.parse(fs_1.readFileSync(metaPath).toString());
|
||||
let args = JSON.parse((0, fs_1.readFileSync)(metaPath).toString());
|
||||
let key;
|
||||
for (key in meta) {
|
||||
let val = args[key];
|
||||
@@ -50,9 +52,9 @@ function default_1(name) {
|
||||
injectinto: 'inject-into',
|
||||
excludematch: 'exclude-match',
|
||||
};
|
||||
return [
|
||||
return {
|
||||
meta,
|
||||
`// ==UserScript==
|
||||
metaString: `// ==UserScript==
|
||||
${Object.keys(meta)
|
||||
.filter(key => {
|
||||
let val = meta[key];
|
||||
@@ -69,24 +71,37 @@ ${Object.keys(meta)
|
||||
let key_str = key in keyConversion
|
||||
? keyConversion[key]
|
||||
: key;
|
||||
key_str = key_str.padStart(12, ' ');
|
||||
key_str = key_str.padEnd(12, ' ');
|
||||
if (typeof val === 'boolean') {
|
||||
//bool
|
||||
if (val)
|
||||
return `// @${key_str}`;
|
||||
}
|
||||
else if (typeof val === 'string') {
|
||||
//string
|
||||
return `// @${key_str} ${val}`;
|
||||
}
|
||||
else if (Array.isArray(val)) {
|
||||
//multiple
|
||||
return val.map(v => `// @${key_str} ${v}`).join('\n');
|
||||
}
|
||||
else if (typeof val === 'object') {
|
||||
//multilingual
|
||||
let langs = val;
|
||||
return Object.keys(langs)
|
||||
.map(lang => {
|
||||
let langStr = lang === 'default' ? '' : `:${lang}`;
|
||||
return `// @${key_str}${langStr} ${langs[lang]}`;
|
||||
})
|
||||
.join('\n');
|
||||
}
|
||||
return '';
|
||||
})
|
||||
.filter(l => l.length)
|
||||
.join('\n')}
|
||||
// ==/UserScript==
|
||||
`,
|
||||
];
|
||||
};
|
||||
}
|
||||
exports.default = default_1;
|
||||
exports.default =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$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",
|
||||
"description": "UserScript metadata fields, from https://violentmonkey.github.io/api/metadata-block/",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"$schema": {
|
||||
"type": "string",
|
||||
"description": "Read https://violentmonkey.github.io/api/metadata-block/ for more examples and information about metadata"
|
||||
},
|
||||
"name": {
|
||||
"description": "Script Name",
|
||||
"type": "string"
|
||||
"description": "The name of the script, shown in script list and menus",
|
||||
"type": ["string", "object"],
|
||||
"properties": {
|
||||
"default": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"additionalProperties": {
|
||||
"type": "string"
|
||||
},
|
||||
"required": ["default"]
|
||||
},
|
||||
"namespace": {
|
||||
"description": "Author namespace",
|
||||
"description": "The combination of namespace and name is the unique identifier for a userscript",
|
||||
"type": "string"
|
||||
},
|
||||
"match": {
|
||||
"description": "",
|
||||
"description": "Define rules to decide whether a script should be executed",
|
||||
"type": ["string", "array"],
|
||||
"minItems": 1,
|
||||
"uniqueItems": true,
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"excludematch": {
|
||||
"description": "",
|
||||
"description": "Define rules to decide whether a script should be executed",
|
||||
"type": ["string", "array"],
|
||||
"minItems": 1,
|
||||
"uniqueItems": true,
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"version": {
|
||||
"description": "",
|
||||
"description": "Version of the script, it can be used to check if a script has new versions",
|
||||
"type": "string"
|
||||
},
|
||||
"description": {
|
||||
"description": "",
|
||||
"type": "string"
|
||||
"description": "A brief summary to describe the script",
|
||||
"type": ["string", "object"],
|
||||
"properties": {
|
||||
"default": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"additionalProperties": {
|
||||
"type": "string"
|
||||
},
|
||||
"required": ["default"]
|
||||
},
|
||||
"icon": {
|
||||
"description": "",
|
||||
"description": "Specify an icon for the script",
|
||||
"type": "string"
|
||||
},
|
||||
"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"],
|
||||
"minItems": 1,
|
||||
"uniqueItems": true,
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"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"],
|
||||
"minItems": 1,
|
||||
"uniqueItems": true,
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"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",
|
||||
"enum": ["document-start", "document-end", "document-idle"]
|
||||
"enum": ["document-end", "document-idle", "document-start"]
|
||||
},
|
||||
"noframes": {
|
||||
"description": "",
|
||||
"description": "When present, the script will execute only in top level document, but not in nested frames",
|
||||
"type": "boolean"
|
||||
},
|
||||
"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"],
|
||||
"minItems": 1,
|
||||
"uniqueItems": true,
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"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",
|
||||
"enum": ["page", "content", "auto"]
|
||||
},
|
||||
"downloadURL": {
|
||||
"description": "",
|
||||
"description": "The URL the script can be downloaded from",
|
||||
"type": "string"
|
||||
},
|
||||
"supportURL": {
|
||||
"description": "",
|
||||
"description": "If supplied, the question mark icon in the user scripts list will link to this.",
|
||||
"type": "string"
|
||||
},
|
||||
"homepageURL": {
|
||||
"description": "",
|
||||
"description": "If supplied, the home icon in the user scripts list will link to this.",
|
||||
"type": "string"
|
||||
},
|
||||
"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"
|
||||
}
|
||||
},
|
||||
"additionalProperties": false,
|
||||
"required": ["name", "namespace", "version"]
|
||||
}
|
||||
|
||||
21
package.json
21
package.json
@@ -1,15 +1,15 @@
|
||||
{
|
||||
"name": "browser-scripts-builder",
|
||||
"version": "1.0.0",
|
||||
"version": "1.1.6",
|
||||
"description": "",
|
||||
"main": "./lib/main.mjs",
|
||||
"module": "./lib/main.mjs",
|
||||
"main": "./lib/main.js",
|
||||
"module": "./lib/main.js",
|
||||
"bin": {
|
||||
"bsbuild": "./lib/main.js"
|
||||
},
|
||||
"scripts": {
|
||||
"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"
|
||||
},
|
||||
"repository": {
|
||||
@@ -19,11 +19,16 @@
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"esbuild": "^0.14.42"
|
||||
"chokidar": "^3.6.0",
|
||||
"command-line-args": "^5.2.1",
|
||||
"esbuild": "^0.21.5",
|
||||
"prettier": "^3.3.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^17.0.40",
|
||||
"eslint": "^8.17.0",
|
||||
"prettier": "^2.6.2"
|
||||
"@types/command-line-args": "^5.2.3",
|
||||
"@types/node": "^20.14.5",
|
||||
"@types/prettier": "^2.7.3",
|
||||
"eslint": "^9.5.0",
|
||||
"typescript": "^5.4.5"
|
||||
}
|
||||
}
|
||||
|
||||
2157
pnpm-lock.yaml
generated
2157
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
|
||||
|
||||
note: if `package.json` is not present, running the command is presumed to be a mistake and will refuse to run
|
||||
|
||||
```text
|
||||
Root
|
||||
├───<package.json/etc>
|
||||
@@ -23,3 +25,67 @@ Root
|
||||
└───dist
|
||||
└───[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
|
||||
let { meta, metaString } = readMeta(name)
|
||||
let paths = AllPaths.script(name)
|
||||
|
||||
let 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}'`,
|
||||
},
|
||||
})
|
||||
|
||||
let 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 {
|
||||
let 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 {
|
||||
let 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
|
||||
let paths = AllPaths.script(name)
|
||||
|
||||
let 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) {
|
||||
let paths = AllPaths.script(name)
|
||||
|
||||
let 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))
|
||||
})
|
||||
}
|
||||
224
src/main.ts
224
src/main.ts
@@ -1,64 +1,190 @@
|
||||
import { build } from 'esbuild'
|
||||
import {
|
||||
lstatSync,
|
||||
readdirSync,
|
||||
readFileSync,
|
||||
unlinkSync,
|
||||
writeFileSync,
|
||||
} from 'fs'
|
||||
import { DistBase, DistPath, ScriptBase, ScriptPath } from './paths'
|
||||
import readMeta from './readmeta'
|
||||
import { existsSync, lstatSync, mkdirSync, readdirSync, unlinkSync } from 'fs'
|
||||
import commandLineArgs from 'command-line-args'
|
||||
import { updateReadmeFile } from './readmefile'
|
||||
import runBuild, { runBuildResult } from './build'
|
||||
import * as Path from 'path'
|
||||
import getAllPaths from './paths'
|
||||
import * as chokidar from 'chokidar'
|
||||
|
||||
async function compileProject(name: string) {
|
||||
//read meta file
|
||||
let [metaJson, metaString] = readMeta(name)
|
||||
let outPath = DistPath(name)
|
||||
export interface CLIArgsT {
|
||||
watch: boolean
|
||||
minify: boolean
|
||||
prettier: boolean
|
||||
srccomment: boolean
|
||||
readme: boolean
|
||||
|
||||
await build({
|
||||
entryPoints: [ScriptPath(name).main],
|
||||
outfile: outPath,
|
||||
url?: string
|
||||
supporturl?: string
|
||||
homepageurl?: string
|
||||
remotebranch?: string
|
||||
in?: string
|
||||
out?: string
|
||||
|
||||
target: 'esnext',
|
||||
platform: 'node',
|
||||
format: 'esm',
|
||||
help?: boolean
|
||||
|
||||
bundle: true,
|
||||
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)
|
||||
src?: string
|
||||
}
|
||||
|
||||
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) {
|
||||
let 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')
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
//delete compiled scripts
|
||||
readdirSync(DistBase).forEach(file => unlinkSync(`${DistBase}/${file}`))
|
||||
//delete compiled scripts or create output folder if it doesnt exist
|
||||
if (!existsSync(AllPaths.base.out)) {
|
||||
mkdirSync(AllPaths.base.out)
|
||||
} else {
|
||||
readdirSync(AllPaths.base.out).forEach(file =>
|
||||
unlinkSync(`${AllPaths.base.out}/${file}`)
|
||||
)
|
||||
}
|
||||
|
||||
//compile scripts
|
||||
readdirSync(ScriptBase).forEach(name => {
|
||||
let path = ScriptPath(name)
|
||||
async function doCompile() {
|
||||
let scripts = readdirSync(AllPaths.base.in)
|
||||
let scriptMeta: runBuildResult[] = []
|
||||
|
||||
if (
|
||||
!name.endsWith('_') &&
|
||||
lstatSync(path.dir).isDirectory() &&
|
||||
lstatSync(path.main).isFile()
|
||||
) {
|
||||
compileProject(name)
|
||||
for (let name of scripts) {
|
||||
let path = AllPaths.script(name)
|
||||
|
||||
if (
|
||||
!name.endsWith('_') &&
|
||||
existsSync(path.dir) &&
|
||||
lstatSync(path.dir).isDirectory() &&
|
||||
existsSync(path.main) &&
|
||||
lstatSync(path.main).isFile()
|
||||
) {
|
||||
let 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) {
|
||||
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 const RemoteBranch = 'main'
|
||||
export const ScriptBase = 'scripts'
|
||||
export const DistBase = 'dist'
|
||||
export interface ScriptPathT {
|
||||
dir: `${string}/${string}`
|
||||
main: `${string}/${string}/main.ts`
|
||||
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 const FileUrl = (name: string) =>
|
||||
`${BaseUrl}/raw/branch/${RemoteBranch}/${DistBase}/${name}.user.js`
|
||||
export interface getAllPathsOps {
|
||||
baseUrl: string
|
||||
supportUrl: string
|
||||
homepageUrl: string
|
||||
remoteBranch: string
|
||||
inBase: string
|
||||
outBase: string
|
||||
}
|
||||
|
||||
export const ScriptPath = (name: string) => ({
|
||||
dir: `${ScriptBase}/${name}`,
|
||||
main: `${ScriptBase}/${name}/main.ts`,
|
||||
meta: `${ScriptBase}/${name}/meta.json`,
|
||||
})
|
||||
export default function getAllPaths({
|
||||
baseUrl,
|
||||
supportUrl,
|
||||
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`,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
77
src/readmefile.ts
Normal file
77
src/readmefile.ts
Normal file
@@ -0,0 +1,77 @@
|
||||
import { readdirSync, readFileSync, writeFileSync } from 'fs'
|
||||
import { runBuildResult } from './build'
|
||||
|
||||
export function updateReadmeFile(fileList: runBuildResult[]) {
|
||||
let readmeFile = getReadmeFileName()
|
||||
if (readmeFile !== null) {
|
||||
let [readmeStart, readmeEnd] = readReadmeFile(readmeFile)
|
||||
|
||||
let installLinks = fileList.map(readmeDataToString).join('\n')
|
||||
|
||||
let installLinksAll = `<!-- START INSTALL LINKS -->
|
||||
## Installs
|
||||
|
||||
${installLinks}
|
||||
<!-- END INSTALL LINKS -->`
|
||||
|
||||
let 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 readmeDataToString(results: runBuildResult): string {
|
||||
let { meta, error } = results
|
||||
let errStr = error !== null ? '~~' : ''
|
||||
let errMsg = readmeDataErrorString(error)
|
||||
return `
|
||||
- ${errStr}[${meta.name}](${meta.downloadURL})${errStr}${errMsg}
|
||||
- ${meta.namespace} ${meta.version}
|
||||
- ${meta.description}
|
||||
`.trim()
|
||||
}
|
||||
|
||||
function getReadmeFileName(): string | null {
|
||||
let files = readdirSync('.')
|
||||
for (let 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 {
|
||||
let 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 { BaseUrl, FileUrl, ScriptPath, SupportUrl } from './paths'
|
||||
import { UserDataMeta, UserDataMetaFull, UserDataMetaPartial } from './types'
|
||||
import { existsSync, lstatSync, readFileSync } from 'fs'
|
||||
import { AllPaths } from './main'
|
||||
import {
|
||||
UserScriptMeta,
|
||||
UserScriptMetaFull,
|
||||
UserScriptMetaPartial,
|
||||
} from './types'
|
||||
|
||||
export default function (name: string): [UserDataMetaFull, string] {
|
||||
var meta: UserDataMetaFull = {
|
||||
export default interface readMeta {
|
||||
meta: UserScriptMetaFull
|
||||
metaString: string
|
||||
}
|
||||
|
||||
export default function readMeta(name: string) {
|
||||
let paths = AllPaths.script(name)
|
||||
let urls = AllPaths.url
|
||||
|
||||
var meta: UserScriptMetaFull = {
|
||||
name: name,
|
||||
namespace: 'zomo.dev',
|
||||
match: '',
|
||||
@@ -17,21 +29,21 @@ export default function (name: string): [UserDataMetaFull, string] {
|
||||
noframes: false,
|
||||
grant: '',
|
||||
injectinto: '',
|
||||
downloadURL: FileUrl(name),
|
||||
supportURL: SupportUrl,
|
||||
homepageURL: BaseUrl,
|
||||
downloadURL: paths.url,
|
||||
supportURL: urls.support,
|
||||
homepageURL: urls.home,
|
||||
unwrap: false,
|
||||
}
|
||||
|
||||
let metaPath = ScriptPath(name).meta
|
||||
let metaPath = paths.meta
|
||||
|
||||
if (lstatSync(metaPath).isFile()) {
|
||||
if (existsSync(metaPath) && lstatSync(metaPath).isFile()) {
|
||||
try {
|
||||
let args: UserDataMetaPartial = JSON.parse(
|
||||
let args: UserScriptMetaPartial = JSON.parse(
|
||||
readFileSync(metaPath).toString()
|
||||
)
|
||||
|
||||
let key: keyof UserDataMeta
|
||||
let key: keyof UserScriptMeta
|
||||
for (key in meta) {
|
||||
let val = args[key]
|
||||
|
||||
@@ -56,10 +68,10 @@ export default function (name: string): [UserDataMetaFull, string] {
|
||||
excludematch: 'exclude-match',
|
||||
}
|
||||
|
||||
return [
|
||||
return {
|
||||
meta,
|
||||
`// ==UserScript==
|
||||
${(Object.keys(meta) as Array<keyof UserDataMetaFull>)
|
||||
metaString: `// ==UserScript==
|
||||
${(Object.keys(meta) as Array<keyof UserScriptMetaFull>)
|
||||
.filter(key => {
|
||||
let val = meta[key]
|
||||
if (val === undefined) return false
|
||||
@@ -69,18 +81,30 @@ ${(Object.keys(meta) as Array<keyof UserDataMetaFull>)
|
||||
})
|
||||
.map(key => {
|
||||
let val = meta[key]
|
||||
let key_str =
|
||||
let key_str: string =
|
||||
key in keyConversion
|
||||
? keyConversion[key as keyof typeof keyConversion]
|
||||
: key
|
||||
key_str = key_str.padStart(12, ' ')
|
||||
key_str = key_str.padEnd(12, ' ')
|
||||
|
||||
if (typeof val === 'boolean') {
|
||||
//bool
|
||||
if (val) return `// @${key_str}`
|
||||
} else if (typeof val === 'string') {
|
||||
//string
|
||||
return `// @${key_str} ${val}`
|
||||
} else if (Array.isArray(val)) {
|
||||
//multiple
|
||||
return val.map(v => `// @${key_str} ${v}`).join('\n')
|
||||
} else if (typeof val === 'object') {
|
||||
//multilingual
|
||||
let langs = val
|
||||
return Object.keys(langs)
|
||||
.map(lang => {
|
||||
let langStr = lang === 'default' ? '' : `:${lang}`
|
||||
return `// @${key_str}${langStr} ${langs[lang]}`
|
||||
})
|
||||
.join('\n')
|
||||
}
|
||||
|
||||
return ''
|
||||
@@ -89,5 +113,5 @@ ${(Object.keys(meta) as Array<keyof UserDataMetaFull>)
|
||||
.join('\n')}
|
||||
// ==/UserScript==
|
||||
`,
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
42
src/types.ts
42
src/types.ts
@@ -1,16 +1,24 @@
|
||||
export interface UserDataMetaPartial {
|
||||
name?: string
|
||||
export type UserScriptMetaMultilingual =
|
||||
| string
|
||||
| {
|
||||
default: string
|
||||
[lang: string]: string
|
||||
}
|
||||
export type UserScriptMetaMultiple = string | string[]
|
||||
|
||||
export interface UserScriptMetaPartial {
|
||||
name?: UserScriptMetaMultilingual
|
||||
namespace?: string
|
||||
match?: string | string[]
|
||||
excludematch?: string | string[]
|
||||
match?: UserScriptMetaMultiple
|
||||
excludematch?: UserScriptMetaMultiple
|
||||
version?: string
|
||||
description?: string
|
||||
description?: UserScriptMetaMultilingual
|
||||
icon?: string
|
||||
require?: string | string[]
|
||||
resource?: string | string[]
|
||||
require?: UserScriptMetaMultiple
|
||||
resource?: UserScriptMetaMultiple
|
||||
runat?: 'document-start' | 'document-end' | 'document-idle' | ''
|
||||
noframes?: boolean
|
||||
grant?: string | string[]
|
||||
grant?: UserScriptMetaMultiple
|
||||
injectinto?: 'page' | 'content' | 'auto' | ''
|
||||
downloadURL?: string
|
||||
supportURL?: string
|
||||
@@ -18,8 +26,8 @@ export interface UserDataMetaPartial {
|
||||
unwrap?: boolean
|
||||
}
|
||||
|
||||
export interface UserDataMeta extends UserDataMetaPartial {
|
||||
name: string
|
||||
export interface UserScriptMeta extends UserScriptMetaPartial {
|
||||
name: UserScriptMetaMultilingual
|
||||
namespace: string
|
||||
version: string
|
||||
downloadURL: string
|
||||
@@ -27,16 +35,16 @@ export interface UserDataMeta extends UserDataMetaPartial {
|
||||
homepageURL: string
|
||||
}
|
||||
|
||||
export interface UserDataMetaFull extends UserDataMeta {
|
||||
match: string | string[]
|
||||
excludematch: string | string[]
|
||||
description: string
|
||||
export interface UserScriptMetaFull extends UserScriptMeta {
|
||||
match: UserScriptMetaMultiple
|
||||
excludematch: UserScriptMetaMultiple
|
||||
description: UserScriptMetaMultilingual
|
||||
icon: string
|
||||
require: string | string[]
|
||||
resource: string | string[]
|
||||
require: UserScriptMetaMultiple
|
||||
resource: UserScriptMetaMultiple
|
||||
runat: 'document-start' | 'document-end' | 'document-idle' | ''
|
||||
noframes: boolean
|
||||
grant: string | string[]
|
||||
grant: UserScriptMetaMultiple
|
||||
injectinto: 'page' | 'content' | 'auto' | ''
|
||||
unwrap: boolean
|
||||
}
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
// TODO add tests
|
||||
|
||||
@@ -13,8 +13,5 @@
|
||||
"rootDir": "./src",
|
||||
"outDir": "./lib",
|
||||
"moduleResolution": "node"
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user