Commit 11313198 authored by rockyl's avatar rockyl

修改generate返回值,增加找不到依赖的列表

parent 54f66b5a
...@@ -15,6 +15,7 @@ program ...@@ -15,6 +15,7 @@ program
.description('scilla declare generator') .description('scilla declare generator')
.option('-i, --input [string]', 'input file') .option('-i, --input [string]', 'input file')
.option('-o, --output [string]', 'output file') .option('-o, --output [string]', 'output file')
.option('-v, --verbose [boolean]', 'verbose mode', false)
.parse(process.argv); .parse(process.argv);
const systemComponentsPath = path.join(os.homedir(), '.scilla', 'components'); const systemComponentsPath = path.join(os.homedir(), '.scilla', 'components');
...@@ -39,4 +40,13 @@ const result = generateDeclareMap( ...@@ -39,4 +40,13 @@ const result = generateDeclareMap(
declareFilter declareFilter
); );
console.log(result); if(program.verbose){
console.log(result);
}
if(result.missingDependencies.length > 0){
process.exit(1);
}
fs.ensureDirSync(path.dirname(program.output));
fs.writeJsonSync(program.output, result.declareMap);
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
const ts = require('typescript'); const ts = require('typescript');
let classDeclareMap; let declareMap;
let _componentsPath; let _componentsPath;
let _projectPath; let _projectPath;
let _assetsPath; let _assetsPath;
...@@ -28,16 +28,24 @@ exports.generateDeclareMap = function(tsconfig, file, componentsPath, projectPat ...@@ -28,16 +28,24 @@ exports.generateDeclareMap = function(tsconfig, file, componentsPath, projectPat
const program = ts.createProgram(files, config.options); const program = ts.createProgram(files, config.options);
const sourceFiles = program.getSourceFiles(); const sourceFiles = program.getSourceFiles();
classDeclareMap = {}; declareMap = {};
if(showLog) console.time('getTypeChecker'); if(showLog) console.time('getTypeChecker');
const checker = program.getTypeChecker(); const checker = program.getTypeChecker();
if(showLog) console.timeEnd('getTypeChecker'); if(showLog) console.timeEnd('getTypeChecker');
if(showLog) console.time('delint'); if(showLog) console.time('delint');
const missingDependencies = [];
for(let sourceFile of sourceFiles){ for(let sourceFile of sourceFiles){
if (sourceFile.fileName.indexOf('.d.ts') < 0) { if (sourceFile.fileName.indexOf('.d.ts') < 0) {
if(!_filter || _filter(sourceFile)){ if(!_filter || _filter(sourceFile)){
if(sourceFile.resolvedModules){
sourceFile.resolvedModules.forEach((item, key)=>{
if(!item){
missingDependencies.push(key);
}
});
}
if(showLog && showVerboseLog) console.time(sourceFile.fileName); if(showLog && showVerboseLog) console.time(sourceFile.fileName);
delint(checker, sourceFile); delint(checker, sourceFile);
if(showLog && showVerboseLog) console.timeEnd(sourceFile.fileName); if(showLog && showVerboseLog) console.timeEnd(sourceFile.fileName);
...@@ -46,11 +54,10 @@ exports.generateDeclareMap = function(tsconfig, file, componentsPath, projectPat ...@@ -46,11 +54,10 @@ exports.generateDeclareMap = function(tsconfig, file, componentsPath, projectPat
} }
if(showLog) console.timeEnd('delint'); if(showLog) console.timeEnd('delint');
/*for(let name in classDeclareMap){ return {
transFullyDeclare(name); declareMap,
}*/ missingDependencies,
};
return classDeclareMap;
}; };
function delint(checker, sourceFile) { function delint(checker, sourceFile) {
...@@ -63,10 +70,10 @@ function delint(checker, sourceFile) { ...@@ -63,10 +70,10 @@ function delint(checker, sourceFile) {
const {fullClassName: enumName} = getFullyQualifiedNameOfType(checker.getTypeAtLocation(node), checker); const {fullClassName: enumName} = getFullyQualifiedNameOfType(checker.getTypeAtLocation(node), checker);
let members; let members;
if (enumName in classDeclareMap) { if (enumName in declareMap) {
members = classDeclareMap[enumName]; members = declareMap[enumName];
} else { } else {
classDeclareMap[enumName] = members = { declareMap[enumName] = members = {
__type__: 'enum', __type__: 'enum',
map: {}, map: {},
}; };
...@@ -89,10 +96,10 @@ function delint(checker, sourceFile) { ...@@ -89,10 +96,10 @@ function delint(checker, sourceFile) {
const {fullClassName, path, className} = getFullyQualifiedNameOfType(checker.getTypeAtLocation(node), checker); const {fullClassName, path, className} = getFullyQualifiedNameOfType(checker.getTypeAtLocation(node), checker);
let members; let members;
if (fullClassName in classDeclareMap) { if (fullClassName in declareMap) {
members = classDeclareMap[fullClassName]; members = declareMap[fullClassName];
} else { } else {
classDeclareMap[fullClassName] = members = {properties: {}, methods: {}}; declareMap[fullClassName] = members = {properties: {}, methods: {}};
} }
getJsDoc(members, node); getJsDoc(members, node);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment