message: build(aio): compute which examples to include when watching guide docs
  PR Close
diff: * 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
  */
  +
  +/* eslint no-console: "off" */
  +
  const Package = require('dgeni').Package;
  -const { basePackage, CONTENTS_PATH, getBoilerPlateExcludes } = require('./base-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(/<code-(?:pane|example) [^>]*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'));
  + }
  -function createPackage(exampleName) {
  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'
  }
  ];
  