@contentstack/cli-cm-bootstrap 1.7.0 → 1.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2023 Contentstack
3
+ Copyright (c) 2024 Contentstack
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -15,7 +15,7 @@ $ npm install -g @contentstack/cli-cm-bootstrap
15
15
  $ csdx COMMAND
16
16
  running command...
17
17
  $ csdx (--version)
18
- @contentstack/cli-cm-bootstrap/1.7.0 linux-x64 node-v18.18.2
18
+ @contentstack/cli-cm-bootstrap/1.8.0 linux-x64 node-v18.19.0
19
19
  $ csdx --help [COMMAND]
20
20
  USAGE
21
21
  $ csdx COMMAND
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const zlib = require("zlib");
4
4
  const tar = require("tar");
5
- const mkdirp = require("mkdirp");
5
+ const mkdirp = require('mkdirp');
6
6
  const cli_utilities_1 = require("@contentstack/cli-utilities");
7
7
  const github_error_1 = require("./github-error");
8
8
  const messages_1 = require("../../messages");
@@ -71,6 +71,11 @@ class Bootstrap {
71
71
  else {
72
72
  throw new Error(messages_1.default.parse('CLI_BOOTSTRAP_NO_API_KEY_FOUND'));
73
73
  }
74
+ if (this.options.livePreviewEnabled) {
75
+ cli_utilities_1.cliux.print('Note: Before running the app, please configure a preview token, preview host, and app host in the environment file', {
76
+ color: 'yellow',
77
+ });
78
+ }
74
79
  cli_utilities_1.cliux.print(messages_1.default.parse('CLI_BOOTSTRAP_SUCCESS'));
75
80
  }
76
81
  catch (error) {
@@ -9,3 +9,4 @@ export declare function inquireCloneDirectory(): Promise<string>;
9
9
  export declare function inquireGithubAccessToken(): Promise<any>;
10
10
  export declare function inquireAppType(): Promise<string>;
11
11
  export declare function inquireLivePreviewSupport(): Promise<any>;
12
+ export declare function continueBootstrapCommand(): Promise<any>;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.inquireLivePreviewSupport = exports.inquireAppType = exports.inquireGithubAccessToken = exports.inquireCloneDirectory = exports.inquireApp = void 0;
3
+ exports.continueBootstrapCommand = exports.inquireLivePreviewSupport = exports.inquireAppType = exports.inquireGithubAccessToken = exports.inquireCloneDirectory = exports.inquireApp = void 0;
4
4
  const path = require("path");
5
5
  const inquirer = require('inquirer');
6
6
  const cli_utilities_1 = require("@contentstack/cli-utilities");
@@ -96,3 +96,14 @@ async function inquireLivePreviewSupport() {
96
96
  return livePreviewEnabled;
97
97
  }
98
98
  exports.inquireLivePreviewSupport = inquireLivePreviewSupport;
99
+ async function continueBootstrapCommand() {
100
+ const { shouldContinue } = await inquirer.prompt({
101
+ type: 'list',
102
+ name: 'shouldContinue',
103
+ message: `To continue with the Bootstrap command without Live Preview, please select Yes.`,
104
+ choices: ['yes', 'no'],
105
+ loop: false,
106
+ });
107
+ return shouldContinue;
108
+ }
109
+ exports.continueBootstrapCommand = continueBootstrapCommand;
@@ -4,6 +4,7 @@ exports.setupEnvironments = void 0;
4
4
  const fs = require("fs");
5
5
  const path = require("path");
6
6
  const cli_utilities_1 = require("@contentstack/cli-utilities");
7
+ const interactive_1 = require("../bootstrap/interactive");
7
8
  const messages_1 = require("../messages");
8
9
  /**
9
10
  * @description Setup the environment for a given app for each environment
@@ -12,6 +13,7 @@ const messages_1 = require("../messages");
12
13
  * Create enviroment
13
14
  */
14
15
  const setupEnvironments = async (managementAPIClient, api_key, appConfig, clonedDirectory, region, livePreviewEnabled, managementToken) => {
16
+ var _a, _b;
15
17
  const environmentResult = await managementAPIClient
16
18
  .stack({ api_key, management_token: managementToken })
17
19
  .environment()
@@ -38,27 +40,39 @@ const setupEnvironments = async (managementAPIClient, api_key, appConfig, cloned
38
40
  ],
39
41
  },
40
42
  };
