diff --git a/types/feflow__cli/feflow__cli-tests.ts b/types/feflow__cli/feflow__cli-tests.ts new file mode 100644 index 0000000000..b6fbc6dd06 --- /dev/null +++ b/types/feflow__cli/feflow__cli-tests.ts @@ -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'); + }); +}; diff --git a/types/feflow__cli/index.d.ts b/types/feflow__cli/index.d.ts new file mode 100644 index 0000000000..1f59db421b --- /dev/null +++ b/types/feflow__cli/index.d.ts @@ -0,0 +1,120 @@ +// Type definitions for @feflow/cli 0.18 +// Project: https://github.com/Tencent/feflow/releases +// Definitions by: nikewu +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// +/** + * feflow namespace + */ +declare namespace Feflow { + /** + * feflow context + */ + interface ctx { + /** + * Feflow context params + */ + args: { + _: Array + }; + /** + * 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 eg:devtool + * @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 eg:report + * @param fn Hook callback function eg:report + */ + 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; +} diff --git a/types/feflow__cli/tsconfig.json b/types/feflow__cli/tsconfig.json new file mode 100644 index 0000000000..a9dd275098 --- /dev/null +++ b/types/feflow__cli/tsconfig.json @@ -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" + ] +} diff --git a/types/feflow__cli/tslint.json b/types/feflow__cli/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/feflow__cli/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }