Skip to content

Commit

Permalink
Update ci scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
hyrious committed Mar 28, 2022
1 parent 3f9b19c commit f9bacb7
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 19 deletions.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-react": "^7.29.4",
"eslint-webpack-plugin": "^3.1.1",
"find-up": "5",
"fork-ts-checker-webpack-plugin": "^7.2.1",
"husky": "^7.0.4",
"less": "^4.1.2",
Expand All @@ -57,7 +58,8 @@
"svgo": "^2.8.0",
"typescript": "^4.6.2",
"vite": "^2.8.6",
"webpack": "^5.70.0"
"webpack": "^5.70.0",
"yaml": "^1.10.2"
},
"pnpm": {
"//": "don't worry, we will download it in the main-app/postinstall script.",
Expand Down
6 changes: 5 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 6 additions & 7 deletions scripts/ci/install-changed-package-dependencies.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
if (!process.env.CI) {
return;
process.exit();
}

const fs = require("fs");
const { rootPackageJSONPath } = require("../constants");
const yaml = require("yaml");
const { workspacePath } = require("../constants");

const { components, types, renderer, main, flatWeb } = process.env;

Expand Down Expand Up @@ -51,12 +52,10 @@ if (workspaces.length === 0) {

console.log(`will install dependencies in: ${workspaces.join(", ")}`);

const packageJSONFileContent = require(rootPackageJSONPath);
const content = yaml.parse(fs.readFileSync(workspacePath, "utf8"));

packageJSONFileContent.workspaces.packages = workspaces;
content.workspaces = workspaces;

const newFileContent = JSON.stringify(packageJSONFileContent, null, 2);

fs.writeFileSync(rootPackageJSONPath, newFileContent, {
fs.writeFileSync(workspacePath, yaml.stringify(content), {
encoding: "utf-8",
});
16 changes: 6 additions & 10 deletions scripts/ci/remove-workspace-packages.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,25 @@
const fs = require("fs");
const path = require("path");
const yaml = require("yaml");
const { workspacePath } = require("../constants");

const rootPackageJSONPath = path.resolve(__dirname, "..", "..", "package.json");

/**
* @type { typeof import("../../package.json") }
*/
const packageJSONContent = require(rootPackageJSONPath);
const content = yaml.parse(fs.readFileSync(workspacePath, "utf8"));

const retentionPackageName = process.argv[2];

switch (retentionPackageName) {
case "desktop": {
packageJSONContent.workspaces.packages = ["desktop/*", "packages/*"];
content.workspaces = ["desktop/**", "packages/**"];
break;
}
case "web": {
packageJSONContent.workspaces.packages = ["web/*", "packages/*"];
content.workspaces = ["web/**", "packages/**"];
break;
}
default: {
throw new Error("need retention package name not found, only supports: desktop / web");
}
}

fs.writeFileSync(rootPackageJSONPath, JSON.stringify(packageJSONContent, null, 2), {
fs.writeFileSync(workspacePath, yaml.stringify(content), {
encoding: "utf-8",
});
3 changes: 3 additions & 0 deletions scripts/constants.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { join } = require("path");
const findUp = require("find-up");

const rootPath = join(__dirname, "..");
const configPath = join(rootPath, "config");
Expand All @@ -15,6 +16,7 @@ const typesEntryPath = join(packagesPath, "flat-types", "src");
const i18nEntryPath = join(packagesPath, "flat-i18n", "locales");
const componentsEntryPath = join(packagesPath, "flat-components", "src");

const workspacePath = findUp.sync("pnpm-workspace.yaml");
const rootPackageJSONPath = join(rootPath, "package.json");
const mainPackageJSONPath = join(mainPath, "package.json");

Expand All @@ -37,6 +39,7 @@ module.exports.typesEntryPath = typesEntryPath;
module.exports.i18nEntryPath = i18nEntryPath;
module.exports.componentsEntryPath = componentsEntryPath;

module.exports.workspacePath = workspacePath;
module.exports.rootPackageJSONPath = rootPackageJSONPath;
module.exports.mainPackageJSONPath = mainPackageJSONPath;

Expand Down

0 comments on commit f9bacb7

Please sign in to comment.