Skip to content

Commit 31ee37c

Browse files
committed
chore: add --check arg for update-dependencies
1 parent 17bf888 commit 31ee37c

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

nx.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,9 @@
2121
},
2222
"tasksRunnerOptions": {
2323
"default": {
24-
"runner": "@nrwl/nx-cloud",
24+
"runner": "nx/tasks-runners/default",
2525
"options": {
26-
"cacheableOperations": ["build", "lint", "test", "e2e"],
27-
"accessToken": "ZTE4ZjVjMDMtNmJiOS00MmRlLThiMTQtMzczNjlmOGY5MWNhfHJlYWQtd3JpdGU="
26+
"cacheableOperations": ["build", "lint", "test", "e2e"]
2827
}
2928
}
3029
},

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@
1313
"lint:style": "stylelint **/*.{css,scss,html,md}",
1414
"lint:style:fix": "yarn lint:style --fix",
1515
"prepare": "husky install && chmod ug+x .husky/*",
16-
"prepublishOnly": "yarn util:update-dependencies && nx run-many --target=build --parallel=7 --exclude=site,vscode-extension",
16+
"prepublishOnly": "nx run-many --target=build --parallel=7 --exclude=site,vscode-extension",
1717
"publish:vscode-extension": "yarn build:vscode-extension && cd dist/packages/vscode-extension && vsce publish --yarn",
1818
"serve:site": "nx serve site",
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",
2222
"util:sort-package-json": "sort-package-json 'package.json' 'packages/*/package.json'",
2323
"util:update-dependencies": "ts-node -P ./tools/tsconfig.json ./tools/update-dependencies.ts",
24+
"preversion": "yarn util:update-dependencies --check",
2425
"version": "prettier lerna.json --write"
2526
},
2627
"dependencies": {},

tools/update-dependencies.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { exec } from 'child_process';
1+
import { exec, execSync } from 'child_process';
22
import path from 'path';
33

44
import { existsSync, outputJsonSync, readdirSync, readFileSync, readJsonSync, statSync } from 'fs-extra';
@@ -13,13 +13,17 @@ const ROOT_PATH = path.join(__dirname, '..');
1313
const TSCONFIG_OPTIONS = ['tsconfig.app.json', 'tsconfig.lib.json'];
1414
const SKIP_IMPORT = ['.', 'packages', 'vscode'];
1515

16+
const checkMode = process.argv.includes('--check');
17+
1618
const table = createStream({
1719
columnDefault: { width: 50 },
1820
columnCount: 2,
1921
columns: [{ width: 40 }, { width: 10, alignment: 'center' }],
2022
});
2123

22-
console.info(`Update package.json...`);
24+
if (!checkMode) {
25+
console.info(`Update package.json...`);
26+
}
2327

2428
const getModuleName = (importStr: string) => {
2529
const arr = importStr.split('/');
@@ -111,9 +115,16 @@ Object.entries(workspace.projects).forEach(([projectName, projectPath]) => {
111115

112116
Promise.all([handleTS(), handleSCSS()]).then(() => {
113117
outputJsonSync(packagePath, projectPackageJson);
114-
exec(`yarn prettier ${packagePath} --write`);
115-
exec('yarn util:sort-package-json');
116-
table.write([projectName, '✅']);
118+
execSync(`yarn prettier ${packagePath} --write`);
119+
execSync(`yarn sort-package-json "${packagePath}"`);
120+
if (!checkMode) {
121+
table.write([projectName, '✅']);
122+
} else {
123+
const out = execSync('git status --porcelain', { encoding: 'utf8' });
124+
if (out) {
125+
throw new Error('Make sure all files has been committed!');
126+
}
127+
}
117128
});
118129
}
119130
});

0 commit comments

Comments
 (0)