Skip to content

Commit 6ce03b1

Browse files
committed
added generate-env
1 parent 3ae4c2e commit 6ce03b1

1 file changed

Lines changed: 10 additions & 32 deletions

File tree

generate-env.js

Lines changed: 10 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
#!/usr/bin/env node
22

3-
const {
4-
getContentstackEndpoints,
5-
getRegionForString,
6-
} = require("@timbenniks/contentstack-endpoints");
3+
const { getContentstackEndpoint } = require("@contentstack/utils");
74

85
const fs = require("fs");
96
const path = require("path");
@@ -30,8 +27,7 @@ if (fs.existsSync(envPath)) {
3027
});
3128
}
3229

33-
const region = getRegionForString(envVars.NG_APP_CONTENTSTACK_REGION);
34-
const endpoints = getContentstackEndpoints(region, true);
30+
const endpoints = getContentstackEndpoint(envVars.NG_APP_CONTENTSTACK_REGION || 'us', '', true);
3531

3632
// Generate environment.ts content
3733
const environmentContent = `export const environment = {
@@ -41,21 +37,12 @@ const environmentContent = `export const environment = {
4137
deliveryToken: '${envVars.NG_APP_CONTENTSTACK_DELIVERY_TOKEN || ""}',
4238
previewToken: '${envVars.NG_APP_CONTENTSTACK_PREVIEW_TOKEN || ""}',
4339
environment: '${envVars.NG_APP_CONTENTSTACK_ENVIRONMENT || "preview"}',
44-
region: '${region ? region : envVars.NG_APP_CONTENTSTACK_REGION}',
40+
region: '${envVars.NG_APP_CONTENTSTACK_REGION || "us"}',
4541
preview: ${envVars.NG_APP_CONTENTSTACK_PREVIEW === "true"},
4642
47-
contentDelivery: '${
48-
envVars.NG_APP_CONTENTSTACK_CONTENT_DELIVERY ||
49-
(endpoints && endpoints.contentDelivery)
50-
}',
51-
previewHost: '${
52-
envVars.NG_APP_CONTENTSTACK_PREVIEW_HOST ||
53-
(endpoints && endpoints.preview)
54-
}',
55-
applicationHost: '${
56-
envVars.NG_APP_CONTENTSTACK_CONTENT_APPLICATION ||
57-
(endpoints && endpoints.application)
58-
}'
43+
contentDelivery: '${envVars.NG_APP_CONTENTSTACK_CONTENT_DELIVERY || endpoints.contentDelivery}',
44+
previewHost: '${envVars.NG_APP_CONTENTSTACK_PREVIEW_HOST || endpoints.preview}',
45+
applicationHost: '${envVars.NG_APP_CONTENTSTACK_CONTENT_APPLICATION || endpoints.application}'
5946
}
6047
};
6148
`;
@@ -68,21 +55,12 @@ const environmentProdContent = `export const environment = {
6855
deliveryToken: '${envVars.NG_APP_CONTENTSTACK_DELIVERY_TOKEN || ""}',
6956
previewToken: '${envVars.NG_APP_CONTENTSTACK_PREVIEW_TOKEN || ""}',
7057
environment: '${envVars.NG_APP_CONTENTSTACK_ENVIRONMENT || "preview"}',
71-
region: '${region ? region : envVars.NG_APP_CONTENTSTACK_REGION}',
58+
region: '${envVars.NG_APP_CONTENTSTACK_REGION || "us"}',
7259
preview: ${envVars.NG_APP_CONTENTSTACK_PREVIEW === "true"},
7360
74-
contentDelivery: '${
75-
envVars.NG_APP_CONTENTSTACK_CONTENT_DELIVERY ||
76-
(endpoints && endpoints.contentDelivery)
77-
}',
78-
previewHost: '${
79-
envVars.NG_APP_CONTENTSTACK_PREVIEW_HOST ||
80-
(endpoints && endpoints.preview)
81-
}',
82-
applicationHost: '${
83-
envVars.NG_APP_CONTENTSTACK_CONTENT_APPLICATION ||
84-
(endpoints && endpoints.application)
85-
}'
61+
contentDelivery: '${envVars.NG_APP_CONTENTSTACK_CONTENT_DELIVERY || endpoints.contentDelivery}',
62+
previewHost: '${envVars.NG_APP_CONTENTSTACK_PREVIEW_HOST || endpoints.preview}',
63+
applicationHost: '${envVars.NG_APP_CONTENTSTACK_CONTENT_APPLICATION || endpoints.application}'
8664
8765
}
8866
};

0 commit comments

Comments
 (0)