11const fs = require ( "fs" ) ;
22const path = require ( "path" ) ;
33const chalk = require ( "chalk" ) ;
4- const { UNNECESSORYFOLDERS } = require ( "./constants" ) ;
4+ const {
5+ UNNECESSORY_FOLDERS_FOR_DEV ,
6+ UNNECESSORY_FOLDERS_FOR_PROD
7+ } = require ( "./constants" ) ;
58
69/**
710 * @summary copies the directory content from source to destination directory
811 * @param {String } source path of source file
912 * @param {String } destination path of destination file
13+ * @param {boolean } prod tells if user require prod environment
1014 */
11- function copyDirectory ( source , destination ) {
15+ function copyDirectory ( source , destination , prod ) {
16+ let UNNECESSORY_FOLDERS = prod
17+ ? UNNECESSORY_FOLDERS_FOR_PROD
18+ : UNNECESSORY_FOLDERS_FOR_DEV ;
19+
1220 createDirectory ( destination ) ;
1321
1422 var content = fs . readdirSync ( source ) ;
1523 for ( let i = 0 ; i < content . length ; i ++ ) {
1624 let currentFile = fs . lstatSync ( path . join ( source , content [ i ] ) ) ;
1725
18- if ( String ( content [ i ] ) . match ( UNNECESSORYFOLDERS ) ) {
26+ if ( String ( content [ i ] ) . match ( UNNECESSORY_FOLDERS ) ) {
1927 continue ;
2028 } else if ( currentFile . isDirectory ( ) ) {
2129 copyDirectory (
2230 path . join ( source , content [ i ] ) ,
23- path . join ( destination , content [ i ] )
31+ path . join ( destination , content [ i ] ) ,
32+ prod
2433 ) ;
2534 } else if ( currentFile . isSymbolicLink ( ) ) {
2635 var symlink = fs . readlinkSync ( source , content [ i ] ) ;
2736 fs . symlinkSync ( symlink , path . join ( destination , content [ i ] ) ) ;
2837 } else {
2938 copyFile (
3039 path . join ( source , content [ i ] ) ,
31- path . join ( destination , content [ i ] )
40+ path . join ( destination , content [ i ] ) ,
41+ prod
3242 ) ;
3343 }
3444 }
@@ -38,11 +48,15 @@ function copyDirectory(source, destination) {
3848 * @summary copies the file content from source to destination file
3949 * @param {String } source path of source file
4050 * @param {String } destination path of destination file
51+ * @param {boolean } prod tells if user require prod environment
4152 */
42- function copyFile ( source , destination ) {
53+ function copyFile ( source , destination , prod ) {
4354 var inputFile , outputFile ;
4455 if ( source . match ( ".json$" ) ) {
4556 inputFile = JSON . parse ( fs . readFileSync ( source , "utf8" ) ) ;
57+ if ( prod && source . match ( "package.json$" ) ) {
58+ inputFile . scripts . start = "node server/" ;
59+ }
4660 fs . writeFileSync ( destination , JSON . stringify ( inputFile , null , 2 ) , "utf8" ) ;
4761 } else {
4862 inputFile = fs . createReadStream ( source ) ;
0 commit comments