1+ #!/usr/bin/env node
2+ var program = require ( 'commander' ) ;
3+ var process = require ( 'process' ) ;
4+ var path = require ( 'path' ) ;
5+ var fse = require ( 'fs-extra' ) ;
6+ var package = require ( './package.json' ) ;
7+ var cac = require ( './index' ) ;
8+
9+ program
10+ . description ( package . description )
11+ . arguments ( '<file>' )
12+ . action ( function ( file ) {
13+ var fileText = fse . readFileSync ( file , 'utf8' ) ;
14+ var components = cac . getComponentsFromHtml ( fileText ) ;
15+ var generatedCount = 0 ;
16+
17+ components . forEach ( function ( component ) {
18+ var targetPath = path . join ( process . cwd ( ) , component . dashedName ) ;
19+ fse . removeSync ( targetPath ) ;
20+ fse . mkdirSync ( targetPath ) ;
21+
22+ var tsFilePath = path . join ( targetPath , component . dashedName + '.component.ts' ) ;
23+ var cssFilePath = path . join ( targetPath , component . dashedName + '.component.css' ) ;
24+ var htmlFilePath = path . join ( targetPath , component . dashedName + '.component.html' ) ;
25+ var specFilePath = path . join ( targetPath , component . dashedName + '.component.spec.ts' ) ;
26+
27+ fse . writeFileSync ( tsFilePath , component . ts , 'utf8' ) ;
28+ fse . writeFileSync ( cssFilePath , component . css , 'utf8' ) ;
29+ fse . writeFileSync ( htmlFilePath , component . html , 'utf8' ) ;
30+ fse . writeFileSync ( specFilePath , component . spec , 'utf8' ) ;
31+ generatedCount ++ ;
32+ } ) ;
33+
34+ console . log ( 'Generated ' + generatedCount + ' components, into ' + process . cwd ( ) ) ;
35+ } )
36+ . version ( package . version )
37+ . parse ( process . argv ) ;
38+
39+ // Check the program.args obj - if none, show help
40+ if ( program . args . length === 0 ) {
41+ program . help ( ) ;
42+ }
0 commit comments