@seayoo-web/finder 2.0.15 → 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 +26 -14
- package/package.json +1 -1
- package/types/src/core.d.ts +10 -4
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
|
|
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";
|
|
@@ -294,21 +294,35 @@ async function finderDeploy(option) {
|
|
|
294
294
|
})
|
|
295
295
|
);
|
|
296
296
|
const lastDeployResult = results[results.length - 1];
|
|
297
|
-
if (
|
|
298
|
-
|
|
297
|
+
if (lastDeployResult && lastDeployResult.previewUrl) {
|
|
298
|
+
doPreview(lastDeployResult.previewUrl, preview);
|
|
299
299
|
}
|
|
300
|
-
return
|
|
300
|
+
return deployTo.join(",");
|
|
301
301
|
}
|
|
302
302
|
const deployResult = await deploy({ debug, target: deployTo, buffer, user, key, payload });
|
|
303
|
-
if (
|
|
304
|
-
|
|
303
|
+
if (deployResult && deployResult.previewUrl) {
|
|
304
|
+
doPreview(deployResult.previewUrl, preview);
|
|
305
305
|
}
|
|
306
|
-
return
|
|
306
|
+
return deployTo;
|
|
307
|
+
}
|
|
308
|
+
function doPreview(defaultPreviewUrl, option) {
|
|
309
|
+
if (!option) {
|
|
310
|
+
return;
|
|
311
|
+
}
|
|
312
|
+
if (option === true) {
|
|
313
|
+
open(defaultPreviewUrl);
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
316
|
+
const base = defaultPreviewUrl.replace(/index\.html.*$/i, "");
|
|
317
|
+
const files = Array.isArray(option) ? option : [option];
|
|
318
|
+
files.forEach((file) => {
|
|
319
|
+
open(base + file);
|
|
320
|
+
});
|
|
307
321
|
}
|
|
308
322
|
async function finderUpload(option) {
|
|
309
|
-
const { filePath, deployTo, user, key, preview, debug } = option;
|
|
310
|
-
if (!filePath) {
|
|
311
|
-
throw `部署缺少参数 filePath(文件全路径)`.bgRed;
|
|
323
|
+
const { filePath, fileContent, deployTo, user, key, preview, debug } = option;
|
|
324
|
+
if (!filePath && !fileContent) {
|
|
325
|
+
throw `部署缺少参数 filePath(文件全路径) 或 fileContent(文件内容)`.bgRed;
|
|
312
326
|
}
|
|
313
327
|
if (filePath && !existsSync(filePath)) {
|
|
314
328
|
throw `部署文件不存在(请确保传入完整文件路径)`.bgRed + " " + filePath;
|
|
@@ -316,10 +330,8 @@ async function finderUpload(option) {
|
|
|
316
330
|
if (!deployTo) {
|
|
317
331
|
throw `部署缺少参数 deployTo(部署目标)`.bgRed;
|
|
318
332
|
}
|
|
319
|
-
const
|
|
320
|
-
const
|
|
321
|
-
const target = !deployTo.endsWith(fileExtension) ? `${pure(deployTo)}/${filename}` : pure(deployTo);
|
|
322
|
-
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 });
|
|
323
335
|
if (preview && resp.previewUrl) {
|
|
324
336
|
open(resp.previewUrl);
|
|
325
337
|
}
|
package/package.json
CHANGED
package/types/src/core.d.ts
CHANGED
|
@@ -17,15 +17,21 @@ export declare function finderDeploy(option: {
|
|
|
17
17
|
key: string;
|
|
18
18
|
/** 是否输出更多调试信息 */
|
|
19
19
|
debug?: boolean;
|
|
20
|
-
/**
|
|
21
|
-
|
|
20
|
+
/**
|
|
21
|
+
* 是否部署完毕后打开目标文件(index.html)
|
|
22
|
+
*
|
|
23
|
+
* 也可以指定不同的目标文件
|
|
24
|
+
*/
|
|
25
|
+
preview?: boolean | string | string[];
|
|
22
26
|
/** 代码的 commit log 信息,换行用 \n */
|
|
23
27
|
commitLogs?: string;
|
|
24
28
|
}): Promise<string>;
|
|
25
29
|
/** 上传一个文件到 finder */
|
|
26
30
|
export declare function finderUpload(option: {
|
|
27
|
-
/**
|
|
28
|
-
filePath
|
|
31
|
+
/** 需要上传的文件路径 */
|
|
32
|
+
filePath?: string;
|
|
33
|
+
/** 需要上传的文件内容 */
|
|
34
|
+
fileContent?: string | Buffer;
|
|
29
35
|
/** 部署目标全路径,需要包含文件名 */
|
|
30
36
|
deployTo: string;
|
|
31
37
|
user: string;
|