11import arg from 'arg' ;
22import fs from 'fs' ;
33import path from 'path' ;
4- import clc from " cli-color" ;
4+ import clc from ' cli-color' ;
55import { spawn } from 'child_process' ;
66
77import normalizeUrl from './os' ;
@@ -19,10 +19,10 @@ function parseArgumentsIntoOptions(rawArgs) {
1919 '--no-bundle' : Boolean ,
2020 '--analyze' : Boolean ,
2121 '--port' : Number ,
22- '--ssr' : Boolean ,
22+ '--ssr' : Boolean
2323 } ,
2424 {
25- argv : rawArgs . slice ( 2 ) ,
25+ argv : rawArgs . slice ( 2 )
2626 }
2727 ) ;
2828 const argsList = removeUnneccesaryValueInObject ( {
@@ -32,17 +32,18 @@ function parseArgumentsIntoOptions(rawArgs) {
3232 noBundle : args [ '--no-bundle' ] ,
3333 analyze : args [ '--analyze' ] ,
3434 configFile : args [ '--config' ] ,
35- ssr : args [ '--ssr' ] ,
35+ ssr : args [ '--ssr' ]
3636 } ) ;
3737
3838 return argsList ;
3939}
4040
4141function getVoltranConfigs ( configFile ) {
42- const normalizePath = normalizeUrl ( path . resolve ( __dirname ) ) ;
43- const dirName = normalizePath . indexOf ( 'node_modules' ) > - 1 ?
44- normalizePath . split ( '/node_modules' ) [ 0 ] :
45- normalizePath . split ( 'voltran/lib' ) [ 0 ] + 'voltran' ;
42+ const normalizePath = normalizeUrl ( path . resolve ( __dirname ) ) ;
43+ const dirName =
44+ normalizePath . indexOf ( 'node_modules' ) > - 1
45+ ? normalizePath . split ( '/node_modules' ) [ 0 ]
46+ : `${ normalizePath . split ( 'voltran/lib' ) [ 0 ] } voltran` ;
4647 const voltranConfigs = require ( path . resolve ( dirName , configFile ) ) ;
4748
4849 return voltranConfigs ;
@@ -68,35 +69,40 @@ function runDevelopmentMode() {
6869function runProductionMode ( voltranConfigs , onlyBundle ) {
6970 const bundle = require ( '../src/tools/bundle' ) ;
7071
71- bundle ( )
72- . then ( ( res ) => {
73- console . log ( clc . green ( 'Bundle is completed.\n' , `File: ${ voltranConfigs . distFolder } /server/server.js` ) ) ;
72+ bundle ( ) . then ( ( ) => {
73+ console . log (
74+ clc . green ( 'Bundle is completed.\n' , `File: ${ voltranConfigs . distFolder } /server/server.js` )
75+ ) ;
7476
75- if ( ! onlyBundle ) {
76- serve ( voltranConfigs ) ;
77- }
78- } ) ;
77+ if ( ! onlyBundle ) {
78+ serve ( voltranConfigs ) ;
79+ }
80+ } ) ;
7981}
8082
8183function serve ( voltranConfigs ) {
8284 console . log ( clc . green ( 'Project Serve is starting...' ) ) ;
8385
84- const out = spawn ( 'node' , [
85- '-r' ,
86- 'source-map-support/register' ,
87- '--max-http-header-size=20480' ,
88- `${ voltranConfigs . distFolder } /server/server.js`
89- ] , { env : { 'NODE_ENV' : 'production' , ...process . env } } ) ;
86+ const out = spawn (
87+ 'node' ,
88+ [
89+ '-r' ,
90+ 'source-map-support/register' ,
91+ '--max-http-header-size=20480' ,
92+ `${ voltranConfigs . distFolder } /server/server.js`
93+ ] ,
94+ { env : { NODE_ENV : 'production' , ...process . env } }
95+ ) ;
9096
91- out . stdout . on ( 'data' , ( data ) => {
97+ out . stdout . on ( 'data' , data => {
9298 console . log ( data . toString ( ) ) ;
9399 } ) ;
94100
95- out . stderr . on ( 'data' , ( data ) => {
101+ out . stderr . on ( 'data' , data => {
96102 console . error ( data . toString ( ) ) ;
97103 } ) ;
98104
99- out . on ( 'close' , ( code ) => {
105+ out . on ( 'close' , code => {
100106 console . log ( `child process exited with code ${ code } ` ) ;
101107 } ) ;
102108}
@@ -123,17 +129,17 @@ export function cli(args) {
123129 if ( isValid ) {
124130 const createdConfig = `module.exports = ${ JSON . stringify ( mergeAllConfigs ) } ` ;
125131
126- fs . writeFile ( path . resolve ( __dirname , '../voltran.config.js' ) , createdConfig , function ( err ) {
132+ fs . writeFile ( path . resolve ( __dirname , '../voltran.config.js' ) , createdConfig , function ( err ) {
127133 if ( err ) throw err ;
128134
129135 console . log ( 'File is created successfully.' , mergeAllConfigs . dev ) ;
130136
131137 if ( mergeAllConfigs . dev ) {
132138 runDevelopmentMode ( ) ;
133139 } else {
134- argumentList . noBundle ?
135- serve ( voltranConfigs ) :
136- runProductionMode ( mergeAllConfigs , argumentList . bundle ) ;
140+ argumentList . noBundle
141+ ? serve ( voltranConfigs )
142+ : runProductionMode ( mergeAllConfigs , argumentList . bundle ) ;
137143 }
138144 } ) ;
139145 } else {
0 commit comments