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

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.
@@ -1 +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;
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={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;
@@ -1 +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]};
1
+ Object.defineProperty(exports,"__esModule",{value:!0});let PublishScriptCommand_1=require("./commands/PublishScriptCommand"),SyncScriptsFromEnvironmentCommand_1=require("./commands/SyncScriptsFromEnvironmentCommand"),CreateScriptCommand_1=require("./commands/CreateScriptCommand");exports.default={commands:[PublishScriptCommand_1.publishScriptCommand,CreateScriptCommand_1.createScriptCommand,SyncScriptsFromEnvironmentCommand_1.syncScriptsFromEnvironmentCommand]};
@@ -1,4 +1,4 @@
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";
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 "@digital-herd/content-hub-cli";
2
2
 
3
3
  export default {
4
4
  identifier: "${r.identifier}",
@@ -4,7 +4,6 @@ import FileService from "../../../services/FileService";
4
4
  declare class SyncScriptService {
5
5
  contenthubService: ContenthubService;
6
6
  config: ContenthubConfig;
7
- static IgnoreUserScriptsOnSyncAll: string[];
8
7
  fileService: FileService;
9
8
  constructor(contenthubService: ContenthubService, config: ContenthubConfig);
10
9
  syncAllScripts(): Promise<void>;
@@ -1 +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;
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"),logger_1=__importDefault(require("../../../utils/logger")),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;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){var e=Array.isArray(t)?t:[t],t=e.flatMap(t=>{var e=t.getRelation("ScriptToActiveScriptContent")?.getIds();return e?.length?e||[]:t.getRelation("ScriptToDraftScriptContent")?.getIds()||[]}),i=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 e){let e=t.getRelation("ScriptToActiveScriptContent")?.getIds()[0];var r=i.find(t=>t.id===e);r&&await this.syncScriptInFolder(t,r)}}async syncScriptInFolder(t,e){var i=t.getPropertyValue("M.Script.Name"),r=(0,script_js_1.scriptNameToSlug)(i),c=this.fileService.getScriptConfig(i);let n={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(c){let t=await this.fileService.tsFileImport(c);if(n.identifier!==t.identifier)throw new Error("Identifier in local folder does not match with environment");n=t}await this.fileService.writeScript(r,e.getPropertyValue("M.ScriptContent.Script"),n)}async loadAllScripts(){logger_1.default.info("Load all scripts");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||[]);return logger_1.default.info("All scripts loaded"),e}}exports.default=SyncScriptService;
@@ -1,5 +1,5 @@
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";
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 i=t.getRelation("AssetToPageComponent")?.getIds()||[];t=(await(0,apiCatch_1.apiErrorCatch)(()=>this.contenthubService.client.entities.getManyAsync(i,sc_contenthub_webclient_sdk_1.EntityLoadConfiguration.Full))).reduce((e,t)=>{let i=t.getPropertyValue("PageComponent.Settings").config;var n=e.find(e=>(0,lodash_1.isEqual)(e.config,i));return n?n.pageComponentIdentifiers.push(t.identifier):e.push({pageComponentIdentifiers:[t.identifier],config:i}),e},[]);this.writeConfigFile(e,{components:t})}writeConfigFile(e,t){var i=this.externalComponentsService.getDirectoryOfComponent(e);(0,fs_1.writeFileSync)(i+`/${e}.config.ts`,`
2
+ import { type ExternalComponentConfig } from "@digital-herd/content-hub-cli";
3
3
 
4
4
  export default ${JSON.stringify(t)} as ExternalComponentConfig;
5
5
 
@@ -1 +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;
1
+ var __importDefault=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};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"),logger_js_1=__importDefault(require("../utils/logger.js"));class ContenthubService{client;entityIdMapping=new Map;constructor(t,e){e&&e.length||(logger_js_1.default.error("Api token is invalid"),process.exit(-1)),logger_js_1.default.info("Contenthub endpoint: "+t),this.client=new sc_contenthub_webclient_sdk_1.ContentHubClient(t),this.client.internalClient.setRequestHeaders({"x-auth-token":e})}async validateClient(){await(0,apiCatch_js_1.apiErrorCatch)(()=>this.client.internalClient.authenticateAsync())||(logger_js_1.default.error("Authentication failed with endpoint + api token"),process.exit(-1))}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;
@@ -1,5 +1,5 @@
1
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";
2
+ import { type ActionScriptConfig } from "@digital-herd/content-hub-cli";
3
3
  export default {
4
4
  identifier: "${i.identifier}",
5
5
  type: "${i.type}",
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.1",
4
+ "version": "1.0.2",
5
5
  "type": "commonjs",
6
6
  "main": "./lib/index.js",
7
7
  "types": "./lib/index.d.ts",