Skip to content

Commit c4c73bb

Browse files
authored
Merge pull request #4 from react-storefront-community/kh-github-actions
Add github actions for deploying to staging/prod
2 parents cee56b0 + a4bf32d commit c4c73bb

File tree

6 files changed

+55
-5
lines changed

6 files changed

+55
-5
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
test/tmp
22
node_modules
3+
.idea/*

lib/create-react-storefront-internal.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
const { calculateReactStorefrontPath } = require('./utils')
22
const { isTargetPathValid } = require('./input-validation')
3-
const { processReactStorefrontConfigJsons, processPackageJson } = require('./template-processing')
3+
const {
4+
copyResources,
5+
processReactStorefrontConfigJsons,
6+
processPackageJson,
7+
} = require('./template-processing')
48
const { retrieveTemplate } = require('./retrieve-template')
59
const ora = require('ora')
610
const util = require('util')
@@ -69,6 +73,16 @@ const createReactStorefrontInternal = async (options, userConfig) => {
6973
process.exit(1)
7074
}
7175

76+
try {
77+
spinner = ora('Copying resources...').start()
78+
await copyResources(targetPath, userConfig)
79+
spinner.succeed('Copying resources... done.')
80+
} catch (e) {
81+
spinner.fail('Failed')
82+
console.error(e)
83+
process.exit(1)
84+
}
85+
7286
ora(`React Storefront app created.`).succeed()
7387

7488
console.log('')

lib/retrieve-template.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ const handleError = require('./handle-error')
55
const path = require('path')
66
const util = require('util')
77
const urlExists = util.promisify(require('url-exists'))
8-
const defaultBranchName = 'master'
98
const downloadedTemplateName = 'react_storefront_template.zip'
109

1110
const _deleteTemplate = () => {

lib/template-processing.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const fs = require('fs')
1+
const fs = require('fs-extra')
22
const handleError = require('./handle-error')
33
const os = require('os')
44
const path = require('path')
@@ -77,15 +77,27 @@ const processPackageJson = (name, targetPath, { xdn, ...config } = {}) => {
7777
delete packageJson.scripts['rsf:link']
7878
}
7979
// remove react-storefront team from the deploy script, so it defaults to the user's own team:
80-
packageJson.scripts.deploy = packageJson.scripts.deploy.replace('xdn deploy react-storefront', 'xdn deploy')
80+
packageJson.scripts.deploy = packageJson.scripts.deploy.replace(
81+
'xdn deploy react-storefront --environment=production',
82+
'xdn deploy'
83+
)
8184

8285
_writeConfigJson(packageJsonPath, packageJson)
8386
}
8487

88+
const copyResources = async (targetPath, { xdn }) => {
89+
if (xdn) {
90+
await fs.copy(path.join(targetPath, 'crs-resources'), targetPath)
91+
await fs.unlink(path.join(targetPath, '.github', 'workflows', 'xdn.yml'))
92+
await fs.unlink(path.join(targetPath, 'crs-resources'))
93+
}
94+
}
95+
8596
module.exports = {
8697
_processReactStorefrontConfigJson,
8798
_readConfigJson,
8899
_writeConfigJson,
89100
processReactStorefrontConfigJsons,
90101
processPackageJson,
102+
copyResources,
91103
}

package-lock.json

Lines changed: 24 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"chalk": "^2.4.2",
88
"decompress": "^4.2.0",
99
"download": "^7.1.0",
10+
"fs-extra": "^8.1.0",
1011
"lodash": "^4.17.11",
1112
"ora": "^3.4.0",
1213
"prompts": "^1.1.0",

0 commit comments

Comments
 (0)