Skip to content

Commit d38c08f

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

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
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)