@contentstack/cli-cm-bootstrap 1.0.8 → 1.1.1

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Contentstack
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- Contentstack CLI’s “Bootstrap” plugin enables you to automate the process of setting up projects for sample and starter apps in Contentstack.
1
+ Contentstack CLI’s “Bootstrap” plugin enables you to automate the process of setting up projects for sample and starter apps in Contentstack.
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
 
@@ -6,20 +6,23 @@ This means that all the required steps such as stack, environment, and content t
6
6
  * [Usage](#usage)
7
7
  * [Commands](#commands)
8
8
  <!-- tocstop -->
9
+
9
10
  # Usage
11
+
10
12
  <!-- usage -->
11
13
  ```sh-session
12
14
  $ npm install -g @contentstack/cli-cm-bootstrap
13
15
  $ csdx COMMAND
14
16
  running command...
15
17
  $ csdx (-v|--version|version)
16
- @contentstack/cli-cm-bootstrap/1.0.8 linux-x64 node-v16.14.2
18
+ @contentstack/cli-cm-bootstrap/1.1.1 darwin-arm64 node-v16.17.0
17
19
  $ csdx --help [COMMAND]
18
20
  USAGE
19
21
  $ csdx COMMAND
20
22
  ...
21
23
  ```
22
24
  <!-- usagestop -->
25
+
23
26
  ```sh-session
24
27
  $ npm install -g @contentstack/cli-cm-clone
25
28
  $ csdx COMMAND
@@ -29,7 +32,9 @@ USAGE
29
32
  $ csdx COMMAND
30
33
  ...
31
34
  ```
35
+
32
36
  # Commands
37
+
33
38
  <!-- commands -->
34
39
  * [`csdx cm:bootstrap`](#csdx-cmbootstrap)
35
40
 
@@ -42,20 +47,27 @@ USAGE
42
47
  $ csdx cm:bootstrap
43
48
 
44
49
  OPTIONS
45
- -a, --appName=appName App name, reactjs-starter, nextjs-starter, gatsby-starter, angular-starter,
46
- nuxt-starter
50
+ -k, --stack-api-key=stack-api-key Provide stack API key to seed content
51
+ -n, --stack-name=stack-name Name of a new stack that will be created.
52
+ -y, --yes=yes
53
+
54
+ --app-name=app-name App name, reactjs-starter, nextjs-starter, gatsby-starter, angular-starter,
55
+ nuxt-starter, vue-starter, stencil-starter
47
56
 
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
57
+ --org=org Provide organization UID to create a new stack
51
58
 
52
- -t, --accessToken=accessToken Access token for private github repo
59
+ --project-dir=project-dir Directory to setup the project. If directory name has a space then provide the path
60
+ as a string or escap the space using back slash eg: "../../test space" or
61
+ ../../test\ space
53
62
 
54
63
  EXAMPLES
55
64
  $ csdx cm:bootstrap
56
- $ csdx cm:bootstrap -d <path/to/setup/the/app>
57
- $ csdx cm:bootstrap -t <github access token>
65
+ $ csdx cm:bootstrap --project-dir <path/to/setup/the/app>
66
+ $ csdx cm:bootstrap --app-name "reactjs-starter" --project-dir <path/to/setup/the/app>
67
+ $ csdx cm:bootstrap --app-name "reactjs-starter" --project-dir <path/to/setup/the/app> --stack-api-key "stack-api-key"
68
+ $ csdx cm:bootstrap --app-name "reactjs-starter" --project-dir <path/to/setup/the/app> --org "your-org-uid"
69
+ --stack-name "stack-name"
58
70
  ```
59
71
 
60
- _See code: [src/commands/cm/bootstrap.ts](https://github.com/contentstack/cli/blob/v1.0.8/src/commands/cm/bootstrap.ts)_
72
+ _See code: [src/commands/cm/bootstrap.ts](https://github.com/contentstack/cli/blob/v1.1.1/src/commands/cm/bootstrap.ts)_
61
73
  <!-- commandsstop -->
@@ -5,7 +5,7 @@ class BootstrapError extends Error {
5
5
  super(message);
6
6
  this.suggestions = suggestions;
7
7
  this.name = this.constructor.name;
8
- if (typeof Error.captureStackTrace === 'function') {
8
+ if (typeof Error.captureStackTrace === "function") {
9
9
  Error.captureStackTrace(this, this.constructor);
10
10
  }
11
11
  else {
@@ -1,12 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const axios_1 = require("axios");
4
3
  const zlib = require("zlib");
5
4
  const tar = require("tar");
6
5
  const mkdirp = require("mkdirp");
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");
9
- const DEFAULT_BRANCH = 'master';
9
+ const DEFAULT_BRANCH = 'cli-use';
10
10
  class GitHubClient {
11
11
  constructor(repo, privateRepo = false, token) {
12
12
  this.repo = repo;
@@ -42,14 +42,14 @@ class GitHubClient {
42
42
  if (this.private) {
43
43
  if (this.accessToken) {
44
44
  options.headers = {
45
- Authorization: `token ${this.accessToken}`
45
+ Authorization: `token ${this.accessToken}`,
46
46
  };
47
47
  }
48
48
  else {
49
49
  throw new github_error_1.default(messages_1.default.parse('CLI_BOOTSTRAP_GITHUB_ACCESS_NOT_FOUND'), 1);
50
50
  }
51
51
  }
52
- const response = await axios_1.default.get(url, options);
52
+ const response = await cli_utilities_1.HttpClient.create().options(options).get(url);
53
53
  return response.data;
54
54
  }
55
55
  async extract(destination, stream) {
@@ -5,7 +5,7 @@ class GithubError extends Error {
5
5
  super(message);
6
6
  this.status = status;
7
7
  this.name = this.constructor.name;
8
- if (typeof Error.captureStackTrace === 'function') {
8
+ if (typeof Error.captureStackTrace === "function") {
9
9
  Error.captureStackTrace(this, this.constructor);
10
10
  }
11
11
  else {
@@ -1,14 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ENGLISH_LOCALE = void 0;
4
- const cli_ux_1 = require("cli-ux");
5
4
  const path = require("path");
6
- const seed_1 = require("@contentstack/cli-cm-seed/lib/commands/cm/seed");
7
- const client_1 = require("./github/client");
8
- const github_error_1 = require("./github/github-error");
9
- const utils_1 = require("./utils");
5
+ const cli_utilities_1 = require("@contentstack/cli-utilities");
6
+ const seed_1 = require("@contentstack/cli-cm-seed/lib/commands/cm/stacks/seed");
10
7
  const messages_1 = require("../messages");
11
- exports.ENGLISH_LOCALE = "en-us";
8
+ const utils_1 = require("./utils");
9
+ const github_error_1 = require("./github/github-error");
10
+ const client_1 = require("./github/client");
11
+ exports.ENGLISH_LOCALE = 'en-us';
12
12
  /**
13
13
  * @description Bootstraps the sample app
14
14
  * Clone the repo
@@ -31,34 +31,47 @@ class Bootstrap {
31
31
  this.options = options;
32
32
  }
33
33
  async run() {
34
- cli_ux_1.default.action.start(messages_1.default.parse("CLI_BOOTSTRAP_START_CLONE_APP"));
34
+ cli_utilities_1.cliux.loader(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
39
  if (error instanceof github_error_1.default) {
40
40
  if (error.status === 404) {
41
- cli_ux_1.default.error(messages_1.default.parse("CLI_BOOTSTRAP_REPO_NOT_FOUND", this.appConfig.source));
41
+ cli_utilities_1.cliux.error(messages_1.default.parse('CLI_BOOTSTRAP_REPO_NOT_FOUND', this.appConfig.source));
42
42
  }
43
43
  }
44
44
  throw error;
45
45
  }
46
46
  finally {
47
- cli_ux_1.default.action.stop();
47
+ cli_utilities_1.cliux.loader();
48
48
  }
49
49
  // seed plugin start
50
50
  try {
51
- const result = await seed_1.default.run(["-r", this.appConfig.stack]);
51
+ const cmd = ['--repo', this.appConfig.stack];
52
+ if (this.options.seedParams.stackAPIKey) {
53
+ cmd.push('--stack-api-key', this.options.seedParams.stackAPIKey);
54
+ }
55
+ if (this.options.seedParams.org) {
56
+ cmd.push('--org', this.options.seedParams.org);
57
+ }
58
+ if (this.options.seedParams.stackName) {
59
+ cmd.push('-n', this.options.seedParams.stackName);
60
+ }
61
+ if (this.options.seedParams.yes) {
62
+ cmd.push('-y', this.options.seedParams.yes);
63
+ }
64
+ const result = await seed_1.default.run(cmd);
52
65
  if (result.api_key) {
53
- await (0, utils_1.setupEnvironments)(this.managementAPIClient, result.api_key, this.appConfig, this.cloneDirectory, this.region);
66
+ await (0, utils_1.setupEnvironments)(this.managementAPIClient, result.api_key, this.appConfig, this.cloneDirectory, this.region, this.options.livePreviewEnabled);
54
67
  }
55
68
  else {
56
- throw new Error(messages_1.default.parse("CLI_BOOTSTRAP_NO_API_KEY_FOUND"));
69
+ throw new Error(messages_1.default.parse('CLI_BOOTSTRAP_NO_API_KEY_FOUND'));
57
70
  }
58
- cli_ux_1.default.log(messages_1.default.parse("CLI_BOOTSTRAP_SUCCESS"));
71
+ cli_utilities_1.cliux.print(messages_1.default.parse('CLI_BOOTSTRAP_SUCCESS'));
59
72
  }
60
73
  catch (error) {
61
- cli_ux_1.default.error(messages_1.default.parse("CLI_BOOTSTRAP_STACK_CREATION_FAILED", this.appConfig.stack));
74
+ cli_utilities_1.cliux.error(messages_1.default.parse('CLI_BOOTSTRAP_STACK_CREATION_FAILED', this.appConfig.stack));
62
75
  }
63
76
  }
64
77
  }
@@ -1,29 +1,31 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.inquireAppType = exports.inquireGithubAccessToken = exports.inquireCloneDirectory = exports.inquireApp = void 0;
4
- const inquirer = require("inquirer");
5
- const cli_ux_1 = require("cli-ux");
3
+ exports.inquireLivePreviewSupport = exports.inquireAppType = exports.inquireGithubAccessToken = exports.inquireCloneDirectory = exports.inquireApp = void 0;
6
4
  const path = require("path");
5
+ const inquirer = require("inquirer");
6
+ const cli_utilities_1 = require("@contentstack/cli-utilities");
7
7
  const messages_1 = require("../messages");
8
8
  /**
9
9
  * @description Inquire starter app
10
10
  */
11
11
  async function inquireApp(apps) {
12
- const appsPreview = apps.map(app => {
12
+ const appsPreview = apps.map((app) => {
13
13
  return {
14
14
  name: app.displayName,
15
15
  value: app,
16
16
  };
17
17
  });
18
- const actions = [{
18
+ const actions = [
19
+ {
19
20
  type: 'list',
20
21
  name: 'app',
21
22
  message: messages_1.default.parse('CLI_BOOTSTRAP_APP_SELECTION_ENQUIRY'),
22
23
  choices: [...appsPreview, 'Exit'],
23
- }];
24
+ },
25
+ ];
24
26
  const selectedApp = await inquirer.prompt(actions);
25
27
  if (selectedApp.app === 'Exit') {
26
- cli_ux_1.default.log('Exiting...');
28
+ cli_utilities_1.cliux.print('Exiting...');
27
29
  throw new Error('Exit');
28
30
  }
29
31
  return selectedApp.app;
@@ -33,36 +35,64 @@ exports.inquireApp = inquireApp;
33
35
  * @description Inquire clone destination directory
34
36
  */
35
37
  async function inquireCloneDirectory() {
36
- const actions = [{
38
+ const actions = [
39
+ {
37
40
  type: 'list',
38
41
  name: 'path',
39
42
  message: messages_1.default.parse('CLI_BOOTSTRAP_APP_COPY_SOURCE_CODE_DESTINATION_TYPE_ENQUIRY'),
40
43
  choices: ['Current Folder', 'Other'],
41
- }];
44
+ },
45
+ ];
42
46
  const selectedPath = await inquirer.prompt(actions);
43
47
  if (selectedPath.path === 'Current Folder') {
44
48
  return process.cwd();
45
49
  }
46
50
  // Ask for the custom path
47
- let selectedCustomPath = await inquirer.prompt([{ type: 'string', name: 'path', message: messages_1.default.parse('CLI_BOOTSTRAP_APP_COPY_SOURCE_CODE_DESTINATION_ENQUIRY') }]);
51
+ let selectedCustomPath = await inquirer.prompt([
52
+ {
53
+ type: 'string',
54
+ name: 'path',
55
+ message: messages_1.default.parse('CLI_BOOTSTRAP_APP_COPY_SOURCE_CODE_DESTINATION_ENQUIRY'),
56
+ },
57
+ ]);
48
58
  selectedCustomPath = path.resolve(selectedCustomPath.path);
49
59
  return selectedCustomPath;
50
60
  }
51
61
  exports.inquireCloneDirectory = inquireCloneDirectory;
52
62
  async function inquireGithubAccessToken() {
53
63
  // Ask for the access token
54
- const accessToken = await inquirer.prompt([{ type: 'string', name: 'token', message: messages_1.default.parse('CLI_BOOTSTRAP_NO_ACCESS_TOKEN_CREATED') }]);
64
+ const accessToken = await inquirer.prompt([
65
+ {
66
+ type: 'string',
67
+ name: 'token',
68
+ message: messages_1.default.parse('CLI_BOOTSTRAP_NO_ACCESS_TOKEN_CREATED'),
69
+ },
70
+ ]);
55
71
  return accessToken.token;
56
72
  }
57
73
  exports.inquireGithubAccessToken = inquireGithubAccessToken;
58
74
  async function inquireAppType() {
59
- const actions = [{
75
+ const actions = [
76
+ {
60
77
  type: 'list',
61
78
  name: 'type',
62
79
  message: messages_1.default.parse('CLI_BOOTSTRAP_TYPE_OF_APP_ENQUIRY'),
63
- choices: [{ name: 'Sample App', value: 'sampleapp' }, { name: 'Starter App', value: 'starterapp' }],
64
- }];
80
+ choices: [
81
+ { name: 'Sample App', value: 'sampleapp' },
82
+ { name: 'Starter App', value: 'starterapp' },
83
+ ],
84
+ },
85
+ ];
65
86
  const appType = await inquirer.prompt(actions);
66
87
  return appType.type;
67
88
  }
68
89
  exports.inquireAppType = inquireAppType;
90
+ async function inquireLivePreviewSupport() {
91
+ const { livePreviewEnabled } = await inquirer.prompt({
92
+ type: 'confirm',
93
+ name: 'livePreviewEnabled',
94
+ message: 'Enable live preview?'
95
+ });
96
+ return livePreviewEnabled;
97
+ }
98
+ exports.inquireLivePreviewSupport = inquireLivePreviewSupport;
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.setupEnvironments = void 0;
4
- const cli_ux_1 = require("cli-ux");
5
4
  const fs = require("fs");
6
5
  const path = require("path");
6
+ const cli_utilities_1 = require("@contentstack/cli-utilities");
7
7
  const messages_1 = require("../messages");
8
8
  /**
9
9
  * @description Setup the environment for a given app for each environment
@@ -11,27 +11,27 @@ 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) => {
14
+ const setupEnvironments = async (managementAPIClient, api_key, appConfig, clonedDirectory, region, livePreviewEnabled) => {
15
15
  const environmentResult = await managementAPIClient.stack({ api_key }).environment().query().find();
16
16
  if (Array.isArray(environmentResult.items) && environmentResult.items.length > 0) {
17
17
  for (const environment of environmentResult.items) {
18
18
  if (environment.name) {
19
19
  const body = {
20
- 'token': {
21
- 'name': `Sample app ${environment.name}`,
22
- 'description': 'Sample app',
23
- 'scope': [
20
+ token: {
21
+ name: `Sample app ${environment.name}`,
22
+ description: 'Sample app',
23
+ scope: [
24
24
  {
25
- 'module': 'environment',
26
- 'environments': [environment.name],
27
- 'acl': { 'read': true }
25
+ module: 'environment',
26
+ environments: [environment.name],
27
+ acl: { read: true },
28
28
  },
29
29
  {
30
- module: "branch",
30
+ module: 'branch',
31
31
  acl: { read: true },
32
- branches: ["main"]
33
- }
34
- ]
32
+ branches: ['main'],
33
+ },
34
+ ],
35
35
  },
36
36
  };
37
37
  try {
@@ -40,26 +40,27 @@ const setupEnvironments = async (managementAPIClient, api_key, appConfig, cloned
40
40
  const environmentVariables = {
41
41
  api_key,
42
42
  deliveryToken: tokenResult.token,
43
- environment: environment.name
43
+ environment: environment.name,
44
+ livePreviewEnabled,
44
45
  };
45
- await envFileHandler(appConfig.appConfigKey || "", environmentVariables, clonedDirectory, region);
46
+ await envFileHandler(appConfig.appConfigKey || '', environmentVariables, clonedDirectory, region, livePreviewEnabled);
46
47
  }
47
48
  else {
48
- cli_ux_1.default.log(messages_1.default.parse('CLI_BOOTSTRAP_APP_FAILED_TO_CREATE_TOKEN_FOR_ENV', environment.name));
49
+ cli_utilities_1.cliux.print(messages_1.default.parse('CLI_BOOTSTRAP_APP_FAILED_TO_CREATE_TOKEN_FOR_ENV', environment.name));
49
50
  }
50
51
  }
51
52
  catch (error) {
52
- console.log("error", error);
53
- cli_ux_1.default.log(messages_1.default.parse('CLI_BOOTSTRAP_APP_FAILED_TO_CREATE_ENV_FILE_FOR_ENV', environment.name));
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));
54
55
  }
55
56
  }
56
57
  else {
57
- cli_ux_1.default.log('No environments name found for the environment');
58
+ cli_utilities_1.cliux.print('No environments name found for the environment');
58
59
  }
59
60
  }
60
61
  }
61
62
  else {
62
- cli_ux_1.default.error(messages_1.default.parse('CLI_BOOTSTRAP_APP_ENV_NOT_FOUND_FOR_THE_STACK'));
63
+ cli_utilities_1.cliux.error(messages_1.default.parse('CLI_BOOTSTRAP_APP_ENV_NOT_FOUND_FOR_THE_STACK'));
63
64
  }
64
65
  };
65
66
  exports.setupEnvironments = setupEnvironments;
@@ -68,7 +69,7 @@ const writeEnvFile = (content, fileName) => {
68
69
  return;
69
70
  }
70
71
  return new Promise((resolve, reject) => {
71
- fs.writeFile(fileName, content, 'utf8', error => {
72
+ fs.writeFile(fileName, content, 'utf8', (error) => {
72
73
  if (error) {
73
74
  reject(error);
74
75
  }
@@ -82,7 +83,7 @@ const writeEnvFile = (content, fileName) => {
82
83
  * @description Create environment files for each app
83
84
  * TBD: moving the content to config file
84
85
  */
85
- const envFileHandler = async (appConfigKey, environmentVariables, clonedDirectory, region) => {
86
+ const envFileHandler = async (appConfigKey, environmentVariables, clonedDirectory, region, livePreviewEnabled) => {
86
87
  if (!appConfigKey || !environmentVariables) {
87
88
  return;
88
89
  }
@@ -103,21 +104,21 @@ const envFileHandler = async (appConfigKey, environmentVariables, clonedDirector
103
104
  case 'reactjs-starter':
104
105
  fileName = `.env.${environmentVariables.environment}.local`;
105
106
  filePath = path.join(clonedDirectory, fileName);
106
- 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`;
107
+ 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}`;
107
108
  result = await writeEnvFile(content, filePath);
108
109
  break;
109
110
  case 'nextjs':
110
111
  case 'nextjs-starter':
111
112
  fileName = `.env.${environmentVariables.environment}.local`;
112
113
  filePath = path.join(clonedDirectory, fileName);
113
- 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 : '')}`;
114
+ 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}`;
114
115
  result = await writeEnvFile(content, filePath);
115
116
  break;
116
117
  case 'gatsby':
117
118
  case 'gatsby-starter':
118
119
  fileName = `.env.${environmentVariables.environment}`;
119
120
  filePath = path.join(clonedDirectory, fileName);
120
- content = `CONTENTSTACK_API_KEY=${environmentVariables.api_key}\nCONTENTSTACK_DELIVERY_TOKEN=${environmentVariables.deliveryToken}\nCONTENTSTACK_ENVIRONMENT=${environmentVariables.environment}\nCONTENTSTACK_API_HOST=${managementAPIHost}`;
121
+ content = `CONTENTSTACK_API_KEY=${environmentVariables.api_key}\nCONTENTSTACK_DELIVERY_TOKEN=${environmentVariables.deliveryToken}\nCONTENTSTACK_ENVIRONMENT=${environmentVariables.environment}\nCONTENTSTACK_API_HOST=${managementAPIHost}\nCONTENTSTACK_LIVE_PREVIEW=${livePreviewEnabled}`;
121
122
  result = await writeEnvFile(content, filePath);
122
123
  break;
123
124
  case 'angular':
@@ -127,20 +128,27 @@ const envFileHandler = async (appConfigKey, environmentVariables, clonedDirector
127
128
  result = await writeEnvFile(content, filePath);
128
129
  break;
129
130
  case 'angular-starter':
130
- 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 : ''}',\n\tapp_host: '',\n\tmanagement_token: '',\n\tlive_preview: ''\n};`;
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}'${(!isUSRegion && !customHost ? `,\n\tregion: '${region.name}'` : '')},\n\tapi_host: '${customHost ? customHost : managementAPIHost}',\n\tapp_host: '',\n\tmanagement_token: '',\n\tlive_preview: ${livePreviewEnabled}\n};`;
131
132
  fileName = `environment${(environmentVariables.environment === 'production' ? '.prod.' : ".")}ts`;
