@@ -28,6 +28,7 @@ optParser.addOption('b', 'binary', 'boolean', 'Pack binary');
28
28
optParser . addOption ( 'np' , 'no-pseudo' , 'boolean' , 'Whether use pseudo library' ) ;
29
29
optParser . addOption ( 'wf' , 'with-ffmpeg' , 'boolean' , 'Whether pack ffmpeg library' ) ;
30
30
optParser . addOption ( 'h' , 'help' , 'boolean' , 'Show help' ) ;
31
+ optParser . addOption ( 'li' , 'lint' , 'boolean' , 'Whether lint code with eslint' ) ;
31
32
32
33
const options = optParser . parseArgs ( process . argv ) ;
33
34
@@ -58,6 +59,26 @@ if (options.help || Object.keys(options).length === 0) {
58
59
process . exit ( 0 ) ;
59
60
}
60
61
62
+ if ( options . lint ) {
63
+ // Check lint deps
64
+ const lintDeps = [ 'eslint' ] ;
65
+ console . log ( 'Checking lint dependencies...' ) ;
66
+ const npmRoot = execSync ( `npm root -g` ) . toString ( ) . trim ( ) ;
67
+ const missingLintDeps = lintDeps . filter ( ( dep ) => {
68
+ return ! fs . existsSync ( path . join ( npmRoot , dep ) ) ;
69
+ } ) ;
70
+
71
+ if ( missingLintDeps . length === 0 ) {
72
+ console . log ( 'Lint dependencies OK.' ) ;
73
+ } else {
74
+ for ( const dep of missingLintDeps ) {
75
+ console . log ( 'Installing eslint' ) ;
76
+ execSync ( `npm install eslint --global --save-dev` ) ;
77
+ execSync ( 'npm init --yes' ) ;
78
+ }
79
+ }
80
+ }
81
+
61
82
var npmInstallOption = '' ;
62
83
if ( process . getuid && process . getuid ( ) === 0 ) {
63
84
// Running as root
@@ -237,9 +258,30 @@ function packCommon(target) {
237
258
}
238
259
}
239
260
if ( common . files ) {
261
+ let eslint ;
262
+ if ( options . lint ) {
263
+ const { ESLint } = require ( 'eslint' ) ;
264
+ eslint = new ESLint ( { overrideConfigFile : `${ rootDir } /source/.eslintrc.json` } ) ;
265
+ }
240
266
// Copy common files
241
267
for ( const file of common . files ) {
242
268
const filePath = path . join ( packSrc , file ) ;
269
+ const extname = path . extname ( filePath ) ;
270
+ if ( options . lint && extname === '.js' ) {
271
+ eslint . lintFiles ( filePath )
272
+ . then ( ( results ) => {
273
+ eslint . loadFormatter ( 'stylish' )
274
+ . then ( ( formatter ) => {
275
+ console . log ( formatter . format ( results ) ) ;
276
+ } )
277
+ . catch ( ( err ) => {
278
+ console . log ( err ) ;
279
+ } )
280
+ } )
281
+ . catch ( ( err ) => {
282
+ console . log ( err ) ;
283
+ } )
284
+ }
243
285
execSync ( `cp -a ${ filePath } ${ packDist } ` ) ;
244
286
}
245
287
}
0 commit comments