diff --git a/.github/workflows/deploy-web-dev-cn.yml b/.github/workflows/deploy-web-dev-cn.yml index daf10fe5900..cae9598cd9a 100644 --- a/.github/workflows/deploy-web-dev-cn.yml +++ b/.github/workflows/deploy-web-dev-cn.yml @@ -37,8 +37,8 @@ jobs: echo "FLAT_AGREEMENT_URL=$FLAT_AGREEMENT_URL" >> config/CN/.env.development echo "FLAT_WEB_ALIYUN_PREFIX=$FLAT_WEB_ALIYUN_PREFIX" >> config/CN/.env.development echo "FLAT_WEB_SCENE_ID=$FLAT_WEB_SCENE_ID" >> config/CN/.env.development - node ./scripts/ci/remove-workspace-packages.js web - node ./scripts/ci/remove-package-scripts-hooks.js + pnpm exec esbuild-dev --cjs ./scripts/ci/remove-workspace-packages.ts web + pnpm exec esbuild-dev --cjs ./scripts/ci/remove-package-scripts-hooks.ts # failure automatically retries 3 times pnpm i || pnpm i || pnpm i diff --git a/.github/workflows/deploy-web-dev-sg.yml b/.github/workflows/deploy-web-dev-sg.yml index c7bfacac863..70342e9cb36 100644 --- a/.github/workflows/deploy-web-dev-sg.yml +++ b/.github/workflows/deploy-web-dev-sg.yml @@ -35,8 +35,8 @@ jobs: run: | echo "FLAT_WEB_ALIYUN_PREFIX=$FLAT_WEB_ALIYUN_PREFIX" >> config/CN/.env.development echo "FLAT_WEB_SCENE_ID=$FLAT_WEB_SCENE_ID" >> config/CN/.env.development - node ./scripts/ci/remove-workspace-packages.js web - node ./scripts/ci/remove-package-scripts-hooks.js + pnpm exec esbuild-dev --cjs ./scripts/ci/remove-workspace-packages.ts web + pnpm exec esbuild-dev --cjs ./scripts/ci/remove-package-scripts-hooks.ts # failure automatically retries 3 times pnpm i || pnpm i || pnpm i diff --git a/.github/workflows/deploy-web-prod-sg.yml b/.github/workflows/deploy-web-prod-sg.yml index 72343997831..0649e4159ba 100644 --- a/.github/workflows/deploy-web-prod-sg.yml +++ b/.github/workflows/deploy-web-prod-sg.yml @@ -29,8 +29,8 @@ jobs: run: | echo "FLAT_WEB_ALIYUN_PREFIX=$FLAT_WEB_ALIYUN_PREFIX" >> config/CN/.env.production echo "FLAT_WEB_SCENE_ID=$FLAT_WEB_SCENE_ID" >> config/CN/.env.production - node ./scripts/ci/remove-workspace-packages.js web - node ./scripts/ci/remove-package-scripts-hooks.js + pnpm exec esbuild-dev --cjs ./scripts/ci/remove-workspace-packages.ts web + pnpm exec esbuild-dev --cjs ./scripts/ci/remove-package-scripts-hooks.ts # failure automatically retries 3 times pnpm i || pnpm i || pnpm i diff --git a/package.json b/package.json index 9055ff725d0..ba80c6b2d25 100644 --- a/package.json +++ b/package.json @@ -8,9 +8,9 @@ "lint": "lint-staged --cwd .", "check-spelling": "cspell --no-progress \"**/*.{md,ts,tsx,js,css,less,json,yml,yaml,html,sh}\"", "storybook": "pnpm -F flat-components start", - "start": "node scripts/launch/index.js", - "start:cn": "cross-env FLAT_REGION=CN node scripts/launch/index.js", - "start:sg": "cross-env FLAT_REGION=SG node scripts/launch/index.js", + "start": "esbuild-dev --cjs scripts/launch/index.ts", + "start:cn": "cross-env FLAT_REGION=CN esbuild-dev --cjs scripts/launch/index.ts", + "start:sg": "cross-env FLAT_REGION=SG esbuild-dev --cjs scripts/launch/index.ts", "start:web": "pnpm -F flat-web start", "ship": "pnpm -F renderer-app build && pnpm -F flat ship", "ship:mac": "pnpm -F renderer-app build && pnpm -F flat ship:mac", @@ -18,8 +18,8 @@ "ship:all": "pnpm -F renderer-app build && pnpm -F flat build && pnpm -F flat pack:win && pnpm -F flat pack:mac", "ship:cn:all": "cross-env FLAT_REGION=CN pnpm ship:all", "ship:sg:all": "cross-env FLAT_REGION=SG pnpm ship:all", - "pub:cn": "cross-env FLAT_REGION=CN node scripts/deployment/upload-ali-oss.js", - "pub:sg": "cross-env FLAT_REGION=SG node scripts/deployment/upload-ali-oss.js" + "pub:cn": "cross-env FLAT_REGION=CN esbuild-dev --cjs scripts/deployment/upload-ali-oss.ts", + "pub:sg": "cross-env FLAT_REGION=SG esbuild-dev --cjs scripts/deployment/upload-ali-oss.ts" }, "license": "MIT", "devDependencies": { diff --git a/scripts/changelog.js b/scripts/changelog.js deleted file mode 100644 index 8c192aefbdd..00000000000 --- a/scripts/changelog.js +++ /dev/null @@ -1,58 +0,0 @@ -const semver = require("semver") -const current = require('../desktop/main-app/package.json').version - -const next = process.argv[2]; -if (!next) { - console.log("usage: node scripts/changelog.js", semver.inc(current, "patch")); - process.exit(1); -} - -const today = new Date().toISOString().slice(0, 10); - -const log = require("child_process").execSync('git log --pretty=format:"%h:%H %s" $(git describe --tags --abbrev=0 @^)..@', { encoding: "utf-8" }); -const features = [] -const fixes = [] -const perf = [] -log.trimEnd().split("\n").forEach(line => { - const match = line.match(/^(\w+):(\w+) (\w+)\(([^\)]+)\): (.+)/) - if (match === null) return; - const abbr = match[1]; - const commit = match[2]; - const type = match[3]; - const scope = match[4]; - const message = match[5].replace(/\#(\d+)/, "[#$1](https://github.com/netless-io/flat/issues/$1)"); - const item = `* **${scope}**: ${message} ([${abbr}](https://github.com/netless-io/flat/commit/${abbr}))`; - if (type === "feat") features.push(item); - if (type === "fix") fixes.push(item); - if (type === "perf") perf.push(item); -}); - -let result = `## [${next}](https://github.com/netless-io/flat/compare/v${current}...v${next}) (${today}) - -`; - -if (features.length > 0) { - result += ` -### Features - -${features.join("\n")} -`; -} - -if (fixes.length > 0) { - result += ` -### Bug Fixes - -${fixes.join("\n")} -`; -} - -if (perf.length > 0) { - result += ` -### Performance Improvements - -${perf.join("\n")} -`; -} - -console.log(result); diff --git a/scripts/changelog.ts b/scripts/changelog.ts new file mode 100644 index 00000000000..7ca551ef9b1 --- /dev/null +++ b/scripts/changelog.ts @@ -0,0 +1,66 @@ +import { execSync } from "child_process"; + +const semver = require("semver"); +const current = require("../desktop/main-app/package.json").version; + +const next = process.argv[2]; +if (!next) { + console.log("usage: node scripts/changelog.ts", semver.inc(current, "patch")); + process.exit(1); +} + +const today = new Date().toISOString().slice(0, 10); + +const log = execSync('git log --pretty=format:"%h:%H %s" $(git describe --tags --abbrev=0 @^)..@', { + encoding: "utf-8", +}); +const features: string[] = []; +const fixes: string[] = []; +const perf: string[] = []; +log.trimEnd() + .split("\n") + .forEach((line: string) => { + const match = line.match(/^(\w+):(\w+) (\w+)\(([^\)]+)\): (.+)/); + if (match === null) return; + const abbr = match[1]; + const type = match[3]; + const scope = match[4]; + const message = match[5].replace( + /\#(\d+)/, + "[#$1](https://github.com/netless-io/flat/issues/$1)", + ); + const item = `* **${scope}**: ${message} ([${abbr}](https://github.com/netless-io/flat/commit/${abbr}))`; + if (type === "feat") features.push(item); + if (type === "fix") fixes.push(item); + if (type === "perf") perf.push(item); + }); + +let result = `## [${next}](https://github.com/netless-io/flat/compare/v${current}...v${next}) (${today}) + +`; + +if (features.length > 0) { + result += ` +### Features + +${features.join("\n")} +`; +} + +if (fixes.length > 0) { + result += ` +### Bug Fixes + +${fixes.join("\n")} +`; +} + +if (perf.length > 0) { + result += ` +### Performance Improvements + +${perf.join("\n")} +`; +} + +console.log(result); diff --git a/scripts/ci/remove-package-scripts-hooks.js b/scripts/ci/remove-package-scripts-hooks.ts similarity index 98% rename from scripts/ci/remove-package-scripts-hooks.js rename to scripts/ci/remove-package-scripts-hooks.ts index a2b6a5b6e75..c14cfdae12f 100644 --- a/scripts/ci/remove-package-scripts-hooks.js +++ b/scripts/ci/remove-package-scripts-hooks.ts @@ -17,3 +17,4 @@ for (const scriptName in packageJSONContent.scripts) { fs.writeFileSync(rootPackageJSONPath, JSON.stringify(packageJSONContent, null, 2), { encoding: "utf-8", }); +export {}; diff --git a/scripts/ci/remove-workspace-packages.js b/scripts/ci/remove-workspace-packages.ts similarity index 89% rename from scripts/ci/remove-workspace-packages.js rename to scripts/ci/remove-workspace-packages.ts index d25f6abf513..86b9798cdc1 100644 --- a/scripts/ci/remove-workspace-packages.js +++ b/scripts/ci/remove-workspace-packages.ts @@ -1,7 +1,9 @@ const fs = require("fs"); const { workspacePath } = require("../constants"); -const content = {}; +const content: { packages: string[] } = { + packages: [], +}; const retentionPackageName = process.argv[2]; @@ -24,3 +26,4 @@ const text = `packages:\n - ${content.packages.join("\n - ")}`; fs.writeFileSync(workspacePath, text, { encoding: "utf-8", }); +export {}; diff --git a/scripts/constants.js b/scripts/constants.ts similarity index 98% rename from scripts/constants.js rename to scripts/constants.ts index 9b6e1fcc461..606d1a7d8d8 100644 --- a/scripts/constants.js +++ b/scripts/constants.ts @@ -1,4 +1,4 @@ -const { join } = require("path"); +import { join } from "path"; const rootPath = join(__dirname, ".."); const configPath = join(rootPath, "config"); diff --git a/scripts/deployment/constants.js b/scripts/deployment/constants.ts similarity index 85% rename from scripts/deployment/constants.js rename to scripts/deployment/constants.ts index 32a198448ad..4fe0dbf7e78 100644 --- a/scripts/deployment/constants.js +++ b/scripts/deployment/constants.ts @@ -18,12 +18,13 @@ const macArtifactsRegExp = [ /^(Flat|Flint)-.+\.zip$/, ]; -module.exports.winBuildPath = region => { +module.exports.winBuildPath = (region: string) => { return join(buildPath, region, "win"); }; -module.exports.macBuildPath = region => { +module.exports.macBuildPath = (region: string) => { return join(buildPath, region, "mac"); }; module.exports.winArtifactsRegExp = winArtifactsRegExp; module.exports.macArtifactsRegExp = macArtifactsRegExp; +export {}; diff --git a/scripts/deployment/upload-ali-oss.js b/scripts/deployment/upload-ali-oss.ts similarity index 98% rename from scripts/deployment/upload-ali-oss.js rename to scripts/deployment/upload-ali-oss.ts index c1cb06783f5..2ef76d3c82e 100644 --- a/scripts/deployment/upload-ali-oss.js +++ b/scripts/deployment/upload-ali-oss.ts @@ -39,7 +39,7 @@ const client = new OSS({ repl.on("SIGINT", () => { repl && repl.close(); }); - const answer = await new Promise(resolve => { + const answer = await new Promise(resolve => { repl.question(`is that ok? (y/N) `, a => resolve(a || "N")); }); if (answer[0].toLowerCase() !== "y") { @@ -137,3 +137,4 @@ const client = new OSS({ await Promise.all(uploadEffectFile); process.exit(0); })(); +export {}; diff --git a/scripts/deployment/utils.js b/scripts/deployment/utils.ts similarity index 54% rename from scripts/deployment/utils.js rename to scripts/deployment/utils.ts index 55615b23864..90a659fe44e 100644 --- a/scripts/deployment/utils.js +++ b/scripts/deployment/utils.ts @@ -14,28 +14,22 @@ if (!process.env.FLAT_REGION) { process.exit(1); } -/** - * file info list - * @typedef {Array<{ - * localPath: string, - * name: string, - * size: number, - * }>} FileInfoList - */ +type FileInfo = { + localPath: string; + name: string; + size: number; +}; + +type FileInfoList = FileInfo[]; -/** - * get file path and file size in specify directory - * @param {string} p - specify directory - * @return {FileInfoList} file info list - */ -const getFilesAndSizeInDir = p => { - const result = []; +const getFilesAndSizeInDir = (p: string): FileInfoList => { + const result: FileInfoList = []; if (!fs.existsSync(p)) { return result; } - fs.readdirSync(p).forEach(name => { + fs.readdirSync(p).forEach((name: string) => { const stat = fs.lstatSync(path.join(p, name)); if (stat.isFile()) { @@ -50,13 +44,7 @@ const getFilesAndSizeInDir = p => { return result; }; -/** - * in the file list, get artifacts files - * @param {RegExp[]} regex - match artifacts files regex list - * @param {FileInfoList} fileList - list of files to be detected - * @return {FileInfoList} artifacts files - */ -const getArtifactsFiles = (regex, fileList) => { +const getArtifactsFiles = (regex: RegExp[], fileList: FileInfoList): FileInfoList => { for (const regx of regex) { if (fileList.some(file => regx.test(file.name))) continue; throw new Error(`Can't find a file that matches the ${regx} RegExp`); @@ -74,14 +62,8 @@ module.exports.macArtifactsFiles = getArtifactsFiles( getFilesAndSizeInDir(macBuildPath(process.env.FLAT_REGION)), ); -/** - * set up different directories according to different files and platforms - * @param {string} folder - bucket folder name - * @param {"win" | "mac"} platform - platform to which the file belongs - * @return {function} accept the file name and mode to match - */ -module.exports.uploadRule = (folder, platform) => { - const prefix = mode => { +module.exports.uploadRule = (folder: string, platform: "win" | "mac") => { + const prefix = (mode: "backup" | "effect"): string => { if (mode === "backup") { return `v${version}/${platform}`; } @@ -92,25 +74,16 @@ module.exports.uploadRule = (folder, platform) => { return `latest/stable/${platform}`; }; - /** - * @param {string} filename - file name - * @param {"effect" | "backup"} mode - origin: really used for upgrading, backup: for backup - * @return {string} finally object name (oss / s3 file path) - */ - return (filename, mode) => { + return (filename: string, mode: "effect" | "backup"): string => { return `${folder}/${prefix(mode)}/${filename}`; }; }; -/** - * array chunk - * @param {Array} array - origin array - * @param {number} chunk_size - chunk number - * @return {Array[]} - */ -module.exports.arrayChunks = (array, chunk_size) => { +const arrayChunks = (array: T[], chunk_size: number): T[][] => { return Array(Math.ceil(array.length / chunk_size)) - .fill() + .fill(null) .map((_, index) => index * chunk_size) .map(begin => array.slice(begin, begin + chunk_size)); }; +module.exports.arrayChunks = arrayChunks; +export {}; diff --git a/scripts/launch/index.js b/scripts/launch/index.ts similarity index 86% rename from scripts/launch/index.js rename to scripts/launch/index.ts index 43417d9817e..88458b4d0c1 100644 --- a/scripts/launch/index.js +++ b/scripts/launch/index.ts @@ -1,13 +1,13 @@ const { spawnSync } = require("child_process"); -function system(cmd, printStdout = true) { +function system(cmd: string, printStdout = true) { return spawnSync(cmd, { stdio: printStdout ? "inherit" : "pipe", shell: true, }); } -function parseStdout({ stdout }) { +function parseStdout({ stdout }: { stdout: Buffer }): string { return stdout.toString().trim(); } @@ -27,3 +27,4 @@ if (process.platform === "win32") { system("osascript ./scripts/launch/mac/launch_terminal.scpt " + suffix); } } +export {}; diff --git a/scripts/utils/auto-choose-config.js b/scripts/utils/auto-choose-config.ts similarity index 75% rename from scripts/utils/auto-choose-config.js rename to scripts/utils/auto-choose-config.ts index f2f495f9972..b889b74ee75 100644 --- a/scripts/utils/auto-choose-config.js +++ b/scripts/utils/auto-choose-config.ts @@ -1,13 +1,15 @@ const { configPath } = require("../constants"); const path = require("path"); -const configRegion = () => { +const configRegion = (): string => { return process.env.FLAT_REGION || "CN"; }; -const autoChooseConfig = () => { +const autoChooseConfig = (): string => { return path.join(configPath, configRegion()); }; module.exports.configRegion = configRegion; module.exports.autoChooseConfig = autoChooseConfig; + +export {};