vite-plugin-deploy-oss 3.4.1 → 3.5.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/cli.d.ts ADDED
@@ -0,0 +1 @@
1
+ #!/usr/bin/env node
package/dist/cli.js ADDED
@@ -0,0 +1,156 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ deployOss
4
+ } from "./chunk-6D7VVVXN.js";
5
+
6
+ // src/cli.ts
7
+ import { access, readFile } from "fs/promises";
8
+ import { extname, resolve } from "path";
9
+ import { pathToFileURL } from "url";
10
+ var DEFAULT_CONFIG_FILES = [
11
+ "deploy-oss.config.js",
12
+ "deploy-oss.config.mjs",
13
+ "deploy-oss.config.cjs",
14
+ "deploy-oss.config.json"
15
+ ];
16
+ var helpText = `
17
+ Usage:
18
+ deploy-oss --config deploy-oss.config.mjs
19
+ deploy-oss --outDir dist --uploadDir H5/demo/prod
20
+
21
+ Options:
22
+ --config <path> Config file path
23
+ --outDir <path> Local directory to upload, default dist
24
+ --uploadDir <path> OSS target directory
25
+ --region <region> OSS region
26
+ --bucket <bucket> OSS bucket
27
+ --accessKeyId <value> OSS access key ID
28
+ --accessKeySecret <value>
29
+ --configBase <url> URL base used by manifest
30
+ --alias <url> URL alias used by manifest
31
+ --skip <glob> Glob to skip, can be used multiple times
32
+ --manifest [file] Enable manifest, optional file name
33
+ --concurrency <number> Upload concurrency
34
+ --retryTimes <number> Retry times
35
+ --debug Show debug timing
36
+ --no-fancy Disable styled progress
37
+ --no-cache Set no-cache headers
38
+ --no-overwrite Forbid overwrite
39
+ --no-fail-on-error Do not exit with error on upload failure
40
+ -h, --help Show help
41
+ `.trim();
42
+ var readValue = (args, index, name) => {
43
+ const value = args[index + 1];
44
+ if (!value || value.startsWith("-")) {
45
+ throw new Error(`${name} requires a value`);
46
+ }
47
+ return value;
48
+ };
49
+ var parseArgs = (args) => {
50
+ const option = {};
51
+ let configPath;
52
+ let help = false;
53
+ for (let i = 0; i < args.length; i++) {
54
+ const arg = args[i];
55
+ switch (arg) {
56
+ case "-h":
57
+ case "--help":
58
+ help = true;
59
+ break;
60
+ case "--config":
61
+ configPath = readValue(args, i, arg);
62
+ i++;
63
+ break;
64
+ case "--outDir":
65
+ case "--uploadDir":
66
+ case "--region":
67
+ case "--bucket":
68
+ case "--accessKeyId":
69
+ case "--accessKeySecret":
70
+ case "--configBase":
71
+ case "--alias": {
72
+ const key = arg.slice(2);
73
+ option[key] = readValue(args, i, arg);
74
+ i++;
75
+ break;
76
+ }
77
+ case "--skip": {
78
+ const value = readValue(args, i, arg);
79
+ option.skip = Array.isArray(option.skip) ? [...option.skip, value] : option.skip ? [option.skip, value] : value;
80
+ i++;
81
+ break;
82
+ }
83
+ case "--manifest": {
84
+ const next = args[i + 1];
85
+ if (next && !next.startsWith("-")) {
86
+ option.manifest = { fileName: next };
87
+ i++;
88
+ } else {
89
+ option.manifest = true;
90
+ }
91
+ break;
92
+ }
93
+ case "--debug":
94
+ option.debug = true;
95
+ break;
96
+ case "--no-fancy":
97
+ option.fancy = false;
98
+ break;
99
+ case "--no-cache":
100
+ option.noCache = true;
101
+ break;
102
+ case "--no-overwrite":
103
+ option.overwrite = false;
104
+ break;
105
+ case "--no-fail-on-error":
106
+ option.failOnError = false;
107
+ break;
108
+ case "--concurrency":
109
+ case "--retryTimes":
110
+ case "--multipartThreshold": {
111
+ const key = arg.slice(2);
112
+ option[key] = Number(readValue(args, i, arg));
113
+ i++;
114
+ break;
115
+ }
116
+ default:
117
+ throw new Error(`Unknown option: ${arg}`);
118
+ }
119
+ }
120
+ return { configPath, option, help };
121
+ };
122
+ var findDefaultConfig = async () => {
123
+ for (const file of DEFAULT_CONFIG_FILES) {
124
+ const filePath = resolve(file);
125
+ try {
126
+ await access(filePath);
127
+ return filePath;
128
+ } catch {
129
+ }
130
+ }
131
+ };
132
+ var loadConfig = async (configPath) => {
133
+ const resolvedConfigPath = configPath ? resolve(configPath) : await findDefaultConfig();
134
+ if (!resolvedConfigPath) return {};
135
+ if (extname(resolvedConfigPath) === ".json") {
136
+ return JSON.parse(await readFile(resolvedConfigPath, "utf8"));
137
+ }
138
+ const mod = await import(pathToFileURL(resolvedConfigPath).href);
139
+ return mod.default || mod.deployOss || {};
140
+ };
141
+ var main = async () => {
142
+ const { configPath, option, help } = parseArgs(process.argv.slice(2));
143
+ if (help) {
144
+ console.log(helpText);
145
+ return;
146
+ }
147
+ const config = await loadConfig(configPath);
148
+ await deployOss({
149
+ ...config,
150
+ ...option
151
+ });
152
+ };
153
+ main().catch((error) => {
154
+ console.error(error instanceof Error ? error.message : error);
155
+ process.exitCode = 1;
156
+ });
@@ -0,0 +1,70 @@
1
+ import oss from 'ali-oss';
2
+
3
+ interface ManifestOption {
4
+ fileName?: string;
5
+ }
6
+ type ManifestConfig = boolean | ManifestOption | undefined;
7
+ interface vitePluginDeployOssOption extends Omit<oss.Options, 'accessKeyId' | 'accessKeySecret' | 'bucket' | 'region'> {
8
+ configBase?: string;
9
+ accessKeyId: string;
10
+ accessKeySecret: string;
11
+ region: string;
12
+ secure?: boolean;
13
+ bucket: string;
14
+ overwrite?: boolean;
15
+ uploadDir: string;
16
+ alias?: string;
17
+ autoDelete?: boolean;
18
+ skip?: string | string[];
19
+ open?: boolean;
20
+ debug?: boolean;
21
+ fancy?: boolean;
22
+ noCache?: boolean;
23
+ failOnError?: boolean;
24
+ concurrency?: number;
25
+ retryTimes?: number;
26
+ multipartThreshold?: number;
27
+ manifest?: ManifestConfig;
28
+ }
29
+ interface DeployOssOption extends vitePluginDeployOssOption {
30
+ outDir?: string;
31
+ }
32
+ interface DeployOssResult {
33
+ success: boolean;
34
+ results: UploadResult[];
35
+ outDir: string;
36
+ durationSeconds: number;
37
+ uploadedBytes: number;
38
+ retryCount: number;
39
+ manifestUrl?: string;
40
+ }
41
+ interface UploadResult {
42
+ success: boolean;
43
+ file: string;
44
+ relativeFilePath: string;
45
+ name: string;
46
+ size: number;
47
+ retries: number;
48
+ error?: Error;
49
+ }
50
+ interface UploadTask {
51
+ filePath: string;
52
+ relativeFilePath: string;
53
+ name: string;
54
+ size: number;
55
+ cacheControl?: string;
56
+ }
57
+ interface ManifestFileItem {
58
+ file: string;
59
+ key: string;
60
+ url: string;
61
+ md5: string;
62
+ }
63
+ interface ManifestPayload {
64
+ version: number;
65
+ files: ManifestFileItem[];
66
+ }
67
+
68
+ declare const deployOss: (option: DeployOssOption) => Promise<DeployOssResult>;
69
+
70
+ export { type DeployOssOption as D, type ManifestConfig as M, type UploadResult as U, type DeployOssResult as a, type ManifestFileItem as b, type ManifestOption as c, type ManifestPayload as d, type UploadTask as e, deployOss as f, type vitePluginDeployOssOption as v };
@@ -0,0 +1,2 @@
1
+ export { f as deployOss } from './deploy-slMJUcSr.js';
2
+ import 'ali-oss';
package/dist/deploy.js ADDED
@@ -0,0 +1,6 @@
1
+ import {
2
+ deployOss
3
+ } from "./chunk-6D7VVVXN.js";
4
+ export {
5
+ deployOss
6
+ };
package/dist/index.d.ts CHANGED
@@ -1,59 +1,10 @@
1
1
  import { Plugin } from 'vite';
