egg-ts-helper
Advanced tools
Comparing version 1.30.4 to 1.31.0
@@ -5,66 +5,3 @@ #! /usr/bin/env node | ||
const tslib_1 = require("tslib"); | ||
const path_1 = tslib_1.__importDefault(require("path")); | ||
const commander_1 = require("commander"); | ||
const assert_1 = tslib_1.__importDefault(require("assert")); | ||
const package_json_1 = tslib_1.__importDefault(require("../package.json")); | ||
const _1 = require("./"); | ||
const utils_1 = require("./utils"); | ||
const commands = (0, utils_1.loadModules)(path_1.default.resolve(__dirname, './cmd'), true); | ||
let executeCmd; | ||
// override executeSubCommand to support async subcommand. | ||
commander_1.Command.prototype.addImplicitHelpCommand = () => { }; | ||
commander_1.Command.prototype.executeSubCommand = async function (argv, args, unknown) { | ||
const cwd = this.cwd || _1.defaultConfig.cwd; | ||
const command = commands[executeCmd]; | ||
(0, assert_1.default)(command, executeCmd + ' does not exist'); | ||
await command.run(this, { cwd, argv, args: args.filter(item => item !== this), unknown }); | ||
}; | ||
const program = new commander_1.Command() | ||
.version(package_json_1.default.version, '-v, --version') | ||
.usage('[commands] [options]') | ||
.option('-w, --watch', 'Watching files, d.ts would recreated while file changed') | ||
.option('-c, --cwd [path]', 'Egg application base dir (default: process.cwd)') | ||
.option('-C, --config [path]', 'Configuration file, The argument can be a file path to a valid JSON/JS configuration file.(default: {cwd}/tshelper.js') | ||
.option('-f, --framework [name]', 'Egg framework(default: egg)') | ||
.option('-o, --oneForAll [path]', 'Create a d.ts import all types (default: typings/ets.d.ts)') | ||
.option('-s, --silent', 'Running without output') | ||
.option('-i, --ignore [dirs]', 'Ignore watchDirs, your can ignore multiple dirs with comma like: -i controller,service') | ||
.option('-e, --enabled [dirs]', 'Enable watchDirs, your can enable multiple dirs with comma like: -e proxy,other') | ||
.option('-E, --extra [json]', 'Extra config, the value should be json string'); | ||
if (!process.argv.slice(2).length) { | ||
execute(); | ||
} | ||
else { | ||
Object.keys(commands).forEach(cmd => { | ||
const subCommand = commands[cmd]; | ||
const cmdName = subCommand.options ? `${cmd} ${subCommand.options}` : cmd; | ||
program.command(cmdName, subCommand.description) | ||
.action(command => executeCmd = command); | ||
}); | ||
program.parse(process.argv); | ||
if (!executeCmd) { | ||
execute(); | ||
} | ||
} | ||
// execute fn | ||
function execute() { | ||
const watchFiles = program.watch; | ||
const watchDirs = {}; | ||
(program.ignore || '').split(',').forEach(key => (watchDirs[key] = false)); | ||
(program.enabled || '').split(',').forEach(key => (watchDirs[key] = true)); | ||
const tsHelperConfig = Object.assign({ cwd: program.cwd || _1.defaultConfig.cwd, framework: program.framework, watch: watchFiles, watchDirs, configFile: program.config }, (program.extra ? JSON.parse(program.extra) : {})); | ||
// silent | ||
if (program.silent) { | ||
tsHelperConfig.silent = true; | ||
} | ||
if ((0, utils_1.checkMaybeIsJsProj)(tsHelperConfig.cwd)) { | ||
// write jsconfig if the project is wrote by js | ||
(0, utils_1.writeJsConfig)(tsHelperConfig.cwd); | ||
} | ||
// create instance | ||
const tsHelper = (0, _1.createTsHelperInstance)(tsHelperConfig).build(); | ||
if (program.oneForAll) { | ||
// create one for all | ||
tsHelper.createOneForAll(program.oneForAll); | ||
} | ||
} | ||
const command_1 = tslib_1.__importDefault(require("./command")); | ||
new command_1.default().init(process.argv); |
@@ -1,2 +0,9 @@ | ||
export {}; | ||
import TsHelper from './'; | ||
export default class Register { | ||
tsHelperClazz: typeof TsHelper; | ||
constructor(options?: { | ||
tsHelperClazz?: typeof TsHelper; | ||
}); | ||
init(): void; | ||
} | ||
//# sourceMappingURL=register.d.ts.map |
@@ -6,39 +6,43 @@ "use strict"; | ||
const debug_1 = tslib_1.__importDefault(require("debug")); | ||
const _1 = require("./"); | ||
const _1 = tslib_1.__importDefault(require("./")); | ||
const util = tslib_1.__importStar(require("./utils")); | ||
const debug = (0, debug_1.default)('egg-ts-helper#register'); | ||
/* istanbul ignore else */ | ||
if (cluster_1.default.isMaster) { | ||
// make sure ets only run once | ||
const pid = process.env.ETS_REGISTER_PID; | ||
if (pid) { | ||
debug('egg-ts-helper watcher has ran in %s', pid); | ||
class Register { | ||
constructor(options) { | ||
this.tsHelperClazz = (options === null || options === void 0 ? void 0 : options.tsHelperClazz) || _1.default; | ||
} | ||
else { | ||
register(util.convertString(process.env.ETS_WATCH, process.env.NODE_ENV !== 'test')); | ||
} | ||
} | ||
// start to register | ||
function register(watch) { | ||
const cwd = process.cwd(); | ||
const instance = (0, _1.createTsHelperInstance)({ watch }); | ||
if (util.checkMaybeIsJsProj(cwd)) { | ||
// write jsconfig if the project is wrote by js | ||
util.writeJsConfig(cwd); | ||
} | ||
else { | ||
const tsNodeMode = process.env.EGG_TYPESCRIPT === 'true'; | ||
// no need to clean in js project | ||
// clean local js file at first. | ||
// because egg-loader cannot load the same property name to egg. | ||
if (tsNodeMode && instance.config.autoRemoveJs) { | ||
util.cleanJs(cwd); | ||
init() { | ||
/* istanbul ignore else */ | ||
if (!cluster_1.default.isMaster) | ||
return; | ||
// make sure ets only run once | ||
const pid = process.env.ETS_REGISTER_PID; | ||
if (pid) { | ||
return debug('egg-ts-helper watcher has ran in %s', pid); | ||
} | ||
const watch = util.convertString(process.env.ETS_WATCH, process.env.NODE_ENV !== 'test'); | ||
const clazz = this.tsHelperClazz; | ||
const cwd = process.cwd(); | ||
const instance = new clazz({ watch }); | ||
if (util.checkMaybeIsJsProj(cwd)) { | ||
// write jsconfig if the project is wrote by js | ||
util.writeJsConfig(cwd); | ||
} | ||
else { | ||
const tsNodeMode = process.env.EGG_TYPESCRIPT === 'true'; | ||
// no need to clean in js project | ||
// clean local js file at first. | ||
// because egg-loader cannot load the same property name to egg. | ||
if (tsNodeMode && instance.config.autoRemoveJs) { | ||
util.cleanJs(cwd); | ||
} | ||
} | ||
if (watch) { | ||
// cache pid to env, prevent child process executing ets again | ||
process.env.ETS_REGISTER_PID = `${process.pid}`; | ||
} | ||
// exec building | ||
instance.build(); | ||
} | ||
if (watch) { | ||
// cache pid to env, prevent child process executing ets again | ||
process.env.ETS_REGISTER_PID = `${process.pid}`; | ||
} | ||
// exec building | ||
(0, _1.createTsHelperInstance)({ watch }).build(); | ||
} | ||
exports.default = Register; |
1.31.0 / 2022-07-18 | ||
================== | ||
**features** | ||
* [[`874c1b2`](http://github.com/whxaxes/egg-ts-helper/commit/874c1b210e48626a33a98cafaba4a0bf986b3372)] - feat: make command & register as clazz (#88) (吖猩 <<whxaxes@gmail.com>>) | ||
1.30.4 / 2022-06-30 | ||
@@ -3,0 +9,0 @@ ================== |
{ | ||
"name": "egg-ts-helper", | ||
"version": "1.30.4", | ||
"version": "1.31.0", | ||
"description": "egg typescript helper", | ||
@@ -14,2 +14,10 @@ "bin": { | ||
}, | ||
"exports": { | ||
".": "./dist/index.js", | ||
"./command": "./dist/command.js", | ||
"./register": "./dist/register.js", | ||
"./config": "./dist/config.js", | ||
"./watcher": "./dist/watcher.js", | ||
"./generators/*": "./dist/generators/*.js" | ||
}, | ||
"scripts": { | ||
@@ -16,0 +24,0 @@ "build": "tsc -d", |
@@ -1,1 +0,2 @@ | ||
require('./dist/register'); | ||
const Register = require('./dist/register').default; | ||
new Register().init(); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
144437
69
2358