Pete Bacon Darwin 600402d440 build(aio): big move of docs related files (#14361)
All the docs related files (docs-app, doc-gen, content, etc)
are now to be found inside the `/aio` folder.

The related gulp tasks have been moved from the top level
gulp file to a new one inside the `/aio` folder.

The structure of the `/aio` folder now looks like:

```
/aio/
  build/         # gulp tasks
  content/       #MARKDOWN FILES for devguides, cheatsheet, etc
    devguides/
    cheatsheets/
  transforms/    #dgeni packages, templates, etc
  src/
    app/
    assets/
    content/    #HTML + JSON build artifacts produced by dgeni from /aio/content.
                #This dir is .gitignored-ed
  e2e/           #protractor tests for the doc viewer app
  node_modules/ #dependencies for both the doc viewer builds and the dgeni stuff
                #This dir is .gitignored-ed
  gulpfile.js   #Tasks for generating docs and building & deploying the doc viewer
```

Closes #14361
2017-02-09 11:58:36 -08:00

67 lines
2.1 KiB
JavaScript

const {mapObject} = require('../utils');
module.exports = function collectExamples(exampleMap, regionParser, log, createDocMessage) {
return {
$runAfter: ['files-read'],
$runBefore: ['parsing-tags'],
$validate: {exampleFolders: {presence: true}},
$process: function(docs) {
const exampleFolders = this.exampleFolders;
const regionDocs = [];
docs = docs.filter((doc) => {
if (doc.docType === 'example-file') {
try {
// find the first matching folder
exampleFolders.some((folder) => {
if (doc.fileInfo.relativePath.indexOf(folder) === 0) {
const relativePath =
doc.fileInfo.relativePath.substr(folder.length).replace(/^\//, '');
exampleMap[folder] = exampleMap[folder] || {};
exampleMap[folder][relativePath] = doc;
const parsedRegions = regionParser(doc.content, doc.fileInfo.extension);
log.debug(
'found example file', folder, relativePath, Object.keys(parsedRegions.regions));
doc.renderedContent = parsedRegions.contents;
// Map each region into a doc that can be put through the rendering pipeline
doc.regions = mapObject(parsedRegions.regions, (regionName, regionContents) => {
const regionDoc =
createRegionDoc(folder, relativePath, regionName, regionContents);
regionDocs.push(regionDoc);
return regionDoc;
});
return true;
}
});
return false;
} catch (e) {
throw new Error(createDocMessage(e.message, doc, e));
}
} else {
return true;
}
});
return docs.concat(regionDocs);
}
};
};
function createRegionDoc(folder, relativePath, regionName, regionContents) {
const path = folder + '/' + relativePath;
const id = path + '#' + regionName
return {
docType: 'example-region',
path: path,
name: regionName,
id: id,
aliases: [id],
contents: regionContents
};
}