Skip to content

Commit f8ba7a8

Browse files
committed
chore: add platform-project script
1 parent 41c7a9a commit f8ba7a8

File tree

9 files changed

+131
-53
lines changed

9 files changed

+131
-53
lines changed

commitlint.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function parseMessage(message) {
1919
}
2020

2121
function getScopesRule() {
22-
const messages = fs.readFileSync(message, { encoding: 'utf-8' });
22+
const messages = fs.readFileSync(message, { encoding: 'utf8' });
2323
const parsed = parseMessage(messages.split('\n')[0]);
2424
if (parsed) {
2525
const { scope } = parsed;

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"test:affected": "nx affected --target=test --parallel=7",
2020
"util:base64-data": "ts-node -P ./tools/tsconfig.json ./tools/base64-data.ts",
2121
"util:check-update": "yarn upgrade-interactive --latest",
22+
"util:platform-project": "ts-node -P ./tools/tsconfig.json ./tools/platform-project.ts",
2223
"util:sort-package-json": "sort-package-json 'package.json' 'packages/*/package.json'",
2324
"util:update-dependencies": "ts-node -P ./tools/tsconfig.json ./tools/update-dependencies.ts",
2425
"preversion": "yarn util:update-dependencies --check",
@@ -45,6 +46,7 @@
4546
"@testing-library/react": "^13.4.0",
4647
"@types/fs-extra": "^9.0.13",
4748
"@types/glob": "^8.0.0",
49+
"@types/inquirer": "^8.2.5",
4850
"@types/jest": "^27.4.1",
4951
"@types/lodash": "^4.14.188",
5052
"@types/marked": "^4.0.7",
@@ -80,6 +82,7 @@
8082
"husky": "^8.0.1",
8183
"i18next": "^22.0.4",
8284
"immer": "^9.0.16",
85+
"inquirer": "^8.2.5",
8386
"is-builtin-module": "^3.2.0",
8487
"jest": "^27.5.1",
8588
"jest-environment-jsdom": "28.1.1",

packages/platform/package.json

Lines changed: 0 additions & 43 deletions
This file was deleted.

packages/site/executors/build-base/build-base.impl.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,9 @@ class GenerateSite {
320320
mdRouteTmp = mdRouteTmp.replace(
321321
langRegExp,
322322
new TextEncoder()
323-
.encode(readFileSync(path.join(ROUTES_DIR, ...paths, routeName + (lang === 'en-US' ? '' : `.${lang}`)) + '.md').toString())
323+
.encode(
324+
readFileSync(path.join(ROUTES_DIR, ...paths, routeName + (lang === 'en-US' ? '' : `.${lang}`)) + '.md', { encoding: 'utf8' })
325+
)
324326
.join()
325327
);
326328
});
@@ -381,9 +383,9 @@ class GenerateSite {
381383
updateTmp() {
382384
this.resources = readJsonSync(path.join(__dirname, 'files', 'resources.json'));
383385
this.menuGroups = readJsonSync(path.join(__dirname, 'files', 'menu-groups.json'));
384-
this.routesTmp = readFileSync(path.join(__dirname, 'files', 'routes.txt')).toString();
385-
this.componentRouteTmp = readFileSync(path.join(__dirname, 'files', 'ComponentRoute.txt')).toString();
386-
this.mdRouteTmp = readFileSync(path.join(__dirname, 'files', 'MdRoute.txt')).toString();
386+
this.routesTmp = readFileSync(path.join(__dirname, 'files', 'routes.txt'), { encoding: 'utf8' });
387+
this.componentRouteTmp = readFileSync(path.join(__dirname, 'files', 'ComponentRoute.txt'), { encoding: 'utf8' });
388+
this.mdRouteTmp = readFileSync(path.join(__dirname, 'files', 'MdRoute.txt'), { encoding: 'utf8' });
387389

388390
this.menuConfig = [];
389391
this.menuGroups.forEach((item) => {

tools/base64-data.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ const reduceDir = (dirPath: string, paths: string[] = []) => {
2121
reduceDir(filePath, [...paths, file]);
2222
} else if (/^base64\.[\s\S]+\.[\s\S]+$/.test(file) && file !== OUT_FILE) {
2323
table.write([filePath.match(/(?<=packages\/)[\s\S]+?(?=\/)/)![0], file]);
24-
const bitmap = readFileSync(filePath);
25-
output += String.raw` '${file.match(/(?<=\.)[\s\S]+(?=\.)/)![0]}': '${bitmap.toString('base64')}',
24+
const bitmap = readFileSync(filePath, { encoding: 'base64' });
25+
output += String.raw` '${file.match(/(?<=\.)[\s\S]+(?=\.)/)![0]}': '${bitmap}',
2626
`;
2727
}
2828
}

tools/platform-project.ts

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import { execSync } from 'child_process';
2+
import path from 'path';
3+
4+
import { outputFileSync, outputJsonSync, readFileSync } from 'fs-extra';
5+
import inquirer from 'inquirer';
6+
7+
import eslintrcJson from '../.eslintrc.json';
8+
import lernaJson from '../lerna.json';
9+
import nxJson from '../nx.json';
10+
import packageJson from '../package.json';
11+
import tsconfigJson from '../tsconfig.base.json';
12+
import workspaceJson from '../workspace.json';
13+
14+
const ROOT_PATH = path.join(__dirname, '..');
15+
const VERSION = lernaJson.version;
16+
17+
inquirer
18+
.prompt([
19+
/* Pass your questions in here */
20+
{
21+
type: 'confirm',
22+
name: 'toRun',
23+
message: 'I hope you know what you do!!!',
24+
default: false,
25+
},
26+
])
27+
.then((answers) => {
28+
// Use user feedback for... whatever!!
29+
if (answers.toRun) {
30+
console.info('Updating...');
31+
const eslintrcJsonPath = path.join(ROOT_PATH, '.eslintrc.json');
32+
eslintrcJson.overrides.forEach((_, index) => {
33+
if (eslintrcJson.overrides[index].rules && eslintrcJson.overrides[index].rules!['@nrwl/nx/enforce-module-boundaries']) {
34+
delete eslintrcJson.overrides[index].rules!['@nrwl/nx/enforce-module-boundaries'];
35+
}
36+
});
37+
outputJsonSync(eslintrcJsonPath, eslintrcJson);
38+
execSync(`yarn prettier ${eslintrcJsonPath} --write`);
39+
40+
const lernaJsonPath = path.join(ROOT_PATH, 'lerna.json');
41+
lernaJson.packages = [];
42+
lernaJson.version = '0.0.1';
43+
outputJsonSync(lernaJsonPath, lernaJson);
44+
execSync(`yarn prettier ${lernaJsonPath} --write`);
45+
46+
const nxJsonPath = path.join(ROOT_PATH, 'nx.json');
47+
nxJson.defaultProject = 'platform';
48+
outputJsonSync(nxJsonPath, nxJson);
49+
execSync(`yarn prettier ${nxJsonPath} --write`);
50+
51+
const packageJsonPath = path.join(ROOT_PATH, 'package.json');
52+
packageJson.devDependencies['@react-devui/hooks'] = VERSION;
53+
packageJson.devDependencies['@react-devui/icons'] = VERSION;
54+
packageJson.devDependencies['@react-devui/ui'] = VERSION;
55+
packageJson.devDependencies['@react-devui/utils'] = VERSION;
56+
outputJsonSync(packageJsonPath, packageJson);
57+
execSync(`yarn prettier ${packageJsonPath} --write`);
58+
59+
const tsconfigJsonPath = path.join(ROOT_PATH, 'tsconfig.base.json');
60+
tsconfigJson.compilerOptions.paths = {} as any;
61+
outputJsonSync(tsconfigJsonPath, tsconfigJson);
62+
execSync(`yarn prettier ${tsconfigJsonPath} --write`);
63+
64+
const workspaceJsonPath = path.join(ROOT_PATH, 'workspace.json');
65+
workspaceJson.projects = { platform: 'packages/platform' } as any;
66+
outputJsonSync(workspaceJsonPath, workspaceJson);
67+
execSync(`yarn prettier ${workspaceJsonPath} --write`);
68+
69+
const webpackJsPath = path.join(ROOT_PATH, 'packages', 'platform', 'webpack.js');
70+
const webpackJs = readFileSync(webpackJsPath, { encoding: 'utf8' });
71+
outputFileSync(webpackJsPath, webpackJs.replace(/.*react-devui\/ui\/styles.*/g, ''));
72+
execSync(`yarn eslint ${webpackJsPath} --fix`);
73+
}
74+
})
75+
.catch((error) => {
76+
if (error.isTtyError) {
77+
// Prompt couldn't be rendered in the current environment
78+
} else {
79+
// Something else went wrong
80+
}
81+
});

tools/update-dependencies.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ Object.entries(workspace.projects).forEach(([projectName, projectPath]) => {
5454
if (statSync(filePath).isDirectory()) {
5555
reduceDir(filePath, [...paths, file]);
5656
} else if (tsFiles.includes(filePath)) {
57-
ts.createSourceFile(file, readFileSync(filePath).toString(), ts.ScriptTarget.Latest)
57+
ts.createSourceFile(file, readFileSync(filePath, { encoding: 'utf8' }), ts.ScriptTarget.Latest)
5858
.getChildren()
5959
.forEach((node) => {
6060
node.getChildren().forEach((node) => {
@@ -95,7 +95,7 @@ Object.entries(workspace.projects).forEach(([projectName, projectPath]) => {
9595
if (statSync(filePath).isDirectory()) {
9696
reduceDir(filePath, [...paths, file]);
9797
} else if (file.endsWith('.scss')) {
98-
const content = readFileSync(filePath).toString();
98+
const content = readFileSync(filePath, { encoding: 'utf8' });
9999
if (content.includes('~')) {
100100
const importArr = content.match(/(?<=@import ('|")~).+(?=('|"))/g);
101101
if (importArr) {

tsconfig.base.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"emitDecoratorMetadata": true,
1111
"experimentalDecorators": true,
1212
"target": "es2015",
13-
"lib": ["es2017", "dom"],
13+
"lib": ["es2015", "dom"],
1414
"useDefineForClassFields": true,
1515
"noFallthroughCasesInSwitch": true,
1616
"noPropertyAccessFromIndexSignature": true,

yarn.lock

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3626,6 +3626,13 @@
36263626
dependencies:
36273627
"@types/node" "*"
36283628

3629+
"@types/inquirer@^8.2.5":
3630+
version "8.2.5"
3631+
resolved "https://registry.yarnpkg.com/@types/inquirer/-/inquirer-8.2.5.tgz#c508423bcc11126db278170ab07347783ac2300c"
3632+
integrity sha512-QXlzybid60YtAwfgG3cpykptRYUx2KomzNutMlWsQC64J/WG/gQSl+P4w7A21sGN0VIxRVava4rgnT7FQmFCdg==
3633+
dependencies:
3634+
"@types/through" "*"
3635+
36293636
"@types/istanbul-lib-coverage@*", "@types/istanbul-lib-coverage@^2.0.0", "@types/istanbul-lib-coverage@^2.0.1":
36303637
version "2.0.4"
36313638
resolved "https://registry.yarnpkg.com/@types/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.4.tgz#8467d4b3c087805d63580480890791277ce35c44"
@@ -3855,6 +3862,13 @@
38553862
dependencies:
38563863
"@types/jest" "*"
38573864

3865+
"@types/through@*":
3866+
version "0.0.30"
3867+
resolved "https://registry.yarnpkg.com/@types/through/-/through-0.0.30.tgz#e0e42ce77e897bd6aead6f6ea62aeb135b8a3895"
3868+
integrity sha512-FvnCJljyxhPM3gkRgWmxmDZyAQSiBQQWLI0A0VFL0K7W1oRUrPJSqNO0NvTnLkBcotdlp3lKvaT0JrnyRDkzOg==
3869+
dependencies:
3870+
"@types/node" "*"
3871+
38583872
"@types/tough-cookie@*":
38593873
version "4.0.2"
38603874
resolved "https://registry.yarnpkg.com/@types/tough-cookie/-/tough-cookie-4.0.2.tgz#6286b4c7228d58ab7866d19716f3696e03a09397"
@@ -8365,6 +8379,27 @@ inquirer@^8.2.4:
83658379
through "^2.3.6"
83668380
wrap-ansi "^7.0.0"
83678381

8382+
inquirer@^8.2.5:
8383+
version "8.2.5"
8384+
resolved "https://registry.yarnpkg.com/inquirer/-/inquirer-8.2.5.tgz#d8654a7542c35a9b9e069d27e2df4858784d54f8"
8385+
integrity sha512-QAgPDQMEgrDssk1XiwwHoOGYF9BAbUcc1+j+FhEvaOt8/cKRqyLn0U5qA6F74fGhTMGxf92pOvPBeh29jQJDTQ==
8386+
dependencies:
8387+
ansi-escapes "^4.2.1"
8388+
chalk "^4.1.1"
8389+
cli-cursor "^3.1.0"
8390+
cli-width "^3.0.0"
8391+
external-editor "^3.0.3"
8392+
figures "^3.0.0"
8393+
lodash "^4.17.21"
8394+
mute-stream "0.0.8"
8395+
ora "^5.4.1"
8396+
run-async "^2.4.0"
8397+
rxjs "^7.5.5"
8398+
string-width "^4.1.0"
8399+
strip-ansi "^6.0.0"
8400+
through "^2.3.6"
8401+
wrap-ansi "^7.0.0"
8402+
83688403
internal-slot@^1.0.3:
83698404
version "1.0.3"
83708405
resolved "https://registry.yarnpkg.com/internal-slot/-/internal-slot-1.0.3.tgz#7347e307deeea2faac2ac6205d4bc7d34967f59c"

0 commit comments

Comments
 (0)