File tree Expand file tree Collapse file tree 1 file changed +41
-0
lines changed
Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change 1+ const { watch } = require ( 'cpx' ) ;
2+ const { resolve } = require ( 'path' ) ;
3+ const packageJson = require ( './../package.json' ) ;
4+
5+ const readline = require ( 'readline' ) ;
6+
7+ const rl = readline . createInterface ( {
8+ input : process . stdin ,
9+ output : process . stdout
10+ } ) ;
11+
12+ const PROJECT_DIR = resolve ( __dirname , './../' ) ;
13+ let TARGET_DIR = process . env . TARGET_DIR ;
14+
15+ if ( ! TARGET_DIR ) {
16+ console . error ( 'Missing TARGET_DIR process env, aborting!' ) ;
17+ console . error ( 'EXAMPLE USAGE: TARGET_DIR=/Users/YOU/Documents/someproject npm run watchcpx' ) ;
18+ process . exit ( 1 ) ;
19+ }
20+
21+ if ( ! TARGET_DIR . includes ( 'node_modules' ) ) {
22+ TARGET_DIR = `${ TARGET_DIR } /node_modules/${ packageJson . name } ` ;
23+ }
24+
25+
26+ rl . question ( `Watch for changes in '${ PROJECT_DIR } ' and copy to '${ TARGET_DIR } '? (y/n): ` , ( answer ) => {
27+ if ( answer . toLowerCase ( ) === 'y' ) {
28+ console . log ( 'For the watch! (watching has begun)' ) ;
29+ const watcher = watch ( PROJECT_DIR + '/**/*.*' , TARGET_DIR , { verbose : true } ) ;
30+ watcher . on ( 'copy' , ( e ) => {
31+ if ( ! e . srcPath . startsWith ( 'node_modules' ) ) {
32+ console . log ( `Copied ${ e . srcPath } to ${ e . dstPath } ` ) ;
33+ }
34+ } ) ;
35+ } else {
36+ console . log ( 'Aborting watch.' ) ;
37+ process . exit ( ) ;
38+ }
39+ rl . close ( ) ;
40+ } ) ;
41+
You can’t perform that action at this time.
0 commit comments