Skip to content

Commit

Permalink
feat: use typescript v5 (#107)
Browse files Browse the repository at this point in the history
  • Loading branch information
fengmk2 authored Aug 2, 2023
1 parent 639278d commit a934501
Show file tree
Hide file tree
Showing 14 changed files with 38 additions and 62 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ on:
branches: [ "master" ]
pull_request:
branches: [ "master" ]
schedule:
- cron: "55 4 * * 4"

jobs:
analyze:
Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ on:
jobs:
Job:
name: Node.js
uses: artusjs/github-actions/.github/workflows/node-test.yml@v1
uses: node-modules/github-actions/.github/workflows/node-test.yml@master
with:
os: 'ubuntu-latest'
version: '14, 16, 18'
install: 'npm i -g npminstall && npminstall'
version: '14, 16, 18, 20'
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
jobs:
release:
name: Node.js
uses: artusjs/github-actions/.github/workflows/node-release.yml@v1
uses: node-modules/github-actions/.github/workflows/node-release.yml@master
secrets:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
GIT_TOKEN: ${{ secrets.GIT_TOKEN }}
Expand Down
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
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,16 @@
"author": "wanghx",
"license": "MIT",
"dependencies": {
"chalk": "^2.4.2",
"chalk": "^4.0.0",
"chokidar": "^3.0.0",
"commander": "^2.15.1",
"dot-prop": "^4.2.0",
"enquirer": "^2.3.0",
"globby": "^11.0.0",
"json5": "^2.2.0",
"json5": "^2.2.3",
"ts-node": "^10.9.1",
"tslib": "^2.0.0",
"typescript": "^4.0.0",
"tslib": "^2.6.1",
"typescript": "^5.1.6",
"yn": "^3.0.0"
},
"devDependencies": {
Expand All @@ -53,11 +53,11 @@
"@types/del": "^3.0.0",
"@types/globby": "^6.1.0",
"@types/mocha": "^10.0.0",
"@types/node": "^14.18.36",
"@types/node": "^20.4.5",
"del": "^3.0.0",
"del-cli": "^1.1.0",
"egg": "^3.5.0",
"egg-bin": "^5.5.0",
"egg-bin": "^6.4.1",
"egg-mock": "^5.2.1",
"egg-sequelize": "^4.3.1",
"eslint": "^8.28.0",
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/clean.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { cleanJs } from '../utils';
import chalk from 'chalk';
import { cleanJs } from '../utils';

class CleanCommand implements SubCommand {
description = 'Clean js file while it has the same name ts/tsx file';
Expand Down
3 changes: 1 addition & 2 deletions 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 Expand Up @@ -546,7 +545,7 @@ export function isClass(v): v is { new (...args: any[]): any } {
}

// check kind in node.modifiers.
export function modifierHas(node: ts.Node, kind) {
export function modifierHas(node, kind) {
return node.modifiers && node.modifiers.find(mod => kind === mod.kind);
}

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
1 change: 0 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"esModuleInterop": true,
"charset": "utf8",
"allowJs": false,
"pretty": true,
"declaration": true,
Expand Down

0 comments on commit a934501

Please sign in to comment.