@digital-herd/content-hub-cli 1.1.5 → 1.1.7
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/bin.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
var __importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0});let commander_1=require("commander"),modules_1=__importDefault(require("./modules")),program=new commander_1.Command;program.name("content-hub-tools").description("ContentHub build & utility CLI").version("1.1.
|
|
2
|
+
var __importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0});let commander_1=require("commander"),modules_1=__importDefault(require("./modules")),program=new commander_1.Command;program.name("content-hub-tools").description("ContentHub build & utility CLI").version("1.1.7");for(let o of modules_1.default)for(let e of o.commands)program.addCommand(e);program.parse(process.argv);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var __importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0});let FileService_1=__importDefault(require("../../../services/FileService")),vite_1=require("vite"),path_1=__importDefault(require("path")),lodash_1=require("lodash"),array_1=require("../../../utils/array"),logger_1=__importDefault(require("../../..//utils/logger")),TypeCheckService_1=__importDefault(require("./TypeCheckService")),tempDirectory_1=require("../../../config/tempDirectory"),fs_1=__importDefault(require("fs")),zlib_1=require("zlib");class ExternalComponentBuildService{fileService;typeCheck;constructor(e,i){this.fileService=new FileService_1.default(e),this.typeCheck=new TypeCheckService_1.default(e,i)}async buildAll(){var e=this.fileService.getAllComponentNames(),i=await this.getViteConfigs(e),t=(await this.typeCheck.all(),(0,array_1.arrayToChunks)(i,5));for(let e=0;e<t.length;e++)logger_1.default.info(`Building batch ${e+1}/${t.length}...`),await Promise.all(t[e].map(e=>(0,vite_1.build)(e))),this.logBuildSizes(t[e].map(e=>e.build.lib.fileName)),logger_1.default.info(`Batch ${e+1}/${t.length} finished`);return logger_1.default.info(`All ${e.length} components built successfully`),e}async build(e){e=Array.isArray(e)?e:[e];let i=this.fileService.getAllComponentNames();
|
|
1
|
+
var __importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0});let FileService_1=__importDefault(require("../../../services/FileService")),vite_1=require("vite"),path_1=__importDefault(require("path")),lodash_1=require("lodash"),array_1=require("../../../utils/array"),logger_1=__importDefault(require("../../..//utils/logger")),TypeCheckService_1=__importDefault(require("./TypeCheckService")),tempDirectory_1=require("../../../config/tempDirectory"),fs_1=__importDefault(require("fs")),zlib_1=require("zlib");class ExternalComponentBuildService{fileService;typeCheck;constructor(e,i){this.fileService=new FileService_1.default(e),this.typeCheck=new TypeCheckService_1.default(e,i)}async buildAll(){var e=this.fileService.getAllComponentNames(),i=await this.getViteConfigs(e),t=(await this.typeCheck.all(),(0,array_1.arrayToChunks)(i,5));for(let e=0;e<t.length;e++)logger_1.default.info(`Building batch ${e+1}/${t.length}...`),await Promise.all(t[e].map(e=>(0,vite_1.build)(e))),this.logBuildSizes(t[e].map(e=>e.build.lib.fileName)),logger_1.default.info(`Batch ${e+1}/${t.length} finished`);return logger_1.default.info(`All ${e.length} components built successfully`),e}async build(e){e=Array.isArray(e)?e:[e];let i=this.fileService.getAllComponentNames();var t=e.filter(e=>!i.includes(e)),t=(t.length&&(logger_1.default.error(t.join(", ")+" components not found"),process.exit(-1)),await this.typeCheck.specificComponents(e),await this.getViteConfigs(e)),l=(0,array_1.arrayToChunks)(t,5);for(let e=0;e<l.length;e++)logger_1.default.info(`Building component batch ${e+1}/${l.length}...`),await Promise.all(l[e].map(e=>(0,vite_1.build)(e))),this.logBuildSizes(l[e].map(e=>e.build.lib.fileName)),logger_1.default.info(`Component Batch ${e+1}/${l.length} finished`);return logger_1.default.info(e.length+" component(s) built successfully"),e}async getViteConfigs(e){var i=path_1.default.resolve(process.cwd(),"vite.config.js");let l=await(0,vite_1.loadConfigFromFile)({command:"build",mode:"production"},i);if(l)return e.map(e=>{var i=this.fileService.getEntryOfComponent(e),t=(0,lodash_1.cloneDeep)(l.config);return t.build.lib={formats:["es"],fileName:e,entry:i},t.build.outDir=tempDirectory_1.BUILD_DIRECTORY,t.build.emptyOutDir=!1,t.mode="production",t.logLevel="warn",t});throw new Error("Vite config not found")}logBuildSizes(e){e.forEach(e=>{var i,t,l=path_1.default.join(tempDirectory_1.BUILD_DIRECTORY,e+".js");fs_1.default.existsSync(l)&&(i=(l=fs_1.default.readFileSync(l)).length,l=(0,zlib_1.gzipSync)(l).length,t=e=>e<1024?e+" B":e<1048576?(e/1024).toFixed(2)+" KB":(e/1048576).toFixed(2)+" MB",logger_1.default.info(` ${e}.js: ${t(i)} (gzip: ${t(l)})`))})}}exports.default=ExternalComponentBuildService;
|
|
@@ -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={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){
|
|
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){throw(0,fs_1.unlinkSync)(t),new Error("TypeScript type check failed")}}}exports.default=TypeCheckService;
|
|
@@ -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")),url_1=require("url"),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(path_1.default.sep)
|
|
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")),url_1=require("url"),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(path_1.default.sep);return t[t.length-2]})}getDirectoryOfComponent(t){var t=(0,glob_1.sync)(this.config.componentDir+`/**/${t}/*.tsx`)[0];return t?((t=t.split(path_1.default.sep)).pop(),t.join(path_1.default.sep)):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,t=(0,url_1.pathToFileURL)(t).href,e=e?(0,url_1.pathToFileURL)(e).href: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}",
|
package/package.json
CHANGED