@sitecore-content-sdk/cli 0.1.0-beta.4 → 0.1.0-beta.40
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/bin/sitecore-tools.js +65 -0
- package/dist/cjs/cli.js +1 -1
- package/dist/cjs/scripts/build.js +40 -0
- package/dist/cjs/scripts/index.js +42 -0
- package/dist/cjs/scripts/scaffold.js +68 -0
- package/dist/cjs/utils/load-config.js +42 -0
- package/dist/esm/cli.js +1 -1
- package/dist/esm/scripts/build.js +33 -0
- package/dist/esm/scripts/index.js +5 -0
- package/dist/esm/scripts/scaffold.js +60 -0
- package/dist/esm/utils/load-config.js +36 -0
- package/package.json +7 -4
- package/types/scripts/build.d.ts +24 -0
- package/types/scripts/index.d.ts +3 -0
- package/types/scripts/scaffold.d.ts +44 -0
- package/types/utils/load-config.d.ts +8 -0
- package/dist/cjs/bin/jss.js +0 -19
- /package/types/bin/{jss.d.ts → sitecore-tools.d.ts} +0 -0
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
10
|
+
}) : (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
o[k2] = m[k];
|
|
13
|
+
}));
|
|
14
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
+
}) : function(o, v) {
|
|
17
|
+
o["default"] = v;
|
|
18
|
+
});
|
|
19
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
20
|
+
var ownKeys = function(o) {
|
|
21
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
22
|
+
var ar = [];
|
|
23
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
24
|
+
return ar;
|
|
25
|
+
};
|
|
26
|
+
return ownKeys(o);
|
|
27
|
+
};
|
|
28
|
+
return function (mod) {
|
|
29
|
+
if (mod && mod.__esModule) return mod;
|
|
30
|
+
var result = {};
|
|
31
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
32
|
+
__setModuleDefault(result, mod);
|
|
33
|
+
return result;
|
|
34
|
+
};
|
|
35
|
+
})();
|
|
36
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
37
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
38
|
+
};
|
|
39
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
+
const resolve_1 = __importDefault(require("resolve"));
|
|
41
|
+
const process_env_1 = __importDefault(require("../utils/process-env"));
|
|
42
|
+
const commands = __importStar(require("../scripts"));
|
|
43
|
+
/**
|
|
44
|
+
* Resolves and executes the locally installed version of the sitecore content sdk CLI (sitecore-tools).
|
|
45
|
+
*/
|
|
46
|
+
(0, resolve_1.default)('@sitecore-content-sdk/cli', { basedir: process.cwd() }, (error, projectLocalCli) => {
|
|
47
|
+
let cli;
|
|
48
|
+
if (error) {
|
|
49
|
+
// If there is an error, resolve could not find the cli
|
|
50
|
+
// library from a package.json. Instead, include it from a relative
|
|
51
|
+
// path to this script file (which is likely a globally installed
|
|
52
|
+
// npm package).
|
|
53
|
+
// Not erroring here because we might use this in future for scaffolding.
|
|
54
|
+
cli = require('../cli').default;
|
|
55
|
+
console.warn('Sitecore Content SDK CLI is running in global mode because it was not installed in the local node_modules folder.');
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
// No error implies a projectLocalCli, which will load whatever
|
|
59
|
+
// version of jss-cli you have installed in a local package.json
|
|
60
|
+
cli = require(projectLocalCli).default;
|
|
61
|
+
// Since we are in context of a project, load its environment variables
|
|
62
|
+
(0, process_env_1.default)(process.cwd());
|
|
63
|
+
}
|
|
64
|
+
cli(commands);
|
|
65
|
+
});
|
package/dist/cjs/cli.js
CHANGED
|
@@ -30,7 +30,7 @@ process.on('unhandledRejection', (err) => {
|
|
|
30
30
|
function cli(commands) {
|
|
31
31
|
return __awaiter(this, void 0, void 0, function* () {
|
|
32
32
|
let appCommands = yargs_1.default.usage('$0 <command>');
|
|
33
|
-
appCommands = appCommands.scriptName('
|
|
33
|
+
appCommands = appCommands.scriptName('sitecore-tools');
|
|
34
34
|
// Register commands if available
|
|
35
35
|
if (commands && Object.keys(commands).length > 0) {
|
|
36
36
|
for (const cmd of Object.keys(commands)) {
|
|
@@ -0,0 +1,40 @@
|
|
|
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
|
+
exports.builder = exports.describe = exports.command = void 0;
|
|
16
|
+
exports.handler = handler;
|
|
17
|
+
const load_config_1 = __importDefault(require("../utils/load-config"));
|
|
18
|
+
exports.command = 'build';
|
|
19
|
+
exports.describe = 'Handles build time automation';
|
|
20
|
+
exports.builder = {
|
|
21
|
+
config: {
|
|
22
|
+
requiresArg: false,
|
|
23
|
+
type: 'string',
|
|
24
|
+
describe: 'Path to the `sitecore.cli.config` file. Supports both JavaScript (`.js`) and TypeScript (`.ts`) formats.',
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Handler for the build command.
|
|
29
|
+
* @param {BuildArgs} argv - The arguments passed to the command.
|
|
30
|
+
*/
|
|
31
|
+
function handler(argv) {
|
|
32
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
33
|
+
const cliConfig = (0, load_config_1.default)(argv.config);
|
|
34
|
+
if (cliConfig.build && Array.isArray(cliConfig.build.commands)) {
|
|
35
|
+
for (const command of cliConfig.build.commands) {
|
|
36
|
+
yield command();
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// commands available when running from an app location (with CLI installed to local node_modules)
|
|
3
|
+
// e.g. setup, deploy
|
|
4
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
5
|
+
if (k2 === undefined) k2 = k;
|
|
6
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
7
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
8
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
9
|
+
}
|
|
10
|
+
Object.defineProperty(o, k2, desc);
|
|
11
|
+
}) : (function(o, m, k, k2) {
|
|
12
|
+
if (k2 === undefined) k2 = k;
|
|
13
|
+
o[k2] = m[k];
|
|
14
|
+
}));
|
|
15
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
16
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
17
|
+
}) : function(o, v) {
|
|
18
|
+
o["default"] = v;
|
|
19
|
+
});
|
|
20
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
21
|
+
var ownKeys = function(o) {
|
|
22
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
23
|
+
var ar = [];
|
|
24
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
25
|
+
return ar;
|
|
26
|
+
};
|
|
27
|
+
return ownKeys(o);
|
|
28
|
+
};
|
|
29
|
+
return function (mod) {
|
|
30
|
+
if (mod && mod.__esModule) return mod;
|
|
31
|
+
var result = {};
|
|
32
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
33
|
+
__setModuleDefault(result, mod);
|
|
34
|
+
return result;
|
|
35
|
+
};
|
|
36
|
+
})();
|
|
37
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
+
exports.scaffold = exports.build = void 0;
|
|
39
|
+
const build = __importStar(require("./build"));
|
|
40
|
+
exports.build = build;
|
|
41
|
+
const scaffold = __importStar(require("./scaffold"));
|
|
42
|
+
exports.scaffold = scaffold;
|
|
@@ -0,0 +1,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 tools_1 = require("@sitecore-content-sdk/core/tools");
|
|
10
|
+
const load_config_1 = __importDefault(require("../utils/load-config"));
|
|
11
|
+
const config_1 = require("@sitecore-content-sdk/core/config");
|
|
12
|
+
/**
|
|
13
|
+
* @param {Argv} yargs
|
|
14
|
+
*/
|
|
15
|
+
function builder(yargs) {
|
|
16
|
+
return yargs.command('scaffold <componentName>', 'Scaffolds a new component. Use `sitecore-tools scaffold --help` for available options.', args, handler);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* @param {Argv} yargs
|
|
20
|
+
*/
|
|
21
|
+
function args(yargs) {
|
|
22
|
+
return yargs
|
|
23
|
+
.positional('componentName', {
|
|
24
|
+
requiresArg: true,
|
|
25
|
+
positional: true,
|
|
26
|
+
type: 'string',
|
|
27
|
+
describe: `Name of the component to scaffold. Component name should start with an uppercase letter and contain only letters, numbers,
|
|
28
|
+
dashes, or underscores. It can also contain slashes to indicate a subfolder. Example: MyComponent or MyFolder/MyComponent. If no subfolder is specified, the component will be created under 'src/components'.`,
|
|
29
|
+
})
|
|
30
|
+
.option('config', {
|
|
31
|
+
requiresArg: false,
|
|
32
|
+
type: 'string',
|
|
33
|
+
describe: 'Path to the `sitecore.cli.config` file. Supports both JavaScript (`.js`) and TypeScript (`.ts`) formats',
|
|
34
|
+
})
|
|
35
|
+
.option('templateName', {
|
|
36
|
+
requiresArg: false,
|
|
37
|
+
type: 'string',
|
|
38
|
+
describe: 'Name of the template that will be used to scaffold the component. Can be configured in the cli.config.',
|
|
39
|
+
})
|
|
40
|
+
.option('byoc', {
|
|
41
|
+
requiresArg: false,
|
|
42
|
+
type: 'boolean',
|
|
43
|
+
describe: 'If true, scaffolds a byoc component.',
|
|
44
|
+
default: false,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Handler for the scaffold command.
|
|
49
|
+
* @param {ScaffoldArgs} argv - The arguments passed to the command.
|
|
50
|
+
*/
|
|
51
|
+
function handler(argv) {
|
|
52
|
+
var _a;
|
|
53
|
+
if (!argv.componentName) {
|
|
54
|
+
throw new Error('Component name is required. Usage: sitecore-tools scaffold <ComponentName>');
|
|
55
|
+
}
|
|
56
|
+
const nameParamFormat = new RegExp(/^((?:[\w\-]+\/)*)([A-Z][\w-]+)$/);
|
|
57
|
+
const regExResult = nameParamFormat.exec(argv.componentName);
|
|
58
|
+
if (regExResult === null) {
|
|
59
|
+
throw new Error(`Component name should start with an uppercase letter and contain only letters, numbers,
|
|
60
|
+
dashes, or underscores. It can also contain slashes to indicate a subfolder`);
|
|
61
|
+
}
|
|
62
|
+
const cliConfig = (0, load_config_1.default)(argv.config);
|
|
63
|
+
const componentPath = regExResult[1];
|
|
64
|
+
const componentName = regExResult[2];
|
|
65
|
+
const outputFolder = componentPath || 'src/components';
|
|
66
|
+
const templateName = (_a = argv.templateName) !== null && _a !== void 0 ? _a : (argv.byoc ? config_1.ComponentTemplateType.BYOC : config_1.ComponentTemplateType.DEFAULT);
|
|
67
|
+
(0, tools_1.scaffoldComponent)(outputFolder, componentName, templateName, cliConfig.scaffold.templates);
|
|
68
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
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.default = loadCliConfig;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const fs_1 = __importDefault(require("fs"));
|
|
9
|
+
const process_env_1 = __importDefault(require("./process-env"));
|
|
10
|
+
const tsx = require('tsx/cjs/api');
|
|
11
|
+
/**
|
|
12
|
+
* Loads Sitecore Content SDK CLI configuration from the specified file.
|
|
13
|
+
* @param {string} [configFile] - The path to the configuration file.
|
|
14
|
+
* @returns {SitecoreCliConfig} The default export from the configuration file.
|
|
15
|
+
* @throws Will throw an error if the configuration file does not exist or does not have a default export.
|
|
16
|
+
*/
|
|
17
|
+
function loadCliConfig(configFile) {
|
|
18
|
+
// If no config file is provided, try to load the default config file.
|
|
19
|
+
if (!configFile) {
|
|
20
|
+
configFile = './sitecore.cli.config.ts';
|
|
21
|
+
if (!fs_1.default.existsSync(path_1.default.resolve(process.cwd(), configFile))) {
|
|
22
|
+
configFile = './sitecore.cli.config.js';
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
// configuration file/filepath has been provided
|
|
27
|
+
// the env variables have been already loaded from the current working directory, however the current command may be running outside of a context of a project
|
|
28
|
+
// if so try loading the env vars from the directory of the provided config file
|
|
29
|
+
const configFileDirectory = path_1.default.dirname(path_1.default.resolve(process.cwd(), configFile));
|
|
30
|
+
if (process.cwd() !== configFileDirectory) {
|
|
31
|
+
(0, process_env_1.default)(configFileDirectory);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
let cliConfig;
|
|
35
|
+
try {
|
|
36
|
+
cliConfig = tsx.require(path_1.default.resolve(process.cwd(), configFile), __filename);
|
|
37
|
+
}
|
|
38
|
+
catch (e) {
|
|
39
|
+
throw `Error while trying to load the cli configuration from ${configFile}. Error message: ${e.message}`;
|
|
40
|
+
}
|
|
41
|
+
return cliConfig.default;
|
|
42
|
+
}
|
package/dist/esm/cli.js
CHANGED
|
@@ -24,7 +24,7 @@ process.on('unhandledRejection', (err) => {
|
|
|
24
24
|
export default function cli(commands) {
|
|
25
25
|
return __awaiter(this, void 0, void 0, function* () {
|
|
26
26
|
let appCommands = yargs.usage('$0 <command>');
|
|
27
|
-
appCommands = appCommands.scriptName('
|
|
27
|
+
appCommands = appCommands.scriptName('sitecore-tools');
|
|
28
28
|
// Register commands if available
|
|
29
29
|
if (commands && Object.keys(commands).length > 0) {
|
|
30
30
|
for (const cmd of Object.keys(commands)) {
|
|
@@ -0,0 +1,33 @@
|
|
|
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 loadCliConfig from '../utils/load-config';
|
|
11
|
+
export const command = 'build';
|
|
12
|
+
export const describe = 'Handles build time automation';
|
|
13
|
+
export const builder = {
|
|
14
|
+
config: {
|
|
15
|
+
requiresArg: false,
|
|
16
|
+
type: 'string',
|
|
17
|
+
describe: 'Path to the `sitecore.cli.config` file. Supports both JavaScript (`.js`) and TypeScript (`.ts`) formats.',
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Handler for the build command.
|
|
22
|
+
* @param {BuildArgs} argv - The arguments passed to the command.
|
|
23
|
+
*/
|
|
24
|
+
export function handler(argv) {
|
|
25
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
const cliConfig = loadCliConfig(argv.config);
|
|
27
|
+
if (cliConfig.build && Array.isArray(cliConfig.build.commands)) {
|
|
28
|
+
for (const command of cliConfig.build.commands) {
|
|
29
|
+
yield command();
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { scaffoldComponent } from '@sitecore-content-sdk/core/tools';
|
|
2
|
+
import loadCliConfig from '../utils/load-config';
|
|
3
|
+
import { ComponentTemplateType } from '@sitecore-content-sdk/core/config';
|
|
4
|
+
/**
|
|
5
|
+
* @param {Argv} yargs
|
|
6
|
+
*/
|
|
7
|
+
export function builder(yargs) {
|
|
8
|
+
return yargs.command('scaffold <componentName>', 'Scaffolds a new component. Use `sitecore-tools scaffold --help` for available options.', args, handler);
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* @param {Argv} yargs
|
|
12
|
+
*/
|
|
13
|
+
export function args(yargs) {
|
|
14
|
+
return yargs
|
|
15
|
+
.positional('componentName', {
|
|
16
|
+
requiresArg: true,
|
|
17
|
+
positional: true,
|
|
18
|
+
type: 'string',
|
|
19
|
+
describe: `Name of the component to scaffold. Component name should start with an uppercase letter and contain only letters, numbers,
|
|
20
|
+
dashes, or underscores. It can also contain slashes to indicate a subfolder. Example: MyComponent or MyFolder/MyComponent. If no subfolder is specified, the component will be created under 'src/components'.`,
|
|
21
|
+
})
|
|
22
|
+
.option('config', {
|
|
23
|
+
requiresArg: false,
|
|
24
|
+
type: 'string',
|
|
25
|
+
describe: 'Path to the `sitecore.cli.config` file. Supports both JavaScript (`.js`) and TypeScript (`.ts`) formats',
|
|
26
|
+
})
|
|
27
|
+
.option('templateName', {
|
|
28
|
+
requiresArg: false,
|
|
29
|
+
type: 'string',
|
|
30
|
+
describe: 'Name of the template that will be used to scaffold the component. Can be configured in the cli.config.',
|
|
31
|
+
})
|
|
32
|
+
.option('byoc', {
|
|
33
|
+
requiresArg: false,
|
|
34
|
+
type: 'boolean',
|
|
35
|
+
describe: 'If true, scaffolds a byoc component.',
|
|
36
|
+
default: false,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Handler for the scaffold command.
|
|
41
|
+
* @param {ScaffoldArgs} argv - The arguments passed to the command.
|
|
42
|
+
*/
|
|
43
|
+
export function handler(argv) {
|
|
44
|
+
var _a;
|
|
45
|
+
if (!argv.componentName) {
|
|
46
|
+
throw new Error('Component name is required. Usage: sitecore-tools scaffold <ComponentName>');
|
|
47
|
+
}
|
|
48
|
+
const nameParamFormat = new RegExp(/^((?:[\w\-]+\/)*)([A-Z][\w-]+)$/);
|
|
49
|
+
const regExResult = nameParamFormat.exec(argv.componentName);
|
|
50
|
+
if (regExResult === null) {
|
|
51
|
+
throw new Error(`Component name should start with an uppercase letter and contain only letters, numbers,
|
|
52
|
+
dashes, or underscores. It can also contain slashes to indicate a subfolder`);
|
|
53
|
+
}
|
|
54
|
+
const cliConfig = loadCliConfig(argv.config);
|
|
55
|
+
const componentPath = regExResult[1];
|
|
56
|
+
const componentName = regExResult[2];
|
|
57
|
+
const outputFolder = componentPath || 'src/components';
|
|
58
|
+
const templateName = (_a = argv.templateName) !== null && _a !== void 0 ? _a : (argv.byoc ? ComponentTemplateType.BYOC : ComponentTemplateType.DEFAULT);
|
|
59
|
+
scaffoldComponent(outputFolder, componentName, templateName, cliConfig.scaffold.templates);
|
|
60
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import processEnv from './process-env';
|
|
4
|
+
const tsx = require('tsx/cjs/api');
|
|
5
|
+
/**
|
|
6
|
+
* Loads Sitecore Content SDK CLI configuration from the specified file.
|
|
7
|
+
* @param {string} [configFile] - The path to the configuration file.
|
|
8
|
+
* @returns {SitecoreCliConfig} The default export from the configuration file.
|
|
9
|
+
* @throws Will throw an error if the configuration file does not exist or does not have a default export.
|
|
10
|
+
*/
|
|
11
|
+
export default function loadCliConfig(configFile) {
|
|
12
|
+
// If no config file is provided, try to load the default config file.
|
|
13
|
+
if (!configFile) {
|
|
14
|
+
configFile = './sitecore.cli.config.ts';
|
|
15
|
+
if (!fs.existsSync(path.resolve(process.cwd(), configFile))) {
|
|
16
|
+
configFile = './sitecore.cli.config.js';
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
// configuration file/filepath has been provided
|
|
21
|
+
// the env variables have been already loaded from the current working directory, however the current command may be running outside of a context of a project
|
|
22
|
+
// if so try loading the env vars from the directory of the provided config file
|
|
23
|
+
const configFileDirectory = path.dirname(path.resolve(process.cwd(), configFile));
|
|
24
|
+
if (process.cwd() !== configFileDirectory) {
|
|
25
|
+
processEnv(configFileDirectory);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
let cliConfig;
|
|
29
|
+
try {
|
|
30
|
+
cliConfig = tsx.require(path.resolve(process.cwd(), configFile), __filename);
|
|
31
|
+
}
|
|
32
|
+
catch (e) {
|
|
33
|
+
throw `Error while trying to load the cli configuration from ${configFile}. Error message: ${e.message}`;
|
|
34
|
+
}
|
|
35
|
+
return cliConfig.default;
|
|
36
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sitecore-content-sdk/cli",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.40",
|
|
4
4
|
"description": "Sitecore JSS command-line",
|
|
5
5
|
"main": "dist/cjs/cli.js",
|
|
6
6
|
"module": "dist/esm/cli.js",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"build": "npm run clean && tsc -p tsconfig.json && tsc -p tsconfig-esm.json",
|
|
14
14
|
"clean": "del-cli dist types",
|
|
15
15
|
"lint": "eslint \"./src/**/*.ts\"",
|
|
16
|
-
"
|
|
16
|
+
"sitecore-tools": "node ./dist/cjs/bin/sitecore-tools.js",
|
|
17
17
|
"test": "mocha --require ts-node/register/transpile-only \"./src/**/*.test.ts\"",
|
|
18
18
|
"coverage": "nyc --require ts-node/register/transpile-only npm test"
|
|
19
19
|
},
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
},
|
|
23
23
|
"preferGlobal": true,
|
|
24
24
|
"bin": {
|
|
25
|
-
"
|
|
25
|
+
"sitecore-tools": "./dist/cjs/bin/sitecore-tools.js"
|
|
26
26
|
},
|
|
27
27
|
"author": {
|
|
28
28
|
"name": "Sitecore Corporation",
|
|
@@ -34,10 +34,12 @@
|
|
|
34
34
|
"url": "https://github.com/sitecore/jss/issues"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
+
"@sitecore-content-sdk/core": "0.1.0-beta.40",
|
|
37
38
|
"dotenv": "^16.4.7",
|
|
38
39
|
"dotenv-expand": "^12.0.1",
|
|
39
40
|
"resolve": "^1.22.10",
|
|
40
41
|
"tmp": "^0.2.3",
|
|
42
|
+
"tsx": "^4.19.3",
|
|
41
43
|
"yargs": "^17.7.2"
|
|
42
44
|
},
|
|
43
45
|
"devDependencies": {
|
|
@@ -54,11 +56,12 @@
|
|
|
54
56
|
"eslint": "^8.56.0",
|
|
55
57
|
"mocha": "^11.1.0",
|
|
56
58
|
"nyc": "^17.1.0",
|
|
59
|
+
"proxyquire": "^2.1.3",
|
|
57
60
|
"sinon": "^19.0.2",
|
|
58
61
|
"ts-node": "^10.9.1",
|
|
59
62
|
"typescript": "~5.7.3"
|
|
60
63
|
},
|
|
61
|
-
"gitHead": "
|
|
64
|
+
"gitHead": "90440a673c5d818a20218d8a0800bbd784caf924",
|
|
62
65
|
"files": [
|
|
63
66
|
"dist",
|
|
64
67
|
"types"
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export declare const command = "build";
|
|
2
|
+
export declare const describe = "Handles build time automation";
|
|
3
|
+
export declare const builder: {
|
|
4
|
+
config: {
|
|
5
|
+
requiresArg: boolean;
|
|
6
|
+
type: string;
|
|
7
|
+
describe: string;
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* The arguments for the build command.
|
|
12
|
+
*/
|
|
13
|
+
export type BuildArgs = {
|
|
14
|
+
/**
|
|
15
|
+
* Path to the `sitecore.cli.config` file.
|
|
16
|
+
* Supports both JavaScript (`.js`) and TypeScript (`.ts`) formats.
|
|
17
|
+
*/
|
|
18
|
+
config?: string;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Handler for the build command.
|
|
22
|
+
* @param {BuildArgs} argv - The arguments passed to the command.
|
|
23
|
+
*/
|
|
24
|
+
export declare function handler(argv: BuildArgs): Promise<void>;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { Argv } from 'yargs';
|
|
2
|
+
/**
|
|
3
|
+
* @param {Argv} yargs
|
|
4
|
+
*/
|
|
5
|
+
export declare function builder(yargs: Argv<ScaffoldArgs>): Argv<ScaffoldArgs>;
|
|
6
|
+
/**
|
|
7
|
+
* @param {Argv} yargs
|
|
8
|
+
*/
|
|
9
|
+
export declare function args(yargs: Argv<ScaffoldArgs>): Argv<import("yargs").Omit<import("yargs").Omit<import("yargs").Omit<import("yargs").Omit<ScaffoldArgs, "componentName"> & {
|
|
10
|
+
componentName: string | undefined;
|
|
11
|
+
}, "config"> & {
|
|
12
|
+
config: string | undefined;
|
|
13
|
+
}, "templateName"> & {
|
|
14
|
+
templateName: string | undefined;
|
|
15
|
+
}, "byoc"> & {
|
|
16
|
+
byoc: boolean;
|
|
17
|
+
}>;
|
|
18
|
+
/**
|
|
19
|
+
* Arguments for the scaffold command.
|
|
20
|
+
*/
|
|
21
|
+
export type ScaffoldArgs = {
|
|
22
|
+
/**
|
|
23
|
+
* The name of the component to be scaffolded.
|
|
24
|
+
*/
|
|
25
|
+
componentName: string;
|
|
26
|
+
/**
|
|
27
|
+
* Path to the `sitecore.cli.config` file.
|
|
28
|
+
* Supports both JavaScript (`.js`) and TypeScript (`.ts`) formats.
|
|
29
|
+
*/
|
|
30
|
+
config?: string;
|
|
31
|
+
/**
|
|
32
|
+
* The name of the template to use for scaffolding.
|
|
33
|
+
*/
|
|
34
|
+
templateName?: string;
|
|
35
|
+
/**
|
|
36
|
+
* Indicates whether to scaffold a BYOC type component.
|
|
37
|
+
*/
|
|
38
|
+
byoc?: boolean;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Handler for the scaffold command.
|
|
42
|
+
* @param {ScaffoldArgs} argv - The arguments passed to the command.
|
|
43
|
+
*/
|
|
44
|
+
export declare function handler(argv: ScaffoldArgs): void;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { SitecoreCliConfig } from '@sitecore-content-sdk/core/types/config';
|
|
2
|
+
/**
|
|
3
|
+
* Loads Sitecore Content SDK CLI configuration from the specified file.
|
|
4
|
+
* @param {string} [configFile] - The path to the configuration file.
|
|
5
|
+
* @returns {SitecoreCliConfig} The default export from the configuration file.
|
|
6
|
+
* @throws Will throw an error if the configuration file does not exist or does not have a default export.
|
|
7
|
+
*/
|
|
8
|
+
export default function loadCliConfig(configFile?: string): SitecoreCliConfig;
|
package/dist/cjs/bin/jss.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
"use strict";
|
|
3
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
-
};
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
const resolve_1 = __importDefault(require("resolve"));
|
|
8
|
-
const process_env_1 = __importDefault(require("../utils/process-env"));
|
|
9
|
-
/**
|
|
10
|
-
* Resolves and executes the locally installed version of the JSS CLI.
|
|
11
|
-
*/
|
|
12
|
-
(0, resolve_1.default)('@sitecore-content-sdk/cli', { basedir: process.cwd() }, (_, projectLocalCli) => {
|
|
13
|
-
// No error implies a projectLocalCli, which will load whatever
|
|
14
|
-
// version of jss-cli you have installed in a local package.json
|
|
15
|
-
const cli = require(projectLocalCli).default;
|
|
16
|
-
// Since we are in context of a project, load its environment variables
|
|
17
|
-
(0, process_env_1.default)(process.cwd());
|
|
18
|
-
cli();
|
|
19
|
-
});
|
|
File without changes
|