Skip to content

Commit

Permalink
f
Browse files Browse the repository at this point in the history
  • Loading branch information
fengmk2 committed Aug 2, 2023
1 parent 34e5df7 commit 578fc23
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 47 deletions.
27 changes: 10 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,39 +15,32 @@

A simple tool for creating `d.ts` in [egg](https://eggjs.org) application. Injecting `controller, proxy, service, etc.` to definition type of egg ( such as `Context` `Application` etc. ) by [Declaration Merging](https://www.typescriptlang.org/docs/handbook/declaration-merging.html), and making IntelliSense works in both egg-js and egg-ts.


## Install

open your application and install.

```
```bash
npm i egg-ts-helper --save-dev
```

or

```
yarn add egg-ts-helper --dev
```

## QuickStart

Open your egg application, executing ets by [npx](https://github.com/zkat/npx)

```
$ npx ets
```bash
npx ets
```

Watching files by `-w` flag.

```
$ npx ets -w
```bash
npx ets -w
```

`egg-ts-helper` has build-in in `egg-bin`, You can easily to use it by

```
$ egg-bin dev --dts
```bash
egg-bin dev --dts
```

or add configuration `egg.declarations` in `package.json`
Expand Down Expand Up @@ -180,7 +173,7 @@ Also you can pass options by env ( support since 1.22.0 )

> Support since 1.24.0
`egg-ts-helper` support customLoader configuration of egg. see https://github.com/eggjs/egg/issues/3480
`egg-ts-helper` support customLoader configuration of egg. see <https://github.com/eggjs/egg/issues/3480>

Configure in `config.default.ts`

Expand Down Expand Up @@ -535,9 +528,9 @@ module.exports = {

`egg-ts-helper` can works in both `ts` and `js` egg project.

TS demo: https://github.com/whxaxes/egg-boilerplate-d-ts
TS demo: <https://github.com/whxaxes/egg-boilerplate-d-ts>

JS demo: https://github.com/whxaxes/egg-boilerplate-d-js
JS demo: <https://github.com/whxaxes/egg-boilerplate-d-js>

## License

Expand Down
30 changes: 12 additions & 18 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,41 +19,35 @@

打开应用目录并且安装

```
```bash
npm i egg-ts-helper --save-dev
```

或者

```
yarn add egg-ts-helper --dev
```

## 快速开始

打开你的 egg 应用,通过 [npx](https://github.com/zkat/npx) 来执行 ets 指令

```
$ npx ets
```bash
npx ets
```

可以通过 `-w` 来监听文件改动并且重新生成 `d.ts`

```
$ npx ets -w
```bash
npx ets -w
```

`egg-ts-helper` 已经内置在 `egg-bin` 中,可以通过以下命令方便使用

```
$ egg-bin dev --dts
```bash
egg-bin dev --dts
```

再或者在 `package.json` 中配置 `egg.declarations` 为 true 即可。

## 命令行

```
```bash
$ ets -h

Usage: ets [commands] [options]
Expand Down Expand Up @@ -161,7 +155,7 @@ module.exports = {

> 在 1.24.0 之后版本支持
`egg-ts-helper` 支持 egg 的 customLoader 配置,会自动去读取应用/插件/框架中的 customLoader 配置. 详情请看 https://github.com/eggjs/egg/issues/3480
`egg-ts-helper` 支持 egg 的 customLoader 配置,会自动去读取应用/插件/框架中的 customLoader 配置. 详情请看 <https://github.com/eggjs/egg/issues/3480>

`config.default.ts` 中配置 customLoader

Expand Down Expand Up @@ -190,7 +184,7 @@ export default function(appInfo: EggAppConfig) {
}
```

`egg-ts-helper` 将会根据 `app/model` 目录下的文件,自动生成声明 ( 参考 https://github.com/whxaxes/egg-boilerplate-d-ts 这个项目 )
`egg-ts-helper` 将会根据 `app/model` 目录下的文件,自动生成声明 ( 参考 <https://github.com/whxaxes/egg-boilerplate-d-ts> 这个项目 )

```typescript
// This file is created by [email protected]
Expand Down Expand Up @@ -515,9 +509,9 @@ module.exports = {

`egg-ts-helper` 可用于 egg 的 `ts``js` 项目.

TS 项目: https://github.com/whxaxes/egg-boilerplate-d-ts
TS 项目: <https://github.com/whxaxes/egg-boilerplate-d-ts>

JS 项目: https://github.com/whxaxes/egg-boilerplate-d-js
JS 项目: <https://github.com/whxaxes/egg-boilerplate-d-js>

## License

Expand Down
1 change: 0 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export const TS_CONFIG: Partial<TsConfigJson> = {
experimentalDecorators: true,
emitDecoratorMetadata: true,
allowSyntheticDefaultImports: true,
charset: 'utf8',
allowJs: false,
pretty: true,
lib: [ 'es6' ],
Expand Down
3 changes: 1 addition & 2 deletions src/watcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ export default class Watcher extends EventEmitter {
.concat(utils.toArray(this.options.ignore).map(p => `!${utils.formatPath(p)}`));

assert(options.directory, `options.directory must set in ${generatorName}`);
const baseDir = options.directory.replace(/\/|\\/, path.sep);
this.dir = path.resolve(this.config.cwd, baseDir);
this.dir = path.resolve(this.config.cwd, options.directory);
this.dtsDir = path.resolve(
this.config.typings,
path.relative(this.config.cwd, this.dir),
Expand Down
5 changes: 2 additions & 3 deletions test/fixtures/app12/tsHelper.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"generatorConfig.dal": {
"directory": "app/dal/dao",
"caseStyle": "upper",
"watch": false
"caseStyle": "upper"
}
}
}
5 changes: 2 additions & 3 deletions test/fixtures/app13/tsCustom.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"generatorConfig.dal": {
"directory": "app/dal/dao",
"caseStyle": "upper",
"watch": false
"caseStyle": "upper"
}
}
}
1 change: 0 additions & 1 deletion test/fixtures/app9/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"module": "commonjs",
"moduleResolution": "node",
"skipLibCheck": true,
"watch": false,
"jsx": "react",
},
"include": [
Expand Down
2 changes: 0 additions & 2 deletions test/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
"esModuleInterop": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"charset": "utf8",
"allowJs": true,
"watch": false,
"pretty": true,
"noEmitOnError": false,
"noUnusedLocals": true,
Expand Down

0 comments on commit 578fc23

Please sign in to comment.