@digital-herd/content-hub-cli 1.0.2 → 1.0.3

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 (28) hide show
  1. package/README.md +52 -0
  2. package/lib/index.d.ts +1 -0
  3. package/lib/index.js +1 -1
  4. package/lib/modules/index.js +1 -1
  5. package/lib/modules/manual-patches/commands/createPatchComponent.d.ts +2 -0
  6. package/lib/modules/manual-patches/commands/createPatchComponent.js +1 -0
  7. package/lib/modules/manual-patches/commands/runPatch.d.ts +2 -0
  8. package/lib/modules/manual-patches/commands/runPatch.js +1 -0
  9. package/lib/modules/manual-patches/index.d.ts +4 -0
  10. package/lib/modules/manual-patches/index.js +1 -0
  11. package/lib/modules/manual-patches/services/CreatePatchService.d.ts +10 -0
  12. package/lib/modules/manual-patches/services/CreatePatchService.js +10 -0
  13. package/lib/modules/manual-patches/services/RunPatchService.d.ts +23 -0
  14. package/lib/modules/manual-patches/services/RunPatchService.js +1 -0
  15. package/lib/modules/patches/commands/createPatchComponent.d.ts +2 -0
  16. package/lib/modules/patches/commands/createPatchComponent.js +1 -0
  17. package/lib/modules/patches/commands/runPatch.d.ts +2 -0
  18. package/lib/modules/patches/commands/runPatch.js +1 -0
  19. package/lib/modules/patches/index.d.ts +4 -0
  20. package/lib/modules/patches/index.js +1 -0
  21. package/lib/modules/patches/services/CreatePatchService.d.ts +10 -0
  22. package/lib/modules/patches/services/CreatePatchService.js +10 -0
  23. package/lib/modules/patches/services/RunPatchService.d.ts +23 -0
  24. package/lib/modules/patches/services/RunPatchService.js +1 -0
  25. package/lib/types/ContentHubConfig.interface.d.ts +1 -0
  26. package/lib/types/Patch.interface.d.ts +4 -0
  27. package/lib/types/Patch.interface.js +1 -0
  28. package/package.json +1 -1
package/README.md CHANGED
@@ -8,6 +8,8 @@
8
8
  |---------|-------------|
9
9
  | `create-component` | Create a new React component from template |
10
10
  | `create-script` | Create a new C# script with API auto-fetch |
11
+ | `create-manual-patch` | Create a new manual patch from template |
12
+ | `run-manual-patch` | Run a manual patch on ContentHub |
11
13
  | `build` | Build external components for production |
12
14
  | `watch` | Watch and serve components with HMR |
13
15
  | `publish-script` | Publish scripts to ContentHub environment |
@@ -255,6 +257,56 @@ content-hub-tools <command> [options]
255
257
  content-hub-tools sync-scripts -e local
