Skip to content

Commit e76516d

Browse files
authored
Merge pull request #1 from react-storefront-community/feature/xdn
Add option to deploy to the Moovweb XDN
2 parents bf45530 + 407b755 commit e76516d

15 files changed

+2811
-1630
lines changed

.prettierrc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"singleQuote": true,
3+
"semi": false,
4+
"trailingComma": "es5",
5+
"printWidth": 100
6+
}

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,24 @@
11
# create-react-storefront
2+
23
A CLI for creating new apps based on react-storefront
4+
5+
## Usage
6+
7+
```
8+
npm create react-storefront (app-name)
9+
```
10+
11+
To accept all of the defaults, run:
12+
13+
```
14+
npm create react-storefront (app-name) --yes
15+
```
16+
17+
## Development
18+
19+
To run this app in development:
20+
21+
```
22+
npm i
23+
npm start
24+
```

index.js

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,21 +53,14 @@ const argv = require('yargs')
5353
const returnedYargs = yargs
5454
.positional('app-name', {
5555
describe: 'A name for the new app',
56-
type: 'string'
56+
type: 'string',
5757
})
5858
.option('yes', {
5959
describe: 'Run in non-interactive mode, accepting all defaults.',
6060
default: false,
61-
type: 'boolean'
61+
type: 'boolean',
6262
})
6363
.alias('yes', 'y')
64-
.option('branch', {
65-
describe:
66-
'Use a specific branch from react-storefront-starter-app as the app template (defaults to master). Example: --branch=commercial',
67-
default: 'master',
68-
type: 'string'
69-
})
70-
.alias('branch', 'b')
7164
.help()
7265
.alias('help', 'h')
7366
.wrap(yargs.terminalWidth())

