build: convert some scripts to TS (#24891)

This commit is contained in:
Samuel Attard 2020-08-07 13:48:46 -07:00 committed by GitHub
parent 2028492356
commit 4d50f3f62c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 32 additions and 29 deletions

View file

@ -108,7 +108,7 @@
"node script/lint.js --js --fix --only --" "node script/lint.js --js --fix --only --"
], ],
"*.{js,ts,d.ts}": [ "*.{js,ts,d.ts}": [
"node script/gen-filenames.js" "ts-node script/gen-filenames.ts"
], ],
"*.{cc,mm,c,h}": [ "*.{cc,mm,c,h}": [
"python script/run-clang-format.py -r -c --fix" "python script/run-clang-format.py -r -c --fix"
@ -124,13 +124,13 @@
"node script/lint.js --py --fix --only --" "node script/lint.js --py --fix --only --"
], ],
"docs/api/**/*.md": [ "docs/api/**/*.md": [
"node script/gen-filenames.js", "ts-node script/gen-filenames.ts",
"python script/check-trailing-whitespace.py --fix", "python script/check-trailing-whitespace.py --fix",
"git add filenames.auto.gni" "git add filenames.auto.gni"
], ],
"{*.patch,.patches}": [ "{*.patch,.patches}": [
"node script/lint.js --patches --only --", "node script/lint.js --patches --only --",
"node script/check-patch-diff.js" "ts-node script/check-patch-diff.ts"
], ],
"DEPS": [ "DEPS": [
"node script/gen-hunspell-filenames.js" "node script/gen-hunspell-filenames.js"

View file

@ -1,6 +1,5 @@
const { spawnSync } = require('child_process'); import { spawnSync } from 'child_process';
const path = require('path'); import * as path from 'path';
const { inspect } = require('util');
const srcPath = path.resolve(__dirname, '..', '..', '..'); const srcPath = path.resolve(__dirname, '..', '..', '..');
const patchExportFnPath = path.resolve(__dirname, 'export_all_patches.py'); const patchExportFnPath = path.resolve(__dirname, 'export_all_patches.py');

View file

@ -1,6 +1,6 @@
const cp = require('child_process'); import * as cp from 'child_process';
const fs = require('fs'); import * as fs from 'fs';
const path = require('path'); import * as path from 'path';
const certificatePath = process.argv[2]; const certificatePath = process.argv[2];
const outPath = process.argv[3]; const outPath = process.argv[3];

View file

@ -40,7 +40,7 @@ DevToolsSecurity -enable
# security import "$dir"/public.key -k $KEY_CHAIN # security import "$dir"/public.key -k $KEY_CHAIN
# Generate Trust Settings # Generate Trust Settings
node "$(dirname $0)"/gen-trust.js "$dir"/certificate.cer "$dir"/trust.xml npx ts-node node "$(dirname $0)"/gen-trust.ts "$dir"/certificate.cer "$dir"/trust.xml
# Import Trust Settings # Import Trust Settings
sudo security trust-settings-import -d "$dir/trust.xml" sudo security trust-settings-import -d "$dir/trust.xml"

View file

@ -1,7 +1,7 @@
const cp = require('child_process'); import * as cp from 'child_process';
const fs = require('fs-extra'); import * as fs from 'fs-extra';
const os = require('os'); import * as os from 'os';
const path = require('path'); import * as path from 'path';
const rootPath = path.resolve(__dirname, '..'); const rootPath = path.resolve(__dirname, '..');
const gniPath = path.resolve(__dirname, '../filenames.auto.gni'); const gniPath = path.resolve(__dirname, '../filenames.auto.gni');
@ -43,7 +43,7 @@ const main = async () => {
} }
]; ];
await Promise.all(webpackTargets.map(async webpackTarget => { const webpackTargetsWithDeps = await Promise.all(webpackTargets.map(async webpackTarget => {
const tmpDir = await fs.mkdtemp(path.resolve(os.tmpdir(), 'electron-filenames-')); const tmpDir = await fs.mkdtemp(path.resolve(os.tmpdir(), 'electron-filenames-'));
const child = cp.spawn('node', [ const child = cp.spawn('node', [
'build/webpack/get-outputs.js', 'build/webpack/get-outputs.js',
@ -66,20 +66,24 @@ const main = async () => {
resolve(); resolve();
})); }));
webpackTarget.dependencies = JSON.parse(output) const webpackTargetWithDeps = {
// Remove whitespace ...webpackTarget,
.map(line => line.trim()) dependencies: (JSON.parse(output) as string[])
// Get the relative path // Remove whitespace
.map(line => path.relative(rootPath, line).replace(/\\/g, '/')) .map(line => line.trim())
// Only care about files in //electron // Get the relative path
.filter(line => !line.startsWith('..')) .map(line => path.relative(rootPath, line).replace(/\\/g, '/'))
// Only care about our own files // Only care about files in //electron
.filter(line => !line.startsWith('node_modules')) .filter(line => !line.startsWith('..'))
// All webpack builds depend on the tsconfig and package json files // Only care about our own files
.concat(['tsconfig.json', 'tsconfig.electron.json', 'package.json', ...typingFiles]) .filter(line => !line.startsWith('node_modules'))
// Make the generated list easier to read // All webpack builds depend on the tsconfig and package json files
.sort(); .concat(['tsconfig.json', 'tsconfig.electron.json', 'package.json', ...typingFiles])
// Make the generated list easier to read
.sort()
};
await fs.remove(tmpDir); await fs.remove(tmpDir);
return webpackTargetWithDeps;
})); }));
fs.writeFileSync( fs.writeFileSync(
@ -90,7 +94,7 @@ auto_filenames = {
${allDocs.map(doc => ` "${doc}",`).join('\n')} ${allDocs.map(doc => ` "${doc}",`).join('\n')}
] ]
${webpackTargets.map(target => ` ${target.name} = [ ${webpackTargetsWithDeps.map(target => ` ${target.name} = [
${target.dependencies.map(dep => ` "${dep}",`).join('\n')} ${target.dependencies.map(dep => ` "${dep}",`).join('\n')}
]`).join('\n\n')} ]`).join('\n\n')}
} }