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,7 +32,7 @@ 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 ;
@@ -65,35 +65,40 @@ function runDevelopmentMode() {
6565function runProductionMode ( voltranConfigs , onlyBundle ) {
6666 const bundle = require ( '../src/tools/bundle' ) ;
6767
68- bundle ( )
69- . then ( ( res ) => {
70- console . log ( clc . green ( 'Bundle is completed.\n' , `File: ${ voltranConfigs . distFolder } /server/server.js` ) ) ;
68+ bundle ( ) . then ( res => {
69+ console . log (
70+ clc . green ( 'Bundle is completed.\n' , `File: ${ voltranConfigs . distFolder } /server/server.js` )
71+ ) ;
7172
72- if ( ! onlyBundle ) {
73- serve ( voltranConfigs ) ;
74- }
75- } ) ;
73+ if ( ! onlyBundle ) {
74+ serve ( voltranConfigs ) ;
75+ }
76+ } ) ;
7677}
7778
7879function serve ( voltranConfigs ) {
7980 console . log ( clc . green ( 'Project Serve is starting...' ) ) ;
8081
81- const out = spawn ( 'node' , [
82- '-r' ,
83- 'source-map-support/register' ,
84- '--max-http-header-size=20480' ,
85- `${ voltranConfigs . distFolder } /server/server.js`
86- ] , { env : { 'NODE_ENV' : 'production' , ...process . env } } ) ;
82+ const out = spawn (
83+ 'node' ,
84+ [
85+ '-r' ,
86+ 'source-map-support/register' ,
87+ '--max-http-header-size=20480' ,
88+ `${ voltranConfigs . distFolder } /server/server.js`
89+ ] ,
90+ { env : { NODE_ENV : 'production' , ...process . env } }
91+ ) ;
8792
88- out . stdout . on ( 'data' , ( data ) => {
93+ out . stdout . on ( 'data' , data => {
8994 console . log ( data . toString ( ) ) ;
9095 } ) ;
9196
92- out . stderr . on ( 'data' , ( data ) => {
97+ out . stderr . on ( 'data' , data => {
9398 console . error ( data . toString ( ) ) ;
9499 } ) ;
95100
96- out . on ( 'close' , ( code ) => {
101+ out . on ( 'close' , code => {
97102 console . log ( `child process exited with code ${ code } ` ) ;
98103 } ) ;
99104}
@@ -110,7 +115,6 @@ function checkRequiredVariables(mergeConfigs) {
110115}
111116
112117export function cli ( args ) {
113- console . log ( 'SELAM' ) ;
114118 const argumentList = parseArgumentsIntoOptions ( args ) ;
115119 console . log ( clc . blue ( JSON . stringify ( argumentList ) ) ) ;
116120 const voltranConfigs = argumentList . configFile ? getVoltranConfigs ( argumentList . configFile ) : { } ;
@@ -121,17 +125,17 @@ export function cli(args) {
121125 if ( isValid ) {
122126 const createdConfig = `module.exports = ${ JSON . stringify ( mergeAllConfigs ) } ` ;
123127
124- fs . writeFile ( path . resolve ( __dirname , '../voltran.config.js' ) , createdConfig , function ( err ) {
128+ fs . writeFile ( path . resolve ( __dirname , '../voltran.config.js' ) , createdConfig , function ( err ) {
125129 if ( err ) throw err ;
126130
127131 console . log ( 'File is created successfully.' , mergeAllConfigs . dev ) ;
128132
129133 if ( mergeAllConfigs . dev ) {
130134 runDevelopmentMode ( ) ;
131135 } else {
132- argumentList . noBundle ?
133- serve ( voltranConfigs ) :
134- runProductionMode ( mergeAllConfigs , argumentList . bundle ) ;
136+ argumentList . noBundle
137+ ? serve ( voltranConfigs )
138+ : runProductionMode ( mergeAllConfigs , argumentList . bundle ) ;
135139 }
136140 } ) ;
137141 } else {
0 commit comments