flatten vendor dirs and simplify build-vendor

+ replace the inconvenient unicode symbol with ASCII `->` and flatten dirs by default to simplify writing the rules and improve their readability
+ rename and sort functions in the order they run
+ use `node-fetch` instead of the gargantuan `make-fetch-happen`
+ use `glob` which is already installed by other deps
This commit is contained in:
tophf 2022-01-14 15:06:13 +03:00
parent ee44cc4970
commit 4bdad16376
17 changed files with 288 additions and 1091 deletions

View File

@ -144,7 +144,7 @@ async function toggleInjectionOrder(state) {
const shown = $('.injection-order'); const shown = $('.injection-order');
if (state && !shown) { if (state && !shown) {
await require([ await require([
'/vendor/@eight04/draggable-list/dist/draggable-list.iife.min.js', '/vendor/draggable-list/draggable-list.iife.min.js',
'/injection-order/injection-order.css', '/injection-order/injection-order.css',
'/injection-order/injection-order', /* global InjectionOrder */ '/injection-order/injection-order', /* global InjectionOrder */
]); ]);

941
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -22,12 +22,11 @@
}, },
"devDependencies": { "devDependencies": {
"archiver": "^4.0.1", "archiver": "^4.0.1",
"endent": "^1.4.0",
"eslint": "^7.20.0", "eslint": "^7.20.0",
"fs-extra": "^9.0.0", "fs-extra": "^9.0.0",
"make-fetch-happen": "^8.0.7", "glob": "^7.2.0",
"node-fetch": "^2.6.6",
"sync-version": "^1.0.1", "sync-version": "^1.0.1",
"tiny-glob": "^0.2.6",
"web-ext": "^6.5.0" "web-ext": "^6.5.0"
}, },
"scripts": { "scripts": {

View File

@ -1,14 +1,16 @@
/* eslint-env node */
'use strict'; 'use strict';
const fetch = require('node-fetch');
const fs = require('fs');
const fse = require('fs-extra');
const glob = require('glob').sync;
const path = require('path'); const path = require('path');
const endent = require('endent'); const KEEP_DIRECTORIES = null;
const fetch = require('make-fetch-happen');
const fse = require('fs-extra');
const glob = require('tiny-glob');
const files = { const files = {
'codemirror': [ 'codemirror': [
KEEP_DIRECTORIES,
'addon/comment/comment.js', 'addon/comment/comment.js',
'addon/dialog', 'addon/dialog',
'addon/edit/closebrackets.js', 'addon/edit/closebrackets.js',
@ -35,30 +37,30 @@ const files = {
'theme/*', 'theme/*',
], ],
'jsonlint': [ 'jsonlint': [
'lib/jsonlint.js → jsonlint.js', 'lib/jsonlint.js',
'README.md LICENSE', 'README.md -> LICENSE',
], ],
'less-bundle': [ 'less-bundle': [
'dist/less.min.js → less.min.js', 'dist/less.min.js',
], ],
'lz-string-unsafe': [ 'lz-string-unsafe': [
'lz-string-unsafe.min.js', 'lz-string-unsafe.min.js',
], ],
'stylelint-bundle': [ 'stylelint-bundle': [
'dist/stylelint-bundle.min.js → stylelint-bundle.min.js', 'dist/stylelint-bundle.min.js',
'https://github.com/stylelint/stylelint/raw/{VERSION}/LICENSE → LICENSE', 'https://github.com/stylelint/stylelint/raw/{VERSION}/LICENSE',
], ],
'stylus-lang-bundle': [ 'stylus-lang-bundle': [
'dist/stylus-renderer.min.js → stylus-renderer.min.js', 'dist/stylus-renderer.min.js',
], ],
'usercss-meta': [ 'usercss-meta': [
'dist/usercss-meta.min.js → usercss-meta.min.js', 'dist/usercss-meta.min.js',
], ],
'db-to-cloud': [ 'db-to-cloud': [
'dist/db-to-cloud.min.js → db-to-cloud.min.js', 'dist/db-to-cloud.min.js',
], ],
'webext-launch-web-auth-flow': [ 'webext-launch-web-auth-flow': [
'dist/webext-launch-web-auth-flow.min.js → webext-launch-web-auth-flow.min.js', 'dist/webext-launch-web-auth-flow.min.js',
], ],
'@eight04/draggable-list': [ '@eight04/draggable-list': [
'dist/draggable-list.iife.min.js', 'dist/draggable-list.iife.min.js',
@ -69,96 +71,97 @@ main().catch(console.error);
async function main() { async function main() {
fse.emptyDirSync('vendor'); fse.emptyDirSync('vendor');
for (const pkg in files) { await Promise.all(Object.keys(files).map(async pkg => {
console.log('\x1b[32m%s\x1b[0m', `Building ${pkg}...`); console.log(`Building ${pkg}...`);
// other files const pkgName = getFileName(pkg);
const [fetched, copied] = await buildFiles(pkg, files[pkg]); const flatPkg = pkg === pkgName || files[pkgName]
// README ? pkg.replace(/\//g, '-')
await fse.outputFile(`vendor/${pkg}/README.md`, generateReadme(pkg, fetched, copied)); : pkgName;
// LICENSE const res = await buildFiles(pkg, flatPkg, files[pkg]);
await copyLicense(pkg); buildLicense(pkg, flatPkg);
} buildReadme(pkg, flatPkg, res);
console.log('\x1b[32m%s\x1b[0m', 'updating codemirror themes list...'); }));
await fse.outputFile('edit/codemirror-themes.js', await generateThemeList()); console.log('Building CodeMirror theme list...');
buildThemeList();
} }
async function generateThemeList() { async function buildFiles(pkg, flatPkg, patterns) {
const themes = (await fse.readdir('vendor/codemirror/theme')) const keepDirs = patterns.includes(KEEP_DIRECTORIES);
.filter(name => name.endsWith('.css')) let fetched = '';
.map(name => name.replace('.css', '')) let copied = '';
.sort(); for (let pattern of patterns) {
return endent` if (pattern === KEEP_DIRECTORIES) continue;
pattern = pattern.replace('{VERSION}', require(`${pkg}/package.json`).version);
const [src, dest = !keepDirs && getFileName(src)] = pattern.split(/\s*->\s*/);
if (/^https?:/.test(src)) {
fse.outputFileSync(`vendor/${flatPkg}/${dest}`, await (await fetch(src)).text());
fetched += `* ${dest}: ${src}\n`;
} else {
const files = glob(`node_modules/${pkg}/${src}`);
if (!files.length) {
throw new Error(`Pattern ${src} matches no files`);
}
for (const file of files) {
fse.copySync(file, dest
? `vendor/${flatPkg}/${dest}`
: `vendor/${path.relative('node_modules', file).replace(pkg + '/', flatPkg + '/')}`);
const relSrc = path.relative(`node_modules/${pkg}`, file).replace(/\\/g, '/');
copied += dest && dest !== relSrc
? `* ${dest}: ${
keepDirs || getFileName(dest) !== getFileName(relSrc)
? relSrc
: relSrc.replace(/[^/]+$/, '*')
}\n`
: `* ${relSrc}\n`;
}
}
}
return {fetched, copied};
}
function buildLicense(pkg, flatPkg) {
const LICENSE = `vendor/${flatPkg}/LICENSE`;
if (!fs.existsSync(LICENSE)) {
const [src] = glob(`node_modules/${pkg}/LICEN[SC]E*`);
if (!src) throw new Error(`Cannot find license file for ${pkg}`);
fse.copySync(src, LICENSE);
}
}
function buildReadme(pkg, flatPkg, {fetched, copied}) {
const {name, version} = require(`${pkg}/package.json`);
fse.outputFileSync(`vendor/${flatPkg}/README.md`, [
`## ${name} v${version}`,
fetched && `Files downloaded from URL:\n${fetched}`,
copied && `Files copied from NPM (node_modules):\n${copied}`,
].filter(Boolean).join('\n\n'));
}
function buildThemeList() {
fse.outputFileSync('edit/codemirror-themes.js', deindent(`\
/* Do not edit. This file is auto-generated by build-vendor.js */ /* Do not edit. This file is auto-generated by build-vendor.js */
'use strict'; 'use strict';
/* exported CODEMIRROR_THEMES */ /* exported CODEMIRROR_THEMES */
const CODEMIRROR_THEMES = [ const CODEMIRROR_THEMES = [
${ ${
themes.map(t => ` '${t.replace(/'/g, '\\$&')}',\n`).join('') fs.readdirSync('vendor/codemirror/theme')
}]; .filter(name => name.endsWith('.css'))
` + '\n'; .map(name => name.replace('.css', ''))
} .sort()
.map(t => ` '${t.replace(/'/g, '\\$&')}',`).join('\n')
async function copyLicense(pkg) {
try {
await fse.access(`vendor/${pkg}/LICENSE`);
return;
} catch (err) {
// pass
}
for (const file of await glob(`node_modules/${pkg}/LICEN[SC]E*`)) {
await fse.copy(file, `vendor/${pkg}/LICENSE`);
return;
}
throw new Error(`cannot find license file for ${pkg}`);
}
async function buildFiles(pkg, patterns) {
const fetchedFiles = [];
const copiedFiles = [];
for (let pattern of patterns) {
pattern = pattern.replace('{VERSION}', require(`${pkg}/package.json`).version);
const [src, dest] = pattern.split(/\s*→\s*/);
if (src.startsWith('http')) {
const content = await (await fetch(src)).text();
await fse.outputFile(`vendor/${pkg}/${dest}`, content);
fetchedFiles.push([src, dest]);
} else {
let dirty = false;
for (const file of await glob(`node_modules/${pkg}/${src}`)) {
if (dest) {
await fse.copy(file, `vendor/${pkg}/${dest}`);
} else {
await fse.copy(file, path.join('vendor', path.relative('node_modules', file)));
}
copiedFiles.push([path.relative(`node_modules/${pkg}`, file), dest]);
dirty = true;
}
if (!dirty) {
throw new Error(`Pattern ${src} matches no files`);
}
} }
} ];
return [fetchedFiles, copiedFiles]; `));
} }
function generateReadme(lib, fetched, copied) { function deindent(str) {
const pkg = require(`${lib}/package.json`); const indent = str.match(/^\s*/)[0];
let txt = `## ${pkg.name} v${pkg.version}\n\n`; return indent
if (fetched.length) { ? str.replace(new RegExp('^' + indent, 'gm'), '')
txt += `Following files are downloaded from HTTP:\n\n${generateList(fetched)}\n\n`; : str;
}
if (copied.length) {
txt += `Following files are copied from npm (node_modules):\n\n${generateList(copied)}\n`;
}
return txt;
} }
function generateList(list) { function getFileName(path) {
return list.map(([src, dest]) => { return path.split('/').pop();
if (dest) {
return `* ${dest}: ${src}`;
}
return `* ${src}`;
}).join('\n');
} }

View File

@ -1,5 +0,0 @@
## @eight04/draggable-list v0.3.0
Following files are copied from npm (node_modules):
* dist\draggable-list.iife.min.js

View File

@ -1,99 +1,98 @@
## codemirror v5.63.3 ## codemirror v5.63.3
Following files are copied from npm (node_modules): Files copied from NPM (node_modules):
* addon/comment/comment.js
* addon\comment\comment.js * addon/dialog
* addon\dialog * addon/edit/closebrackets.js
* addon\edit\closebrackets.js * addon/edit/matchbrackets.js
* addon\edit\matchbrackets.js * addon/fold/brace-fold.js
* addon\fold\brace-fold.js * addon/fold/comment-fold.js
* addon\fold\comment-fold.js * addon/fold/foldcode.js
* addon\fold\foldcode.js * addon/fold/foldgutter.css
* addon\fold\foldgutter.css * addon/fold/foldgutter.js
* addon\fold\foldgutter.js * addon/fold/indent-fold.js
* addon\fold\indent-fold.js * addon/hint/css-hint.js
* addon\hint\css-hint.js * addon/hint/show-hint.css
* addon\hint\show-hint.css * addon/hint/show-hint.js
* addon\hint\show-hint.js * addon/lint/css-lint.js
* addon\lint\css-lint.js * addon/lint/json-lint.js
* addon\lint\json-lint.js * addon/lint/lint.css
* addon\lint\lint.css * addon/lint/lint.js
* addon\lint\lint.js * addon/scroll/annotatescrollbar.js
* addon\scroll\annotatescrollbar.js * addon/search/matchesonscrollbar.css
* addon\search\matchesonscrollbar.css * addon/search/matchesonscrollbar.js
* addon\search\matchesonscrollbar.js * addon/search/searchcursor.js
* addon\search\searchcursor.js * addon/selection/active-line.js
* addon\selection\active-line.js * keymap/emacs.js
* keymap\emacs.js * keymap/sublime.js
* keymap\sublime.js * keymap/vim.js
* keymap\vim.js * lib/codemirror.css
* lib\codemirror.css * lib/codemirror.js
* lib\codemirror.js * mode/css
* mode\css * mode/javascript
* mode\javascript * mode/stylus
* mode\stylus * theme/3024-day.css
* theme\3024-day.css * theme/3024-night.css
* theme\3024-night.css * theme/abbott.css
* theme\abbott.css * theme/abcdef.css
* theme\abcdef.css * theme/ambiance-mobile.css
* theme\ambiance-mobile.css * theme/ambiance.css
* theme\ambiance.css * theme/ayu-dark.css
* theme\ayu-dark.css * theme/ayu-mirage.css
* theme\ayu-mirage.css * theme/base16-dark.css
* theme\base16-dark.css * theme/base16-light.css
* theme\base16-light.css * theme/bespin.css
* theme\bespin.css * theme/blackboard.css
* theme\blackboard.css * theme/cobalt.css
* theme\cobalt.css * theme/colorforth.css
* theme\colorforth.css * theme/darcula.css
* theme\darcula.css * theme/dracula.css
* theme\dracula.css * theme/duotone-dark.css
* theme\duotone-dark.css * theme/duotone-light.css
* theme\duotone-light.css * theme/eclipse.css
* theme\eclipse.css * theme/elegant.css
* theme\elegant.css * theme/erlang-dark.css
* theme\erlang-dark.css * theme/gruvbox-dark.css
* theme\gruvbox-dark.css * theme/hopscotch.css
* theme\hopscotch.css * theme/icecoder.css
* theme\icecoder.css * theme/idea.css
* theme\idea.css * theme/isotope.css
* theme\isotope.css * theme/juejin.css
* theme\juejin.css * theme/lesser-dark.css
* theme\lesser-dark.css * theme/liquibyte.css
* theme\liquibyte.css * theme/lucario.css
* theme\lucario.css * theme/material-darker.css
* theme\material-darker.css * theme/material-ocean.css
* theme\material-ocean.css * theme/material-palenight.css
* theme\material-palenight.css * theme/material.css
* theme\material.css * theme/mbo.css
* theme\mbo.css * theme/mdn-like.css
* theme\mdn-like.css * theme/midnight.css
* theme\midnight.css * theme/monokai.css
* theme\monokai.css * theme/moxer.css
* theme\moxer.css * theme/neat.css
* theme\neat.css * theme/neo.css
* theme\neo.css * theme/night.css
* theme\night.css * theme/nord.css
* theme\nord.css * theme/oceanic-next.css
* theme\oceanic-next.css * theme/panda-syntax.css
* theme\panda-syntax.css * theme/paraiso-dark.css
* theme\paraiso-dark.css * theme/paraiso-light.css
* theme\paraiso-light.css * theme/pastel-on-dark.css
* theme\pastel-on-dark.css * theme/railscasts.css
* theme\railscasts.css * theme/rubyblue.css
* theme\rubyblue.css * theme/seti.css
* theme\seti.css * theme/shadowfox.css
* theme\shadowfox.css * theme/solarized.css
* theme\solarized.css * theme/ssms.css
* theme\ssms.css * theme/the-matrix.css
* theme\the-matrix.css * theme/tomorrow-night-bright.css
* theme\tomorrow-night-bright.css * theme/tomorrow-night-eighties.css
* theme\tomorrow-night-eighties.css * theme/ttcn.css
* theme\ttcn.css * theme/twilight.css
* theme\twilight.css * theme/vibrant-ink.css
* theme\vibrant-ink.css * theme/xq-dark.css
* theme\xq-dark.css * theme/xq-light.css
* theme\xq-light.css * theme/yeti.css
* theme\yeti.css * theme/yonce.css
* theme\yonce.css * theme/zenburn.css
* theme\zenburn.css

View File

@ -1,5 +1,4 @@
## db-to-cloud v0.7.0 ## db-to-cloud v0.7.0
Following files are copied from npm (node_modules): Files copied from NPM (node_modules):
* db-to-cloud.min.js: dist/*
* db-to-cloud.min.js: dist\db-to-cloud.min.js

4
vendor/draggable-list/README.md vendored Normal file
View File

@ -0,0 +1,4 @@
## @eight04/draggable-list v0.3.0
Files copied from NPM (node_modules):
* draggable-list.iife.min.js: dist/*

View File

@ -1,6 +1,5 @@
## jsonlint v1.6.3 ## jsonlint v1.6.3
Following files are copied from npm (node_modules): Files copied from NPM (node_modules):
* jsonlint.js: lib/*
* jsonlint.js: lib\jsonlint.js
* LICENSE: README.md * LICENSE: README.md

View File

@ -1,5 +1,4 @@
## less-bundle v0.1.0 ## less-bundle v0.1.0
Following files are copied from npm (node_modules): Files copied from NPM (node_modules):
* less.min.js: dist/*
* less.min.js: dist\less.min.js

View File

@ -1,5 +1,4 @@
## lz-string-unsafe v1.4.4-fork-1 ## lz-string-unsafe v1.4.4-fork-1
Following files are copied from npm (node_modules): Files copied from NPM (node_modules):
* lz-string-unsafe.min.js * lz-string-unsafe.min.js

View File

@ -1,9 +1,8 @@
## stylelint-bundle v13.8.0 ## stylelint-bundle v13.8.0
Following files are downloaded from HTTP: Files downloaded from URL:
* LICENSE: https://github.com/stylelint/stylelint/raw/13.8.0/LICENSE * LICENSE: https://github.com/stylelint/stylelint/raw/13.8.0/LICENSE
Following files are copied from npm (node_modules):
* stylelint-bundle.min.js: dist\stylelint-bundle.min.js Files copied from NPM (node_modules):
* stylelint-bundle.min.js: dist/*

View File

@ -1,5 +1,4 @@
## stylus-lang-bundle v0.54.7 ## stylus-lang-bundle v0.54.7
Following files are copied from npm (node_modules): Files copied from NPM (node_modules):
* stylus-renderer.min.js: dist/*
* stylus-renderer.min.js: dist\stylus-renderer.min.js

View File

@ -1,5 +1,4 @@
## usercss-meta v0.12.0 ## usercss-meta v0.12.0
Following files are copied from npm (node_modules): Files copied from NPM (node_modules):
* usercss-meta.min.js: dist/*
* usercss-meta.min.js: dist\usercss-meta.min.js

View File

@ -1,5 +1,4 @@
## webext-launch-web-auth-flow v0.1.1 ## webext-launch-web-auth-flow v0.1.1
Following files are copied from npm (node_modules): Files copied from NPM (node_modules):
* webext-launch-web-auth-flow.min.js: dist/*
* webext-launch-web-auth-flow.min.js: dist\webext-launch-web-auth-flow.min.js