@sitecore-content-sdk/cli 1.3.0-canary.7 → 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.
Files changed (50) hide show
  1. package/LICENSE.txt +202 -202
  2. package/README.md +5 -5
  3. package/dist/cjs/bin/sitecore-tools.js +77 -77
  4. package/dist/cjs/cli.js +69 -69
  5. package/dist/cjs/scripts/index.js +40 -40
  6. package/dist/cjs/scripts/project/build.js +42 -42
  7. package/dist/cjs/scripts/project/component/add.js +241 -236
  8. package/dist/cjs/scripts/project/component/generate-map.js +70 -68
  9. package/dist/cjs/scripts/project/component/index.js +57 -57
  10. package/dist/cjs/scripts/project/component/scaffold.js +69 -66
  11. package/dist/cjs/scripts/project/index.js +56 -56
  12. package/dist/cjs/utils/load-config.js +42 -42
  13. package/dist/cjs/utils/process-env.js +70 -70
  14. package/dist/cjs/utils/watch-items.js +18 -18
  15. package/dist/esm/cli.js +63 -63
  16. package/dist/esm/scripts/index.js +4 -4
  17. package/dist/esm/scripts/project/build.js +35 -35
  18. package/dist/esm/scripts/project/component/add.js +198 -193
  19. package/dist/esm/scripts/project/component/generate-map.js +62 -60
  20. package/dist/esm/scripts/project/component/index.js +21 -21
  21. package/dist/esm/scripts/project/component/scaffold.js +61 -58
  22. package/dist/esm/scripts/project/index.js +20 -20
  23. package/dist/esm/utils/load-config.js +36 -36
  24. package/dist/esm/utils/process-env.js +31 -31
  25. package/dist/esm/utils/watch-items.js +12 -12
  26. package/package.json +79 -79
  27. package/types/bin/sitecore-tools.d.ts +3 -2
  28. package/types/bin/sitecore-tools.d.ts.map +1 -0
  29. package/types/cli.d.ts +14 -13
  30. package/types/cli.d.ts.map +1 -0
  31. package/types/scripts/index.d.ts +3 -2
  32. package/types/scripts/index.d.ts.map +1 -0
  33. package/types/scripts/project/build.d.ts +25 -24
  34. package/types/scripts/project/build.d.ts.map +1 -0
  35. package/types/scripts/project/component/add.d.ts +59 -58
  36. package/types/scripts/project/component/add.d.ts.map +1 -0
  37. package/types/scripts/project/component/generate-map.d.ts +33 -32
  38. package/types/scripts/project/component/generate-map.d.ts.map +1 -0
  39. package/types/scripts/project/component/index.d.ts +6 -5
  40. package/types/scripts/project/component/index.d.ts.map +1 -0
  41. package/types/scripts/project/component/scaffold.d.ts +45 -44
  42. package/types/scripts/project/component/scaffold.d.ts.map +1 -0
  43. package/types/scripts/project/index.d.ts +6 -5
  44. package/types/scripts/project/index.d.ts.map +1 -0
  45. package/types/utils/load-config.d.ts +9 -8
  46. package/types/utils/load-config.d.ts.map +1 -0
  47. package/types/utils/process-env.d.ts +9 -8
  48. package/types/utils/process-env.d.ts.map +1 -0
  49. package/types/utils/watch-items.d.ts +7 -6
  50. package/types/utils/watch-items.d.ts.map +1 -0
