@contentstack/apps-cli 1.2.1 → 1.3.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/README.md CHANGED
@@ -20,7 +20,7 @@ $ npm install -g @contentstack/apps-cli
20
20
  $ csdx COMMAND
21
21
  running command...
22
22
  $ csdx (--version|-v)
23
- @contentstack/apps-cli/1.2.1 darwin-arm64 node-v18.12.1
23
+ @contentstack/apps-cli/1.3.0 darwin-arm64 node-v18.16.0
24
24
  $ csdx --help [COMMAND]
25
25
  USAGE
26
26
  $ csdx COMMAND
@@ -67,7 +67,7 @@ EXAMPLES
67
67
  $ csdx app:reinstall
68
68
  ```
69
69
 
70
- _See code: [src/commands/app/index.ts](https://github.com/contentstack/apps-cli/blob/v1.2.1/src/commands/app/index.ts)_
70
+ _See code: [src/commands/app/index.ts](https://github.com/contentstack/apps-cli/blob/v1.3.0/src/commands/app/index.ts)_
71
71
 
72
72
  ## `csdx app:create`
73
73
 
@@ -75,14 +75,16 @@ Create a new app in Developer Hub and optionally clone a boilerplate locally.
75
75
 
76
76
  ```
77
77
  USAGE
78
- $ csdx app:create [-n <value>] [--app-type stack|organization] [-c <value>] [-d <value>]
78
+ $ csdx app:create [-n <value>] [--app-type stack|organization] [-c <value>] [-d <value>] [--boilerplate
79
+ <value>]
79
80
 
80
81
  FLAGS
81
82
  -c, --config=<value> Path of the external config
82
83
  -d, --data-dir=<value> Current working directory.
83
- -n, --name=<value> [default: app-boilerplate] Name of the app to be created
84
+ -n, --name=<value> Name of the app to be created
84
85
  --app-type=<option> [default: stack] Type of app
85
86
  <options: stack|organization>
87
+ --boilerplate=<value> Provide a boilerplate. <options: App Boilerplate|DAM App Boilerplate|Ecommerce App Boilerplate>
86
88
 
87
89
  DESCRIPTION
88
90
  Create a new app in Developer Hub and optionally clone a boilerplate locally.
@@ -95,9 +97,15 @@ EXAMPLES
95
97
  $ csdx app:create --name App-2 --app-type stack -d ./boilerplate
96
98
 
97
99
  $ csdx app:create --name App-3 --app-type organization --org <UID> -d ./boilerplate -c ./external-config.json
100
+
101
+ $ csdx app:create --name App-4 --app-type organization --org <UID> --boilerplate <App Boilerplate>
102
+
103
+ $ csdx app:create --name App-4 --app-type organization --org <UID> --boilerplate <DAM App Boilerplate>
104
+
105
+ $ csdx app:create --name App-4 --app-type organization --org <UID> --boilerplate <Ecommerce App Boilerplate>
98
106
  ```
99
107
 
100
- _See code: [src/commands/app/create.ts](https://github.com/contentstack/apps-cli/blob/v1.2.1/src/commands/app/create.ts)_
108
+ _See code: [src/commands/app/create.ts](https://github.com/contentstack/apps-cli/blob/v1.3.0/src/commands/app/create.ts)_
101
109
 
102
110
  ## `csdx app:delete`
103
111
 
@@ -121,7 +129,7 @@ EXAMPLES
121
129
  $ csdx app:delete --app-uid <value> --org <value> -d ./boilerplate
122
130
  ```
123
131
 
