@nx/angular
Version:
36 lines (35 loc) • 1.89 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.exportScam = exportScam;
const devkit_1 = require("@nx/devkit");
const entry_point_1 = require("./entry-point");
const path_1 = require("./path");
function exportScam(tree, options) {
if (!options.export) {
return;
}
const { projectType, root, sourceRoot } = (0, devkit_1.readProjectConfiguration)(tree, options.projectName);
const projectSourceRoot = sourceRoot ?? (0, devkit_1.joinPathFragments)(root, 'src');
if (projectType === 'application') {
devkit_1.logger.warn('--export=true was ignored as the project the SCAM is being generated in is not a library.');
return;
}
const entryPointPath = (0, entry_point_1.locateLibraryEntryPointFromDirectory)(tree, options.directory, root, projectSourceRoot);
if (!entryPointPath) {
// Let's not error, simply warn the user
// It's not too much effort to manually do this
// It would be more frustrating to have to find the correct path and re-run the command
devkit_1.logger.warn(`Could not export SCAM. Unable to determine project's entry point. SCAM has still been created.`);
return;
}
const relativePathFromEntryPoint = (0, path_1.getRelativeImportToFile)(entryPointPath, options.filePath);
const entryPointContent = tree.read(entryPointPath, 'utf-8');
let updatedEntryPointContent = (0, devkit_1.stripIndents) `${entryPointContent}
export * from '${relativePathFromEntryPoint}';`;
if (!options.inlineScam) {
const relativePathFromModule = (0, path_1.getRelativeImportToFile)(entryPointPath, options.modulePath);
updatedEntryPointContent = (0, devkit_1.stripIndents) `${updatedEntryPointContent}
export * from '${relativePathFromModule}';`;
}
tree.write(entryPointPath, updatedEntryPointContent);
}