@seayoo-web/finder 2.1.0 → 2.2.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/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import fs, { readdirSync, lstatSync, existsSync, readFileSync, writeFileSync } from "fs";
2
- import path, { relative, join, basename, normalize, sep, dirname, resolve, extname } from "path";
2
+ import path, { relative, join, basename, normalize, sep, dirname, resolve } from "path";
3
3
  import open from "open";
4
4
  import "colors";
5
5
  import { zip } from "compressing";
@@ -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 == null ? void 0 : contentType.includes("application/json")) {
112
+ if (contentType?.includes("application/json")) {
113
113
  responseData = await response.json();
114
114
  } else {
115
115
  responseData = await response.text();
@@ -320,9 +320,9 @@ function doPreview(defaultPreviewUrl, option) {
320
320
  });
321
321
  }
322
322
  async function finderUpload(option) {
323
- const { filePath, deployTo, user, key, preview, debug } = option;
324
- if (!filePath) {
325
- throw `部署缺少参数 filePath(文件全路径)`.bgRed;
323
+ const { filePath, fileContent, deployTo, user, key, preview, debug } = option;
324
+ if (!filePath && !fileContent) {
325
+ throw `部署缺少参数 filePath(文件全路径) 或 fileContent(文件内容)`.bgRed;
326
326
  }
327
327
  if (filePath && !existsSync(filePath)) {
328
328
  throw `部署文件不存在(请确保传入完整文件路径)`.bgRed + " " + filePath;
@@ -330,10 +330,8 @@ async function finderUpload(option) {
330
330
  if (!deployTo) {
331
331
  throw `部署缺少参数 deployTo(部署目标)`.bgRed;
332
332
  }
333
- const fileExtension = extname(filePath);
334
- const filename = basename(filePath);
335
- const target = !deployTo.endsWith(fileExtension) ? `${pure(deployTo)}/${filename}` : pure(deployTo);
336
- const resp = await upload({ debug, target, buffer: Buffer.from(readFileSync(filePath)), user, key });
333
+ 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 });
337
335
  if (preview && resp.previewUrl) {
338
336
  open(resp.previewUrl);
339
337
  }
@@ -349,21 +347,21 @@ function viteDeployPlugin(option) {
349
347
  }
350
348
  },
351
349
  async closeBundle() {
352
- var _a, _b;
353
350
  if (!distDir) {
354
351
  console.error("没有找到部署资源,请尝试检查 build 是否生成了正确的资源".bgRed);
355
352
  return;
356
353
  }
354
+ await option.onBeforeDeploy?.(distDir);
357
355
  const result = await finderDeploy({
358
356
  preview: true,
359
357
  ...option,
360
358
  dist: distDir
361
359
  }).catch((e) => e instanceof Error ? e : typeof e === "string" ? new Error(e) : new Error(e + ""));
362
360
  if (result instanceof Error) {
363
- (_a = option.onError) == null ? void 0 : _a.call(option);
361
+ option.onError?.();
364
362
  console.log("部署失败".bgRed, result.message);
365
363
  } else {
366
- (_b = option.onFinished) == null ? void 0 : _b.call(option);
364
+ option.onFinished?.();
367
365
  console.log("部署成功".bgGreen, (result || "").green);
368
366
  }
369
367
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seayoo-web/finder",
3
- "version": "2.1.0",
3
+ "version": "2.2.0",
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.3"
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
  }
@@ -28,8 +28,10 @@ export declare function finderDeploy(option: {
28
28
  }): Promise<string>;
29
29
  /** 上传一个文件到 finder */
30
30
  export declare function finderUpload(option: {
31
- /** 需要上传的文件全局路 */
32
- filePath: string;
31
+ /** 需要上传的文件路径,与 fileContent 二选一,优先级高于 fileContent */
32
+ filePath?: string;
33
+ /** 需要上传的文件内容,与 filePath 二选一 */
34
+ fileContent?: string | Buffer;
33
35
  /** 部署目标全路径,需要包含文件名 */
34
36
  deployTo: string;
35
37
  user: string;
@@ -1,5 +1,6 @@
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
  };