@seayoo-web/finder 2.1.1 → 2.2.1
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/dist/index.js +21 -19
- package/package.json +3 -2
- package/types/src/core.d.ts +5 -2
- package/types/src/plugin.d.ts +2 -1
- package/types/src/service.d.ts +2 -0
package/dist/index.js
CHANGED
|
@@ -109,7 +109,7 @@ async function request({
|
|
|
109
109
|
const response = await fetch(url, requestInit);
|
|
110
110
|
let responseData;
|
|
111
111
|
const contentType = response.headers.get("content-type");
|
|
112
|
-
if (contentType
|
|
112
|
+
if (contentType?.includes("application/json")) {
|
|
113
113
|
responseData = await response.json();
|
|
114
114
|
} else {
|
|
115
115
|
responseData = await response.text();
|
|
@@ -140,8 +140,8 @@ const FinderApiPaths = {
|
|
|
140
140
|
upload: "/service/upload"
|
|
141
141
|
};
|
|
142
142
|
async function deploy(option) {
|
|
143
|
-
const { debug, target, buffer, user, key, payload } = option;
|
|
144
|
-
const targetServer = await findTargetServer(target, debug);
|
|
143
|
+
const { debug, target, buffer, user, key, payload, ignoreCache } = option;
|
|
144
|
+
const targetServer = await findTargetServer(target, debug, ignoreCache);
|
|
145
145
|
if (!targetServer) {
|
|
146
146
|
throw `finder不支持该域名部署,请检查 ${target}`.bgRed;
|
|
147
147
|
}
|
|
@@ -174,8 +174,8 @@ async function deploy(option) {
|
|
|
174
174
|
};
|
|
175
175
|
}
|
|
176
176
|
async function upload(option) {
|
|
177
|
-
const { debug, target, buffer, user, key } = option;
|
|
178
|
-
const targetServer = await findTargetServer(target, debug);
|
|
177
|
+
const { debug, target, buffer, user, key, ignoreCache } = option;
|
|
178
|
+
const targetServer = await findTargetServer(target, debug, ignoreCache);
|
|
179
179
|
if (!targetServer) {
|
|
180
180
|
throw `finder不支持该域名部署,请检查 ${target}`.bgRed;
|
|
181
181
|
}
|
|
@@ -204,18 +204,20 @@ async function upload(option) {
|
|
|
204
204
|
const getFinderServerFullPath = function(domain) {
|
|
205
205
|
return (domain.endsWith("internal") ? "http://" : "https://") + domain;
|
|
206
206
|
};
|
|
207
|
-
async function findTargetServer(target, debug) {
|
|
207
|
+
async function findTargetServer(target, debug, ignoreCache) {
|
|
208
208
|
const t = pure(target);
|
|
209
|
-
await updateSupportedProjects(
|
|
209
|
+
await updateSupportedProjects(!!ignoreCache, debug);
|
|
210
210
|
for (const domain in FinderServers) {
|
|
211
211
|
if (FinderServers[domain].find((url) => t.startsWith(url))) {
|
|
212
212
|
return domain;
|
|
213
213
|
}
|
|
214
214
|
}
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
215
|
+
if (!ignoreCache) {
|
|
216
|
+
await updateSupportedProjects(true, debug);
|
|
217
|
+
for (const domain in FinderServers) {
|
|
218
|
+
if (FinderServers[domain].find((url) => t.startsWith(url))) {
|
|
219
|
+
return domain;
|
|
220
|
+
}
|
|
219
221
|
}
|
|
220
222
|
}
|
|
221
223
|
return null;
|
|
@@ -265,7 +267,7 @@ async function getServerSupportedProjects(serverDomain, ignoreCache = false, deb
|
|
|
265
267
|
return pureList;
|
|
266
268
|
}
|
|
267
269
|
async function finderDeploy(option) {
|
|
268
|
-
const { dist, ignoreFiles, deployTo, user, key, debug, preview, commitLogs } = option;
|
|
270
|
+
const { dist, ignoreFiles, deployTo, user, key, debug, preview, commitLogs, ignoreCache } = option;
|
|
269
271
|
if (!dist) {
|
|
270
272
|
throw "部署参数 dist 缺失".bgRed;
|
|
271
273
|
}
|
|
@@ -290,7 +292,7 @@ async function finderDeploy(option) {
|
|
|
290
292
|
if (Array.isArray(deployTo)) {
|
|
291
293
|
const results = await Promise.all(
|
|
292
294
|
deployTo.map((target) => {
|
|
293
|
-
return deploy({ debug, target, buffer, user, key, payload });
|
|
295
|
+
return deploy({ debug, target, buffer, user, key, payload, ignoreCache });
|
|
294
296
|
})
|
|
295
297
|
);
|
|
296
298
|
const lastDeployResult = results[results.length - 1];
|
|
@@ -299,7 +301,7 @@ async function finderDeploy(option) {
|
|
|
299
301
|
}
|
|
300
302
|
return deployTo.join(",");
|
|
301
303
|
}
|
|
302
|
-
const deployResult = await deploy({ debug, target: deployTo, buffer, user, key, payload });
|
|
304
|
+
const deployResult = await deploy({ debug, target: deployTo, buffer, user, key, payload, ignoreCache });
|
|
303
305
|
if (deployResult && deployResult.previewUrl) {
|
|
304
306
|
doPreview(deployResult.previewUrl, preview);
|
|
305
307
|
}
|
|
@@ -320,7 +322,7 @@ function doPreview(defaultPreviewUrl, option) {
|
|
|
320
322
|
});
|
|
321
323
|
}
|
|
322
324
|
async function finderUpload(option) {
|
|
323
|
-
const { filePath, fileContent, deployTo, user, key, preview, debug } = option;
|
|
325
|
+
const { filePath, fileContent, deployTo, user, key, preview, debug, ignoreCache } = option;
|
|
324
326
|
if (!filePath && !fileContent) {
|
|
325
327
|
throw `部署缺少参数 filePath(文件全路径) 或 fileContent(文件内容)`.bgRed;
|
|
326
328
|
}
|
|
@@ -331,7 +333,7 @@ async function finderUpload(option) {
|
|
|
331
333
|
throw `部署缺少参数 deployTo(部署目标)`.bgRed;
|
|
332
334
|
}
|
|
333
335
|
const content = filePath ? Buffer.from(readFileSync(filePath)) : Buffer.isBuffer(fileContent) ? fileContent : Buffer.from(fileContent || "");
|
|
334
|
-
const resp = await upload({ debug, target: pure(deployTo), buffer: content, user, key });
|
|
336
|
+
const resp = await upload({ debug, target: pure(deployTo), buffer: content, user, key, ignoreCache });
|
|
335
337
|
if (preview && resp.previewUrl) {
|
|
336
338
|
open(resp.previewUrl);
|
|
337
339
|
}
|
|
@@ -347,21 +349,21 @@ function viteDeployPlugin(option) {
|
|
|
347
349
|
}
|
|
348
350
|
},
|
|
349
351
|
async closeBundle() {
|
|
350
|
-
var _a, _b;
|
|
351
352
|
if (!distDir) {
|
|
352
353
|
console.error("没有找到部署资源,请尝试检查 build 是否生成了正确的资源".bgRed);
|
|
353
354
|
return;
|
|
354
355
|
}
|
|
356
|
+
await option.onBeforeDeploy?.(distDir);
|
|
355
357
|
const result = await finderDeploy({
|
|
356
358
|
preview: true,
|
|
357
359
|
...option,
|
|
358
360
|
dist: distDir
|
|
359
361
|
}).catch((e) => e instanceof Error ? e : typeof e === "string" ? new Error(e) : new Error(e + ""));
|
|
360
362
|
if (result instanceof Error) {
|
|
361
|
-
|
|
363
|
+
option.onError?.();
|
|
362
364
|
console.log("部署失败".bgRed, result.message);
|
|
363
365
|
} else {
|
|
364
|
-
|
|
366
|
+
option.onFinished?.();
|
|
365
367
|
console.log("部署成功".bgGreen, (result || "").green);
|
|
366
368
|
}
|
|
367
369
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@seayoo-web/finder",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.1",
|
|
4
4
|
"description": "agent for web finder",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"source": "index.ts",
|
|
@@ -28,10 +28,11 @@
|
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@types/node": "^22.13.1",
|
|
30
30
|
"vitest": "^3.0.5",
|
|
31
|
-
"@seayoo-web/tsconfig": "^1.0.
|
|
31
|
+
"@seayoo-web/tsconfig": "^1.0.5"
|
|
32
32
|
},
|
|
33
33
|
"scripts": {
|
|
34
34
|
"build": "vite build && tsc --emitDeclarationOnly",
|
|
35
|
+
"type-check": "tsc --noEmit",
|
|
35
36
|
"test": "vitest",
|
|
36
37
|
"prepublish": "pnpm build"
|
|
37
38
|
}
|
package/types/src/core.d.ts
CHANGED
|
@@ -25,12 +25,14 @@ export declare function finderDeploy(option: {
|
|
|
25
25
|
preview?: boolean | string | string[];
|
|
26
26
|
/** 代码的 commit log 信息,换行用 \n */
|
|
27
27
|
commitLogs?: string;
|
|
28
|
+
/** 是否忽略本地缓存的服务器更新信息 */
|
|
29
|
+
ignoreCache?: boolean;
|
|
28
30
|
}): Promise<string>;
|
|
29
31
|
/** 上传一个文件到 finder */
|
|
30
32
|
export declare function finderUpload(option: {
|
|
31
|
-
/**
|
|
33
|
+
/** 需要上传的文件路径,与 fileContent 二选一,优先级高于 fileContent */
|
|
32
34
|
filePath?: string;
|
|
33
|
-
/**
|
|
35
|
+
/** 需要上传的文件内容,与 filePath 二选一 */
|
|
34
36
|
fileContent?: string | Buffer;
|
|
35
37
|
/** 部署目标全路径,需要包含文件名 */
|
|
36
38
|
deployTo: string;
|
|
@@ -38,4 +40,5 @@ export declare function finderUpload(option: {
|
|
|
38
40
|
key: string;
|
|
39
41
|
debug?: boolean;
|
|
40
42
|
preview?: boolean;
|
|
43
|
+
ignoreCache?: boolean;
|
|
41
44
|
}): Promise<void>;
|
package/types/src/plugin.d.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { finderDeploy } from "./core";
|
|
2
2
|
type FinderDeployVitePluginOption = Omit<Parameters<typeof finderDeploy>[0], "dist"> & {
|
|
3
|
+
onBeforeDeploy?: (distDir: string) => unknown;
|
|
3
4
|
onFinished?: () => unknown;
|
|
4
5
|
onError?: () => unknown;
|
|
5
6
|
};
|
|
6
7
|
export declare function viteDeployPlugin(option: FinderDeployVitePluginOption): {
|
|
7
8
|
name: string;
|
|
8
9
|
generateBundle({ dir }: {
|
|
9
|
-
dir
|
|
10
|
+
dir?: string;
|
|
10
11
|
}): void;
|
|
11
12
|
closeBundle(): Promise<void>;
|
|
12
13
|
};
|
package/types/src/service.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ export declare function deploy(option: {
|
|
|
6
6
|
user: string;
|
|
7
7
|
key: string;
|
|
8
8
|
payload?: Record<string, string>;
|
|
9
|
+
ignoreCache?: boolean;
|
|
9
10
|
}): Promise<{
|
|
10
11
|
previewUrl?: string;
|
|
11
12
|
}>;
|
|
@@ -16,6 +17,7 @@ export declare function upload(option: {
|
|
|
16
17
|
buffer: Buffer;
|
|
17
18
|
user: string;
|
|
18
19
|
key: string;
|
|
20
|
+
ignoreCache?: boolean;
|
|
19
21
|
}): Promise<{
|
|
20
22
|
previewUrl?: string;
|
|
21
23
|
}>;
|