Guest User

Untitled

a guest
Dec 11th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.27 KB | None | 0 0
  1. export enum NodeEnv {
  2. Production = "production",
  3. Development = "development"
  4. }
  5.  
  6. export enum OcastEnv {
  7. Altair = "altair",
  8. Development = "development",
  9. Staging = "stage",
  10. Production = "production"
  11. }
  12.  
  13. /**
  14. * Build options that may be customized freely depending on what kind of build you want to produce,
  15. * whether it's about customizing your developer experience or fine tuning a deployed build.
  16. */
  17. export type BuildOptions = {
  18. outputFolder?: string;
  19. sourceMaps?: boolean;
  20. hashFilenames?: boolean;
  21. log?: boolean;
  22. debug?: boolean;
  23. cache?: boolean;
  24. compress?: boolean;
  25. minify?: boolean;
  26. hmr?: boolean;
  27. };
  28.  
  29. /**
  30. * Returns the most commonly used options depending on the node and ocast environment.
  31. * NOTE Do not change these defaults for your personal preference. Extend the options object that is returned.
  32. */
  33. export function getCommonBuildOptions (ocastEnv: OcastEnv, nodeEnv: NodeEnv): BuildOptions {
  34. const inProd = ocastEnv === OcastEnv.Production && nodeEnv === NodeEnv.Production;
  35. const inDev = !inProd;
  36. return {
  37. outputFolder: "dist",
  38. hashFilenames: inProd,
  39. compress: inProd,
  40. minify: inProd,
  41. sourceMaps: inDev,
  42. log: inDev,
  43. debug: inDev,
  44. hmr: inDev,
  45. cache: inDev
  46. };
  47. }
  48.  
  49. /**
  50. * Gets the OcastEnv and NodeEnv defined in the systems environment variables.
  51. * - If an invalid configuration is found an error will be thrown.
  52. * - Defaults to Development if nothing is configured.
  53. * - Allows you to pass in your own environment strings. Useful for parsing CLI arguments.
  54. * @returns {{ocastEnv: OcastEnv | OcastEnv.Development; nodeEnv: NodeEnv | NodeEnv.Development}}
  55. */
  56. export function getEnvironments (
  57. ocastEnvString = process.env.OCAST_CONFIG,
  58. nodeEnvString = process.env.NODE_ENV
  59. ) {
  60. const ocastEnv = ocastEnvString ? OcastEnv[ocastEnvString as any] as OcastEnv : OcastEnv.Development;
  61. const nodeEnv = nodeEnvString ? OcastEnv[nodeEnvString as any] as NodeEnv : NodeEnv.Development;
  62.  
  63. if (Object.values(OcastEnv).indexOf(ocastEnv) === -1) {
  64. throw new Error(`Unknown OcastEnv: ${ocastEnv}. Supported values: ${Object.values(OcastEnv)}`);
  65. }
  66.  
  67. if (Object.values(NodeEnv).indexOf(nodeEnv) === -1) {
  68. throw new Error(`Unknown NodeEnv: ${nodeEnv}. Supported values: ${Object.values(NodeEnv)}`);
  69. }
  70.  
  71. return {ocastEnv, nodeEnv};
  72. }
Add Comment
Please, Sign In to add comment