@@ -1,236 +1,241 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
36
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
37
- return new (P || (P = Promise))(function (resolve, reject) {
38
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
39
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
40
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
41
- step((generator = generator.apply(thisArg, _arguments || [])).next());
42
- });
43
- };
44
- var __importDefault = (this && this.__importDefault) || function (mod) {
45
- return (mod && mod.__esModule) ? mod : { "default": mod };
46
- };
47
- Object.defineProperty(exports, "__esModule", { value: true });
48
- exports.unitMocks = void 0;
49
- exports.args = args;
50
- exports.builder = builder;
51
- exports.handler = handler;
52
- const fs_1 = __importDefault(require("fs"));
53
- const path_1 = __importDefault(require("path"));
54
- const chalk_1 = __importDefault(require("chalk"));
55
- const child_process_1 = require("child_process");
56
- const tools = __importStar(require("@sitecore-content-sdk/core/tools"));
57
- const inquirer_1 = __importDefault(require("inquirer"));
58
- const generate_map_1 = require("./generate-map");
59
- const load_config_1 = __importDefault(require("../../../utils/load-config"));
60
- let { getComponentSpec, getComponentList, getComponentSpecUrl } = tools;
61
- const unitMocks = (toolsModule) => {
62
- getComponentSpec = toolsModule.getComponentSpec;
63
- getComponentList = toolsModule.getComponentList;
64
- getComponentSpecUrl = toolsModule.getComponentSpecUrl;
65
- };
66
- exports.unitMocks = unitMocks;
67
- /**
68
- * @param {Argv} yargs
69
- */
70
- function args(yargs) {
71
- /* istanbul ignore next */
72
- return yargs
73
- .positional('componentId', {
74
- requiresArg: true,
75
- positional: true,
76
- type: 'string',
77
- describe: `The unique identifier of the newly created component.`,
78
- })
79
- .option('token', {
80
- requiresArg: true,
81
- type: 'string',
82
- describe: 'The authentication token.',
83
- demandOption: true,
84
- })
85
- .option('target-path', {
86
- requiresArg: false,
87
- type: 'string',
88
- describe: 'The relative target path for the component.\n(Example: components/Promo.WithText.ts)',
89
- })
90
- .option('skip-component-map', {
91
- requiresArg: false,
92
- type: 'boolean',
93
- describe: 'If true, skips the component map generation.',
94
- default: false,
95
- })
96
- .option('overwrite', {
97
- requiresArg: false,
98
- type: 'boolean',
99
- describe: 'If true, overwrites the existing component.',
100
- default: false,
101
- })
102
- .option('config', {
103
- requiresArg: false,
104
- type: 'string',
105
- describe: 'Path to the `sitecore.cli.config` file. Supports both JavaScript (`.js`) and TypeScript (`.ts`) formats',
106
- });
107
- }
108
- /**
109
- * @param {Argv} yargs
110
- */
111
- function builder(yargs) {
112
- /* istanbul ignore next */
113
- return yargs.command('add <component-id>', 'Adds a component', args, handler);
114
- }
115
- /**
116
- * Validates the target path. If no target path is provided, returns true.
117
- * @param {string} [targetPath] - The target path to validate.
118
- * @returns {boolean | string} True if the target path is valid, the error message otherwise.
119
- */
120
- const validateTargetPath = (targetPath) => {
121
- if (!targetPath) {
122
- return true;
123
- }
124
- // Check for unsafe absolute path starting with "/"
125
- if (path_1.default.isAbsolute(targetPath)) {
126
- return 'Target path cannot be an absolute path starting with "/"';
127
- }
128
- // Check for path traversal attempts
129
- if (targetPath.includes('..')) {
130
- return 'Target path cannot contain ".." (path traversal)';
131
- }
132
- return true;
133
- };
134
- /**
135
- * Handler for the add command.
136
- * @param {AddArgs} argv - The arguments passed to the command.
137
- */
138
- function handler(argv) {
139
- return __awaiter(this, void 0, void 0, function* () {
140
- const { componentId, token, targetPath: targetPathArg, skipComponentMap, config, overwrite, } = argv;
141
- console.log(chalk_1.default.green('Adding component'));
142
- let targetPath = targetPathArg;
143
- const cliConfig = (0, load_config_1.default)(config);
144
- if (!cliConfig.config) {
145
- console.error('The `sitecore.cli.config` file is missing a `config`. Please add it to use this command.');
146
- return;
147
- }
148
- const { edgeUrl } = cliConfig.config.api.edge;
149
- let backupPath;
150
- let resolvedFilePath;
151
- try {
152
- if (validateTargetPath(targetPath) !== true) {
153
- console.error(chalk_1.default.red(validateTargetPath(targetPath)));
154
- return;
155
- }
156
- const spec = yield getComponentSpec({
157
- edgeUrl,
158
- componentId,
159
- targetPath,
160
- token,
161
- });
162
- const componentType = spec.meta['contentsdk-component-type'];
163
- const componentName = spec.meta['contentsdk-component-name'];
164
- const variantName = spec.meta['contentsdk-component-variant-name'];
165
- const title = spec.title;
166
- if (componentType !== 'variant') {
167
- console.error(chalk_1.default.red(`The component "${title}" is not a content-sdk variant. Please, select a content-sdk variant to use this command.`));
168
- return;
169
- }
170
- if (!targetPath) {
171
- const { paths, exclude } = cliConfig.componentMap;
172
- const components = getComponentList(paths, exclude, true);
173
- const registeredComponent = components.find((c) => c.componentName === componentName);
174
- if (registeredComponent) {
175
- targetPath = registeredComponent.filePath
176
- .replace(/\\/g, '/')
177
- .replace(/([^/]+)\.([^.]+)$/, `$1.${variantName}.$2`);
178
- }
179
- else {
180
- targetPath = yield inquirer_1.default
181
- .prompt({
182
- type: 'input',
183
- name: 'targetPath',
184
- required: true,
185
- message: `Enter the target path for the component.\n(Example: components/Promo.WithText.ts):`,
186
- validate: validateTargetPath,
187
- })
188
- .then((answer) => answer.targetPath);
189
- }
190
- }
191
- resolvedFilePath = path_1.default.resolve(process.cwd(), targetPath);
192
- const isFileAlreadyExists = fs_1.default.existsSync(resolvedFilePath);
193
- backupPath = `${resolvedFilePath}.backup`;
194
- if (isFileAlreadyExists) {
195
- if (!overwrite) {
196
- const shouldOverwrite = yield inquirer_1.default.prompt({
197
- type: 'confirm',
198
- name: 'overwrite',
199
- message: `File already exists: ${targetPath}. Overwrite?`,
200
- default: false,
201
- });
202
- if (!shouldOverwrite.overwrite) {
203
- return;
204
- }
205
- }
206
- fs_1.default.renameSync(resolvedFilePath, backupPath);
207
- console.log(chalk_1.default.yellow(`Overwriting existing file: ${targetPath}`));
208
- }
209
- const componentSpecUrl = getComponentSpecUrl({
210
- componentId,
211
- targetPath: targetPath,
212
- edgeUrl,
213
- token,
214
- });
215
- (0, child_process_1.execSync)(`npx shadcn@^3.4.2 add "${componentSpecUrl}"`, {
216
- stdio: 'inherit',
217
- cwd: process.cwd(),
218
- });
219
- if (isFileAlreadyExists) {
220
- fs_1.default.unlinkSync(backupPath);
221
- }
222
- if (!skipComponentMap) {
223
- (0, generate_map_1.handler)({ config });
224
- }
225
- console.log(chalk_1.default.green(`Component ${componentName} added successfully`));
226
- }
227
- catch (error) {
228
- if (backupPath && resolvedFilePath && fs_1.default.existsSync(backupPath)) {
229
- fs_1.default.renameSync(backupPath, resolvedFilePath);
230
- }
231
- const errorMessage = error instanceof Error ? error.message : String(error);
232
- console.error(chalk_1.default.red(`Failed to add component: ${errorMessage}`));
233
- return;
234
- }
235
- });
236
- }
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
36
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
37
+ return new (P || (P = Promise))(function (resolve, reject) {
38
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
39
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
40
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
41
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
42
+ });
43
+ };
44
+ var __importDefault = (this && this.__importDefault) || function (mod) {
45
+ return (mod && mod.__esModule) ? mod : { "default": mod };
46
+ };
47
+ Object.defineProperty(exports, "__esModule", { value: true });
48
+ exports.unitMocks = void 0;
49
+ exports.args = args;
50
+ exports.builder = builder;
51
+ exports.handler = handler;
52
+ const fs_1 = __importDefault(require("fs"));
53
+ const path_1 = __importDefault(require("path"));
54
+ const chalk_1 = __importDefault(require("chalk"));
55
+ const child_process_1 = require("child_process");
56
+ const tools = __importStar(require("@sitecore-content-sdk/core/tools"));
57
+ const inquirer_1 = __importDefault(require("inquirer"));
58
+ const generate_map_1 = require("./generate-map");
59
+ const load_config_1 = __importDefault(require("../../../utils/load-config"));
60
+ let { getComponentSpec, getComponentList, getComponentSpecUrl } = tools;
61
+ const unitMocks = (toolsModule) => {
62
+ getComponentSpec = toolsModule.getComponentSpec;
63
+ getComponentList = toolsModule.getComponentList;
64
+ getComponentSpecUrl = toolsModule.getComponentSpecUrl;
65
+ };
66
+ exports.unitMocks = unitMocks;
67
+ /**
68
+ * @param {Argv} yargs
69
+ */
70
+ function args(yargs) {
71
+ /* istanbul ignore next */
72
+ return yargs
73
+ .positional('componentId', {
74
+ requiresArg: true,
75
+ positional: true,
76
+ type: 'string',
77
+ describe: `The unique identifier of the newly created component.`,
78
+ })
79
+ .option('token', {
80
+ requiresArg: true,
81
+ type: 'string',
82
+ describe: 'The authentication token.',
83
+ demandOption: true,
84
+ alias: 't',
85
+ })
86
+ .option('target-path', {
87
+ requiresArg: false,
88
+ type: 'string',
89
+ describe: 'The relative target path for the component.\n(Example: components/Promo.WithText.ts)',
90
+ alias: 'p',
91
+ })
92
+ .option('skip-component-map', {
93
+ requiresArg: false,
94
+ type: 'boolean',
95
+ describe: 'If true, skips the component map generation.',
96
+ default: false,
97
+ alias: 's',
98
+ })
99
+ .option('overwrite', {
100
+ requiresArg: false,
101
+ type: 'boolean',
102
+ describe: 'If true, overwrites the existing component.',
103
+ default: false,
104
+ alias: 'o',
105
+ })
106
+ .option('config', {
107
+ requiresArg: false,
108
+ type: 'string',
109
+ describe: 'Path to the `sitecore.cli.config` file. Supports both JavaScript (`.js`) and TypeScript (`.ts`) formats',
110
+ alias: 'c',
111
+ });
112
+ }
113
+ /**
114
+ * @param {Argv} yargs
115
+ */
116
+ function builder(yargs) {
117
+ /* istanbul ignore next */
118
+ return yargs.command(['add <component-id>', 'a <component-id>'], 'Adds a component', args, handler);
119
+ }
120
+ /**
121
+ * Validates the target path. If no target path is provided, returns true.
122
+ * @param {string} [targetPath] - The target path to validate.
123
+ * @returns {boolean | string} True if the target path is valid, the error message otherwise.
124
+ */
125
+ const validateTargetPath = (targetPath) => {
126
+ if (!targetPath) {
127
+ return true;
128
+ }
129
+ // Check for unsafe absolute path starting with "/"
130
+ if (path_1.default.isAbsolute(targetPath)) {
131
+ return 'Target path cannot be an absolute path starting with "/"';
132
+ }
133
+ // Check for path traversal attempts
134
+ if (targetPath.includes('..')) {
135
+ return 'Target path cannot contain ".." (path traversal)';
136
+ }
137
+ return true;
138
+ };
139
+ /**
140
+ * Handler for the add command.
141
+ * @param {AddArgs} argv - The arguments passed to the command.
142
+ */
143
+ function handler(argv) {
144
+ return __awaiter(this, void 0, void 0, function* () {
145
+ const { componentId, token, targetPath: targetPathArg, skipComponentMap, config, overwrite, } = argv;
146
+ console.log(chalk_1.default.green('Adding component'));
147
+ let targetPath = targetPathArg;
148
+ const cliConfig = (0, load_config_1.default)(config);
149
+ if (!cliConfig.config) {
150
+ console.error('The `sitecore.cli.config` file is missing a `config`. Please add it to use this command.');
151
+ return;
152
+ }
153
+ const { edgeUrl } = cliConfig.config.api.edge;
154
+ let backupPath;
155
+ let resolvedFilePath;
156
+ try {
157
+ if (validateTargetPath(targetPath) !== true) {
158
+ console.error(chalk_1.default.red(validateTargetPath(targetPath)));
159
+ return;
160
+ }
161
+ const spec = yield getComponentSpec({
162
+ edgeUrl,
163
+ componentId,
164
+ targetPath,
165
+ token,
166
+ });
167
+ const componentType = spec.meta['contentsdk-component-type'];
168
+ const componentName = spec.meta['contentsdk-component-name'];
169
+ const variantName = spec.meta['contentsdk-component-variant-name'];
170
+ const title = spec.title;
171
+ if (componentType !== 'variant') {
172
+ console.error(chalk_1.default.red(`The component "${title}" is not a content-sdk variant. Please, select a content-sdk variant to use this command.`));
173
+ return;
174
+ }
175
+ if (!targetPath) {
176
+ const { paths, exclude } = cliConfig.componentMap;
177
+ const components = getComponentList(paths, exclude, true);
178
+ const registeredComponent = components.find((c) => c.componentName === componentName);
179
+ if (registeredComponent) {
180
+ targetPath = registeredComponent.filePath
181
+ .replace(/\\/g, '/')
182
+ .replace(/([^/]+)\.([^.]+)$/, `$1.${variantName}.$2`);
183
+ }
184
+ else {
185
+ targetPath = yield inquirer_1.default
186
+ .prompt({
187
+ type: 'input',
188
+ name: 'targetPath',
189
+ required: true,
190
+ message: `Enter the target path for the component.\n(Example: components/Promo.WithText.ts):`,
191
+ validate: validateTargetPath,
192
+ })
193
+ .then((answer) => answer.targetPath);
194
+ }
195
+ }
196
+ resolvedFilePath = path_1.default.resolve(process.cwd(), targetPath);
197
+ const isFileAlreadyExists = fs_1.default.existsSync(resolvedFilePath);
198
+ backupPath = `${resolvedFilePath}.backup`;
199
+ if (isFileAlreadyExists) {
200
+ if (!overwrite) {
201
+ const shouldOverwrite = yield inquirer_1.default.prompt({
202
+ type: 'confirm',
203
+ name: 'overwrite',
204
+ message: `File already exists: ${targetPath}. Overwrite?`,
205
+ default: false,
206
+ });
207
+ if (!shouldOverwrite.overwrite) {
208
+ return;
209
+ }
210
+ }
211
+ fs_1.default.renameSync(resolvedFilePath, backupPath);
212
+ console.log(chalk_1.default.yellow(`Overwriting existing file: ${targetPath}`));
213
+ }
214
+ const componentSpecUrl = getComponentSpecUrl({
215
+ componentId,
216
+ targetPath: targetPath,
217
+ edgeUrl,
218
+ token,
219
+ });
220
+ (0, child_process_1.execSync)(`npx shadcn@^3.4.2 add "${componentSpecUrl}"`, {
221
+ stdio: 'inherit',
222
+ cwd: process.cwd(),
223
+ });
224
+ if (isFileAlreadyExists) {
225
+ fs_1.default.unlinkSync(backupPath);
226
+ }
227
+ if (!skipComponentMap) {
228
+ (0, generate_map_1.handler)({ config });
229
+ }
230
+ console.log(chalk_1.default.green(`Component ${componentName} added successfully`));
231
+ }
232
+ catch (error) {
233
+ if (backupPath && resolvedFilePath && fs_1.default.existsSync(backupPath)) {
234
+ fs_1.default.renameSync(backupPath, resolvedFilePath);
235
+ }
236
+ const errorMessage = error instanceof Error ? error.message : String(error);
237
+ console.error(chalk_1.default.red(`Failed to add component: ${errorMessage}`));
238
+ return;
239
+ }
240
+ });
241
+ }
@@ -1,68 +1,70 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.builder = builder;
7
- exports.args = args;
8
- exports.handler = handler;
9
- const watch_items_1 = require("../../../utils/watch-items");
10
- const load_config_1 = __importDefault(require("../../../utils/load-config"));
11
- /**
12
- * @param {Argv} yargs
13
- */
14
- function builder(yargs) {
15
- return yargs.command('generate-map', 'Generates component map based on provided paths', args, handler);
16
- }
17
- /**
18
- * @param {Argv} yargs
19
- */
20
- function args(yargs) {
21
- return yargs
22
- .option('watch', {
23
- requiresArg: false,
24
- type: 'boolean',
25
- describe: 'If true, watches for changes in the specified paths and updates the component map accordingly.',
26
- default: false,
27
- })
28
- .option('config', {
29
- requiresArg: false,
30
- type: 'string',
31
- describe: 'Path to the `sitecore.cli.config` file. Supports both JavaScript (`.js`) and TypeScript (`.ts`) formats',
32
- });
33
- }
34
- /**
35
- * Handler for the `generate-map` command.
36
- * @param {GenerateMapCliArgs} argv Cli arguments for the command
37
- */
38
- function handler(argv) {
39
- const cliConfig = (0, load_config_1.default)(argv.config);
40
- if (!cliConfig.componentMap) {
41
- console.error('The `sitecore.cli.config` file is missing a `componentMap` configuration. Please add it to use this command.');
42
- return;
43
- }
44
- const componentMapGenerator = cliConfig.componentMap.generator;
45
- const { paths, destination, componentImports, exclude, clientComponentMap, includeVariants } = cliConfig.componentMap;
46
- if (argv.watch) {
47
- console.log(`Watching for component changes to component builder sources in:\n ${paths.join('\n')}`);
48
- (0, watch_items_1.watchItems)(paths, componentMapGenerator.bind(null, {
49
- paths,
50
- destination,
51
- componentImports,
52
- exclude,
53
- clientComponentMap,
54
- includeVariants,
55
- }));
56
- }
57
- else {
58
- console.log(`Generating component map for:\n ${paths.join('\n')}`);
59
- componentMapGenerator({
60
- paths,
61
- destination,
62
- componentImports,
63
- exclude,
64
- clientComponentMap,
65
- includeVariants,
66
- });
67
- }
68
- }
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.builder = builder;
7
+ exports.args = args;
8
+ exports.handler = handler;
9
+ const watch_items_1 = require("../../../utils/watch-items");
10
+ const load_config_1 = __importDefault(require("../../../utils/load-config"));
11
+ /**
12
+ * @param {Argv} yargs
13
+ */
14
+ function builder(yargs) {
15
+ return yargs.command(['generate-map', 'g'], 'Generates component map based on provided paths', args, handler);
16
+ }
17
+ /**
18
+ * @param {Argv} yargs
19
+ */
20
+ function args(yargs) {
21
+ return yargs
22
+ .option('watch', {
23
+ requiresArg: false,
24
+ type: 'boolean',
25
+ describe: 'If true, watches for changes in the specified paths and updates the component map accordingly.',
26
+ default: false,
27
+ alias: 'w',
28
+ })
29
+ .option('config', {
30
+ requiresArg: false,
31
+ type: 'string',
32
+ describe: 'Path to the `sitecore.cli.config` file. Supports both JavaScript (`.js`) and TypeScript (`.ts`) formats',
33
+ alias: 'c',
34
+ });
35
+ }
36
+ /**
37
+ * Handler for the `generate-map` command.
38
+ * @param {GenerateMapCliArgs} argv Cli arguments for the command
39
+ */
40
+ function handler(argv) {
41
+ const cliConfig = (0, load_config_1.default)(argv.config);
42
+ if (!cliConfig.componentMap) {
43
+ console.error('The `sitecore.cli.config` file is missing a `componentMap` configuration. Please add it to use this command.');
44
+ return;
45
+ }
46
+ const componentMapGenerator = cliConfig.componentMap.generator;
47
+ const { paths, destination, componentImports, exclude, clientComponentMap, includeVariants } = cliConfig.componentMap;
48
+ if (argv.watch) {
49
+ console.log(`Watching for component changes to component builder sources in:\n ${paths.join('\n')}`);
50
+ (0, watch_items_1.watchItems)(paths, componentMapGenerator.bind(null, {
51
+ paths,
52
+ destination,
53
+ componentImports,
54
+ exclude,
55
+ clientComponentMap,
56
+ includeVariants,
57
+ }));
58
+ }
59
+ else {
60
+ console.log(`Generating component map for:\n ${paths.join('\n')}`);
61
+ componentMapGenerator({
62
+ paths,
63
+ destination,
64
+ componentImports,
65
+ exclude,
66
+ clientComponentMap,
67
+ includeVariants,
68
+ });
69
+ }
70
+ }