Browse Source

build: convert some scripts to TS (#24891)

Samuel Attard 4 years ago
parent
commit
4d50f3f62c

+ 3 - 3
package.json

@@ -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"

+ 2 - 3
script/check-patch-diff.js → script/check-patch-diff.ts

@@ -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');

+ 3 - 3
script/codesign/gen-trust.js → script/codesign/gen-trust.ts

@@ -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];

+ 1 - 1
script/codesign/generate-identity.sh

@@ -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"

+ 23 - 19
script/gen-filenames.js → script/gen-filenames.ts

@@ -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')}
 }