lib/check-node-version.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ module.exports = function checkNodeVersion() {
55

66
if (parseInt(major) < 8) {
77
console.log('')
8-
console.log(`React Storefront requires node v8 or newer. You're running node ${process.version}.`)
8+
console.log(
9+
`React Storefront requires node v8 or newer. You're running node ${process.version}.`
10+
)
911
console.log('')
1012
process.exit(0)
1113
}

lib/config-defaults.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ module.exports = {
33
version: '1.0.0',
44
license: 'UNLICENSED',
55
private: true,
6-
createDirectory: true
6+
createDirectory: true,
77
}

lib/create-react-storefront-internal.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,16 @@ const createReactStorefrontInternal = async (options, userConfig) => {
2929
let spinner
3030

3131
try {
32-
spinner = ora('Downloading React Storefront app template...').start()
32+
const message = `Downloading React Storefront ${userConfig.xdn ? 'XDN ' : ''}template...`
33+
34+
spinner = ora(message).start()
3335

3436
await retrieveTemplate({
35-
branch: options.branch,
36-
targetPath: targetPath
37+
branch: userConfig.xdn ? 'commercial' : 'master',
38+
targetPath: targetPath,
3739
})
3840

39-
spinner.succeed('Downloading React Storefront app template... done.')
41+
spinner.succeed(`${message} done.`)
4042
} catch (e) {
4143
spinner.fail('Download failed')
4244
console.error(e)

lib/create-react-storefront.js

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,12 @@ const createReactStorefront = async options => {
1919
author: '',
2020
license: configDefaults.license,
2121
private: configDefaults.private,
22-
createDirectory: configDefaults.createDirectory
23-
}
24-
25-
if (!(await checkTemplateExistence(options.branch))) {
26-
console.log(
27-
`The ${options.branch} branch of react-storefront-starter-app does not exist. Check your spelling or use the default.`
28-
)
29-
return
22+
createDirectory: configDefaults.createDirectory,
3023
}
3124

3225
if (!options.yes) {
3326
try {
34-
userConfig = await promptForConfig({ configUpstream: false })
27+
userConfig = await promptForConfig(options)
3528
} catch (err) {
3629
console.log(err.message)
3730
return
@@ -43,5 +36,5 @@ const createReactStorefront = async options => {
4336

4437
module.exports = {
4538
_calculateStartCommand,
46-
createReactStorefront
39+
createReactStorefront,
4740
}

lib/input-validation.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ const isTargetPathValid = targetPath => {
1414
// not valid.
1515
if (
1616
fs.existsSync(targetPath) &&
17-
(!fs.statSync(targetPath).isDirectory() || fs.readdirSync(targetPath).length !== 0)) {
17+
(!fs.statSync(targetPath).isDirectory() || fs.readdirSync(targetPath).length !== 0)
18+
) {
1819
return false
1920
}
2021
return true
@@ -27,5 +28,5 @@ const isTargetPathValid = targetPath => {
2728
}
2829

2930
module.exports = {
30-
isTargetPathValid
31+
isTargetPathValid,
3132
}

lib/prompt-for-config.js

Lines changed: 22 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -24,124 +24,83 @@ const _requireInput = value => {
2424
}
2525
}
2626

27-
const defaultQuestions = [
27+
const questions = [
2828
{
2929
name: 'version',
3030
type: 'text',
3131
message: 'version',
32-
initial: configDefaults.version
32+
initial: configDefaults.version,
3333
},
3434
{
3535
name: 'description',
3636
type: 'text',
37-
message: 'description'
37+
message: 'description',
3838
},
3939
{
4040
name: 'repoUrl',
4141
type: 'text',
42-
message: 'repository url'
42+
message: 'repository url',
4343
},
4444
{
4545
name: 'author',
4646
type: 'text',
47-
message: 'author'
47+
message: 'author',
4848
},
4949
{
5050
name: 'license',
5151
type: 'text',
5252
message: 'license',
53-
initial: configDefaults.license
53+
initial: configDefaults.license,
5454
},
5555
{
5656
name: 'private',
5757
type: 'toggle',
5858
message: 'private',
5959
initial: configDefaults.private,
6060
active: configDefaults.private.toString(),
61-
inactive: 'false'
61+
inactive: 'false',
62+
},
63+
{
64+
name: 'xdn',
65+
message: 'Will you be deploying your app on the Moovweb XDN?',
66+
type: 'toggle',
67+
initial: false,
68+
active: 'yes',
69+
inactive: 'no',
6270
},
6371
{
6472
name: 'createDirectory',
6573
type: 'toggle',
66-
message: 'create a directory for this app?',
74+
message: 'Create a directory for this app?',
6775
initial: true,
6876
active: configDefaults.createDirectory ? 'yes' : 'no',
69-
inactive: 'no'
70-
}
71-
]
72-
73-
const upstreamQuestions = [
74-
{
75-
name: 'prodHostname',
76-
type: 'text',
77-
message: 'hostname for production site in moov cloud',
78-
validate: _requireInput
79-
},
80-
{
81-
name: 'prodUpstream',
82-
type: 'text',
83-
message: 'upstream hostname for production moov cloud',
84-
validate: _requireInput,
85-
initial: _initialProdUpstream
77+
inactive: 'no',
8678
},
87-
{
88-
name: 'devHostname',
89-
type: 'text',
90-
message: 'hostname for development site in moov cloud',
91-
validate: _requireInput,
92-
initial: _initialDevHostname
93-
},
94-
{
95-
name: 'devUpstream',
96-
type: 'text',
97-
message: 'upstream hostname for development moov cloud',
98-
validate: _requireInput,
99-
initial: _initialDevUpstream
100-
}
10179
]
10280

10381
/**
10482
* Prompt user for React Storefront configuration options.
10583
*/
106-
const promptForConfig = async ({ configUpstream }) => {
84+
const promptForConfig = async () => {
10785
console.log(
10886
`\nLet's create a new React Storefront app! First, I need you to provide some information for package.json...\n`
10987
)
11088

111-
const defaultQuestionResponses = await prompts(defaultQuestions)
89+
const answers = await prompts(questions)
11290

11391
// If the user has not provided all input, abort.
114-
if (Object.keys(defaultQuestionResponses).length !== defaultQuestions.length) {
92+
if (Object.keys(answers).length !== questions.length) {
11593
throw new Error('User configuration is incomplete. Aborting.')
11694
}
11795

118-
if (configUpstream) {
119-
console.log(
120-
"\nYou've indicated that you'd like to configure an upstream site. Let's do that now...\n"
121-
)
122-
123-
const upstreamQuestionResponses = await prompts(upstreamQuestions)
124-
125-
// If the user has not provided all input, abort.
126-
if (Object.keys(upstreamQuestionResponses).length !== upstreamQuestions.length) {
127-
throw new Error('User configuration is incomplete. Aborting.')
128-
}
129-
130-
// Merge the answers to the different sets of questions into one
131-
// configuration object. Note that this is acceptable only because all
132-
// questions have unique names. When adding questions, ensure that this
133-
// remains the case.
134-
_.merge(defaultQuestionResponses, upstreamQuestionResponses)
135-
}
136-
13796
// If upstream responses were given, they have been merged into this object.
138-
return defaultQuestionResponses
97+
return answers
13998
}
14099

141100
module.exports = {
142101
_initialDevHostname,
143102
_initialDevUpstream,
144103
_initialProdUpstream,
145104
_requireInput,
146-
promptForConfig
105+
promptForConfig,
147106
}

lib/retrieve-template.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const _calculateTemplateUrl = branch => {
2626
const _downloadTemplate = async ({ templateUrl } = {}) => {
2727
try {
2828
await download(templateUrl, process.cwd(), {
29-
filename: downloadedTemplateName
29+
filename: downloadedTemplateName,
3030
})
3131
} catch (err) {
3232
handleError(
@@ -43,7 +43,7 @@ const _getTemplatePath = () => {
4343
const _unzipTemplate = async targetPath => {
4444
try {
4545
await decompress(_getTemplatePath(), targetPath, {
46-
strip: 1
46+
strip: 1,
4747
})
4848
} catch (err) {
4949
handleError(err, 'Error decompressing the React Storefront template. See error stack above.')
@@ -75,7 +75,7 @@ const retrieveTemplate = async ({ branch, targetPath }) => {
7575
}
7676

7777
await _downloadTemplate({
78-
templateUrl: _calculateTemplateUrl(branch)
78+
templateUrl: _calculateTemplateUrl(branch),
7979
})
8080

8181
await _unzipTemplate(targetPath)
@@ -92,5 +92,5 @@ module.exports = {
9292
_getTemplatePath,
9393
_unzipTemplate,
9494
retrieveTemplate,
95-
checkTemplateExistence
95+
checkTemplateExistence,
9696
}

0 commit comments

Comments
 (0)