Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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};
- }
Add Comment
Please, Sign In to add comment