zeabur 0.0.0 → 0.0.1-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintignore +7 -0
- package/.eslintrc +18 -0
- package/.husky/pre-commit +4 -0
- package/.lintstagedrc +4 -0
- package/.prettierignore +7 -0
- package/.prettierrc +16 -0
- package/.stylelintignore +7 -0
- package/.stylelintrc +21 -0
- package/CHANGELOG.md +0 -0
- package/LICENSE.md +9 -0
- package/README.md +0 -0
- package/dts-bundle-generator.config.ts +18 -0
- package/favicon.svg +15 -0
- package/index.html +4 -4
- package/package.json +42 -8
- package/src/ZeaburClient.ts +189 -0
- package/src/index.ts +1 -3
- package/src/lib/types.ts +4 -0
- package/src/lib/utils.ts +26 -0
- package/tsconfig.json +12 -13
- package/vite.config.ts +34 -16
package/.eslintignore
ADDED
package/.eslintrc
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"root": true,
|
|
3
|
+
"parser": "@typescript-eslint/parser",
|
|
4
|
+
"plugins": ["@typescript-eslint", "prettier"],
|
|
5
|
+
"extends": [
|
|
6
|
+
"eslint:recommended",
|
|
7
|
+
"plugin:@typescript-eslint/eslint-recommended",
|
|
8
|
+
"plugin:@typescript-eslint/recommended",
|
|
9
|
+
"prettier"
|
|
10
|
+
],
|
|
11
|
+
"env": {
|
|
12
|
+
"browser": true,
|
|
13
|
+
"node": true
|
|
14
|
+
},
|
|
15
|
+
"rules": {
|
|
16
|
+
"prettier/prettier": "error"
|
|
17
|
+
}
|
|
18
|
+
}
|
package/.lintstagedrc
ADDED
package/.prettierignore
ADDED
package/.prettierrc
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"printWidth": 80,
|
|
3
|
+
"tabWidth": 2,
|
|
4
|
+
"singleQuote": false,
|
|
5
|
+
"trailingComma": "es5",
|
|
6
|
+
"arrowParens": "avoid",
|
|
7
|
+
"bracketSpacing": true,
|
|
8
|
+
"useTabs": false,
|
|
9
|
+
"endOfLine": "auto",
|
|
10
|
+
"singleAttributePerLine": false,
|
|
11
|
+
"bracketSameLine": false,
|
|
12
|
+
"jsxBracketSameLine": false,
|
|
13
|
+
"jsxSingleQuote": false,
|
|
14
|
+
"quoteProps": "as-needed",
|
|
15
|
+
"semi": true
|
|
16
|
+
}
|
package/.stylelintignore
ADDED
package/.stylelintrc
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"plugins": ["stylelint-prettier"],
|
|
3
|
+
"extends": [
|
|
4
|
+
"stylelint-config-recommended",
|
|
5
|
+
"stylelint-config-sass-guidelines",
|
|
6
|
+
"stylelint-config-prettier"
|
|
7
|
+
],
|
|
8
|
+
"overrides": [
|
|
9
|
+
{
|
|
10
|
+
"files": ["**/*.scss"],
|
|
11
|
+
"customSyntax": "postcss-scss"
|
|
12
|
+
}
|
|
13
|
+
],
|
|
14
|
+
"rules": {
|
|
15
|
+
"prettier/prettier": true,
|
|
16
|
+
"function-parentheses-space-inside": null,
|
|
17
|
+
"no-descending-specificity": null,
|
|
18
|
+
"max-nesting-depth": 2,
|
|
19
|
+
"selector-max-id": 1
|
|
20
|
+
}
|
|
21
|
+
}
|
package/CHANGELOG.md
ADDED
|
File without changes
|
package/LICENSE.md
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 MichaelYuhe
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
File without changes
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
2
|
+
const packageJson = require("./package.json");
|
|
3
|
+
|
|
4
|
+
const getPackageName = () => {
|
|
5
|
+
return packageJson.name;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
const config = {
|
|
9
|
+
entries: [
|
|
10
|
+
{
|
|
11
|
+
filePath: "./src/index.ts",
|
|
12
|
+
outFile: `./dist/${getPackageName()}.d.ts`,
|
|
13
|
+
noCheck: false,
|
|
14
|
+
},
|
|
15
|
+
],
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
module.exports = config;
|
package/favicon.svg
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
<svg width="410" height="404" viewBox="0 0 410 404" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
2
|
+
<path d="M399.641 59.5246L215.643 388.545C211.844 395.338 202.084 395.378 198.228 388.618L10.5817 59.5563C6.38087 52.1896 12.6802 43.2665 21.0281 44.7586L205.223 77.6824C206.398 77.8924 207.601 77.8904 208.776 77.6763L389.119 44.8058C397.439 43.2894 403.768 52.1434 399.641 59.5246Z" fill="url(#paint0_linear)"/>
|
|
3
|
+
<path d="M292.965 1.5744L156.801 28.2552C154.563 28.6937 152.906 30.5903 152.771 32.8664L144.395 174.33C144.198 177.662 147.258 180.248 150.51 179.498L188.42 170.749C191.967 169.931 195.172 173.055 194.443 176.622L183.18 231.775C182.422 235.487 185.907 238.661 189.532 237.56L212.947 230.446C216.577 229.344 220.065 232.527 219.297 236.242L201.398 322.875C200.278 328.294 207.486 331.249 210.492 326.603L212.5 323.5L323.454 102.072C325.312 98.3645 322.108 94.137 318.036 94.9228L279.014 102.454C275.347 103.161 272.227 99.746 273.262 96.1583L298.731 7.86689C299.767 4.27314 296.636 0.855181 292.965 1.5744Z" fill="url(#paint1_linear)"/>
|
|
4
|
+
<defs>
|
|
5
|
+
<linearGradient id="paint0_linear" x1="6.00017" y1="32.9999" x2="235" y2="344" gradientUnits="userSpaceOnUse">
|
|
6
|
+
<stop stop-color="#41D1FF"/>
|
|
7
|
+
<stop offset="1" stop-color="#BD34FE"/>
|
|
8
|
+
</linearGradient>
|
|
9
|
+
<linearGradient id="paint1_linear" x1="194.651" y1="8.81818" x2="236.076" y2="292.989" gradientUnits="userSpaceOnUse">
|
|
10
|
+
<stop stop-color="#FFEA83"/>
|
|
11
|
+
<stop offset="0.0833333" stop-color="#FFDD35"/>
|
|
12
|
+
<stop offset="1" stop-color="#FFA800"/>
|
|
13
|
+
</linearGradient>
|
|
14
|
+
</defs>
|
|
15
|
+
</svg>
|
package/index.html
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
<!
|
|
1
|
+
<!DOCTYPE html>
|
|
2
2
|
<html lang="en">
|
|
3
3
|
<head>
|
|
4
4
|
<meta charset="UTF-8" />
|
|
5
|
-
<link rel="icon" type="image/svg+xml" href="
|
|
5
|
+
<link rel="icon" type="image/svg+xml" href="favicon.svg" />
|
|
6
6
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
|
-
<title>Vite
|
|
7
|
+
<title>Vite App</title>
|
|
8
8
|
</head>
|
|
9
9
|
<body>
|
|
10
10
|
<div id="app"></div>
|
|
11
|
-
<script type="module" src="/src/
|
|
11
|
+
<script type="module" src="/src/index.ts"></script>
|
|
12
12
|
</body>
|
|
13
13
|
</html>
|
package/package.json
CHANGED
|
@@ -1,17 +1,51 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zeabur",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.0.0",
|
|
5
|
-
"
|
|
6
|
-
"
|
|
4
|
+
"version": "0.0.1-alpha.0",
|
|
5
|
+
"main": "./dist/zeabur.cjs",
|
|
6
|
+
"module": "./dist/zeabur.mjs",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"require": "./dist/zeabur.cjs",
|
|
10
|
+
"import": "./dist/zeabur.mjs"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
7
13
|
"author": "MichaelYuhe",
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"types": "./dist/zeabur-js.d.ts",
|
|
8
16
|
"scripts": {
|
|
9
|
-
"dev": "vite",
|
|
10
|
-
"build": "tsc && vite build",
|
|
11
|
-
"
|
|
17
|
+
"dev": "vite --host",
|
|
18
|
+
"build": "rimraf dist && tsc && vite build && dts-bundle-generator --config ./dts-bundle-generator.config.ts",
|
|
19
|
+
"lint:scripts": "eslint . --ext .ts",
|
|
20
|
+
"lint:styles": "stylelint ./**/*.{css,scss}",
|
|
21
|
+
"format:scripts": "prettier . --write",
|
|
22
|
+
"format:styles": "stylelint ./**/*.{css,scss} --fix",
|
|
23
|
+
"format": "npm run format:scripts && npm run format:styles",
|
|
24
|
+
"prepare": "husky install && husky set .husky/pre-commit 'npx lint-staged' && git add .husky/pre-commit",
|
|
25
|
+
"uninstall-husky": "npm uninstall husky --no-save && git config --unset core.hooksPath && npx rimraf .husky"
|
|
12
26
|
},
|
|
13
27
|
"devDependencies": {
|
|
14
|
-
"
|
|
15
|
-
"
|
|
28
|
+
"@types/jsdom": "^21.1.1",
|
|
29
|
+
"@types/node": "^20.4.9",
|
|
30
|
+
"@typescript-eslint/eslint-plugin": "^6.3.0",
|
|
31
|
+
"@typescript-eslint/parser": "^6.3.0",
|
|
32
|
+
"dts-bundle-generator": "^8.0.1",
|
|
33
|
+
"eslint": "^8.46.0",
|
|
34
|
+
"eslint-config-prettier": "^9.0.0",
|
|
35
|
+
"eslint-plugin-prettier": "^5.0.0",
|
|
36
|
+
"husky": "^8.0.3",
|
|
37
|
+
"lint-staged": "^13.2.3",
|
|
38
|
+
"prettier": "^3.0.1",
|
|
39
|
+
"rimraf": "^5.0.1",
|
|
40
|
+
"stylelint": "^14.16.1",
|
|
41
|
+
"stylelint-config-prettier": "^9.0.5",
|
|
42
|
+
"stylelint-config-recommended": "^9.0.0",
|
|
43
|
+
"stylelint-prettier": "^3.0.0",
|
|
44
|
+
"ts-node": "^10.9.1",
|
|
45
|
+
"typescript": "^5.1.6",
|
|
46
|
+
"vite": "^4.4.9"
|
|
47
|
+
},
|
|
48
|
+
"dependencies": {
|
|
49
|
+
"jszip": "^3.10.1"
|
|
16
50
|
}
|
|
17
51
|
}
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import { Region } from "./lib/types";
|
|
2
|
+
import { generateRandomString, zipCode } from "./lib/utils";
|
|
3
|
+
|
|
4
|
+
const API_URL = "https://gateway.zeabur.com/graphql";
|
|
5
|
+
|
|
6
|
+
export default class ZeaburClient {
|
|
7
|
+
private apiKey: string;
|
|
8
|
+
|
|
9
|
+
constructor(apiKey: string) {
|
|
10
|
+
this.apiKey = apiKey;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// Create a Project
|
|
14
|
+
private async createProject(
|
|
15
|
+
projectRegion: keyof typeof Region
|
|
16
|
+
): Promise<string> {
|
|
17
|
+
try {
|
|
18
|
+
const res = await fetch(API_URL, {
|
|
19
|
+
method: "POST",
|
|
20
|
+
headers: {
|
|
21
|
+
"Content-Type": "application/json",
|
|
22
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
23
|
+
},
|
|
24
|
+
body: JSON.stringify({
|
|
25
|
+
query: `mutation CreateProject($region: String!) {
|
|
26
|
+
createProject(region: $region) {
|
|
27
|
+
_id
|
|
28
|
+
}
|
|
29
|
+
}`,
|
|
30
|
+
variables: { region: projectRegion },
|
|
31
|
+
}),
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const { data } = await res.json();
|
|
35
|
+
|
|
36
|
+
return data.createProject._id;
|
|
37
|
+
} catch (error) {
|
|
38
|
+
console.error(error);
|
|
39
|
+
throw error;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Create a Service
|
|
44
|
+
private async createService(
|
|
45
|
+
projectID: string,
|
|
46
|
+
serviceName: string
|
|
47
|
+
): Promise<string> {
|
|
48
|
+
try {
|
|
49
|
+
const res = await fetch(API_URL, {
|
|
50
|
+
method: "POST",
|
|
51
|
+
headers: {
|
|
52
|
+
"Content-Type": "application/json",
|
|
53
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
54
|
+
},
|
|
55
|
+
body: JSON.stringify({
|
|
56
|
+
query: `mutation CreateService($projectID: ObjectID!, $template: ServiceTemplate!, $name: String!) {
|
|
57
|
+
createService(projectID: $projectID, template: $template, name: $name) {
|
|
58
|
+
_id
|
|
59
|
+
}
|
|
60
|
+
}`,
|
|
61
|
+
variables: {
|
|
62
|
+
projectID,
|
|
63
|
+
template: "GIT",
|
|
64
|
+
name: serviceName,
|
|
65
|
+
},
|
|
66
|
+
}),
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
const { data } = await res.json();
|
|
70
|
+
|
|
71
|
+
return data.createService._id;
|
|
72
|
+
} catch (error) {
|
|
73
|
+
console.error(error);
|
|
74
|
+
throw error;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// Get Environment ID
|
|
79
|
+
private async getEnvironment(projectID: string): Promise<string> {
|
|
80
|
+
try {
|
|
81
|
+
const res = await fetch(API_URL, {
|
|
82
|
+
method: "POST",
|
|
83
|
+
headers: {
|
|
84
|
+
"Content-Type": "application/json",
|
|
85
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
86
|
+
},
|
|
87
|
+
body: JSON.stringify({
|
|
88
|
+
query: `query GetEnvironment($projectID: ObjectID!) {
|
|
89
|
+
environments(projectID: $projectID) {
|
|
90
|
+
_id
|
|
91
|
+
}
|
|
92
|
+
}`,
|
|
93
|
+
variables: {
|
|
94
|
+
projectID,
|
|
95
|
+
},
|
|
96
|
+
}),
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
const { data } = await res.json();
|
|
100
|
+
|
|
101
|
+
return data.environments[0]._id;
|
|
102
|
+
} catch (error) {
|
|
103
|
+
console.error(error);
|
|
104
|
+
throw error;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// Create a Domain
|
|
109
|
+
private async createDomain(
|
|
110
|
+
serviceID: string,
|
|
111
|
+
environmentID: string,
|
|
112
|
+
serviceName: string,
|
|
113
|
+
domainName?: string
|
|
114
|
+
): Promise<string> {
|
|
115
|
+
try {
|
|
116
|
+
const res = await fetch(API_URL, {
|
|
117
|
+
method: "POST",
|
|
118
|
+
headers: {
|
|
119
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
120
|
+
"Content-Type": "application/json",
|
|
121
|
+
},
|
|
122
|
+
body: JSON.stringify({
|
|
123
|
+
query: `mutation CreateDomain($serviceID: ObjectID!, $environmentID: ObjectID!, $domain: String!, $isGenerated: Boolean!) {
|
|
124
|
+
addDomain(serviceID: $serviceID, environmentID: $environmentID, domain: $domain, isGenerated: $isGenerated) {
|
|
125
|
+
domain
|
|
126
|
+
}
|
|
127
|
+
}`,
|
|
128
|
+
variables: {
|
|
129
|
+
serviceID,
|
|
130
|
+
environmentID,
|
|
131
|
+
domain: domainName ?? `${serviceName + generateRandomString()}`,
|
|
132
|
+
isGenerated: true,
|
|
133
|
+
},
|
|
134
|
+
}),
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
const { data } = await res.json();
|
|
138
|
+
return data.addDomain.domain;
|
|
139
|
+
} catch (error) {
|
|
140
|
+
console.error(error);
|
|
141
|
+
throw error;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// Deploy Codes to Zeabur and Get a Domain
|
|
146
|
+
public async deploy(
|
|
147
|
+
code: string,
|
|
148
|
+
projectRegion: keyof typeof Region,
|
|
149
|
+
serviceName: string,
|
|
150
|
+
domainName?: string
|
|
151
|
+
): Promise<string> {
|
|
152
|
+
try {
|
|
153
|
+
if (!code) throw new Error("Code is required");
|
|
154
|
+
|
|
155
|
+
const zipFile = await zipCode(code);
|
|
156
|
+
|
|
157
|
+
const projectID = await this.createProject(projectRegion);
|
|
158
|
+
const environmentID = await this.getEnvironment(projectID);
|
|
159
|
+
const serviceID = await this.createService(projectID, serviceName);
|
|
160
|
+
|
|
161
|
+
const formData = new FormData();
|
|
162
|
+
formData.append("environment", environmentID);
|
|
163
|
+
formData.append("code", zipFile, "code.zip");
|
|
164
|
+
|
|
165
|
+
await fetch(
|
|
166
|
+
`https://gateway.zeabur.com/projects/${projectID}/services/${serviceID}/deploy`,
|
|
167
|
+
{
|
|
168
|
+
method: "POST",
|
|
169
|
+
headers: {
|
|
170
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
171
|
+
},
|
|
172
|
+
body: formData,
|
|
173
|
+
}
|
|
174
|
+
);
|
|
175
|
+
|
|
176
|
+
const domain = await this.createDomain(
|
|
177
|
+
serviceID,
|
|
178
|
+
environmentID,
|
|
179
|
+
serviceName,
|
|
180
|
+
domainName
|
|
181
|
+
);
|
|
182
|
+
|
|
183
|
+
return domain;
|
|
184
|
+
} catch (error) {
|
|
185
|
+
console.error(error);
|
|
186
|
+
throw error;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
package/src/index.ts
CHANGED
package/src/lib/types.ts
ADDED
package/src/lib/utils.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import JSZip from "jszip";
|
|
2
|
+
|
|
3
|
+
async function zipCode(code: string) {
|
|
4
|
+
try {
|
|
5
|
+
const zip = new JSZip();
|
|
6
|
+
zip.file("index.html", code);
|
|
7
|
+
|
|
8
|
+
const zipFile = await zip.generateAsync({ type: "blob" });
|
|
9
|
+
return zipFile;
|
|
10
|
+
} catch (error) {
|
|
11
|
+
console.error(error);
|
|
12
|
+
throw new Error("Error while zipping code");
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function generateRandomString() {
|
|
17
|
+
let result = "";
|
|
18
|
+
const characters = "abcdefghijklmnopqrstuvwxyz";
|
|
19
|
+
const charactersLength = characters.length;
|
|
20
|
+
for (let i = 0; i < 6; i++) {
|
|
21
|
+
result += characters.charAt(Math.floor(Math.random() * charactersLength));
|
|
22
|
+
}
|
|
23
|
+
return result;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export { zipCode, generateRandomString };
|
package/tsconfig.json
CHANGED
|
@@ -1,23 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"compilerOptions": {
|
|
3
|
-
"
|
|
3
|
+
"rootDir": "./src",
|
|
4
|
+
"target": "ESNext",
|
|
4
5
|
"useDefineForClassFields": true,
|
|
5
6
|
"module": "ESNext",
|
|
6
|
-
"lib": ["
|
|
7
|
-
"
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
"moduleResolution": "bundler",
|
|
11
|
-
"allowImportingTsExtensions": true,
|
|
7
|
+
"lib": ["ESNext", "DOM"],
|
|
8
|
+
"moduleResolution": "Node",
|
|
9
|
+
"strict": true,
|
|
10
|
+
"sourceMap": true,
|
|
12
11
|
"resolveJsonModule": true,
|
|
13
|
-
"
|
|
12
|
+
"esModuleInterop": true,
|
|
14
13
|
"noEmit": true,
|
|
15
|
-
|
|
16
|
-
/* Linting */
|
|
17
|
-
"strict": true,
|
|
18
14
|
"noUnusedLocals": true,
|
|
19
15
|
"noUnusedParameters": true,
|
|
20
|
-
"
|
|
16
|
+
"noImplicitReturns": true,
|
|
17
|
+
"forceConsistentCasingInFileNames": true,
|
|
18
|
+
"types": ["vite/client", "node"]
|
|
21
19
|
},
|
|
22
|
-
"include": ["src"]
|
|
20
|
+
"include": ["src"],
|
|
21
|
+
"exclude": ["**/*.test.ts", "node_modules", "test/**", ".history/**"]
|
|
23
22
|
}
|
package/vite.config.ts
CHANGED
|
@@ -1,21 +1,39 @@
|
|
|
1
|
-
|
|
1
|
+
/// <reference types="vitest" />
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { defineConfig } from "vite";
|
|
4
|
+
import packageJson from "./package.json";
|
|
2
5
|
|
|
3
|
-
|
|
6
|
+
const getPackageName = () => {
|
|
7
|
+
return packageJson.name;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
const getPackageNameCamelCase = () => {
|
|
11
|
+
try {
|
|
12
|
+
return getPackageName().replace(/-./g, (char) => char[1].toUpperCase());
|
|
13
|
+
} catch (err) {
|
|
14
|
+
throw new Error("Name property in package.json is missing.");
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const fileName = {
|
|
19
|
+
es: `${getPackageName()}.mjs`,
|
|
20
|
+
cjs: `${getPackageName()}.cjs`,
|
|
21
|
+
iife: `${getPackageName()}.iife.js`,
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const formats = Object.keys(fileName) as Array<keyof typeof fileName>;
|
|
25
|
+
|
|
26
|
+
module.exports = defineConfig({
|
|
27
|
+
base: "./",
|
|
4
28
|
build: {
|
|
5
29
|
lib: {
|
|
6
|
-
entry:
|
|
7
|
-
name:
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
rollupOptions: {
|
|
11
|
-
// 确保外部化处理那些你不想打包进库的依赖
|
|
12
|
-
external: ['vue'],
|
|
13
|
-
output: {
|
|
14
|
-
// 在 UMD 构建模式下为这些外部化的依赖提供一个全局变量
|
|
15
|
-
globals: {
|
|
16
|
-
vue: 'Vue',
|
|
17
|
-
},
|
|
18
|
-
},
|
|
30
|
+
entry: path.resolve(__dirname, "src/index.ts"),
|
|
31
|
+
name: getPackageNameCamelCase(),
|
|
32
|
+
formats,
|
|
33
|
+
fileName: (format) => fileName[format],
|
|
19
34
|
},
|
|
20
35
|
},
|
|
21
|
-
|
|
36
|
+
test: {
|
|
37
|
+
|
|
38
|
+
}
|
|
39
|
+
});
|