@seayoo-web/finder 2.1.0 → 2.1.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 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";
@@ -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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seayoo-web/finder",
3
- "version": "2.1.0",
3
+ "version": "2.1.1",
4
4
  "description": "agent for web finder",
5
5
  "type": "module",
6
6
  "source": "index.ts",
@@ -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
+ /** 需要上传的文件路径 */
32
+ filePath?: string;
33
+ /** 需要上传的文件内容 */
34
+ fileContent?: string | Buffer;
33
35
  /** 部署目标全路径,需要包含文件名 */
34
36
  deployTo: string;
35
37
  user: string;