1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 |
|
7 | class Env {
|
8 | constructor({
|
9 | target = 'client',
|
10 | mode = defaultMode()
|
11 | } = {}) {
|
12 | this.target = target;
|
13 | this.mode = mode;
|
14 | }
|
15 |
|
16 | get hasProductionAssets() {
|
17 | return this.isProduction || this.isStaging;
|
18 | }
|
19 |
|
20 | get isClient() {
|
21 | return this.target === 'client';
|
22 | }
|
23 |
|
24 | get isServer() {
|
25 | return this.target === 'server';
|
26 | }
|
27 |
|
28 | get isBrowser() {
|
29 | return this.isServiceWorker || this.isClient;
|
30 | }
|
31 |
|
32 | get isServiceWorker() {
|
33 | return this.target === 'service-worker';
|
34 | }
|
35 |
|
36 | get isProduction() {
|
37 | return this.mode === 'production';
|
38 | }
|
39 |
|
40 | get isDevelopment() {
|
41 | return this.mode === 'development';
|
42 | }
|
43 |
|
44 | get isNotDevelopment() {
|
45 | return !this.isDevelopment;
|
46 | }
|
47 |
|
48 | get isStaging() {
|
49 | return this.mode === 'staging';
|
50 | }
|
51 |
|
52 | get isTest() {
|
53 | return this.mode === 'test';
|
54 | }
|
55 |
|
56 | get isCircleCI() {
|
57 | return process.env.CIRCLECI === 'true';
|
58 | }
|
59 |
|
60 | get isCI() {
|
61 | return process.env.CI === 'true' || process.env.CI === '1';
|
62 | }
|
63 |
|
64 | get isDevelopmentClient() {
|
65 | return this.isDevelopment && this.isClient;
|
66 | }
|
67 |
|
68 | get isProductionClient() {
|
69 | throw new Error('env.isProductionClient has been removed. Use env.isClient && env.hasProductionAssets instead');
|
70 | }
|
71 |
|
72 | get isTestClient() {
|
73 | return this.isTest && this.isClient;
|
74 | }
|
75 |
|
76 | get isDevelopmentServer() {
|
77 | return this.isDevelopment && this.isServer;
|
78 | }
|
79 |
|
80 | get isProductionServer() {
|
81 | throw new Error('env.isProductionServer has been removed. Use env.isServer && env.hasProductionAssets instead');
|
82 | }
|
83 |
|
84 | get isShopifyBuild() {
|
85 | return process.env.SHOPIFY_BUILD_VERSION != null;
|
86 | }
|
87 |
|
88 | get isTestServer() {
|
89 | return this.isTest && this.isServer;
|
90 | }
|
91 |
|
92 | toString() {
|
93 | return `${this.mode} ${this.target}`;
|
94 | }
|
95 |
|
96 | match(cases) {
|
97 | if (this.isServer) {
|
98 | return cases.server;
|
99 | }
|
100 |
|
101 | if (this.isServiceWorker) {
|
102 | return cases.serviceWorker;
|
103 | }
|
104 |
|
105 | return cases.client;
|
106 | }
|
107 |
|
108 | }
|
109 |
|
110 | exports.default = Env;
|
111 |
|
112 | function defaultMode() {
|
113 | return process.env.NODE_ENV || 'production';
|
114 | } |
\ | No newline at end of file |