api-builder: move ngdoc stuff out from doc-package and into content package
This commit is contained in:
parent
d08ebf4b9a
commit
bc8a319f61
|
@ -0,0 +1,35 @@
|
||||||
|
var Package = require('dgeni').Package;
|
||||||
|
var jsdocPackage = require('dgeni-packages/jsdoc');
|
||||||
|
var linksPackage = require('../links-package');
|
||||||
|
var path = require('canonical-path');
|
||||||
|
var fs = require('fs');
|
||||||
|
|
||||||
|
// Define the dgeni package for generating the docs
|
||||||
|
module.exports = new Package('content', [jsdocPackage, linksPackage])
|
||||||
|
|
||||||
|
// Register the services and file readers
|
||||||
|
.factory(require('./readers/content'))
|
||||||
|
|
||||||
|
// Configure file reading
|
||||||
|
.config(function(readFilesProcessor, contentFileReader) {
|
||||||
|
readFilesProcessor.fileReaders.push(contentFileReader);
|
||||||
|
})
|
||||||
|
|
||||||
|
// Configure ids and paths
|
||||||
|
.config(function(computeIdsProcessor, computePathsProcessor) {
|
||||||
|
|
||||||
|
computeIdsProcessor.idTemplates.push({
|
||||||
|
docTypes: ['content'],
|
||||||
|
getId: function(doc) {
|
||||||
|
return doc.fileInfo.relativePath
|
||||||
|
// path should be relative to `modules` folder
|
||||||
|
.replace(/.*\/?modules\//, '')
|
||||||
|
// path should not include `/docs/`
|
||||||
|
.replace(/\/docs\//, '/')
|
||||||
|
// path should not have a suffix
|
||||||
|
.replace(/\.\w*$/, '');
|
||||||
|
},
|
||||||
|
getAliases: function(doc) { return [doc.id]; }
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
var Package = require('dgeni').Package;
|
||||||
|
|
||||||
|
module.exports = function mockPackage() {
|
||||||
|
|
||||||
|
return new Package('mockPackage', [require('../')])
|
||||||
|
|
||||||
|
// provide a mock log service
|
||||||
|
.factory('log', function() { return require('dgeni/lib/mocks/log')(false); })
|
||||||
|
.factory('templateEngine', function() { return {}; });
|
||||||
|
|
||||||
|
};
|
|
@ -1,9 +1,9 @@
|
||||||
var path = require('canonical-path');
|
var path = require('canonical-path');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dgService ngdocFileReader
|
* @dgService
|
||||||
* @description
|
* @description
|
||||||
* This file reader will pull the contents from a text file (by default .ngdoc)
|
* This file reader will pull the contents from a text file (by default .md)
|
||||||
*
|
*
|
||||||
* The doc will initially have the form:
|
* The doc will initially have the form:
|
||||||
* ```
|
* ```
|
||||||
|
@ -13,13 +13,13 @@ var path = require('canonical-path');
|
||||||
* }
|
* }
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
module.exports = function ngdocFileReader() {
|
module.exports = function contentFileReader() {
|
||||||
var reader = {
|
return {
|
||||||
name: 'ngdocFileReader',
|
name: 'contentFileReader',
|
||||||
defaultPattern: /\.md$/,
|
defaultPattern: /\.md$/,
|
||||||
getDocs: function(fileInfo) {
|
getDocs: function(fileInfo) {
|
||||||
|
|
||||||
// We return a single element array because ngdoc files only contain one document
|
// We return a single element array because content files only contain one document
|
||||||
return [{
|
return [{
|
||||||
docType: 'guide',
|
docType: 'guide',
|
||||||
content: fileInfo.content,
|
content: fileInfo.content,
|
||||||
|
@ -27,6 +27,4 @@ module.exports = function ngdocFileReader() {
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return reader;
|
|
||||||
};
|
};
|
|
@ -1,9 +1,16 @@
|
||||||
var ngdocFileReaderFactory = require('./ngdoc');
|
var mockPackage = require('../mocks/mockPackage');
|
||||||
|
var Dgeni = require('dgeni');
|
||||||
var path = require('canonical-path');
|
var path = require('canonical-path');
|
||||||
|
var _ = require('lodash');
|
||||||
|
|
||||||
describe('ngdocFileReader', function() {
|
describe('contentFileReader', function() {
|
||||||
|
var dgeni, injector, fileReader;
|
||||||
|
|
||||||
var fileReader;
|
beforeEach(function() {
|
||||||
|
dgeni = new Dgeni([mockPackage()]);
|
||||||
|
injector = dgeni.configureInjector();
|
||||||
|
fileReader = injector.get('contentFileReader');
|
||||||
|
});
|
||||||
|
|
||||||
var createFileInfo = function(file, content, basePath) {
|
var createFileInfo = function(file, content, basePath) {
|
||||||
return {
|
return {
|
||||||
|
@ -17,12 +24,6 @@ describe('ngdocFileReader', function() {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
beforeEach(function() {
|
|
||||||
fileReader = ngdocFileReaderFactory();
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
describe('defaultPattern', function() {
|
describe('defaultPattern', function() {
|
||||||
it('should match .md files', function() {
|
it('should match .md files', function() {
|
||||||
expect(fileReader.defaultPattern.test('abc.md')).toBeTruthy();
|
expect(fileReader.defaultPattern.test('abc.md')).toBeTruthy();
|
|
@ -10,9 +10,6 @@ var fs = require('fs');
|
||||||
// Define the dgeni package for generating the docs
|
// Define the dgeni package for generating the docs
|
||||||
module.exports = new Package('angular-v2-docs', [jsdocPackage, nunjucksPackage, typescriptPackage, linksPackage, gitPackage])
|
module.exports = new Package('angular-v2-docs', [jsdocPackage, nunjucksPackage, typescriptPackage, linksPackage, gitPackage])
|
||||||
|
|
||||||
// Register the services and file readers
|
|
||||||
.factory(require('./readers/ngdoc'))
|
|
||||||
|
|
||||||
// Register the processors
|
// Register the processors
|
||||||
.processor(require('./processors/convertPrivateClassesToInterfaces'))
|
.processor(require('./processors/convertPrivateClassesToInterfaces'))
|
||||||
.processor(require('./processors/extractDirectiveClasses'))
|
.processor(require('./processors/extractDirectiveClasses'))
|
||||||
|
@ -36,9 +33,8 @@ module.exports = new Package('angular-v2-docs', [jsdocPackage, nunjucksPackage,
|
||||||
})
|
})
|
||||||
|
|
||||||
// Configure file reading
|
// Configure file reading
|
||||||
.config(function(readFilesProcessor, ngdocFileReader, readTypeScriptModules) {
|
.config(function(readTypeScriptModules) {
|
||||||
readFilesProcessor.fileReaders = [ngdocFileReader];
|
|
||||||
// set the readFilesProcessor base path to point to angular repo.
|
|
||||||
var angular_repo_path = path.resolve(__dirname, '../../../../angular');
|
var angular_repo_path = path.resolve(__dirname, '../../../../angular');
|
||||||
// confirm that the angular repo is actually there.
|
// confirm that the angular repo is actually there.
|
||||||
if (!fs.existsSync(angular_repo_path)) {
|
if (!fs.existsSync(angular_repo_path)) {
|
||||||
|
@ -54,6 +50,7 @@ module.exports = new Package('angular-v2-docs', [jsdocPackage, nunjucksPackage,
|
||||||
|
|
||||||
.config(function(parseTagsProcessor, getInjectables) {
|
.config(function(parseTagsProcessor, getInjectables) {
|
||||||
// We actually don't want to parse param docs in this package as we are getting the data out using TS
|
// We actually don't want to parse param docs in this package as we are getting the data out using TS
|
||||||
|
// TODO: rewire the param docs to the params extracted from TS
|
||||||
parseTagsProcessor.tagDefinitions.forEach(function(tagDef) {
|
parseTagsProcessor.tagDefinitions.forEach(function(tagDef) {
|
||||||
if (tagDef.name === 'param') {
|
if (tagDef.name === 'param') {
|
||||||
tagDef.docProperty = 'paramData';
|
tagDef.docProperty = 'paramData';
|
||||||
|
@ -95,29 +92,4 @@ module.exports = new Package('angular-v2-docs', [jsdocPackage, nunjucksPackage,
|
||||||
'${ doc.docType }.template.html',
|
'${ doc.docType }.template.html',
|
||||||
'common.template.html'
|
'common.template.html'
|
||||||
];
|
];
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
// Configure ids and paths
|
|
||||||
.config(function(computeIdsProcessor, computePathsProcessor) {
|
|
||||||
|
|
||||||
computeIdsProcessor.idTemplates.push({
|
|
||||||
docTypes: ['guide'],
|
|
||||||
getId: function(doc) {
|
|
||||||
return doc.fileInfo.relativePath
|
|
||||||
// path should be relative to `modules` folder
|
|
||||||
.replace(/.*\/?modules\//, '')
|
|
||||||
// path should not include `/docs/`
|
|
||||||
.replace(/\/docs\//, '/')
|
|
||||||
// path should not have a suffix
|
|
||||||
.replace(/\.\w*$/, '');
|
|
||||||
},
|
|
||||||
getAliases: function(doc) { return [doc.id]; }
|
|
||||||
});
|
|
||||||
|
|
||||||
computePathsProcessor.pathTemplates.push({
|
|
||||||
docTypes: ['guide'],
|
|
||||||
pathTemplate: '/${id}',
|
|
||||||
outputPathTemplate: 'partials/guides/${id}.html'
|
|
||||||
});
|
|
||||||
});
|
});
|
Loading…
Reference in New Issue