132
133
  filePath = path.join(clonedDirectory, 'src', 'environments', fileName);
133
134
  result = await writeEnvFile(content, filePath);
134
135
  break;
135
136
  case 'nuxtjs':
136
137
  case 'nuxt-starter':
138
+ case 'stencil-starter':
137
139
  fileName = (production ? '.env.production' : '.env');
138
140
  filePath = path.join(clonedDirectory, fileName);
139
- 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 : '')}`;
141
+ 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}`;
142
+ result = await writeEnvFile(content, filePath);
143
+ break;
144
+ case 'vue-starter':
145
+ fileName = '.env';
146
+ filePath = path.join(clonedDirectory, fileName);
147
+ 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}`;
140
148
  result = await writeEnvFile(content, filePath);
141
149
  break;
142
150
  default:
143
- cli_ux_1.default.error(messages_1.default.parse('CLI_BOOTSTRAP_INVALID_APP_NAME'));
151
+ cli_utilities_1.cliux.error(messages_1.default.parse('CLI_BOOTSTRAP_INVALID_APP_NAME'));
144
152
  }
145
153
  return result;
146
154
  };
@@ -1,68 +1,82 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const cli_command_1 = require("@contentstack/cli-command");
4
+ const path_1 = require("path");
4
5
  const ContentstackManagementSDK = require('@contentstack/management');
5
6
  const bootstrap_1 = require("../../bootstrap");
6
7
  const interactive_1 = require("../../bootstrap/interactive");
8
+ const cli_utilities_1 = require("@contentstack/cli-utilities");
7
9
  const config_1 = require("../../config");
8
10
  const messages_1 = require("../../messages");
9
11
  class BootstrapCommand extends cli_command_1.Command {
10
12
  get managementAPIClient() {
11
- this._managementAPIClient = ContentstackManagementSDK.client({ host: this.cmaHost, authtoken: this.authToken });
12
- return this._managementAPIClient;
13
+ this.bootstrapManagementAPIClient = ContentstackManagementSDK.client({
14
+ host: this.cmaHost,
15
+ authtoken: this.authToken,
16
+ });
17
+ return this.bootstrapManagementAPIClient;
13
18
  }
14
19
  async run() {
15
20
  const bootstrapCommandFlags = this.parse(BootstrapCommand).flags;
16
21
  try {
17
22
  if (!this.authToken) {
18
- this.error(messages_1.default.parse("CLI_BOOTSTRAP_LOGIN_FAILED"), {
23
+ this.error(messages_1.default.parse('CLI_BOOTSTRAP_LOGIN_FAILED'), {
19
24
  exit: 2,
20
- suggestions: [
21
- "https://www.contentstack.com/docs/developers/cli/authentication/",
22
- ],
25
+ suggestions: ['https://www.contentstack.com/docs/developers/cli/authentication/'],
23
26
  });
24
27
  }
25
28
  // inquire user inputs
26
- let appType = bootstrapCommandFlags.appType || "starterapp";
29
+ let appType = bootstrapCommandFlags.appType || bootstrapCommandFlags['app-type'] || 'starterapp';
27
30
  if (!appType) {
28
31
  appType = await (0, interactive_1.inquireAppType)();
29
32
  }
30
- const selectedAppName = bootstrapCommandFlags.appName;
33
+ const selectedAppName = bootstrapCommandFlags.appName || bootstrapCommandFlags['app-name'];
31
34
  let selectedApp;
32
35
  if (!selectedAppName) {
33
- if (appType === "sampleapp") {
36
+ if (appType === 'sampleapp') {
34
37
  selectedApp = await (0, interactive_1.inquireApp)(config_1.default.sampleApps);
35
38
  }
36
- else if (appType === "starterapp") {
39
+ else if (appType === 'starterapp') {
37
40
  selectedApp = await (0, interactive_1.inquireApp)(config_1.default.starterApps);
38
41
  }
39
42
  else {
40
- this.error("Invalid app type provided " + appType, { exit: 1 });
43
+ this.error('Invalid app type provided ' + appType, { exit: 1 });
41
44
  }
42
45
  }
43
46
  if (!selectedAppName && !selectedApp) {
44
- this.error(messages_1.default.parse("CLI_BOOTSTRAP_INVALID_APP_NAME"), {
47
+ this.error(messages_1.default.parse('CLI_BOOTSTRAP_INVALID_APP_NAME'), {
45
48
  exit: 1,
46
49
  });
47
50
  }
51
+ const yes = bootstrapCommandFlags.yes;
48
52
  const appConfig = (0, config_1.getAppLevelConfigByName)(selectedAppName || selectedApp.configKey);
49
- let cloneDirectory = bootstrapCommandFlags.directory;
53
+ let cloneDirectory = bootstrapCommandFlags.directory || bootstrapCommandFlags['project-dir'];
50
54
  if (!cloneDirectory) {
51
55
  cloneDirectory = await (0, interactive_1.inquireCloneDirectory)();
52
56
  }
53
- // Check the access token
54
- let accessToken = bootstrapCommandFlags.accessToken;
55
- if (appConfig.private && !accessToken) {
56
- accessToken = await (0, interactive_1.inquireGithubAccessToken)();
57
- }
57
+ cloneDirectory = (0, path_1.resolve)(cloneDirectory);
58
+ const livePreviewEnabled = await (0, interactive_1.inquireLivePreviewSupport)();
59
+ const seedParams = {};
60
+ const stackAPIKey = bootstrapCommandFlags['stack-api-key'];
61
+ const org = bootstrapCommandFlags['org'];
62
+ const stackName = bootstrapCommandFlags['stack-name'];
63
+ if (stackAPIKey)
64
+ seedParams.stackAPIKey = stackAPIKey;
65
+ if (org)
66
+ seedParams.org = org;
67
+ if (stackName)
68
+ seedParams.stackName = stackName;
69
+ if (yes)
70
+ seedParams.yes = yes;
58
71
  // initiate bootstrsourceap
59
72
  const options = {
60
73
  appConfig,
74
+ seedParams,
61
75
  cloneDirectory,
62
76
  managementAPIClient: this.managementAPIClient,
63
77
  region: this.region,
64
- accessToken,
65
78
  appType,
79
+ livePreviewEnabled,
66
80
  };
67
81
  const bootstrap = new bootstrap_1.default(options);
68
82
  await bootstrap.run();
@@ -76,27 +90,68 @@ exports.default = BootstrapCommand;
76
90
  BootstrapCommand.description = 'Bootstrap contentstack apps';
77
91
  BootstrapCommand.examples = [
78
92
  '$ csdx cm:bootstrap',
79
- '$ csdx cm:bootstrap -d <path/to/setup/the/app>',
80
- '$ csdx cm:bootstrap -t <github access token>',
93
+ '$ csdx cm:bootstrap --project-dir <path/to/setup/the/app>',
94
+ '$ csdx cm:bootstrap --app-name "reactjs-starter" --project-dir <path/to/setup/the/app>',
95
+ '$ csdx cm:bootstrap --app-name "reactjs-starter" --project-dir <path/to/setup/the/app> --stack-api-key "stack-api-key"',
96
+ '$ csdx cm:bootstrap --app-name "reactjs-starter" --project-dir <path/to/setup/the/app> --org "your-org-uid" --stack-name "stack-name"',
81
97
  ];
82
98
  BootstrapCommand.flags = {
99
+ 'app-name': cli_command_1.flags.string({
100
+ description: 'App name, reactjs-starter, nextjs-starter, gatsby-starter, angular-starter, nuxt-starter, vue-starter, stencil-starter',
101
+ multiple: false,
102
+ required: false,
103
+ }),
104
+ 'project-dir': cli_command_1.flags.string({
105
+ 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',
106
+ multiple: false,
107
+ required: false,
108
+ }),
109
+ 'app-type': cli_command_1.flags.string({
110
+ description: 'Sample or Starter app',
111
+ multiple: false,
112
+ required: false,
113
+ hidden: true,
114
+ }),
115
+ 'stack-api-key': cli_command_1.flags.string({
116
+ char: 'k',
117
+ description: 'Provide stack API key to seed content',
118
+ multiple: false,
119
+ required: false,
120
+ exclusive: ['org', 'stack-name'],
121
+ }),
122
+ org: cli_command_1.flags.string({
123
+ description: 'Provide organization UID to create a new stack',
124
+ multiple: false,
125
+ required: false,
126
+ exclusive: ['stack-api-key'],
127
+ }),
128
+ 'stack-name': cli_command_1.flags.string({
129
+ char: 'n',
130
+ description: 'Name of a new stack that will be created.',
131
+ multiple: false,
132
+ required: false,
133
+ exclusive: ['stack-api-key'],
134
+ }),
135
+ yes: cli_command_1.flags.string({
136
+ char: 'y',
137
+ required: false,
138
+ }),
139
+ // To be deprecated
83
140
  appName: cli_command_1.flags.string({
84
141
  char: 'a',
85
142
  description: 'App name, reactjs-starter, nextjs-starter, gatsby-starter, angular-starter, nuxt-starter',
86
143
  multiple: false,
87
144
  required: false,
145
+ hidden: true,
146
+ parse: (0, cli_utilities_1.printFlagDeprecation)(['-a', '--appName'], ['--app-name']),
88
147
  }),
89
148
  directory: cli_command_1.flags.string({
90
149
  char: 'd',
91
- 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',
92
- multiple: false,
93
- required: false,
94
- }),
95
- accessToken: cli_command_1.flags.string({
96
- char: 't',
97
- description: 'Access token for private github repo',
150
+ description: 'Directory to set up the project. If directory name has a space then provide the path as a string or escape the space using backslash eg: "../../test space" or ../../test\\ space',
98
151
  multiple: false,
99
152
  required: false,
153
+ hidden: true,
154
+ parse: (0, cli_utilities_1.printFlagDeprecation)(['-d', '--directory'], ['--project-dir']),
100
155
  }),
101
156
  appType: cli_command_1.flags.string({
102
157
  char: 's',
@@ -104,5 +159,6 @@ BootstrapCommand.flags = {
104
159
  multiple: false,
105
160
  required: false,
106
161
  hidden: true,
162
+ parse: (0, cli_utilities_1.printFlagDeprecation)(['-s', '--appType'], ['--app-type']),
107
163
  }),
108
164
  };
package/lib/config.js CHANGED
@@ -15,6 +15,8 @@ const config = {
15
15
  { displayName: 'Gatsby', configKey: 'gatsby-starter' },
16
16
  { displayName: 'Angular', configKey: 'angular-starter' },
17
17
  { displayName: 'Nuxt JS', configKey: 'nuxt-starter' },
18
+ { displayName: 'Vue JS', configKey: 'vue-starter' },
19
+ { displayName: 'Stencil', configKey: 'stencil-starter' },
18
20
  ],
19
21
  appLevelConfig: {
20
22
  nextjs: {
@@ -51,12 +53,20 @@ const config = {
51
53
  },
52
54
  'gatsby-starter': {
53
55
  source: 'contentstack/contentstack-gatsby-starter-app',
54
- stack: 'contentstack/stack-starter-app'
56
+ stack: 'contentstack/stack-starter-app',
55
57
  },
56
58
  'angular-starter': {
57
59
  source: 'contentstack/contentstack-angular-starter',
58
60
  stack: 'contentstack/stack-starter-app',
59
61
  },
62
+ 'vue-starter': {
63
+ source: 'contentstack/contentstack-vuejs-starter-app',
64
+ stack: 'contentstack/stack-starter-app',
65
+ },
66
+ 'stencil-starter': {
67
+ source: 'contentstack/contentstack-stencil-starter-app',
68
+ stack: 'contentstack/stack-starter-app',
69
+ },
60
70
  },
61
71
  };
62
72
  exports.default = config;
@@ -1 +1 @@
1
- {"version":"1.0.8","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":[]}}}
1
+ {"version":"1.1.1","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 --project-dir <path/to/setup/the/app>","$ csdx cm:bootstrap --app-name \"reactjs-starter\" --project-dir <path/to/setup/the/app>","$ csdx cm:bootstrap --app-name \"reactjs-starter\" --project-dir <path/to/setup/the/app> --stack-api-key \"stack-api-key\"","$ csdx cm:bootstrap --app-name \"reactjs-starter\" --project-dir <path/to/setup/the/app> --org \"your-org-uid\" --stack-name \"stack-name\""],"flags":{"app-name":{"name":"app-name","type":"option","description":"App name, reactjs-starter, nextjs-starter, gatsby-starter, angular-starter, nuxt-starter, vue-starter, stencil-starter","required":false},"project-dir":{"name":"project-dir","type":"option","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},"app-type":{"name":"app-type","type":"option","description":"Sample or Starter app","hidden":true,"required":false},"stack-api-key":{"name":"stack-api-key","type":"option","char":"k","description":"Provide stack API key to seed content","required":false},"org":{"name":"org","type":"option","description":"Provide organization UID to create a new stack","required":false},"stack-name":{"name":"stack-name","type":"option","char":"n","description":"Name of a new stack that will be created.","required":false},"yes":{"name":"yes","type":"option","char":"y","required":false},"appName":{"name":"appName","type":"option","char":"a","description":"App name, reactjs-starter, nextjs-starter, gatsby-starter, angular-starter, nuxt-starter","hidden":true,"required":false},"directory":{"name":"directory","type":"option","char":"d","description":"Directory to set up the project. If directory name has a space then provide the path as a string or escape the space using backslash eg: \"../../test space\" or ../../test\\ space","hidden":true,"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.8",
4
+ "version": "1.1.1",
5
5
  "author": "Contentstack",
6
6
  "bugs": "https://github.com/contentstack/cli/issues",
7
7
  "scripts": {
@@ -17,27 +17,26 @@
17
17
  "test:report": "nyc --reporter=lcov mocha \"test/**/*.test.js\""
18
18
  },
19
19
  "dependencies": {
20
- "@contentstack/cli-cm-seed": "^1.0.12",
21
- "@contentstack/cli-command": "^0.1.1-beta.6",
20
+ "@contentstack/cli-cm-seed": "^1.1.1",
21
+ "@contentstack/cli-command": "^1.0.1",
22
+ "@contentstack/cli-utilities": "^1.0.2",
22
23
  "@contentstack/management": "^1.3.0",
23
- "@oclif/command": "^1.8.0",
24
- "@oclif/config": "^1.17.0",
25
- "axios": "^0.21.1",
26
- "cli-ux": "^5.5.0",
24
+ "@oclif/command": "^1.8.16",
25
+ "@oclif/config": "^1.18.3",
27
26
  "inquirer": "^8.0.0",
28
27
  "mkdirp": "^1.0.4",
29
28
  "tar": "^6.0.5"
30
29
  },
31
30
  "devDependencies": {
32
31
  "@oclif/dev-cli": "^1.22.2",
33
- "@oclif/plugin-help": "^3.2.0",
32
+ "@oclif/plugin-help": "^5.1.12",
34
33
  "@oclif/test": "^1.2.8",
35
34
  "@types/inquirer": "^7.3.1",
36
35
  "@types/mkdirp": "^1.0.1",
37
36
  "@types/node": "^14.14.32",
38
37
  "@types/tar": "^4.0.3",
39
38
  "chai": "^4.3.4",
40
- "eslint": "^5.16.0",
39
+ "eslint": "^8.18.0",
41
40
  "eslint-config-oclif": "^3.1.0",
42
41
  "eslint-config-oclif-typescript": "^0.1.0",
43
42
  "globby": "^10.0.2",