@analogjs/content
Version:
Content Rendering for Analog
49 lines • 2.22 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = update;
/* eslint-disable @typescript-eslint/no-unused-vars */
const devkit_1 = require("@nx/devkit");
const ts_morph_1 = require("ts-morph");
async function update(host) {
let project;
(0, devkit_1.visitNotIgnoredFiles)(host, '/', (file) => {
if (file.endsWith('.ts')) {
const content = host.read(file, 'utf-8');
if (content &&
content.includes('withMarkdownRenderer') &&
!content.includes('withPrismHighlighter') &&
!content.includes('withShikiHighlighter')) {
if (!project) {
project = new ts_morph_1.Project({
useInMemoryFileSystem: true,
skipAddingFilesFromTsConfig: true,
});
}
const sourceFile = project.createSourceFile(file, content);
const provideContentNode = sourceFile.getFirstDescendant((node) => ts_morph_1.Node.isCallExpression(node) &&
node.getText().includes('provideContent') &&
node.getText().includes('withMarkdownRenderer'));
if (provideContentNode) {
sourceFile.addImportDeclaration({
moduleSpecifier: '@analogjs/content/prism-highlighter',
namedImports: ['withPrismHighlighter'],
});
provideContentNode.addArgument('withPrismHighlighter()');
}
host.write(file, sourceFile.getFullText());
}
}
});
// NOTE: we only add the dependency if the project is an Angular project
// Nx projects can add the dependency from migrations.json
let dependencyAdded = false;
if (host.exists('/angular.json')) {
(0, devkit_1.addDependenciesToPackageJson)(host, { 'marked-mangle': '^1.1.7' }, {});
dependencyAdded = true;
}
await (0, devkit_1.formatFiles)(host);
if (dependencyAdded) {
return () => (0, devkit_1.installPackagesTask)(host);
}
}
//# sourceMappingURL=update-markdown-renderer-feature.js.map