@@ -15,25 +15,20 @@ process.on('unhandledRejection', err => {
1515} ) ;
1616
1717const fs = require ( 'fs-extra' ) ;
18- const os = require ( 'os' ) ;
1918const path = require ( 'path' ) ;
2019const chalk = require ( 'chalk' ) ;
2120const shelljs = require ( '@devloco/create-react-wptheme-utils/shell-js' ) ;
22- const spawn = require ( 'react-dev-utils/crossSpawn' ) ;
2321
24- module . exports = function (
22+ const fnUpdateAppPackage = function (
23+ appPackage ,
2524 appPath ,
2625 appName ,
2726 verbose ,
2827 originalDirectory ,
2928 templateName ,
3029 readmeExists ,
31- useTypeScript ,
3230 useYarn
3331) {
34- const appPackage = require ( path . join ( appPath , 'package.json' ) ) ;
35- const reactSrcName = 'react-src' ;
36-
3732 let aOriginalDirectory = originalDirectory . replace ( / \\ / g, '/' ) . split ( '/' ) ;
3833 let originalThemeName = aOriginalDirectory [ aOriginalDirectory . length - 1 ] ;
3934
@@ -62,11 +57,22 @@ module.exports = function(
6257 // Set the app name correctly
6358 appPackage . name = originalThemeName ;
6459
65- // rewrite package.json
66- fs . writeFileSync (
67- path . join ( appPath , 'package.json' ) ,
68- JSON . stringify ( appPackage , null , 2 ) + os . EOL
69- ) ;
60+ return appPackage ;
61+ } ;
62+
63+ const fnFinish = function (
64+ appPackage ,
65+ appPath ,
66+ appName ,
67+ verbose ,
68+ originalDirectory ,
69+ templateName ,
70+ readmeExists ,
71+ useYarn
72+ ) {
73+ const reactSrcName = 'react-src' ;
74+ let aOriginalDirectory = originalDirectory . replace ( / \\ / g, '/' ) . split ( '/' ) ;
75+ let originalThemeName = aOriginalDirectory [ aOriginalDirectory . length - 1 ] ;
7076
7177 // Update the theme's style.css file with the Theme Name
7278 let styleCssFile = path . join ( appPath , '/public/style.css' ) ;
@@ -77,22 +83,6 @@ module.exports = function(
7783 ) ;
7884 fs . writeFileSync ( styleCssFile , result , 'utf8' , 'w' ) ;
7985
80- // To use TypeScript, we need the types from Facebook's react-scripts.
81- if ( useTypeScript === true ) {
82- let command = useYarn ? 'yarn add' : 'npm install' ;
83- let args = [ verbose && '--verbose' ] . filter ( e => e ) ;
84- args . push ( 'react-scripts' ) ;
85-
86- console . log ( `Installing react-scripts using: ${ command } ...` ) ;
87- console . log ( ) ;
88-
89- const proc = spawn . sync ( command , args , { stdio : 'inherit' } ) ;
90- if ( proc . status !== 0 ) {
91- console . error ( `\`${ command } ${ args . join ( ' ' ) } \` failed` ) ;
92- return ;
93- }
94- }
95-
9686 // if we're not on Windows, then try to chmod the folder so that the PHP portion of
9787 // the setup can complete (the webserver needs write access to package.json)
9888 if ( process . platform !== 'win32' ) {
@@ -139,6 +129,8 @@ module.exports = function(
139129
140130 // Change displayed command to yarn instead of yarnPkg
141131 const displayedCommand = useYarn ? 'yarn' : 'npm run' ;
132+ const buildCommandName = 'build' ;
133+ const startCommandName = 'start' ;
142134
143135 console . log ( ) ;
144136 console . log ( `Success! Created ${ originalThemeName } at ${ appPath } ` ) ;
@@ -171,3 +163,8 @@ module.exports = function(
171163 console . log ( ) ;
172164 console . log ( 'Happy hacking!' ) ;
173165} ;
166+
167+ module . exports = {
168+ fnFinish,
169+ fnUpdateAppPackage,
170+ } ;
0 commit comments