@digital-herd/content-hub-cli 1.0.2 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +52 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +1 -1
- package/lib/modules/index.d.ts +1 -0
- package/lib/modules/index.js +1 -1
- package/lib/modules/manual-patches/commands/createPatchComponent.d.ts +2 -0
- package/lib/modules/manual-patches/commands/createPatchComponent.js +1 -0
- package/lib/modules/manual-patches/commands/runPatch.d.ts +2 -0
- package/lib/modules/manual-patches/commands/runPatch.js +1 -0
- package/lib/modules/manual-patches/index.d.ts +6 -0
- package/lib/modules/manual-patches/index.js +1 -0
- package/lib/modules/manual-patches/services/CreatePatchService.d.ts +10 -0
- package/lib/modules/manual-patches/services/CreatePatchService.js +12 -0
- package/lib/modules/manual-patches/services/PatchService.d.ts +14 -0
- package/lib/modules/manual-patches/services/PatchService.js +1 -0
- package/lib/modules/manual-patches/services/RunPatchService.d.ts +21 -0
- package/lib/modules/manual-patches/services/RunPatchService.js +1 -0
- package/lib/modules/patches/commands/createPatchComponent.d.ts +2 -0
- package/lib/modules/patches/commands/createPatchComponent.js +1 -0
- package/lib/modules/patches/commands/runPatch.d.ts +2 -0
- package/lib/modules/patches/commands/runPatch.js +1 -0
- package/lib/modules/patches/index.d.ts +4 -0
- package/lib/modules/patches/index.js +1 -0
- package/lib/modules/patches/services/CreatePatchService.d.ts +10 -0
- package/lib/modules/patches/services/CreatePatchService.js +10 -0
- package/lib/modules/patches/services/RunPatchService.d.ts +23 -0
- package/lib/modules/patches/services/RunPatchService.js +1 -0
- package/lib/services/FileService.d.ts +1 -1
- package/lib/services/FileService.js +2 -2
- package/lib/types/ContentHubConfig.interface.d.ts +1 -0
- package/lib/types/Patch.interface.d.ts +4 -0
- package/lib/types/Patch.interface.js +1 -0
- package/package.json +4 -2
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
package/lib/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var __createBinding=this&&this.__createBinding||(Object.create?function(e,t,r,
|
|
1
|
+
var __createBinding=this&&this.__createBinding||(Object.create?function(e,t,r,o){void 0===o&&(o=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,o,i)}:function(e,t,r,o){e[o=void 0===o?r:o]=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),__exportStar(require("./modules"),exports);
|
package/lib/modules/index.d.ts
CHANGED
package/lib/modules/index.js
CHANGED
|
@@ -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 __createBinding=this&&this.__createBinding||(Object.create?function(e,t,r,a){void 0===a&&(a=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,a,n)}:function(e,t,r,a){e[a=void 0===a?r:a]=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)},__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"));__exportStar(require("./manual-patches"),exports),exports.default=[external_components_1.default,scripts_1.default,manual_patches_1.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}),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 @@
|
|
|
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,environment:a}=await(0,globalCommandConfig_js_1.globalCommandConfig)(e),e=new RunPatchService_js_1.default(e,a);try{var r=e.getAvailablePatches(),o=(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 e.runPatch(o)}catch(e){e instanceof Error&&logger_js_1.default.error("Failed to run patch: "+e.message),process.exit(1)}});
|
|
@@ -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.PatchService=void 0;let createPatchComponent_1=require("./commands/createPatchComponent"),runPatch_1=require("./commands/runPatch"),PatchService_1=__importDefault(require("./services/PatchService"));exports.PatchService=PatchService_1.default,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,12 @@
|
|
|
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"));class CreatePatchService{config;patchDir;constructor(e){this.config=e,this.patchDir=path.resolve(process.cwd(),e.patchDir)}async createPatch(e){var e=e.charAt(0).toUpperCase()+e.slice(1),t=e.charAt(0).toLowerCase()+e.slice(1),t=(fs.existsSync(this.patchDir)||fs.mkdirSync(this.patchDir,{recursive:!0}),path.join(this.patchDir,t+".patch.ts"));if(fs.existsSync(t))throw logger_js_1.default.error(`Patch "${e}" already exists`),new Error("Patch already exists");logger_js_1.default.info(`📦 Creating patch "${e}"...`);var r=`import { PatchService } from "@digital-herd/content-hub-cli";
|
|
2
|
+
|
|
3
|
+
const patchService = new PatchService();
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
const runPatch${e} = async () => {
|
|
7
|
+
const client = await patchService.getClient();
|
|
8
|
+
// run patch
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export default runPatch${e};
|
|
12
|
+
`;fs.writeFileSync(t,r,"utf-8"),logger_js_1.default.info(`✅ Patch "${e}" created successfully!`),logger_js_1.default.info("📁 Location: "+path.relative(process.cwd(),t))}}exports.default=CreatePatchService;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import ContenthubService from "@/services/ContenthubService";
|
|
2
|
+
import { ContenthubConfig, ContenthubEnvironment } from "@/types/ContentHubConfig.interface";
|
|
3
|
+
declare class PatchService {
|
|
4
|
+
private _initialised;
|
|
5
|
+
runtimeConfig?: {
|
|
6
|
+
config: ContenthubConfig;
|
|
7
|
+
environment: ContenthubEnvironment;
|
|
8
|
+
contenthubService: ContenthubService;
|
|
9
|
+
};
|
|
10
|
+
constructor();
|
|
11
|
+
private init;
|
|
12
|
+
getClient(): Promise<import("@sitecore/sc-contenthub-webclient-sdk").ContentHubClient>;
|
|
13
|
+
}
|
|
14
|
+
export default PatchService;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Object.defineProperty(exports,"__esModule",{value:!0});let globalCommandConfig_1=require("@/utils/globalCommandConfig");class PatchService{_initialised=!1;runtimeConfig;constructor(){}async init(){this._initialised||(this.runtimeConfig=await(0,globalCommandConfig_1.globalCommandConfig)({environent:process.env.ENVIRONMENT}),this._initialised=!0)}async getClient(){return await this.init(),this.runtimeConfig.contenthubService.client}}exports.default=PatchService;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ContenthubConfig } from "../../../types/ContentHubConfig.interface.js";
|
|
2
|
+
import { ContenthubEnvironment } from "../../../types/ContentHubConfig.interface.js";
|
|
3
|
+
interface PatchFile {
|
|
4
|
+
name: string;
|
|
5
|
+
path: string;
|
|
6
|
+
modifiedTime: Date;
|
|
7
|
+
}
|
|
8
|
+
export default class RunPatchService {
|
|
9
|
+
private environment;
|
|
10
|
+
private patchDir;
|
|
11
|
+
constructor(config: ContenthubConfig, environment: ContenthubEnvironment);
|
|
12
|
+
/**
|
|
13
|
+
* Get all available patch files sorted by last modified (newest first)
|
|
14
|
+
*/
|
|
15
|
+
getAvailablePatches(): PatchFile[];
|
|
16
|
+
/**
|
|
17
|
+
* Execute a specific patch
|
|
18
|
+
*/
|
|
19
|
+
runPatch(patchName: string): Promise<void>;
|
|
20
|
+
}
|
|
21
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
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]}),__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 n=function(e){return(n=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=n(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")),child_process_1=require("child_process"),logger_js_1=__importDefault(require("../../../utils/logger.js"));class RunPatchService{environment;patchDir;constructor(e,t){this.environment=t,this.patchDir=path.resolve(process.cwd(),e.patchDir)}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(i){let n=path.join(this.patchDir,i+".patch.ts");if(fs.existsSync(n))return logger_js_1.default.info(`🚀 Running patch "${i}"...`),new Promise((t,r)=>{var e=(0,child_process_1.spawn)("npx",["tsx",n],{stdio:["inherit","inherit","inherit"],shell:!0,cwd:process.cwd(),env:{...process.env,ENVIRONMENT:this.environment.name}});e.on("error",e=>{logger_js_1.default.error("Failed to spawn patch process: "+e.message),r(e)}),e.on("exit",e=>{0===e?(logger_js_1.default.info(`✅ Patch "${i}" completed successfully!`),t()):(e=new Error("Patch exited with code "+e),logger_js_1.default.error(`Failed to run patch "${i}": `+e.message),r(e))})});throw logger_js_1.default.error(`Patch "${i}" not found at `+n),new Error("Patch not found")}}exports.default=RunPatchService;
|
|
@@ -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 @@
|
|
|
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 @@
|
|
|
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;
|
|
@@ -12,7 +12,7 @@ declare class FileService {
|
|
|
12
12
|
getScriptConfig(scriptName: string): string;
|
|
13
13
|
getScriptContent(scriptName: string): string;
|
|
14
14
|
getAbsolutePath(p: string): string;
|
|
15
|
-
tsFileImport<T = any>(
|
|
15
|
+
tsFileImport<T = any>(filePath: string, tsconfigPath?: string): Promise<T>;
|
|
16
16
|
writeScript(scriptName: string, content: string, config: ActionScriptConfig): Promise<void>;
|
|
17
17
|
prettyFile(filePath: string): Promise<void>;
|
|
18
18
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
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,
|
|
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,e){t=this.getAbsolutePath(t),e=e?this.getAbsolutePath(e):void 0;return(await(0,api_1.tsImport)(t,t,{tsconfig:e})).default}async writeScript(t,e,i){var r=this.config.scriptDir+"/"+t,o=((0,fs_1.existsSync)(r)||(0,fs_1.mkdirSync)(r,{recursive:!0}),r+`/${t}.config.ts`);(0,fs_1.writeFileSync)(o,`
|
|
2
2
|
import { type ActionScriptConfig } from "@digital-herd/content-hub-cli";
|
|
3
3
|
export default {
|
|
4
4
|
identifier: "${i.identifier}",
|
|
@@ -7,4 +7,4 @@ var __importDefault=this&&this.__importDefault||function(t){return t&&t.__esModu
|
|
|
7
7
|
description: \`${i.description}\`,
|
|
8
8
|
executeAsUser: ${i.executeAsUser?"true":"false"},
|
|
9
9
|
} as ActionScriptConfig;
|
|
10
|
-
`),await this.prettyFile(
|
|
10
|
+
`),await this.prettyFile(o),(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 @@
|
|
|
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.
|
|
4
|
+
"version": "1.0.4",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "./lib/index.js",
|
|
7
7
|
"types": "./lib/index.d.ts",
|
|
@@ -26,7 +26,6 @@
|
|
|
26
26
|
"@inquirer/input": "^5.0.4",
|
|
27
27
|
"@inquirer/prompts": "^8.2.0",
|
|
28
28
|
"@inquirer/select": "^5.0.4",
|
|
29
|
-
"@sitecore/sc-contenthub-webclient-sdk": "1.2.96",
|
|
30
29
|
"chalk": "^5.6.2",
|
|
31
30
|
"chokidar": "^5.0.0",
|
|
32
31
|
"commander": "^11.0.0",
|
|
@@ -44,5 +43,8 @@
|
|
|
44
43
|
"@types/lodash": "^4.17.23",
|
|
45
44
|
"ts-node": "^10.9.2",
|
|
46
45
|
"typescript": "^5.3.3"
|
|
46
|
+
},
|
|
47
|
+
"peerDependencies": {
|
|
48
|
+
"@sitecore/sc-contenthub-webclient-sdk": "^1.2.96"
|
|
47
49
|
}
|
|
48
50
|
}
|