Commit 38469208 authored by rockyl's avatar rockyl

cli wrapper

parent 735bba59
/**
* Created by rockyl on 2019-04-29.
*/
const os = require('os');
const path = require('path');
const fs = require('fs-extra');
const {generateDeclareMap} = require('../src/index');
export async function execute(program){
if(!program.input || !program.output){
console.warn('parameter is incorrect');
process.exit(1);
}
const componentsPath = program.projectPath || path.join(os.homedir(), '.scilla', 'components');
const componentsSrcPath = path.join(componentsPath, 'src');
const tsconfig = fs.readJsonSync(path.join(componentsPath, 'tsconfig.json'));
const inputFile = program.input;
const inputFileFolder = path.dirname(inputFile);
const projectPath = process.cwd();
function declareFilter(source) {
return source.fileName.indexOf(inputFileFolder) >= 0;
}
const result = generateDeclareMap(
tsconfig,
program.input,
componentsSrcPath,
projectPath,
null,
declareFilter
);
if(program.verbose){
console.log(result);
}
if(Object.keys(result.missingDependencies).length > 0){
console.warn(JSON.stringify(result.missingDependencies, null, '\t'));
process.exit(2);
}
fs.ensureDirSync(path.dirname(program.output));
fs.writeJsonSync(program.output, result.declareMap);
}
......@@ -4,56 +4,20 @@
* Created by rockyl on 2019-04-26.
*/
const os = require('os');
const path = require('path');
const fs = require('fs-extra');
import {execute} from "./cli-wrapper";
const program = require('commander');
const {generateDeclareMap} = require('../src/index');
program
.version('1.0.3')
.description('scilla declare generator')
.option('-i, --input [string]', 'input file')
.option('-o, --output [string]', 'output file')
.option('-p, --pathofcomponents [string]', 'path of components')
.option('-p, --projectPath [string]', 'path of components')
.option('-v, --verbose [boolean]', 'verbose mode', false)
.parse(process.argv);
if(!program.input || !program.output){
console.warn('parameter is incorrect');
process.exit(1);
}
const componentsPath = program.pathofcomponents || path.join(os.homedir(), '.scilla', 'components');
const componentsSrcPath = path.join(componentsPath, 'src');
const tsconfig = fs.readJsonSync(path.join(componentsPath, 'tsconfig.json'));
const inputFile = program.input;
const inputFileFolder = path.dirname(inputFile);
const projectPath = process.cwd();
function declareFilter(source) {
return source.fileName.indexOf(inputFileFolder) >= 0;
}
const result = generateDeclareMap(
tsconfig,
program.input,
componentsSrcPath,
projectPath,
null,
declareFilter
);
if(program.verbose){
console.log(result);
}
if(Object.keys(result.missingDependencies).length > 0){
console.warn(JSON.stringify(result.missingDependencies, null, '\t'));
execute(program).catch(e=>{
console.error(e);
process.exit(2);
}
fs.ensureDirSync(path.dirname(program.output));
fs.writeJsonSync(program.output, result.declareMap);
});
{
"name": "scilla-declare-generator",
"version": "1.0.2",
"version": "1.0.3",
"main": "src/index.js",
"bin": "bin/cli.js",
"license": "MIT",
......
......@@ -35,6 +35,7 @@ exports.generateDeclareMap = function(tsconfig, file, componentsPath, projectPat
if(showLog) console.timeEnd('getTypeChecker');
if(showLog) console.time('delint');
const dependencies = [];
const missingDependencies = {};
for(let sourceFile of sourceFiles){
if (sourceFile.fileName.indexOf('.d.ts') < 0) {
......@@ -42,6 +43,9 @@ exports.generateDeclareMap = function(tsconfig, file, componentsPath, projectPat
const fileName = sourceFile.fileName;
if(sourceFile.resolvedModules){
sourceFile.resolvedModules.forEach((item, key)=>{
if(!dependencies.includes(key)){
dependencies.push(key);
}
if(!item){
let t = missingDependencies[fileName];
if(!t){
......@@ -61,6 +65,7 @@ exports.generateDeclareMap = function(tsconfig, file, componentsPath, projectPat
return {
declareMap,
dependencies,
missingDependencies,
};
};
......
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