This repository has been archived by the owner on Aug 17, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.js
57 lines (48 loc) · 1.89 KB
/
deploy.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/**
* React Starter Kit (https://www.reactstarterkit.com/)
*
* Copyright © 2014-2016 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 GitRepo from 'git-repository';
import run from './run';
import fetch from './lib/fetch';
// TODO: Update deployment URL
// For more information visit http://gitolite.com/deploy.html
const getRemote = (slot) => ({
name: slot || 'production',
url: `https://example${slot ? `-${slot}` : ''}.scm.azurewebsites.net:443/example.git`,
website: `http://example${slot ? `-${slot}` : ''}.azurewebsites.net`,
});
/**
* Deploy the contents of the `/build` folder to a remote
* server via Git. Example: `npm run deploy -- production`
*/
async function deploy() {
// By default deploy to the staging deployment slot
const remote = getRemote(process.argv.includes('--production') ? null : 'staging');
// Initialize a new Git repository inside the `/build` folder
// if it doesn't exist yet
const repo = await GitRepo.open('build', { init: true });
await repo.setRemote(remote.name, remote.url);
// Fetch the remote repository if it exists
if ((await repo.hasRef(remote.url, 'master'))) {
await repo.fetch(remote.name);
await repo.reset(`${remote.name}/master`, { hard: true });
await repo.clean({ force: true });
}
// Build the project in RELEASE mode which
// generates optimized and minimized bundles
process.argv.push('--release');
await run(require('./build'));
// Push the contents of the build folder to the remote server via Git
await repo.add('--all .');
await repo.commit('Update');
await repo.push(remote.name, 'master');
// Check if the site was successfully deployed
const response = await fetch(remote.website);
console.log(`${remote.website} -> ${response.statusCode}`);
}
export default deploy;