@contentstack/cli-cm-bootstrap 1.4.11 → 1.4.13
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/README.md +3 -2
- package/lib/bootstrap/index.d.ts +2 -0
- package/lib/bootstrap/index.js +4 -1
- package/lib/bootstrap/utils.d.ts +1 -1
- package/lib/bootstrap/utils.js +35 -29
- package/lib/commands/cm/bootstrap.js +13 -2
- package/oclif.manifest.json +8 -1
- package/package.json +5 -5
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.4.
|
|
18
|
+
@contentstack/cli-cm-bootstrap/1.4.13 linux-x64 node-v18.17.0
|
|
19
19
|
$ csdx --help [COMMAND]
|
|
20
20
|
USAGE
|
|
21
21
|
$ csdx COMMAND
|
|
@@ -45,9 +45,10 @@ Bootstrap contentstack apps
|
|
|
45
45
|
```
|
|
46
46
|
USAGE
|
|
47
47
|
$ csdx cm:bootstrap [--app-name <value>] [--project-dir <value>] [-k <value> | --org <value> | -n <value>] [-y
|
|
48
|
-
<value>]
|
|
48
|
+
<value>] [-a <value>]
|
|
49
49
|
|
|
50
50
|
FLAGS
|
|
51
|
+
-a, --alias=<value> Alias of the management token
|
|
51
52
|
-k, --stack-api-key=<value> Provide stack API key to seed content
|
|
52
53
|
-n, --stack-name=<value> Name of a new stack that will be created.
|
|
53
54
|
-y, --yes=<value> [Optional] Skip stack confirmation
|
package/lib/bootstrap/index.d.ts
CHANGED
package/lib/bootstrap/index.js
CHANGED
|
@@ -61,9 +61,12 @@ class Bootstrap {
|
|
|
61
61
|
if (this.options.seedParams.yes) {
|
|
62
62
|
cmd.push('-y', this.options.seedParams.yes);
|
|
63
63
|
}
|
|
64
|
+
if (this.options.seedParams.managementTokenAlias) {
|
|
65
|
+
cmd.push('--alias', this.options.seedParams.managementTokenAlias);
|
|
66
|
+
}
|
|
64
67
|
const result = await seed_1.default.run(cmd);
|
|
65
68
|
if (result && result.api_key) {
|
|
66
|
-
await (0, utils_1.setupEnvironments)(this.managementAPIClient, result.api_key, this.appConfig, this.cloneDirectory, this.region, this.options.livePreviewEnabled);
|
|
69
|
+
await (0, utils_1.setupEnvironments)(this.managementAPIClient, result.api_key, this.appConfig, this.cloneDirectory, this.region, this.options.livePreviewEnabled, this.options.seedParams.managementToken);
|
|
67
70
|
}
|
|
68
71
|
else {
|
|
69
72
|
throw new Error(messages_1.default.parse('CLI_BOOTSTRAP_NO_API_KEY_FOUND'));
|
package/lib/bootstrap/utils.d.ts
CHANGED
|
@@ -5,4 +5,4 @@ import { AppConfig } from '../config';
|
|
|
5
5
|
* Create delivery token
|
|
6
6
|
* Create enviroment
|
|
7
7
|
*/
|
|
8
|
-
export declare const setupEnvironments: (managementAPIClient: any, api_key: string, appConfig: AppConfig, clonedDirectory: string, region: any, livePreviewEnabled: boolean) => Promise<void>;
|
|
8
|
+
export declare const setupEnvironments: (managementAPIClient: any, api_key: string, appConfig: AppConfig, clonedDirectory: string, region: any, livePreviewEnabled: boolean, managementToken?: string) => Promise<void>;
|
package/lib/bootstrap/utils.js
CHANGED
|
@@ -11,8 +11,12 @@ const messages_1 = require("../messages");
|
|
|
11
11
|
* Create delivery token
|
|
12
12
|
* Create enviroment
|
|
13
13
|
*/
|
|
14
|
-
const setupEnvironments = async (managementAPIClient, api_key, appConfig, clonedDirectory, region, livePreviewEnabled) => {
|
|
15
|
-
const environmentResult = await managementAPIClient
|
|
14
|
+
const setupEnvironments = async (managementAPIClient, api_key, appConfig, clonedDirectory, region, livePreviewEnabled, managementToken) => {
|
|
15
|
+
const environmentResult = await managementAPIClient
|
|
16
|
+
.stack({ api_key, management_token: managementToken })
|
|
17
|
+
.environment()
|
|
18
|
+
.query()
|
|
19
|
+
.find();
|
|
16
20
|
if (Array.isArray(environmentResult.items) && environmentResult.items.length > 0) {
|
|
17
21
|
for (const environment of environmentResult.items) {
|
|
18
22
|
if (environment.name) {
|
|
@@ -34,25 +38,27 @@ const setupEnvironments = async (managementAPIClient, api_key, appConfig, cloned
|
|
|
34
38
|
],
|
|
35
39
|
},
|
|
36
40
|
};
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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));
|
|
55
|
+
}
|
|
47
56
|
}
|
|
48
|
-
|
|
49
|
-
|
|
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));
|
|
50
60
|
}
|
|
51
61
|
}
|
|
52
|
-
catch (error) {
|
|
53
|
-
console.log('error', error);
|
|
54
|
-
cli_utilities_1.cliux.print(messages_1.default.parse('CLI_BOOTSTRAP_APP_FAILED_TO_CREATE_ENV_FILE_FOR_ENV', environment.name));
|
|
55
|
-
}
|
|
56
62
|
}
|
|
57
63
|
else {
|
|
58
64
|
cli_utilities_1.cliux.print('No environments name found for the environment');
|
|
@@ -94,24 +100,24 @@ const envFileHandler = async (appConfigKey, environmentVariables, clonedDirector
|
|
|
94
100
|
let customHost;
|
|
95
101
|
const regionName = region && region.name && region.name.toLowerCase();
|
|
96
102
|
const managementAPIHost = region.cma && region.cma.substring('8');
|
|
97
|
-
const isUSRegion =
|
|
103
|
+
const isUSRegion = regionName === 'us' || regionName === 'na';
|
|
98
104
|
if (regionName !== 'eu' && !isUSRegion) {
|
|
99
105
|
customHost = region.cma && region.cma.substring('8');
|
|
100
106
|
}
|
|
101
|
-
const production =
|
|
107
|
+
const production = environmentVariables.environment === 'production' ? true : false;
|
|
102
108
|
switch (appConfigKey) {
|
|
103
109
|
case 'reactjs':
|
|
104
110
|
case 'reactjs-starter':
|
|
105
111
|
fileName = `.env.${environmentVariables.environment}.local`;
|
|
106
112
|
filePath = path.join(clonedDirectory, fileName);
|
|
107
|
-
content = `REACT_APP_CONTENTSTACK_API_KEY=${environmentVariables.api_key}\nREACT_APP_CONTENTSTACK_DELIVERY_TOKEN=${environmentVariables.deliveryToken}\nREACT_APP_CONTENTSTACK_ENVIRONMENT=${environmentVariables.environment}${
|
|
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}`;
|
|
108
114
|
result = await writeEnvFile(content, filePath);
|
|
109
115
|
break;
|
|
110
116
|
case 'nextjs':
|
|
111
117
|
case 'nextjs-starter':
|
|
112
118
|
fileName = `.env.${environmentVariables.environment}.local`;
|
|
113
119
|
filePath = path.join(clonedDirectory, fileName);
|
|
114
|
-
content = `CONTENTSTACK_API_KEY=${environmentVariables.api_key}\nCONTENTSTACK_DELIVERY_TOKEN=${environmentVariables.deliveryToken}\nCONTENTSTACK_ENVIRONMENT=${environmentVariables.environment}${
|
|
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}`;
|
|
115
121
|
result = await writeEnvFile(content, filePath);
|
|
116
122
|
break;
|
|
117
123
|
case 'gatsby':
|
|
@@ -122,30 +128,30 @@ const envFileHandler = async (appConfigKey, environmentVariables, clonedDirector
|
|
|
122
128
|
result = await writeEnvFile(content, filePath);
|
|
123
129
|
break;
|
|
124
130
|
case 'angular':
|
|
125
|
-
content = `export const environment = { \n\tproduction:${
|
|
126
|
-
fileName = `environment${
|
|
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 };`;
|
|
132
|
+
fileName = `environment${environmentVariables.environment === 'production' ? '.prod.' : '.'}ts`;
|
|
127
133
|
filePath = path.join(clonedDirectory, 'src', 'environments', fileName);
|
|
128
134
|
result = await writeEnvFile(content, filePath);
|
|
129
135
|
break;
|
|
130
136
|
case 'angular-starter':
|
|
131
|
-
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}'${
|
|
132
|
-
fileName = `environment${
|
|
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};`;
|
|
138
|
+
fileName = `environment${environmentVariables.environment === 'production' ? '.prod.' : '.'}ts`;
|
|
133
139
|
filePath = path.join(clonedDirectory, 'src', 'environments', fileName);
|
|
134
140
|
result = await writeEnvFile(content, filePath);
|
|
135
141
|
break;
|
|
136
142
|
case 'nuxtjs':
|
|
137
143
|
case 'nuxt-starter':
|
|
138
144
|
case 'stencil-starter':
|
|
139
|
-
fileName =
|
|
145
|
+
fileName = production ? '.env.production' : '.env';
|
|
140
146
|
filePath = path.join(clonedDirectory, fileName);
|
|
141
147
|
// 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.
|
|
142
|
-
content = `CONTENTSTACK_API_KEY=${environmentVariables.api_key}\nCONTENTSTACK_DELIVERY_TOKEN=${environmentVariables.deliveryToken}\nCONTENTSTACK_ENVIRONMENT=${environmentVariables.environment}${
|
|
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`;
|
|
143
149
|
result = await writeEnvFile(content, filePath);
|
|
144
150
|
break;
|
|
145
151
|
case 'vue-starter':
|
|
146
152
|
fileName = '.env';
|
|
147
153
|
filePath = path.join(clonedDirectory, fileName);
|
|
148
|
-
content = `VUE_APP_CONTENTSTACK_API_KEY=${environmentVariables.api_key}\nVUE_APP_CONTENTSTACK_DELIVERY_TOKEN=${environmentVariables.deliveryToken}\nVUE_APP_CONTENTSTACK_ENVIRONMENT=${environmentVariables.environment}${
|
|
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}`;
|
|
149
155
|
result = await writeEnvFile(content, filePath);
|
|
150
156
|
break;
|
|
151
157
|
default:
|
|
@@ -10,8 +10,9 @@ const messages_1 = require("../../messages");
|
|
|
10
10
|
class BootstrapCommand extends cli_command_1.Command {
|
|
11
11
|
async run() {
|
|
12
12
|
const { flags: bootstrapCommandFlags } = await this.parse(BootstrapCommand);
|
|
13
|
+
const managementTokenAlias = bootstrapCommandFlags.alias;
|
|
13
14
|
try {
|
|
14
|
-
if (!(0, cli_utilities_1.isAuthenticated)()) {
|
|
15
|
+
if (!(0, cli_utilities_1.isAuthenticated)() && !managementTokenAlias) {
|
|
15
16
|
this.error(messages_1.default.parse('CLI_BOOTSTRAP_LOGIN_FAILED'), {
|
|
16
17
|
exit: 2,
|
|
17
18
|
suggestions: ['https://www.contentstack.com/docs/developers/cli/authentication/'],
|
|
@@ -53,7 +54,7 @@ class BootstrapCommand extends cli_command_1.Command {
|
|
|
53
54
|
const livePreviewEnabled = bootstrapCommandFlags.yes ? true : await (0, interactive_1.inquireLivePreviewSupport)();
|
|
54
55
|
const seedParams = {};
|
|
55
56
|
const stackAPIKey = bootstrapCommandFlags['stack-api-key'];
|
|
56
|
-
const org = bootstrapCommandFlags
|
|
57
|
+
const org = bootstrapCommandFlags.org;
|
|
57
58
|
const stackName = bootstrapCommandFlags['stack-name'];
|
|
58
59
|
if (stackAPIKey)
|
|
59
60
|
seedParams.stackAPIKey = stackAPIKey;
|
|
@@ -63,6 +64,12 @@ class BootstrapCommand extends cli_command_1.Command {
|
|
|
63
64
|
seedParams.stackName = stackName;
|
|
64
65
|
if (yes)
|
|
65
66
|
seedParams.yes = yes;
|
|
67
|
+
if (managementTokenAlias) {
|
|
68
|
+
seedParams.managementTokenAlias = managementTokenAlias;
|
|
69
|
+
const listOfTokens = cli_utilities_1.configHandler.get('tokens');
|
|
70
|
+
const managementToken = listOfTokens[managementTokenAlias].token;
|
|
71
|
+
seedParams.managementToken = managementToken;
|
|
72
|
+
}
|
|
66
73
|
// initiate bootstrsourceap
|
|
67
74
|
const options = {
|
|
68
75
|
appConfig,
|
|
@@ -157,4 +164,8 @@ BootstrapCommand.flags = {
|
|
|
157
164
|
hidden: true,
|
|
158
165
|
parse: (0, cli_utilities_1.printFlagDeprecation)(['-s', '--appType'], ['--app-type']),
|
|
159
166
|
}),
|
|
167
|
+
alias: cli_utilities_1.flags.string({
|
|
168
|
+
char: 'a',
|
|
169
|
+
description: 'Alias of the management token',
|
|
170
|
+
}),
|
|
160
171
|
};
|
package/oclif.manifest.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.4.
|
|
2
|
+
"version": "1.4.13",
|
|
3
3
|
"commands": {
|
|
4
4
|
"cm:bootstrap": {
|
|
5
5
|
"id": "cm:bootstrap",
|
|
@@ -106,6 +106,13 @@
|
|
|
106
106
|
"hidden": true,
|
|
107
107
|
"required": false,
|
|
108
108
|
"multiple": false
|
|
109
|
+
},
|
|
110
|
+
"alias": {
|
|
111
|
+
"name": "alias",
|
|
112
|
+
"type": "option",
|
|
113
|
+
"char": "a",
|
|
114
|
+
"description": "Alias of the management token",
|
|
115
|
+
"multiple": false
|
|
109
116
|
}
|
|
110
117
|
},
|
|
111
118
|
"args": {}
|
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.4.
|
|
4
|
+
"version": "1.4.13",
|
|
5
5
|
"author": "Contentstack",
|
|
6
6
|
"bugs": "https://github.com/contentstack/cli/issues",
|
|
7
7
|
"scripts": {
|
|
@@ -17,9 +17,9 @@
|
|
|
17
17
|
"test:report": "nyc --reporter=lcov mocha \"test/**/*.test.js\""
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@contentstack/cli-cm-seed": "^1.4.
|
|
21
|
-
"@contentstack/cli-command": "^1.2.
|
|
22
|
-
"@contentstack/cli-utilities": "^1.
|
|
20
|
+
"@contentstack/cli-cm-seed": "^1.4.13",
|
|
21
|
+
"@contentstack/cli-command": "^1.2.11",
|
|
22
|
+
"@contentstack/cli-utilities": "^1.5.1",
|
|
23
23
|
"inquirer": "8.2.4",
|
|
24
24
|
"mkdirp": "^1.0.4",
|
|
25
25
|
"tar": "^6.1.13"
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"eslint-config-oclif": "^4.0.0",
|
|
36
36
|
"eslint-config-oclif-typescript": "^0.1.0",
|
|
37
37
|
"globby": "^10.0.2",
|
|
38
|
-
"mocha": "
|
|
38
|
+
"mocha": "10.1.0",
|
|
39
39
|
"nyc": "^15.1.0",
|
|
40
40
|
"oclif": "^3.8.1",
|
|
41
41
|
"rimraf": "^2.7.1",
|