forked from kriasoft/react-starter-kit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Combine deployment scripts into a single; remove git-repository depen…
…dency (kriasoft#1127)
- Loading branch information
Showing
9 changed files
with
123 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/** | ||
* React Starter Kit (https://www.reactstarterkit.com/) | ||
* | ||
* Copyright © 2014-present Kriasoft, LLC. All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE.txt file in the root directory of this source tree. | ||
*/ | ||
|
||
import path from 'path'; | ||
import fetch from 'node-fetch'; | ||
import { spawn } from './lib/cp'; | ||
import { makeDir } from './lib/fs'; | ||
import run from './run'; | ||
|
||
// GitHub Pages | ||
const remote = { | ||
name: 'github', | ||
url: 'https://github.com/<user>/<repo>.git', | ||
branch: 'gh-pages', | ||
website: 'https://<user>.github.io/<repo>/', | ||
static: true, | ||
}; | ||
|
||
// Azure Web Apps | ||
// const remote = { | ||
// name: 'azure', | ||
// url: 'https://<user>@<app>.scm.azurewebsites.net:443/<app>.git', | ||
// branch: 'master', | ||
// website: `http://<app>.azurewebsites.net`, | ||
// }; | ||
|
||
const options = { | ||
cwd: path.resolve(__dirname, '../build', remote.static ? 'public' : ''), | ||
stdio: ['ignore', 'inherit', 'inherit'], | ||
}; | ||
|
||
/** | ||
* Deploy the contents of the `/build` folder to a remote server via Git. | ||
*/ | ||
async function deploy() { | ||
// Initialize a new repository | ||
await makeDir('build/public'); | ||
await spawn('git', ['init', '--quiet'], options); | ||
|
||
// Changing a remote's URL | ||
let isRemoteExists = false; | ||
try { | ||
await spawn('git', ['config', '--get', `remote.${remote.name}.url`], options); | ||
isRemoteExists = true; | ||
} catch (error) { | ||
/* skip */ | ||
} | ||
await spawn('git', ['remote', isRemoteExists ? 'set-url' : 'add', remote.name, remote.url], options); | ||
|
||
// Fetch the remote repository if it exists | ||
let isRefExists = false; | ||
try { | ||
await spawn('git', ['ls-remote', '--exit-code', remote.url, remote.branch], options); | ||
isRefExists = true; | ||
} catch (error) { | ||
/* skip */ | ||
} | ||
if (isRefExists) { | ||
await spawn('git', ['fetch', remote.name], options); | ||
await spawn('git', ['reset', `${remote.name}/${remote.branch}`, '--hard'], options); | ||
await spawn('git', ['clean', '--force'], options); | ||
} | ||
|
||
// Build the project in RELEASE mode which | ||
// generates optimized and minimized bundles | ||
process.argv.push('--release'); | ||
if (remote.static) process.argv.push('--static'); | ||
await run(require('./build').default); | ||
|
||
// Push the contents of the build folder to the remote server via Git | ||
await spawn('git', ['add', '.', '--all'], options); | ||
await spawn('git', ['commit', '--message', `Update ${new Date().toISOString()}`], options); | ||
await spawn('git', ['push', remote.name, `master:${remote.branch}`, '--force', '--set-upstream'], options); | ||
|
||
// Check if the site was successfully deployed | ||
const response = await fetch(remote.website); | ||
console.log(`${remote.website} => ${response.status} ${response.statusText}`); | ||
} | ||
|
||
export default deploy; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/** | ||
* React Starter Kit (https://www.reactstarterkit.com/) | ||
* | ||
* Copyright © 2014-present Kriasoft, LLC. All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE.txt file in the root directory of this source tree. | ||
*/ | ||
|
||
import cp from 'child_process'; | ||
|
||
export const spawn = (command, args, options) => new Promise((resolve, reject) => { | ||
cp.spawn(command, args, options).on('close', (code) => { | ||
if (code === 0) { | ||
resolve(); | ||
} else { | ||
reject(new Error(`${command} ${args.join(' ')} => ${code} (error)`)); | ||
} | ||
}); | ||
}); | ||
|
||
export default { spawn }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2949,10 +2949,6 @@ getpass@^0.1.1: | |
dependencies: | ||
assert-plus "^1.0.0" | ||
|
||
git-repository@^0.1.4: | ||
version "0.1.4" | ||
resolved "https://registry.yarnpkg.com/git-repository/-/git-repository-0.1.4.tgz#678391ab6e0c8b3c24f73762ecebb63c769474ac" | ||
|
||
glob-base@^0.3.0: | ||
version "0.3.0" | ||
resolved "https://registry.yarnpkg.com/glob-base/-/glob-base-0.3.0.tgz#dbb164f6221b1c0b1ccf82aea328b497df0ea3c4" | ||
|
@@ -4041,7 +4037,7 @@ lodash.uniq@^4.3.0: | |
version "4.5.0" | ||
resolved "https://registry.yarnpkg.com/lodash.uniq/-/lodash.uniq-4.5.0.tgz#d0225373aeb652adc1bc82e4945339a842754773" | ||
|
||
[email protected]: | ||
[email protected], lodash@^4.2.0: | ||
version "4.12.0" | ||
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.12.0.tgz#2bd6dc46a040f59e686c972ed21d93dc59053258" | ||
|
||
|
@@ -4053,7 +4049,7 @@ lodash@^3.10.1: | |
version "3.10.1" | ||
resolved "https://registry.yarnpkg.com/lodash/-/lodash-3.10.1.tgz#5bf45e8e49ba4189e17d482789dfd15bd140b7b6" | ||
|
||
lodash@^4.0.0, lodash@^4.1.0, lodash@^4.14.0, lodash@^4.17.2, lodash@^4.17.4, lodash@^4.2.0, lodash@^4.3.0, lodash@^4.5.1, lodash@^4.6.1: | ||
lodash@^4.0.0, lodash@^4.1.0, lodash@^4.14.0, lodash@^4.17.2, lodash@^4.17.4, lodash@^4.3.0, lodash@^4.5.1, lodash@^4.6.1: | ||
version "4.17.4" | ||
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.4.tgz#78203a4d1c328ae1d86dca6460e369b57f4055ae" | ||
|
||
|