UNPKG

rucken

Version:

Console tools and scripts for nx and not only that I (EndyKaufman) use to automate the workflow and speed up the development process

87 lines 3.84 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.MakeTsListService = void 0; const tslib_1 = require("tslib"); const common_1 = require("@nestjs/common"); const fs_1 = require("fs"); const log4js_1 = require("log4js"); const path_1 = require("path"); const recursive_readdir_1 = tslib_1.__importDefault(require("recursive-readdir")); const replace_ext_1 = tslib_1.__importDefault(require("replace-ext")); // @ts-expect-error - No type definitions available for sort-paths const sort_paths_1 = tslib_1.__importDefault(require("sort-paths")); const utils_service_1 = require("../utils/utils.service"); let MakeTsListService = class MakeTsListService { utilsService; static title = 'make-ts-list'; logger; constructor(utilsService) { this.utilsService = utilsService; } setLogger(command) { this.logger = (0, log4js_1.getLogger)(command); this.logger.level = utils_service_1.UtilsService.logLevel(); } async makeTsListHandler({ indexFileName, excludes, }) { this.logger.info('Start create list files...'); this.logger.debug(`Config: ${JSON.stringify({ indexFileName, excludes, })}`); const projects = this.utilsService.getWorkspaceProjects(); const projectNames = Object.keys(projects) .filter((projectName) => projects[projectName].projectType === 'library' || projects[projectName].sourceRoot?.substring(0, 5) === 'libs/') .filter((key) => !key.includes('-e2e')); for (const projectName of projectNames) { const project = projects[projectName]; if (project.sourceRoot) { this.logger.debug(`Process library "${projectName}" in ${project.sourceRoot}`); await this.processLibrary({ path: project.sourceRoot, indexFileName, excludes, }); } } this.logger.info('End of create list files...'); } async processLibrary({ path, indexFileName, excludes, }) { const indexFilePath = (0, path_1.resolve)(path, `${indexFileName}.ts`); const newExcludes = ['!*.ts*', ...excludes, indexFilePath]; if (!(0, fs_1.existsSync)(path)) { (0, fs_1.mkdirSync)(path, { recursive: true }); } let files = await (0, recursive_readdir_1.default)(path, newExcludes); files = (0, sort_paths_1.default)(files, path_1.sep); const exportStatements = []; for (const file of files) { const normalizedFile = file.split(path_1.sep).join('/'); let localFile = (0, replace_ext_1.default)(normalizedFile .replace(path, '') .replace(new RegExp(`\\${path_1.sep}`, 'g'), '/'), '') .split(path_1.sep) .join('/'); if (localFile && localFile[0] === '/') { localFile = `.${localFile}`; } if (localFile !== `./${indexFileName}`) { exportStatements.push(`export * from '${localFile}';`); } } const body = `${exportStatements.join('\n')}\n`; if (exportStatements.join('').length > 0) { const indexDir = (0, path_1.dirname)(indexFilePath); if (!(0, fs_1.existsSync)(indexDir)) { (0, fs_1.mkdirSync)(indexDir, { recursive: true }); } (0, fs_1.writeFileSync)(indexFilePath, body); } } }; exports.MakeTsListService = MakeTsListService; exports.MakeTsListService = MakeTsListService = tslib_1.__decorate([ (0, common_1.Injectable)(), tslib_1.__metadata("design:paramtypes", [utils_service_1.UtilsService]) ], MakeTsListService); //# sourceMappingURL=make-ts-list.service.js.map