From f71b79c65d40784aee54f6ceb9c51c986140f995 Mon Sep 17 00:00:00 2001 From: Xicheng Guo Date: Wed, 17 Jan 2024 14:30:12 +0800 Subject: [PATCH] update --- package-lock.json | 27 +++++++- package.json | 9 ++- rollup.config.mjs | 67 +++++++++++-------- src/__tests__/authenticate-github.test.ts | 2 +- src/__tests__/book-repository.test.ts | 2 +- src/__tests__/chat-repository.test.ts | 2 +- src/__tests__/helper/book-model.ts | 2 +- src/__tests__/helper/book-repository.ts | 3 +- src/__tests__/helper/chat-model.ts | 2 +- src/__tests__/helper/chat-repository.ts | 3 +- src/__tests__/helper/helper.ts | 2 +- src/__tests__/helper/user-model.ts | 2 +- src/__tests__/helper/user-repository.ts | 3 +- src/__tests__/user-repository.test.ts | 2 +- src/__tests__/wx-request.test.ts | 2 +- src/index.ts | 28 ++++++-- src/repository-lib/base/base-repository.ts | 2 +- src/repository-lib/gitee/gitee-repository.ts | 2 +- .../github/github-repository.ts | 2 +- .../gitlab/gitlab-repository.ts | 2 +- src/repository-lib/index.ts | 14 ---- src/request-lib/base/base-request.ts | 4 +- src/request-lib/base/request-options.ts | 4 +- src/request-lib/index.ts | 3 - src/utils/index.ts | 1 - tsconfig.json | 5 +- 26 files changed, 115 insertions(+), 82 deletions(-) delete mode 100644 src/repository-lib/index.ts delete mode 100644 src/request-lib/index.ts delete mode 100644 src/utils/index.ts diff --git a/package-lock.json b/package-lock.json index 97f1006..7c9a6ec 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "tiny-crud", - "version": "1.0.22", + "version": "1.0.23", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "tiny-crud", - "version": "1.0.22", + "version": "1.0.23", "license": "MIT", "devDependencies": { "@babel/preset-env": "^7.23.3", @@ -30,6 +30,7 @@ "nyc": "^15.1.0", "rimraf": "^5.0.5", "rollup": "^4.3.0", + "rollup-plugin-dts": "^6.1.0", "ts-jest": "^29.1.1", "tslib": "^2.6.2", "typescript": "^5.2.2" @@ -7262,6 +7263,28 @@ "fsevents": "~2.3.2" } }, + "node_modules/rollup-plugin-dts": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/rollup-plugin-dts/-/rollup-plugin-dts-6.1.0.tgz", + "integrity": "sha512-ijSCPICkRMDKDLBK9torss07+8dl9UpY9z1N/zTeA1cIqdzMlpkV3MOOC7zukyvQfDyxa1s3Dl2+DeiP/G6DOw==", + "dev": true, + "dependencies": { + "magic-string": "^0.30.4" + }, + "engines": { + "node": ">=16" + }, + "funding": { + "url": "https://github.com/sponsors/Swatinem" + }, + "optionalDependencies": { + "@babel/code-frame": "^7.22.13" + }, + "peerDependencies": { + "rollup": "^3.29.4 || ^4", + "typescript": "^4.5 || ^5.0" + } + }, "node_modules/semver": { "version": "6.3.1", "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", diff --git a/package.json b/package.json index 1bc8cf7..3f16564 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "tiny-crud", - "version": "1.0.22", - "description": "", + "version": "1.0.23", + "description": "A tiny CRUD library based on Git Issue API", "main": "dist/bundle.cjs.js", "module": "dist/bundle.esm.js", "types": "dist/index.d.ts", @@ -13,7 +13,9 @@ "author": "Xicheng_Guo", "license": "MIT", "files": [ - "dist" + "dist/bundle.cjs.js", + "dist/bundle.esm.js", + "dist/index.d.ts" ], "devDependencies": { "@babel/preset-env": "^7.23.3", @@ -37,6 +39,7 @@ "nyc": "^15.1.0", "rimraf": "^5.0.5", "rollup": "^4.3.0", + "rollup-plugin-dts": "^6.1.0", "ts-jest": "^29.1.1", "tslib": "^2.6.2", "typescript": "^5.2.2" diff --git a/rollup.config.mjs b/rollup.config.mjs index 5e39739..c9896ab 100644 --- a/rollup.config.mjs +++ b/rollup.config.mjs @@ -1,30 +1,39 @@ -import { nodeResolve } from '@rollup/plugin-node-resolve'; -import babel from '@rollup/plugin-babel'; -import commonjs from '@rollup/plugin-commonjs'; -import json from '@rollup/plugin-json'; -import typescript from '@rollup/plugin-typescript'; +import { nodeResolve } from "@rollup/plugin-node-resolve"; +import babel from "@rollup/plugin-babel"; +import commonjs from "@rollup/plugin-commonjs"; +import json from "@rollup/plugin-json"; +import typescript from "@rollup/plugin-typescript"; +import dts from "rollup-plugin-dts"; -export default { - input: 'src/index.ts', - output: [ - { - file: 'dist/bundle.cjs.js', // CommonJS 输出文件 - format: 'cjs', - }, - { - file: 'dist/bundle.esm.js', // ES Module 输出文件 - format: 'esm', - }, - ], - plugins: [ - typescript({ include: ['./src/**/*.ts'] }), - babel({ - babelHelpers: 'bundled', - extensions: ['.ts', '.tsx'], - presets: ['@babel/preset-env', '@babel/preset-typescript'], - }), - nodeResolve(), - commonjs(), - json() - ] -}; +export default [ + { + input: "src/index.ts", + output: [ + { + file: "dist/bundle.cjs.js", // CommonJS 输出文件 + format: "cjs", + }, + { + file: "dist/bundle.esm.js", // ES Module 输出文件 + format: "esm", + }, + ], + plugins: [ + typescript({ include: ["./src/**/*.ts"] }), + babel({ + babelHelpers: "bundled", + extensions: [".ts", ".tsx"], + presets: ["@babel/preset-env", "@babel/preset-typescript"], + }), + nodeResolve(), + commonjs(), + json(), + ], + }, + /* 单独生成声明文件 */ + { + input: "dist/types/index.d.ts", + output: [{ file: "dist/index.d.ts", format: "es" }], + plugins: [dts()], + }, +]; diff --git a/src/__tests__/authenticate-github.test.ts b/src/__tests__/authenticate-github.test.ts index 68a7d71..0534b0c 100644 --- a/src/__tests__/authenticate-github.test.ts +++ b/src/__tests__/authenticate-github.test.ts @@ -1,4 +1,4 @@ -import { GithubUser } from "./../repository-lib"; +import { GithubUser } from "../index"; import { USE_API, githubRequest } from "./helper/helper"; import { mockGithubUser } from "./mock/mock-git-user"; diff --git a/src/__tests__/book-repository.test.ts b/src/__tests__/book-repository.test.ts index 3b79afa..b4f4885 100644 --- a/src/__tests__/book-repository.test.ts +++ b/src/__tests__/book-repository.test.ts @@ -1,5 +1,5 @@ import dayjs from "dayjs"; -import { PlainObject } from "./../repository-lib"; +import { PlainObject } from "../index"; import { BookModel } from "./helper/book-model"; import { USE_API } from "./helper/helper"; import { Book } from "./helper/book-repository"; diff --git a/src/__tests__/chat-repository.test.ts b/src/__tests__/chat-repository.test.ts index aa1009b..8d51167 100644 --- a/src/__tests__/chat-repository.test.ts +++ b/src/__tests__/chat-repository.test.ts @@ -1,4 +1,4 @@ -import { PlainObject } from "./../repository-lib"; +import { PlainObject } from "../index"; import { ChatModel } from "./helper/chat-model"; import { Chat } from "./helper/chat-repository"; import { USE_API } from "./helper/helper"; diff --git a/src/__tests__/helper/book-model.ts b/src/__tests__/helper/book-model.ts index f25a9c6..f78d017 100644 --- a/src/__tests__/helper/book-model.ts +++ b/src/__tests__/helper/book-model.ts @@ -1,4 +1,4 @@ -import { BaseModel } from '../../repository-lib/'; +import { BaseModel} from '../../index' export interface BookModel extends BaseModel { book_name: string; book_author: string; diff --git a/src/__tests__/helper/book-repository.ts b/src/__tests__/helper/book-repository.ts index 67bd7fa..24283e3 100644 --- a/src/__tests__/helper/book-repository.ts +++ b/src/__tests__/helper/book-repository.ts @@ -1,5 +1,4 @@ -import { GithubRepository } from "../../repository-lib"; -import { SingletonFactory } from "../../utils"; +import { GithubRepository, SingletonFactory } from "../../index"; import { BookModel } from "./book-model"; import { githubRequest } from "./helper"; diff --git a/src/__tests__/helper/chat-model.ts b/src/__tests__/helper/chat-model.ts index 8552b1a..20b051d 100644 --- a/src/__tests__/helper/chat-model.ts +++ b/src/__tests__/helper/chat-model.ts @@ -1,4 +1,4 @@ -import { BaseModel } from "../../repository-lib"; +import { BaseModel } from "../../index"; export interface ChatModel extends BaseModel { participants: string[]; diff --git a/src/__tests__/helper/chat-repository.ts b/src/__tests__/helper/chat-repository.ts index 8b553d9..539dc1b 100644 --- a/src/__tests__/helper/chat-repository.ts +++ b/src/__tests__/helper/chat-repository.ts @@ -1,7 +1,6 @@ -import { GitlabRepository } from "../../repository-lib"; +import { GitlabRepository, SingletonFactory } from "../../index"; import { ChatModel } from "./chat-model"; import { GITLAB_NUMBER, gitlabRequest } from "./helper"; -import { SingletonFactory } from "../../utils"; class ChatRepository extends GitlabRepository { constructor() { diff --git a/src/__tests__/helper/helper.ts b/src/__tests__/helper/helper.ts index 033e5ed..0d6b434 100644 --- a/src/__tests__/helper/helper.ts +++ b/src/__tests__/helper/helper.ts @@ -1,7 +1,7 @@ import 'dotenv/config'; import axios from 'axios'; import CryptoJS from 'crypto-js'; -import { createRequest } from '../../request-lib'; +import { createRequest } from '../../index'; import dayjs from 'dayjs'; import utc from 'dayjs/plugin/utc'; import timezone from 'dayjs/plugin/timezone'; diff --git a/src/__tests__/helper/user-model.ts b/src/__tests__/helper/user-model.ts index 5e673c0..e869dd6 100644 --- a/src/__tests__/helper/user-model.ts +++ b/src/__tests__/helper/user-model.ts @@ -1,4 +1,4 @@ -import { BaseModel } from "../../repository-lib"; +import { BaseModel } from "../../index"; export interface UserModel extends BaseModel { name: string; age: number; diff --git a/src/__tests__/helper/user-repository.ts b/src/__tests__/helper/user-repository.ts index 1216c4e..989b305 100644 --- a/src/__tests__/helper/user-repository.ts +++ b/src/__tests__/helper/user-repository.ts @@ -1,6 +1,5 @@ -import { GiteeRepository } from '../../repository-lib'; -import { SingletonFactory } from '../../utils'; +import { GiteeRepository, SingletonFactory } from '../../index'; import { GITEE_NUMBER, giteeRequest } from './helper'; import { UserModel } from './user-model'; diff --git a/src/__tests__/user-repository.test.ts b/src/__tests__/user-repository.test.ts index 92a76a9..b348894 100644 --- a/src/__tests__/user-repository.test.ts +++ b/src/__tests__/user-repository.test.ts @@ -1,5 +1,5 @@ import dayjs from "dayjs"; -import { PlainObject } from "./../repository-lib"; +import { PlainObject } from "../index"; import { UserModel } from "./helper/user-model"; import { User } from "./helper/user-repository"; import { setupGiteeMock } from "./mock/mock-gitee-api"; diff --git a/src/__tests__/wx-request.test.ts b/src/__tests__/wx-request.test.ts index 231501c..203f243 100644 --- a/src/__tests__/wx-request.test.ts +++ b/src/__tests__/wx-request.test.ts @@ -1,4 +1,4 @@ -import { createRequest } from './../request-lib'; +import { createRequest } from '../index'; const wx = { request: jest.fn() diff --git a/src/index.ts b/src/index.ts index 41c8aa2..ef2a4f7 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,8 +1,22 @@ -import { createRequest } from "./request-lib/create-request"; -import { BaseModel, GiteeRepository, GitlabRepository, GithubRepository, PlainObject } from "./repository-lib"; -import { SingletonFactory } from "./utils" -export { - createRequest, BaseModel, PlainObject, - GiteeRepository, GitlabRepository, GithubRepository, SingletonFactory -}; +export { createRequest } from './request-lib/create-request'; + +export { SingletonFactory } from './utils/singleton-factory'; + +export { BaseRepository } from './repository-lib/base/base-repository'; + +export { BaseModel } from './repository-lib/base/base-model'; + +export { PlainObject } from './repository-lib/base/plain-object'; + +export { GiteeRepository } from './repository-lib/gitee/gitee-repository'; + +export { GithubRepository } from './repository-lib/github/github-repository'; + +export { GitlabRepository } from './repository-lib/gitlab/gitlab-repository'; + +export { GitlabUser } from './repository-lib/gitlab/gitlab-user'; + +export { GithubUser } from './repository-lib/github/github-user'; + +export { GiteeUser } from './repository-lib/gitee/gitee-user'; diff --git a/src/repository-lib/base/base-repository.ts b/src/repository-lib/base/base-repository.ts index 49b5b5a..797b9c2 100644 --- a/src/repository-lib/base/base-repository.ts +++ b/src/repository-lib/base/base-repository.ts @@ -1,4 +1,4 @@ -import { BaseRequest } from "../../request-lib"; +import { BaseRequest } from "../../request-lib/base/base-request"; import { Author } from "./author"; import { BaseComment } from "./base-comment"; import { BaseModel } from "./base-model"; diff --git a/src/repository-lib/gitee/gitee-repository.ts b/src/repository-lib/gitee/gitee-repository.ts index eff7031..6422686 100644 --- a/src/repository-lib/gitee/gitee-repository.ts +++ b/src/repository-lib/gitee/gitee-repository.ts @@ -1,4 +1,4 @@ -import { BaseRequest } from "../../request-lib"; +import { BaseRequest } from "../../request-lib/base/base-request"; import { Author } from "../base/author"; import { BaseComment } from "../base/base-comment"; import { BaseModel } from "../base/base-model"; diff --git a/src/repository-lib/github/github-repository.ts b/src/repository-lib/github/github-repository.ts index 1673e32..d9441a9 100644 --- a/src/repository-lib/github/github-repository.ts +++ b/src/repository-lib/github/github-repository.ts @@ -1,4 +1,4 @@ -import { BaseRequest } from "../../request-lib"; +import { BaseRequest } from "../../request-lib/base/base-request"; import { Author } from "../base/author"; import { BaseComment } from "../base/base-comment"; import { BaseModel } from "../base/base-model"; diff --git a/src/repository-lib/gitlab/gitlab-repository.ts b/src/repository-lib/gitlab/gitlab-repository.ts index 51de6ef..368bd5f 100644 --- a/src/repository-lib/gitlab/gitlab-repository.ts +++ b/src/repository-lib/gitlab/gitlab-repository.ts @@ -1,4 +1,4 @@ -import { BaseRequest } from "../../request-lib"; +import { BaseRequest } from "../../request-lib/base/base-request"; import { BaseComment } from "../base/base-comment"; import { BaseModel } from "../base/base-model"; import { BaseRepository } from "../base/base-repository"; diff --git a/src/repository-lib/index.ts b/src/repository-lib/index.ts deleted file mode 100644 index 59aa21f..0000000 --- a/src/repository-lib/index.ts +++ /dev/null @@ -1,14 +0,0 @@ -export { BaseModel } from './base/base-model'; -export { PlainObject } from './base/plain-object'; -/** Gitee */ -export { GiteeUser } from './gitee/gitee-user'; -export { GiteeOptions } from './gitee/gitee-options'; -export { GiteeRepository } from './gitee/gitee-repository'; -/** Github */ -export { GithubUser } from './github/github-user'; -export { GithubOptions } from './github/github-options'; -export { GithubRepository } from './github/github-repository'; -/** Gitlab */ -export { GitlabUser } from './gitlab/gitlab-user'; -export { GitlabOptions } from './gitlab/gitlab-options'; -export { GitlabRepository } from './gitlab/gitlab-repository'; \ No newline at end of file diff --git a/src/request-lib/base/base-request.ts b/src/request-lib/base/base-request.ts index 6faaf28..99b3016 100644 --- a/src/request-lib/base/base-request.ts +++ b/src/request-lib/base/base-request.ts @@ -1,5 +1,7 @@ import { StoragePlatform } from "../../enums"; -import { GiteeUser, GithubUser, GitlabUser } from "../../repository-lib"; +import { GiteeUser } from '../../repository-lib/gitee/gitee-user'; +import { GithubUser } from '../../repository-lib/github/github-user'; +import { GitlabUser } from '../../repository-lib/gitlab/gitlab-user'; import { RequestMethods } from "./request-methods"; import { RequestOptions } from "./request-options"; diff --git a/src/request-lib/base/request-options.ts b/src/request-lib/base/request-options.ts index e022b62..3e1594a 100644 --- a/src/request-lib/base/request-options.ts +++ b/src/request-lib/base/request-options.ts @@ -1,4 +1,6 @@ -import { GiteeOptions, GithubOptions, GitlabOptions } from "../../repository-lib"; +import { GiteeOptions } from "../../repository-lib/gitee/gitee-options"; +import { GithubOptions } from "../../repository-lib/github/github-options"; +import { GitlabOptions } from "../../repository-lib/gitlab/gitlab-options"; import { AxiosOptions } from "../axios/axios-options"; import { WxOptions } from "../wx/wx-options"; diff --git a/src/request-lib/index.ts b/src/request-lib/index.ts deleted file mode 100644 index d80be83..0000000 --- a/src/request-lib/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -export {createRequest} from './create-request'; -export {BaseRequest} from './base/base-request'; -export {WxRequestOptions} from './wx/wx-interface'; \ No newline at end of file diff --git a/src/utils/index.ts b/src/utils/index.ts deleted file mode 100644 index 299cdb5..0000000 --- a/src/utils/index.ts +++ /dev/null @@ -1 +0,0 @@ -export { SingletonFactory } from './singleton-factory'; \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index 815d454..fb2769c 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -28,8 +28,8 @@ "module": "ESNext" /* Specify what module code is generated. */, // "rootDir": "./", /* Specify the root folder within your source files. */ "moduleResolution": "Node" /* Specify how TypeScript looks up a file from a given module specifier. */, - // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ - // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */ + // "baseUrl": "./" /* Specify the base directory to resolve non-relative module names. */, + // "paths": {} /* Specify a set of entries that re-map imports to additional lookup locations. */, // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */ // "types": [], /* Specify type package names to be included without being referenced in a source file. */ @@ -50,6 +50,7 @@ /* Emit */ "declaration": true /* Generate .d.ts files from TypeScript and JavaScript files in your project. */, + "declarationDir": "./dist/types", // "declarationMap": true, /* Create sourcemaps for d.ts files. */ // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */ // "sourceMap": true, /* Create source map files for emitted JavaScript files. */