UNPKG

@ng-doc/builder

Version:

<!-- PROJECT LOGO --> <br /> <div align="center"> <a href="https://github.com/ng-doc/ng-doc"> <img src="https://ng-doc.com/assets/images/ng-doc.svg?raw=true" alt="Logo" height="150px"> </a>

45 lines 2.05 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PAGE_PLAYGROUND_BUILDER_TAG = void 0; exports.playgroundBuilder = playgroundBuilder; const tslib_1 = require("tslib"); const builder_1 = require("@ng-doc/builder"); const path = tslib_1.__importStar(require("path")); const rxjs_1 = require("rxjs"); const helpers_1 = require("../../../helpers"); const core_1 = require("../../core"); exports.PAGE_PLAYGROUND_BUILDER_TAG = 'PagePlayground'; /** * * @param config */ function playgroundBuilder(config) { const { page } = config; const references = (0, helpers_1.getPlaygroundsClassDeclarations)(page.objectExpression()).map((classDeclaration) => classDeclaration.getSourceFile()); const outPath = path.join(page.outDir, 'playgrounds.ts'); const cacheStrategy = { id: `${page.path}#Playground`, action: 'skip', files: () => [page.path, outPath, ...references.map((sourceFile) => sourceFile.getFilePath())], }; const builder = (0, rxjs_1.of)(void 0).pipe((0, builder_1.runBuild)(exports.PAGE_PLAYGROUND_BUILDER_TAG, async () => { references.forEach((sourceFile) => { sourceFile.refreshFromFileSystemSync(); }); const playgroundMetadata = (0, builder_1.getPlaygroundMetadata)(page.entry, page.objectExpression()); return { filePath: outPath, content: (0, builder_1.renderTemplate)('./playgrounds.ts.nunj', { context: { playgroundMetadata, hasImports: !!page.objectExpression().getProperty('imports'), entryImportPath: (0, builder_1.createImportPath)(page.outDir, path.join(page.dir, builder_1.PAGE_NAME)), }, }), }; }, cacheStrategy)); return (0, builder_1.createBuilder)([ (0, builder_1.createMainTrigger)(...references.map((sourceFile) => (0, core_1.watchFile)(sourceFile.getFilePath(), 'update'))), ], () => builder); } //# sourceMappingURL=playground.builder.js.map