256
258
  ```
257
259
 
260
+ - **create-manual-patch** — Create a new manual patch from template (interactive)
261
+
262
+ This command will interactively prompt you to provide a patch name and create a TypeScript patch file that can be used to run one-off data migrations or fixes.
263
+
264
+ Examples:
265
+
266
+ - Create a new patch (interactive prompts):
267
+ ```bash
268
+ content-hub-tools create-manual-patch
269
+ ```
270
+
271
+ The interactive prompts will guide you through:
272
+ - **Patch name**: Enter a PascalCase name (e.g., `FixUserIssue`, `MigrateData`)
273
+ - Only letters are allowed in the name
274
+ - The name will be automatically converted to PascalCase if needed
275
+
276
+ After running, the patch will be created at:
277
+ ```
278
+ patches/<PatchName>.patch.ts
279
+ ```
280
+
281
+ The generated patch file will contain:
282
+ - `PatchParams` interface with ContentHub client
283
+ - `runPatch<Name>` function ready for implementation
284
+
285
+ - **run-manual-patch** — Run a manual patch on ContentHub (interactive)
286
+
287
+ This command will display all available patches sorted by last modified date (newest first) and execute the selected patch.
288
+
289
+ Examples:
290
+
291
+ - Run a patch (interactive selection):
292
+ ```bash
293
+ content-hub-tools run-manual-patch -e staging
294
+ ```
295
+
296
+ - Run a patch on production:
297
+ ```bash
298
+ content-hub-tools run-manual-patch -e production
299
+ ```
300
+
301
+ The interactive prompt will show:
302
+ - List of all available `.patch.ts` files
303
+ - Last modified timestamp for each patch
304
+ - Patches sorted with newest first
305
+
306
+ The patch will be executed with:
307
+ - Access to the ContentHub client via `PatchParams`
308
+ - Connection to the selected environment
309
+
258
310
  ## Developer notes
259
311
 
260
312
  - The CLI is implemented with `commander` and TypeScript. Entry point: `src/bin.ts`.
package/lib/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from "./types/ContentHubConfig.interface.js";
2
2
  export * from "./types/ExternalComponentConfig.interface.js";
3
3
  export * from "./types/ScriptConfig.interface.js";
4
+ export * from "./types/Patch.interface.js";
package/lib/index.js CHANGED
@@ -1 +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);
1
+ var __createBinding=this&&this.__createBinding||(Object.create?function(e,t,r,i){void 0===i&&(i=r);var n=Object.getOwnPropertyDescriptor(t,r);n&&("get"in n?t.__esModule:!n.writable&&!n.configurable)||(n={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,i,n)}:function(e,t,r,i){e[i=void 0===i?r:i]=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),__exportStar(require("./types/Patch.interface.js"),exports);
@@ -1 +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];
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")),manual_patches_1=__importDefault(require("./manual-patches"));exports.default=[external_components_1.default,scripts_1.default,manual_patches_1.default];
@@ -0,0 +1,2 @@
1
+ import { Command } from "commander";
2
+ export declare const createPatchCommand: 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.createPatchCommand=void 0;let commander_1=require("commander"),prompts_1=require("@inquirer/prompts"),globalCommandConfig_js_1=require("../../../utils/globalCommandConfig.js"),logger_js_1=__importDefault(require("../../../utils/logger.js")),CreatePatchService_js_1=__importDefault(require("../services/CreatePatchService.js"));exports.createPatchCommand=new commander_1.Command("create-manual-patch").description("Create a new patch from template").action(async e=>{e=(await(0,globalCommandConfig_js_1.globalCommandConfig)(e)).config,e=new CreatePatchService_js_1.default(e);try{var t=(await(0,prompts_1.input)({message:"Enter the patch name (e.g., MyPatch, FixUserIssue):",validate:e=>e&&0!==e.trim().length?!!/^[a-zA-Z]+$/.test(e)||"Patch name must contain only letters":"Patch name is required"})).trim();await e.createPatch(t)}catch(e){e instanceof Error&&logger_js_1.default.error("Failed to create patch: "+e.message),process.exit(1)}});
@@ -0,0 +1,2 @@
1
+ import { Command } from "commander";
2
+ export declare const runPatchCommand: 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.runPatchCommand=void 0;let commander_1=require("commander"),prompts_1=require("@inquirer/prompts"),globalCommandConfig_js_1=require("../../../utils/globalCommandConfig.js"),logger_js_1=__importDefault(require("../../../utils/logger.js")),RunPatchService_js_1=__importDefault(require("../services/RunPatchService.js"));exports.runPatchCommand=(0,globalCommandConfig_js_1.setGlobalConfig)(new commander_1.Command("run-manual-patch")).description("Run a patch").action(async e=>{var{config:e,contenthubService:a}=await(0,globalCommandConfig_js_1.globalCommandConfig)(e),a=new RunPatchService_js_1.default(a,e);try{var r=a.getAvailablePatches(),t=(0===r.length&&(logger_js_1.default.error("No patches found in the patch directory"),process.exit(1)),await(0,prompts_1.select)({message:"Select a patch to run:",choices:r.map(e=>({name:`${e.name} (modified: ${e.modifiedTime.toLocaleString()})`,value:e.name}))}));await a.runPatch(t)}catch(e){e instanceof Error&&logger_js_1.default.error("Failed to run patch: "+e.message),process.exit(1)}});
@@ -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 createPatchComponent_1=require("./commands/createPatchComponent"),runPatch_1=require("./commands/runPatch");exports.default={commands:[createPatchComponent_1.createPatchCommand,runPatch_1.runPatchCommand]};
@@ -0,0 +1,10 @@
1
+ import { ContenthubConfig } from "../../../types/ContentHubConfig.interface.js";
2
+ export default class CreatePatchService {
3
+ private config;
4
+ private patchDir;
5
+ constructor(config: ContenthubConfig);
6
+ /**
7
+ * Create a new patch file from template
8
+ */
9
+ createPatch(patchName: string): Promise<void>;
10
+ }
@@ -0,0 +1,10 @@
1
+ var __createBinding=this&&this.__createBinding||(Object.create?function(t,e,r,a){void 0===a&&(a=r);var i=Object.getOwnPropertyDescriptor(e,r);i&&("get"in i?e.__esModule:!i.writable&&!i.configurable)||(i={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,a,i)}:function(t,e,r,a){t[a=void 0===a?r:a]=e[r]}),__setModuleDefault=this&&this.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),__importStar=this&&this.__importStar||(()=>{var i=function(t){return(i=Object.getOwnPropertyNames||function(t){var e,r=[];for(e in t)Object.prototype.hasOwnProperty.call(t,e)&&(r[r.length]=e);return r})(t)};return function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var r=i(t),a=0;a<r.length;a++)"default"!==r[a]&&__createBinding(e,t,r[a]);return __setModuleDefault(e,t),e}})(),__importDefault=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(exports,"__esModule",{value:!0});let fs=__importStar(require("fs")),path=__importStar(require("path")),logger_js_1=__importDefault(require("../../../utils/logger.js"));class CreatePatchService{config;patchDir;constructor(t){this.config=t,this.patchDir=path.resolve(process.cwd(),t.patchDir)}async createPatch(t){var t=t.charAt(0).toUpperCase()+t.slice(1),e=t.charAt(0).toLowerCase()+t.slice(1),e=(fs.existsSync(this.patchDir)||fs.mkdirSync(this.patchDir,{recursive:!0}),path.join(this.patchDir,e+".patch.ts"));if(fs.existsSync(e))throw logger_js_1.default.error(`Patch "${t}" already exists`),new Error("Patch already exists");logger_js_1.default.info(`📦 Creating patch "${t}"...`);var r=`import { PatchParams } from "@digital-herd/content-hub-cli";
2
+
3
+
4
+
5
+ const runPatch${t} = ({ client }: PatchParams) => {
6
+ // run patch
7
+ };
8
+
9
+ export default runPatch${t};
10
+ `;fs.writeFileSync(e,r,"utf-8"),logger_js_1.default.info(`✅ Patch "${t}" created successfully!`),logger_js_1.default.info("📁 Location: "+path.relative(process.cwd(),e))}}exports.default=CreatePatchService;
@@ -0,0 +1,23 @@
1
+ import { ContenthubConfig } from "../../../types/ContentHubConfig.interface.js";
2
+ import ContenthubService from "../../../services/ContenthubService.js";
3
+ interface PatchFile {
4
+ name: string;
5
+ path: string;
6
+ modifiedTime: Date;
7
+ }
8
+ export default class RunPatchService {
9
+ private contenthubService;
10
+ private config;
11
+ private patchDir;
12
+ private fileService;
13
+ constructor(contenthubService: ContenthubService, config: ContenthubConfig);
14
+ /**
15
+ * Get all available patch files sorted by last modified (newest first)
16
+ */
17
+ getAvailablePatches(): PatchFile[];
18
+ /**
19
+ * Execute a specific patch
20
+ */
21
+ runPatch(patchName: string): Promise<void>;
22
+ }
23
+ export {};
@@ -0,0 +1 @@
1
+ var __createBinding=this&&this.__createBinding||(Object.create?function(e,t,r,i){void 0===i&&(i=r);var a=Object.getOwnPropertyDescriptor(t,r);a&&("get"in a?t.__esModule:!a.writable&&!a.configurable)||(a={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,i,a)}: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 a=function(e){return(a=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=a(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 RunPatchService{contenthubService;config;patchDir;fileService;constructor(e,t){this.contenthubService=e,this.config=t,this.patchDir=path.resolve(process.cwd(),t.patchDir),this.fileService=new FileService_js_1.default(t)}getAvailablePatches(){return fs.existsSync(this.patchDir)?fs.readdirSync(this.patchDir).filter(e=>e.endsWith(".patch.ts")).map(e=>{var t=path.join(this.patchDir,e),r=fs.statSync(t);return{name:e.replace(".patch.ts",""),path:t,modifiedTime:r.mtime}}).sort((e,t)=>t.modifiedTime.getTime()-e.modifiedTime.getTime()):(logger_js_1.default.warn("Patch directory not found: "+this.patchDir),[])}async runPatch(t){var e=path.join(this.patchDir,t+".patch.ts");if(!fs.existsSync(e))throw logger_js_1.default.error(`Patch "${t}" not found at `+e),new Error("Patch not found");logger_js_1.default.info(`🚀 Running patch "${t}"...`);try{var r=await this.fileService.tsFileImport(e);if("function"!=typeof r)throw new Error(`Patch "${t}" does not export a default function`);await r({client:this.contenthubService.client}),logger_js_1.default.info(`✅ Patch "${t}" completed successfully!`)}catch(e){throw logger_js_1.default.error(`Failed to run patch "${t}":`,e),e}}}exports.default=RunPatchService;
@@ -0,0 +1,2 @@
1
+ import { Command } from "commander";
2
+ export declare const createPatchCommand: 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.createPatchCommand=void 0;let commander_1=require("commander"),prompts_1=require("@inquirer/prompts"),globalCommandConfig_js_1=require("../../../utils/globalCommandConfig.js"),logger_js_1=__importDefault(require("../../../utils/logger.js")),CreatePatchService_js_1=__importDefault(require("../services/CreatePatchService.js"));exports.createPatchCommand=new commander_1.Command("create-patch").description("Create a new patch from template").action(async e=>{e=(await(0,globalCommandConfig_js_1.globalCommandConfig)(e)).config,e=new CreatePatchService_js_1.default(e);try{var t=(await(0,prompts_1.input)({message:"Enter the patch name (e.g., MyPatch, FixUserIssue):",validate:e=>e&&0!==e.trim().length?!!/^[a-zA-Z]+$/.test(e)||"Patch name must contain only letters":"Patch name is required"})).trim();await e.createPatch(t)}catch(e){e instanceof Error&&logger_js_1.default.error("Failed to create patch: "+e.message),process.exit(1)}});
@@ -0,0 +1,2 @@
1
+ import { Command } from "commander";
2
+ export declare const runPatchCommand: 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.runPatchCommand=void 0;let commander_1=require("commander"),prompts_1=require("@inquirer/prompts"),globalCommandConfig_js_1=require("../../../utils/globalCommandConfig.js"),logger_js_1=__importDefault(require("../../../utils/logger.js")),RunPatchService_js_1=__importDefault(require("../services/RunPatchService.js"));exports.runPatchCommand=(0,globalCommandConfig_js_1.setGlobalConfig)(new commander_1.Command("run-patch")).description("Run a patch").action(async e=>{var{config:e,contenthubService:a}=await(0,globalCommandConfig_js_1.globalCommandConfig)(e),a=new RunPatchService_js_1.default(a,e);try{var r=a.getAvailablePatches(),t=(0===r.length&&(logger_js_1.default.error("No patches found in the patch directory"),process.exit(1)),await(0,prompts_1.select)({message:"Select a patch to run:",choices:r.map(e=>({name:`${e.name} (modified: ${e.modifiedTime.toLocaleString()})`,value:e.name}))}));await a.runPatch(t)}catch(e){e instanceof Error&&logger_js_1.default.error("Failed to run patch: "+e.message),process.exit(1)}});
@@ -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 createPatchComponent_1=require("./commands/createPatchComponent"),runPatch_1=require("./commands/runPatch");exports.default={commands:[createPatchComponent_1.createPatchCommand,runPatch_1.runPatchCommand]};
@@ -0,0 +1,10 @@
1
+ import { ContenthubConfig } from "../../../types/ContentHubConfig.interface.js";
2
+ export default class CreatePatchService {
3
+ private config;
4
+ private patchDir;
5
+ constructor(config: ContenthubConfig);
6
+ /**
7
+ * Create a new patch file from template
8
+ */
9
+ createPatch(patchName: string): Promise<void>;
10
+ }
@@ -0,0 +1,10 @@
1
+ var __createBinding=this&&this.__createBinding||(Object.create?function(t,e,r,a){void 0===a&&(a=r);var i=Object.getOwnPropertyDescriptor(e,r);i&&("get"in i?e.__esModule:!i.writable&&!i.configurable)||(i={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,a,i)}:function(t,e,r,a){t[a=void 0===a?r:a]=e[r]}),__setModuleDefault=this&&this.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),__importStar=this&&this.__importStar||(()=>{var i=function(t){return(i=Object.getOwnPropertyNames||function(t){var e,r=[];for(e in t)Object.prototype.hasOwnProperty.call(t,e)&&(r[r.length]=e);return r})(t)};return function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var r=i(t),a=0;a<r.length;a++)"default"!==r[a]&&__createBinding(e,t,r[a]);return __setModuleDefault(e,t),e}})(),__importDefault=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(exports,"__esModule",{value:!0});let fs=__importStar(require("fs")),path=__importStar(require("path")),logger_js_1=__importDefault(require("../../../utils/logger.js"));class CreatePatchService{config;patchDir;constructor(t){this.config=t,this.patchDir=path.resolve(process.cwd(),t.patchDir)}async createPatch(t){var t=t.charAt(0).toUpperCase()+t.slice(1),e=t.charAt(0).toLowerCase()+t.slice(1),e=(fs.existsSync(this.patchDir)||fs.mkdirSync(this.patchDir,{recursive:!0}),path.join(this.patchDir,e+".patch.ts"));if(fs.existsSync(e))throw logger_js_1.default.error(`Patch "${t}" already exists`),new Error("Patch already exists");logger_js_1.default.info(`📦 Creating patch "${t}"...`);var r=`import { PatchParams } from "@digital-herd/content-hub-cli";
2
+
3
+
4
+
5
+ const runPatch${t} = ({ client }: PatchParams) => {
6
+ // run patch
7
+ };
8
+
9
+ export default runPatch${t};
10
+ `;fs.writeFileSync(e,r,"utf-8"),logger_js_1.default.info(`✅ Patch "${t}" created successfully!`),logger_js_1.default.info("📁 Location: "+path.relative(process.cwd(),e))}}exports.default=CreatePatchService;
@@ -0,0 +1,23 @@
1
+ import { ContenthubConfig } from "../../../types/ContentHubConfig.interface.js";
2
+ import ContenthubService from "../../../services/ContenthubService.js";
3
+ interface PatchFile {
4
+ name: string;
5
+ path: string;
6
+ modifiedTime: Date;
7
+ }
8
+ export default class RunPatchService {
9
+ private contenthubService;
10
+ private config;
11
+ private patchDir;
12
+ private fileService;
13
+ constructor(contenthubService: ContenthubService, config: ContenthubConfig);
14
+ /**
15
+ * Get all available patch files sorted by last modified (newest first)
16
+ */
17
+ getAvailablePatches(): PatchFile[];
18
+ /**
19
+ * Execute a specific patch
20
+ */
21
+ runPatch(patchName: string): Promise<void>;
22
+ }
23
+ export {};
@@ -0,0 +1 @@
1
+ var __createBinding=this&&this.__createBinding||(Object.create?function(e,t,r,i){void 0===i&&(i=r);var a=Object.getOwnPropertyDescriptor(t,r);a&&("get"in a?t.__esModule:!a.writable&&!a.configurable)||(a={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,i,a)}: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 a=function(e){return(a=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=a(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 RunPatchService{contenthubService;config;patchDir;fileService;constructor(e,t){this.contenthubService=e,this.config=t,this.patchDir=path.resolve(process.cwd(),t.patchDir),this.fileService=new FileService_js_1.default(t)}getAvailablePatches(){return fs.existsSync(this.patchDir)?fs.readdirSync(this.patchDir).filter(e=>e.endsWith(".patch.ts")).map(e=>{var t=path.join(this.patchDir,e),r=fs.statSync(t);return{name:e.replace(".patch.ts",""),path:t,modifiedTime:r.mtime}}).sort((e,t)=>t.modifiedTime.getTime()-e.modifiedTime.getTime()):(logger_js_1.default.warn("Patch directory not found: "+this.patchDir),[])}async runPatch(t){var e=path.join(this.patchDir,t+".patch.ts");if(!fs.existsSync(e))throw logger_js_1.default.error(`Patch "${t}" not found at `+e),new Error("Patch not found");logger_js_1.default.info(`🚀 Running patch "${t}"...`);try{var r=await this.fileService.tsFileImport(e);if("function"!=typeof r)throw new Error(`Patch "${t}" does not export a default function`);await r({client:this.contenthubService.client}),logger_js_1.default.info(`✅ Patch "${t}" completed successfully!`)}catch(e){throw logger_js_1.default.error(`Failed to run patch "${t}":`,e),e}}}exports.default=RunPatchService;
@@ -6,6 +6,7 @@ export interface ContenthubEnvironment {
6
6
  export interface ContenthubConfig {
7
7
  componentDir: string;
8
8
  scriptDir: string;
9
+ patchDir: string;
9
10
  port: number;
10
11
  templates: {
11
12
  externalComponent: string;
@@ -0,0 +1,4 @@
1
+ import { ContentHubClient } from "@sitecore/sc-contenthub-webclient-sdk";
2
+ export interface PatchParams {
3
+ client: ContentHubClient;
4
+ }
@@ -0,0 +1 @@
1
+ Object.defineProperty(exports,"__esModule",{value:!0});
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@digital-herd/content-hub-cli",
3
3
  "description": "CLI tools for managing Sitecore Content Hub external components and scripts",
4
- "version": "1.0.2",
4
+ "version": "1.0.3",
5
5
  "type": "commonjs",
6
6
  "main": "./lib/index.js",
7
7
  "types": "./lib/index.d.ts",