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

View file

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

View file

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

View file

@ -40,7 +40,7 @@ DevToolsSecurity -enable
# security import "$dir"/public.key -k $KEY_CHAIN
# 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
sudo security trust-settings-import -d "$dir/trust.xml"

View file

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