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
|
|
|
|
2017-04-16 15:48:22 -04:00
|
|
|
const Package = require('dgeni').Package;
|
2017-04-21 08:10:52 -04:00
|
|
|
const contentPackage = require('../angular-content-package');
|
|
|
|
const { readFileSync } = require('fs');
|
|
|
|
const { resolve } = require('canonical-path');
|
|
|
|
const { CONTENTS_PATH } = require('../config');
|
|
|
|
|
|
|
|
/* 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));
|
|
|
|
|
|
|
|
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
|
|
|
|
2017-04-21 08:10:52 -04:00
|
|
|
return new Package('author-tutorial', [contentPackage])
|
2017-04-16 15:48:22 -04:00
|
|
|
.config(function(readFilesProcessor) {
|
|
|
|
readFilesProcessor.sourceFiles = [
|
|
|
|
{
|
|
|
|
basePath: CONTENTS_PATH,
|
2017-04-21 08:10:52 -04:00
|
|
|
include: tutorialFilePath,
|
2017-04-16 15:48:22 -04:00
|
|
|
fileReader: 'contentFileReader'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
basePath: CONTENTS_PATH,
|
2017-04-21 08:10:52 -04:00
|
|
|
include: examples.map(example => resolve(CONTENTS_PATH, example)),
|
2017-04-16 15:48:22 -04:00
|
|
|
fileReader: 'exampleFileReader'
|
|
|
|
}
|
|
|
|
];
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-05-19 15:08:49 -04:00
|
|
|
module.exports = { createPackage };
|