From 97303510483c898b0de12a0112398e84e593f064 Mon Sep 17 00:00:00 2001 From: Peter Bacon Darwin Date: Thu, 20 Apr 2017 20:33:47 +0100 Subject: [PATCH] build(aio): compute which examples to include when watching guide docs (#16213) PR Close #16213 --- .../authors-package/guide-package.js | 27 ++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/aio/tools/transforms/authors-package/guide-package.js b/aio/tools/transforms/authors-package/guide-package.js index 28166db3de..dbf155c184 100644 --- a/aio/tools/transforms/authors-package/guide-package.js +++ b/aio/tools/transforms/authors-package/guide-package.js @@ -5,22 +5,37 @@ * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ -const Package = require('dgeni').Package; -const { basePackage, CONTENTS_PATH, getBoilerPlateExcludes } = require('./base-package'); -function createPackage(exampleName) { +/* eslint no-console: "off" */ + +const Package = require('dgeni').Package; +const { basePackage, CONTENTS_PATH } = require('./base-package'); +const { readFileSync } = require('fs'); +const { resolve } = require('canonical-path'); + +function createPackage(guideName) { + + const guideFilePath = `${CONTENTS_PATH}/guide/${guideName}.md`; + const guideFile = readFileSync(guideFilePath, 'utf8'); + const examples = []; + guideFile.replace(/]*path="([^"]+)"/g, (_, path) => examples.push('examples/' + path)); + + if (examples.length) { + console.log('The following example files are referenced in this guide:'); + console.log(examples.map(example => ' - ' + example).join('\n')); + } + return new Package('author-guide', [basePackage]) .config(function(readFilesProcessor) { readFilesProcessor.sourceFiles = [ { basePath: CONTENTS_PATH, - include: `${CONTENTS_PATH}/guide/${exampleName}.md`, + include: guideFilePath, fileReader: 'contentFileReader' }, { basePath: CONTENTS_PATH, - include: `${CONTENTS_PATH}/examples/*${exampleName}/**/*`, - exclude: getBoilerPlateExcludes(), + include: examples.map(example => resolve(CONTENTS_PATH, example)), fileReader: 'exampleFileReader' } ];