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
88 lines (87 loc) • 4.12 kB
JavaScript
;
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"));
const sort_paths_1 = tslib_1.__importDefault(require("sort-paths"));
const utils_service_1 = require("../utils/utils.service");
let MakeTsListService = class MakeTsListService {
constructor(utilsService) {
this.utilsService = utilsService;
}
setLogger(command) {
this.logger = (0, log4js_1.getLogger)(command);
this.logger.level = utils_service_1.UtilsService.logLevel();
}
makeTsListHandler({ indexFileName, excludes, }) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
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) => {
var _a;
return projects[projectName].projectType === 'library' ||
((_a = projects[projectName].sourceRoot) === null || _a === void 0 ? void 0 : _a.substring(0, 5)) === 'libs/';
})
.filter((key) => !key.includes('-e2e'));
for (let index = 0; index < projectNames.length; index++) {
const projectName = projectNames[index];
if (projects[projectName].sourceRoot) {
this.logger.debug(`Process library "${projectName}" in ${projects[projectName].sourceRoot}`);
yield this.processLibrary({
path: projects[projectName].sourceRoot,
indexFileName,
excludes,
});
}
}
this.logger.info('End of create list files...');
});
}
processLibrary({ path, indexFileName, excludes, }) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
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 = yield (0, recursive_readdir_1.default)(path, newExcludes);
files = (0, sort_paths_1.default)(files, path_1.sep);
const list = [];
for (let findex = 0; findex < files.length; findex++) {
const file = files[findex].split(path_1.sep).join('/');
let localFile = (0, replace_ext_1.default)(file.replace(path, '').replace(new RegExp(`\\${path_1.sep}`, 'g'), '/'), '')
.split(path_1.sep)
.join('/');
if (localFile && localFile[0] === '/') {
localFile = `.${localFile}`;
}
if (localFile !== `./${indexFileName}`) {
list.push(`export * from '${localFile}';`);
}
}
const body = `${list.join('\n')}\n`;
if (list.join('').length > 0) {
if (!(0, fs_1.existsSync)((0, path_1.dirname)(indexFilePath))) {
(0, fs_1.mkdirSync)((0, path_1.dirname)(indexFilePath), { recursive: true });
}
(0, fs_1.writeFileSync)(indexFilePath, body);
}
});
}
};
MakeTsListService.title = 'make-ts-list';
MakeTsListService = tslib_1.__decorate([
(0, common_1.Injectable)(),
tslib_1.__metadata("design:paramtypes", [utils_service_1.UtilsService])
], MakeTsListService);
exports.MakeTsListService = MakeTsListService;