@digital-herd/content-hub-cli 1.0.3 → 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/lib/index.d.ts +1 -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/runPatch.js +1 -1
- package/lib/modules/manual-patches/index.d.ts +2 -0
- package/lib/modules/manual-patches/index.js +1 -1
- package/lib/modules/manual-patches/services/CreatePatchService.js +6 -4
- 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 +3 -5
- package/lib/modules/manual-patches/services/RunPatchService.js +1 -1
- package/lib/services/FileService.d.ts +1 -1
- package/lib/services/FileService.js +2 -2
- package/package.json +4 -2
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")),manual_patches_1=__importDefault(require("./manual-patches"));exports.default=[external_components_1.default,scripts_1.default,manual_patches_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];
|
|
@@ -1 +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,
|
|
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)}});
|
|
@@ -1 +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]};
|
|
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]};
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
var __createBinding=this&&this.__createBinding||(Object.create?function(t,
|
|
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
2
|
|
|
3
|
+
const patchService = new PatchService();
|
|
3
4
|
|
|
4
5
|
|
|
5
|
-
const runPatch${
|
|
6
|
+
const runPatch${e} = async () => {
|
|
7
|
+
const client = await patchService.getClient();
|
|
6
8
|
// run patch
|
|
7
9
|
};
|
|
8
10
|
|
|
9
|
-
export default runPatch${
|
|
10
|
-
`;fs.writeFileSync(
|
|
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;
|
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
import { ContenthubConfig } from "../../../types/ContentHubConfig.interface.js";
|
|
2
|
-
import
|
|
2
|
+
import { ContenthubEnvironment } from "../../../types/ContentHubConfig.interface.js";
|
|
3
3
|
interface PatchFile {
|
|
4
4
|
name: string;
|
|
5
5
|
path: string;
|
|
6
6
|
modifiedTime: Date;
|
|
7
7
|
}
|
|
8
8
|
export default class RunPatchService {
|
|
9
|
-
private
|
|
10
|
-
private config;
|
|
9
|
+
private environment;
|
|
11
10
|
private patchDir;
|
|
12
|
-
|
|
13
|
-
constructor(contenthubService: ContenthubService, config: ContenthubConfig);
|
|
11
|
+
constructor(config: ContenthubConfig, environment: ContenthubEnvironment);
|
|
14
12
|
/**
|
|
15
13
|
* Get all available patch files sorted by last modified (newest first)
|
|
16
14
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var __createBinding=this&&this.__createBinding||(Object.create?function(e,t,r,i){void 0===i&&(i=r);var
|
|
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;
|
|
@@ -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;
|
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
|
}
|