Skip to content

Commit e69dbd9

Browse files
authored
Merge pull request #153 from FrontEndDev-org/feat/v0.x
Feat/v0.x
2 parents 1831944 + 353dee9 commit e69dbd9

20 files changed

+230
-129
lines changed

.eslintrc.cjs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,28 @@ module.exports = defineConfig({
1010
},
1111

1212
overrides: [
13+
{
14+
files: ['*.cjs'],
15+
extends: [
16+
//
17+
'eslint:recommended',
18+
],
19+
rules: {
20+
'prettier/prettier': 'error',
21+
},
22+
},
1323
{
1424
files: ['*.mjs'],
1525
parserOptions: {
1626
sourceType: 'module',
1727
},
28+
extends: [
29+
//
30+
'eslint:recommended',
31+
],
32+
rules: {
33+
'prettier/prettier': 'error',
34+
},
1835
},
1936
{
2037
files: ['*.ts'],

.husky/pre-commit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/usr/bin/env sh
22
. "$(dirname -- "$0")/_/husky.sh"
33

4-
npx lint-staged
4+
npx lint-staged --allow-empty

.lintstagedrc.cjs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
module.exports = {
2-
'*.ts': 'eslint --fix',
3-
'*': 'prettier --ignore-unknown --write',
2+
'(src|test)/*.{cjs,mjs,ts,tsx}': 'eslint --fix',
3+
'*.{cjs,mjs,ts,tsx,html,css,scss}': 'prettier --write',
4+
'(package|tsconfig*).json': 'prettier --write',
45
};

README.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -131,22 +131,22 @@ generate({
131131

132132
# 配置
133133

134-
| 参数名 | 类型 | 可选性 | 描述 | 默认值 |
135-
| -------------------- | ----------------- | ------- | --------------------------------------------------------------------------------- | ----------------------------------------------- |
136-
| `cwd` | `string` | `false` | 当前工作路径 | `process.cwd()` |
137-
| `dest` | `string` | `false` | 目标目录 | `src/apis` |
138-
| `axiosImport` | `string` | `false` | axios 导入内容 | 默认从官方 Axios 导入,可以使用自己实现的客户端 |
139-
| `unwrapResponseData` | `boolean` | `false` | 是否取消对 axios response 的包裹(即直接返回 ResponseData,而不是 AxiosResponse) | `false` |
140-
| `apis` | `OpenapiConfig[]` | `false` | OpenAPI 列表 | `[]` |
134+
| 参数名 | 类型 | 可选性 | 描述 | 默认值 |
135+
|----------------------|-------------------|---------|----------------------------------------------------------------|-----------------------------|
136+
| `cwd` | `string` | `false` | 当前工作路径 | `process.cwd()` |
137+
| `dest` | `string` | `false` | 目标目录 | `src/apis` |
138+
| `axiosImport` | `string` | `false` | axios 导入内容 | 默认从官方 Axios 导入,可以使用自己实现的客户端 |
139+
| `unwrapResponseData` | `boolean` | `false` | 是否取消对 axios response 的包裹(即直接返回 ResponseData,而不是 AxiosResponse) | `false` |
140+
| `apis` | `OpenapiConfig[]` | `false` | OpenAPI 列表 | `[]` |
141141

142142
`OpenapiConfig` 签名:
143143

144-
| 名称 | 类型 | 可选项 | 描述 | 默认值 |
145-
| -------------------- | --------- | ------------ | --------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------- | ----------- |
146-
| `name` | `string` | 必须 | openapi 的名称,将会生成 ${name}.ts 文件 | `undefined` |
147-
| `axiosImport` | `string` | 可选 | axios 导入内容,优先级更高 | |
148-
| `unwrapResponseData` | `boolean` | 可选 | 是否取消对 axios response 的包裹,优先级更高(即直接返回 ResponseData,而不是 AxiosResponse) | `false` |
149-
| `schema` | `string | OpenApiSpec` | 必须 | openapi 的 schema,可以是一个链接地址,也可以是本地路径,也可以是一个对象 | `undefined` |
144+
| 名称 | 类型 | 可选 | 描述 | 默认值 |
145+
|----------------------|-----------|--------------|----------------------------------------------------------------------|----------------------------------------------|
146+
| `name` | `string` | 必须 | openapi 的名称,将会生成 ${name}.ts 文件 | `undefined` |
147+
| `axiosImport` | `string` | 可选 | axios 导入内容,优先级更高 ||
148+
| `unwrapResponseData` | `boolean` | 可选 | 是否取消对 axios response 的包裹,优先级更高(即直接返回 ResponseData,而不是 AxiosResponse) | `false` |
149+
| `schema` | `string | OpenApiSpec` | 必须 | openapi 的 schema,可以是一个链接地址,也可以是本地路径,也可以是一个对象 | `undefined` |
150150

151151
# 鸣谢
152152

package-lock.json

Lines changed: 113 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "OpenAPI ➡️ Axios",
55
"scripts": {
66
"prepare": "husky install",
7-
"lint": "eslint src/**/*.ts test/**/*.ts && tsc --project tsconfig.json --noEmit",
7+
"lint": "eslint --ext=.cjs,.mjs,.ts,.tsx src/ test/ && tsc --project tsconfig.json --noEmit",
88
"test": "vitest run",
99
"test:coverage": "vitest run --coverage",
1010
"build:types": "rm -rf dist-dts && tsc --project tsconfig.types.json",
@@ -51,18 +51,21 @@
5151
"OAS",
5252
"axios"
5353
],
54-
"author": "publish-node-package-action",
54+
"author": "云淡然 <hi@ydr.me> (https://ydr.me)",
5555
"homepage": "https://github.com/FrontEndDev-org/openapi-axios",
5656
"repository": "https://github.com/FrontEndDev-org/openapi-axios",
5757
"license": "MIT",
5858
"dependencies": {
5959
"chalk": "^4.1.2",
60-
"swagger-typescript-api": "^12.0.4"
60+
"swagger-typescript-api": "^12.0.4",
61+
"try-flatten": "^1.0.1"
6162
},
6263
"devDependencies": {
6364
"@commitlint/cli": "^17.4.4",
6465
"@commitlint/config-conventional": "^17.4.4",
6566
"@commitlint/types": "^17.4.4",
67+
"@rollup/plugin-node-resolve": "^15.0.1",
68+
"@rollup/plugin-replace": "^5.0.2",
6669
"@rollup/plugin-typescript": "^11.0.0",
6770
"@types/node": "^18.15.7",
6871
"@types/prettier": "^2.7.2",

rollup.config.mjs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
import nodeResolve from '@rollup/plugin-node-resolve';
2+
import replace from '@rollup/plugin-replace';
13
import typescript from '@rollup/plugin-typescript';
4+
import pkg from './package.json' assert { type: 'json' };
25

36
/** @type {import('rollup').RollupOptions} */
47
export default {
@@ -19,7 +22,14 @@ export default {
1922
sourcemap: true,
2023
},
2124
],
25+
external: Object.keys(pkg.dependencies),
2226
plugins: [
27+
nodeResolve(),
28+
replace({
29+
preventAssignment: true,
30+
'process.env.PKG_NAME': JSON.stringify(pkg.name),
31+
'process.env.PKG_VERSION': JSON.stringify(pkg.version),
32+
}),
2333
typescript({
2434
tsconfig: 'tsconfig.json',
2535
}),

src/commands.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import chalk from 'chalk';
2-
import path from 'path';
2+
import * as path from 'path';
33
import * as process from 'process';
4+
import { normalizeError, tryFlatten } from 'try-flatten';
45
import { defineConfig } from './configure';
56
import { generate } from './generator';
67
import { UserConfig } from './types';
7-
import { isFile, isString, isUrl, normalizeError, syncPromise, tryCatch } from './utils';
8+
import { isFile } from './utils/fs2';
9+
import { isString, isUrl } from './utils/type-is';
810

911
interface StartConfig {
1012
// 指定配置文件绝对路径
@@ -41,7 +43,7 @@ export async function start(startConfig?: StartConfig) {
4143
}
4244

4345
// eslint-disable-next-line @typescript-eslint/no-var-requires
44-
const [err, config] = await tryCatch<UserConfig>(syncPromise(() => require(configPath)));
46+
const [err, config] = tryFlatten(() => require(configPath) as UserConfig | undefined);
4547

4648
if (err) {
4749
throw new Error(err.message);

src/const.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import path from 'path';
1+
import * as path from 'path';
2+
3+
export const pkgName = process.env.PKG_NAME!;
4+
export const pkgVersion = process.env.PKG_VERSION!;
25

36
const dirname = __dirname;
47

src/generator.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import fs from 'fs/promises';
2-
import path from 'path';
1+
import * as fs from 'fs/promises';
2+
import * as path from 'path';
33
import { generateApi, GenerateApiParams } from 'swagger-typescript-api';
44
import { axiosImportDefault, helpersImport, templatesDir } from './const';
55
import { Generated, GeneratedCallback, OpenapiConfig, StrictConfig } from './types';
6-
import { isBoolean, isString, isUrl } from './utils';
6+
import { isBoolean, isString, isUrl } from './utils/type-is';
77

88
export function generateParams(openapiConfig: OpenapiConfig, config: StrictConfig): GenerateApiParams {
99
const { name, schema, unwrapResponseData: unwrapResponseDataScope } = openapiConfig;

0 commit comments

Comments
 (0)