This repository has been archived by the owner on Jul 26, 2021. It is now read-only.
-
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.
Add tests, update readme, consolidate host + bucket into domain, bump…
… to version 2
- Loading branch information
1 parent
12243ec
commit dee4169
Showing
14 changed files
with
403 additions
and
136 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,21 +1,17 @@ | ||
module.exports = { | ||
verbose: true, | ||
transform: { | ||
"^.+\\.ts$": "ts-jest" | ||
}, | ||
testRegex: "(/__tests__/.*|(\\.|/)(test|spec))\\.(js|ts)$", | ||
moduleDirectories: ["node_modules", "app"], | ||
moduleFileExtensions: ["ts", "js", "json", "node"], | ||
moduleNameMapper: { | ||
"\\.(css|eot|woff|woff2)$": "<rootDir>/app/spec/__mocks__/styleMock.js", | ||
"util/jss": "<rootDir>/app/spec/__mocks__/jssMock.js" | ||
'^.+\\.ts$': 'ts-jest' | ||
}, | ||
testRegex: 'test\\.ts$', | ||
moduleDirectories: ['node_modules', 'app'], | ||
moduleFileExtensions: ['ts', 'js', 'json', 'node'], | ||
globals: { | ||
"ts-jest": { | ||
tsConfigFile: "tsconfig.json" | ||
'ts-jest': { | ||
tsConfigFile: 'tsconfig.json' | ||
} | ||
}, | ||
roots: ["<rootDir>/app"], | ||
roots: ['<rootDir>/src'], | ||
collectCoverage: true, | ||
coveragePathIgnorePatterns: ["/node_modules"] | ||
coveragePathIgnorePatterns: ['/node_modules'] | ||
} |
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,129 @@ | ||
#!/usr/bin/env node | ||
|
||
import mri from 'mri' | ||
|
||
interface ParsedArgs { | ||
action: 'deploy' | 'undeploy' | 'promote' | ||
domain: string | ||
|
||
zone?: string | ||
distribution?: string | ||
channel?: string | ||
dir?: string | ||
} | ||
|
||
const errors = { | ||
domain: { | ||
req: 'Domain is required', | ||
char: "Domain can only be a-z, 0-9, '.', and '-'." | ||
}, | ||
zone: { | ||
req: 'Zone is required', | ||
char: 'Zone can only be A-Z and 0-9.', | ||
len: 'Zone has to be 14 characters long.' | ||
}, | ||
directory: { req: 'Directory is required' }, | ||
distribution: { req: 'Distribution is required' } | ||
} | ||
|
||
const parseArgs = (argv: string[]): ParsedArgs => { | ||
const args = mri(argv, { string: ['domain', 'zone', 'channel'] }) | ||
|
||
const { | ||
_: [action, dir], | ||
domain, | ||
zone, | ||
distribution, | ||
channel | ||
} = args | ||
|
||
return { action, dir, domain, zone, channel, distribution } as ParsedArgs | ||
} | ||
|
||
const forcedExit = (msg: string) => { | ||
console.error(msg) | ||
process.exit(1) | ||
} | ||
|
||
const isValidAction = (action: string) => { | ||
const allowedActions = new Set(['promote', 'deploy', 'undeploy']) | ||
|
||
if (!allowedActions.has(action)) | ||
return `${action} is not a valid action. Allowed actions: ${Array.from(allowedActions.values()).join(', ')}` | ||
|
||
return true | ||
} | ||
|
||
const isValidDomain = (domain: string) => { | ||
if (typeof domain === 'undefined') return errors.domain.req | ||
if (!/^[a-z0-9-\.]+$/.test(domain)) return errors.domain.char | ||
|
||
return true | ||
} | ||
|
||
const isValidZone = (zone: string) => { | ||
if (typeof zone === 'undefined') return errors.zone.req | ||
if (!/^[A-Z0-9]+$/.test(zone)) return errors.zone.char | ||
if (zone.length !== 14) return errors.zone.len | ||
|
||
return true | ||
} | ||
|
||
const isValidDir = (dir: string) => { | ||
if (typeof dir === 'undefined') return errors.directory.req | ||
|
||
return true | ||
} | ||
|
||
const isValidDistribution = (distribution: string) => { | ||
if (typeof distribution === 'undefined') return errors.distribution.req | ||
|
||
return true | ||
} | ||
|
||
const deploy = ({ domain, zone, dir, channel }: ParsedArgs) => { | ||
const validDomain = isValidDomain(domain) | ||
const validZone = isValidZone(zone) | ||
const validDir = isValidDir(dir) | ||
|
||
if (validDomain !== true) return forcedExit(validDomain) | ||
if (validZone !== true) return forcedExit(validZone) | ||
if (validDir !== true) return forcedExit(validDir) | ||
|
||
require('./deploy').deploy(domain, zone, dir, channel) | ||
} | ||
|
||
const undeploy = ({ domain, zone }: ParsedArgs) => { | ||
const validDomain = isValidDomain(domain) | ||
const validZone = isValidZone(zone) | ||
|
||
if (validDomain !== true) return forcedExit(validDomain) | ||
if (validZone !== true) return forcedExit(validZone) | ||
|
||
require('./undeploy').undeploy(domain, zone) | ||
} | ||
|
||
const promote = ({ domain, distribution, dir, channel }: ParsedArgs) => { | ||
const validDomain = isValidDomain(domain) | ||
const validDistribution = isValidDistribution(distribution) | ||
const validDir = isValidDir(dir) | ||
|
||
if (validDomain !== true) return forcedExit(validDomain) | ||
if (validDistribution !== true) return forcedExit(validDistribution) | ||
if (validDir !== true) return forcedExit(validDir) | ||
|
||
require('./promote').promote(domain, distribution, dir, channel) | ||
} | ||
|
||
export const cli = (argv: string[]) => { | ||
const args = parseArgs(argv) | ||
|
||
const { action } = args | ||
|
||
const validAction = isValidAction(action) | ||
if (validAction !== true) return forcedExit(validAction) | ||
|
||
if (action === 'deploy') deploy(args) | ||
else if (action === 'undeploy') undeploy(args) | ||
else if (action === 'promote') promote(args) | ||
} |
Oops, something went wrong.