diff --git a/package.json b/package.json index 6ffdb164c3..aa27046013 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,7 @@ "codelyzer": "0.0.18", "del": "^1.2.0", "dgeni": "^0.4.0", - "dgeni-packages": "^0.11.1", + "dgeni-packages": "^0.12.0", "diff": "^2.1.3", "fs-extra": "^0.24.0", "glob": "^5.0.14", diff --git a/tools/api-builder/docs-package/index.js b/tools/api-builder/docs-package/index.js index c6cb9e88af..b9db3249c2 100644 --- a/tools/api-builder/docs-package/index.js +++ b/tools/api-builder/docs-package/index.js @@ -1,7 +1,7 @@ var Package = require('dgeni').Package; var jsdocPackage = require('dgeni-packages/jsdoc'); var nunjucksPackage = require('dgeni-packages/nunjucks'); -var typescriptPackage = require('../typescript-package'); +var typescriptPackage = require('dgeni-packages/typescript'); var linksPackage = require('../links-package'); var gitPackage = require('dgeni-packages/git'); var path = require('canonical-path'); diff --git a/tools/api-builder/typescript-package/index.js b/tools/api-builder/typescript-package/index.js deleted file mode 100644 index 4c7046bc5c..0000000000 --- a/tools/api-builder/typescript-package/index.js +++ /dev/null @@ -1,73 +0,0 @@ -var basePackage = require('dgeni-packages/base'); -var Package = require('dgeni').Package; -var path = require('canonical-path'); - -// Define the dgeni package for generating the docs -module.exports = new Package('typescript-parsing', [basePackage]) - -// Register the services and file readers -.factory(require('./services/modules')) -.factory(require('./services/tsParser')) -.factory(require('./services/tsParser/createCompilerHost')) -.factory(require('./services/tsParser/getFileInfo')) -.factory(require('./services/tsParser/getExportDocType')) -.factory(require('./services/tsParser/getContent')) - -.factory(require('./services/convertPrivateClassesToInterfaces')) - -.factory('EXPORT_DOC_TYPES', function() { - return [ - 'class', - 'interface', - 'function', - 'var', - 'const', - 'let', - 'enum', - 'type-alias' - ]; -}) - - -// Register the processors -.processor(require('./processors/readTypeScriptModules')) - - -// Configure the log service -.config(function(log) { - log.level = 'warn'; -}) - - -// Configure ids and paths -.config(function(computeIdsProcessor, computePathsProcessor, EXPORT_DOC_TYPES) { - - computeIdsProcessor.idTemplates.push({ - docTypes: ['member'], - idTemplate: '${classDoc.id}.${name}', - getAliases: function(doc) { - return doc.classDoc.aliases.map(function(alias) { return alias + '.' + doc.name; }); - } - }); - - computePathsProcessor.pathTemplates.push({ - docTypes: ['member'], - pathTemplate: '${classDoc.path}#${name}', - getOutputPath: function() {} // These docs are not written to their own file, instead they are part of their class doc - }); - - var MODULES_DOCS_PATH = 'partials/modules'; - - computePathsProcessor.pathTemplates.push({ - docTypes: ['module'], - pathTemplate: '/${id}', - outputPathTemplate: MODULES_DOCS_PATH + '/${id}/index.html' - }); - - computePathsProcessor.pathTemplates.push({ - docTypes: EXPORT_DOC_TYPES, - pathTemplate: '${moduleDoc.path}/${name}', - outputPathTemplate: MODULES_DOCS_PATH + '/${path}/index.html' - }); - -}); diff --git a/tools/api-builder/typescript-package/mocks/mockPackage.js b/tools/api-builder/typescript-package/mocks/mockPackage.js deleted file mode 100644 index 834d53c959..0000000000 --- a/tools/api-builder/typescript-package/mocks/mockPackage.js +++ /dev/null @@ -1,11 +0,0 @@ -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 {}; }); - -}; diff --git a/tools/api-builder/typescript-package/mocks/readTypeScriptModules/ignoreExportsMatching.ts b/tools/api-builder/typescript-package/mocks/readTypeScriptModules/ignoreExportsMatching.ts deleted file mode 100644 index 476d4cc44b..0000000000 --- a/tools/api-builder/typescript-package/mocks/readTypeScriptModules/ignoreExportsMatching.ts +++ /dev/null @@ -1,4 +0,0 @@ -export var __esModule = true; -export class OKToExport {} -export function _thisIsPrivate() {} -export var thisIsOK = '!'; \ No newline at end of file diff --git a/tools/api-builder/typescript-package/mocks/readTypeScriptModules/interfaces.ts b/tools/api-builder/typescript-package/mocks/readTypeScriptModules/interfaces.ts deleted file mode 100644 index a2d4be4fec..0000000000 --- a/tools/api-builder/typescript-package/mocks/readTypeScriptModules/interfaces.ts +++ /dev/null @@ -1,5 +0,0 @@ -export interface MyInterface { - optionalProperty? : string - >(param: T) : U - new (param: number) : MyInterface -} \ No newline at end of file diff --git a/tools/api-builder/typescript-package/mocks/readTypeScriptModules/orderingOfMembers.ts b/tools/api-builder/typescript-package/mocks/readTypeScriptModules/orderingOfMembers.ts deleted file mode 100644 index 2020ec7fa4..0000000000 --- a/tools/api-builder/typescript-package/mocks/readTypeScriptModules/orderingOfMembers.ts +++ /dev/null @@ -1,6 +0,0 @@ -export class Test { - firstItem; - constructor() { this.doStuff(); } - otherMethod() {} - doStuff() {} -} \ No newline at end of file diff --git a/tools/api-builder/typescript-package/mocks/readTypeScriptModules/privateModule.ts b/tools/api-builder/typescript-package/mocks/readTypeScriptModules/privateModule.ts deleted file mode 100644 index d4c6ef610a..0000000000 --- a/tools/api-builder/typescript-package/mocks/readTypeScriptModules/privateModule.ts +++ /dev/null @@ -1 +0,0 @@ -export var x = 10; \ No newline at end of file diff --git a/tools/api-builder/typescript-package/mocks/readTypeScriptModules/publicModule.ts b/tools/api-builder/typescript-package/mocks/readTypeScriptModules/publicModule.ts deleted file mode 100644 index 0fbae4ad2f..0000000000 --- a/tools/api-builder/typescript-package/mocks/readTypeScriptModules/publicModule.ts +++ /dev/null @@ -1,3 +0,0 @@ -export { x as y} from './privateModule'; - -export abstract class AbstractClass {} \ No newline at end of file diff --git a/tools/api-builder/typescript-package/mocks/tsParser/importedSrc.ts b/tools/api-builder/typescript-package/mocks/tsParser/importedSrc.ts deleted file mode 100644 index 74a115e5fe..0000000000 --- a/tools/api-builder/typescript-package/mocks/tsParser/importedSrc.ts +++ /dev/null @@ -1 +0,0 @@ -export var x = 100; \ No newline at end of file diff --git a/tools/api-builder/typescript-package/mocks/tsParser/testSrc.ts b/tools/api-builder/typescript-package/mocks/tsParser/testSrc.ts deleted file mode 100644 index 7b6d3f18dd..0000000000 --- a/tools/api-builder/typescript-package/mocks/tsParser/testSrc.ts +++ /dev/null @@ -1,34 +0,0 @@ -/** - * @module - * @description - * This is the module description - */ - -export * from 'importedSrc'; - -/** - * This is some random other comment - */ - -/** - * This is MyClass - */ -export class MyClass { - message: String; - - /** - * Create a new MyClass - * @param {String} name The name to say hello to - */ - constructor(name) { this.message = 'hello ' + name; } - - /** - * Return a greeting message - */ - greet() { return this.message; } -} - -/** - * An exported function - */ -export var myFn = (val: number) => return val * 2; \ No newline at end of file diff --git a/tools/api-builder/typescript-package/processors/readTypeScriptModules.js b/tools/api-builder/typescript-package/processors/readTypeScriptModules.js deleted file mode 100644 index c5f7bec65b..0000000000 --- a/tools/api-builder/typescript-package/processors/readTypeScriptModules.js +++ /dev/null @@ -1,451 +0,0 @@ -var glob = require('glob'); -var path = require('canonical-path'); -var _ = require('lodash'); -var ts = require('typescript'); - -module.exports = function readTypeScriptModules(tsParser, modules, getFileInfo, - getExportDocType, getContent, createDocMessage, log) { - - return { - $runAfter: ['files-read'], - $runBefore: ['parsing-tags'], - - $validate: { - sourceFiles: {presence: true}, - basePath: {presence: true}, - hidePrivateMembers: {inclusion: [true, false]}, - sortClassMembers: {inclusion: [true, false]}, - ignoreExportsMatching: {} - }, - - // A collection of globs that identify those modules for which we should create docs - sourceFiles: [], - // The base path from which to load the source files - basePath: '.', - // We can ignore members of classes that are private - hidePrivateMembers: true, - // We leave class members sorted in order of declaration - sortClassMembers: false, - // We can provide a collection of strings or regexes to ignore exports whose export names match - ignoreExportsMatching: ['___esModule', '___core_private_types__', '___platform_browser_private__', '___compiler_private__', '__core_private__', '___core_private__'], - - $process: function(docs) { - - // Convert ignoreExportsMatching to an array of regexes - var ignoreExportsMatching = convertToRegexCollection(this.ignoreExportsMatching); - - var hidePrivateMembers = this.hidePrivateMembers; - var sortClassMembers = this.sortClassMembers; - - var basePath = path.resolve(this.basePath); - var filesPaths = expandSourceFiles(this.sourceFiles, basePath); - var parseInfo = tsParser.parse(filesPaths, this.basePath); - var moduleSymbols = parseInfo.moduleSymbols; - - // Iterate through each of the modules that were parsed and generate a module doc - // as well as docs for each module's exports. - moduleSymbols.forEach(function(moduleSymbol) { - - var moduleDoc = createModuleDoc(moduleSymbol, basePath); - - // Add this module doc to the module lookup collection and the docs collection - modules[moduleDoc.id] = moduleDoc; - docs.push(moduleDoc); - - // Iterate through this module's exports and generate a doc for each - moduleSymbol.exportArray.forEach(function(exportSymbol) { - - // Ignore exports starting with an underscore - if (anyMatches(ignoreExportsMatching, exportSymbol.name)) return; - - // If the symbol is an Alias then for most things we want the original resolved symbol - var resolvedExport = exportSymbol.resolvedSymbol || exportSymbol; - - // If the resolved symbol contains no declarations then it is invalid - // (probably an abstract class) - // For the moment we are just going to ignore such exports - // TODO: find a way of generating docs for them - if (!resolvedExport.declarations) return; - - var exportDoc = createExportDoc(exportSymbol.name, resolvedExport, moduleDoc, basePath, parseInfo.typeChecker); - log.debug('>>>> EXPORT: ' + exportDoc.name + ' (' + exportDoc.docType + ') from ' + moduleDoc.id); - - // Add this export doc to its module doc - moduleDoc.exports.push(exportDoc); - docs.push(exportDoc); - - exportDoc.members = []; - exportDoc.statics = []; - - // Generate docs for each of the export's members - if (resolvedExport.flags & ts.SymbolFlags.HasMembers) { - - for(var memberName in resolvedExport.members) { - // FIXME(alexeagle): why do generic type params appear in members? - if (memberName === 'T') { - continue; - } - log.silly('>>>>>> member: ' + memberName + ' from ' + exportDoc.id + ' in ' + moduleDoc.id); - var memberSymbol = resolvedExport.members[memberName]; - var memberDoc = createMemberDoc(memberSymbol, exportDoc, basePath, parseInfo.typeChecker); - - // We special case the constructor and sort the other members alphabetically - if (memberSymbol.flags & ts.SymbolFlags.Constructor) { - exportDoc.constructorDoc = memberDoc; - docs.push(memberDoc); - } else if (!hidePrivateMembers || memberSymbol.name.charAt(0) !== '_') { - docs.push(memberDoc); - exportDoc.members.push(memberDoc); - } else if (memberSymbol.name === '__call' && memberSymbol.flags & ts.SymbolFlags.Signature) { - docs.push(memberDoc); - exportDoc.callMember = memberDoc; - } else if (memberSymbol.name === '__new' && memberSymbol.flags & ts.SymbolFlags.Signature) { - docs.push(memberDoc); - exportDoc.newMember = memberDoc; - } - } - } - - if (exportDoc.docType === 'enum') { - for(var memberName in resolvedExport.exports) { - log.silly('>>>>>> member: ' + memberName + ' from ' + exportDoc.id + ' in ' + moduleDoc.id); - var memberSymbol = resolvedExport.exports[memberName]; - var memberDoc = createMemberDoc(memberSymbol, exportDoc, basePath, parseInfo.typeChecker); - docs.push(memberDoc); - exportDoc.members.push(memberDoc); - } - } else if (resolvedExport.flags & ts.SymbolFlags.HasExports) { - for (var exported in resolvedExport.exports) { - if (exported === 'prototype') continue; - if (hidePrivateMembers && exported.charAt(0) === '_') continue; - var memberSymbol = resolvedExport.exports[exported]; - var memberDoc = createMemberDoc(memberSymbol, exportDoc, basePath, parseInfo.typeChecker); - memberDoc.isStatic = true; - docs.push(memberDoc); - exportDoc.statics.push(memberDoc); - } - } - - if (sortClassMembers) { - exportDoc.members.sort(function(a, b) { - if (a.name > b.name) return 1; - if (a.name < b.name) return -1; - return 0; - }); - exportDoc.statics.sort(function(a, b) { - if (a.name > b.name) return 1; - if (a.name < b.name) return -1; - return 0; - }); - } - }); - }); - } - }; - - - function createModuleDoc(moduleSymbol, basePath) { - var id = moduleSymbol.name.replace(/^"|"$/g, ''); - var name = id.split('/').pop(); - var moduleDoc = { - docType: 'module', - name: name, - id: id, - aliases: [id, name], - moduleTree: moduleSymbol, - content: getContent(moduleSymbol), - exports: [], - fileInfo: getFileInfo(moduleSymbol, basePath), - location: getLocation(moduleSymbol) - }; - return moduleDoc; - } - - function createExportDoc(name, exportSymbol, moduleDoc, basePath, typeChecker) { - var typeParamString = ''; - var heritageString = ''; - var typeDefinition = ''; - - exportSymbol.declarations.forEach(function(decl) { - var sourceFile = ts.getSourceFileOfNode(decl); - - if (decl.typeParameters) { - typeParamString = '<' + getText(sourceFile, decl.typeParameters) + '>'; - } - - if (decl.symbol.flags & ts.SymbolFlags.TypeAlias) { - typeDefinition = getText(sourceFile, decl.type); - } - - if (decl.heritageClauses) { - decl.heritageClauses.forEach(function(heritage) { - - if (heritage.token == ts.SyntaxKind.ExtendsKeyword) { - heritageString += " extends"; - heritage.types.forEach(function(typ, idx) { - heritageString += (idx > 0 ? ',' : '') + typ.getFullText(); - }); - } - - if (heritage.token == ts.SyntaxKind.ImplementsKeyword) { - heritageString += " implements"; - heritage.types.forEach(function(typ, idx) { - heritageString += (idx > 0 ? ', ' : '') + typ.getFullText(); - }); - } - }); - } - }); - - //Make sure duplicate aliases aren't created, so "Ambiguous link" warnings are prevented - var aliasNames = [name, moduleDoc.id + '/' + name]; - if (typeParamString) { - aliasNames.push(name + typeParamString); - aliasNames.push(moduleDoc.id + '/' + name + typeParamString); - } - - var exportDoc = { - docType: getExportDocType(exportSymbol), - exportSymbol: exportSymbol, - name: name, - id: moduleDoc.id + '/' + name, - typeParams: typeParamString, - heritage: heritageString, - decorators: getDecorators(exportSymbol), - aliases: aliasNames, - moduleDoc: moduleDoc, - content: getContent(exportSymbol), - fileInfo: getFileInfo(exportSymbol, basePath), - location: getLocation(exportSymbol) - }; - - if (exportDoc.docType === 'var' || exportDoc.docType === 'const' || exportDoc.docType === 'let') { - exportDoc.symbolTypeName = exportSymbol.valueDeclaration.type && - exportSymbol.valueDeclaration.type.typeName && - exportSymbol.valueDeclaration.type.typeName.text; - } - - if (exportDoc.docType === 'type-alias') { - exportDoc.returnType = getReturnType(typeChecker, exportSymbol); - } - - if(exportSymbol.flags & ts.SymbolFlags.Function) { - exportDoc.parameters = getParameters(typeChecker, exportSymbol); - } - if(exportSymbol.flags & ts.SymbolFlags.Value) { - exportDoc.returnType = getReturnType(typeChecker, exportSymbol); - } - if (exportSymbol.flags & ts.SymbolFlags.TypeAlias) { - exportDoc.typeDefinition = typeDefinition; - } - - // Compute the original module name from the relative file path - exportDoc.originalModule = exportDoc.fileInfo.relativePath - .replace(new RegExp('\.' + exportDoc.fileInfo.extension + '$'), ''); - - return exportDoc; - } - - function createMemberDoc(memberSymbol, classDoc, basePath, typeChecker) { - var memberDoc = { - docType: 'member', - classDoc: classDoc, - name: memberSymbol.name, - decorators: getDecorators(memberSymbol), - content: getContent(memberSymbol), - fileInfo: getFileInfo(memberSymbol, basePath), - location: getLocation(memberSymbol) - }; - - memberDoc.typeParameters = getTypeParameters(typeChecker, memberSymbol); - - if(memberSymbol.flags & (ts.SymbolFlags.Signature) ) { - memberDoc.parameters = getParameters(typeChecker, memberSymbol); - memberDoc.returnType = getReturnType(typeChecker, memberSymbol); - switch(memberDoc.name) { - case '__call': - memberDoc.name = ''; - break; - case '__new': - memberDoc.name = 'new'; - break; - } - } - - if (memberSymbol.flags & ts.SymbolFlags.Method) { - // NOTE: we use the property name `parameters` here so we don't conflict - // with the `params` property that will be updated by dgeni reading the - // `@param` tags from the docs - memberDoc.parameters = getParameters(typeChecker, memberSymbol); - } - - if (memberSymbol.flags & ts.SymbolFlags.Constructor) { - memberDoc.parameters = getParameters(typeChecker, memberSymbol); - memberDoc.name = 'constructor'; - } - - if(memberSymbol.flags & ts.SymbolFlags.Value) { - memberDoc.returnType = getReturnType(typeChecker, memberSymbol); - } - - if(memberSymbol.flags & ts.SymbolFlags.Optional) { - memberDoc.optional = true; - } - - return memberDoc; - } - - - function getDecorators(symbol) { - - var declaration = symbol.valueDeclaration || symbol.declarations[0]; - var sourceFile = ts.getSourceFileOfNode(declaration); - - var decorators = declaration.decorators && declaration.decorators.map(function(decorator) { - decorator = decorator.expression; - return { - name: decorator.expression ? decorator.expression.text : decorator.text, - arguments: decorator.arguments && decorator.arguments.map(function(argument) { - return getText(sourceFile, argument).trim(); - }), - argumentInfo: decorator.arguments && decorator.arguments.map(function(argument) { - return parseArgument(argument); - }), - expression: decorator - }; - }); - return decorators; - } - - function parseProperties(properties) { - var result = {}; - _.forEach(properties, function(property) { - result[property.name.text] = parseArgument(property.initializer); - }); - return result; - } - - function parseArgument(argument) { - if (argument.text) return argument.text; - if (argument.properties) return parseProperties(argument.properties); - if (argument.elements) return argument.elements.map(function(element) { return element.text; }); - var sourceFile = ts.getSourceFileOfNode(argument); - var text = getText(sourceFile, argument).trim(); - return text; - } - - function getParameters(typeChecker, symbol) { - var declaration = symbol.valueDeclaration || symbol.declarations[0]; - var sourceFile = ts.getSourceFileOfNode(declaration); - if (!declaration.parameters) { - var location = getLocation(symbol); - throw new Error('missing declaration parameters for "' + symbol.name + - '" in ' + sourceFile.fileName + - ' at line ' + location.start.line); - } - return declaration.parameters.map(function(parameter) { - var paramText = ''; - if (parameter.dotDotDotToken) { - paramText += '...'; - } - paramText += getText(sourceFile, parameter.name); - if (parameter.questionToken || parameter.initializer) { - paramText += '?'; - } - if (parameter.type) { - paramText += ':' + getType(sourceFile, parameter.type); - } else { - paramText += ': any'; - if (parameter.dotDotDotToken) { - paramText += '[]'; - } - } - return paramText.trim(); - }); - } - - function getTypeParameters(typeChecker, symbol) { - var declaration = symbol.valueDeclaration || symbol.declarations[0]; - var sourceFile = ts.getSourceFileOfNode(declaration); - if (!declaration.typeParameters) return; - var typeParams = declaration.typeParameters.map(function(type) { - return getText(sourceFile, type).trim(); - }); - return typeParams; - } - - function getReturnType(typeChecker, symbol) { - var declaration = symbol.valueDeclaration || symbol.declarations[0]; - var sourceFile = ts.getSourceFileOfNode(declaration); - if (declaration.type) { - return getType(sourceFile, declaration.type).trim(); - } else if (declaration.initializer) { - // The symbol does not have a "type" but it is being initialized - // so we can deduce the type of from the initializer (mostly). - if (declaration.initializer.expression) { - return declaration.initializer.expression.text.trim(); - } else { - return getType(sourceFile, declaration.initializer).trim(); - } - } - } - - - function expandSourceFiles(sourceFiles, basePath) { - var filePaths = []; - sourceFiles.forEach(function(sourcePattern) { - filePaths = filePaths.concat(glob.sync(sourcePattern, { cwd: basePath })); - }); - return filePaths; - } - - - function getText(sourceFile, node) { - return sourceFile.text.substring(node.pos, node.end); - } - - - // Strip any local renamed imports from the front of types - function getType(sourceFile, type) { - var text = getText(sourceFile, type); - while (text.indexOf(".") >= 0) { - // Keep namespaced symbols in RxNext - if (text.match(/^\s*RxNext\./)) break; - // handle the case List -> List - text = text.replace(/([^.<]*)\.([^>]*)/, "$2"); - } - return text; - } - - function getLocation(symbol) { - var node = symbol.valueDeclaration || symbol.declarations[0]; - var sourceFile = ts.getSourceFileOfNode(node); - var location = { - start: ts.getLineAndCharacterOfPosition(sourceFile, node.pos), - end: ts.getLineAndCharacterOfPosition(sourceFile, node.end) - }; - return location; - } - -}; - -function convertToRegexCollection(items) { - if (!items) return []; - - // Must be an array - if (!_.isArray(items)) { - items = [items]; - } - - // Convert string to exact matching regexes - return items.map(function(item) { - return _.isString(item) ? new RegExp('^' + item + '$') : item; - }); -} - -function anyMatches(regexes, item) { - for(var i=0; i']); - expect(exportedInterface.newMember).toBeDefined(); - expect(exportedInterface.newMember.parameters).toEqual(['param: number']); - expect(exportedInterface.newMember.returnType).toEqual('MyInterface'); - }); - }); - - - describe('ordering of members', function() { - it('should order class members in order of appearance (by default)', function() { - processor.sourceFiles = ['orderingOfMembers.ts']; - var docs = []; - processor.$process(docs); - var classDoc = _.find(docs, { docType: 'class' }); - expect(classDoc.docType).toEqual('class'); - expect(getNames(classDoc.members)).toEqual([ - 'firstItem', - 'otherMethod', - 'doStuff', - ]); - }); - - - it('should not order class members if not sortClassMembers is false', function() { - processor.sourceFiles = ['orderingOfMembers.ts']; - processor.sortClassMembers = false; - var docs = []; - processor.$process(docs); - var classDoc = _.find(docs, { docType: 'class' }); - expect(classDoc.docType).toEqual('class'); - expect(getNames(classDoc.members)).toEqual([ - 'firstItem', - 'otherMethod', - 'doStuff' - ]); - }); - }); -}); - -function getNames(collection) { - return collection.map(function(item) { return item.name; }); -} \ No newline at end of file diff --git a/tools/api-builder/typescript-package/services/convertPrivateClassesToInterfaces.js b/tools/api-builder/typescript-package/services/convertPrivateClassesToInterfaces.js deleted file mode 100644 index 69afdea89e..0000000000 --- a/tools/api-builder/typescript-package/services/convertPrivateClassesToInterfaces.js +++ /dev/null @@ -1,31 +0,0 @@ -var _ = require('lodash'); - -module.exports = function convertPrivateClassesToInterfaces() { - return function(exportDocs, addInjectableReference) { - _.forEach(exportDocs, function(exportDoc) { - - // Search for classes with a constructor marked as `@internal` - if (exportDoc.docType === 'class' && exportDoc.constructorDoc && exportDoc.constructorDoc.internal) { - - // Convert this class to an interface with no constructor - exportDoc.docType = 'interface'; - exportDoc.constructorDoc = null; - - if (exportDoc.heritage) { - // convert the heritage since interfaces use `extends` not `implements` - exportDoc.heritage = exportDoc.heritage.replace('implements', 'extends'); - } - - if (addInjectableReference) { - // Add the `declare var SomeClass extends InjectableReference` construct - exportDocs.push({ - docType: 'var', - name: exportDoc.name, - id: exportDoc.id, - returnType: 'InjectableReference' - }); - } - } - }); - }; -}; diff --git a/tools/api-builder/typescript-package/services/convertPrivateClassesToInterfaces.spec.js b/tools/api-builder/typescript-package/services/convertPrivateClassesToInterfaces.spec.js deleted file mode 100644 index bc4ed7411c..0000000000 --- a/tools/api-builder/typescript-package/services/convertPrivateClassesToInterfaces.spec.js +++ /dev/null @@ -1,76 +0,0 @@ -var mockPackage = require('../mocks/mockPackage'); -var Dgeni = require('dgeni'); -var _ = require('lodash'); - -describe('readTypeScriptModules', function() { - var dgeni, injector, convertPrivateClassesToInterfaces; - - beforeEach(function() { - dgeni = new Dgeni([mockPackage()]); - injector = dgeni.configureInjector(); - convertPrivateClassesToInterfaces = injector.get('convertPrivateClassesToInterfaces'); - }); - - it('should convert private class docs to interface docs', function() { - var docs = [ - { - docType: 'class', - name: 'privateClass', - id: 'privateClass', - constructorDoc: { internal: true } - } - ]; - convertPrivateClassesToInterfaces(docs, false); - expect(docs[0].docType).toEqual('interface'); - }); - - - it('should not touch non-private class docs', function() { - var docs = [ - { - docType: 'class', - name: 'privateClass', - id: 'privateClass', - constructorDoc: { } - } - ]; - convertPrivateClassesToInterfaces(docs, false); - expect(docs[0].docType).toEqual('class'); - }); - - - it('should convert the heritage since interfaces use `extends` not `implements`', function() { - var docs = [ - { - docType: 'class', - name: 'privateClass', - id: 'privateClass', - constructorDoc: { internal: true }, - heritage: 'implements parentInterface' - } - ]; - convertPrivateClassesToInterfaces(docs, false); - expect(docs[0].heritage).toEqual('extends parentInterface'); - }); - - - it('should add new injectable reference types, if specified, to the passed in collection', function() { - var docs = [ - { - docType: 'class', - name: 'privateClass', - id: 'privateClass', - constructorDoc: { internal: true }, - heritage: 'implements parentInterface' - } - ]; - convertPrivateClassesToInterfaces(docs, true); - expect(docs[1]).toEqual({ - docType : 'var', - name : 'privateClass', - id : 'privateClass', - returnType : 'InjectableReference' - }); - }); - -}); diff --git a/tools/api-builder/typescript-package/services/modules.js b/tools/api-builder/typescript-package/services/modules.js deleted file mode 100644 index 7601390220..0000000000 --- a/tools/api-builder/typescript-package/services/modules.js +++ /dev/null @@ -1,3 +0,0 @@ -module.exports = function modules() { - return {}; -}; diff --git a/tools/api-builder/typescript-package/services/tsParser/createCompilerHost.js b/tools/api-builder/typescript-package/services/tsParser/createCompilerHost.js deleted file mode 100644 index 812d608b81..0000000000 --- a/tools/api-builder/typescript-package/services/tsParser/createCompilerHost.js +++ /dev/null @@ -1,80 +0,0 @@ -var ts = require('typescript'); -var fs = require('fs'); -var path = require('canonical-path'); - -// We need to provide our own version of CompilerHost because we want to set the -// base directory and specify what extensions to consider when trying to load a source -// file -module.exports = function createCompilerHost(log) { - - return function createCompilerHost(options, baseDir, extensions) { - - return { - getSourceFile: function(fileName, languageVersion, onError) { - var text, resolvedPath, resolvedPathWithExt; - - // Strip off the extension and resolve relative to the baseDir - baseFilePath = fileName.replace(/\.[^.]+$/, ''); - resolvedPath = path.resolve(baseDir, baseFilePath); - - // Iterate through each possible extension and return the first source file that is actually found - for(var i=0; i