@trapi/metadata
Advanced tools
Comparing version 0.2.3 to 0.3.0
@@ -29,3 +29,3 @@ "use strict"; | ||
decorator_1.TypeNodeResolver.clearCache(); | ||
const sourceFiles = this.scanSourceFiles(config.entryFile); | ||
const sourceFiles = this.scanSourceFiles(config.entryPoint); | ||
this.program = (0, typescript_1.createProgram)(sourceFiles, compilerOptions); | ||
@@ -145,14 +145,22 @@ this.typeChecker = this.program.getTypeChecker(); | ||
} | ||
scanSourceFiles(sourceFiles) { | ||
const sourceFilesExpressions = Array.isArray(sourceFiles) ? sourceFiles : [sourceFiles]; | ||
scanSourceFiles(input) { | ||
const sources = Array.isArray(input) ? input : [input]; | ||
const result = new Set(); | ||
const options = { | ||
cwd: this.config.rootPath || process.cwd(), | ||
nodir: true, | ||
absolute: true, | ||
}; | ||
sourceFilesExpressions.forEach((pattern) => { | ||
const matches = (0, glob_1.sync)(pattern, options); | ||
matches.forEach((file) => { result.add(file); }); | ||
}); | ||
for (let i = 0; i < sources.length; i++) { | ||
const source = sources[i]; | ||
let matches; | ||
if (typeof source === 'string') { | ||
matches = (0, glob_1.sync)(source, Object.assign({}, options)); | ||
} | ||
else { | ||
matches = (0, glob_1.sync)(source.pattern, Object.assign(Object.assign({}, options), { cwd: source.cwd })); | ||
} | ||
for (let j = 0; j < matches.length; j++) { | ||
result.add(matches[j]); | ||
} | ||
} | ||
return Array.from(result); | ||
@@ -159,0 +167,0 @@ } |
@@ -5,2 +5,7 @@ import { ArrayType, BaseType, Config as DecoratorConfig, NestedObjectLiteralType, RefObjectType, ReferenceTypes } from '@trapi/decorator'; | ||
export { CompilerOptions, }; | ||
export declare type EntryPointConfig = { | ||
cwd: string; | ||
pattern: string; | ||
}; | ||
export declare type EntryPoint = string | string[] | EntryPointConfig | EntryPointConfig[]; | ||
export interface Config { | ||
@@ -10,10 +15,4 @@ /** | ||
*/ | ||
entryFile: string | string[]; | ||
entryPoint: EntryPoint; | ||
/** | ||
* Root path. | ||
* | ||
* Default: process.cwd() | ||
*/ | ||
rootPath?: string; | ||
/** | ||
* Directory to ignore during TypeScript files scan. | ||
@@ -20,0 +19,0 @@ * Default: [] |
{ | ||
"name": "@trapi/metadata", | ||
"version": "0.2.3", | ||
"version": "0.3.0", | ||
"description": "Generate REST-API metadata scheme from TypeScript Decorators.", | ||
@@ -57,3 +57,3 @@ "main": "./dist/index.js", | ||
}, | ||
"gitHead": "354c89e48f325ff58eb9a32ec5c4628e1a6f0c97" | ||
"gitHead": "a325c55212f69c91105400621ffa553bc69a1ed1" | ||
} |
@@ -37,2 +37,12 @@ # @trapi/metadata 📚 | ||
export type EntryPointConfig = { | ||
cwd: string, | ||
pattern: string | ||
}; | ||
export type EntryPoint = string | | ||
string[] | | ||
EntryPointConfig | | ||
EntryPointConfig[]; | ||
export interface Config { | ||
@@ -42,3 +52,3 @@ /** | ||
*/ | ||
entryFile: string | string[]; | ||
entryPoint: EntryPoint; | ||
/** | ||
@@ -123,3 +133,6 @@ * Directory to ignore during TypeScript files scan. | ||
const metadata : Output = createMetadata({ | ||
entryFile: path.join(process.cwd(), 'src', 'controllers', '**', '*.ts'), | ||
entryPoint: { | ||
cwd: path.join(process.cwd(), 'src', 'controllers'), | ||
pattern: '**/*.ts' | ||
}, | ||
ignore: ['**/node_modules/**'], | ||
@@ -126,0 +139,0 @@ cache: { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
126165
1752
163