1- const { basename, resolve } = require ( 'path' ) ;
2- const os = require ( 'os' ) ;
1+ const chalk = require ( 'chalk' ) ;
32const changeCase = require ( 'change-case' ) ;
4- const inquirer = require ( 'inquirer' ) ;
53const execa = require ( 'execa' ) ;
6- const chalk = require ( 'chalk' ) ;
74const gitUserInfo = require ( 'git-user-info' ) ;
8- const isInvalidPath = require ( 'is-invalid-path ' ) ;
5+ const inquirer = require ( 'inquirer ' ) ;
96const isValidNpmName = require ( 'is-valid-npm-name' ) ;
7+ const os = require ( 'os' ) ;
108const pkg = require ( '../package.json' ) ;
11- const {
12- sampleBackends
13- } = require ( '@magento/pwa-buildpack/lib/cli/create-project' ) ;
14-
9+ const { basename, resolve} = require ( 'path' ) ;
10+ const { sampleBackends} = require ( '@magento/pwa-buildpack/lib/cli/create-project' ) ;
1511module . exports = async ( ) => {
1612 console . log ( chalk . greenBright ( `${ pkg . name } v${ pkg . version } ` ) ) ;
17- console . log (
18- chalk . white ( `Creating a ${ chalk . whiteBright ( 'PWA Studio' ) } project` )
19- ) ;
13+ console . log ( chalk . white ( `Creating a ${ chalk . whiteBright ( 'PWA Studio' ) } project` ) ) ;
2014 const userAgent = process . env . npm_config_user_agent || '' ;
2115 const isYarn = userAgent . includes ( 'yarn' ) ;
22-
2316 const questions = [
2417 {
25- name : 'directory' ,
26- message :
27- 'Project root directory (will be created if it does not exist)' ,
28- validate : dir =>
29- ! dir
30- ? 'Please enter a directory path'
31- : isInvalidPath ( dir )
32- ? 'Invalid directory path; contains illegal characters'
33- : true
18+ message : 'Project root directory (will be created if it does not exist)'
19+ , name : 'directory'
20+ , validate : dir => ! dir ? 'Please enter a directory path' : true
3421 } ,
3522 {
36- name : 'name' ,
37- message :
38- 'Short name of the project to put in the package.json "name" field' ,
39- validate : isValidNpmName ,
40- default : ( { directory } ) => basename ( directory )
23+ default : ( { directory} ) => basename ( directory )
24+ , message : 'Short name of the project to put in the package.json "name" field'
25+ , name : 'name'
26+ , validate : isValidNpmName
4127 } ,
4228 {
43- name : 'author' ,
44- message :
45- 'Name of the author to put in the package.json "author" field' ,
4629 default : ( ) => {
4730 const userInfo = os . userInfo ( ) ;
4831 let author = userInfo . username ;
49- const gitInfo = gitUserInfo ( {
50- path : resolve ( userInfo . homedir , '.gitconfig' )
51- } ) ;
52-
32+ const gitInfo = gitUserInfo ( { path : resolve ( userInfo . homedir , '.gitconfig' ) } ) ;
5333 if ( gitInfo ) {
5434 author = gitInfo . name || author ;
5535 if ( gitInfo . email ) {
@@ -58,61 +38,53 @@ module.exports = async () => {
5838 }
5939 return author ;
6040 }
41+ , message : 'Name of the author to put in the package.json "author" field'
42+ , name : 'author'
6143 } ,
6244 {
63- name : 'backendUrl' ,
64- type : 'list' ,
65- message :
66- 'Magento instance to use as a backend (will be added to `.env` file)' ,
6745 choices : sampleBackends . environments
6846 . map ( ( { name, description, url } ) => ( {
6947 name : description ,
7048 value : url ,
7149 short : name
7250 } ) )
73- . concat ( [
74- {
75- name :
76- 'Other (I will provide my own backing Magento instance)' ,
77- value : false ,
78- short : 'Other '
79- }
80- ] )
51+ . concat ( [ {
52+ name : 'Other (I will provide my own backing Magento instance)' ,
53+ value : false ,
54+ short : 'Other'
55+ } ] )
56+ , message : 'Magento instance to use as a backend (will be added to `.env` file) '
57+ , name : 'backendUrl'
58+ , type : 'list'
8159 } ,
8260 {
83- name : 'customBackendUrl' ,
84- message :
85- 'URL of a Magento instance to use as a backend (will be added to `.env` file)' ,
86- default : 'https://magento2.localhost' ,
87- when : ( { backendUrl } ) => ! backendUrl
61+ default : 'https://magento2.localhost'
62+ , message : 'URL of a Magento instance to use as a backend (will be added to `.env` file)'
63+ , name : 'customBackendUrl'
64+ , when : ( { backendUrl} ) => ! backendUrl
8865 } ,
8966 {
90- name : 'braintreeToken' ,
91- message :
92- 'Braintree API token to use to communicate with your Braintree instance (will be added to `.env` file)' ,
9367 default : 'sandbox_8yrzsvtm_s2bg8fs563crhqzk'
68+ , message : 'Braintree API token to use to communicate with your Braintree instance (will be added to `.env` file)'
69+ , name : 'braintreeToken'
9470 } ,
9571 {
96- name : 'npmClient' ,
97- type : 'list' ,
98- message : 'NPM package management client to use' ,
99- choices : [ 'npm' , 'yarn' ] ,
100- default : isYarn ? 'yarn' : 'npm '
72+ choices : [ 'npm' , 'yarn' ]
73+ , default : isYarn ? 'yarn' : 'npm'
74+ , message : 'NPM package management client to use'
75+ , name : 'npmClient'
76+ , type : 'list '
10177 } ,
10278 {
103- name : 'install' ,
104- type : 'confirm' ,
105- message : ( { npmClient } ) =>
106- `Install package dependencies with ${ npmClient } after creating project` ,
10779 default : true
80+ , message : ( { npmClient } ) => `Install package dependencies with ${ npmClient } after creating project`
81+ , name : 'install'
82+ , type : 'confirm'
10883 }
10984 ] ;
11085 let answers ;
111- try {
112- answers = await inquirer . prompt ( questions ) ;
113- } catch ( e ) {
114- console . error ( 'App creation cancelled.' ) ;
115- }
86+ try { answers = await inquirer . prompt ( questions ) ; }
87+ catch ( e ) { console . error ( 'App creation cancelled.' ) ; }
11688 answers . backendUrl = answers . backendUrl || answers . customBackendUrl ;
11789 const args = questions . reduce (
11890 ( args , q ) => {
@@ -131,19 +103,8 @@ module.exports = async () => {
131103 } ,
132104 [ 'create-project' , answers . directory , '--template' , '"venia-concept"' ]
133105 ) ;
134-
135106 const argsString = args . join ( ' ' ) ;
136-
137- console . log (
138- '\nRunning command: \n\n' +
139- chalk . whiteBright ( `buildpack ${ argsString } \n\n` )
140- ) ;
141-
142- const buildpackBinLoc = resolve (
143- require . resolve ( '@magento/pwa-buildpack' ) ,
144- '../../bin/buildpack'
145- ) ;
146- await execa . shell ( `${ buildpackBinLoc } ${ argsString } ` , {
147- stdio : 'inherit'
148- } ) ;
107+ console . log ( '\nRunning command: \n\n' + chalk . whiteBright ( `buildpack ${ argsString } \n\n` ) ) ;
108+ const buildpackBinLoc = resolve ( require . resolve ( '@magento/pwa-buildpack' ) , '../../bin/buildpack' ) ;
109+ await execa . shell ( `${ buildpackBinLoc } ${ argsString } ` , { stdio : 'inherit' } ) ;
149110} ;
0 commit comments