Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/deploy-web-dev-cn.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/deploy-web-dev-sg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/deploy-web-prod-sg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@
"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",
"ship:win": "pnpm -F renderer-app build && pnpm -F flat ship:win",
"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": {
Expand Down
58 changes: 0 additions & 58 deletions scripts/changelog.js

This file was deleted.

66 changes: 66 additions & 0 deletions scripts/changelog.ts
Original file line number Diff line number Diff line change
@@ -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);
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ for (const scriptName in packageJSONContent.scripts) {
fs.writeFileSync(rootPackageJSONPath, JSON.stringify(packageJSONContent, null, 2), {
encoding: "utf-8",
});
export {};
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
const fs = require("fs");
const { workspacePath } = require("../constants");

const content = {};
const content: { packages: string[] } = {
packages: [],
};

const retentionPackageName = process.argv[2];

Expand All @@ -24,3 +26,4 @@ const text = `packages:\n - ${content.packages.join("\n - ")}`;
fs.writeFileSync(workspacePath, text, {
encoding: "utf-8",
});
export {};
2 changes: 1 addition & 1 deletion scripts/constants.js → scripts/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { join } = require("path");
import { join } from "path";

const rootPath = join(__dirname, "..");
const configPath = join(rootPath, "config");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {};
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>(resolve => {
repl.question(`is that ok? (y/N) `, a => resolve(a || "N"));
});
if (answer[0].toLowerCase() !== "y") {
Expand Down Expand Up @@ -137,3 +137,4 @@ const client = new OSS({
await Promise.all(uploadEffectFile);
process.exit(0);
})();
export {};
63 changes: 18 additions & 45 deletions scripts/deployment/utils.js → scripts/deployment/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand All @@ -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`);
Expand All @@ -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}`;
}
Expand All @@ -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<any>} array - origin array
* @param {number} chunk_size - chunk number
* @return {Array<any>[]}
*/
module.exports.arrayChunks = (array, chunk_size) => {
const arrayChunks = <T>(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 {};
5 changes: 3 additions & 2 deletions scripts/launch/index.js → scripts/launch/index.ts
Original file line number Diff line number Diff line change
@@ -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();
}

Expand All @@ -27,3 +27,4 @@ if (process.platform === "win32") {
system("osascript ./scripts/launch/mac/launch_terminal.scpt " + suffix);
}
}
export {};
Original file line number Diff line number Diff line change
@@ -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 {};