2017-04-16 15:48:22 -04:00
|
|
|
/**
|
|
|
|
* @license
|
2020-05-19 15:08:49 -04:00
|
|
|
* Copyright Google LLC All Rights Reserved.
|
2017-04-16 15:48:22 -04:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
2017-04-21 08:10:52 -04:00
|
|
|
|
2021-01-18 09:55:04 -05:00
|
|
|
const {resolve} = require('canonical-path');
|
2017-04-16 15:48:22 -04:00
|
|
|
const Package = require('dgeni').Package;
|
2021-01-18 09:55:04 -05:00
|
|
|
const {readFileSync} = require('fs');
|
|
|
|
|
2017-04-21 08:10:52 -04:00
|
|
|
const contentPackage = require('../angular-content-package');
|
2021-01-18 09:55:04 -05:00
|
|
|
const {CONTENTS_PATH} = require('../config');
|
2021-01-20 05:13:59 -05:00
|
|
|
const baseAuthoringPackage = require('./base-authoring-package');
|
2021-01-18 09:55:04 -05:00
|
|
|
const {codeExampleMatcher} = require('./utils');
|
2017-04-21 08:10:52 -04:00
|
|
|
|
|
|
|
/* eslint no-console: "off" */
|
|
|
|
|
|
|
|
function createPackage(tutorialName) {
|
|
|
|
const tutorialFilePath = `${CONTENTS_PATH}/tutorial/${tutorialName}.md`;
|
|
|
|
const tutorialFile = readFileSync(tutorialFilePath, 'utf8');
|
|
|
|
const examples = [];
|
2021-01-18 09:55:04 -05:00
|
|
|
tutorialFile.replace(codeExampleMatcher, (_, path) => examples.push('examples/' + path));
|
2017-04-21 08:10:52 -04:00
|
|
|
|
|
|
|
if (examples.length) {
|
|
|
|
console.log('The following example files are referenced in this tutorial:');
|
|
|
|
console.log(examples.map(example => ' - ' + example).join('\n'));
|
|
|
|
}
|
2017-04-16 15:48:22 -04:00
|
|
|
|
2021-01-20 05:13:59 -05:00
|
|
|
return new Package('author-tutorial', [baseAuthoringPackage, contentPackage]).config(function(readFilesProcessor) {
|
2021-01-18 09:55:04 -05:00
|
|
|
readFilesProcessor.sourceFiles = [
|
|
|
|
{basePath: CONTENTS_PATH, include: tutorialFilePath, fileReader: 'contentFileReader'}, {
|
|
|
|
basePath: CONTENTS_PATH,
|
|
|
|
include: examples.map(example => resolve(CONTENTS_PATH, example)),
|
|
|
|
fileReader: 'exampleFileReader'
|
|
|
|
}
|
|
|
|
];
|
|
|
|
});
|
2017-04-16 15:48:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-01-18 09:55:04 -05:00
|
|
|
module.exports = {createPackage};
|