@digital-herd/content-hub-cli 1.0.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 (84) hide show
  1. package/README.md +269 -0
  2. package/lib/bin.d.ts +2 -0
  3. package/lib/bin.js +2 -0
  4. package/lib/config/tempDirectory.d.ts +2 -0
  5. package/lib/config/tempDirectory.js +1 -0
  6. package/lib/index.d.ts +3 -0
  7. package/lib/index.js +1 -0
  8. package/lib/modules/external-components/commands/buildExternalComponent.d.ts +2 -0
  9. package/lib/modules/external-components/commands/buildExternalComponent.js +1 -0
  10. package/lib/modules/external-components/commands/createComponent.d.ts +2 -0
  11. package/lib/modules/external-components/commands/createComponent.js +1 -0
  12. package/lib/modules/external-components/commands/watchExternalComponent.d.ts +2 -0
  13. package/lib/modules/external-components/commands/watchExternalComponent.js +1 -0
  14. package/lib/modules/external-components/index.d.ts +4 -0
  15. package/lib/modules/external-components/index.js +1 -0
  16. package/lib/modules/external-components/services/CreateComponentService.d.ts +17 -0
  17. package/lib/modules/external-components/services/CreateComponentService.js +1 -0
  18. package/lib/modules/external-components/services/ExternalComponentBuildService.d.ts +10 -0
  19. package/lib/modules/external-components/services/ExternalComponentBuildService.js +1 -0
  20. package/lib/modules/external-components/services/ExternalComponentPublishService.d.ts +13 -0
  21. package/lib/modules/external-components/services/ExternalComponentPublishService.js +1 -0
  22. package/lib/modules/external-components/services/ExternalComponentWatchService.d.ts +18 -0
  23. package/lib/modules/external-components/services/ExternalComponentWatchService.js +2 -0
  24. package/lib/modules/external-components/services/TypeCheckService.d.ts +9 -0
  25. package/lib/modules/external-components/services/TypeCheckService.js +1 -0
  26. package/lib/modules/index.d.ts +4 -0
  27. package/lib/modules/index.js +1 -0
  28. package/lib/modules/scripts/commands/CreateScriptCommand.d.ts +2 -0
  29. package/lib/modules/scripts/commands/CreateScriptCommand.js +4 -0
  30. package/lib/modules/scripts/commands/PublishScriptCommand.d.ts +2 -0
  31. package/lib/modules/scripts/commands/PublishScriptCommand.js +1 -0
  32. package/lib/modules/scripts/commands/SyncScriptsFromEnvironmentCommand.d.ts +2 -0
  33. package/lib/modules/scripts/commands/SyncScriptsFromEnvironmentCommand.js +1 -0
  34. package/lib/modules/scripts/errors/ScriptCompileError.d.ts +8 -0
  35. package/lib/modules/scripts/errors/ScriptCompileError.js +1 -0
  36. package/lib/modules/scripts/index.d.ts +4 -0
  37. package/lib/modules/scripts/index.js +1 -0
  38. package/lib/modules/scripts/services/CreateScriptService.d.ts +18 -0
  39. package/lib/modules/scripts/services/CreateScriptService.js +10 -0
  40. package/lib/modules/scripts/services/PublishScriptService.d.ts +15 -0
  41. package/lib/modules/scripts/services/PublishScriptService.js +1 -0
  42. package/lib/modules/scripts/services/SyncScriptService.d.ts +15 -0
  43. package/lib/modules/scripts/services/SyncScriptService.js +1 -0
  44. package/lib/modules/scripts/utils/script.d.ts +3 -0
  45. package/lib/modules/scripts/utils/script.js +1 -0
  46. package/lib/modules/setup/commands/createComponentAssetMapping.d.ts +2 -0
  47. package/lib/modules/setup/commands/createComponentAssetMapping.js +1 -0
  48. package/lib/modules/setup/commands/fetchAllAssetsNotTracked.d.ts +2 -0
  49. package/lib/modules/setup/commands/fetchAllAssetsNotTracked.js +1 -0
  50. package/lib/modules/setup/commands/fetchAssetPagesFromMap.d.ts +2 -0
  51. package/lib/modules/setup/commands/fetchAssetPagesFromMap.js +1 -0
  52. package/lib/modules/setup/commands/syncComponentConfig.d.ts +2 -0
  53. package/lib/modules/setup/commands/syncComponentConfig.js +1 -0
  54. package/lib/modules/setup/index.d.ts +4 -0
  55. package/lib/modules/setup/index.js +1 -0
  56. package/lib/modules/setup/services/ExternalComponentConfigService.d.ts +13 -0
  57. package/lib/modules/setup/services/ExternalComponentConfigService.js +6 -0
  58. package/lib/modules/setup/utils/moveComponent.d.ts +1 -0
  59. package/lib/modules/setup/utils/moveComponent.js +1 -0
  60. package/lib/services/ContenthubService.d.ts +9 -0
  61. package/lib/services/ContenthubService.js +1 -0
  62. package/lib/services/FileService.d.ts +19 -0
  63. package/lib/services/FileService.js +10 -0
  64. package/lib/types/ContentHubConfig.interface.d.ts +16 -0
  65. package/lib/types/ContentHubConfig.interface.js +1 -0
  66. package/lib/types/ExternalComponentConfig.interface.d.ts +7 -0
  67. package/lib/types/ExternalComponentConfig.interface.js +1 -0
  68. package/lib/types/ScriptConfig.interface.d.ts +8 -0
  69. package/lib/types/ScriptConfig.interface.js +1 -0
  70. package/lib/utils/apiCatch.d.ts +2 -0
  71. package/lib/utils/apiCatch.js +1 -0
  72. package/lib/utils/array.d.ts +1 -0
  73. package/lib/utils/array.js +1 -0
  74. package/lib/utils/getCliConfig.d.ts +2 -0
  75. package/lib/utils/getCliConfig.js +1 -0
  76. package/lib/utils/globalCommandConfig.d.ts +8 -0
  77. package/lib/utils/globalCommandConfig.js +1 -0
  78. package/lib/utils/hash.d.ts +1 -0
  79. package/lib/utils/hash.js +1 -0
  80. package/lib/utils/logger.d.ts +4 -0
  81. package/lib/utils/logger.js +1 -0
  82. package/lib/utils/number.d.ts +1 -0
  83. package/lib/utils/number.js +1 -0
  84. package/package.json +48 -0
