Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8d2bbf8
commit cf8a5b9
Showing
6 changed files
with
174 additions
and
14 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 |
---|---|---|
@@ -1,9 +1,13 @@ | ||
// https://github.com/facebook/flow/issues/1192 - build script guarantees SPORT is never null or undefined | ||
declare class process { | ||
static argv: string[]; | ||
|
||
static env: { | ||
SPORT: string, | ||
[string]: ?string, | ||
}; | ||
|
||
static exit(code: number): void; | ||
|
||
static hrtime(time?: [number, number]): [number, number]; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// @flow | ||
|
||
const { spawn } = require("child_process"); | ||
const cloudflare = require("cloudflare"); | ||
const build = require("./buildFuncs"); | ||
const cloudflareConfig = require("../../../.config/cloudflare.json"); | ||
|
||
const getSubdomain = () => { | ||
if (process.argv[2] === "beta" || process.argv[2] === "play") { | ||
return process.argv[2]; | ||
} | ||
if (process.argv[2] === undefined) { | ||
return "play"; | ||
} | ||
throw new Error( | ||
`Invalid subdomain ${ | ||
process.argv[2] | ||
} - should be either beta or play (default is play)`, | ||
); | ||
}; | ||
|
||
const mySpawn = (command, args) => { | ||
return new Promise(resolve => { | ||
console.log(`${command} ${args.join(" ")}`); | ||
|
||
const cmd = spawn(command, args, { shell: true, stdio: "inherit" }); | ||
cmd.on("close", code => { | ||
if (code !== 0) { | ||
console.log(`child process exited with code ${code}`); | ||
process.exit(code); | ||
} | ||
resolve(); | ||
}); | ||
}); | ||
}; | ||
|
||
(async () => { | ||
const subdomain = getSubdomain(); | ||
const sport = build.getSport(); | ||
const domain = `${subdomain}.${sport}-gm.com`; | ||
|
||
console.log(`Deploying to ${domain}...`); | ||
|
||
// Copy gen first, so index.html never links to partial file | ||
console.log("Copying gen..."); | ||
await mySpawn("rsync", [ | ||
"-vhrl", | ||
"./build/gen/", | ||
`jersch50@garibaldi.dreamhost.com:/home/jersch50/${domain}/gen/`, | ||
]); | ||
|
||
console.log("Copying other files..."); | ||
const excludes = ["--exclude", "/gen"]; | ||
if (subdomain === "beta") { | ||
excludes.push("--exclude", "/sw.js*"); | ||
} | ||
await mySpawn("rsync", [ | ||
"-vhrl", | ||
"--delete", | ||
...excludes, | ||
"./build/", | ||
`jersch50@garibaldi.dreamhost.com:/home/jersch50/${domain}/`, | ||
]); | ||
|
||
if (subdomain !== "beta") { | ||
console.log("Invalidating Cloudflare cache..."); | ||
|
||
const zone = cloudflareConfig.zones[sport]; | ||
|
||
const cf = cloudflare({ | ||
email: "jdscheff@gmail.com", | ||
key: cloudflareConfig.apiKey, | ||
}); | ||
|
||
const response = await cf.zones.purgeCache(zone, { | ||
purge_everything: true, | ||
}); | ||
if (!response.success) { | ||
console.log(response); | ||
} | ||
} else { | ||
console.log("No Cloudfare cache invalidation needed in beta"); | ||
} | ||
|
||
console.log("\nDone!"); | ||
})(); |
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