2020-02-14 17:02:57 +00:00
|
|
|
/* eslint-env node */
|
|
|
|
'use strict';
|
|
|
|
const path = require('path');
|
|
|
|
|
|
|
|
const endent = require('endent');
|
|
|
|
const fetch = require('make-fetch-happen');
|
|
|
|
const fse = require('fs-extra');
|
|
|
|
const glob = require('tiny-glob');
|
|
|
|
|
|
|
|
const files = {
|
|
|
|
'codemirror': [
|
|
|
|
'addon/comment/comment.js',
|
|
|
|
'addon/dialog',
|
|
|
|
'addon/edit/closebrackets.js',
|
|
|
|
'addon/edit/matchbrackets.js',
|
|
|
|
'addon/fold/brace-fold.js',
|
|
|
|
'addon/fold/comment-fold.js',
|
|
|
|
'addon/fold/foldcode.js',
|
|
|
|
'addon/fold/foldgutter.*',
|
|
|
|
'addon/fold/indent-fold.js',
|
|
|
|
'addon/hint/css-hint.js',
|
|
|
|
'addon/hint/show-hint.*',
|
|
|
|
'addon/lint/css-lint.js',
|
|
|
|
'addon/lint/json-lint.js',
|
|
|
|
'addon/lint/lint.*',
|
|
|
|
'addon/scroll/annotatescrollbar.js',
|
|
|
|
'addon/search/matchesonscrollbar.*',
|
|
|
|
'addon/search/searchcursor.js',
|
|
|
|
'addon/selection/active-line.js',
|
|
|
|
'keymap/*',
|
|
|
|
'lib/*',
|
|
|
|
'mode/css',
|
|
|
|
'mode/javascript',
|
|
|
|
'mode/stylus',
|
2020-11-18 11:17:15 +00:00
|
|
|
'theme/*',
|
2020-02-14 17:02:57 +00:00
|
|
|
],
|
|
|
|
'jsonlint': [
|
|
|
|
'lib/jsonlint.js → jsonlint.js',
|
2020-11-18 11:17:15 +00:00
|
|
|
'README.md → LICENSE',
|
2020-02-14 17:02:57 +00:00
|
|
|
],
|
|
|
|
'less-bundle': [
|
2020-11-18 11:17:15 +00:00
|
|
|
'dist/less.min.js → less.min.js',
|
2020-02-14 17:02:57 +00:00
|
|
|
],
|
|
|
|
'lz-string-unsafe': [
|
2020-11-18 11:17:15 +00:00
|
|
|
'lz-string-unsafe.min.js',
|
2020-02-14 17:02:57 +00:00
|
|
|
],
|
|
|
|
'semver-bundle': [
|
2020-11-18 11:17:15 +00:00
|
|
|
'dist/semver.js → semver.js',
|
2020-02-14 17:02:57 +00:00
|
|
|
],
|
|
|
|
'stylelint-bundle': [
|
|
|
|
'stylelint-bundle.min.js',
|
2020-11-18 11:17:15 +00:00
|
|
|
'https://github.com/stylelint/stylelint/raw/{VERSION}/LICENSE → LICENSE',
|
2020-02-14 17:02:57 +00:00
|
|
|
],
|
|
|
|
'stylus-lang-bundle': [
|
2020-11-18 11:17:15 +00:00
|
|
|
'dist/stylus-renderer.min.js → stylus-renderer.min.js',
|
2020-02-14 17:02:57 +00:00
|
|
|
],
|
|
|
|
'usercss-meta': [
|
2020-11-18 11:17:15 +00:00
|
|
|
'dist/usercss-meta.min.js → usercss-meta.min.js',
|
2020-02-14 17:02:57 +00:00
|
|
|
],
|
|
|
|
'db-to-cloud': [
|
2020-11-18 11:17:15 +00:00
|
|
|
'dist/db-to-cloud.min.js → db-to-cloud.min.js',
|
2020-02-14 17:02:57 +00:00
|
|
|
],
|
2020-08-31 08:38:18 +00:00
|
|
|
'webext-launch-web-auth-flow': [
|
2020-11-18 11:17:15 +00:00
|
|
|
'dist/webext-launch-web-auth-flow.min.js → webext-launch-web-auth-flow.min.js',
|
|
|
|
],
|
2020-02-14 17:02:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
main().catch(console.error);
|
|
|
|
|
|
|
|
async function main() {
|
|
|
|
for (const pkg in files) {
|
|
|
|
console.log('\x1b[32m%s\x1b[0m', `Building ${pkg}...`);
|
|
|
|
// other files
|
|
|
|
const [fetched, copied] = await buildFiles(pkg, files[pkg]);
|
|
|
|
// README
|
|
|
|
await fse.outputFile(`vendor/${pkg}/README.md`, generateReadme(pkg, fetched, copied));
|
|
|
|
// LICENSE
|
|
|
|
await copyLicense(pkg);
|
|
|
|
}
|
|
|
|
console.log('\x1b[32m%s\x1b[0m', 'updating codemirror themes list...');
|
|
|
|
await fse.outputFile('edit/codemirror-themes.js', await generateThemeList());
|
|
|
|
}
|
|
|
|
|
|
|
|
async function generateThemeList() {
|
|
|
|
const themes = (await fse.readdir('vendor/codemirror/theme'))
|
|
|
|
.filter(name => name.endsWith('.css'))
|
|
|
|
.map(name => name.replace('.css', ''))
|
|
|
|
.sort();
|
|
|
|
return endent`
|
2020-11-18 11:17:15 +00:00
|
|
|
/* Do not edit. This file is auto-generated by build-vendor.js */
|
2020-02-14 17:02:57 +00:00
|
|
|
'use strict';
|
|
|
|
|
2020-11-18 11:17:15 +00:00
|
|
|
/* exported CODEMIRROR_THEMES */
|
|
|
|
const CODEMIRROR_THEMES = [
|
|
|
|
${
|
|
|
|
themes.map(t => ` '${t.replace(/'/g, '\\$&')}',\n`).join('')
|
|
|
|
}];
|
|
|
|
` + '\n';
|
2020-02-14 17:02:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
2020-02-20 12:17:15 +00:00
|
|
|
let dirty = false;
|
2020-02-14 17:02:57 +00:00
|
|
|
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]);
|
2020-02-20 12:17:15 +00:00
|
|
|
dirty = true;
|
|
|
|
}
|
|
|
|
if (!dirty) {
|
|
|
|
throw new Error(`Pattern ${src} matches no files`);
|
2020-02-14 17:02:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return [fetchedFiles, copiedFiles];
|
|
|
|
}
|
|
|
|
|
|
|
|
function generateReadme(lib, fetched, copied) {
|
|
|
|
const pkg = require(`${lib}/package.json`);
|
|
|
|
let txt = `## ${pkg.name} v${pkg.version}\n\n`;
|
|
|
|
if (fetched.length) {
|
|
|
|
txt += `Following files are downloaded from HTTP:\n\n${generateList(fetched)}\n\n`;
|
|
|
|
}
|
|
|
|
if (copied.length) {
|
|
|
|
txt += `Following files are copied from npm (node_modules):\n\n${generateList(copied)}\n`;
|
|
|
|
}
|
|
|
|
return txt;
|
|
|
|
}
|
|
|
|
|
|
|
|
function generateList(list) {
|
|
|
|
return list.map(([src, dest]) => {
|
|
|
|
if (dest) {
|
|
|
|
return `* ${dest}: ${src}`;
|
|
|
|
}
|
|
|
|
return `* ${src}`;
|
|
|
|
}).join('\n');
|
|
|
|
}
|
|
|
|
|
|
|
|
// Rename CodeMirror$1 -> CodeMirror for development purposes
|
|
|
|
// FIXME: is this a workaround for old version of codemirror?
|
|
|
|
// function renameCodeMirrorVariable(filePath) {
|
|
|
|
// const file = fs.readFileSync(filePath, 'utf8');
|
|
|
|
// fs.writeFileSync(filePath, file.replace(/CodeMirror\$1/g, 'CodeMirror'));
|
|
|
|
// }
|