2
- import oss from 'ali-oss';
2
+ import { v as vitePluginDeployOssOption, D as DeployOssOption } from './deploy-slMJUcSr.js';
3
+ export { a as DeployOssResult, M as ManifestConfig, b as ManifestFileItem, c as ManifestOption, d as ManifestPayload, U as UploadResult, e as UploadTask, f as deployOss } from './deploy-slMJUcSr.js';
4
+ import 'ali-oss';
3
5
 
4
- interface ManifestOption {
5
- fileName?: string;
6
- }
7
- type ManifestConfig = boolean | ManifestOption | undefined;
8
- interface vitePluginDeployOssOption extends Omit<oss.Options, 'accessKeyId' | 'accessKeySecret' | 'bucket' | 'region'> {
9
- configBase?: string;
10
- accessKeyId: string;
11
- accessKeySecret: string;
12
- region: string;
13
- secure?: boolean;
14
- bucket: string;
15
- overwrite?: boolean;
16
- uploadDir: string;
17
- alias?: string;
18
- autoDelete?: boolean;
19
- skip?: string | string[];
20
- open?: boolean;
21
- debug?: boolean;
22
- fancy?: boolean;
23
- noCache?: boolean;
24
- failOnError?: boolean;
25
- concurrency?: number;
26
- retryTimes?: number;
27
- multipartThreshold?: number;
28
- manifest?: ManifestConfig;
29
- }
30
- interface UploadResult {
31
- success: boolean;
32
- file: string;
33
- relativeFilePath: string;
34
- name: string;
35
- size: number;
36
- retries: number;
37
- error?: Error;
38
- }
39
- interface UploadTask {
40
- filePath: string;
41
- relativeFilePath: string;
42
- name: string;
43
- size: number;
44
- cacheControl?: string;
45
- }
46
- interface ManifestFileItem {
47
- file: string;
48
- key: string;
49
- url: string;
50
- md5: string;
51
- }
52
- interface ManifestPayload {
53
- version: number;
54
- files: ManifestFileItem[];
55
- }
6
+ declare const defineDeployConfig: (option: DeployOssOption) => DeployOssOption;
56
7
 
57
8
  declare function vitePluginDeployOss(option: vitePluginDeployOssOption): Plugin;
58
9
 
59
- export { type ManifestConfig, type ManifestFileItem, type ManifestOption, type ManifestPayload, type UploadResult, type UploadTask, vitePluginDeployOss as default, type vitePluginDeployOssOption };
10
+ export { DeployOssOption, vitePluginDeployOss as default, defineDeployConfig, vitePluginDeployOssOption };