diff --git a/aio/tools/transforms/authors-package/getting-started-package.js b/aio/tools/transforms/authors-package/getting-started-package.js index 02fa87e39b..eb2e0110ff 100644 --- a/aio/tools/transforms/authors-package/getting-started-package.js +++ b/aio/tools/transforms/authors-package/getting-started-package.js @@ -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(/]*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}; diff --git a/aio/tools/transforms/authors-package/guide-package.js b/aio/tools/transforms/authors-package/guide-package.js index 3926e21856..4ba82e950d 100644 --- a/aio/tools/transforms/authors-package/guide-package.js +++ b/aio/tools/transforms/authors-package/guide-package.js @@ -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(/]*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}; diff --git a/aio/tools/transforms/authors-package/tutorial-package.js b/aio/tools/transforms/authors-package/tutorial-package.js index 0bcc72ca04..3fd0fbda16 100644 --- a/aio/tools/transforms/authors-package/tutorial-package.js +++ b/aio/tools/transforms/authors-package/tutorial-package.js @@ -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(/]*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}; diff --git a/aio/tools/transforms/authors-package/utils.js b/aio/tools/transforms/authors-package/utils.js new file mode 100644 index 0000000000..d36515d92b --- /dev/null +++ b/aio/tools/transforms/authors-package/utils.js @@ -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: /]*\bpath="([^"]+)"/g, +};