package/README.md ADDED
@@ -0,0 +1,269 @@
1
+ # ContentHub CLI (content-hub-tools)
2
+
3
+ > ContentHub build & utility CLI used to build, watch and manage external components and scripts.
4
+
5
+ ## Quick Reference
6
+
7
+ | Command | Description |
8
+ |---------|-------------|
9
+ | `create-component` | Create a new React component from template |
10
+ | `create-script` | Create a new C# script with API auto-fetch |
11
+ | `build` | Build external components for production |
12
+ | `watch` | Watch and serve components with HMR |
13
+ | `publish-script` | Publish scripts to ContentHub environment |
14
+ | `sync-scripts` | Sync scripts from ContentHub to local |
15
+
16
+ **Jump to:**
17
+ - [Installation](#install)
18
+ - [Configuration](#config-file)
19
+ - [All Commands](#commands)
20
+ - [Examples](#commands)
21
+
22
+ ## Install
23
+
24
+ - From source (recommended during development):
25
+
26
+ ```bash
27
+ cd contenthub-cli
28
+ npm install
29
+ npm run build
30
+ # make the CLI available locally
31
+ npm link
32
+ ```
33
+
34
+
35
+ After installation the binary is `content-hub-tools`.
36
+
37
+ ## Config file
38
+
39
+ The CLI loads its configuration from `contenthubConfig.build.config.ts` by default. Example shape:
40
+
41
+ ```ts
42
+ export default {
43
+ componentDir: "external-components/components",
44
+ scriptDir: "scripts",
45
+ port: 5173,
46
+ mainEnvironment: "local",
47
+ environments: [
48
+ { name: "local", domain: "https://localhost", apiToken: "<token>" },
49
+ { name: "staging", domain: "https://staging.example.com", apiToken: "<token>" }
50
+ ]
51
+ };
52
+ ```
53
+
54
+ If your config lives in a different path, set `NODE_ENV` or adjust imports when invoking programmatically or update the `getCliConfig` call.
55
+
56
+ ## Global options
57
+
58
+ - `-e, --environment <environment>`: select which environment (name) from the config to use. If omitted the `mainEnvironment` from the config is used.
59
+
60
+ ## Commands
61
+
62
+ All commands are exposed via the `content-hub-tools` binary. Usage:
63
+
64
+ ```bash
65
+ content-hub-tools <command> [options]
66
+ ```
67
+
68
+ - **create-component** — Create a new external component from template (interactive)
69
+
70
+ This command will interactively prompt you to:
71
+ 1. Select which section (folder) to create the component in
72
+ 2. Enter a component name (must start with uppercase and contain only letters/numbers)
73
+
74
+ The command copies the template from `contenthub-cli/templates/external-components/` and creates the new component with all template files renamed and updated with your component name.
75
+
76
+ Examples:
77
+
78
+ - Create a new component (interactive prompts):
79
+ ```bash
80
+ content-hub-tools create-component
81
+ ```
82
+
83
+ The interactive prompts will guide you through:
84
+ - **Section selection**: Choose from available sections (e.g., `asset`, `general`, `workflows/cgi`)
85
+ - **Component name**: Enter a PascalCase name (e.g., `ProductCard`, `MyNewWidget`)
86
+
87
+ After running, the component will be created at:
88
+ ```
89
+ external-components/components/<section>/<ComponentName>/
90
+ ```
91
+
92
+ - **create-script** — Create a new script from template (interactive)
93
+
94
+ This command will interactively prompt you to provide script details. If you provide an identifier that exists in the environment, it will automatically fetch the default values (title, description, execute as user) from the API.
95
+
96
+ Examples:
97
+
98
+ - Create a new script (interactive prompts):
99
+ ```bash
100
+ content-hub-tools create-script -e local
101
+ ```
102
+
103
+ The interactive prompts will guide you through:
104
+ 1. **Identifier**: Script identifier (e.g., `M.Script.MyNewScript`)
105
+ 2. **Auto-fetch**: If the identifier exists in the environment, defaults will be fetched
106
+ 3. **Title**: Script title (pre-filled if fetched from API)
107
+ 4. **Description**: Script description (pre-filled if fetched from API)
108
+ 5. **Type**: Script type (Action or Trigger)
109
+ 6. **Execute as user**: Whether to execute as user (pre-filled if fetched from API)
110
+
111
+ After running, the script will be created at:
112
+ ```
113
+ action-scripts/scripts/<ScriptName>/
114
+ ```
115
+
116
+ Files created:
117
+ - `<ScriptName>.config.ts` - Script configuration with metadata
118
+ - `<ScriptName>.cs` - C# script implementation file
119
+
120
+ - **build** — Build External component(s)
121
+
122
+ Options:
123
+ - `-c, --components <comp>`: comma-separated component names to build. If omitted, builds all components.
124
+ - `-d, --deprecated`: build using `tsconfig.deprecated.json` (TypeScript strict mode disabled) instead of the default `tsconfig.json`.
125
+ - `-p, --publish`: after building, publish the built components to the configured ContentHub environment portal asset.
126
+
127
+ Examples:
128
+
129
+ - Build all components using default tsconfig:
130
+ ```bash
131
+ content-hub-tools build -e local
132
+ ```
133
+
134
+ - Build all components using mainEnvironment from config:
135
+ ```bash
136
+ content-hub-tools build
137
+ ```
138
+
139
+ - Build a single component:
140
+ ```bash
141
+ content-hub-tools build -c "ProductCard" -e local
142
+ ```
143
+
144
+ - Build multiple specific components:
145
+ ```bash
146
+ content-hub-tools build -c "Button,Card,Header" -e staging
147
+ ```
148
+
149
+ - Build and publish to production:
150
+ ```bash
151
+ content-hub-tools build -c "Button,Card" -p -e production
152
+ ```
153
+
154
+ - Build all components and publish:
155
+ ```bash
156
+ content-hub-tools build -p -e staging
157
+ ```
158
+
159
+ - Build using deprecated TS config (compatibility mode):
160
+ ```bash
161
+ content-hub-tools build -d -e local
162
+ ```
163
+
164
+ - Build specific components with deprecated config and publish:
165
+ ```bash
166
+ content-hub-tools build -c "LegacyComponent" -d -p -e staging
167
+ ```
168
+
169
+ - **watch** — Watch and serve External component(s) with HMR (development)
170
+
171
+ Options:
172
+ - `-c, --components <comp>`: comma-separated list of components to watch. If omitted, watches all components.
173
+ - `-d, --deprecated`: use `tsconfig.deprecated.json` (TypeScript strict mode disabled) while watching.
174
+
175
+ Examples:
176
+
177
+ - Watch all components with HMR:
178
+ ```bash
179
+ content-hub-tools watch -e local
180
+ ```
181
+
182
+ - Watch all components using mainEnvironment:
183
+ ```bash
184
+ content-hub-tools watch
185
+ ```
186
+
187
+ - Watch a single component for development:
188
+ ```bash
189
+ content-hub-tools watch -c "ProductCard" -e local
190
+ ```
191
+
192
+ - Watch multiple specific components:
193
+ ```bash
194
+ content-hub-tools watch -c "Button,Card,Header" -e local
195
+ ```
196
+
197
+ - Watch with deprecated tsconfig:
198
+ ```bash
199
+ content-hub-tools watch -d -e local
200
+ ```
201
+
202
+ - Watch specific components with deprecated config:
203
+ ```bash
204
+ content-hub-tools watch -c "LegacyComponent,OldCard" -d -e local
205
+ ```
206
+
207
+ - **publish-script** — Publish scripts to environment
208
+
209
+ Options:
210
+ - `-s, --scripts <script>`: comma-separated list of script names to publish (required).
211
+
212
+ Examples:
213
+
214
+ - Publish a single script:
215
+ ```bash
216
+ content-hub-tools publish-script -s "myScript" -e staging
217
+ ```
218
+
219
+ - Publish multiple scripts:
220
+ ```bash
221
+ content-hub-tools publish-script -s "myScript,anotherScript" -e staging
222
+ ```
223
+
224
+ - Publish to production environment:
225
+ ```bash
226
+ content-hub-tools publish-script -s "ProductionScript" -e production
227
+ ```
228
+
229
+ - Publish scripts using mainEnvironment:
230
+ ```bash
231
+ content-hub-tools publish-script -s "myScript,anotherScript"
232
+ ```
233
+
234
+ - **sync-scripts** — Sync scripts from environment to local
235
+
236
+ Examples:
237
+
238
+ - Sync scripts from staging environment:
239
+ ```bash
240
+ content-hub-tools sync-scripts -e staging
241
+ ```
242
+
243
+ - Sync scripts from production:
244
+ ```bash
245
+ content-hub-tools sync-scripts -e production
246
+ ```
247
+
248
+ - Sync using mainEnvironment from config:
249
+ ```bash
250
+ content-hub-tools sync-scripts
251
+ ```
252
+
253
+ - Sync from local development environment:
254
+ ```bash
255
+ content-hub-tools sync-scripts -e local
256
+ ```
257
+
258
+ ## Developer notes
259
+
260
+ - The CLI is implemented with `commander` and TypeScript. Entry point: `src/bin.ts`.
261
+ - Commands are registered from `src/modules/*` — see `src/modules/external-components` and `src/modules/scripts`.
262
+ - The CLI expects a config matching [src/types/ContentHubConfig.interface.ts](src/types/ContentHubConfig.interface.ts).
263
+ - The binary target is `dist/bin.js` as defined in `package.json`'s `bin` field.
264
+
265
+ ## Troubleshooting
266
+
267
+ - `❌ environment not specified -e or --environment`: either pass `-e <name>` or set `mainEnvironment` in the config.
268
+ - `❌ Failed to load config`: confirm `contenthubConfig.build.config.ts` path is correct and exports a default config.
269
+
package/lib/bin.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/lib/bin.js ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ var __importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0});let commander_1=require("commander"),modules_1=__importDefault(require("./modules")),program=new commander_1.Command;program.name("content-hub-tools").description("ContentHub build & utility CLI").version("1.0.0");for(let o of modules_1.default)for(let e of o.commands)program.addCommand(e);program.parse(process.argv);
@@ -0,0 +1,2 @@
1
+ export declare const GLOBAL_TEMP_DIRECTORY = ".contenthub-cli";
2
+ export declare const BUILD_DIRECTORY = ".contenthub-cli/dist";
@@ -0,0 +1 @@
1
+ Object.defineProperty(exports,"__esModule",{value:!0}),exports.BUILD_DIRECTORY=exports.GLOBAL_TEMP_DIRECTORY=void 0,exports.GLOBAL_TEMP_DIRECTORY=".contenthub-cli",exports.BUILD_DIRECTORY=".contenthub-cli/dist";
package/lib/index.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ export * from "./types/ContentHubConfig.interface.js";
2
+ export * from "./types/ExternalComponentConfig.interface.js";
3
+ export * from "./types/ScriptConfig.interface.js";
package/lib/index.js ADDED
@@ -0,0 +1 @@
1
+ var __createBinding=this&&this.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r);var i=Object.getOwnPropertyDescriptor(t,r);i&&("get"in i?t.__esModule:!i.writable&&!i.configurable)||(i={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,n,i)}:function(e,t,r,n){e[n=void 0===n?r:n]=t[r]}),__exportStar=this&&this.__exportStar||function(e,t){for(var r in e)"default"===r||Object.prototype.hasOwnProperty.call(t,r)||__createBinding(t,e,r)};Object.defineProperty(exports,"__esModule",{value:!0}),__exportStar(require("./types/ContentHubConfig.interface.js"),exports),__exportStar(require("./types/ExternalComponentConfig.interface.js"),exports),__exportStar(require("./types/ScriptConfig.interface.js"),exports);
@@ -0,0 +1,2 @@
1
+ import { Command } from "commander";
2
+ export declare const buildExternalComponentCommand: Command;
@@ -0,0 +1 @@
1
+ var __importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.buildExternalComponentCommand=void 0;let commander_1=require("commander"),globalCommandConfig_js_1=require("../../../utils/globalCommandConfig.js"),ExternalComponentBuildService_js_1=__importDefault(require("../services/ExternalComponentBuildService.js")),ExternalComponentPublishService_js_1=__importDefault(require("../services/ExternalComponentPublishService.js"));exports.buildExternalComponentCommand=(0,globalCommandConfig_js_1.setGlobalConfig)(new commander_1.Command("build")).option("-c, --components <comp>","component list to build").option("-d, --deprecated","build with deprecated tsconfig").option("-p, --publish","Deploy the compoonent to the environment").description("Build External component(s)").action(async e=>{process.env.NODE_ENV="production";var o,{config:n,contenthubService:t}=await(0,globalCommandConfig_js_1.globalCommandConfig)(e),i=e.deprecated?"tsconfig.deprecated.json":void 0,i=new ExternalComponentBuildService_js_1.default(n,i);let l=[];l=e.components?(o=e.components.split(",").map(e=>e.trim()),await i.build(o)):await i.buildAll(),e.publish&&await new ExternalComponentPublishService_js_1.default(t,n).publishToPortalAsset(l)});
@@ -0,0 +1,2 @@
1
+ import { Command } from "commander";
2
+ export declare const createComponentCommand: Command;
@@ -0,0 +1 @@
1
+ var __importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.createComponentCommand=void 0;let commander_1=require("commander"),prompts_1=require("@inquirer/prompts"),globalCommandConfig_js_1=require("../../../utils/globalCommandConfig.js"),CreateComponentService_js_1=__importDefault(require("../services/CreateComponentService.js")),logger_js_1=__importDefault(require("../../../utils/logger.js"));exports.createComponentCommand=new commander_1.Command("create-component").description("Create a new external component from template").action(async e=>{e=(await(0,globalCommandConfig_js_1.globalCommandConfig)(e)).config,e=new CreateComponentService_js_1.default(e);try{var t=e.getAvailableSections(),o=(0===t.length&&(logger_js_1.default.error("No sections found in components directory"),process.exit(1)),await(0,prompts_1.select)({message:"Select a section for the component:",choices:t.map(e=>({name:e,value:e}))})),n=await(0,prompts_1.input)({message:"Enter the component name (e.g., MyNewComponent):",validate:e=>e&&0!==e.trim().length?!!/^[A-Z][a-zA-Z0-9]*$/.test(e)||"Component name must start with uppercase letter and contain only letters and numbers":"Component name is required"});await e.createComponent(o,n.trim())}catch(e){e instanceof Error&&logger_js_1.default.error("Failed to create component: "+e.message),process.exit(1)}});
@@ -0,0 +1,2 @@
1
+ import { Command } from "commander";
2
+ export declare const watchExternalComponentCommand: Command;
@@ -0,0 +1 @@
1
+ var __importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.watchExternalComponentCommand=void 0;let commander_1=require("commander"),globalCommandConfig_js_1=require("../../../utils/globalCommandConfig.js"),ExternalComponentWatchService_js_1=__importDefault(require("../services/ExternalComponentWatchService.js"));exports.watchExternalComponentCommand=new commander_1.Command("watch").option("-c, --components <comp>","component list to watch (comma-separated)").option("-d, --deprecated","build with deprecated tsconfig").description("Watch and serve External component(s) with HMR").action(async e=>{process.env.NODE_ENV="development";var{config:t,contenthubService:o}=await(0,globalCommandConfig_js_1.globalCommandConfig)(e),n=e.deprecated?"tsconfig.deprecated.json":void 0,o=new ExternalComponentWatchService_js_1.default(o,t,n);e.components?(t=e.components.split(",").map(e=>e.trim()),await o.watchComponents(t)):await o.watchAll()});
@@ -0,0 +1,4 @@
1
+ declare const _default: {
2
+ commands: import("commander").Command[];
3
+ };
4
+ export default _default;
@@ -0,0 +1 @@
1
+ Object.defineProperty(exports,"__esModule",{value:!0});let buildExternalComponent_1=require("./commands/buildExternalComponent"),watchExternalComponent_1=require("./commands/watchExternalComponent"),createComponent_1=require("./commands/createComponent");exports.default={commands:[buildExternalComponent_1.buildExternalComponentCommand,watchExternalComponent_1.watchExternalComponentCommand,createComponent_1.createComponentCommand]};
@@ -0,0 +1,17 @@
1
+ import { ContenthubConfig } from "../../../types/ContentHubConfig.interface.js";
2
+ export default class CreateComponentService {
3
+ private config;
4
+ private templateDir;
5
+ private componentsDir;
6
+ private fileService;
7
+ constructor(config: ContenthubConfig);
8
+ /**
9
+ * Get available sections (subdirectories) in components folder
10
+ * Includes nested subdirectories for workflows (e.g., workflows/cgi, workflows/adaptation)
11
+ */
12
+ getAvailableSections(): string[];
13
+ /**
14
+ * Create a new component from template
15
+ */
16
+ createComponent(section: string, componentName: string): Promise<void>;
17
+ }
@@ -0,0 +1 @@
1
+ var __createBinding=this&&this.__createBinding||(Object.create?function(e,t,r,i){void 0===i&&(i=r);var o=Object.getOwnPropertyDescriptor(t,r);o&&("get"in o?t.__esModule:!o.writable&&!o.configurable)||(o={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,i,o)}:function(e,t,r,i){e[i=void 0===i?r:i]=t[r]}),__setModuleDefault=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),__importStar=this&&this.__importStar||(()=>{var o=function(e){return(o=Object.getOwnPropertyNames||function(e){var t,r=[];for(t in e)Object.prototype.hasOwnProperty.call(e,t)&&(r[r.length]=t);return r})(e)};return function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r=o(e),i=0;i<r.length;i++)"default"!==r[i]&&__createBinding(t,e,r[i]);return __setModuleDefault(t,e),t}})(),__importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0});let fs=__importStar(require("fs")),path=__importStar(require("path")),logger_js_1=__importDefault(require("../../../utils/logger.js")),FileService_js_1=__importDefault(require("../../../services/FileService.js"));class CreateComponentService{config;templateDir;componentsDir;fileService;constructor(e){this.config=e,this.templateDir=e.templates.externalComponent,this.componentsDir=path.resolve(process.cwd(),e.componentDir),this.fileService=new FileService_js_1.default(e)}getAvailableSections(){if(!fs.existsSync(this.componentsDir))return logger_js_1.default.error("Components directory not found: "+this.componentsDir),[];var e,t,r=[];for(e of fs.readdirSync(this.componentsDir,{withFileTypes:!0}).filter(e=>e.isDirectory()))"workflows"===e.name?(t=path.join(this.componentsDir,"workflows"),t=fs.readdirSync(t,{withFileTypes:!0}).filter(e=>e.isDirectory()).map(e=>"workflows/"+e.name),r.push(...t)):r.push(e.name);return r.sort()}async createComponent(e,t){if(this.fileService.getAllComponentNames().includes(t))throw new Error(t+" already exists.");if(!fs.existsSync(this.templateDir))throw new Error("Template directory not found: "+this.templateDir);var r=path.join(this.componentsDir,e);if(!fs.existsSync(r))throw new Error("Section directory not found: "+r);var i,o=path.join(r,t);if(fs.existsSync(o))throw new Error(`Component "${t}" already exists in section "${e}"`);logger_js_1.default.info(`📦 Creating component "${t}" in section "${e}"...`),fs.mkdirSync(o,{recursive:!0});for(i of fs.readdirSync(this.templateDir)){var n=path.join(this.templateDir,i),s=i.replace("<ComponentName>",t),a=path.join(o,s);let e=fs.readFileSync(n,"utf-8");"<ComponentName>.config.ts"!==i&&(e=(e=e.replace(/\$\$ComponentName/g,t)).replace(/\$\$componentName/g,t.toLowerCase())),fs.writeFileSync(a,e,"utf-8"),logger_js_1.default.info(" ✓ Created "+s)}logger_js_1.default.info(`✅ Component "${t}" created successfully!`),logger_js_1.default.info("📁 Location: "+path.relative(process.cwd(),o))}}exports.default=CreateComponentService;
@@ -0,0 +1,10 @@
1
+ import { ContenthubConfig } from "../../../types/ContentHubConfig.interface";
2
+ declare class ExternalComponentBuildService {
3
+ private fileService;
4
+ private typeCheck;
5
+ constructor(config: ContenthubConfig, tsconfigName?: string);
6
+ buildAll(): Promise<string[]>;
7
+ build(components: string | string[]): Promise<string[]>;
8
+ private getViteConfigs;
9
+ }
10
+ export default ExternalComponentBuildService;
@@ -0,0 +1 @@
1
+ var __importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0});let FileService_1=__importDefault(require("../../../services/FileService")),vite_1=require("vite"),path_1=__importDefault(require("path")),lodash_1=require("lodash"),array_1=require("../../../utils/array"),logger_1=__importDefault(require("../../..//utils/logger")),TypeCheckService_1=__importDefault(require("./TypeCheckService")),tempDirectory_1=require("../../../config/tempDirectory");class ExternalComponentBuildService{fileService;typeCheck;constructor(e,r){this.fileService=new FileService_1.default(e),this.typeCheck=new TypeCheckService_1.default(e,r)}async buildAll(){var e,r=this.fileService.getAllComponentNames(),i=await this.getViteConfigs(r),i=(await this.typeCheck.all(),(0,array_1.arrayToChunks)(i,5));for(e of i)await Promise.all(e.map(e=>(0,vite_1.build)(e)));return r}async build(e){e=Array.isArray(e)?e:[e];let r=this.fileService.getAllComponentNames();var i,t=e.filter(e=>!r.includes(e)),t=(t.length&&(logger_1.default.error(t.join(", ")+" components not found"),process.exit(-1)),await this.typeCheck.specificComponents(e),await this.getViteConfigs(e));for(i of(0,array_1.arrayToChunks)(t,5))await Promise.all(i.map(e=>(0,vite_1.build)(e)));return e}async getViteConfigs(e){var r=path_1.default.resolve(process.cwd(),"vite.config.js");let t=await(0,vite_1.loadConfigFromFile)({command:"build",mode:"production"},r);if(t)return e.map(e=>{var r=this.fileService.getEntryOfComponent(e),i=(0,lodash_1.cloneDeep)(t.config);return i.build.lib={formats:["es"],fileName:e,entry:r},i.build.outDir=tempDirectory_1.BUILD_DIRECTORY,i.mode="production",i});throw new Error("Vite config not found")}}exports.default=ExternalComponentBuildService;
@@ -0,0 +1,13 @@
1
+ import { ContenthubConfig } from "../../../types/ContentHubConfig.interface";
2
+ import ContenthubService from "../../../services/ContenthubService";
3
+ declare class ExternalComponentPublishService {
4
+ contenthubService: ContenthubService;
5
+ private fileService;
6
+ constructor(contenthubService: ContenthubService, config: ContenthubConfig);
7
+ publishToPortalAsset(components: string | string[]): Promise<void>;
8
+ publishToLocalPath(host: string, components: string | string[]): Promise<void>;
9
+ private updateExternalComponents;
10
+ private createOrUpdateAsset;
11
+ private getOrCreateAsset;
12
+ }
13
+ export default ExternalComponentPublishService;
@@ -0,0 +1 @@
1
+ var __createBinding=this&&this.__createBinding||(Object.create?function(e,t,n,i){void 0===i&&(i=n);var r=Object.getOwnPropertyDescriptor(t,n);r&&("get"in r?t.__esModule:!r.writable&&!r.configurable)||(r={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,i,r)}:function(e,t,n,i){e[i=void 0===i?n:i]=t[n]}),__setModuleDefault=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),__importStar=this&&this.__importStar||(()=>{var r=function(e){return(r=Object.getOwnPropertyNames||function(e){var t,n=[];for(t in e)Object.prototype.hasOwnProperty.call(e,t)&&(n[n.length]=t);return n})(e)};return function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n=r(e),i=0;i<n.length;i++)"default"!==n[i]&&__createBinding(t,e,n[i]);return __setModuleDefault(t,e),t}})(),__importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0});let sc_contenthub_webclient_sdk_1=require("@sitecore/sc-contenthub-webclient-sdk"),FileService_1=__importDefault(require("../../../services/FileService")),array_1=require("../../../utils/array"),apiCatch_1=require("../../../utils/apiCatch"),hash_1=require("../../../utils/hash"),logger_1=__importStar(require("../../../utils/logger")),lodash_1=require("lodash");class ExternalComponentPublishService{contenthubService;fileService;constructor(e,t){this.contenthubService=e,this.fileService=new FileService_1.default(t)}async publishToPortalAsset(e){var t;for(t of Array.isArray(e)?e:[e]){var n=this.fileService.getComponentConfig(t),i=this.fileService.getComponentBuild(t),i=await this.createOrUpdateAsset(t,i),n=await this.fileService.tsFileImport(n);await this.updateExternalComponents(t,n,{assetId:i.id}),logger_1.loggerSuccess.info(t+" Published")}}async publishToLocalPath(e,t){var n;for(n of Array.isArray(t)?t:[t]){var i=this.fileService.getComponentConfig(n),i=await this.fileService.tsFileImport(i),r=`${e}/${n}.js`;await this.updateExternalComponents(n,i,{path:r}),logger_1.loggerSuccess.info(`"${n}" Page component updated to local path`)}}async updateExternalComponents(e,n,{assetId:i,path:r}){var o=n.components.flatMap(e=>e.pageComponentIdentifiers),a=(logger_1.default.info(`Start updating ${o.length} External Page components`),await Promise.all((0,array_1.arrayToChunks)(o,50).map(e=>(0,apiCatch_1.apiErrorCatch)(()=>this.contenthubService.client.entities.getManyAsync(e,new sc_contenthub_webclient_sdk_1.EntityLoadConfiguration(sc_contenthub_webclient_sdk_1.CultureLoadOption.Default,new sc_contenthub_webclient_sdk_1.PropertyLoadOption("PageComponent.Settings"),new sc_contenthub_webclient_sdk_1.RelationLoadOption(["AssetToPageComponent"])))))).then(e=>e.flat()));for(let t of o){let e=a.find(e=>e.identifier===t);var s=n.components.find(e=>e.pageComponentIdentifiers.includes(t)),c=(e||(logger_1.default.error(`${t} was not found that was specified in the config of "${e}"`),process.exit(-1)),await e.getPropertyValue("PageComponent.Settings")),s={...c,config:s.config,path:r||void 0},c=((0,lodash_1.isEqual)(c,s)||e.setPropertyValue("PageComponent.Settings",s),e.getRelation("AssetToPageComponent"));i&&!c.getIds().includes(i)?c.setIds([i]):r&&c.setIds([]),e.isDirty&&await(0,apiCatch_1.apiErrorCatch)(()=>this.contenthubService.client.entities.saveAsync(e))}}async createOrUpdateAsset(e,t){var n=await this.getOrCreateAsset(e),i=n.getPropertyValue("Digest");if(i){var r=await(0,hash_1.sha1FromFile)(t);if(i.replace("0x","")===r)return logger_1.default.info(`"${e}" source code wasn't updated so skip.`),n}i=new sc_contenthub_webclient_sdk_1.LocalUploadSource("file://"+t);let o=new sc_contenthub_webclient_sdk_1.UploadRequest(i,"AssetUploadConfiguration","NewMainFile");return o.actionParameters={AssetId:n.id},await(0,apiCatch_1.apiErrorCatch)(()=>this.contenthubService.client.uploads.uploadAsync(o)),logger_1.default.info(`"${e}" source code uploaded to asset`),n}async getOrCreateAsset(t){var e=await this.contenthubService.getOrFetchId("M.Content.Repository.Portal");let n=new sc_contenthub_webclient_sdk_1.Query({filter:new sc_contenthub_webclient_sdk_1.CompositeQueryFilter({combineMethod:sc_contenthub_webclient_sdk_1.CompositeFilterOperator.And,children:[new sc_contenthub_webclient_sdk_1.DefinitionQueryFilter({name:"M.Asset",operator:sc_contenthub_webclient_sdk_1.ComparisonOperator.Equals}),new sc_contenthub_webclient_sdk_1.PropertyQueryFilter({property:"Title",dataType:sc_contenthub_webclient_sdk_1.FilterDataType.String,values:[t,t+".js"],operator:sc_contenthub_webclient_sdk_1.ComparisonOperator.Equals}),new sc_contenthub_webclient_sdk_1.RelationQueryFilter({relation:"ContentRepositoryToAsset",parentId:e})]}),take:1});var i=await(0,apiCatch_1.apiErrorCatch)(()=>this.contenthubService.client.querying.queryAsync(n,new sc_contenthub_webclient_sdk_1.EntityLoadConfiguration(sc_contenthub_webclient_sdk_1.CultureLoadOption.Default,new sc_contenthub_webclient_sdk_1.PropertyLoadOption(["FileName","Title","Digest"]),new sc_contenthub_webclient_sdk_1.RelationLoadOption(["AssetToPageComponent"]))));if(i.items.length){let e=i.items[0];return e.getPropertyValue("Title")!==t&&(e.setPropertyValue("Title",t),await(0,apiCatch_1.apiErrorCatch)(()=>this.contenthubService.client.entities.saveAsync(e))),e}let r=await this.contenthubService.client.entityFactory.createAsync("M.Asset");return r.setPropertyValue("Title",t),r.setPropertyValue("FileName",t+".js"),r.getRelation("ContentRepositoryToAsset")?.setIds([e]),r.id=await(0,apiCatch_1.apiErrorCatch)(()=>this.contenthubService.client.entities.saveAsync(r)),r}}exports.default=ExternalComponentPublishService;
@@ -0,0 +1,18 @@
1
+ import { ContenthubConfig } from "../../../types/ContentHubConfig.interface";
2
+ import ContenthubService from "@/services/ContenthubService";
3
+ declare class ExternalComponentWatchService {
4
+ config: ContenthubConfig;
5
+ private fileService;
6
+ private typeCheck;
7
+ private publishService;
8
+ private componentBuilds;
9
+ private componentWatchers;
10
+ constructor(contenthubService: ContenthubService, config: ContenthubConfig, tsconfigName?: string);
11
+ watchAll(): Promise<void>;
12
+ watchSingleComponent(component: string): Promise<void>;
13
+ private getOrCreateCertificate;
14
+ private setupFileWatcher;
15
+ watchComponents(components: string[], updateExternalComponentConfig?: boolean): Promise<void>;
16
+ private buildComponent;
17
+ }
18
+ export default ExternalComponentWatchService;
@@ -0,0 +1,2 @@
1
+ var __createBinding=this&&this.__createBinding||(Object.create?function(e,t,r,i){void 0===i&&(i=r);var o=Object.getOwnPropertyDescriptor(t,r);o&&("get"in o?t.__esModule:!o.writable&&!o.configurable)||(o={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,i,o)}:function(e,t,r,i){e[i=void 0===i?r:i]=t[r]}),__setModuleDefault=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),__importStar=this&&this.__importStar||(()=>{var o=function(e){return(o=Object.getOwnPropertyNames||function(e){var t,r=[];for(t in e)Object.prototype.hasOwnProperty.call(e,t)&&(r[r.length]=t);return r})(e)};return function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r=o(e),i=0;i<r.length;i++)"default"!==r[i]&&__createBinding(t,e,r[i]);return __setModuleDefault(t,e),t}})(),__importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0});let FileService_1=__importDefault(require("../../../services/FileService")),vite_1=require("vite"),path_1=__importDefault(require("path")),lodash_1=require("lodash"),fs_1=__importDefault(require("fs")),https_1=__importDefault(require("https")),connect_1=__importDefault(require("connect")),child_process_1=require("child_process"),util_1=require("util"),chokidar_1=require("chokidar"),logger_1=__importDefault(require("../../../utils/logger")),TypeCheckService_1=__importDefault(require("./TypeCheckService")),ExternalComponentPublishService_1=__importDefault(require("./ExternalComponentPublishService")),execPromise=(0,util_1.promisify)(child_process_1.exec);class ExternalComponentWatchService{config;fileService;typeCheck;publishService;componentBuilds=new Map;componentWatchers=new Map;constructor(e,t,r){this.config=t,this.fileService=new FileService_1.default(t),this.typeCheck=new TypeCheckService_1.default(t,r),this.publishService=new ExternalComponentPublishService_1.default(e,t)}async watchAll(){logger_1.default.info("In watch all mode, it does not update the external components to local path");var e=this.fileService.getAllComponentNames();await this.watchComponents(e,!1)}async watchSingleComponent(e){await this.watchComponents([e])}async getOrCreateCertificate(){var e=path_1.default.resolve(process.cwd(),".vite-certs"),t=path_1.default.join(e,"key.pem"),r=path_1.default.join(e,"cert.pem");if(fs_1.default.existsSync(t)&&fs_1.default.existsSync(r))return{key:fs_1.default.readFileSync(t,"utf-8"),cert:fs_1.default.readFileSync(r,"utf-8")};fs_1.default.existsSync(e)||fs_1.default.mkdirSync(e,{recursive:!0});e=`openssl req -x509 -newkey rsa:2048 -keyout "${t}" -out "${r}" -days 365 -nodes -subj "/CN=localhost"`;try{return await execPromise(e),{key:fs_1.default.readFileSync(t,"utf-8"),cert:fs_1.default.readFileSync(r,"utf-8")}}catch(e){throw logger_1.default.error("Failed to generate certificate:",e),new Error("Failed to generate self-signed certificate. Make sure OpenSSL is installed.")}}setupFileWatcher(e,t){var r;this.componentWatchers.has(e)||(r=this.fileService.getEntryOfComponent(e),r=path_1.default.dirname(r),(r=(0,chokidar_1.watch)(r,{ignored:/(node_modules|\.git|\.vite-cache)/,awaitWriteFinish:{stabilityThreshold:100,pollInterval:100}})).on("change",()=>{logger_1.default.info(`
2
+ 📝 File changed in ${e}, rebuilding`),this.componentBuilds.delete(e),this.buildComponent(e,t)}),this.componentWatchers.set(e,r))}async watchComponents(o,e=!0){let t=this.fileService.getAllComponentNames();var r=o.filter(e=>!t.includes(e)),r=(r.length&&(logger_1.default.error("Some components does not exists: "+r.join(", ")),process.exit(-1)),await Promise.resolve().then(()=>__importStar(require("vite")))).loadConfigFromFile,r=await r({command:"serve",mode:"development"},path_1.default.resolve(process.cwd(),"vite.config.js"));if(!r)throw new Error("Vite config not found");var i=this.config.port||4e3;e&&await this.publishService.publishToLocalPath("https://localhost:"+i,o);let n=(0,lodash_1.cloneDeep)(r.config),a=await(0,vite_1.createServer)({...n,server:{middlewareMode:!0}});e=(0,connect_1.default)(),e.use(async(t,r,e)=>{t=t.url.match(/^\/([a-zA-Z0-9_]+)\.js$/);if(t){t=t[1];if(!o.includes(t))return r.statusCode=404,void r.end("Component not found");try{this.setupFileWatcher(t,n);var i=await this.buildComponent(t,n);return r.setHeader("Content-Type","application/javascript"),r.setHeader("Access-Control-Allow-Origin","*"),r.setHeader("Cache-Control","no-cache, no-store, must-revalidate"),void r.end(i)}catch(e){return logger_1.default.error(`Error building ${t}:`,e),r.statusCode=500,void r.end("Error building component: "+e)}}e()}),e.use(a.middlewares),r=await this.getOrCreateCertificate();let l=https_1.default.createServer(r,e);l.listen(i,()=>{logger_1.default.info("\n✓ Dev server ready at https://localhost:4000"),logger_1.default.info("\nAvailable components:"),o.forEach(e=>{logger_1.default.info(` • https://localhost:4000/${e}.js`)})}),process.on("SIGINT",async()=>{logger_1.default.info("\nShutting down dev server...");for(var e of this.componentWatchers.values())await e.close();await a.close(),l.close(),process.exit(0)})}async buildComponent(t,e){if(this.componentBuilds.has(t))return this.componentBuilds.get(t);await this.typeCheck.specificComponents(t);var r=this.fileService.getEntryOfComponent(t),e=(0,lodash_1.cloneDeep)(e),r=(e.build={...e.build,lib:{formats:["es"],fileName:t,entry:r},outDir:path_1.default.resolve(process.cwd(),".vite-cache",t),emptyOutDir:!1,minify:!1},e.mode="development",(0,vite_1.build)(e).then(()=>{var e=path_1.default.resolve(process.cwd(),".vite-cache",t,t+".js");return fs_1.default.readFileSync(e,"utf-8")}));return this.componentBuilds.set(t,r),r}}exports.default=ExternalComponentWatchService;
@@ -0,0 +1,9 @@
1
+ import { ContenthubConfig } from "../../../types/ContentHubConfig.interface";
2
+ declare class TypeCheckService {
3
+ private tsconfigPath;
4
+ private fileService;
5
+ constructor(config: ContenthubConfig, tsconfigName?: string);
6
+ all(): void;
7
+ specificComponents(components: string | string[]): void;
8
+ }
9
+ export default TypeCheckService;
@@ -0,0 +1 @@
1
+ var __importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0});let tempDirectory_1=require("../../../config/tempDirectory"),FileService_1=__importDefault(require("../../../services/FileService")),logger_1=__importDefault(require("../../../utils/logger")),child_process_1=require("child_process"),fs_1=require("fs"),path_1=__importDefault(require("path"));class TypeCheckService{tsconfigPath;fileService;constructor(e,t){this.tsconfigPath=path_1.default.resolve(process.cwd(),t||"tsconfig.json"),this.fileService=new FileService_1.default(e)}all(){logger_1.default.info("Running TypeScript type check");try{(0,child_process_1.execSync)("npx tsc --noEmit --project "+this.tsconfigPath,{stdio:"inherit"}),logger_1.default.info("TypeScript type check passed")}catch(e){logger_1.default.error("TypeScript type check failed"),process.exit(-1)}}specificComponents(e){var e=Array.isArray(e)?e:[e],t=process.cwd()+"/"+tempDirectory_1.GLOBAL_TEMP_DIRECTORY,t=((0,fs_1.existsSync)(t)||(0,fs_1.mkdirSync)(t,{recursive:!0}),path_1.default.join(t,process.pid+".tsconfig.tmp.json")),e=(console.log(this.tsconfigPath),{extends:this.tsconfigPath,include:e.map(e=>"../"+this.fileService.getDirectoryOfComponent(e))});(0,fs_1.writeFileSync)(t,JSON.stringify(e,null,2)),logger_1.default.info("Running TypeScript type check");try{(0,child_process_1.execSync)("npx tsc --noEmit --project "+t,{stdio:"inherit"}),(0,fs_1.unlinkSync)(t),logger_1.default.info("TypeScript type check passed")}catch(e){logger_1.default.error("TypeScript type check failed"),(0,fs_1.unlinkSync)(t),process.exit(-1)}}}exports.default=TypeCheckService;
@@ -0,0 +1,4 @@
1
+ declare const _default: {
2
+ commands: import("commander").Command[];
3
+ }[];
4
+ export default _default;
@@ -0,0 +1 @@
1
+ var __importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0});let external_components_1=__importDefault(require("./external-components")),scripts_1=__importDefault(require("./scripts"));exports.default=[external_components_1.default,scripts_1.default];
@@ -0,0 +1,2 @@
1
+ import { Command } from "commander";
2
+ export declare const createScriptCommand: Command;
@@ -0,0 +1,4 @@
1
+ var __importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.createScriptCommand=void 0;let commander_1=require("commander"),prompts_1=require("@inquirer/prompts"),globalCommandConfig_js_1=require("../../../utils/globalCommandConfig.js"),CreateScriptService_js_1=__importDefault(require("../services/CreateScriptService.js")),logger_js_1=__importDefault(require("../../../utils/logger.js")),script_js_1=require("../utils/script.js");exports.createScriptCommand=new commander_1.Command("create-script").description("Create a new script from template").action(async e=>{var{config:e,contenthubService:t}=await(0,globalCommandConfig_js_1.globalCommandConfig)(e),t=new CreateScriptService_js_1.default(t,e);try{var r=await(0,prompts_1.input)({message:"Enter the script identifier (e.g., M.Script.MyScript):",validate:e=>!(!e||0===e.trim().length)||"Script identifier is required"}),i=(logger_js_1.default.info("🔍 Checking if script exists in environment..."),await t.fetchScriptDefaults(r.trim()));let e;e=i?(logger_js_1.default.info("✓ Found script in environment, using defaults"),await(0,prompts_1.confirm)({message:`Use fetched values?
2
+ Title: "${i.title}"
3
+ Description: "${i.description}"
4
+ Execute as user: `+i.executeAsUser,default:!0})?i:await(0,script_js_1.promptForScriptDetails)(r.trim(),i)):(logger_js_1.default.info("ℹ Script not found in environment, please provide details manually"),await(0,script_js_1.promptForScriptDetails)(r.trim())),await t.createScript(e)}catch(e){e instanceof Error&&logger_js_1.default.error("Failed to create script: "+e.message),process.exit(1)}});
@@ -0,0 +1,2 @@
1
+ import { Command } from "commander";
2
+ export declare const publishScriptCommand: Command;
@@ -0,0 +1 @@
1
+ var __importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.publishScriptCommand=void 0;let commander_1=require("commander"),globalCommandConfig_js_1=require("../../../utils/globalCommandConfig.js"),PublishScriptService_js_1=__importDefault(require("../services/PublishScriptService.js")),logger_js_1=__importDefault(require("../../../utils/logger.js"));exports.publishScriptCommand=(0,globalCommandConfig_js_1.setGlobalConfig)(new commander_1.Command("publish-script")).option("-s, --scripts <script>","script list to publish (comma-separated)").description("Publish scripts to environment").action(async e=>{var{config:i,contenthubService:s}=await(0,globalCommandConfig_js_1.globalCommandConfig)(e),e=(e.scripts||(logger_js_1.default.error("Please specify the scripts that needs to be pusblished via --scripts"),process.exit(-1)),e.scripts.split(",").map(e=>e.trim()));await new PublishScriptService_js_1.default(s,i).publishScripts(e)});
@@ -0,0 +1,2 @@
1
+ import { Command } from "commander";
2
+ export declare const syncScriptsFromEnvironmentCommand: Command;
@@ -0,0 +1 @@
1
+ var __importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.syncScriptsFromEnvironmentCommand=void 0;let commander_1=require("commander"),globalCommandConfig_js_1=require("../../../utils/globalCommandConfig.js"),SyncScriptService_js_1=__importDefault(require("../services/SyncScriptService.js"));exports.syncScriptsFromEnvironmentCommand=(0,globalCommandConfig_js_1.setGlobalConfig)(new commander_1.Command("sync-scripts")).description("Sync scripts from environment").action(async e=>{var{config:e,contenthubService:n}=await(0,globalCommandConfig_js_1.globalCommandConfig)(e);await new SyncScriptService_js_1.default(n,e).syncAllScripts()});
@@ -0,0 +1,8 @@
1
+ import { Logger } from "tslog";
2
+ declare class ScriptCompileError extends Error {
3
+ compilationErrors: any;
4
+ logger: Logger<unknown>;
5
+ constructor(message: string, compilationErrors: any);
6
+ logError(): void;
7
+ }
8
+ export default ScriptCompileError;
@@ -0,0 +1 @@
1
+ Object.defineProperty(exports,"__esModule",{value:!0});let tslog_1=require("tslog");class ScriptCompileError extends Error{compilationErrors;logger=new tslog_1.Logger({name:"Compile",minLevel:0,prettyLogTemplate:"{{name}} | {{logLevelName}}: "});constructor(r,e){super(r),this.compilationErrors=e}logError(){this.compilationErrors.forEach(r=>{this.logger.error(r.line+`:${r.column}: `+r.message)})}}exports.default=ScriptCompileError;
@@ -0,0 +1,4 @@
1
+ declare const _default: {
2
+ commands: import("commander").Command[];
3
+ };
4
+ export default _default;
@@ -0,0 +1 @@
1
+ Object.defineProperty(exports,"__esModule",{value:!0});let PublishScriptCommand_1=require("./commands/PublishScriptCommand"),CreateScriptCommand_1=require("./commands/CreateScriptCommand");exports.default={commands:[PublishScriptCommand_1.publishScriptCommand,CreateScriptCommand_1.createScriptCommand]};
@@ -0,0 +1,18 @@
1
+ import { ContenthubConfig } from "../../../types/ContentHubConfig.interface.js";
2
+ import ContenthubService from "../../../services/ContenthubService.js";
3
+ import { ActionScriptConfig } from "../../../types/ScriptConfig.interface.js";
4
+ export default class CreateScriptService {
5
+ private contenthubService;
6
+ private config;
7
+ private templateDir;
8
+ private scriptsDir;
9
+ constructor(contenthubService: ContenthubService, config: ContenthubConfig);
10
+ /**
11
+ * Fetch script metadata from ContentHub by identifier
12
+ */
13
+ fetchScriptDefaults(identifier: string): Promise<Partial<ActionScriptConfig> | null>;
14
+ /**
15
+ * Create a new script from template
16
+ */
17
+ createScript(config: ActionScriptConfig): Promise<void>;
18
+ }
@@ -0,0 +1,10 @@
1
+ var __createBinding=this&&this.__createBinding||(Object.create?function(e,t,r,i){void 0===i&&(i=r);var c=Object.getOwnPropertyDescriptor(t,r);c&&("get"in c?t.__esModule:!c.writable&&!c.configurable)||(c={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,i,c)}:function(e,t,r,i){e[i=void 0===i?r:i]=t[r]}),__setModuleDefault=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),__importStar=this&&this.__importStar||(()=>{var c=function(e){return(c=Object.getOwnPropertyNames||function(e){var t,r=[];for(t in e)Object.prototype.hasOwnProperty.call(e,t)&&(r[r.length]=t);return r})(e)};return function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r=c(e),i=0;i<r.length;i++)"default"!==r[i]&&__createBinding(t,e,r[i]);return __setModuleDefault(t,e),t}})(),__importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0});let fs=__importStar(require("fs")),path=__importStar(require("path")),logger_js_1=__importDefault(require("../../../utils/logger.js")),sc_contenthub_webclient_sdk_1=require("@sitecore/sc-contenthub-webclient-sdk"),apiCatch_js_1=require("../../../utils/apiCatch.js"),script_js_1=require("../utils/script.js");class CreateScriptService{contenthubService;config;templateDir;scriptsDir;constructor(e,t){this.contenthubService=e,this.config=t,this.templateDir=t.templates.script,this.scriptsDir=path.resolve(process.cwd(),t.scriptDir)}async fetchScriptDefaults(t){try{var e=await(0,apiCatch_js_1.apiErrorCatch)(()=>this.contenthubService.client.entities.getAsync(t,new sc_contenthub_webclient_sdk_1.EntityLoadConfiguration(sc_contenthub_webclient_sdk_1.CultureLoadOption.Default,new sc_contenthub_webclient_sdk_1.PropertyLoadOption(["M.Script.Name","M.Script.Description","M.Script.ExecuteAsUser","M.Script.Type"]))));return e?{identifier:e.identifier,type:e.getPropertyValue("M.Script.Type")||"Action",title:e.getPropertyValue("M.Script.Name")||"",description:e.getPropertyValue("M.Script.Description")||"",executeAsUser:e.getPropertyValue("M.Script.ExecuteAsUser")||!1}:null}catch(e){return logger_js_1.default.warn("⚠️ Could not fetch script from API: "+t),null}}async createScript(r){if(!fs.existsSync(this.templateDir))throw logger_js_1.default.error("Template directory not found: "+this.templateDir),new Error("Template directory not found");var i,c=(0,script_js_1.scriptNameToSlug)(r.title),s=path.join(this.scriptsDir,c);if(fs.existsSync(s))throw logger_js_1.default.error(`Script "${c}" already exists`),new Error("Script already exists");logger_js_1.default.info(`📦 Creating script "${c}"...`),fs.mkdirSync(s,{recursive:!0});for(i of fs.readdirSync(this.templateDir)){var n=path.join(this.templateDir,i);let e=i;"<ScriptName>.config.ts"===i?e=c+".config.ts":"<ScriptName>.cs"===i&&(e=c+".cs");var o=path.join(s,e);let t=fs.readFileSync(n,"utf-8");"<ScriptName>.config.ts"===i&&(t=`import { type ActionScriptConfig } from "@nestle/contenthub-cli";
2
+
3
+ export default {
4
+ identifier: "${r.identifier}",
5
+ type: "${r.type}",
6
+ title: "${r.title}",
7
+ description: "${r.description}",
8
+ executeAsUser: ${r.executeAsUser},
9
+ } as ActionScriptConfig;
10
+ `),fs.writeFileSync(o,t,"utf-8"),logger_js_1.default.info(" ✓ Created "+e)}logger_js_1.default.info(`✅ Script "${c}" created successfully!`),logger_js_1.default.info("📁 Location: "+path.relative(process.cwd(),s))}}exports.default=CreateScriptService;
@@ -0,0 +1,15 @@
1
+ import { ContenthubConfig } from "../../../types/ContentHubConfig.interface";
2
+ import ContenthubService from "../../../services/ContenthubService";
3
+ import FileService from "../../../services/FileService";
4
+ declare class PublishScriptService {
5
+ contenthubService: ContenthubService;
6
+ config: ContenthubConfig;
7
+ fileService: FileService;
8
+ constructor(contenthubService: ContenthubService, config: ContenthubConfig);
9
+ publishScripts(scripts: string[]): Promise<void>;
10
+ publishScript(script: string): Promise<void>;
11
+ private syncScriptRemote;
12
+ private syncScriptContent;
13
+ private compileScript;
14
+ }
15
+ export default PublishScriptService;
@@ -0,0 +1 @@
1
+ var __importDefault=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(exports,"__esModule",{value:!0});let fs_1=require("fs"),FileService_1=__importDefault(require("../../../services/FileService")),apiCatch_1=require("../../../utils/apiCatch"),sc_contenthub_webclient_sdk_1=require("@sitecore/sc-contenthub-webclient-sdk"),ScriptCompileError_1=__importDefault(require("../errors/ScriptCompileError")),logger_1=__importDefault(require("../../../utils/logger"));class PublishScriptService{contenthubService;config;fileService;constructor(t,e){this.contenthubService=t,this.config=e,this.fileService=new FileService_1.default(e)}async publishScripts(t){for(var e of t)await this.publishScript(e)}async publishScript(t){var e=this.fileService.getScriptConfig(t),i=(e||(logger_1.default.error(`script "${t}" config not found`),process.exit(-1)),this.fileService.getScriptContent(t)),t=(i||(logger_1.default.error(`script "${t}" content (.cs) not found`),process.exit(-1)),await this.fileService.tsFileImport(e)),e=(0,fs_1.readFileSync)(i,"utf-8");await this.syncScriptRemote(t,e)}async syncScriptRemote(t,e){let i=await(0,apiCatch_1.apiErrorCatch)(()=>this.contenthubService.client.entities.getAsync(t.identifier,sc_contenthub_webclient_sdk_1.EntityLoadConfiguration.Full));i||(logger_1.default.error(`script with identifier "${t.identifier}" could not be found on the environment`),process.exit(-1)),logger_1.default.info(`Start script publish for "${t.title}"`),await this.syncScriptContent(i,e,t),t.title!==i.getPropertyValue("M.Script.Name")&&i.setPropertyValue("M.Script.Name",t.title),t.type!==i.getPropertyValue("M.Script.Type")&&i.setPropertyValue("M.Script.Type",t.type),t.description!==i.getPropertyValue("M.Script.Description")&&i.setPropertyValue("M.Script.Description",t.description);e=null!=i.getPropertyValue("M.Script.ExecuteAsUser")&&i.getPropertyValue("M.Script.ExecuteAsUser");t.executeAsUser!==e&&i.setPropertyValue("M.Script.ExecuteAsUser",t.executeAsUser),i.isDirty&&await(0,apiCatch_1.apiErrorCatch)(()=>this.contenthubService.client.entities.saveAsync(i)),logger_1.default.info(`Script "${t.title}"is updated`)}async syncScriptContent(t,e,i){let r=t?.getRelation("ScriptToActiveScriptContent")?.getIds()[0],c=t?.getRelation("ScriptToDraftScriptContent")?.getIds()[0];if(r&&(await(0,apiCatch_1.apiErrorCatch)(()=>this.contenthubService.client.entities.getAsync(r,sc_contenthub_webclient_sdk_1.EntityLoadConfiguration.Full)))?.getPropertyValue("M.ScriptContent.Script")===e)return void logger_1.default.info("Script is same with remote, not updating content");let n=c&&await(0,apiCatch_1.apiErrorCatch)(()=>this.contenthubService.client.entities.getAsync(c,sc_contenthub_webclient_sdk_1.EntityLoadConfiguration.Full)),o=(n||(n=await this.contenthubService.client.entityFactory.createAsync("M.ScriptContent")).getRelation("ScriptToDraftScriptContent")?.setIds([t.id]),n.setPropertyValue("M.ScriptContent.Script",e),await(0,apiCatch_1.apiErrorCatch)(()=>this.contenthubService.client.entities.saveAsync(n)));await this.compileScript(o),logger_1.default.info("Start publish script"),await(0,apiCatch_1.apiErrorCatch)(()=>this.contenthubService.client.raw.postAsync(`/api/scripts/${o}/publish`,{})),logger_1.default.info("Script published")}async compileScript(e){logger_1.default.info("Start compile script content"),await(0,apiCatch_1.apiErrorCatch)(()=>this.contenthubService.client.raw.postAsync(`/api/scripts/${e}/compile`,{})),await new Promise((i,r)=>{let t=0,c=setInterval(()=>{if(30<(t+=1))throw new Error("Script not compiled after 1m.");(0,apiCatch_1.apiErrorCatch)(()=>this.contenthubService.client.entities.getAsync(e,new sc_contenthub_webclient_sdk_1.EntityLoadConfiguration(sc_contenthub_webclient_sdk_1.CultureLoadOption.Default,new sc_contenthub_webclient_sdk_1.PropertyLoadOption(["M.ScriptContent.CompileStatus","M.ScriptContent.CompilationErrors","M.ScriptContent.CompilationMessage"])))).then(t=>{var e=t?.getPropertyValue("M.ScriptContent.CompileStatus")?.toLowerCase();"success"===e?(i(!0),clearInterval(c)):"errors"===e&&(r(new ScriptCompileError_1.default(t?.getPropertyValue("M.ScriptContent.CompilationMessage"),t?.getPropertyValue("M.ScriptContent.CompilationErrors"))),clearInterval(c))})},2e3)}).then(()=>{logger_1.default.info("Script Content compiled")}).catch(t=>{t instanceof ScriptCompileError_1.default&&t.logError(),process.exit(-1)})}}exports.default=PublishScriptService;
@@ -0,0 +1,15 @@
1
+ import ContenthubService from "../../../services/ContenthubService";
2
+ import { ContenthubConfig } from "../../../types/ContentHubConfig.interface";
3
+ import FileService from "../../../services/FileService";
4
+ declare class SyncScriptService {
5
+ contenthubService: ContenthubService;
6
+ config: ContenthubConfig;
7
+ static IgnoreUserScriptsOnSyncAll: string[];
8
+ fileService: FileService;
9
+ constructor(contenthubService: ContenthubService, config: ContenthubConfig);
10
+ syncAllScripts(): Promise<void>;
11
+ private syncScripts;
12
+ private syncScriptInFolder;
13
+ private loadAllScripts;
14
+ }
15
+ export default SyncScriptService;
@@ -0,0 +1 @@
1
+ var __importDefault=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(exports,"__esModule",{value:!0});let array_1=require("../../../utils/array"),apiCatch_1=require("../../../utils/apiCatch"),sc_contenthub_webclient_sdk_1=require("@sitecore/sc-contenthub-webclient-sdk"),FileService_1=__importDefault(require("../../../services/FileService")),script_js_1=require("../utils/script.js"),scriptLoadConfig=new sc_contenthub_webclient_sdk_1.EntityLoadConfiguration(sc_contenthub_webclient_sdk_1.CultureLoadOption.Default,new sc_contenthub_webclient_sdk_1.PropertyLoadOption(["M.Script.Name","M.Script.Enabled","M.Script.ExecuteAsUser","M.Script.Description","M.Script.Type"]),new sc_contenthub_webclient_sdk_1.RelationLoadOption(["ScriptToActiveScriptContent","ScriptToDraftScriptContent"]));class SyncScriptService{contenthubService;config;static IgnoreUserScriptsOnSyncAll=["@sitecore","Administrator","Jeroen Feyaerts","Evgeni Ivakhnov"];fileService;constructor(t,e){this.contenthubService=t,this.config=e,this.fileService=new FileService_1.default(e)}async syncAllScripts(){var t=await this.loadAllScripts();await this.syncScripts(t)}async syncScripts(t,e=0){var i=Array.isArray(t)?t:[t],t=i.flatMap(t=>{var e=t.getRelation("ScriptToActiveScriptContent")?.getIds();return e?.length?e||[]:t.getRelation("ScriptToDraftScriptContent")?.getIds()||[]}),r=await Promise.all((0,array_1.arrayToChunks)(t,50).map(t=>(0,apiCatch_1.apiErrorCatch)(()=>this.contenthubService.client.entities.getManyAsync(t,new sc_contenthub_webclient_sdk_1.EntityLoadConfiguration(sc_contenthub_webclient_sdk_1.CultureLoadOption.Default,new sc_contenthub_webclient_sdk_1.PropertyLoadOption("M.ScriptContent.Script")))))).then(t=>t.flat());for(let t of i){let e=t.getRelation("ScriptToActiveScriptContent")?.getIds()[0];var n=r.find(t=>t.id===e);n&&await this.syncScriptInFolder(t,n)}}async syncScriptInFolder(t,e){var i=t.getPropertyValue("M.Script.Name"),r=(0,script_js_1.scriptNameToSlug)(i),n=this.fileService.getScriptConfig(i);let c={identifier:t.identifier,type:t.getPropertyValue("M.Script.Type"),title:i,description:t.getPropertyValue("M.Script.Description")||"",executeAsUser:t.getPropertyValue("M.Script.ExecuteAsUser")||!1};if(n){let t=await this.fileService.tsFileImport(n);if(c.identifier!==t.identifier)throw new Error("Identifier in local folder does not match with environment");c=t}await this.fileService.writeScript(r,e.getPropertyValue("M.ScriptContent.Script"),c)}async loadAllScripts(){for(var t=await(0,apiCatch_1.apiErrorCatch)(()=>this.contenthubService.client.entities.getByDefinitionAsync("M.Script",scriptLoadConfig,0,100)),e=[...t.items],i=t.createIterator();i.canMoveNext();)await i.moveNextAsync(),e.push(...i.current?.items||[]);t=e.flatMap(t=>[t.createdBy,t.modifiedBy]),t=[...new Set(t)];let r=(await Promise.all((0,array_1.arrayToChunks)(t,50).map(t=>(0,apiCatch_1.apiErrorCatch)(()=>this.contenthubService.client.entities.getManyAsync(t,new sc_contenthub_webclient_sdk_1.EntityLoadConfiguration(sc_contenthub_webclient_sdk_1.CultureLoadOption.Default,new sc_contenthub_webclient_sdk_1.PropertyLoadOption("Username")))))).then(t=>t.flat())).filter(e=>!SyncScriptService.IgnoreUserScriptsOnSyncAll.some(t=>e.getPropertyValue("Username").includes(t))).map(t=>t.id);return e.filter(t=>r.includes(t.createdBy)||r.includes(t.modifiedBy))}}exports.default=SyncScriptService;
@@ -0,0 +1,3 @@
1
+ import { ActionScriptConfig } from "../../../types/ScriptConfig.interface";
2
+ export declare const scriptNameToSlug: (name: string) => string;
3
+ export declare function promptForScriptDetails(identifier: string, defaults?: Partial<ActionScriptConfig>): Promise<ActionScriptConfig>;
@@ -0,0 +1 @@
1
+ Object.defineProperty(exports,"__esModule",{value:!0}),exports.scriptNameToSlug=void 0,exports.promptForScriptDetails=promptForScriptDetails;let prompts_1=require("@inquirer/prompts"),scriptNameToSlug=e=>e.replace(/-/g,".").split(".").map(e=>e.trim()).map(e=>e.split(" ").filter(Boolean).map(e=>e[0].toUpperCase()+e.slice(1)).join("")).join(".");async function promptForScriptDetails(e,t){var r=await(0,prompts_1.input)({message:"Enter the script title:",default:t?.title||"",validate:e=>!(!e||0===e.trim().length)||"Script title is required"}),i=await(0,prompts_1.input)({message:"Enter the script description:",default:t?.description||""}),s=await(0,prompts_1.select)({message:"Select the script type:",choices:[{name:"Action",value:"Action"},{name:"User sign-in",value:"User_SignIn"},{name:"Metadata processing",value:"Processing_Metadata"},{name:"User pre-registration",value:"User_PreRegistration"},{name:"User post-registration",value:"User_PostRegistration"},{name:"Shared",value:"Shared"},{name:"Processing_AIResult",value:"AI result processing"},{name:"Processing_AIInput",value:"AI input processing"}],default:t?.type||"Action"}),t=await(0,prompts_1.confirm)({message:"Execute as user?",default:t?.executeAsUser||!1});return{identifier:e,type:s,title:r.trim(),description:i.trim(),executeAsUser:t}}exports.scriptNameToSlug=scriptNameToSlug;
@@ -0,0 +1,2 @@
1
+ import { Command } from "commander";
2
+ export declare const createComponentAssetMappingCommand: Command;
@@ -0,0 +1 @@
1
+ var __importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.createComponentAssetMappingCommand=void 0;let commander_1=require("commander"),globalCommandConfig_js_1=require("../../../utils/globalCommandConfig.js"),FileService_js_1=__importDefault(require("../../../services/FileService.js")),sc_contenthub_webclient_sdk_1=require("@sitecore/sc-contenthub-webclient-sdk"),fs_1=require("fs"),apiCatch_js_1=require("../../../utils/apiCatch.js"),logger_js_1=__importDefault(require("../../../utils/logger.js"));exports.createComponentAssetMappingCommand=(0,globalCommandConfig_js_1.setGlobalConfig)(new commander_1.Command("create-component-asset-mapping")).description("Run ContentHub build").action(async e=>{let{config:t,contenthubService:n}=await(0,globalCommandConfig_js_1.globalCommandConfig)(e);e=new FileService_js_1.default(t).getAllComponentNames("index.tsx");let i=new Map,o=new sc_contenthub_webclient_sdk_1.SearchAfterQuery({filter:new sc_contenthub_webclient_sdk_1.LogicalQueryNodeFilter({operator:sc_contenthub_webclient_sdk_1.LogicalOperator.And,left:new sc_contenthub_webclient_sdk_1.RelationQueryNodeFilter({relation:"ContentRepositoryToAsset",role:sc_contenthub_webclient_sdk_1.RelationRole.Parent,id:733}),right:new sc_contenthub_webclient_sdk_1.DefinitionNameQueryNodeFilter({name:"M.Asset"})}),loadConfiguration:sc_contenthub_webclient_sdk_1.EntityLoadConfiguration.Minimal,sorting:[new sc_contenthub_webclient_sdk_1.Sorting({field:"modified_on",fieldType:sc_contenthub_webclient_sdk_1.SortFieldType.Property,order:sc_contenthub_webclient_sdk_1.QuerySortOrder.Desc})],take:50}),r=await(0,apiCatch_js_1.apiErrorCatch)(()=>n.client?.querying.searchAfterAsync(o));for(;r.items.length;)(await(0,apiCatch_js_1.apiErrorCatch)(()=>n.client.entities.getManyAsync(r.items.map(e=>e.id),new sc_contenthub_webclient_sdk_1.EntityLoadConfiguration(sc_contenthub_webclient_sdk_1.CultureLoadOption.None,new sc_contenthub_webclient_sdk_1.PropertyLoadOption("FileName"))))).forEach(e=>{i.set(e.getPropertyValue("FileName"),e.id)}),logger_js_1.default.info(r.items.length),o.searchAfter=r.lastHitData,r=await(0,apiCatch_js_1.apiErrorCatch)(()=>n.client.querying.searchAfterAsync(o));let a={};e.forEach(e=>{a[e]=i.get(e+".js")||null}),(0,fs_1.writeFileSync)("asset-mapping.json",JSON.stringify(a,null,2))});
@@ -0,0 +1,2 @@
1
+ import { Command } from "commander";
2
+ export declare const fetchAllAssetsNotTrackedCommand: Command;
@@ -0,0 +1 @@
1
+ var __importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.fetchAllAssetsNotTrackedCommand=void 0;let commander_1=require("commander"),globalCommandConfig_js_1=require("../../../utils/globalCommandConfig.js"),FileService_js_1=__importDefault(require("../../../services/FileService.js")),sc_contenthub_webclient_sdk_1=require("@sitecore/sc-contenthub-webclient-sdk"),fs_1=require("fs"),apiCatch_js_1=require("../../../utils/apiCatch.js"),userIdsToIgnore=[32489,865085,6,805896,53403,32618,35254,33544,1450886];exports.fetchAllAssetsNotTrackedCommand=(0,globalCommandConfig_js_1.setGlobalConfig)(new commander_1.Command("fetch-all-assets-not-tracked")).description("Run ContentHub build").action(async e=>{let{config:t,contenthubService:n}=await(0,globalCommandConfig_js_1.globalCommandConfig)(e);let i=new FileService_js_1.default(t).getAllComponentNames().map(e=>e+".js"),o=new sc_contenthub_webclient_sdk_1.SearchAfterQuery({filter:new sc_contenthub_webclient_sdk_1.LogicalQueryNodeFilter({operator:sc_contenthub_webclient_sdk_1.LogicalOperator.And,left:new sc_contenthub_webclient_sdk_1.RelationQueryNodeFilter({relation:"ContentRepositoryToAsset",role:sc_contenthub_webclient_sdk_1.RelationRole.Parent,id:733}),right:new sc_contenthub_webclient_sdk_1.DefinitionNameQueryNodeFilter({name:"M.Asset"})}),loadConfiguration:sc_contenthub_webclient_sdk_1.EntityLoadConfiguration.Minimal,sorting:[new sc_contenthub_webclient_sdk_1.Sorting({field:"modified_on",fieldType:sc_contenthub_webclient_sdk_1.SortFieldType.Property,order:sc_contenthub_webclient_sdk_1.QuerySortOrder.Desc})],take:50}),s=await(0,apiCatch_js_1.apiErrorCatch)(()=>n.client?.querying.searchAfterAsync(o));for(var a=[];s.items.length;){var r=await(0,apiCatch_js_1.apiErrorCatch)(()=>n.client.entities.getManyAsync(s.items.map(e=>e.id),new sc_contenthub_webclient_sdk_1.EntityLoadConfiguration(sc_contenthub_webclient_sdk_1.CultureLoadOption.None,new sc_contenthub_webclient_sdk_1.PropertyLoadOption("FileName"),new sc_contenthub_webclient_sdk_1.RelationLoadOption(["AssetToPageComponent"]))));a.push(...r.filter(e=>e.getRelation("AssetToPageComponent")?.getIds().length&&!i.includes(e.getPropertyValue("FileName"))&&!userIdsToIgnore.includes(e.createdBy))),o.searchAfter=s.lastHitData,s=await(0,apiCatch_js_1.apiErrorCatch)(()=>n.client.querying.searchAfterAsync(o))}let c=await n.client.entities.getManyAsync([...new Set(a.map(e=>e.createdBy))],new sc_contenthub_webclient_sdk_1.EntityLoadConfiguration(sc_contenthub_webclient_sdk_1.CultureLoadOption.None,new sc_contenthub_webclient_sdk_1.PropertyLoadOption("Username")));(0,fs_1.writeFileSync)("assets-not-in-repo.json",JSON.stringify(a.map(t=>({id:t.id,name:t.getPropertyValue("FileName"),created_by:c.find(e=>e.id===t.createdBy)?.getPropertyValue("Username")})),null,2))});
@@ -0,0 +1,2 @@
1
+ import { Command } from "commander";
2
+ export declare const moveComponentsCommand: Command;
@@ -0,0 +1 @@
1
+ var __importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.moveComponentsCommand=void 0;let commander_1=require("commander"),globalCommandConfig_js_1=require("../../../utils/globalCommandConfig.js"),fs_1=require("fs"),sc_contenthub_webclient_sdk_1=require("@sitecore/sc-contenthub-webclient-sdk"),array_js_1=require("../../../utils/array.js"),apiCatch_js_1=require("../../../utils/apiCatch.js"),moveComponent_js_1=require("../utils/moveComponent.js"),FileService_js_1=__importDefault(require("../../../services/FileService.js"));exports.moveComponentsCommand=(0,globalCommandConfig_js_1.setGlobalConfig)(new commander_1.Command("move-components")).description("Run ContentHub build").action(async e=>{let{config:t,contenthubService:n}=await(0,globalCommandConfig_js_1.globalCommandConfig)(e);e=(0,fs_1.readFileSync)("asset-mapping.json","utf-8");let o=JSON.parse(e);var e=Object.values(o).filter(e=>!!e),a=await Promise.all((0,array_js_1.arrayToChunks)(e,50).map(e=>(0,apiCatch_js_1.apiErrorCatch)(()=>n.client.entities.getManyAsync(e,new sc_contenthub_webclient_sdk_1.EntityLoadConfiguration(sc_contenthub_webclient_sdk_1.CultureLoadOption.None,sc_contenthub_webclient_sdk_1.PropertyLoadOption.None,new sc_contenthub_webclient_sdk_1.RelationLoadOption(["AssetToPageComponent"])))))).then(e=>e.flat());let i=a.flatMap(e=>e.getRelation("AssetToPageComponent")?.getIds()||[]),s=await Promise.all((0,array_js_1.arrayToChunks)(i,50).map(e=>(0,apiCatch_js_1.apiErrorCatch)(()=>n.client.entities.getManyAsync(e,new sc_contenthub_webclient_sdk_1.EntityLoadConfiguration(sc_contenthub_webclient_sdk_1.CultureLoadOption.None,sc_contenthub_webclient_sdk_1.PropertyLoadOption.None,new sc_contenthub_webclient_sdk_1.RelationLoadOption(["PageToPageComponent"])))))).then(e=>e.flat()),r=s.flatMap(e=>e.getRelation("PageToPageComponent")?.getIds()||[]),_=await Promise.all((0,array_js_1.arrayToChunks)(r,50).map(e=>(0,apiCatch_js_1.apiErrorCatch)(()=>n.client.entities.getManyAsync(e,new sc_contenthub_webclient_sdk_1.EntityLoadConfiguration(sc_contenthub_webclient_sdk_1.CultureLoadOption.None,new sc_contenthub_webclient_sdk_1.PropertyLoadOption("Page.Name")))))).then(e=>e.flat());var l=new FileService_js_1.default(t);let c={};for(let n of Object.keys(o)){var m=l.getDirectoryOfComponent(n);if(m){var p=t.componentDir;if(o[n]){let t=a.find(e=>e.id===o[n]).getRelation("AssetToPageComponent")?.getIds()||[];if(t.length){let e=[...new Set(t.flatMap(t=>s.find(e=>e.id===t)?.getRelation("PageToPageComponent")?.getIds()||[]))];var d=e.map(t=>_.find(e=>e.id===t)?.getPropertyValue("Page.Name"));c[n]=d}else(0,moveComponent_js_1.moveComponent)(m,p.replace("/components","")+"/can-be-removed")}else(0,moveComponent_js_1.moveComponent)(m,p.replace("/components","")+"/asset-not-found")}}e=Object.keys(c).sort().reduce((e,t)=>(e[t]=c[t],e),{});(0,fs_1.writeFileSync)("asset-page-mapping.json",JSON.stringify(e,null,2))});
@@ -0,0 +1,2 @@
1
+ import { Command } from "commander";
2
+ export declare const syncComponentConfigCommand: Command;
@@ -0,0 +1 @@
1
+ var __importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.syncComponentConfigCommand=void 0;let commander_1=require("commander"),globalCommandConfig_js_1=require("../../../utils/globalCommandConfig.js"),fs_1=require("fs"),sc_contenthub_webclient_sdk_1=require("@sitecore/sc-contenthub-webclient-sdk"),array_js_1=require("../../../utils/array.js"),ExternalComponentConfigService_js_1=__importDefault(require("../services/ExternalComponentConfigService.js")),apiCatch_js_1=require("../../../utils/apiCatch.js");exports.syncComponentConfigCommand=(0,globalCommandConfig_js_1.setGlobalConfig)(new commander_1.Command("sync-component-config")).description("Run ContentHub build").action(async e=>{let{config:n,contenthubService:o}=await(0,globalCommandConfig_js_1.globalCommandConfig)(e);e=(0,fs_1.readFileSync)("asset-mapping.json","utf-8");let t=JSON.parse(e);var e=Object.values(t).filter(e=>!!e),i=await Promise.all((0,array_js_1.arrayToChunks)(e,50).map(e=>(0,apiCatch_js_1.apiErrorCatch)(()=>o.client.entities.getManyAsync(e,new sc_contenthub_webclient_sdk_1.EntityLoadConfiguration(sc_contenthub_webclient_sdk_1.CultureLoadOption.None,sc_contenthub_webclient_sdk_1.PropertyLoadOption.None,new sc_contenthub_webclient_sdk_1.RelationLoadOption(["AssetToPageComponent"])))))).then(e=>e.flat()),a=new ExternalComponentConfigService_js_1.default(o,n);for(let n of Object.keys(t))t[n]?a.syncConfigAsset(n,i.find(e=>e.id===t[n])):a.writeConfigFile(n,{components:[]})});
@@ -0,0 +1,4 @@
1
+ declare const _default: {
2
+ commands: import("commander").Command[];
3
+ };
4
+ export default _default;
@@ -0,0 +1 @@
1
+ Object.defineProperty(exports,"__esModule",{value:!0});let createComponentAssetMapping_1=require("./commands/createComponentAssetMapping"),fetchAllAssetsNotTracked_1=require("./commands/fetchAllAssetsNotTracked"),fetchAssetPagesFromMap_1=require("./commands/fetchAssetPagesFromMap"),syncComponentConfig_1=require("./commands/syncComponentConfig");exports.default={commands:[createComponentAssetMapping_1.createComponentAssetMappingCommand,syncComponentConfig_1.syncComponentConfigCommand,fetchAssetPagesFromMap_1.moveComponentsCommand,fetchAllAssetsNotTracked_1.fetchAllAssetsNotTrackedCommand]};
@@ -0,0 +1,13 @@
1
+ import { IEntity } from "@sitecore/sc-contenthub-webclient-sdk";
2
+ import { ContenthubConfig } from "../../../types/ContentHubConfig.interface";
3
+ import ExternalComponentsService from "../../../services/FileService";
4
+ import { ExternalComponentConfig } from "../../../types/ExternalComponentConfig.interface";
5
+ import ContenthubService from "../../../services/ContenthubService";
6
+ declare class ExternalComponentConfigService {
7
+ contenthubService: ContenthubService;
8
+ externalComponentsService: ExternalComponentsService;
9
+ constructor(contenthubService: ContenthubService, config: ContenthubConfig);
10
+ syncConfigAsset(component: string, asset: IEntity): Promise<void>;
11
+ writeConfigFile(component: string, config: ExternalComponentConfig): void;
12
+ }
13
+ export default ExternalComponentConfigService;
@@ -0,0 +1,6 @@
1
+ var __importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0});let sc_contenthub_webclient_sdk_1=require("@sitecore/sc-contenthub-webclient-sdk"),FileService_1=__importDefault(require("../../../services/FileService")),fs_1=require("fs"),lodash_1=require("lodash"),apiCatch_1=require("../../../utils/apiCatch");class ExternalComponentConfigService{contenthubService;externalComponentsService;constructor(e,t){this.contenthubService=e,this.externalComponentsService=new FileService_1.default(t)}async syncConfigAsset(e,t){let n=t.getRelation("AssetToPageComponent")?.getIds()||[];t=(await(0,apiCatch_1.apiErrorCatch)(()=>this.contenthubService.client.entities.getManyAsync(n,sc_contenthub_webclient_sdk_1.EntityLoadConfiguration.Full))).reduce((e,t)=>{let n=t.getPropertyValue("PageComponent.Settings").config;var i=e.find(e=>(0,lodash_1.isEqual)(e.config,n));return i?i.pageComponentIdentifiers.push(t.identifier):e.push({pageComponentIdentifiers:[t.identifier],config:n}),e},[]);this.writeConfigFile(e,{components:t})}writeConfigFile(e,t){var n=this.externalComponentsService.getDirectoryOfComponent(e);(0,fs_1.writeFileSync)(n+`/${e}.config.ts`,`
2
+ import { type ExternalComponentConfig } from "@nestle/contenthub-cli";
3
+
4
+ export default ${JSON.stringify(t)} as ExternalComponentConfig;
5
+
6
+ `)}}exports.default=ExternalComponentConfigService;
@@ -0,0 +1 @@
1
+ export declare const moveComponent: (componentFolder: string, to: string) => void;
@@ -0,0 +1 @@
1
+ Object.defineProperty(exports,"__esModule",{value:!0}),exports.moveComponent=void 0;let fs_1=require("fs"),moveComponent=(e,o)=>{var n;e.endsWith(o)||((0,fs_1.existsSync)(o)||(0,fs_1.mkdirSync)(o),n=e.split("/").pop(),(0,fs_1.renameSync)(e,o+"/"+n))};exports.moveComponent=moveComponent;
@@ -0,0 +1,9 @@
1
+ import { ContentHubClient } from "@sitecore/sc-contenthub-webclient-sdk";
2
+ declare class ContenthubService {
3
+ client: ContentHubClient;
4
+ entityIdMapping: Map<string, number>;
5
+ constructor(endpoint: string, apiToken: string);
6
+ validateClient(): Promise<void>;
7
+ getOrFetchId(identifier: string): Promise<number | undefined>;
8
+ }
9
+ export default ContenthubService;
@@ -0,0 +1 @@
1
+ Object.defineProperty(exports,"__esModule",{value:!0});let sc_contenthub_webclient_sdk_1=require("@sitecore/sc-contenthub-webclient-sdk"),apiCatch_js_1=require("../utils/apiCatch.js");class ContenthubService{client;entityIdMapping=new Map;constructor(t,e){if(!e||!e.length)throw new Error("Api Token is invalid");this.client=new sc_contenthub_webclient_sdk_1.ContentHubClient(t),this.client.internalClient.setRequestHeaders({"x-auth-token":e})}async validateClient(){if(!await(0,apiCatch_js_1.apiErrorCatch)(()=>this.client.internalClient.authenticateAsync()))throw Error("Authentication failed")}async getOrFetchId(t){if(this.entityIdMapping.has(t))return this.entityIdMapping.get(t);var e=await(0,apiCatch_js_1.apiErrorCatch)(()=>this.client.entities.getAsync(t,sc_contenthub_webclient_sdk_1.EntityLoadConfiguration.Minimal));if(e)return this.entityIdMapping.set(t,e.id),e.id;throw new Error(t+" does not exist")}}exports.default=ContenthubService;
@@ -0,0 +1,19 @@
1
+ import { ActionScriptConfig } from "../types/ScriptConfig.interface.js";
2
+ import { ContenthubConfig } from "../types/ContentHubConfig.interface.js";
3
+ declare class FileService {
4
+ config: ContenthubConfig;
5
+ constructor(config: ContenthubConfig);
6
+ getAllComponentPaths(fileToCheck?: string): string[];
7
+ getAllComponentNames(fileToCheck?: string): string[];
8
+ getDirectoryOfComponent(component: string): string | null;
9
+ getComponentConfig(component: string): string;
10
+ getComponentBuild(component: string, absolute?: boolean): string;
11
+ getEntryOfComponent(component: string): string;
12
+ getScriptConfig(scriptName: string): string;
13
+ getScriptContent(scriptName: string): string;
14
+ getAbsolutePath(p: string): string;
15
+ tsFileImport<T = any>(path: string): Promise<T>;
16
+ writeScript(scriptName: string, content: string, config: ActionScriptConfig): Promise<void>;
17
+ prettyFile(filePath: string): Promise<void>;
18
+ }
19
+ export default FileService;
@@ -0,0 +1,10 @@
1
+ var __importDefault=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(exports,"__esModule",{value:!0});let glob_1=require("glob"),path_1=__importDefault(require("path")),prettier_1=__importDefault(require("prettier")),tempDirectory_js_1=require("../config/tempDirectory.js"),api_1=require("tsx/esm/api"),fs_1=require("fs");class FileService{config;constructor(t){this.config=t}getAllComponentPaths(t="*.config.ts"){return(0,glob_1.sync)(this.config.componentDir+"/**/"+t)}getAllComponentNames(t="*.config.ts"){return this.getAllComponentPaths(t).map(t=>{t=t.split("/");return t[t.length-2]})}getDirectoryOfComponent(t){var t=(0,glob_1.sync)(this.config.componentDir+`/**/${t}/*.tsx`)[0];return t?((t=t.split("/")).pop(),t.join("/")):null}getComponentConfig(t){return(0,glob_1.sync)(this.config.componentDir+`/**/${t}/*.config.ts`)[0]}getComponentBuild(t,e=!0){t=(0,glob_1.sync)(tempDirectory_js_1.BUILD_DIRECTORY+`/${t}.js`)[0];return e?t&&this.getAbsolutePath(t):t}getEntryOfComponent(t){return(0,glob_1.sync)(this.config.componentDir+`/**/${t}/*.tsx`)[0]}getScriptConfig(t){return(0,glob_1.sync)(this.config.scriptDir+`/${t}/*.config.ts`)[0]}getScriptContent(t){return(0,glob_1.sync)(this.config.scriptDir+`/${t}/*.cs`)[0]}getAbsolutePath(t){return path_1.default.isAbsolute(t)?t:path_1.default.resolve(process.cwd(),t)}async tsFileImport(t){t=this.getAbsolutePath(t);return(await(0,api_1.tsImport)(t,t)).default}async writeScript(t,e,i){var r=this.config.scriptDir+"/"+t,n=((0,fs_1.existsSync)(r)||(0,fs_1.mkdirSync)(r,{recursive:!0}),r+`/${t}.config.ts`);(0,fs_1.writeFileSync)(n,`
2
+ import { type ActionScriptConfig } from "@nestle/contenthub-cli";
3
+ export default {
4
+ identifier: "${i.identifier}",
5
+ type: "${i.type}",
6
+ title: "${i.title}",
7
+ description: \`${i.description}\`,
8
+ executeAsUser: ${i.executeAsUser?"true":"false"},
9
+ } as ActionScriptConfig;
10
+ `),await this.prettyFile(n),(0,fs_1.writeFileSync)(r+`/${t}.cs`,e)}async prettyFile(t){var e=await prettier_1.default.format((0,fs_1.readFileSync)(t,"utf8"),{...await prettier_1.default.resolveConfig(t),filepath:t});(0,fs_1.writeFileSync)(t,e)}}exports.default=FileService;
@@ -0,0 +1,16 @@
1
+ export interface ContenthubEnvironment {
2
+ domain: string;
3
+ name: string;
4
+ apiToken: string;
5
+ }
6
+ export interface ContenthubConfig {
7
+ componentDir: string;
8
+ scriptDir: string;
9
+ port: number;
10
+ templates: {
11
+ externalComponent: string;
12
+ script: string;
13
+ };
14
+ mainEnvironment: string;
15
+ environments: ContenthubEnvironment[];
16
+ }
@@ -0,0 +1 @@
1
+ Object.defineProperty(exports,"__esModule",{value:!0});
@@ -0,0 +1,7 @@
1
+ export interface ComponentEntry {
2
+ pageComponentIdentifiers: string[];
3
+ config?: any;
4
+ }
5
+ export interface ExternalComponentConfig {
6
+ components: ComponentEntry[];
7
+ }
@@ -0,0 +1 @@
1
+ Object.defineProperty(exports,"__esModule",{value:!0});
@@ -0,0 +1,8 @@
1
+ export type ScriptType = "Action" | "User_SignIn" | "Processing_Metadata" | "User_PreRegistration" | "User_PostRegistration" | "Shared" | "Processing_AIResult" | "Processing_AIInput";
2
+ export interface ActionScriptConfig {
3
+ identifier: string;
4
+ type: ScriptType;
5
+ title: string;
6
+ description: string;
7
+ executeAsUser: boolean;
8
+ }
@@ -0,0 +1 @@
1
+ Object.defineProperty(exports,"__esModule",{value:!0});
@@ -0,0 +1,2 @@
1
+ export declare const waitForRateLimitCall: (time?: number) => Promise<unknown>;
2
+ export declare const apiErrorCatch: <T = any>(fetch: () => Promise<T>, retryOnNoSuccess?: boolean) => Promise<T>;
@@ -0,0 +1 @@
1
+ Object.defineProperty(exports,"__esModule",{value:!0}),exports.apiErrorCatch=exports.waitForRateLimitCall=void 0;let number_js_1=require("./number.js"),wait=t=>new Promise(e=>setTimeout(e,t)),waitForRateLimitCall=(e=1e3/15)=>wait(e),STATUSES_TO_RETRY=(exports.waitForRateLimitCall=waitForRateLimitCall,[429,503]),retryOperation=(o,i,n,s=!1)=>new Promise((t,r)=>{let a=(e=200)=>(503===e&&(i=(0,number_js_1.randomIntFromInterval)(5e3,1e4)),5===n&&(i+=(0,number_js_1.randomIntFromInterval)(1e4,3e4)),wait(i).then(()=>retryOperation(o,i+1e3,n-1)).then(t).catch(r));return o().then(e=>0<n&&e&&STATUSES_TO_RETRY.includes(e.statusCode)||s&&!e.content?a():void t(e)).catch(e=>0<n&&(STATUSES_TO_RETRY.includes(e.statusCode)||s)?a(e.statusCode):r(e))}),apiErrorCatch=(e,t=!1)=>retryOperation(e,(0,number_js_1.randomIntFromInterval)(1001,2e3),10,t);exports.apiErrorCatch=apiErrorCatch;
@@ -0,0 +1 @@
1
+ export declare const arrayToChunks: <T = any>(array: T[], chunkSize?: number) => Array<Array<T>>;
@@ -0,0 +1 @@
1
+ Object.defineProperty(exports,"__esModule",{value:!0}),exports.arrayToChunks=void 0;let arrayToChunks=(e,o=50)=>{var a=[];for(let r=0;r<e.length;r+=o)a.push(e.slice(r,r+o));return a};exports.arrayToChunks=arrayToChunks;
@@ -0,0 +1,2 @@
1
+ import { ContenthubConfig } from "../types/ContentHubConfig.interface.js";
2
+ export declare function getCliConfig(configPath?: string): Promise<ContenthubConfig>;
@@ -0,0 +1 @@
1
+ var __importDefault=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.getCliConfig=getCliConfig;let path_1=__importDefault(require("path")),api_1=require("tsx/esm/api"),logger_js_1=__importDefault(require("./logger.js"));async function getCliConfig(e="contenthubConfig.build.config.ts"){e=path_1.default.isAbsolute(e)?e:path_1.default.resolve(process.cwd(),e);try{return(await(0,api_1.tsImport)(e,e)).default}catch(t){throw logger_js_1.default.error("Failed to load config at "+e),t}}
@@ -0,0 +1,8 @@
1
+ import { Command } from "commander";
2
+ import ContenthubService from "../services/ContenthubService.js";
3
+ export declare const setGlobalConfig: (command: Command) => Command;
4
+ export declare const globalCommandConfig: (options: any) => Promise<{
5
+ config: import("../index.js").ContenthubConfig;
6
+ environment: import("../index.js").ContenthubEnvironment;
7
+ contenthubService: ContenthubService;
8
+ }>;
@@ -0,0 +1 @@
1
+ var __importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.globalCommandConfig=exports.setGlobalConfig=void 0;let getCliConfig_js_1=require("./getCliConfig.js"),ContenthubService_js_1=__importDefault(require("../services/ContenthubService.js")),logger_js_1=__importDefault(require("./logger.js")),setGlobalConfig=e=>(e.option("-e, --environment <environment>","environment id specified in the config file"),e),globalCommandConfig=(exports.setGlobalConfig=setGlobalConfig,async e=>{var n=await(0,getCliConfig_js_1.getCliConfig)();let o=e.environment||n.mainEnvironment;o||(logger_js_1.default.error("environment not specified -e or --environment"),process.exit(-1));var e=n.environments.find(e=>e.name===o),i=(e||(logger_js_1.default.error(`environment ${o} not found`),process.exit(-1)),new ContenthubService_js_1.default(e.domain,e.apiToken));return await i.validateClient(),{config:n,environment:e,contenthubService:i}});exports.globalCommandConfig=globalCommandConfig;
@@ -0,0 +1 @@
1
+ export declare function sha1FromFile(filePath: string): Promise<unknown>;
@@ -0,0 +1 @@
1
+ Object.defineProperty(exports,"__esModule",{value:!0}),exports.sha1FromFile=sha1FromFile;let crypto_1=require("crypto"),fs_1=require("fs");function sha1FromFile(a){return new Promise((e,r)=>{let t=(0,crypto_1.createHash)("sha1");var o=(0,fs_1.createReadStream)(a);o.on("error",r),o.on("data",e=>t.update(e)),o.on("end",()=>{e(t.digest("hex"))})})}
@@ -0,0 +1,4 @@
1
+ import { Logger } from "tslog";
2
+ export declare const logger: Logger<unknown>;
3
+ export declare const loggerSuccess: Logger<unknown>;
4
+ export default logger;
@@ -0,0 +1 @@
1
+ var __importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.loggerSuccess=exports.logger=void 0;let tslog_1=require("tslog"),chalk_1=__importDefault(require("chalk"));exports.logger=new tslog_1.Logger({name:"Contenthub CLI",minLevel:0,prettyLogTemplate:"{{name}} | {{logLevelName}}: "}),exports.loggerSuccess=new tslog_1.Logger({name:"Contenthub CLI",minLevel:0,prettyLogTemplate:`{{name}} | ${chalk_1.default.green("✔ Success")}: `}),exports.default=exports.logger;
@@ -0,0 +1 @@
1
+ export declare const randomIntFromInterval: (min: number, max: number) => number;
@@ -0,0 +1 @@
1
+ Object.defineProperty(exports,"__esModule",{value:!0}),exports.randomIntFromInterval=void 0;let randomIntFromInterval=(r,o)=>Math.floor(Math.random()*(o-r+1)+r);exports.randomIntFromInterval=randomIntFromInterval;
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "@digital-herd/content-hub-cli",
3
+ "description": "CLI tools for managing Sitecore Content Hub external components and scripts",
4
+ "version": "1.0.0",
5
+ "type": "commonjs",
6
+ "main": "./lib/index.js",
7
+ "types": "./lib/index.d.ts",
8
+ "files": [
9
+ "lib"
10
+ ],
11
+ "bin": {
12
+ "content-hub-tools": "lib/bin.js"
13
+ },
14
+ "author": "Digital herd",
15
+ "homepage": "https://www.digital-herd.com/",
16
+ "license": "ISC",
17
+ "sideEffects": false,
18
+ "publishConfig": {
19
+ "access": "public"
20
+ },
21
+ "scripts": {
22
+ "build": "tsc && node scripts/build.js",
23
+ "watch": "tsc --watch"
24
+ },
25
+ "dependencies": {
26
+ "@inquirer/input": "^5.0.4",
27
+ "@inquirer/prompts": "^8.2.0",
28
+ "@inquirer/select": "^5.0.4",
29
+ "@sitecore/sc-contenthub-webclient-sdk": "1.2.96",
30
+ "chalk": "^5.6.2",
31
+ "chokidar": "^5.0.0",
32
+ "commander": "^11.0.0",
33
+ "connect": "^3.7.0",
34
+ "glob": "^13.0.0",
35
+ "lodash": "^4.17.21",
36
+ "prettier": "^3.8.1",
37
+ "tslog": "^4.10.2",
38
+ "tsx": "^4.7.0",
39
+ "uglify-js": "^3.19.3",
40
+ "vite": "^7.3.1"
41
+ },
42
+ "devDependencies": {
43
+ "@types/connect": "^3.4.38",
44
+ "@types/lodash": "^4.17.23",
45
+ "ts-node": "^10.9.2",
46
+ "typescript": "^5.3.3"
47
+ }
48
+ }