@sitecore-content-sdk/cli 1.2.0-canary.9 → 1.3.0-canary.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/dist/cjs/scripts/project/build.js +1 -1
- package/dist/cjs/scripts/project/component/add.js +184 -0
- package/dist/cjs/scripts/project/component/generate-map.js +17 -3
- package/dist/cjs/utils/process-env.js +3 -0
- package/dist/esm/scripts/project/build.js +1 -1
- package/dist/esm/scripts/project/component/add.js +141 -0
- package/dist/esm/scripts/project/component/generate-map.js +17 -3
- package/dist/esm/utils/process-env.js +3 -0
- package/package.json +5 -3
- package/types/scripts/project/component/add.d.ts +58 -0
|
@@ -33,7 +33,7 @@ function handler(argv) {
|
|
|
33
33
|
const cliConfig = (0, load_config_1.default)(argv.config);
|
|
34
34
|
if (cliConfig.build && Array.isArray(cliConfig.build.commands)) {
|
|
35
35
|
for (const command of cliConfig.build.commands) {
|
|
36
|
-
yield command();
|
|
36
|
+
yield command({ scConfig: cliConfig.config });
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
// Exit the process to avoid hanging the process by custom build commands
|
|
@@ -0,0 +1,184 @@
|
|
|
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 chalk_1 = __importDefault(require("chalk"));
|
|
53
|
+
const child_process_1 = require("child_process");
|
|
54
|
+
const tools = __importStar(require("@sitecore-content-sdk/core/tools"));
|
|
55
|
+
const inquirer_1 = __importDefault(require("inquirer"));
|
|
56
|
+
const load_config_1 = __importDefault(require("../../../utils/load-config"));
|
|
57
|
+
const generate_map_1 = require("./generate-map");
|
|
58
|
+
let { getComponentVariantSpec, getComponentList, getComponentVariantSpecUrl } = tools;
|
|
59
|
+
const unitMocks = (toolsModule) => {
|
|
60
|
+
getComponentVariantSpec = toolsModule.getComponentVariantSpec;
|
|
61
|
+
getComponentList = toolsModule.getComponentList;
|
|
62
|
+
getComponentVariantSpecUrl = toolsModule.getComponentVariantSpecUrl;
|
|
63
|
+
};
|
|
64
|
+
exports.unitMocks = unitMocks;
|
|
65
|
+
/**
|
|
66
|
+
* @param {Argv} yargs
|
|
67
|
+
*/
|
|
68
|
+
function args(yargs) {
|
|
69
|
+
/* istanbul ignore next */
|
|
70
|
+
return yargs
|
|
71
|
+
.positional('variantId', {
|
|
72
|
+
requiresArg: true,
|
|
73
|
+
positional: true,
|
|
74
|
+
type: 'string',
|
|
75
|
+
describe: `The unique identifier of the newly created variant.`,
|
|
76
|
+
})
|
|
77
|
+
.option('token', {
|
|
78
|
+
requiresArg: true,
|
|
79
|
+
type: 'string',
|
|
80
|
+
describe: 'The authentication token.',
|
|
81
|
+
demandOption: true,
|
|
82
|
+
})
|
|
83
|
+
.option('target-path', {
|
|
84
|
+
requiresArg: false,
|
|
85
|
+
type: 'string',
|
|
86
|
+
describe: 'The target path for the component variant.',
|
|
87
|
+
})
|
|
88
|
+
.option('skip-component-map', {
|
|
89
|
+
requiresArg: false,
|
|
90
|
+
type: 'boolean',
|
|
91
|
+
describe: 'If true, skips the component map generation.',
|
|
92
|
+
default: false,
|
|
93
|
+
})
|
|
94
|
+
.option('overwrite', {
|
|
95
|
+
requiresArg: false,
|
|
96
|
+
type: 'boolean',
|
|
97
|
+
describe: 'If true, overwrites the existing component.',
|
|
98
|
+
default: false,
|
|
99
|
+
})
|
|
100
|
+
.option('config', {
|
|
101
|
+
requiresArg: false,
|
|
102
|
+
type: 'string',
|
|
103
|
+
describe: 'Path to the `sitecore.cli.config` file. Supports both JavaScript (`.js`) and TypeScript (`.ts`) formats',
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* @param {Argv} yargs
|
|
108
|
+
*/
|
|
109
|
+
function builder(yargs) {
|
|
110
|
+
/* istanbul ignore next */
|
|
111
|
+
return yargs.command('add <variant-id>', 'Adds a component variant', args, handler);
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Handler for the add command.
|
|
115
|
+
* @param {AddArgs} argv - The arguments passed to the command.
|
|
116
|
+
*/
|
|
117
|
+
function handler(argv) {
|
|
118
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
119
|
+
const { variantId, token, targetPath: targetPathArg, skipComponentMap, config, overwrite } = argv;
|
|
120
|
+
console.log(chalk_1.default.green('Adding component variant'));
|
|
121
|
+
let targetPath = targetPathArg;
|
|
122
|
+
const cliConfig = (0, load_config_1.default)(config);
|
|
123
|
+
if (!cliConfig.config) {
|
|
124
|
+
console.error('The `sitecore.cli.config` file is missing a `config`. Please add it to use this command.');
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
const { edgeUrl } = cliConfig.config.api.edge;
|
|
128
|
+
try {
|
|
129
|
+
const spec = yield getComponentVariantSpec({
|
|
130
|
+
edgeUrl,
|
|
131
|
+
variantId,
|
|
132
|
+
targetPath,
|
|
133
|
+
token,
|
|
134
|
+
});
|
|
135
|
+
const componentType = spec.meta['contentsdk-component-type'];
|
|
136
|
+
const componentName = spec.meta['contentsdk-component-name'];
|
|
137
|
+
const variantName = spec.meta['contentsdk-component-variant-name'];
|
|
138
|
+
const title = spec.title;
|
|
139
|
+
if (componentType !== 'variant') {
|
|
140
|
+
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.`));
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
if (!targetPath) {
|
|
144
|
+
const { paths, exclude } = cliConfig.componentMap;
|
|
145
|
+
const components = getComponentList(paths, exclude, true);
|
|
146
|
+
const registeredComponent = components.find((c) => c.componentName === componentName);
|
|
147
|
+
if (registeredComponent) {
|
|
148
|
+
targetPath = registeredComponent.filePath
|
|
149
|
+
.replace(/\\/g, '/')
|
|
150
|
+
.replace(/([^/]+)\.([^.]+)$/, `$1.${variantName}.$2`);
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
targetPath = yield inquirer_1.default
|
|
154
|
+
.prompt({
|
|
155
|
+
type: 'input',
|
|
156
|
+
name: 'targetPath',
|
|
157
|
+
required: true,
|
|
158
|
+
message: `Enter the target path for the component variant.\nThe filename must follow the format: {componentName}.{variantName}.{extension}\n(example: src/components/MyComponent/MyComponent.variantA.ts):`,
|
|
159
|
+
})
|
|
160
|
+
.then((answer) => answer.targetPath);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
const variantSpecUrl = getComponentVariantSpecUrl({
|
|
164
|
+
variantId,
|
|
165
|
+
targetPath: targetPath,
|
|
166
|
+
edgeUrl,
|
|
167
|
+
token,
|
|
168
|
+
});
|
|
169
|
+
(0, child_process_1.execSync)(`npx shadcn@^3.4.2 add "${variantSpecUrl}"${overwrite ? ' --overwrite' : ''}`, {
|
|
170
|
+
stdio: 'inherit',
|
|
171
|
+
cwd: process.cwd(),
|
|
172
|
+
});
|
|
173
|
+
if (!skipComponentMap) {
|
|
174
|
+
(0, generate_map_1.handler)({ config });
|
|
175
|
+
}
|
|
176
|
+
console.log(chalk_1.default.green(`Component variant ${variantName} added successfully`));
|
|
177
|
+
}
|
|
178
|
+
catch (error) {
|
|
179
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
180
|
+
console.error(chalk_1.default.red(`Failed to add component variant: ${errorMessage}`));
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
}
|
|
@@ -42,13 +42,27 @@ function handler(argv) {
|
|
|
42
42
|
return;
|
|
43
43
|
}
|
|
44
44
|
const componentMapGenerator = cliConfig.componentMap.generator;
|
|
45
|
-
const { paths, destination, componentImports, exclude } = cliConfig.componentMap;
|
|
45
|
+
const { paths, destination, componentImports, exclude, clientComponentMap, includeVariants } = cliConfig.componentMap;
|
|
46
46
|
if (argv.watch) {
|
|
47
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, {
|
|
48
|
+
(0, watch_items_1.watchItems)(paths, componentMapGenerator.bind(null, {
|
|
49
|
+
paths,
|
|
50
|
+
destination,
|
|
51
|
+
componentImports,
|
|
52
|
+
exclude,
|
|
53
|
+
clientComponentMap,
|
|
54
|
+
includeVariants,
|
|
55
|
+
}));
|
|
49
56
|
}
|
|
50
57
|
else {
|
|
51
58
|
console.log(`Generating component map for:\n ${paths.join('\n')}`);
|
|
52
|
-
componentMapGenerator({
|
|
59
|
+
componentMapGenerator({
|
|
60
|
+
paths,
|
|
61
|
+
destination,
|
|
62
|
+
componentImports,
|
|
63
|
+
exclude,
|
|
64
|
+
clientComponentMap,
|
|
65
|
+
includeVariants,
|
|
66
|
+
});
|
|
53
67
|
}
|
|
54
68
|
}
|
|
@@ -40,6 +40,7 @@ exports.default = processEnv;
|
|
|
40
40
|
const path_1 = __importDefault(require("path"));
|
|
41
41
|
const dotenv = __importStar(require("dotenv"));
|
|
42
42
|
const dotenv_expand_1 = __importDefault(require("dotenv-expand"));
|
|
43
|
+
const config_cli_1 = require("@sitecore-content-sdk/core/config-cli");
|
|
43
44
|
/**
|
|
44
45
|
* Loads and processes environment variables from `.env` files in the specified directory.
|
|
45
46
|
* It supports multiple `.env` files, including
|
|
@@ -60,6 +61,8 @@ function processEnv(dir) {
|
|
|
60
61
|
mode && `.env.${mode}`,
|
|
61
62
|
'.env',
|
|
62
63
|
].filter(Boolean);
|
|
64
|
+
// Set the environment variable to indicate that the application is running in CLI mode
|
|
65
|
+
process.env[config_cli_1.SITECORE_CLI_MODE_ENV_VAR] = 'true';
|
|
63
66
|
// inspired by https://github.com/entropitor/dotenv-cli/blob/v4.0.0/cli.js#L53-L55
|
|
64
67
|
dotenvFiles.forEach(function (env) {
|
|
65
68
|
dotenv_expand_1.default.expand(dotenv.config({ path: path_1.default.resolve(dir, env) }));
|
|
@@ -26,7 +26,7 @@ export function handler(argv) {
|
|
|
26
26
|
const cliConfig = loadCliConfig(argv.config);
|
|
27
27
|
if (cliConfig.build && Array.isArray(cliConfig.build.commands)) {
|
|
28
28
|
for (const command of cliConfig.build.commands) {
|
|
29
|
-
yield command();
|
|
29
|
+
yield command({ scConfig: cliConfig.config });
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
// Exit the process to avoid hanging the process by custom build commands
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import chalk from 'chalk';
|
|
11
|
+
import { execSync } from 'child_process';
|
|
12
|
+
import * as tools from '@sitecore-content-sdk/core/tools';
|
|
13
|
+
import inquirer from 'inquirer';
|
|
14
|
+
import loadCliConfig from '../../../utils/load-config';
|
|
15
|
+
import { handler as generateMapHandler } from './generate-map';
|
|
16
|
+
let { getComponentVariantSpec, getComponentList, getComponentVariantSpecUrl } = tools;
|
|
17
|
+
export const unitMocks = (toolsModule) => {
|
|
18
|
+
getComponentVariantSpec = toolsModule.getComponentVariantSpec;
|
|
19
|
+
getComponentList = toolsModule.getComponentList;
|
|
20
|
+
getComponentVariantSpecUrl = toolsModule.getComponentVariantSpecUrl;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* @param {Argv} yargs
|
|
24
|
+
*/
|
|
25
|
+
export function args(yargs) {
|
|
26
|
+
/* istanbul ignore next */
|
|
27
|
+
return yargs
|
|
28
|
+
.positional('variantId', {
|
|
29
|
+
requiresArg: true,
|
|
30
|
+
positional: true,
|
|
31
|
+
type: 'string',
|
|
32
|
+
describe: `The unique identifier of the newly created variant.`,
|
|
33
|
+
})
|
|
34
|
+
.option('token', {
|
|
35
|
+
requiresArg: true,
|
|
36
|
+
type: 'string',
|
|
37
|
+
describe: 'The authentication token.',
|
|
38
|
+
demandOption: true,
|
|
39
|
+
})
|
|
40
|
+
.option('target-path', {
|
|
41
|
+
requiresArg: false,
|
|
42
|
+
type: 'string',
|
|
43
|
+
describe: 'The target path for the component variant.',
|
|
44
|
+
})
|
|
45
|
+
.option('skip-component-map', {
|
|
46
|
+
requiresArg: false,
|
|
47
|
+
type: 'boolean',
|
|
48
|
+
describe: 'If true, skips the component map generation.',
|
|
49
|
+
default: false,
|
|
50
|
+
})
|
|
51
|
+
.option('overwrite', {
|
|
52
|
+
requiresArg: false,
|
|
53
|
+
type: 'boolean',
|
|
54
|
+
describe: 'If true, overwrites the existing component.',
|
|
55
|
+
default: false,
|
|
56
|
+
})
|
|
57
|
+
.option('config', {
|
|
58
|
+
requiresArg: false,
|
|
59
|
+
type: 'string',
|
|
60
|
+
describe: 'Path to the `sitecore.cli.config` file. Supports both JavaScript (`.js`) and TypeScript (`.ts`) formats',
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* @param {Argv} yargs
|
|
65
|
+
*/
|
|
66
|
+
export function builder(yargs) {
|
|
67
|
+
/* istanbul ignore next */
|
|
68
|
+
return yargs.command('add <variant-id>', 'Adds a component variant', args, handler);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Handler for the add command.
|
|
72
|
+
* @param {AddArgs} argv - The arguments passed to the command.
|
|
73
|
+
*/
|
|
74
|
+
export function handler(argv) {
|
|
75
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
76
|
+
const { variantId, token, targetPath: targetPathArg, skipComponentMap, config, overwrite } = argv;
|
|
77
|
+
console.log(chalk.green('Adding component variant'));
|
|
78
|
+
let targetPath = targetPathArg;
|
|
79
|
+
const cliConfig = loadCliConfig(config);
|
|
80
|
+
if (!cliConfig.config) {
|
|
81
|
+
console.error('The `sitecore.cli.config` file is missing a `config`. Please add it to use this command.');
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
const { edgeUrl } = cliConfig.config.api.edge;
|
|
85
|
+
try {
|
|
86
|
+
const spec = yield getComponentVariantSpec({
|
|
87
|
+
edgeUrl,
|
|
88
|
+
variantId,
|
|
89
|
+
targetPath,
|
|
90
|
+
token,
|
|
91
|
+
});
|
|
92
|
+
const componentType = spec.meta['contentsdk-component-type'];
|
|
93
|
+
const componentName = spec.meta['contentsdk-component-name'];
|
|
94
|
+
const variantName = spec.meta['contentsdk-component-variant-name'];
|
|
95
|
+
const title = spec.title;
|
|
96
|
+
if (componentType !== 'variant') {
|
|
97
|
+
console.error(chalk.red(`The component "${title}" is not a content-sdk variant. Please, select a content-sdk variant to use this command.`));
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
if (!targetPath) {
|
|
101
|
+
const { paths, exclude } = cliConfig.componentMap;
|
|
102
|
+
const components = getComponentList(paths, exclude, true);
|
|
103
|
+
const registeredComponent = components.find((c) => c.componentName === componentName);
|
|
104
|
+
if (registeredComponent) {
|
|
105
|
+
targetPath = registeredComponent.filePath
|
|
106
|
+
.replace(/\\/g, '/')
|
|
107
|
+
.replace(/([^/]+)\.([^.]+)$/, `$1.${variantName}.$2`);
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
targetPath = yield inquirer
|
|
111
|
+
.prompt({
|
|
112
|
+
type: 'input',
|
|
113
|
+
name: 'targetPath',
|
|
114
|
+
required: true,
|
|
115
|
+
message: `Enter the target path for the component variant.\nThe filename must follow the format: {componentName}.{variantName}.{extension}\n(example: src/components/MyComponent/MyComponent.variantA.ts):`,
|
|
116
|
+
})
|
|
117
|
+
.then((answer) => answer.targetPath);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
const variantSpecUrl = getComponentVariantSpecUrl({
|
|
121
|
+
variantId,
|
|
122
|
+
targetPath: targetPath,
|
|
123
|
+
edgeUrl,
|
|
124
|
+
token,
|
|
125
|
+
});
|
|
126
|
+
execSync(`npx shadcn@^3.4.2 add "${variantSpecUrl}"${overwrite ? ' --overwrite' : ''}`, {
|
|
127
|
+
stdio: 'inherit',
|
|
128
|
+
cwd: process.cwd(),
|
|
129
|
+
});
|
|
130
|
+
if (!skipComponentMap) {
|
|
131
|
+
generateMapHandler({ config });
|
|
132
|
+
}
|
|
133
|
+
console.log(chalk.green(`Component variant ${variantName} added successfully`));
|
|
134
|
+
}
|
|
135
|
+
catch (error) {
|
|
136
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
137
|
+
console.error(chalk.red(`Failed to add component variant: ${errorMessage}`));
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
}
|
|
@@ -34,13 +34,27 @@ export function handler(argv) {
|
|
|
34
34
|
return;
|
|
35
35
|
}
|
|
36
36
|
const componentMapGenerator = cliConfig.componentMap.generator;
|
|
37
|
-
const { paths, destination, componentImports, exclude } = cliConfig.componentMap;
|
|
37
|
+
const { paths, destination, componentImports, exclude, clientComponentMap, includeVariants } = cliConfig.componentMap;
|
|
38
38
|
if (argv.watch) {
|
|
39
39
|
console.log(`Watching for component changes to component builder sources in:\n ${paths.join('\n')}`);
|
|
40
|
-
watchItems(paths, componentMapGenerator.bind(null, {
|
|
40
|
+
watchItems(paths, componentMapGenerator.bind(null, {
|
|
41
|
+
paths,
|
|
42
|
+
destination,
|
|
43
|
+
componentImports,
|
|
44
|
+
exclude,
|
|
45
|
+
clientComponentMap,
|
|
46
|
+
includeVariants,
|
|
47
|
+
}));
|
|
41
48
|
}
|
|
42
49
|
else {
|
|
43
50
|
console.log(`Generating component map for:\n ${paths.join('\n')}`);
|
|
44
|
-
componentMapGenerator({
|
|
51
|
+
componentMapGenerator({
|
|
52
|
+
paths,
|
|
53
|
+
destination,
|
|
54
|
+
componentImports,
|
|
55
|
+
exclude,
|
|
56
|
+
clientComponentMap,
|
|
57
|
+
includeVariants,
|
|
58
|
+
});
|
|
45
59
|
}
|
|
46
60
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
2
|
import * as dotenv from 'dotenv';
|
|
3
3
|
import dotenvExpand from 'dotenv-expand';
|
|
4
|
+
import { SITECORE_CLI_MODE_ENV_VAR } from '@sitecore-content-sdk/core/config-cli';
|
|
4
5
|
/**
|
|
5
6
|
* Loads and processes environment variables from `.env` files in the specified directory.
|
|
6
7
|
* It supports multiple `.env` files, including
|
|
@@ -21,6 +22,8 @@ export default function processEnv(dir) {
|
|
|
21
22
|
mode && `.env.${mode}`,
|
|
22
23
|
'.env',
|
|
23
24
|
].filter(Boolean);
|
|
25
|
+
// Set the environment variable to indicate that the application is running in CLI mode
|
|
26
|
+
process.env[SITECORE_CLI_MODE_ENV_VAR] = 'true';
|
|
24
27
|
// inspired by https://github.com/entropitor/dotenv-cli/blob/v4.0.0/cli.js#L53-L55
|
|
25
28
|
dotenvFiles.forEach(function (env) {
|
|
26
29
|
dotenvExpand.expand(dotenv.config({ path: path.resolve(dir, env) }));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sitecore-content-sdk/cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0-canary.2",
|
|
4
4
|
"description": "Sitecore Content SDK CLI",
|
|
5
5
|
"main": "dist/cjs/cli.js",
|
|
6
6
|
"module": "dist/esm/cli.js",
|
|
@@ -34,10 +34,11 @@
|
|
|
34
34
|
"url": "https://github.com/sitecore/content-sdk/issues"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@sitecore-content-sdk/core": "1.
|
|
37
|
+
"@sitecore-content-sdk/core": "1.3.0-canary.2",
|
|
38
38
|
"chokidar": "^4.0.3",
|
|
39
39
|
"dotenv": "^16.5.0",
|
|
40
40
|
"dotenv-expand": "^12.0.2",
|
|
41
|
+
"inquirer": "^12.9.6",
|
|
41
42
|
"resolve": "^1.22.10",
|
|
42
43
|
"tmp": "^0.2.3",
|
|
43
44
|
"tsx": "^4.19.4",
|
|
@@ -46,6 +47,7 @@
|
|
|
46
47
|
"devDependencies": {
|
|
47
48
|
"@stylistic/eslint-plugin": "^5.2.2",
|
|
48
49
|
"@types/chai": "^5.2.2",
|
|
50
|
+
"@types/inquirer": "^9.0.9",
|
|
49
51
|
"@types/mocha": "^10.0.10",
|
|
50
52
|
"@types/node": "^22.15.13",
|
|
51
53
|
"@types/resolve": "^1.20.6",
|
|
@@ -69,7 +71,7 @@
|
|
|
69
71
|
"ts-node": "^10.9.1",
|
|
70
72
|
"typescript": "~5.8.3"
|
|
71
73
|
},
|
|
72
|
-
"gitHead": "
|
|
74
|
+
"gitHead": "8daa222f701d12815256314f861d9b79ada1fc1b",
|
|
73
75
|
"files": [
|
|
74
76
|
"dist",
|
|
75
77
|
"types"
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { Argv } from 'yargs';
|
|
2
|
+
import * as tools from '@sitecore-content-sdk/core/tools';
|
|
3
|
+
export declare const unitMocks: (toolsModule: Pick<typeof tools, "getComponentVariantSpec" | "getComponentList" | "getComponentVariantSpecUrl">) => void;
|
|
4
|
+
type AddArgs = {
|
|
5
|
+
/**
|
|
6
|
+
* The unique identifier of the newly created variant.
|
|
7
|
+
*/
|
|
8
|
+
variantId: string;
|
|
9
|
+
/**
|
|
10
|
+
* The authentication token.
|
|
11
|
+
*/
|
|
12
|
+
token: string;
|
|
13
|
+
/**
|
|
14
|
+
* The target path for the component variant.
|
|
15
|
+
*/
|
|
16
|
+
targetPath?: string;
|
|
17
|
+
/**
|
|
18
|
+
* If true, skips the component map generation.
|
|
19
|
+
* Default: false.
|
|
20
|
+
*/
|
|
21
|
+
skipComponentMap?: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* If true, overwrites the existing component.
|
|
24
|
+
* Default: false.
|
|
25
|
+
*/
|
|
26
|
+
overwrite?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Path to the `sitecore.cli.config` file.
|
|
29
|
+
* Supports both JavaScript (`.js`) and TypeScript (`.ts`) formats.
|
|
30
|
+
*/
|
|
31
|
+
config?: string;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* @param {Argv} yargs
|
|
35
|
+
*/
|
|
36
|
+
export declare function args(yargs: Argv<AddArgs>): Argv<import("yargs").Omit<import("yargs").Omit<import("yargs").Omit<import("yargs").Omit<AddArgs, "variantId"> & {
|
|
37
|
+
variantId: string | undefined;
|
|
38
|
+
}, "token"> & {
|
|
39
|
+
token: string;
|
|
40
|
+
} & {
|
|
41
|
+
"target-path": string | undefined;
|
|
42
|
+
} & {
|
|
43
|
+
"skip-component-map": boolean;
|
|
44
|
+
}, "overwrite"> & {
|
|
45
|
+
overwrite: boolean;
|
|
46
|
+
}, "config"> & {
|
|
47
|
+
config: string | undefined;
|
|
48
|
+
}>;
|
|
49
|
+
/**
|
|
50
|
+
* @param {Argv} yargs
|
|
51
|
+
*/
|
|
52
|
+
export declare function builder(yargs: Argv<AddArgs>): Argv<AddArgs>;
|
|
53
|
+
/**
|
|
54
|
+
* Handler for the add command.
|
|
55
|
+
* @param {AddArgs} argv - The arguments passed to the command.
|
|
56
|
+
*/
|
|
57
|
+
export declare function handler(argv: AddArgs): Promise<void>;
|
|
58
|
+
export {};
|