File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ const fs = require ( 'fs' ) ;
2+ const path = require ( 'path' ) ;
3+
4+ const USAGE = "Usage: node cp.js [SOURCE_FILE] [DESTINATION_DIR]\n" ;
5+
6+ const args = process . argv . slice ( 2 ) ;
7+
8+ if ( args . length != 2 ) {
9+ console . error ( USAGE ) ;
10+ throw new SyntaxError ( ) ;
11+ }
12+ const src = args [ 0 ] ;
13+ const dest = args [ 1 ] ;
14+
15+ if ( src . includes ( "*" ) || dest . includes ( "*" ) ) {
16+ throw new SyntaxError ( "globbing is not supported" ) ;
17+ }
18+
19+
20+
21+ if ( ! ( fs . existsSync ( src ) && fs . statSync ( src ) . isFile ( ) ) ) {
22+ throw new TypeError ( `${ src } is not a file` ) ;
23+ }
24+
25+ if ( ! ( fs . existsSync ( dest ) && fs . statSync ( dest ) . isDirectory ( ) ) ) {
26+ throw new TypeError ( `${ dest } is not a directory` ) ;
27+ }
28+
29+ fs . copyFileSync ( src , path . join ( dest , path . basename ( src ) ) ) ;
Original file line number Diff line number Diff line change 1+ const fs = require ( 'fs' ) ;
2+
3+ const WARNINGS_ON = true ;
4+
5+ const USAGE = "Usage: node mkdir.js [DIR_NAME]\n" ;
6+
7+ const args = process . argv . slice ( 2 ) ;
8+
9+ if ( args . length != 1 ) {
10+ console . error ( USAGE ) ;
11+ throw new SyntaxError ( ) ;
12+ }
13+ const dir = args [ 0 ] ;
14+
15+ if ( dir . includes ( "*" ) ) {
16+ throw new SyntaxError ( "globbing is not supported" ) ;
17+ }
18+
19+ if ( fs . existsSync ( dir ) ) {
20+ if ( fs . statSync ( dir ) . isFile ( ) ) {
21+ throw new Error ( `${ dir } is a file` ) ;
22+ }
23+ fs . statSync ( dir ) . isDirectory ( ) && WARNINGS_ON && console . warn ( `${ dir } already exists, doing nothing` ) ;
24+ return ;
25+ }
26+
27+ fs . mkdirSync ( dir ) ;
Original file line number Diff line number Diff line change 77 "license" : " MIT" ,
88 "private" : true ,
99 "scripts" : {
10+ "cp" : " node .github/cp.js" ,
11+ "mkdir" : " node .github/mkdir.js" ,
1012 "build" : " yarn run tsc" ,
11- "dev " : " yarn build && node ./dist/test.js " ,
13+ "dist " : " yarn build && yarn cp ./src/ProjectExport.d.ts dist " ,
1214 "test" : " mocha"
1315 },
1416 "dependencies" : {
You can’t perform that action at this time.
0 commit comments