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:
parent
c6a2267bb4
commit
5dd604a15d
@ -6,20 +6,21 @@
|
|||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
const {resolve} = require('canonical-path');
|
||||||
const Package = require('dgeni').Package;
|
const Package = require('dgeni').Package;
|
||||||
|
const {readFileSync} = require('fs');
|
||||||
|
|
||||||
const contentPackage = require('../angular-content-package');
|
const contentPackage = require('../angular-content-package');
|
||||||
const { readFileSync } = require('fs');
|
const {CONTENTS_PATH} = require('../config');
|
||||||
const { resolve } = require('canonical-path');
|
const {codeExampleMatcher} = require('./utils');
|
||||||
const { CONTENTS_PATH } = require('../config');
|
|
||||||
|
|
||||||
/* eslint no-console: "off" */
|
/* eslint no-console: "off" */
|
||||||
|
|
||||||
function createPackage(tutorialName) {
|
function createPackage(tutorialName) {
|
||||||
|
|
||||||
const tutorialFilePath = `${CONTENTS_PATH}/start/${tutorialName}.md`;
|
const tutorialFilePath = `${CONTENTS_PATH}/start/${tutorialName}.md`;
|
||||||
const tutorialFile = readFileSync(tutorialFilePath, 'utf8');
|
const tutorialFile = readFileSync(tutorialFilePath, 'utf8');
|
||||||
const examples = [];
|
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) {
|
if (examples.length) {
|
||||||
console.log('The following example files are referenced in this getting-started:');
|
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])
|
return new Package('author-getting-started', [contentPackage])
|
||||||
.config(function(readFilesProcessor) {
|
.config(function(readFilesProcessor) {
|
||||||
readFilesProcessor.sourceFiles = [
|
readFilesProcessor.sourceFiles = [
|
||||||
{
|
{basePath: CONTENTS_PATH, include: tutorialFilePath, fileReader: 'contentFileReader'}, {
|
||||||
basePath: CONTENTS_PATH,
|
basePath: CONTENTS_PATH,
|
||||||
include: tutorialFilePath,
|
include: examples.map(example => resolve(CONTENTS_PATH, example)),
|
||||||
fileReader: 'contentFileReader'
|
fileReader: 'exampleFileReader'
|
||||||
},
|
}
|
||||||
{
|
];
|
||||||
basePath: CONTENTS_PATH,
|
});
|
||||||
include: examples.map(example => resolve(CONTENTS_PATH, example)),
|
|
||||||
fileReader: 'exampleFileReader'
|
|
||||||
}
|
|
||||||
];
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
module.exports = { createPackage };
|
module.exports = {createPackage};
|
||||||
|
@ -8,39 +8,34 @@
|
|||||||
|
|
||||||
/* eslint no-console: "off" */
|
/* eslint no-console: "off" */
|
||||||
|
|
||||||
|
const {resolve} = require('canonical-path');
|
||||||
const Package = require('dgeni').Package;
|
const Package = require('dgeni').Package;
|
||||||
|
const {readFileSync} = require('fs');
|
||||||
|
|
||||||
const contentPackage = require('../angular-content-package');
|
const contentPackage = require('../angular-content-package');
|
||||||
const { readFileSync } = require('fs');
|
const {CONTENTS_PATH} = require('../config');
|
||||||
const { resolve } = require('canonical-path');
|
const {codeExampleMatcher} = require('./utils');
|
||||||
const { CONTENTS_PATH } = require('../config');
|
|
||||||
|
|
||||||
function createPackage(guideName) {
|
function createPackage(guideName) {
|
||||||
|
|
||||||
const guideFilePath = `${CONTENTS_PATH}/guide/${guideName}.md`;
|
const guideFilePath = `${CONTENTS_PATH}/guide/${guideName}.md`;
|
||||||
const guideFile = readFileSync(guideFilePath, 'utf8');
|
const guideFile = readFileSync(guideFilePath, 'utf8');
|
||||||
const examples = [];
|
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) {
|
if (examples.length) {
|
||||||
console.log('The following example files are referenced in this guide:');
|
console.log('The following example files are referenced in this guide:');
|
||||||
console.log(examples.map(example => ' - ' + example).join('\n'));
|
console.log(examples.map(example => ' - ' + example).join('\n'));
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Package('author-guide', [contentPackage])
|
return new Package('author-guide', [contentPackage]).config(function(readFilesProcessor) {
|
||||||
.config(function(readFilesProcessor) {
|
readFilesProcessor.sourceFiles = [
|
||||||
readFilesProcessor.sourceFiles = [
|
{basePath: CONTENTS_PATH, include: guideFilePath, fileReader: 'contentFileReader'}, {
|
||||||
{
|
basePath: CONTENTS_PATH,
|
||||||
basePath: CONTENTS_PATH,
|
include: examples.map(example => resolve(CONTENTS_PATH, example)),
|
||||||
include: guideFilePath,
|
fileReader: 'exampleFileReader'
|
||||||
fileReader: 'contentFileReader'
|
}
|
||||||
},
|
];
|
||||||
{
|
});
|
||||||
basePath: CONTENTS_PATH,
|
|
||||||
include: examples.map(example => resolve(CONTENTS_PATH, example)),
|
|
||||||
fileReader: 'exampleFileReader'
|
|
||||||
}
|
|
||||||
];
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = { createPackage };
|
module.exports = {createPackage};
|
||||||
|
@ -6,42 +6,37 @@
|
|||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
const {resolve} = require('canonical-path');
|
||||||
const Package = require('dgeni').Package;
|
const Package = require('dgeni').Package;
|
||||||
|
const {readFileSync} = require('fs');
|
||||||
|
|
||||||
const contentPackage = require('../angular-content-package');
|
const contentPackage = require('../angular-content-package');
|
||||||
const { readFileSync } = require('fs');
|
const {CONTENTS_PATH} = require('../config');
|
||||||
const { resolve } = require('canonical-path');
|
const {codeExampleMatcher} = require('./utils');
|
||||||
const { CONTENTS_PATH } = require('../config');
|
|
||||||
|
|
||||||
/* eslint no-console: "off" */
|
/* eslint no-console: "off" */
|
||||||
|
|
||||||
function createPackage(tutorialName) {
|
function createPackage(tutorialName) {
|
||||||
|
|
||||||
const tutorialFilePath = `${CONTENTS_PATH}/tutorial/${tutorialName}.md`;
|
const tutorialFilePath = `${CONTENTS_PATH}/tutorial/${tutorialName}.md`;
|
||||||
const tutorialFile = readFileSync(tutorialFilePath, 'utf8');
|
const tutorialFile = readFileSync(tutorialFilePath, 'utf8');
|
||||||
const examples = [];
|
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) {
|
if (examples.length) {
|
||||||
console.log('The following example files are referenced in this tutorial:');
|
console.log('The following example files are referenced in this tutorial:');
|
||||||
console.log(examples.map(example => ' - ' + example).join('\n'));
|
console.log(examples.map(example => ' - ' + example).join('\n'));
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Package('author-tutorial', [contentPackage])
|
return new Package('author-tutorial', [contentPackage]).config(function(readFilesProcessor) {
|
||||||
.config(function(readFilesProcessor) {
|
readFilesProcessor.sourceFiles = [
|
||||||
readFilesProcessor.sourceFiles = [
|
{basePath: CONTENTS_PATH, include: tutorialFilePath, fileReader: 'contentFileReader'}, {
|
||||||
{
|
basePath: CONTENTS_PATH,
|
||||||
basePath: CONTENTS_PATH,
|
include: examples.map(example => resolve(CONTENTS_PATH, example)),
|
||||||
include: tutorialFilePath,
|
fileReader: 'exampleFileReader'
|
||||||
fileReader: 'contentFileReader'
|
}
|
||||||
},
|
];
|
||||||
{
|
});
|
||||||
basePath: CONTENTS_PATH,
|
|
||||||
include: examples.map(example => resolve(CONTENTS_PATH, example)),
|
|
||||||
fileReader: 'exampleFileReader'
|
|
||||||
}
|
|
||||||
];
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
module.exports = { createPackage };
|
module.exports = {createPackage};
|
||||||
|
11
aio/tools/transforms/authors-package/utils.js
Normal file
11
aio/tools/transforms/authors-package/utils.js
Normal 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,
|
||||||
|
};
|
Loading…
x
Reference in New Issue
Block a user