@seayoo-web/finder 1.1.0 → 2.0.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/src/service.ts ADDED
@@ -0,0 +1,180 @@
1
+ import { existsSync, readFileSync, writeFileSync } from "fs";
2
+ import { basename, dirname, resolve } from "path";
3
+
4
+ import { getSystemTempDir, pure, request } from "./utils";
5
+
6
+ /** finder 服务器列表以及所支持的域名 */
7
+ const FinderServers: Record<string, string[]> = {
8
+ "finder.seayoo.io": [],
9
+ "finder.seayoo.com": [],
10
+ "finder.seayoo.internal": [],
11
+ "finder.dev.seayoo.com": [],
12
+ };
13
+
14
+ /** finder 的 api path */
15
+ const FinderApiPaths = {
16
+ deploy: "/service/deploy",
17
+ inspect: "/inspect/supported/projects",
18
+ upload: "/service/upload",
19
+ } as const;
20
+
21
+ /** 将指定的 zip buffer 部署到指定目录 */
22
+ export async function deploy(option: {
23
+ debug?: boolean;
24
+ target: string;
25
+ buffer: Buffer;
26
+ user: string;
27
+ key: string;
28
+ payload?: Record<string, string>;
29
+ }): Promise<{ previewUrl?: string }> {
30
+ const { debug, target, buffer, user, key, payload } = option;
31
+ const targetServer = await findTargetServer(target, debug);
32
+ if (!targetServer) {
33
+ throw `finder不支持该域名部署,请检查 ${target}`.bgRed;
34
+ }
35
+ if (!user || !key) {
36
+ throw `部署缺少认证信息(user & key)`.bgRed;
37
+ }
38
+ const zipMockName = `${Date.now()}${Math.random().toString(16).slice(-3)}.zip`;
39
+ const { status, message, data } = await request({
40
+ url: `${getFinderServerFullPath(targetServer)}${FinderApiPaths.deploy}?target=${encodeURIComponent(pure(target))}`,
41
+ method: "POST",
42
+ headers: { user, key },
43
+ data: {
44
+ path: zipMockName,
45
+ file: { buffer, filename: zipMockName, contentType: "application/octet-stream" },
46
+ payload: JSON.stringify(payload || ""),
47
+ },
48
+ });
49
+ if (status !== 200) {
50
+ throw `${`部署接口错误(${status})`.bgRed} ${message || ""}.red`;
51
+ }
52
+ if (!data || typeof data !== "object") {
53
+ throw `部署接口响应错误,请自行检查是否部署成功。`.bgRed + JSON.stringify(data).red;
54
+ }
55
+ if ("err" in data || !("data" in data) || typeof data.data !== "string") {
56
+ throw `部署接口错误。`.bgRed + JSON.stringify(data).red;
57
+ }
58
+ // 返回预览页面地址
59
+ const url = data.data;
60
+ if (debug) {
61
+ console.log("部署完毕,接口返回内容", data);
62
+ }
63
+ return {
64
+ previewUrl: url.endsWith("/")
65
+ ? url.replace(/\/*$/, "/") + "index.html?" + Math.random().toString(16).slice(2)
66
+ : url.startsWith("http")
67
+ ? url
68
+ : "",
69
+ };
70
+ }
71
+
72
+ /** 将文件上传到指定位置 */
73
+ export async function upload(option: {
74
+ debug?: boolean;
75
+ target: string;
76
+ buffer: Buffer;
77
+ user: string;
78
+ key: string;
79
+ }): Promise<{ previewUrl?: string }> {
80
+ const { debug, target, buffer, user, key } = option;
81
+ const targetServer = await findTargetServer(target, debug);
82
+ if (!targetServer) {
83
+ throw `finder不支持该域名部署,请检查 ${target}`.bgRed;
84
+ }
85
+ if (!user || !key) {
86
+ throw `部署缺少认证信息(user & key)`.bgRed;
87
+ }
88
+ const filename = basename(target);
89
+ const deployTarget = dirname(pure(target));
90
+ const { status, message, data } = await request({
91
+ url: `${getFinderServerFullPath(targetServer)}${FinderApiPaths.upload}?target=${encodeURIComponent(deployTarget)}`,
92
+ method: "POST",
93
+ headers: { user, key },
94
+ data: {
95
+ path: filename,
96
+ file: { buffer, filename, contentType: "application/octet-stream" },
97
+ },
98
+ });
99
+ if (status !== 200) {
100
+ throw `${`上传接口错误(${status})`.bgRed} ${message || ""}.red`;
101
+ }
102
+ if (!data || typeof data !== "object") {
103
+ throw `上传接口响应错误,请自行检查是否上传成功。`.bgRed + JSON.stringify(data).red;
104
+ }
105
+ if ("err" in data || !("data" in data) || typeof data.data !== "string") {
106
+ throw `上传接口错误。`.bgRed + JSON.stringify(data).red;
107
+ }
108
+ return { previewUrl: `https://${pure(target)}` };
109
+ }
110
+
111
+ const getFinderServerFullPath = function (domain: string) {
112
+ return (domain.endsWith("internal") ? "http://" : "https://") + domain;
113
+ };
114
+
115
+ async function findTargetServer(target: string, debug?: boolean) {
116
+ const t = pure(target);
117
+ await updateSupportedProjects(false, debug);
118
+ for (const domain in FinderServers) {
119
+ if (FinderServers[domain].find((url) => t.startsWith(url))) {
120
+ return domain;
121
+ }
122
+ }
123
+ // 如果没有找到则强制查询后再来一次
124
+ await updateSupportedProjects(true, debug);
125
+ for (const domain in FinderServers) {
126
+ if (FinderServers[domain].find((url) => t.startsWith(url))) {
127
+ return domain;
128
+ }
129
+ }
130
+ // 还是没有找到就返回
131
+ return null;
132
+ }
133
+
134
+ async function updateSupportedProjects(force = false, debug?: boolean) {
135
+ const domains = Object.keys(FinderServers);
136
+ for (const domain of domains) {
137
+ FinderServers[domain] = (await getServerSupportedProjects(domain, force, debug)) || [];
138
+ }
139
+ }
140
+
141
+ async function getServerSupportedProjects(
142
+ serverDomain: string,
143
+ ignoreCache = false,
144
+ debug?: boolean,
145
+ ): Promise<string[]> {
146
+ const cacheFile = resolve(getSystemTempDir(), `${serverDomain}.json`);
147
+ if (existsSync(cacheFile) && !ignoreCache) {
148
+ try {
149
+ const cache = JSON.parse(readFileSync(cacheFile).toString());
150
+ if (Array.isArray(cache) && cache.every((d) => typeof d === "string")) {
151
+ if (debug) {
152
+ console.log({ method: "getServerSupportedProjects", serverDomain, cache });
153
+ }
154
+ return cache;
155
+ }
156
+ } catch (e) {
157
+ console.error("ReadFinderCacheError", e);
158
+ }
159
+ }
160
+ const inspectURL = `${getFinderServerFullPath(serverDomain)}${FinderApiPaths.inspect}`;
161
+ const { status, message, data } = await request({
162
+ url: inspectURL,
163
+ method: "GET",
164
+ headers: { UserAgent: `web finder agent v2` },
165
+ });
166
+ if (status !== 200) {
167
+ console.error(`服务器 ${inspectURL} 检查接口错误`.bgRed, (message || "").red);
168
+ return [];
169
+ }
170
+ if (!Array.isArray(data) || !data.every((d) => typeof d === "string")) {
171
+ console.error(`服务器 ${inspectURL} 接口返回内容错误`.bgRed, JSON.stringify(data).red);
172
+ return [];
173
+ }
174
+ if (debug) {
175
+ console.log({ method: "getServerSupportedProjects", serverDomain, list: data });
176
+ }
177
+ const pureList = data.map(pure);
178
+ writeFileSync(cacheFile, JSON.stringify(pureList));
179
+ return pureList;
180
+ }
package/src/utils.ts ADDED
@@ -0,0 +1,97 @@
1
+ import fs from "fs";
2
+ import os from "os";
3
+ import path from "path";
4
+
5
+ export function pure(url: string) {
6
+ return url.replace(/(?:^https?:\/\/|\/*$)/gi, "");
7
+ }
8
+
9
+ export function getSystemTempDir() {
10
+ const dir = path.resolve(os.tmpdir(), "webfinder");
11
+ if (!fs.existsSync(dir)) {
12
+ fs.mkdirSync(dir, { recursive: true });
13
+ }
14
+ return dir;
15
+ }
16
+
17
+ type RequestData = Record<string, string | number | { buffer: Buffer; contentType: string; filename: string }>;
18
+
19
+ export async function request({
20
+ url,
21
+ method,
22
+ headers,
23
+ data,
24
+ }: {
25
+ url: string;
26
+ method: "GET" | "POST";
27
+ headers?: Record<string, string>;
28
+ data?: RequestData;
29
+ }): Promise<{ status: number; message?: string; data: unknown }> {
30
+ // 检查是否有文件需要上传
31
+ const hasFileUpload =
32
+ method === "POST" && data && Object.values(data).some((value) => typeof value === "object" && "buffer" in value);
33
+
34
+ // 准备请求配置
35
+ const requestInit: RequestInit = {
36
+ method,
37
+ headers: { ...headers },
38
+ };
39
+
40
+ // 处理请求体
41
+ try {
42
+ if (data) {
43
+ if (hasFileUpload) {
44
+ // 使用 FormData 处理包含文件的请求
45
+ const formData = new FormData();
46
+
47
+ // 遍历数据,将普通字段和文件字段添加到 FormData
48
+ Object.entries(data).forEach(([key, value]) => {
49
+ if (typeof value === "object" && "buffer" in value) {
50
+ // 处理文件字段
51
+ const { buffer, filename, contentType } = value;
52
+ const blob = new Blob([buffer], { type: contentType });
53
+ formData.append(key, blob, filename);
54
+ } else {
55
+ // 处理普通字段
56
+ formData.append(key, String(value));
57
+ }
58
+ });
59
+
60
+ requestInit.body = formData;
61
+ } else {
62
+ // 普通 JSON 请求
63
+ requestInit.headers = {
64
+ "Content-Type": "application/json",
65
+ ...headers,
66
+ };
67
+ requestInit.body = JSON.stringify(data);
68
+ }
69
+ }
70
+
71
+ // 发送请求
72
+ const response = await fetch(url, requestInit);
73
+
74
+ // 尝试解析响应
75
+ let responseData: unknown;
76
+ const contentType = response.headers.get("content-type");
77
+
78
+ if (contentType?.includes("application/json")) {
79
+ responseData = await response.json();
80
+ } else {
81
+ responseData = await response.text();
82
+ }
83
+
84
+ // 返回统一的响应格式
85
+ return {
86
+ status: response.status,
87
+ message: response.statusText,
88
+ data: responseData,
89
+ };
90
+ } catch (err) {
91
+ return {
92
+ status: 500,
93
+ message: err instanceof Error ? err.message : String(err),
94
+ data: null,
95
+ };
96
+ }
97
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "@seayoo-web/tsconfig/node.json",
3
+ "include": ["src/**/*.ts", "index.ts"],
4
+ "compilerOptions": {
5
+ "outDir": "dist",
6
+ "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
7
+ "declarationDir": "./types"
8
+ }
9
+ }
@@ -0,0 +1,2 @@
1
+ export * from "./src/core";
2
+ export * from "./src/plugin";
@@ -0,0 +1,4 @@
1
+ /** 代码压缩 */
2
+ export declare function compressToBuffer(sourceDir: string, ignoreFiles?: string[], debug?: boolean): Promise<Buffer>;
3
+ export declare function getAllFiles(dir: string, ignores?: string[]): string[];
4
+ export declare function isIgnoreFile(filePath: string, ignores: string[]): boolean;
@@ -0,0 +1,31 @@
1
+ import "colors";
2
+ /** 部署一个目录 */
3
+ export declare function finderDeploy(option: {
4
+ /** 需要推送的代码目录 */
5
+ dist: string;
6
+ /** 忽略部署的文件,如果是目录则需要以 / 结尾。暂不支持模糊匹配 */
7
+ ignoreFiles?: string[];
8
+ /** 部署的目标地址 */
9
+ deployTo: string | string[];
10
+ /** 部署 user */
11
+ user: string;
12
+ /** 部署 key */
13
+ key: string;
14
+ /** 是否输出更多调试信息 */
15
+ debug?: boolean;
16
+ /** 是否部署完毕后打开目标文件(index.html) */
17
+ preview?: boolean;
18
+ /** 代码的 commit log 信息,换行用 \n */
19
+ commitLogs?: string;
20
+ }): Promise<string>;
21
+ /** 上传一个文件到 finder */
22
+ export declare function finderUpload(option: {
23
+ /** 需要上传的文件全局路 */
24
+ filePath: string;
25
+ /** 部署目标全路径,需要包含文件名 */
26
+ deployTo: string;
27
+ user: string;
28
+ key: string;
29
+ debug?: boolean;
30
+ preview?: boolean;
31
+ }): Promise<void>;
@@ -0,0 +1,14 @@
1
+ import { finderDeploy } from "./core";
2
+ import "colors";
3
+ type FinderDeployVitePluginOption = Omit<Parameters<typeof finderDeploy>[0], "dist"> & {
4
+ onFinished?: () => unknown;
5
+ onError?: () => unknown;
6
+ };
7
+ export declare function viteDeployPlugin(option: FinderDeployVitePluginOption): {
8
+ name: string;
9
+ generateBundle({ dir }: {
10
+ dir: string;
11
+ }): void;
12
+ closeBundle(): Promise<void>;
13
+ };
14
+ export {};
@@ -0,0 +1,21 @@
1
+ /** 将指定的 zip buffer 部署到指定目录 */
2
+ export declare function deploy(option: {
3
+ debug?: boolean;
4
+ target: string;
5
+ buffer: Buffer;
6
+ user: string;
7
+ key: string;
8
+ payload?: Record<string, string>;
9
+ }): Promise<{
10
+ previewUrl?: string;
11
+ }>;
12
+ /** 将文件上传到指定位置 */
13
+ export declare function upload(option: {
14
+ debug?: boolean;
15
+ target: string;
16
+ buffer: Buffer;
17
+ user: string;
18
+ key: string;
19
+ }): Promise<{
20
+ previewUrl?: string;
21
+ }>;
@@ -0,0 +1,18 @@
1
+ export declare function pure(url: string): string;
2
+ export declare function getSystemTempDir(): string;
3
+ type RequestData = Record<string, string | number | {
4
+ buffer: Buffer;
5
+ contentType: string;
6
+ filename: string;
7
+ }>;
8
+ export declare function request({ url, method, headers, data, }: {
9
+ url: string;
10
+ method: "GET" | "POST";
11
+ headers?: Record<string, string>;
12
+ data?: RequestData;
13
+ }): Promise<{
14
+ status: number;
15
+ message?: string;
16
+ data: unknown;
17
+ }>;
18
+ export {};
package/vite.config.ts ADDED
@@ -0,0 +1,27 @@
1
+ import { builtinModules } from "module";
2
+ import { join } from "node:path";
3
+
4
+ import { defineConfig } from "vite";
5
+
6
+ import pkg from "./package.json";
7
+
8
+ export default defineConfig({
9
+ build: {
10
+ outDir: "dist",
11
+ lib: {
12
+ entry: join(process.cwd(), "index.ts"),
13
+ formats: ["es", "cjs"],
14
+ fileName: (format, entryName) => {
15
+ return format === "es"
16
+ ? `${entryName}.js`
17
+ : format === "cjs"
18
+ ? entryName + ".cjs"
19
+ : `${entryName}.${format}.js`;
20
+ },
21
+ },
22
+ minify: false,
23
+ rollupOptions: {
24
+ external: [...Object.keys(pkg.dependencies || {}), ...builtinModules, ...builtinModules.map((n) => `node:${n}`)],
25
+ },
26
+ },
27
+ });
package/dist/core.js DELETED
@@ -1 +0,0 @@
1
- const compressing=require("compressing"),pkg=require("../package.json"),needle=require("needle"),crypto=require("crypto"),fsp=require("fs/promises"),open=require("open"),path=require("path"),fs=require("fs"),os=require("os");require("colors");const finderServers={"finder.seayoo.io":[],"finder.seayoo.com":[],"finder.seayoo.internal":[],"finder.dev.seayoo.com":[]},paths={deploy:"/service/deploy",inspect:"/inspect/supported/projects",upload:"/service/upload"};let isDebugMode=!1;async function finderDeploy({dist:e,zip:r,archive:t,deployTo:i,user:n,key:o,debug:s,preview:a}){if(isDebugMode=!!s,!e&&!r)throw"部署参数 dist(文件目录) 或者 zip(打包文件) 需要二选一".bgBrightRed;if(r&&!/.+\.zip$/i.test(r))throw`部署参数 zip 需要指定一个zip文件 ${r}`;if(r&&!fs.existsSync(r))throw"部署参数 zip 指定的文件不存在(请确保传入完整文件路径)".bgBrightRed+" "+r;if(!(r||fs.existsSync(path.resolve(e))&&fs.lstatSync(path.resolve(e)).isDirectory()))throw"部署参数错误,dist(文件目录) 需要是一个存在的文件目录".bgBrightRed+" "+e;if(!i&&!t)throw"部署参数 archive(打包归档) 和 deployTo(部署文件) 至少需要二选一".bgBrightRed;const d=r||await async function(){const r=path.resolve(getTempDir(),getRandomZipFileName());try{await compressing.zip.compressDir(e,r,{ignoreBase:!0})}catch(e){throw"部署预处理之压缩文件目录失败".bgBrightRed+" "+e.toString()}return r}(),p=Buffer.from(fs.readFileSync(d));if(await archiveFile(d,t,r!==d),!i)return;const c=await deploy({target:i,buffer:p,user:n,key:o});return a&&c&&c.previewUrl&&open(c.previewUrl),c}async function finderUpload({file:e,deployTo:r,user:t,key:i,preview:n}){if(!e)throw"部署缺少参数 file(文件全路径)".bgBrightRed;if(e&&!fs.existsSync(e))throw"部署file参数指定的文件不存在(请确保传入完整文件路径)".bgBrightRed+" "+e;if(!r)throw"部署缺少参数 deployTo(部署目标)".bgBrightRed;const o=path.extname(e);r.endsWith(o)||(r=r.replace(/\/*$/,"")+"/"+md5(await fsp.readFile(e)));const s=await upload({target:r,buffer:Buffer.from(fs.readFileSync(e)),user:t,key:i});n&&s&&s.previewUrl&&open(s.previewUrl)}const getFinderServerFullPath=function(e){return(e.endsWith("internal")?"http://":"https://")+e};function getTempDir(){const e=path.resolve(os.tmpdir(),"webfinder");return fs.existsSync(e)||fs.mkdirSync(e,{recursive:!0}),e}function md5(e){return crypto.createHash("md5").update(e).digest("hex").toLowerCase()}function pure(e){return e.replace(/^https?:\/\//i,"")}function getRandomZipFileName(){return Date.now()+Math.random().toString(16).slice(2)+".zip"}function getDefaultArchiveFileName(){const e=new Date,r=e=>("0"+e).slice(-2);return[e.getFullYear(),r(e.getMonth()+1),r(e.getDate()),r(e.getHours()),r(e.getMinutes())].join("")+".zip"}async function archiveFile(e,r,t){if(!r)return;const i=/\.zip$/i.test(r)?path.resolve(r):path.resolve(r,getDefaultArchiveFileName());await fsp.mkdir(path.dirname(i),{recursive:!0}).catch((e=>{throw"检查归档目录失败 ".brightRed+" "+e.toString()})),await fsp.copyFile(e,i).catch((()=>{console.error("归档文件失败".brightRed)})),t&&await fsp.unlink(e).catch((()=>{console.error(`删除zip文件失败 ${e}`.brightRed)}))}async function deploy({target:e,buffer:r,user:t,key:i}){const n=await findTargetServer(e);if(!n)throw`finder不支持该域名部署,请检查 ${e}`.bgBrightRed;if(!t||!i)throw"部署缺少认证信息(user & key)".bgBrightRed;return new Promise(((o,s)=>{const a=getRandomZipFileName();needle.post(`${getFinderServerFullPath(n)}${paths.deploy}?target=${encodeURIComponent(pure(e))}`,{path:a,file:{buffer:r,filename:a,content_type:"application/octet-stream"}},{headers:{user:t,key:i},multipart:!0},(function(e,r){if(e)return s("部署接口错误".bgBrightRed+" "+JSON.stringify(e));const t=r.body;return t.err?s(t.desc):t.data&&"string"==typeof t.data?void o({previewUrl:t.data.endsWith("/")?t.data.replace(/\/*$/,"/")+"index.html?"+Math.random().toString(16).slice(2):t.data}):s("部署接口数据错误".bgBrightRed+" "+(r.body.message||JSON.stringify(r.body)))}))}))}async function upload({target:e,buffer:r,user:t,key:i}){const n=await findTargetServer(e);if(!n)throw`finder不支持该域名部署,请检查 ${e}`.bgBrightRed;if(!t||!i)throw"部署缺少认证信息(user & key)".bgBrightRed;return new Promise(((o,s)=>{const a=path.basename(e),d=path.dirname(pure(e));needle.post(`${getFinderServerFullPath(n)}${paths.upload}?target=${encodeURIComponent(d)}`,{path:a,file:{buffer:r,filename:a,content_type:"application/octet-stream"}},{headers:{user:t,key:i},multipart:!0},(function(r,t){if(r)return s("上传接口错误".bgBrightRed+" "+JSON.stringify(r));const i=t.body;return i.err?s(i.desc):i.data&&"string"==typeof i.data?void o({previewUrl:"https://"+pure(e)}):s("上传接口数据错误".bgBrightRed+" "+JSON.stringify(t.body))}))}))}async function findTargetServer(e){const r=pure(e);await updateSupportedProjects();for(const e in finderServers)if(finderServers[e].find((e=>r.startsWith(e))))return e;await updateSupportedProjects(!0);for(const e in finderServers)if(finderServers[e].find((e=>r.startsWith(e))))return e;return null}async function updateSupportedProjects(e){const r=Object.keys(finderServers);for(const t of r)finderServers[t]=await getServerSupportedProjects(t,e)||[]}async function getServerSupportedProjects(e,r){const t=path.resolve(getTempDir(),e+".json");if(fs.existsSync(t)&&!r){const e=fs.readFileSync(t).toString();try{const r=JSON.parse(e);if(Array.isArray(r))return r}catch(e){isDebugMode&&console.error("cache file form error".brightRed,e)}}return await new Promise(((r,i)=>{const n=`${getFinderServerFullPath(e)}${paths.inspect}`;needle.get(n,{user_agent:`web finder agent v${pkg.version}`},(function(i,o){if(i)return isDebugMode&&console.error(`服务器 ${n} 检查接口错误`.brightRed+" "+i.toString()),r([]);const s=o.body;if(!Array.isArray(s))return isDebugMode&&console.warn(`服务器 ${n} 接口返回内容错误`.brightRed+" "+JSON.stringify(s)),r([]);isDebugMode&&console.log(`${e} 支持服务器列表`,s);const a=s.map((e=>pure(e,!0)));fsp.writeFile(t,JSON.stringify(a)).then((()=>{r(a)}),(e=>{isDebugMode&&console.error("write cache error".brightRed,e),r(a)}))}))}))}exports.finderDeploy=finderDeploy,exports.finderUpload=finderUpload;
@@ -1 +0,0 @@
1
- const{finderDeploy:finderDeploy}=require("./core"),path=require("path");require("colors"),module.exports=function(e){let r=null;return{name:"finerDeployAgent",generateBundle({dir:e}){r=process.cwd(),e&&(r=path.resolve(r,e))},async closeBundle(){r?await finderDeploy({preview:!0,archive:path.resolve(path.dirname(r),"archive"),...e,dist:r}).then((function(e){e&&console.log("部署成功".bgGreen,(e.previewUrl||"").green)})):console.error("没有找到部署资源,请尝试检查 build 是否生成了正确的资源".bgRed)}}};
@@ -1 +0,0 @@
1
- const{finderDeploy:finderDeploy}=require("./core"),path=require("path");function finderDeployPlugin({archive:e,deployTo:o,user:i,key:n,preview:r}){this.deployConfig={archive:e,deployTo:o,user:i,key:n,preview:void 0===r||!!r}}require("colors"),finderDeployPlugin.prototype.apply=function(e){const o=this.deployConfig;e.hooks.done.tapAsync("finerDeployAgent",(function({compilation:e},i){const n=o.dist=e.outputOptions.path;o.archive=o.archive||path.resolve(path.dirname(n),"archive"),finderDeploy(o).then((function(e){e&&setTimeout((function(){console.log("部署成功".bgGreen,(e.previewUrl||"").green)})),i()}),i)}))},module.exports=finderDeployPlugin;
package/index.d.ts DELETED
@@ -1,81 +0,0 @@
1
- interface IDeployCoreOptions {
2
- /** 要部署的最终目录,比如 https://xxx.com/test/path/ */
3
- dist?: string;
4
- /** 如果不指定目录,可以指定一个zip文件,指定zip后,dist无效 */
5
- zip?: string,
6
- /** 归档备份的文件名,如果不指定文件名,则按照时间戳命名zip文件 */
7
- archive?: string,
8
- /** 部署目标地址 */
9
- deployTo: string,
10
- /** 部署授权用户名 */
11
- user: string,
12
- /** 部署授权key */
13
- key: string,
14
- /** 是否部署完毕后打开目标文件 */
15
- preview?: boolean
16
- /** 是否调试输出更多信息 */
17
- debug?: boolean
18
- }
19
-
20
- interface IDeployResult {
21
- /** 页面预览地址 */
22
- previewUrl: string
23
- }
24
-
25
- interface IUploadCoreOptions {
26
- /** 需要上传的文件全路径 */
27
- file: string,
28
- /** 部署目标地址 */
29
- deployTo: string,
30
- /** 部署授权用户名 */
31
- user: string,
32
- /** 部署授权key */
33
- key: string,
34
- /** 是否部署完毕后打开目标文件 */
35
- preview?: boolean
36
- }
37
-
38
- interface IVitePlugin {
39
- name: string,
40
- }
41
-
42
- /** 部署内容到 finder 中 */
43
- export declare const finderDeploy: (options: IDeployCoreOptions) => Promise<IDeployResult | void>;
44
-
45
- /** 上传本地文件到 finder */
46
- export declare const finderUpload: (options: IUploadCoreOptions) => Promise<void>;
47
-
48
- /** 部署用插件,支持 webpack 和 vite */
49
- export declare const deployPlugin: {
50
- /** webpack 部署插件 */
51
- webpack: (options: {
52
- /** 归档备份的文件名,如果不指定文件名,则按照时间戳命名zip文件 */
53
- archive?: string,
54
- /** 部署目标地址 */
55
- deployTo: string,
56
- /** 部署授权用户名 */
57
- user: string,
58
- /** 部署授权key */
59
- key: string,
60
- /** 是否部署完毕后打开目标文件 */
61
- preview?: boolean
62
- }) => void,
63
-
64
- /** vite 部署插件 */
65
- vite: (options: {
66
- /** 如果不指定目录,可以指定一个zip文件,指定zip后,dist无效 */
67
- zip?: string,
68
- /** 归档备份的文件名,如果不指定文件名,则按照时间戳命名zip文件 */
69
- archive?: string,
70
- /** 是否调试输出更多信息 */
71
- debug?: boolean,
72
- /** 部署目标地址 */
73
- deployTo: string,
74
- /** 部署授权用户名 */
75
- user: string,
76
- /** 部署授权key */
77
- key: string,
78
- /** 是否部署完毕后打开目标文件 */
79
- preview?: boolean
80
- }) => IVitePlugin;
81
- }
package/index.js DELETED
@@ -1,11 +0,0 @@
1
- const { finderDeploy, finderUpload } = require('./dist/core');
2
- const WebpackDeployPlugin = require('./dist/plugin.webpack');
3
- const ViteDeployPlugin = require('./dist/plugin.vite');
4
-
5
- exports.finderDeploy = finderDeploy;
6
- exports.finderUpload = finderUpload;
7
-
8
- exports.deployPlugin = {
9
- webpack: WebpackDeployPlugin,
10
- vite: ViteDeployPlugin
11
- };