build(docs-infra): improve docs-watch example matching (#40479)

In the `docs-watch` job we attempt to guess what additional files need
to be processed given a change to a single file. Previously we were not
finding links to examples that were defined over multiple lines. E.g.

```
<code-pane
  header="src/app/app.component.html"
  region="hero-birthday-template"
  path="pipes/src/app/app.component.html">
</code-pane>
```

This commit improves the regular expression to handle these cases.

PR Close #40479
This commit is contained in:
Pete Bacon Darwin 2021-01-18 14:55:04 +00:00 committed by Jessica Janiuk
parent c6a2267bb4
commit 5dd604a15d
4 changed files with 59 additions and 62 deletions

View File

@ -6,20 +6,21 @@
* found in the LICENSE file at https://angular.io/license
*/
const {resolve} = require('canonical-path');
const Package = require('dgeni').Package;
const {readFileSync} = require('fs');
const contentPackage = require('../angular-content-package');
const { readFileSync } = require('fs');
const { resolve } = require('canonical-path');
const { CONTENTS_PATH } = require('../config');
const {CONTENTS_PATH} = require('../config');
const {codeExampleMatcher} = require('./utils');
/* eslint no-console: "off" */
function createPackage(tutorialName) {
const tutorialFilePath = `${CONTENTS_PATH}/start/${tutorialName}.md`;
const tutorialFile = readFileSync(tutorialFilePath, 'utf8');
const examples = [];
tutorialFile.replace(/<code-(?:pane|example) [^>]*path="([^"]+)"/g, (_, path) => examples.push('examples/' + path));
tutorialFile.replace(codeExampleMatcher, (_, path) => examples.push('examples/' + path));
if (examples.length) {
console.log('The following example files are referenced in this getting-started:');
@ -27,21 +28,16 @@ function createPackage(tutorialName) {
}
return new Package('author-getting-started', [contentPackage])
.config(function(readFilesProcessor) {
readFilesProcessor.sourceFiles = [
{
basePath: CONTENTS_PATH,
include: tutorialFilePath,
fileReader: 'contentFileReader'
},
{
basePath: CONTENTS_PATH,
include: examples.map(example => resolve(CONTENTS_PATH, example)),
fileReader: 'exampleFileReader'
}
];
});
.config(function(readFilesProcessor) {
readFilesProcessor.sourceFiles = [
{basePath: CONTENTS_PATH, include: tutorialFilePath, fileReader: 'contentFileReader'}, {
basePath: CONTENTS_PATH,
include: examples.map(example => resolve(CONTENTS_PATH, example)),
fileReader: 'exampleFileReader'
}
];
});
}
module.exports = { createPackage };
module.exports = {createPackage};

View File

@ -8,39 +8,34 @@
/* eslint no-console: "off" */
const {resolve} = require('canonical-path');
const Package = require('dgeni').Package;
const {readFileSync} = require('fs');
const contentPackage = require('../angular-content-package');
const { readFileSync } = require('fs');
const { resolve } = require('canonical-path');
const { CONTENTS_PATH } = require('../config');
const {CONTENTS_PATH} = require('../config');
const {codeExampleMatcher} = require('./utils');
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));
guideFile.replace(codeExampleMatcher, (_, 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', [contentPackage])
.config(function(readFilesProcessor) {
readFilesProcessor.sourceFiles = [
{
basePath: CONTENTS_PATH,
include: guideFilePath,
fileReader: 'contentFileReader'
},
{
basePath: CONTENTS_PATH,
include: examples.map(example => resolve(CONTENTS_PATH, example)),
fileReader: 'exampleFileReader'
}
];
});
return new Package('author-guide', [contentPackage]).config(function(readFilesProcessor) {
readFilesProcessor.sourceFiles = [
{basePath: CONTENTS_PATH, include: guideFilePath, fileReader: 'contentFileReader'}, {
basePath: CONTENTS_PATH,
include: examples.map(example => resolve(CONTENTS_PATH, example)),
fileReader: 'exampleFileReader'
}
];
});
}
module.exports = { createPackage };
module.exports = {createPackage};

View File

@ -6,42 +6,37 @@
* found in the LICENSE file at https://angular.io/license
*/
const {resolve} = require('canonical-path');
const Package = require('dgeni').Package;
const {readFileSync} = require('fs');
const contentPackage = require('../angular-content-package');
const { readFileSync } = require('fs');
const { resolve } = require('canonical-path');
const { CONTENTS_PATH } = require('../config');
const {CONTENTS_PATH} = require('../config');
const {codeExampleMatcher} = require('./utils');
/* eslint no-console: "off" */
function createPackage(tutorialName) {
const tutorialFilePath = `${CONTENTS_PATH}/tutorial/${tutorialName}.md`;
const tutorialFile = readFileSync(tutorialFilePath, 'utf8');
const examples = [];
tutorialFile.replace(/<code-(?:pane|example) [^>]*path="([^"]+)"/g, (_, path) => examples.push('examples/' + path));
tutorialFile.replace(codeExampleMatcher, (_, path) => examples.push('examples/' + path));
if (examples.length) {
console.log('The following example files are referenced in this tutorial:');
console.log(examples.map(example => ' - ' + example).join('\n'));
}
return new Package('author-tutorial', [contentPackage])
.config(function(readFilesProcessor) {
readFilesProcessor.sourceFiles = [
{
basePath: CONTENTS_PATH,
include: tutorialFilePath,
fileReader: 'contentFileReader'
},
{
basePath: CONTENTS_PATH,
include: examples.map(example => resolve(CONTENTS_PATH, example)),
fileReader: 'exampleFileReader'
}
];
});
return new Package('author-tutorial', [contentPackage]).config(function(readFilesProcessor) {
readFilesProcessor.sourceFiles = [
{basePath: CONTENTS_PATH, include: tutorialFilePath, fileReader: 'contentFileReader'}, {
basePath: CONTENTS_PATH,
include: examples.map(example => resolve(CONTENTS_PATH, example)),
fileReader: 'exampleFileReader'
}
];
});
}
module.exports = { createPackage };
module.exports = {createPackage};

View File

@ -0,0 +1,11 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* 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
*/
module.exports = {
codeExampleMatcher: /<code-(?:pane|example)[^>]*\bpath="([^"]+)"/g,
};