@squiz/dxp-cli-next 5.3.0 → 5.4.0-develop.2

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/lib/cmp/index.js CHANGED
@@ -6,9 +6,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const commander_1 = require("commander");
7
7
  const deploy_1 = __importDefault(require("./deploy"));
8
8
  const dev_mode_1 = __importDefault(require("./dev-mode"));
9
+ const init_1 = __importDefault(require("./init"));
9
10
  const cmpCommand = new commander_1.Command('cmp');
10
11
  cmpCommand
11
12
  .description('Component Service Commands')
12
13
  .addCommand(deploy_1.default)
13
- .addCommand(dev_mode_1.default);
14
+ .addCommand(dev_mode_1.default)
15
+ .addCommand(init_1.default);
14
16
  exports.default = cmpCommand;
@@ -0,0 +1,3 @@
1
+ import { Command } from 'commander';
2
+ declare const initCommand: Command;
3
+ export default initCommand;
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ const commander_1 = require("commander");
16
+ const cli_color_1 = __importDefault(require("cli-color"));
17
+ const component_cli_lib_1 = require("@squiz/component-cli-lib");
18
+ const child_process_1 = require("child_process");
19
+ var componentTypes;
20
+ (function (componentTypes) {
21
+ componentTypes["basic"] = "basic";
22
+ componentTypes["advanced"] = "advanced";
23
+ })(componentTypes || (componentTypes = {}));
24
+ const initCommand = new commander_1.Command()
25
+ .name('init')
26
+ .argument('<path>', 'Destination directory for component')
27
+ .description('Create a new component from a template')
28
+ .addOption(new commander_1.Option('-t, --type <string>', 'Type of component to create.')
29
+ .choices(['basic', 'advanced'])
30
+ .default('basic'))
31
+ .addOption(new commander_1.Option('-i, --install', 'Install dependencies after creating component').default(false))
32
+ .action((destination, { type: componentType, install }) => __awaiter(void 0, void 0, void 0, function* () {
33
+ if (!componentType || componentTypeIsValid(componentType) === false) {
34
+ initCommand.error(cli_color_1.default.red('Invalid component type. Must be one of: basic, advanced'));
35
+ return;
36
+ }
37
+ if (install && componentType === 'basic') {
38
+ initCommand.error(cli_color_1.default.red('Component type "basic" does not come with a package.json file, install is not a valid option'));
39
+ return;
40
+ }
41
+ console.log(`Creating ${componentType} component in ${destination}...`);
42
+ try {
43
+ yield (0, component_cli_lib_1.componentInit)({ componentType, destination });
44
+ if (install) {
45
+ console.log('Installing dependencies');
46
+ (0, child_process_1.execSync)('npm i', {
47
+ cwd: destination,
48
+ stdio: 'inherit',
49
+ });
50
+ }
51
+ }
52
+ catch (error) {
53
+ if (!!process.env.DEBUG && error.stack) {
54
+ initCommand.error(error.stack);
55
+ }
56
+ if (error.message) {
57
+ initCommand.error(cli_color_1.default.red(error.message));
58
+ }
59
+ else {
60
+ initCommand.error(cli_color_1.default.red('An unknown error occurred'));
61
+ }
62
+ }
63
+ }));
64
+ function componentTypeIsValid(componentType) {
65
+ return componentType === 'basic' || componentType == 'advanced';
66
+ }
67
+ exports.default = initCommand;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@squiz/dxp-cli-next",
3
- "version": "5.3.0",
3
+ "version": "5.4.0-develop.2",
4
4
  "repository": {
5
5
  "url": "https://gitlab.squiz.net/developer-experience/dxp-cli-next"
6
6
  },
@@ -39,7 +39,7 @@
39
39
  "codecov"
40
40
  ],
41
41
  "dependencies": {
42
- "@squiz/component-cli-lib": "1.7.0",
42
+ "@squiz/component-cli-lib": "1.16.0",
43
43
  "axios": "1.1.3",
44
44
  "cli-color": "2.0.3",
45
45
  "commander": "9.4.0",