Created
December 8, 2017 14:05
-
-
Save kasper573/fe084b58bb8a3620f7feb78db26111fa to your computer and use it in GitHub Desktop.
This file contains hidden or 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
export enum NodeEnv { | |
Production = "production", | |
Development = "development" | |
} | |
export enum OcastEnv { | |
Altair = "altair", | |
Development = "development", | |
Staging = "stage", | |
Production = "production" | |
} | |
/** | |
* Build options that may be customized freely depending on what kind of build you want to produce, | |
* whether it's about customizing your developer experience or fine tuning a deployed build. | |
*/ | |
export type BuildOptions = { | |
outputFolder?: string; | |
sourceMaps?: boolean; | |
hashFilenames?: boolean; | |
log?: boolean; | |
debug?: boolean; | |
cache?: boolean; | |
compress?: boolean; | |
minify?: boolean; | |
hmr?: boolean; | |
}; | |
/** | |
* Returns the most commonly used options depending on the node and ocast environment. | |
* NOTE Do not change these defaults for your personal preference. Extend the options object that is returned. | |
*/ | |
export function getCommonBuildOptions (ocastEnv: OcastEnv, nodeEnv: NodeEnv): BuildOptions { | |
const inProd = ocastEnv === OcastEnv.Production && nodeEnv === NodeEnv.Production; | |
const inDev = !inProd; | |
return { | |
outputFolder: "dist", | |
hashFilenames: inProd, | |
compress: inProd, | |
minify: inProd, | |
sourceMaps: inDev, | |
log: inDev, | |
debug: inDev, | |
hmr: inDev, | |
cache: inDev | |
}; | |
} | |
/** | |
* Gets the OcastEnv and NodeEnv defined in the systems environment variables. | |
* - If an invalid configuration is found an error will be thrown. | |
* - Defaults to Development if nothing is configured. | |
* - Allows you to pass in your own environment strings. Useful for parsing CLI arguments. | |
* @returns {{ocastEnv: OcastEnv | OcastEnv.Development; nodeEnv: NodeEnv | NodeEnv.Development}} | |
*/ | |
export function getEnvironments ( | |
ocastEnvString = process.env.OCAST_CONFIG, | |
nodeEnvString = process.env.NODE_ENV | |
) { | |
const ocastEnv = ocastEnvString ? OcastEnv[ocastEnvString as any] as OcastEnv : OcastEnv.Development; | |
const nodeEnv = nodeEnvString ? OcastEnv[nodeEnvString as any] as NodeEnv : NodeEnv.Development; | |
if (Object.values(OcastEnv).indexOf(ocastEnv) === -1) { | |
throw new Error(`Unknown OcastEnv: ${ocastEnv}. Supported values: ${Object.values(OcastEnv)}`); | |
} | |
if (Object.values(NodeEnv).indexOf(nodeEnv) === -1) { | |
throw new Error(`Unknown NodeEnv: ${nodeEnv}. Supported values: ${Object.values(NodeEnv)}`); | |
} | |
return {ocastEnv, nodeEnv}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment