Skip to content

Commit 8a638f9

Browse files
committed
feat(class-mock/vue-xrender/superman-shared): extract duplicate tool functions to superman-shared
Extract duplicate tool functions to superman-shared, create class-mock package
1 parent 3271bab commit 8a638f9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1439
-654
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"description": "vue useful lib collection, use vue like a superman",
77
"author": "yangjinming",
88
"scripts": {
9-
"bootstrap": "pnpm i",
9+
"bootstrap": "pnpm i &&pnpm run build --filter superman-shared",
1010
"build": "esno ./scripts/build.ts",
1111
"clean": "rimraf **/node_modules/**",
1212
"commit": "git add . &&git-cz",

packages/class-mock/package.json

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
{
2+
"name": "class-mock",
3+
"version": "0.0.1",
4+
"description": "Proper decorator-based to generate faker data from class constructors",
5+
"keywords": [
6+
"mock",
7+
"faker",
8+
"decorator",
9+
"class-mock",
10+
"vue-superman",
11+
"utils"
12+
],
13+
"author": "yangjinming <https://github.com/2214962083>",
14+
"funding": "https://github.com/sponsors/2214962083",
15+
"license": "MIT",
16+
"private": false,
17+
"scripts": {
18+
"build": "pnpm type-check &&esno ./scripts/build.ts",
19+
"build:watch": "cross-env WATCH=true pnpm build",
20+
"clean": "rimraf ./dist/**/*",
21+
"dev": "vite",
22+
"test": "vitest run --silent",
23+
"test:watch": "pnpm test -- --watch",
24+
"type-check": "tsc --noEmit"
25+
},
26+
"main": "./dist/index.cjs",
27+
"module": "./dist/index.mjs",
28+
"types": "./dist/index.d.ts",
29+
"unpkg": "./dist/index.min.umd.js",
30+
"jsdelivr": "./dist/index.min.umd.js",
31+
"exports": {
32+
".": {
33+
"require": "./dist/index.cjs",
34+
"import": "./dist/index.mjs",
35+
"types": "./dist/index.d.ts"
36+
},
37+
"./*": "./*"
38+
},
39+
"files": [
40+
"dist"
41+
],
42+
"sideEffects": false,
43+
"repository": {
44+
"type": "git",
45+
"url": "git+https://github.com/2214962083/vue-superman.git",
46+
"directory": "packages/class-mock"
47+
},
48+
"bugs": {
49+
"url": "https://github.com/2214962083/vue-superman/issues"
50+
},
51+
"homepage": "https://github.com/2214962083/vue-superman#readme",
52+
"peerDependencies": {
53+
"reflect-metadata": "*"
54+
},
55+
"devDependencies": {
56+
"@types/node": "^17.0.24",
57+
"@types/rimraf": "^3.0.2",
58+
"conventional-changelog-cli": "^2.2.2",
59+
"cross-env": "^7.0.3",
60+
"esno": "^0.14.1",
61+
"jsdom": "^19.0.0",
62+
"reflect-metadata": "^0.1.13",
63+
"rimraf": "^3.0.2",
64+
"superman-shared": "workspace:*",
65+
"typescript": "4.6.3",
66+
"vite": "^2.9.5",
67+
"vitest": "^0.9.3"
68+
}
69+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import {buildUtils} from 'superman-shared'
2+
import {minifyConfig, unMinifyConfig, packagePath} from '../vite.config'
3+
4+
buildUtils.build({
5+
minifyConfig,
6+
unMinifyConfig,
7+
packagePath
8+
})
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import {say} from './index'
2+
3+
describe('class-mock', () => {
4+
test('say', () => {
5+
expect(say()).toBe('hello mock')
6+
})
7+
})

packages/class-mock/src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const say = () => 'hello mock'
2+
3+
say()

packages/class-mock/test/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from 'superman-shared/test-utils'

packages/class-mock/test/setup.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import {polyfillFetch} from 'superman-shared/test-utils'
2+
import {beforeEach} from 'vitest'
3+
4+
polyfillFetch()
5+
6+
beforeEach(() => {
7+
document.body.innerHTML = ''
8+
document.head.innerHTML = ''
9+
})

packages/class-mock/tsconfig.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"extends": "../../tsconfig-base.json",
3+
"compilerOptions": {
4+
"baseUrl": "./",
5+
"outDir": "./dist",
6+
"types": ["vite/client", "vitest", "vitest/globals"],
7+
"paths": {
8+
"@/*": ["./src/*"],
9+
"@test/*": ["./test/*"]
10+
}
11+
},
12+
"include": ["./src/**/*", "./scripts/**/*", "./types/**/*", "./test/**/*", "./*.js", "./*.ts"],
13+
"exclude": ["node_modules", "dist"]
14+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/* eslint-disable @typescript-eslint/no-explicit-any */
2+
3+
declare global {
4+
type Writable<T> = {
5+
-readonly [P in keyof T]: T[P]
6+
}
7+
8+
type DeepPartial<T> = {
9+
[P in keyof T]?: DeepPartial<T[P]>
10+
}
11+
12+
type TimeoutHandle = ReturnType<typeof setTimeout>
13+
type IntervalHandle = ReturnType<typeof setInterval>
14+
15+
function parseInt(s: string | number, radix?: number): number
16+
17+
function parseFloat(string: string | number): number
18+
}
19+
20+
export {}

packages/class-mock/vite.config.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/// <reference types="vitest" />
2+
import {defineConfig, UserConfig} from 'vite'
3+
import {buildUtils} from 'superman-shared'
4+
5+
export const packagePath = __dirname
6+
7+
interface CreateViteConfigOptions {
8+
minify?: boolean
9+
}
10+
11+
const createViteConfig = (options: CreateViteConfigOptions = {}): UserConfig => {
12+
const {minify = false} = options
13+
return buildUtils.createViteConfig({
14+
packagePath,
15+
minify,
16+
dedupe: ['reflect-metadata'] // use the same version
17+
})
18+
}
19+
20+
// default config and build prod config
21+
export const unMinifyConfig = createViteConfig({minify: false})
22+
23+
// build prod and build prod config
24+
export const minifyConfig = createViteConfig({minify: true})
25+
26+
// for vitest
27+
export default defineConfig(unMinifyConfig)

0 commit comments

Comments
 (0)