1
1
#!/usr/bin/env node
2
2
3
- const path = require ( 'path' )
4
- const fs = require ( 'fs' )
3
+ const path = require ( 'path' ) ;
4
+ const fs = require ( 'fs' ) ;
5
5
6
6
// Directory constants
7
- const scriptDirectory = __dirname
8
- const repoDirectory = path . join ( scriptDirectory , '..' )
9
- const libDirectory = path . join ( repoDirectory , 'lib' )
7
+ const scriptDirectory = __dirname ;
8
+ const repoDirectory = path . join ( scriptDirectory , '..' ) ;
9
+ const libDirectory = path . join ( repoDirectory , 'lib' ) ;
10
10
11
11
const helpText = `
12
12
Helper script to update lib/.gitignore for all .js files from .ts files.
@@ -19,7 +19,7 @@ Helper script to update lib/.gitignore for all .js files from .ts files.
19
19
20
20
NOTES FOR USAGE:
21
21
1. This script is tested to work on Ubuntu 18.04 LTS.
22
- `
22
+ ` ;
23
23
24
24
const gitignoreHeader = `# DO NOT EDIT, GENERATED BY: scripts/update_gitignore_for_tsc_output.js
25
25
@@ -30,57 +30,61 @@ const gitignoreHeader = `# DO NOT EDIT, GENERATED BY: scripts/update_gitignore_f
30
30
**/*.js.map
31
31
32
32
# Do not include .js files from .ts files
33
- `
33
+ ` ;
34
34
35
35
function main ( cliCommand ) {
36
36
if ( cliCommand === 'run' ) {
37
- console . log ( 'Generating lib/.gitignore ...' )
37
+ console . log ( 'Generating lib/.gitignore ...' ) ;
38
38
39
39
// Find all .ts files in lib/
40
- const directoriesToProcess = [ libDirectory ]
41
- const tsFiles = [ ]
40
+ const directoriesToProcess = [ libDirectory ] ;
41
+ const tsFiles = [ ] ;
42
42
while ( directoriesToProcess . length > 0 ) {
43
- const directory = directoriesToProcess . pop ( )
43
+ const directory = directoriesToProcess . pop ( ) ;
44
44
if ( ! fs . existsSync ( directory ) ) {
45
- throw new Error ( "Directory doesn't exist:" , directory )
45
+ throw new Error ( "Directory doesn't exist:" , directory ) ;
46
46
}
47
47
48
- const files = fs . readdirSync ( directory )
48
+ const files = fs . readdirSync ( directory ) ;
49
49
files . forEach ( ( file ) => {
50
- const filename = path . join ( directory , file )
51
- const stat = fs . lstatSync ( filename )
50
+ const filename = path . join ( directory , file ) ;
51
+ const stat = fs . lstatSync ( filename ) ;
52
52
if ( stat . isDirectory ( ) ) {
53
- directoriesToProcess . push ( filename )
53
+ directoriesToProcess . push ( filename ) ;
54
54
} else if ( filename . endsWith ( '.ts' ) && ! filename . endsWith ( '.d.ts' ) ) {
55
- tsFiles . push ( filename )
56
- console . log ( 'Found .ts file:' , filename )
55
+ tsFiles . push ( filename ) ;
56
+ console . log ( 'Found .ts file:' , filename ) ;
57
57
}
58
- } )
58
+ } ) ;
59
59
}
60
60
61
61
// Get paths of .js files to ignore
62
62
const jsFilesToIgnore = tsFiles . map ( ( filepath ) => {
63
63
// Cuts off `${libDirectory}/`
64
- const relativeTsPath = filepath . slice ( libDirectory . length + 1 )
64
+ const relativeTsPath = filepath . slice ( libDirectory . length + 1 ) ;
65
65
// Swaps .ts for .js file ending
66
- const relativeJsPath = relativeTsPath . slice ( 0 , relativeTsPath . length - 3 ) + '.js'
66
+ const relativeJsPath =
67
+ relativeTsPath . slice ( 0 , relativeTsPath . length - 3 ) + '.js' ;
67
68
// Always use POSIX-style path separators - .gitignore requires it
68
69
return relativeJsPath . split ( path . sep ) . join ( path . posix . sep ) ;
69
- } )
70
- const jsFilesToIgnoreString = jsFilesToIgnore . join ( '\n' )
71
- const libGitignorePath = path . join ( libDirectory , '.gitignore' )
72
- fs . writeFileSync ( libGitignorePath , gitignoreHeader + jsFilesToIgnoreString + '\n' )
73
- console . log ( 'DONE' )
70
+ } ) ;
71
+ const jsFilesToIgnoreString = jsFilesToIgnore . join ( '\n' ) ;
72
+ const libGitignorePath = path . join ( libDirectory , '.gitignore' ) ;
73
+ fs . writeFileSync (
74
+ libGitignorePath ,
75
+ gitignoreHeader + jsFilesToIgnoreString + '\n'
76
+ ) ;
77
+ console . log ( 'DONE' ) ;
74
78
} else if ( [ 'help' , '--help' , '-h' , undefined ] . includes ( cliCommand ) ) {
75
- console . log ( helpText )
79
+ console . log ( helpText ) ;
76
80
} else {
77
- console . log ( `Unsupported command: ${ cliCommand } ` )
78
- console . log ( "Try running with 'help' to see supported commands." )
79
- process . exit ( 1 )
81
+ console . log ( `Unsupported command: ${ cliCommand } ` ) ;
82
+ console . log ( "Try running with 'help' to see supported commands." ) ;
83
+ process . exit ( 1 ) ;
80
84
}
81
85
}
82
86
83
87
// Main script logic
84
- const cliCommand = process . argv [ 2 ]
88
+ const cliCommand = process . argv [ 2 ] ;
85
89
// Start the bash app's main function
86
- main ( cliCommand )
90
+ main ( cliCommand ) ;
0 commit comments