41
- if (!managementToken) {
42
- try {
43
- const tokenResult = await managementAPIClient.stack({ api_key }).deliveryToken().create(body);
44
- if (tokenResult.token) {
45
- const environmentVariables = {
46
- api_key,
47
- deliveryToken: tokenResult.token,
48
- environment: environment.name,
49
- livePreviewEnabled,
50
- };
51
- await envFileHandler(appConfig.appConfigKey || '', environmentVariables, clonedDirectory, region, livePreviewEnabled);
52
- }
53
- else {
54
- cli_utilities_1.cliux.print(messages_1.default.parse('CLI_BOOTSTRAP_APP_FAILED_TO_CREATE_TOKEN_FOR_ENV', environment.name));
43
+ try {
44
+ const tokenResult = !managementToken
45
+ ? await managementAPIClient
46
+ .stack({ api_key })
47
+ .deliveryToken()
48
+ .create(body, livePreviewEnabled ? { create_with_preview_token: true } : {})
49
+ : {};
50
+ if (livePreviewEnabled && !tokenResult.preview_token && !managementToken) {
51
+ cli_utilities_1.cliux.print(`Info: Failed to generate a preview token for the ${environment.name} environment.\nNote: Live Preview using a preview token is not available in your plan. Please contact the admin for support.`, {
52
+ color: 'yellow',
53
+ });
54
+ if ((await (0, interactive_1.continueBootstrapCommand)()) === 'no') {
55
+ return;
55
56
  }
56
57
  }
57
- catch (error) {
58
- console.log('error', error);
59
- cli_utilities_1.cliux.print(messages_1.default.parse('CLI_BOOTSTRAP_APP_FAILED_TO_CREATE_ENV_FILE_FOR_ENV', environment.name));
58
+ if (tokenResult.token) {
59
+ const environmentVariables = {
60
+ api_key,
61
+ deliveryToken: (_a = tokenResult.token) !== null && _a !== void 0 ? _a : '',
62
+ environment: environment.name,
63
+ livePreviewEnabled,
64
+ preview_token: (_b = tokenResult.preview_token) !== null && _b !== void 0 ? _b : '',
65
+ };
66
+ await envFileHandler(appConfig.appConfigKey || '', environmentVariables, clonedDirectory, region, livePreviewEnabled);
67
+ }
68
+ else {
69
+ cli_utilities_1.cliux.print(messages_1.default.parse('CLI_BOOTSTRAP_APP_FAILED_TO_CREATE_TOKEN_FOR_ENV', environment.name));
60
70
  }
61
71
  }
72
+ catch (error) {
73
+ console.log('error', error);
74
+ cli_utilities_1.cliux.print(messages_1.default.parse('CLI_BOOTSTRAP_APP_FAILED_TO_CREATE_ENV_FILE_FOR_ENV', environment.name));
75
+ }
62
76
  }
63
77
  else {
64
78
  cli_utilities_1.cliux.print('No environments name found for the environment');
@@ -90,6 +104,7 @@ const writeEnvFile = (content, fileName) => {
90
104
  * TBD: moving the content to config file
91
105
  */
92
106
  const envFileHandler = async (appConfigKey, environmentVariables, clonedDirectory, region, livePreviewEnabled) => {
107
+ var _a, _b, _c, _d, _e;
93
108
  if (!appConfigKey || !environmentVariables) {
94
109
  return;
95
110
  }
@@ -98,11 +113,15 @@ const envFileHandler = async (appConfigKey, environmentVariables, clonedDirector
98
113
  let filePath;
99
114
  let fileName;
100
115
  let customHost;
116
+ let previewHost;
117
+ let appHost;
118
+ const managementAPIHost = (_a = region === null || region === void 0 ? void 0 : region.cma) === null || _a === void 0 ? void 0 : _a.substring('8');
101
119
  const regionName = region && region.name && region.name.toLowerCase();
102
- const managementAPIHost = region.cma && region.cma.substring('8');
120
+ previewHost = (_c = (_b = region === null || region === void 0 ? void 0 : region.uiHost) === null || _b === void 0 ? void 0 : _b.substring(8)) === null || _c === void 0 ? void 0 : _c.replace('app', 'rest-preview');
121
+ appHost = (_d = region === null || region === void 0 ? void 0 : region.uiHost) === null || _d === void 0 ? void 0 : _d.substring(8);
103
122
  const isUSRegion = regionName === 'us' || regionName === 'na';
104
123
  if (regionName !== 'eu' && !isUSRegion) {
105
- customHost = region.cma && region.cma.substring('8');
124
+ customHost = (_e = region === null || region === void 0 ? void 0 : region.cma) === null || _e === void 0 ? void 0 : _e.substring(8);
106
125
  }
107
126
  const production = environmentVariables.environment === 'production' ? true : false;
108
127
  switch (appConfigKey) {
@@ -110,31 +129,40 @@ const envFileHandler = async (appConfigKey, environmentVariables, clonedDirector
110
129
  case 'reactjs-starter':
111
130
  fileName = `.env.${environmentVariables.environment}.local`;
112
131
  filePath = path.join(clonedDirectory, fileName);
113
- content = `REACT_APP_CONTENTSTACK_API_KEY=${environmentVariables.api_key}\nREACT_APP_CONTENTSTACK_DELIVERY_TOKEN=${environmentVariables.deliveryToken}\nREACT_APP_CONTENTSTACK_ENVIRONMENT=${environmentVariables.environment}${customHost ? '\nREACT_APP_CONTENTSTACK_API_HOST=' + customHost : ''}${!isUSRegion && !customHost ? '\nREACT_APP_CONTENTSTACK_REGION=' + region.name : ''}\nSKIP_PREFLIGHT_CHECK=true\nREACT_APP_CONTENTSTACK_LIVE_PREVIEW=${livePreviewEnabled}`;
132
+ content = `REACT_APP_CONTENTSTACK_API_KEY=${environmentVariables.api_key}\nREACT_APP_CONTENTSTACK_DELIVERY_TOKEN=${environmentVariables.deliveryToken}${livePreviewEnabled
133
+ ? `\nREACT_APP_CONTENTSTACK_PREVIEW_TOKEN=${environmentVariables.preview_token || `''`}\nREACT_APP_CONTENTSTACK_PREVIEW_HOST=${previewHost}\nREACT_APP_CONTENTSTACK_APP_HOST=${appHost}\n`
134
+ : '\n'}\nREACT_APP_CONTENTSTACK_ENVIRONMENT=${environmentVariables.environment}\n${customHost ? '\nREACT_APP_CONTENTSTACK_API_HOST=' + customHost : ''}${!isUSRegion && !customHost ? '\nREACT_APP_CONTENTSTACK_REGION=' + region.name : ''}\nSKIP_PREFLIGHT_CHECK=true\nREACT_APP_CONTENTSTACK_LIVE_PREVIEW=${livePreviewEnabled}`;
114
135
  result = await writeEnvFile(content, filePath);
115
136
  break;
116
137
  case 'nextjs':
117
138
  case 'nextjs-starter':
118
139
  fileName = `.env.${environmentVariables.environment}.local`;
119
140
  filePath = path.join(clonedDirectory, fileName);
120
- content = `CONTENTSTACK_API_KEY=${environmentVariables.api_key}\nCONTENTSTACK_DELIVERY_TOKEN=${environmentVariables.deliveryToken}\nCONTENTSTACK_ENVIRONMENT=${environmentVariables.environment}${customHost ? '\nCONTENTSTACK_API_HOST=' + customHost : ''}${!isUSRegion && !customHost ? '\nCONTENTSTACK_REGION=' + region.name : ''}\nCONTENTSTACK_LIVE_PREVIEW=${livePreviewEnabled}`;
141
+ content = `CONTENTSTACK_API_KEY=${environmentVariables.api_key}\nCONTENTSTACK_DELIVERY_TOKEN=${environmentVariables.deliveryToken}\n${livePreviewEnabled
142
+ ? `\nCONTENTSTACK_PREVIEW_TOKEN=${environmentVariables.preview_token || `''`}\nCONTENTSTACK_PREVIEW_HOST=${previewHost}\nCONTENTSTACK_APP_HOST=${appHost}\n`
143
+ : '\n'}CONTENTSTACK_ENVIRONMENT=${environmentVariables.environment}\nCONTENTSTACK_API_HOST=${customHost ? customHost : managementAPIHost}${!isUSRegion && !customHost ? '\nCONTENTSTACK_REGION=' + region.name : ''}\nCONTENTSTACK_LIVE_PREVIEW=${livePreviewEnabled}\nCONTENTSTACK_LIVE_EDIT_TAGS=false`;
121
144
  result = await writeEnvFile(content, filePath);
122
145
  break;
123
146
  case 'gatsby':
124
147
  case 'gatsby-starter':
125
148
  fileName = `.env.${environmentVariables.environment}`;
126
149
  filePath = path.join(clonedDirectory, fileName);
127
- content = `CONTENTSTACK_API_KEY=${environmentVariables.api_key}\nCONTENTSTACK_DELIVERY_TOKEN=${environmentVariables.deliveryToken}\nCONTENTSTACK_ENVIRONMENT=${environmentVariables.environment}\nCONTENTSTACK_API_HOST=${managementAPIHost}\nCONTENTSTACK_LIVE_PREVIEW=${livePreviewEnabled}`;
150
+ content = `CONTENTSTACK_API_KEY=${environmentVariables.api_key}\nCONTENTSTACK_DELIVERY_TOKEN=${environmentVariables.deliveryToken}\n${livePreviewEnabled
151
+ ? `\nCONTENTSTACK_PREVIEW_TOKEN=${environmentVariables.preview_token || `''`}\nCONTENTSTACK_PREVIEW_HOST=${previewHost}\nCONTENTSTACK_APP_HOST=${appHost}\n` : '\n'}\nCONTENTSTACK_ENVIRONMENT=${environmentVariables.environment}\nCONTENTSTACK_API_HOST=${managementAPIHost}\nCONTENTSTACK_LIVE_PREVIEW=${livePreviewEnabled}`;
128
152
  result = await writeEnvFile(content, filePath);
129
153
  break;
130
154
  case 'angular':
131
- content = `export const environment = { \n\tproduction:${environmentVariables.environment === 'production' ? true : false}, \n\tconfig : { \n\t\tapi_key: '${environmentVariables.api_key}', \n\t\tdelivery_token: '${environmentVariables.deliveryToken}', \n\t\tenvironment: '${environmentVariables.environment}'${!isUSRegion && !customHost ? `,\n\t\tregion: '${region.name}'` : ''} \n\t } \n };`;
155
+ content = `export const environment = { \n\tproduction:${environmentVariables.environment === 'production' ? true : false}, \n\tconfig : { \n\t\tapi_key: '${environmentVariables.api_key}', \n\t\tdelivery_token: '${environmentVariables.deliveryToken}',\n${livePreviewEnabled
156
+ ? `\n\tpreivew_token:'${environmentVariables.preview_token || `''`}'\n\tpreview_host:'${previewHost}'\n\tapp_host:'${appHost}'\n`
157
+ : '\n'},\n\t\tenvironment: '${environmentVariables.environment}'${!isUSRegion && !customHost ? `,\n\t\tregion: '${region.name}'` : ''} \n\t } \n };`;
132
158
  fileName = `environment${environmentVariables.environment === 'production' ? '.prod.' : '.'}ts`;
133
159
  filePath = path.join(clonedDirectory, 'src', 'environments', fileName);
134
160
  result = await writeEnvFile(content, filePath);
135
161
  break;
136
162
  case 'angular-starter':
137
- content = `export const environment = { \n\tproduction: true \n}; \nexport const Config = { \n\tapi_key: '${environmentVariables.api_key}', \n\tdelivery_token: '${environmentVariables.deliveryToken}', \n\tenvironment: '${environmentVariables.environment}'${!isUSRegion && !customHost ? `,\n\tregion: '${region.name}'` : ''},\n\tapi_host: '${customHost ? customHost : managementAPIHost}',\n\tapp_host: '',\n\tmanagement_token: '',\n\tlive_preview: ${livePreviewEnabled}\n};`;
163
+ content = `export const environment = { \n\tproduction: true \n}; \nexport const Config = { \n\tapi_key: '${environmentVariables.api_key}', \n\tdelivery_token: '${environmentVariables.deliveryToken}',\n\t${livePreviewEnabled
164
+ ? `\npreview_token:'${environmentVariables.preview_token || ''}',\npreview_host:'${previewHost}',\napp_host:'${appHost}'`
165
+ : '\n'},\n\tenvironment: '${environmentVariables.environment}'${!isUSRegion && !customHost ? `,\n\tregion: '${region.name}'` : ''},\n\tapi_host: '${customHost ? customHost : managementAPIHost}',\n\tlive_preview: ${livePreviewEnabled}\n};`;
138
166
  fileName = `environment${environmentVariables.environment === 'production' ? '.prod.' : '.'}ts`;
139
167
  filePath = path.join(clonedDirectory, 'src', 'environments', fileName);
140
168
  result = await writeEnvFile(content, filePath);
@@ -145,13 +173,17 @@ const envFileHandler = async (appConfigKey, environmentVariables, clonedDirector
145
173
  fileName = production ? '.env.production' : '.env';
146
174
  filePath = path.join(clonedDirectory, fileName);
147
175
  // Note: Stencil app needs all the env variables, even if they are not having values otherwise the rollup does not work properly and throws process in undefined error.
148
- content = `CONTENTSTACK_API_KEY=${environmentVariables.api_key}\nCONTENTSTACK_DELIVERY_TOKEN=${environmentVariables.deliveryToken}\nCONTENTSTACK_ENVIRONMENT=${environmentVariables.environment}${!isUSRegion && !customHost ? '\nCONTENTSTACK_REGION=' + region.name : ''}\nCONTENTSTACK_LIVE_PREVIEW=${livePreviewEnabled}\nCONTENTSTACK_MANAGEMENT_TOKEN=''\nCONTENTSTACK_API_HOST='${customHost ? customHost : managementAPIHost}'\nCONTENTSTACK_APP_HOST=''\nCONTENTSTACK_LIVE_EDIT_TAGS=false`;
176
+ content = `CONTENTSTACK_API_KEY=${environmentVariables.api_key}\nCONTENTSTACK_DELIVERY_TOKEN=${environmentVariables.deliveryToken}\n${livePreviewEnabled
177
+ ? `\nCONTENTSTACK_PREVIEW_TOKEN=${environmentVariables.preview_token || `''`}\nCONTENTSTACK_PREVIEW_HOST=${customHost !== null && customHost !== void 0 ? customHost : previewHost}\nCONTENTSTACK_APP_HOST=${appHost}`
178
+ : '\n'}\nCONTENTSTACK_ENVIRONMENT=${environmentVariables.environment}${!isUSRegion && !customHost ? '\nCONTENTSTACK_REGION=' + region.name : ''}\nCONTENTSTACK_API_HOST=${customHost ? customHost : managementAPIHost}\nCONTENTSTACK_LIVE_PREVIEW=${livePreviewEnabled}\n\nCONTENTSTACK_LIVE_EDIT_TAGS=false`;
149
179
  result = await writeEnvFile(content, filePath);
150
180
  break;
151
181
  case 'vue-starter':
152
182
  fileName = '.env';
153
183
  filePath = path.join(clonedDirectory, fileName);
154
- content = `VUE_APP_CONTENTSTACK_API_KEY=${environmentVariables.api_key}\nVUE_APP_CONTENTSTACK_DELIVERY_TOKEN=${environmentVariables.deliveryToken}\nVUE_APP_CONTENTSTACK_ENVIRONMENT=${environmentVariables.environment}${customHost ? '\nVUE_APP_CONTENTSTACK_API_HOST=' + customHost : ''}${!isUSRegion && !customHost ? '\nVUE_APP_CONTENTSTACK_REGION=' + region.name : ''}\nVUE_APP_CONTENTSTACK_LIVE_PREVIEW=${livePreviewEnabled}`;
184
+ content = `VUE_APP_CONTENTSTACK_API_KEY=${environmentVariables.api_key}\nVUE_APP_CONTENTSTACK_DELIVERY_TOKEN=${environmentVariables.deliveryToken}\n${livePreviewEnabled
185
+ ? `\nVUE_APP_CONTENTSTACK_PREVIEW_TOKEN=${environmentVariables.preview_token || `''`}\nVUE_APP_CONTENTSTACK_PREVIEW_HOST=${previewHost}\nVUE_APP_CONTENTSTACK_APP_HOST=${appHost}\n`
186
+ : '\n'}\nVUE_APP_CONTENTSTACK_ENVIRONMENT=${environmentVariables.environment}${customHost ? '\nVUE_APP_CONTENTSTACK_API_HOST=' + customHost : ''}${!isUSRegion && !customHost ? '\nVUE_APP_CONTENTSTACK_REGION=' + region.name : ''}\nVUE_APP_CONTENTSTACK_LIVE_PREVIEW=${livePreviewEnabled}`;
155
187
  result = await writeEnvFile(content, filePath);
156
188
  break;
157
189
  default:
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.7.0",
2
+ "version": "1.8.0",
3
3
  "commands": {
4
4
  "cm:bootstrap": {
5
5
  "id": "cm:bootstrap",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@contentstack/cli-cm-bootstrap",
3
3
  "description": "Bootstrap contentstack apps",
4
- "version": "1.7.0",
4
+ "version": "1.8.0",
5
5
  "author": "Contentstack",
6
6
  "bugs": "https://github.com/contentstack/cli/issues",
7
7
  "scripts": {
@@ -19,13 +19,13 @@
19
19
  "dependencies": {
20
20
  "@contentstack/cli-cm-seed": "~1.7.0",
21
21
  "@contentstack/cli-command": "~1.2.16",
22
- "@contentstack/cli-utilities": "~1.5.8",
22
+ "@contentstack/cli-utilities": "~1.5.11",
23
23
  "inquirer": "8.2.4",
24
24
  "mkdirp": "^1.0.4",
25
25
  "tar": "^6.1.13"
26
26
  },
27
27
  "devDependencies": {
28
- "@oclif/test": "^2.2.10",
28
+ "@oclif/test": "^2.5.6",
29
29
  "@types/inquirer": "^9.0.3",
30
30
  "@types/mkdirp": "^1.0.1",
31
31
  "@types/node": "^14.14.32",
@@ -33,7 +33,7 @@
33
33
  "chai": "^4.3.4",
34
34
  "eslint": "^8.18.0",
35
35
  "eslint-config-oclif": "^4.0.0",
36
- "eslint-config-oclif-typescript": "^0.1.0",
36
+ "eslint-config-oclif-typescript": "^3.0.8",
37
37
  "globby": "^10.0.2",
38
38
  "mocha": "10.1.0",
39
39
  "nyc": "^15.1.0",
@@ -73,4 +73,4 @@
73
73
  }
74
74
  },
75
75
  "repository": "contentstack/cli"
76
- }
76
+ }