1
- import { exec } from 'child_process' ;
1
+ import { exec , execSync } from 'child_process' ;
2
2
import path from 'path' ;
3
3
4
4
import { existsSync , outputJsonSync , readdirSync , readFileSync , readJsonSync , statSync } from 'fs-extra' ;
@@ -13,13 +13,17 @@ const ROOT_PATH = path.join(__dirname, '..');
13
13
const TSCONFIG_OPTIONS = [ 'tsconfig.app.json' , 'tsconfig.lib.json' ] ;
14
14
const SKIP_IMPORT = [ '.' , 'packages' , 'vscode' ] ;
15
15
16
+ const checkMode = process . argv . includes ( '--check' ) ;
17
+
16
18
const table = createStream ( {
17
19
columnDefault : { width : 50 } ,
18
20
columnCount : 2 ,
19
21
columns : [ { width : 40 } , { width : 10 , alignment : 'center' } ] ,
20
22
} ) ;
21
23
22
- console . info ( `Update package.json...` ) ;
24
+ if ( ! checkMode ) {
25
+ console . info ( `Update package.json...` ) ;
26
+ }
23
27
24
28
const getModuleName = ( importStr : string ) => {
25
29
const arr = importStr . split ( '/' ) ;
@@ -111,9 +115,16 @@ Object.entries(workspace.projects).forEach(([projectName, projectPath]) => {
111
115
112
116
Promise . all ( [ handleTS ( ) , handleSCSS ( ) ] ) . then ( ( ) => {
113
117
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
+ }
117
128
} ) ;
118
129
}
119
130
} ) ;
0 commit comments