@sitecore-content-sdk/cli 1.3.0-canary.9 → 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/LICENSE.txt +202 -202
- package/README.md +5 -5
- package/dist/cjs/bin/sitecore-tools.js +77 -77
- package/dist/cjs/cli.js +69 -69
- package/dist/cjs/scripts/index.js +40 -40
- package/dist/cjs/scripts/project/build.js +42 -42
- package/dist/cjs/scripts/project/component/add.js +241 -236
- package/dist/cjs/scripts/project/component/generate-map.js +70 -68
- package/dist/cjs/scripts/project/component/index.js +57 -57
- package/dist/cjs/scripts/project/component/scaffold.js +69 -66
- package/dist/cjs/scripts/project/index.js +56 -56
- package/dist/cjs/utils/load-config.js +42 -42
- package/dist/cjs/utils/process-env.js +70 -70
- package/dist/cjs/utils/watch-items.js +18 -18
- package/dist/esm/cli.js +63 -63
- package/dist/esm/scripts/index.js +4 -4
- package/dist/esm/scripts/project/build.js +35 -35
- package/dist/esm/scripts/project/component/add.js +198 -193
- package/dist/esm/scripts/project/component/generate-map.js +62 -60
- package/dist/esm/scripts/project/component/index.js +21 -21
- package/dist/esm/scripts/project/component/scaffold.js +61 -58
- package/dist/esm/scripts/project/index.js +20 -20
- package/dist/esm/utils/load-config.js +36 -36
- package/dist/esm/utils/process-env.js +31 -31
- package/dist/esm/utils/watch-items.js +12 -12
- package/package.json +79 -79
- package/types/bin/sitecore-tools.d.ts +3 -2
- package/types/bin/sitecore-tools.d.ts.map +1 -0
- package/types/cli.d.ts +14 -13
- package/types/cli.d.ts.map +1 -0
- package/types/scripts/index.d.ts +3 -2
- package/types/scripts/index.d.ts.map +1 -0
- package/types/scripts/project/build.d.ts +25 -24
- package/types/scripts/project/build.d.ts.map +1 -0
- package/types/scripts/project/component/add.d.ts +59 -58
- package/types/scripts/project/component/add.d.ts.map +1 -0
- package/types/scripts/project/component/generate-map.d.ts +33 -32
- package/types/scripts/project/component/generate-map.d.ts.map +1 -0
- package/types/scripts/project/component/index.d.ts +6 -5
- package/types/scripts/project/component/index.d.ts.map +1 -0
- package/types/scripts/project/component/scaffold.d.ts +45 -44
- package/types/scripts/project/component/scaffold.d.ts.map +1 -0
- package/types/scripts/project/index.d.ts +6 -5
- package/types/scripts/project/index.d.ts.map +1 -0
- package/types/utils/load-config.d.ts +9 -8
- package/types/utils/load-config.d.ts.map +1 -0
- package/types/utils/process-env.d.ts +9 -8
- package/types/utils/process-env.d.ts.map +1 -0
- package/types/utils/watch-items.d.ts +7 -6
- 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
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
.
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
const
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
targetPath =
|
|
181
|
-
.
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
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
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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
|
+
}
|