@contentstack/cli-cm-bootstrap 1.0.0 → 1.0.3
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 +52 -15
- package/lib/bootstrap/{error.js → bootstrap-error.js} +0 -0
- package/lib/bootstrap/github/client.js +2 -2
- package/lib/bootstrap/github/{error.js → github-error.js} +0 -0
- package/lib/bootstrap/index.js +9 -9
- package/lib/bootstrap/utils.js +14 -8
- package/lib/commands/cm/bootstrap.js +5 -5
- package/messages/index.json +18 -0
- package/oclif.manifest.json +1 -1
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -2,23 +2,60 @@ Contentstack CLI’s “Bootstrap” plugin enables you to automate the process
|
|
|
2
2
|
|
|
3
3
|
This means that all the required steps such as stack, environment, and content type creation, entry and asset publishing are performed just by using a single command.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
<!-- toc -->
|
|
6
|
+
* [Usage](#usage)
|
|
7
|
+
* [Commands](#commands)
|
|
8
|
+
<!-- tocstop -->
|
|
9
|
+
# Usage
|
|
10
|
+
<!-- usage -->
|
|
11
|
+
```sh-session
|
|
12
|
+
$ npm install -g @contentstack/cli-cm-bootstrap
|
|
13
|
+
$ csdx COMMAND
|
|
14
|
+
running command...
|
|
15
|
+
$ csdx (-v|--version|version)
|
|
16
|
+
@contentstack/cli-cm-bootstrap/1.0.3 darwin-x64 node-v14.16.0
|
|
17
|
+
$ csdx --help [COMMAND]
|
|
18
|
+
USAGE
|
|
19
|
+
$ csdx COMMAND
|
|
20
|
+
...
|
|
21
|
+
```
|
|
22
|
+
<!-- usagestop -->
|
|
23
|
+
```sh-session
|
|
24
|
+
$ npm install -g @contentstack/cli-cm-clone
|
|
25
|
+
$ csdx COMMAND
|
|
26
|
+
running command...
|
|
27
|
+
$ csdx --help [COMMAND]
|
|
28
|
+
USAGE
|
|
29
|
+
$ csdx COMMAND
|
|
30
|
+
...
|
|
31
|
+
```
|
|
32
|
+
# Commands
|
|
33
|
+
<!-- commands -->
|
|
34
|
+
* [`csdx cm:bootstrap`](#csdx-cmbootstrap)
|
|
7
35
|
|
|
8
|
-
|
|
36
|
+
## `csdx cm:bootstrap`
|
|
9
37
|
|
|
10
|
-
|
|
11
|
-
Technology: Select the app framework (React, Angular, Node, and so on) in which you want to set up the project.
|
|
12
|
-
Path: Provide the destination folder path/location where the app will be cloned.
|
|
13
|
-
Organization name: Select your organization name from the provided list.
|
|
14
|
-
Stack: Select the stack where you want to import the content of the app. You can also create a new stack and for the import operation.
|
|
38
|
+
Bootstrap contentstack apps
|
|
15
39
|
|
|
16
|
-
|
|
17
|
-
|
|
40
|
+
```
|
|
41
|
+
USAGE
|
|
42
|
+
$ csdx cm:bootstrap
|
|
18
43
|
|
|
19
|
-
|
|
44
|
+
OPTIONS
|
|
45
|
+
-a, --appName=appName App name, reactjs-starter, nextjs-starter, gatsby-starter, angular-starter,
|
|
46
|
+
nuxt-starter
|
|
20
47
|
|
|
21
|
-
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
48
|
+
-d, --directory=directory Directory to setup the project. If directory name has a space then provide the path as
|
|
49
|
+
a string or escap the space using back slash eg: "../../test space" or ../../test\
|
|
50
|
+
space
|
|
51
|
+
|
|
52
|
+
-t, --accessToken=accessToken Access token for private github repo
|
|
53
|
+
|
|
54
|
+
EXAMPLES
|
|
55
|
+
$ csdx cm:bootstrap
|
|
56
|
+
$ csdx cm:bootstrap -d <path/to/setup/the/app>
|
|
57
|
+
$ csdx cm:bootstrap -t <github access token>
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
_See code: [src/commands/cm/bootstrap.ts](https://github.com/contentstack/cli/blob/v1.0.3/src/commands/cm/bootstrap.ts)_
|
|
61
|
+
<!-- commandsstop -->
|
|
File without changes
|
|
@@ -4,7 +4,7 @@ const axios_1 = require("axios");
|
|
|
4
4
|
const zlib = require("zlib");
|
|
5
5
|
const tar = require("tar");
|
|
6
6
|
const mkdirp = require("mkdirp");
|
|
7
|
-
const
|
|
7
|
+
const github_error_1 = require("./github-error");
|
|
8
8
|
const messages_1 = require("../../messages");
|
|
9
9
|
const DEFAULT_BRANCH = 'master';
|
|
10
10
|
class GitHubClient {
|
|
@@ -46,7 +46,7 @@ class GitHubClient {
|
|
|
46
46
|
};
|
|
47
47
|
}
|
|
48
48
|
else {
|
|
49
|
-
throw new
|
|
49
|
+
throw new github_error_1.default(messages_1.default.parse('CLI_BOOTSTRAP_GITHUB_ACCESS_NOT_FOUND'), 1);
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
const response = await axios_1.default.get(url, options);
|
|
File without changes
|
package/lib/bootstrap/index.js
CHANGED
|
@@ -5,10 +5,10 @@ const cli_ux_1 = require("cli-ux");
|
|
|
5
5
|
const path = require("path");
|
|
6
6
|
const seed_1 = require("@contentstack/cli-cm-seed/lib/commands/cm/seed");
|
|
7
7
|
const client_1 = require("./github/client");
|
|
8
|
-
const
|
|
8
|
+
const github_error_1 = require("./github/github-error");
|
|
9
9
|
const utils_1 = require("./utils");
|
|
10
10
|
const messages_1 = require("../messages");
|
|
11
|
-
exports.ENGLISH_LOCALE =
|
|
11
|
+
exports.ENGLISH_LOCALE = "en-us";
|
|
12
12
|
/**
|
|
13
13
|
* @description Bootstraps the sample app
|
|
14
14
|
* Clone the repo
|
|
@@ -31,14 +31,14 @@ class Bootstrap {
|
|
|
31
31
|
this.options = options;
|
|
32
32
|
}
|
|
33
33
|
async run() {
|
|
34
|
-
cli_ux_1.default.action.start(messages_1.default.parse(
|
|
34
|
+
cli_ux_1.default.action.start(messages_1.default.parse("CLI_BOOTSTRAP_START_CLONE_APP"));
|
|
35
35
|
try {
|
|
36
36
|
await this.ghClient.getLatest(this.cloneDirectory);
|
|
37
37
|
}
|
|
38
38
|
catch (error) {
|
|
39
|
-
if (error instanceof
|
|
39
|
+
if (error instanceof github_error_1.default) {
|
|
40
40
|
if (error.status === 404) {
|
|
41
|
-
cli_ux_1.default.error(messages_1.default.parse(
|
|
41
|
+
cli_ux_1.default.error(messages_1.default.parse("CLI_BOOTSTRAP_REPO_NOT_FOUND", this.appConfig.source));
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
throw error;
|
|
@@ -48,17 +48,17 @@ class Bootstrap {
|
|
|
48
48
|
}
|
|
49
49
|
// seed plugin start
|
|
50
50
|
try {
|
|
51
|
-
const result = await seed_1.default.run([
|
|
51
|
+
const result = await seed_1.default.run(["-r", this.appConfig.stack]);
|
|
52
52
|
if (result.api_key) {
|
|
53
53
|
await utils_1.setupEnvironments(this.managementAPIClient, result.api_key, this.appConfig, this.cloneDirectory, this.region);
|
|
54
54
|
}
|
|
55
55
|
else {
|
|
56
|
-
throw new Error(messages_1.default.parse(
|
|
56
|
+
throw new Error(messages_1.default.parse("CLI_BOOTSTRAP_NO_API_KEY_FOUND"));
|
|
57
57
|
}
|
|
58
|
-
cli_ux_1.default.log(messages_1.default.parse(
|
|
58
|
+
cli_ux_1.default.log(messages_1.default.parse("CLI_BOOTSTRAP_SUCCESS"));
|
|
59
59
|
}
|
|
60
60
|
catch (error) {
|
|
61
|
-
cli_ux_1.default.error(messages_1.default.parse(
|
|
61
|
+
cli_ux_1.default.error(messages_1.default.parse("CLI_BOOTSTRAP_STACK_CREATION_FAILED", this.appConfig.stack));
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
64
|
}
|
package/lib/bootstrap/utils.js
CHANGED
|
@@ -20,14 +20,19 @@ exports.setupEnvironments = async (managementAPIClient, api_key, appConfig, clon
|
|
|
20
20
|
'token': {
|
|
21
21
|
'name': `Sample app ${environment.name}`,
|
|
22
22
|
'description': 'Sample app',
|
|
23
|
-
'scope': [
|
|
23
|
+
'scope': [
|
|
24
|
+
{
|
|
24
25
|
'module': 'environment',
|
|
25
26
|
'environments': [environment.name],
|
|
26
|
-
'acl': {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
'acl': { 'read': true }
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
module: "branch",
|
|
31
|
+
acl: { read: true },
|
|
32
|
+
branches: ["main"]
|
|
33
|
+
}
|
|
34
|
+
]
|
|
35
|
+
},
|
|
31
36
|
};
|
|
32
37
|
try {
|
|
33
38
|
const tokenResult = await managementAPIClient.stack({ api_key }).deliveryToken().create(body);
|
|
@@ -44,6 +49,7 @@ exports.setupEnvironments = async (managementAPIClient, api_key, appConfig, clon
|
|
|
44
49
|
}
|
|
45
50
|
}
|
|
46
51
|
catch (error) {
|
|
52
|
+
console.log("error", error);
|
|
47
53
|
cli_ux_1.default.log(messages_1.default.parse('CLI_BOOTSTRAP_APP_FAILED_TO_CREATE_ENV_FILE_FOR_ENV', environment.name));
|
|
48
54
|
}
|
|
49
55
|
}
|
|
@@ -95,14 +101,14 @@ const envFileHandler = async (appConfigKey, environmentVariables, clonedDirector
|
|
|
95
101
|
case 'reactjs-starter':
|
|
96
102
|
fileName = `.env.${environmentVariables.environment}.local`;
|
|
97
103
|
filePath = path.join(clonedDirectory, fileName);
|
|
98
|
-
content = `
|
|
104
|
+
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_CUSTOM_HOST=' + customHost : '')}${(!isUSRegion && !customHost) ? '\nREACT_APP_CONTENTSTACK_REGION=' + region.name : ''}`;
|
|
99
105
|
result = await writeEnvFile(content, filePath);
|
|
100
106
|
break;
|
|
101
107
|
case 'nextjs':
|
|
102
108
|
case 'nextjs-starter':
|
|
103
109
|
fileName = `.env.${environmentVariables.environment}.local`;
|
|
104
110
|
filePath = path.join(clonedDirectory, fileName);
|
|
105
|
-
content = `
|
|
111
|
+
content = `CONTENTSTACK_API_KEY=${environmentVariables.api_key}\nCONTENTSTACK_DELIVERY_TOKEN=${environmentVariables.deliveryToken}\nCONTENTSTACK_ENVIRONMENT=${environmentVariables.environment}${(customHost ? '\nCONTENTSTACK_CUSTOM_HOST=' + customHost : '')}${(!isUSRegion && !customHost ? '\nCONTENTSTACK_REGION=' + region.name : '')}`;
|
|
106
112
|
result = await writeEnvFile(content, filePath);
|
|
107
113
|
break;
|
|
108
114
|
case 'gatsby':
|
|
@@ -12,17 +12,17 @@ class BootstrapCommand extends cli_command_1.Command {
|
|
|
12
12
|
return this._managementAPIClient;
|
|
13
13
|
}
|
|
14
14
|
async run() {
|
|
15
|
-
const
|
|
15
|
+
const bootstrapCommandFlags = this.parse(BootstrapCommand).flags;
|
|
16
16
|
try {
|
|
17
17
|
if (!this.authToken) {
|
|
18
18
|
this.error(messages_1.default.parse('CLI_BOOTSTRAP_LOGIN_FAILED'), { exit: 2, suggestions: ['https://www.contentstack.com/docs/developers/cli/authentication/'] });
|
|
19
19
|
}
|
|
20
20
|
// inquire user inputs
|
|
21
|
-
let appType =
|
|
21
|
+
let appType = bootstrapCommandFlags.appType || 'starterapp';
|
|
22
22
|
if (!appType) {
|
|
23
23
|
appType = await interactive_1.inquireAppType();
|
|
24
24
|
}
|
|
25
|
-
const selectedAppName =
|
|
25
|
+
const selectedAppName = bootstrapCommandFlags.appName;
|
|
26
26
|
let selectedApp;
|
|
27
27
|
if (!selectedAppName) {
|
|
28
28
|
if (appType === 'sampleapp') {
|
|
@@ -39,12 +39,12 @@ class BootstrapCommand extends cli_command_1.Command {
|
|
|
39
39
|
this.error(messages_1.default.parse('CLI_BOOTSTRAP_INVALID_APP_NAME'), { exit: 1 });
|
|
40
40
|
}
|
|
41
41
|
const appConfig = config_1.getAppLevelConfigByName(selectedAppName || selectedApp.configKey);
|
|
42
|
-
let cloneDirectory =
|
|
42
|
+
let cloneDirectory = bootstrapCommandFlags.directory;
|
|
43
43
|
if (!cloneDirectory) {
|
|
44
44
|
cloneDirectory = await interactive_1.inquireCloneDirectory();
|
|
45
45
|
}
|
|
46
46
|
// Check the access token
|
|
47
|
-
let accessToken =
|
|
47
|
+
let accessToken = bootstrapCommandFlags.accessToken;
|
|
48
48
|
if (appConfig.private && !accessToken) {
|
|
49
49
|
accessToken = await interactive_1.inquireGithubAccessToken();
|
|
50
50
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"CLI_BOOTSTRAP_INVALID_APP_NAME": "Invalid app name received, use cm:bootstrap see the list of apps supported",
|
|
3
|
+
"CLI_BOOTSTRAP_LOGIN_FAILED": "You need to login, first. See: auth:login --help",
|
|
4
|
+
"CLI_BOOTSTRAP_GITHUB_ACCESS_NOT_FOUND": "No Github access token found",
|
|
5
|
+
"CLI_BOOTSTRAP_START_CLONE_APP": "Cloning the selected app",
|
|
6
|
+
"CLI_BOOTSTRAP_REPO_NOT_FOUND": "Unable to find a repo for \"%s\"",
|
|
7
|
+
"CLI_BOOTSTRAP_NO_API_KEY_FOUND": "No API key generated for the stack",
|
|
8
|
+
"CLI_BOOTSTRAP_STACK_CREATION_FAILED": "Unable to create stack for content \"%s\"",
|
|
9
|
+
"CLI_BOOTSTRAP_APP_SELECTION_ENQUIRY": "Select an App",
|
|
10
|
+
"CLI_BOOTSTRAP_APP_COPY_SOURCE_CODE_DESTINATION_TYPE_ENQUIRY": "Choose the location where you want to copy the source code",
|
|
11
|
+
"CLI_BOOTSTRAP_APP_COPY_SOURCE_CODE_DESTINATION_ENQUIRY": "Enter destination path",
|
|
12
|
+
"CLI_BOOTSTRAP_NO_ACCESS_TOKEN_CREATED": "Note: Access token not created already, check out this link https://github.com/settings/tokens \n Provide github access token",
|
|
13
|
+
"CLI_BOOTSTRAP_TYPE_OF_APP_ENQUIRY": "Choose the type of app you want to clone",
|
|
14
|
+
"CLI_BOOTSTRAP_APP_FAILED_TO_CREATE_TOKEN_FOR_ENV": "Failed to create delivery token for env \"%s\"",
|
|
15
|
+
"CLI_BOOTSTRAP_APP_FAILED_TO_CREATE_ENV_FILE_FOR_ENV": "Failed to setup env file for \"%s\"",
|
|
16
|
+
"CLI_BOOTSTRAP_APP_ENV_NOT_FOUND_FOR_THE_STACK": "No environments found for the stack",
|
|
17
|
+
"CLI_BOOTSTRAP_SUCCESS": "Project setup is successful!"
|
|
18
|
+
}
|
package/oclif.manifest.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":"1.0.
|
|
1
|
+
{"version":"1.0.3","commands":{"cm:bootstrap":{"id":"cm:bootstrap","description":"Bootstrap contentstack apps","pluginName":"@contentstack/cli-cm-bootstrap","pluginType":"core","aliases":[],"examples":["$ csdx cm:bootstrap","$ csdx cm:bootstrap -d <path/to/setup/the/app>","$ csdx cm:bootstrap -t <github access token>"],"flags":{"appName":{"name":"appName","type":"option","char":"a","description":"App name, reactjs-starter, nextjs-starter, gatsby-starter, angular-starter, nuxt-starter","required":false},"directory":{"name":"directory","type":"option","char":"d","description":"Directory to setup the project. If directory name has a space then provide the path as a string or escap the space using back slash eg: \"../../test space\" or ../../test\\ space","required":false},"accessToken":{"name":"accessToken","type":"option","char":"t","description":"Access token for private github repo","required":false},"appType":{"name":"appType","type":"option","char":"s","description":"Sample or Starter app","hidden":true,"required":false}},"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.0.
|
|
4
|
+
"version": "1.0.3",
|
|
5
5
|
"author": "Contentstack",
|
|
6
6
|
"bugs": "https://github.com/contentstack/cli/issues",
|
|
7
7
|
"scripts": {
|
|
@@ -18,8 +18,8 @@
|
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@contentstack/cli-command": "^0.1.1-beta.1",
|
|
21
|
-
"@contentstack/cli-cm-seed": "1.0.
|
|
22
|
-
"@contentstack/management": "^1.2.
|
|
21
|
+
"@contentstack/cli-cm-seed": "^1.0.7",
|
|
22
|
+
"@contentstack/management": "^1.2.4",
|
|
23
23
|
"@oclif/command": "^1.8.0",
|
|
24
24
|
"@oclif/config": "^1.17.0",
|
|
25
25
|
"axios": "^0.21.1",
|
|
@@ -53,6 +53,7 @@
|
|
|
53
53
|
},
|
|
54
54
|
"files": [
|
|
55
55
|
"/lib",
|
|
56
|
+
"/messages",
|
|
56
57
|
"/npm-shrinkwrap.json",
|
|
57
58
|
"/oclif.manifest.json"
|
|
58
59
|
],
|