@sitecore-content-sdk/cli 1.0.0-canary.1 → 1.0.0-canary.10

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.
@@ -63,5 +63,15 @@ const commands = __importStar(require("../scripts"));
63
63
  // if the current working directory is not an app project root .env file will be missing and nothing will be loaded
64
64
  // in that case loading environment variables will be handled by the actual cli command
65
65
  (0, process_env_1.default)(process.cwd());
66
+ // Re-enable debug logging after environment variables are loaded
67
+ // This ensures that DEBUG environment variables from .env files take effect
68
+ if (process.env.DEBUG) {
69
+ const debugScopes = process.env.DEBUG.split(',')
70
+ .map((scope) => scope.trim())
71
+ .filter(Boolean);
72
+ console.log(`Debug enabled for scopes: [${debugScopes.join(', ')}]`);
73
+ const debug = require('debug');
74
+ debug.enable(process.env.DEBUG);
75
+ }
66
76
  cli(commands);
67
77
  });
@@ -0,0 +1,54 @@
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 } = 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, { paths, destination, componentImports, exclude }));
49
+ }
50
+ else {
51
+ console.log(`Generating component map for:\n ${paths.join('\n')}`);
52
+ componentMapGenerator({ paths, destination, componentImports, exclude });
53
+ }
54
+ }
@@ -35,6 +35,7 @@ var __importStar = (this && this.__importStar) || (function () {
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.builder = builder;
37
37
  const scaffold = __importStar(require("./scaffold"));
38
+ const generateMap = __importStar(require("./generate-map"));
38
39
  /**
39
40
  * @param {Argv} yargs
40
41
  */
@@ -44,10 +45,11 @@ function builder(yargs) {
44
45
  describe: 'Performs component level operations',
45
46
  builder: (_yargs) => {
46
47
  _yargs = _yargs
47
- .command([scaffold])
48
+ .command([scaffold, generateMap])
48
49
  .strict()
49
50
  .demandCommand(1, 'You need to specify a command to run');
50
51
  _yargs = scaffold.builder(_yargs);
52
+ _yargs = generateMap.builder(_yargs);
51
53
  return _yargs;
52
54
  },
53
55
  handler: () => { },
@@ -0,0 +1,18 @@
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.watchItems = watchItems;
7
+ const chokidar_1 = __importDefault(require("chokidar"));
8
+ /**
9
+ * Run watch mode, watching on @var paths
10
+ * @param {string[]} paths paths to watch by chokidar
11
+ * @param {Function<void>} cb callback to run on file change
12
+ */
13
+ function watchItems(paths, cb) {
14
+ chokidar_1.default
15
+ .watch(paths, { ignoreInitial: true, awaitWriteFinish: true })
16
+ .on('add', cb)
17
+ .on('unlink', cb);
18
+ }
@@ -0,0 +1,46 @@
1
+ import { watchItems } from '../../../utils/watch-items';
2
+ import loadCliConfig from '../../../utils/load-config';
3
+ /**
4
+ * @param {Argv} yargs
5
+ */
6
+ export function builder(yargs) {
7
+ return yargs.command('generate-map', 'Generates component map based on provided paths', args, handler);
8
+ }
9
+ /**
10
+ * @param {Argv} yargs
11
+ */
12
+ export function args(yargs) {
13
+ return yargs
14
+ .option('watch', {
15
+ requiresArg: false,
16
+ type: 'boolean',
17
+ describe: 'If true, watches for changes in the specified paths and updates the component map accordingly.',
18
+ default: false,
19
+ })
20
+ .option('config', {
21
+ requiresArg: false,
22
+ type: 'string',
23
+ describe: 'Path to the `sitecore.cli.config` file. Supports both JavaScript (`.js`) and TypeScript (`.ts`) formats',
24
+ });
25
+ }
26
+ /**
27
+ * Handler for the `generate-map` command.
28
+ * @param {GenerateMapCliArgs} argv Cli arguments for the command
29
+ */
30
+ export function handler(argv) {
31
+ const cliConfig = loadCliConfig(argv.config);
32
+ if (!cliConfig.componentMap) {
33
+ console.error('The `sitecore.cli.config` file is missing a `componentMap` configuration. Please add it to use this command.');
34
+ return;
35
+ }
36
+ const componentMapGenerator = cliConfig.componentMap.generator;
37
+ const { paths, destination, componentImports, exclude } = cliConfig.componentMap;
38
+ if (argv.watch) {
39
+ console.log(`Watching for component changes to component builder sources in:\n ${paths.join('\n')}`);
40
+ watchItems(paths, componentMapGenerator.bind(null, { paths, destination, componentImports, exclude }));
41
+ }
42
+ else {
43
+ console.log(`Generating component map for:\n ${paths.join('\n')}`);
44
+ componentMapGenerator({ paths, destination, componentImports, exclude });
45
+ }
46
+ }
@@ -1,4 +1,5 @@
1
1
  import * as scaffold from './scaffold';
2
+ import * as generateMap from './generate-map';
2
3
  /**
3
4
  * @param {Argv} yargs
4
5
  */
@@ -8,10 +9,11 @@ export function builder(yargs) {
8
9
  describe: 'Performs component level operations',
9
10
  builder: (_yargs) => {
10
11
  _yargs = _yargs
11
- .command([scaffold])
12
+ .command([scaffold, generateMap])
12
13
  .strict()
13
14
  .demandCommand(1, 'You need to specify a command to run');
14
15
  _yargs = scaffold.builder(_yargs);
16
+ _yargs = generateMap.builder(_yargs);
15
17
  return _yargs;
16
18
  },
17
19
  handler: () => { },
@@ -0,0 +1,12 @@
1
+ import chokidar from 'chokidar';
2
+ /**
3
+ * Run watch mode, watching on @var paths
4
+ * @param {string[]} paths paths to watch by chokidar
5
+ * @param {Function<void>} cb callback to run on file change
6
+ */
7
+ export function watchItems(paths, cb) {
8
+ chokidar
9
+ .watch(paths, { ignoreInitial: true, awaitWriteFinish: true })
10
+ .on('add', cb)
11
+ .on('unlink', cb);
12
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sitecore-content-sdk/cli",
3
- "version": "1.0.0-canary.1",
3
+ "version": "1.0.0-canary.10",
4
4
  "description": "Sitecore Content SDK CLI",
5
5
  "main": "dist/cjs/cli.js",
6
6
  "module": "dist/esm/cli.js",
@@ -34,7 +34,8 @@
34
34
  "url": "https://github.com/sitecore/content-sdk/issues"
35
35
  },
36
36
  "dependencies": {
37
- "@sitecore-content-sdk/core": "1.0.0-canary.1",
37
+ "@sitecore-content-sdk/core": "1.0.0-canary.10",
38
+ "chokidar": "^4.0.3",
38
39
  "dotenv": "^16.5.0",
39
40
  "dotenv-expand": "^12.0.2",
40
41
  "resolve": "^1.22.10",
@@ -60,7 +61,7 @@
60
61
  "ts-node": "^10.9.1",
61
62
  "typescript": "~5.8.3"
62
63
  },
63
- "gitHead": "5344d67a03260a187e0db155ff8316a4118569f3",
64
+ "gitHead": "518a65de8c22a059ad4df5e46e2c00839eb2fc2e",
64
65
  "files": [
65
66
  "dist",
66
67
  "types"
@@ -0,0 +1,32 @@
1
+ import { Argv } from 'yargs';
2
+ /**
3
+ * @param {Argv} yargs
4
+ */
5
+ export declare function builder(yargs: Argv<GenerateMapCliArgs>): Argv<GenerateMapCliArgs>;
6
+ /**
7
+ * The arguments for the build command.
8
+ */
9
+ export type GenerateMapCliArgs = {
10
+ /**
11
+ * If true, watches for changes in the specified paths and updates the component map accordingly.
12
+ */
13
+ watch?: boolean;
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
+ * @param {Argv} yargs
22
+ */
23
+ export declare function args(yargs: Argv<GenerateMapCliArgs>): Argv<import("yargs").Omit<import("yargs").Omit<GenerateMapCliArgs, "watch"> & {
24
+ watch: boolean;
25
+ }, "config"> & {
26
+ config: string | undefined;
27
+ }>;
28
+ /**
29
+ * Handler for the `generate-map` command.
30
+ * @param {GenerateMapCliArgs} argv Cli arguments for the command
31
+ */
32
+ export declare function handler(argv: GenerateMapCliArgs): void;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Run watch mode, watching on @var paths
3
+ * @param {string[]} paths paths to watch by chokidar
4
+ * @param {Function<void>} cb callback to run on file change
5
+ */
6
+ export declare function watchItems(paths: string[], cb: () => void): void;