Commit 11313198 authored by rockyl's avatar rockyl

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

parent 54f66b5a
......@@ -15,6 +15,7 @@ program
.description('scilla declare generator')
.option('-i, --input [string]', 'input file')
.option('-o, --output [string]', 'output file')
.option('-v, --verbose [boolean]', 'verbose mode', false)
.parse(process.argv);
const systemComponentsPath = path.join(os.homedir(), '.scilla', 'components');
......@@ -39,4 +40,13 @@ const result = generateDeclareMap(
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 @@
const ts = require('typescript');
let classDeclareMap;
let declareMap;
let _componentsPath;
let _projectPath;
let _assetsPath;
......@@ -28,16 +28,24 @@ exports.generateDeclareMap = function(tsconfig, file, componentsPath, projectPat
const program = ts.createProgram(files, config.options);
const sourceFiles = program.getSourceFiles();
classDeclareMap = {};
declareMap = {};
if(showLog) console.time('getTypeChecker');
const checker = program.getTypeChecker();
if(showLog) console.timeEnd('getTypeChecker');
if(showLog) console.time('delint');
const missingDependencies = [];
for(let sourceFile of sourceFiles){
if (sourceFile.fileName.indexOf('.d.ts') < 0) {
if(!_filter || _filter(sourceFile)){
if(sourceFile.resolvedModules){
sourceFile.resolvedModules.forEach((item, key)=>{
if(!item){
missingDependencies.push(key);
}
});
}
if(showLog && showVerboseLog) console.time(sourceFile.fileName);
delint(checker, sourceFile);
if(showLog && showVerboseLog) console.timeEnd(sourceFile.fileName);
......@@ -46,11 +54,10 @@ exports.generateDeclareMap = function(tsconfig, file, componentsPath, projectPat
}
if(showLog) console.timeEnd('delint');
/*for(let name in classDeclareMap){
transFullyDeclare(name);
}*/
return classDeclareMap;
return {
declareMap,
missingDependencies,
};
};
function delint(checker, sourceFile) {
......@@ -63,10 +70,10 @@ function delint(checker, sourceFile) {
const {fullClassName: enumName} = getFullyQualifiedNameOfType(checker.getTypeAtLocation(node), checker);
let members;
if (enumName in classDeclareMap) {
members = classDeclareMap[enumName];
if (enumName in declareMap) {
members = declareMap[enumName];
} else {
classDeclareMap[enumName] = members = {
declareMap[enumName] = members = {
__type__: 'enum',
map: {},
};
......@@ -89,10 +96,10 @@ function delint(checker, sourceFile) {
const {fullClassName, path, className} = getFullyQualifiedNameOfType(checker.getTypeAtLocation(node), checker);
let members;
if (fullClassName in classDeclareMap) {
members = classDeclareMap[fullClassName];
if (fullClassName in declareMap) {
members = declareMap[fullClassName];
} else {
classDeclareMap[fullClassName] = members = {properties: {}, methods: {}};
declareMap[fullClassName] = members = {properties: {}, methods: {}};
}
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