2017-04-21 08:10:52 -04:00
|
|
|
/**
|
|
|
|
* @license
|
|
|
|
* Copyright Google Inc. 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
|
|
|
|
*/
|
|
|
|
const Package = require('dgeni').Package;
|
2017-06-21 09:16:56 -04:00
|
|
|
const glob = require('glob');
|
2017-06-07 17:34:11 -04:00
|
|
|
const ignore = require('ignore');
|
|
|
|
const fs = require('fs');
|
|
|
|
const path = require('canonical-path');
|
2017-04-21 08:10:52 -04:00
|
|
|
const basePackage = require('../angular-base-package');
|
|
|
|
const contentPackage = require('../content-package');
|
|
|
|
|
2017-06-07 17:34:11 -04:00
|
|
|
const { CONTENTS_PATH, GUIDE_EXAMPLES_PATH } = require('../config');
|
2017-04-21 08:10:52 -04:00
|
|
|
|
|
|
|
module.exports = new Package('angular-content', [basePackage, contentPackage])
|
|
|
|
|
|
|
|
// Where do we get the source files?
|
2017-10-30 17:26:37 -04:00
|
|
|
.config(function(readFilesProcessor, collectExamples, renderExamples) {
|
2017-04-21 08:10:52 -04:00
|
|
|
|
2017-09-19 05:15:39 -04:00
|
|
|
const gitignoreFilePath = path.resolve(GUIDE_EXAMPLES_PATH, '.gitignore');
|
|
|
|
const gitignoreFile = fs.readFileSync(gitignoreFilePath, 'utf8');
|
2017-06-07 17:34:11 -04:00
|
|
|
const gitignore = ignore().add(gitignoreFile);
|
|
|
|
|
2017-06-21 09:16:56 -04:00
|
|
|
const examplePaths = glob.sync('**/*', { cwd: GUIDE_EXAMPLES_PATH, dot: true, ignore: '**/node_modules/**', mark: true })
|
2017-06-07 17:34:11 -04:00
|
|
|
.filter(filePath => filePath !== '.gitignore') // we are not interested in the .gitignore file itself
|
|
|
|
.filter(filePath => !/\/$/.test(filePath)); // this filter removes the folders, leaving only files
|
2017-09-19 05:15:39 -04:00
|
|
|
const ignoredExamplePaths = [];
|
|
|
|
const resolvedExamplePaths = [];
|
|
|
|
|
|
|
|
examplePaths.forEach(filePath => {
|
|
|
|
// filter out files that match the .gitignore rules
|
|
|
|
if (gitignore.ignores(filePath)) {
|
|
|
|
ignoredExamplePaths.push(filePath);
|
|
|
|
} else {
|
|
|
|
// we need the full paths for the filereader
|
|
|
|
resolvedExamplePaths.push(path.resolve(GUIDE_EXAMPLES_PATH, filePath));
|
|
|
|
}
|
|
|
|
});
|
2017-06-07 17:34:11 -04:00
|
|
|
|
2017-04-21 08:10:52 -04:00
|
|
|
readFilesProcessor.sourceFiles = readFilesProcessor.sourceFiles.concat([
|
|
|
|
{
|
|
|
|
basePath: CONTENTS_PATH,
|
2019-03-20 11:10:47 -04:00
|
|
|
include: CONTENTS_PATH + '/{getting-started,guide,tutorial}/**/*.md',
|
2017-04-21 08:10:52 -04:00
|
|
|
fileReader: 'contentFileReader'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
basePath: CONTENTS_PATH + '/marketing',
|
|
|
|
include: CONTENTS_PATH + '/marketing/**/*.{html,md}',
|
|
|
|
fileReader: 'contentFileReader'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
basePath: CONTENTS_PATH,
|
|
|
|
include: CONTENTS_PATH + '/*.md',
|
|
|
|
exclude: [CONTENTS_PATH + '/index.md'],
|
|
|
|
fileReader: 'contentFileReader'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
basePath: CONTENTS_PATH,
|
2017-09-19 05:15:39 -04:00
|
|
|
include: resolvedExamplePaths,
|
2017-04-21 08:10:52 -04:00
|
|
|
fileReader: 'exampleFileReader'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
basePath: CONTENTS_PATH,
|
|
|
|
include: CONTENTS_PATH + '/navigation.json',
|
|
|
|
fileReader: 'jsonFileReader'
|
|
|
|
},
|
2018-02-06 12:55:43 -05:00
|
|
|
{
|
|
|
|
basePath: CONTENTS_PATH,
|
|
|
|
include: CONTENTS_PATH + '/marketing/announcements.json',
|
|
|
|
fileReader: 'jsonFileReader'
|
|
|
|
},
|
2017-04-21 08:10:52 -04:00
|
|
|
{
|
|
|
|
basePath: CONTENTS_PATH,
|
|
|
|
include: CONTENTS_PATH + '/marketing/contributors.json',
|
|
|
|
fileReader: 'jsonFileReader'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
basePath: CONTENTS_PATH,
|
|
|
|
include: CONTENTS_PATH + '/marketing/resources.json',
|
|
|
|
fileReader: 'jsonFileReader'
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
|
|
|
|
collectExamples.exampleFolders.push('examples');
|
2017-09-19 05:15:39 -04:00
|
|
|
collectExamples.registerIgnoredExamples(ignoredExamplePaths, gitignoreFilePath);
|
2017-10-30 17:26:37 -04:00
|
|
|
|
|
|
|
renderExamples.ignoreBrokenExamples = true;
|
2017-04-21 08:10:52 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
// Configure jsdoc-style tag parsing
|
|
|
|
.config(function(inlineTagProcessor) {
|
|
|
|
inlineTagProcessor.inlineTagDefinitions.push(require('./inline-tag-defs/anchor'));
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
.config(function(computePathsProcessor) {
|
|
|
|
|
|
|
|
// Replace any path templates inherited from other packages
|
|
|
|
// (we want full and transparent control)
|
|
|
|
computePathsProcessor.pathTemplates = computePathsProcessor.pathTemplates.concat([
|
|
|
|
{
|
|
|
|
docTypes: ['content'],
|
|
|
|
getPath: (doc) => `${doc.id.replace(/\/index$/, '')}`,
|
|
|
|
outputPathTemplate: '${path}.json'
|
|
|
|
},
|
|
|
|
{docTypes: ['navigation-json'], pathTemplate: '${id}', outputPathTemplate: '../${id}.json'},
|
|
|
|
{docTypes: ['contributors-json'], pathTemplate: '${id}', outputPathTemplate: '../${id}.json'},
|
2018-02-06 12:55:43 -05:00
|
|
|
{docTypes: ['announcements-json'], pathTemplate: '${id}', outputPathTemplate: '../${id}.json'},
|
2017-04-21 08:10:52 -04:00
|
|
|
{docTypes: ['resources-json'], pathTemplate: '${id}', outputPathTemplate: '../${id}.json'}
|
|
|
|
]);
|
|
|
|
})
|
|
|
|
|
|
|
|
// We want the content files to be converted
|
2017-04-27 09:04:51 -04:00
|
|
|
.config(function(convertToJsonProcessor, postProcessHtml) {
|
2017-04-21 08:10:52 -04:00
|
|
|
convertToJsonProcessor.docTypes.push('content');
|
2017-04-27 09:04:51 -04:00
|
|
|
postProcessHtml.docTypes.push('content');
|
2017-04-21 08:10:52 -04:00
|
|
|
});
|