124
- _See code: [src/commands/app/delete.ts](https://github.com/contentstack/apps-cli/blob/v1.2.1/src/commands/app/delete.ts)_
132
+ _See code: [src/commands/app/delete.ts](https://github.com/contentstack/apps-cli/blob/v1.3.0/src/commands/app/delete.ts)_
125
133
 
126
134
  ## `csdx app:deploy`
127
135
 
@@ -158,7 +166,7 @@ EXAMPLES
158
166
  $ csdx app:deploy --org <UID> --app-uid <APP-UID-1> --hosting-type <Hosting with Launch> --launch-project <new> --config <config-path>
159
167
  ```
160
168
 
161
- _See code: [src/commands/app/deploy.ts](https://github.com/contentstack/apps-cli/blob/v1.2.1/src/commands/app/deploy.ts)_
169
+ _See code: [src/commands/app/deploy.ts](https://github.com/contentstack/apps-cli/blob/v1.3.0/src/commands/app/deploy.ts)_
162
170
 
163
171
  ## `csdx app:get`
164
172
 
@@ -187,7 +195,7 @@ EXAMPLES
187
195
  $ csdx app:get --org <value> --app-uid <value> --app-type organization
188
196
  ```
189
197
 
190
- _See code: [src/commands/app/get.ts](https://github.com/contentstack/apps-cli/blob/v1.2.1/src/commands/app/get.ts)_
198
+ _See code: [src/commands/app/get.ts](https://github.com/contentstack/apps-cli/blob/v1.3.0/src/commands/app/get.ts)_
191
199
 
192
200
  ## `csdx app:install`
193
201
 
@@ -212,7 +220,7 @@ EXAMPLES
212
220
  $ csdx app:install --org <UID> --app-uid <APP-UID-1> --stack-api-key <STACK-API-KEY-1>
213
221
  ```
214
222
 
215
- _See code: [src/commands/app/install.ts](https://github.com/contentstack/apps-cli/blob/v1.2.1/src/commands/app/install.ts)_
223
+ _See code: [src/commands/app/install.ts](https://github.com/contentstack/apps-cli/blob/v1.3.0/src/commands/app/install.ts)_
216
224
 
217
225
  ## `csdx app:reinstall`
218
226
 
@@ -237,7 +245,7 @@ EXAMPLES
237
245
  $ csdx app:reinstall --org <UID> --app-uid <APP-UID-1> --stack-api-key <STACK-API-KEY-1>
238
246
  ```
239
247
 
240
- _See code: [src/commands/app/reinstall.ts](https://github.com/contentstack/apps-cli/blob/v1.2.1/src/commands/app/reinstall.ts)_
248
+ _See code: [src/commands/app/reinstall.ts](https://github.com/contentstack/apps-cli/blob/v1.3.0/src/commands/app/reinstall.ts)_
241
249
 
242
250
  ## `csdx app:uninstall`
243
251
 
@@ -263,7 +271,7 @@ EXAMPLES
263
271
  $ csdx app:uninstall --org <UID> --app-uid <APP-UID-1> --installation-uid <INSTALLATION-UID-1>
264
272
  ```
265
273
 
266
- _See code: [src/commands/app/uninstall.ts](https://github.com/contentstack/apps-cli/blob/v1.2.1/src/commands/app/uninstall.ts)_
274
+ _See code: [src/commands/app/uninstall.ts](https://github.com/contentstack/apps-cli/blob/v1.3.0/src/commands/app/uninstall.ts)_
267
275
 
268
276
  ## `csdx app:update`
269
277
 
@@ -285,5 +293,5 @@ EXAMPLES
285
293
  $ csdx app:update --app-manifest ./boilerplate/manifest.json
286
294
  ```
287
295
 
288
- _See code: [src/commands/app/update.ts](https://github.com/contentstack/apps-cli/blob/v1.2.1/src/commands/app/update.ts)_
296
+ _See code: [src/commands/app/update.ts](https://github.com/contentstack/apps-cli/blob/v1.3.0/src/commands/app/update.ts)_
289
297
  <!-- commandsstop -->
@@ -27,6 +27,7 @@ class Create extends base_command_1.BaseCommand {
27
27
  async run() {
28
28
  this.sharedConfig.org = this.flags.org;
29
29
  this.sharedConfig.appName = this.flags.name;
30
+ this.sharedConfig.boilerplateName = this.flags.boilerplate;
30
31
  await this.flagsPromptQueue();
31
32
  this.tempAppData.name = this.sharedConfig.appName;
32
33
  this.tempAppData.target_type = this.flags["app-type"];
@@ -81,8 +82,27 @@ class Create extends base_command_1.BaseCommand {
81
82
  */
82
83
  async flagsPromptQueue() {
83
84
  var _a;
84
- if ((0, isEmpty_1.default)(this.sharedConfig.appName)) {
85
- this.sharedConfig.appName = await (0, util_1.getAppName)(this.sharedConfig.defaultAppName);
85
+ if (this.sharedConfig.appName) {
86
+ (0, util_1.validateAppName)(this.sharedConfig.appName);
87
+ }
88
+ let boilerplate = null;
89
+ if ((0, isEmpty_1.default)(this.sharedConfig.boilerplateName)) {
90
+ boilerplate = await (0, util_1.selectedBoilerplate)();
91
+ }
92
+ else {
93
+ boilerplate = (await (0, util_1.validateBoilerplate)(this.sharedConfig.boilerplateName));
94
+ }
95
+ if (boilerplate) {
96
+ let boilerplateName = this.sharedConfig.appName || boilerplate.name;
97
+ if ((0, isEmpty_1.default)(this.sharedConfig.appName)) {
98
+ boilerplateName = boilerplateName
99
+ .toLowerCase()
100
+ .replace(/ /g, "-")
101
+ .substring(0, 20);
102
+ }
103
+ this.sharedConfig.boilerplateName = boilerplateName;
104
+ this.sharedConfig.appBoilerplateGithubUrl = boilerplate.link;
105
+ this.sharedConfig.appName = boilerplateName;
86
106
  }
87
107
  //Auto select org in case of oauth
88
108
  this.sharedConfig.org =
@@ -126,7 +146,10 @@ class Create extends base_command_1.BaseCommand {
126
146
  const zip = new adm_zip_1.default(filepath);
127
147
  const dataDir = (_a = this.flags["data-dir"]) !== null && _a !== void 0 ? _a : process.cwd();
128
148
  let targetPath = (0, path_1.resolve)(dataDir, this.sharedConfig.appName);
129
- const sourcePath = (0, path_1.resolve)(dataDir, this.sharedConfig.boilerplateName);
149
+ // Get the directory inside the zip file
150
+ const zipEntries = zip.getEntries();
151
+ const firstEntry = zipEntries[0];
152
+ const sourcePath = (0, path_1.resolve)((0, util_1.sanitizePath)(dataDir), (0, util_1.sanitizePath)(firstEntry.entryName.split("/")[0]));
130
153
  if (this.flags["data-dir"] && !(0, fs_1.existsSync)(this.flags["data-dir"])) {
131
154
  (0, fs_1.mkdirSync)(this.flags["data-dir"], { recursive: true });
132
155
  }
@@ -156,7 +179,7 @@ class Create extends base_command_1.BaseCommand {
156
179
  */
157
180
  manageManifestToggeling() {
158
181
  // NOTE Use boilerplate manifest if exist
159
- const manifestPath = (0, path_1.resolve)(this.sharedConfig.folderPath || "", "manifest.json");
182
+ const manifestPath = (0, path_1.resolve)(this.sharedConfig.folderPath, "manifest.json");
160
183
  if ((0, fs_1.existsSync)(manifestPath)) {
161
184
  this.sharedConfig.manifestPath = manifestPath;
162
185
  }
@@ -298,11 +321,13 @@ Create.examples = [
298
321
  "$ <%= config.bin %> <%= command.id %> --name App-1 --app-type stack",
299
322
  "$ <%= config.bin %> <%= command.id %> --name App-2 --app-type stack -d ./boilerplate",
300
323
  "$ <%= config.bin %> <%= command.id %> --name App-3 --app-type organization --org <UID> -d ./boilerplate -c ./external-config.json",
324
+ "$ <%= config.bin %> <%= command.id %> --name App-4 --app-type organization --org <UID> --boilerplate <App Boilerplate>",
325
+ "$ <%= config.bin %> <%= command.id %> --name App-4 --app-type organization --org <UID> --boilerplate <DAM App Boilerplate>",
326
+ "$ <%= config.bin %> <%= command.id %> --name App-4 --app-type organization --org <UID> --boilerplate <Ecommerce App Boilerplate>",
301
327
  ];
302
328
  Create.flags = {
303
329
  name: cli_utilities_1.flags.string({
304
330
  char: "n",
305
- default: "app-boilerplate",
306
331
  description: messages_1.appCreate.NAME_DESCRIPTION,
307
332
  }),
308
333
  "app-type": cli_utilities_1.flags.string({
@@ -318,5 +343,8 @@ Create.flags = {
318
343
  char: "d",
319
344
  description: messages_1.commonMsg.CURRENT_WORKING_DIR,
320
345
  }),
346
+ boilerplate: cli_utilities_1.flags.string({
347
+ description: messages_1.appCreate.BOILERPLATE_TEMPLATES,
348
+ }),
321
349
  };
322
350
  exports.default = Create;
@@ -1,9 +1,9 @@
1
1
  declare const config: {
2
2
  defaultAppName: string;
3
3
  manifestPath: string;
4
- boilerplateName: string;
5
4
  developerHubBaseUrl: string;
6
5
  appBoilerplateGithubUrl: string;
7
6
  defaultAppFileName: string;
7
+ boilerplatesUrl: string;
8
8
  };
9
9
  export default config;
@@ -4,9 +4,9 @@ const path_1 = require("path");
4
4
  const config = {
5
5
  defaultAppName: "app-boilerplate",
6
6
  manifestPath: (0, path_1.resolve)(__dirname, "manifest.json"),
7
- boilerplateName: "marketplace-app-boilerplate-main",
8
7
  developerHubBaseUrl: "",
9
8
  appBoilerplateGithubUrl: "https://codeload.github.com/contentstack/marketplace-app-boilerplate/zip/refs/heads/main",
10
9
  defaultAppFileName: "manifest",
10
+ boilerplatesUrl: 'https://marketplace-artifacts.contentstack.com/cli/starter-template.json'
11
11
  };
12
12
  exports.default = config;
@@ -44,6 +44,8 @@ declare const appCreate: {
44
44
  CONFIRM_CLONE_BOILERPLATE: string;
45
45
  REGISTER_THE_APP_ON_DEVELOPER_HUB: string;
46
46
  START_APP_COMMAND: string;
47
+ BOILERPLATE_TEMPLATES: string;
48
+ SELECT_BOILERPLATE: string;
47
49
  };
48
50
  declare const getAppMsg: {
49
51
  CHOOSE_APP: string;
@@ -49,6 +49,8 @@ const appCreate = {
49
49
  CONFIRM_CLONE_BOILERPLATE: "Would you like to fetch the app template from GitHub?",
50
50
  REGISTER_THE_APP_ON_DEVELOPER_HUB: "Registering the app with the name {appName} on the Developer Hub...",
51
51
  START_APP_COMMAND: "Start the app using the following command: {command}",
52
+ BOILERPLATE_TEMPLATES: "Provide a boilerplate. <options: App Boilerplate|DAM App Boilerplate|Ecommerce App Boilerplate>",
53
+ SELECT_BOILERPLATE: "Select one from the following boilerplates:"
52
54
  };
53
55
  exports.appCreate = appCreate;
54
56
  const getAppMsg = {
@@ -122,3 +122,11 @@ export interface LaunchProjectRes {
122
122
  environmentUid: any;
123
123
  developerHubAppUid: any;
124
124
  }
125
+ export interface BoilerplateAppType {
126
+ name: string;
127
+ description?: string;
128
+ link: string;
129
+ tags?: string[];
130
+ created_at?: string;
131
+ updated_at?: string;
132
+ }
@@ -35,4 +35,6 @@ declare function setupConfig(configPath: string): Record<string, string>;
35
35
  declare function disconnectApp(flags: FlagInput, orgUid: string, developerHubBaseUrl: string): Promise<any>;
36
36
  declare function formatUrl(url: string): string;
37
37
  declare const handleProjectNameConflict: (projectName: string, projects: any[], retry?: number) => Promise<string>;
38
- export { getOrganizations, getOrgAppUiLocation, fetchApps, fetchApp, fetchAppInstallations, deleteApp, installApp, getStacks, fetchStack, uninstallApp, fetchInstalledApps, reinstallApp, sanitizePath, updateApp, getProjects, getManifestDetails, setupConfig, disconnectApp, formatUrl, handleProjectNameConflict, };
38
+ declare function fetchBoilerplateDetails(): Promise<Record<string, any>[]>;
39
+ declare function validateBoilerplate(boilerplateName: string): Promise<Record<string, any>>;
40
+ export { getOrganizations, getOrgAppUiLocation, fetchApps, fetchApp, fetchAppInstallations, deleteApp, installApp, getStacks, fetchStack, uninstallApp, fetchInstalledApps, reinstallApp, sanitizePath, updateApp, getProjects, getManifestDetails, setupConfig, disconnectApp, formatUrl, handleProjectNameConflict, fetchBoilerplateDetails, validateBoilerplate, };
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.handleProjectNameConflict = exports.formatUrl = exports.disconnectApp = exports.setupConfig = exports.getManifestDetails = exports.getProjects = exports.updateApp = exports.sanitizePath = exports.reinstallApp = exports.fetchInstalledApps = exports.uninstallApp = exports.fetchStack = exports.getStacks = exports.installApp = exports.deleteApp = exports.fetchAppInstallations = exports.fetchApp = exports.fetchApps = exports.getOrgAppUiLocation = exports.getOrganizations = void 0;
3
+ exports.validateBoilerplate = exports.fetchBoilerplateDetails = exports.handleProjectNameConflict = exports.formatUrl = exports.disconnectApp = exports.setupConfig = exports.getManifestDetails = exports.getProjects = exports.updateApp = exports.sanitizePath = exports.reinstallApp = exports.fetchInstalledApps = exports.uninstallApp = exports.fetchStack = exports.getStacks = exports.installApp = exports.deleteApp = exports.fetchAppInstallations = exports.fetchApp = exports.fetchApps = exports.getOrgAppUiLocation = exports.getOrganizations = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const map_1 = tslib_1.__importDefault(require("lodash/map"));
6
6
  const cli_utilities_1 = require("@contentstack/cli-utilities");
@@ -9,6 +9,8 @@ const api_request_handler_1 = require("./api-request-handler");
9
9
  const types_1 = require("../types");
10
10
  const inquirer_1 = require("./inquirer");
11
11
  const messages_1 = require("../messages");
12
+ const config_1 = tslib_1.__importDefault(require("../config"));
13
+ const find_1 = tslib_1.__importDefault(require("lodash/find"));
12
14
  async function getOrganizations(options, skip = 0, organizations = []) {
13
15
  const { log, managementSdk } = options;
14
16
  const response = await managementSdk
@@ -296,3 +298,23 @@ const handleProjectNameConflict = async (projectName, projects, retry = 1) => {
296
298
  return projectName;
297
299
  };
298
300
  exports.handleProjectNameConflict = handleProjectNameConflict;
301
+ async function fetchBoilerplateDetails() {
302
+ var _a, _b;
303
+ try {
304
+ const content = await new cli_utilities_1.HttpClient().get(config_1.default.boilerplatesUrl);
305
+ return (_b = (_a = content === null || content === void 0 ? void 0 : content.data) === null || _a === void 0 ? void 0 : _a.templates) !== null && _b !== void 0 ? _b : [];
306
+ }
307
+ catch (error) {
308
+ throw error;
309
+ }
310
+ }
311
+ exports.fetchBoilerplateDetails = fetchBoilerplateDetails;
312
+ async function validateBoilerplate(boilerplateName) {
313
+ const boilerplates = await fetchBoilerplateDetails();
314
+ const boilerplate = (0, find_1.default)(boilerplates, (boilerplate) => boilerplate.name === boilerplateName);
315
+ if (!boilerplate) {
316
+ throw new Error("Invalid boilerplate! Please select a boilerplate from the following options: App Boilerplate, DAM App Boilerplate or Ecommerce App Boilerplate");
317
+ }
318
+ return boilerplate;
319
+ }
320
+ exports.validateBoilerplate = validateBoilerplate;
@@ -39,4 +39,6 @@ declare function selectProject(projects: LaunchProjectRes[]): Promise<LaunchProj
39
39
  declare const askProjectType: () => Promise<string>;
40
40
  declare function askConfirmation(): Promise<boolean>;
41
41
  declare const askProjectName: (projectName: string) => Promise<string>;
42
- export { getOrg, getAppName, getDirName, getDeveloperHubUrl, getApp, getInstalledApps, getStack, getInstallation, getHostingType, getAppUrl, askProjectType, askConfirmation, selectProject, askProjectName };
42
+ declare const selectedBoilerplate: () => Promise<any>;
43
+ declare const validateAppName: (name: string) => void;
44
+ export { getOrg, getAppName, getDirName, getDeveloperHubUrl, getApp, getInstalledApps, getStack, getInstallation, getHostingType, getAppUrl, askProjectType, askConfirmation, selectProject, askProjectName, selectedBoilerplate, validateAppName, };
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.askProjectName = exports.selectProject = exports.askConfirmation = exports.askProjectType = exports.getAppUrl = exports.getHostingType = exports.getInstallation = exports.getStack = exports.getInstalledApps = exports.getApp = exports.getDeveloperHubUrl = exports.getDirName = exports.getAppName = exports.getOrg = void 0;
3
+ exports.validateAppName = exports.selectedBoilerplate = exports.askProjectName = exports.selectProject = exports.askConfirmation = exports.askProjectType = exports.getAppUrl = exports.getHostingType = exports.getInstallation = exports.getStack = exports.getInstalledApps = exports.getApp = exports.getDeveloperHubUrl = exports.getDirName = exports.getAppName = exports.getOrg = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const find_1 = tslib_1.__importDefault(require("lodash/find"));
6
6
  const isEmpty_1 = tslib_1.__importDefault(require("lodash/isEmpty"));
@@ -297,3 +297,23 @@ function inquireRequireValidation(input) {
297
297
  }
298
298
  return true;
299
299
  }
300
+ const selectedBoilerplate = async () => {
301
+ const boilerplates = await (0, common_utils_1.fetchBoilerplateDetails)();
302
+ return await cli_utilities_1.cliux
303
+ .inquire({
304
+ type: "search-list",
305
+ name: "App",
306
+ choices: boilerplates.map((bp) => bp.name),
307
+ message: messages_1.appCreate.SELECT_BOILERPLATE,
308
+ })
309
+ .then((name) => {
310
+ return (0, find_1.default)(boilerplates, (boilerplate) => boilerplate.name === name);
311
+ });
312
+ };
313
+ exports.selectedBoilerplate = selectedBoilerplate;
314
+ const validateAppName = (name) => {
315
+ if (name.length < 3 || name.length > 20) {
316
+ throw new Error((0, messages_1.$t)(messages_1.errors.INVALID_NAME, { min: "3", max: "20" }));
317
+ }
318
+ };
319
+ exports.validateAppName = validateAppName;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contentstack/apps-cli",
3
- "version": "1.2.1",
3
+ "version": "1.3.0",
4
4
  "description": "App ClI",
5
5
  "author": "Contentstack CLI",
6
6
  "homepage": "https://github.com/contentstack/contentstack-apps-cli",