Feature/add typings for feflow cli (#43565)

* feat: Add typings for feflow

* feat: update comment

* feat: fix new line warn

* fix: package name error

* fix: package name  error

* feat: change test name

* fix: fix lint error

* fix: blank error for  lint

* feat: support npm path

* feat: change namespace and tests

Co-authored-by: yanzhanghu <yanzhanghu@tencent.com>
This commit is contained in:
fengbingzi
2020-04-04 08:18:07 +08:00
committed by GitHub
parent ceb9e7338e
commit da93d7b130
4 changed files with 169 additions and 0 deletions

View File

@@ -0,0 +1,20 @@
module.exports = (ctx: Feflow.ctx) => {
const {
commander,
hook,
logger,
} = ctx;
const [ action ] = ctx.args['_'];
logger.debug(String(action));
commander.register('devtool', 'Feflow devtool for better develop a devkit or plugin', async () => {
logger.trace('Start dev');
logger.debug('Start test');
logger.info('Start info');
});
hook.hook('devtool', async () => {
logger.warn('Start warn');
logger.error('Start error');
logger.fatal('Start fatal');
});
};

120
types/feflow__cli/index.d.ts vendored Normal file
View File

@@ -0,0 +1,120 @@
// Type definitions for @feflow/cli 0.18
// Project: https://github.com/Tencent/feflow/releases
// Definitions by: nikewu <https://github.com/nikewu>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference types="node"/>
/**
* feflow namespace
*/
declare namespace Feflow {
/**
* feflow context
*/
interface ctx {
/**
* Feflow context params
*/
args: {
_: Array<number | string>
};
/**
* Feflow configuration file in the current directory
* ( .feflowrc.json/.feflowrc.js/.feflowrc.yml )
*/
projectConfig: string;
/**
* Current project path
*/
projectPath: string;
/**
* Feflow version
*/
version: string;
/**
* Feflow logger includes: (trace、debug、info、warn、error、fatal)
*/
logger: Logger;
/**
* Feflow command includes: (register)
*/
commander: Command;
/**
* Feflow hook includes: (hook)
*/
hook: Hook;
/**
* Feflow home directory path
*/
root: string;
/**
* Feflow home directory package.json path
*/
rootPkg: string;
/**
* feflow config
*/
config: string;
/**
* feflow config path
*/
configPath: string;
}
}
interface Command {
/**
* Plugin registration command method parameter description
* @param cmd Plugin command name egdevtool
* @param desc Plugin command description eg Feflow devtool for better develop a devkit or plugin
* @param fn Plugin callback function
*/
register(cmd: string, desc: string, fn: () => void): void;
}
interface Hook {
/**
* Hook will execute befor any command
* Hook registration command method parameter description
* @param type Hook name egreport
* @param fn Hook callback function egreport
*/
hook(type: string, fn: () => void): void;
}
interface Logger {
/**
* Print trace level log, The Color is gray
* @param desc log detail
*/
trace(desc: string): void;
/**
* Print trace level log, The Color is gray
* @param desc log detail
*/
debug(desc: string): void;
/**
* Print trace level log, The Color is green
* @param desc log detail
*/
info(desc: string): void;
/**
* Print trace level log, The Color is yellow
* @param desc log detail
*/
warn(desc: string): void;
/**
* Print trace level log, The Color is red
* @param desc log detail
*/
error(desc: string): void;
/**
* Print trace level log, The Color is red
* @param desc log detail
*/
fatal(desc: string): void;
}

View File

@@ -0,0 +1,28 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true,
"paths": {
"@feflow/cli": [
"feflow__cli"
]
}
},
"files": [
"index.d.ts",
"feflow__cli-tests.ts"
]
}

View File

@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }