build(aio): compute which examples to include when watching guide docs (#16213)
PR Close #16213
This commit is contained in:
parent
ce687550ae
commit
9730351048
|
@ -5,22 +5,37 @@
|
||||||
* Use of this source code is governed by an MIT-style license that can be
|
* 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
|
* 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(/<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'));
|
||||||
|
}
|
||||||
|
|
||||||
return new Package('author-guide', [basePackage])
|
return new Package('author-guide', [basePackage])
|
||||||
.config(function(readFilesProcessor) {
|
.config(function(readFilesProcessor) {
|
||||||
readFilesProcessor.sourceFiles = [
|
readFilesProcessor.sourceFiles = [
|
||||||
{
|
{
|
||||||
basePath: CONTENTS_PATH,
|
basePath: CONTENTS_PATH,
|
||||||
include: `${CONTENTS_PATH}/guide/${exampleName}.md`,
|
include: guideFilePath,
|
||||||
fileReader: 'contentFileReader'
|
fileReader: 'contentFileReader'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
basePath: CONTENTS_PATH,
|
basePath: CONTENTS_PATH,
|
||||||
include: `${CONTENTS_PATH}/examples/*${exampleName}/**/*`,
|
include: examples.map(example => resolve(CONTENTS_PATH, example)),
|
||||||
exclude: getBoilerPlateExcludes(),
|
|
||||||
fileReader: 'exampleFileReader'
|
fileReader: 'exampleFileReader'
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
Loading…
Reference in New Issue