@meng-xi/vite-plugin 0.1.0 → 0.1.2
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/README-en.md +264 -533
- package/README.md +253 -522
- package/dist/common/format/index.cjs +1 -0
- package/dist/common/format/index.d.cts +156 -0
- package/dist/common/format/index.d.mts +156 -0
- package/dist/common/format/index.d.ts +156 -0
- package/dist/common/format/index.mjs +1 -0
- package/dist/common/fs/index.cjs +1 -0
- package/dist/common/fs/index.d.cts +150 -0
- package/dist/common/fs/index.d.mts +150 -0
- package/dist/common/fs/index.d.ts +150 -0
- package/dist/common/fs/index.mjs +1 -0
- package/dist/common/html/index.cjs +2 -0
- package/dist/common/html/index.d.cts +109 -0
- package/dist/common/html/index.d.mts +109 -0
- package/dist/common/html/index.d.ts +109 -0
- package/dist/common/html/index.mjs +2 -0
- package/dist/common/index.cjs +1 -1
- package/dist/common/index.d.cts +7 -417
- package/dist/common/index.d.mts +7 -417
- package/dist/common/index.d.ts +7 -417
- package/dist/common/index.mjs +1 -1
- package/dist/common/object/index.cjs +1 -0
- package/dist/common/object/index.d.cts +30 -0
- package/dist/common/object/index.d.mts +30 -0
- package/dist/common/object/index.d.ts +30 -0
- package/dist/common/object/index.mjs +1 -0
- package/dist/common/script/index.cjs +1 -0
- package/dist/common/script/index.d.cts +54 -0
- package/dist/common/script/index.d.mts +54 -0
- package/dist/common/script/index.d.ts +54 -0
- package/dist/common/script/index.mjs +1 -0
- package/dist/common/validation/index.cjs +1 -0
- package/dist/common/validation/index.d.cts +93 -0
- package/dist/common/validation/index.d.mts +93 -0
- package/dist/common/validation/index.d.ts +93 -0
- package/dist/common/validation/index.mjs +1 -0
- package/dist/factory/index.cjs +1 -1
- package/dist/factory/index.d.cts +1 -1
- package/dist/factory/index.d.mts +1 -1
- package/dist/factory/index.d.ts +1 -1
- package/dist/factory/index.mjs +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +16 -3
- package/dist/index.d.mts +16 -3
- package/dist/index.d.ts +16 -3
- package/dist/index.mjs +1 -1
- package/dist/plugins/buildProgress/index.cjs +2 -0
- package/dist/plugins/buildProgress/index.d.cts +187 -0
- package/dist/plugins/buildProgress/index.d.mts +187 -0
- package/dist/plugins/buildProgress/index.d.ts +187 -0
- package/dist/plugins/buildProgress/index.mjs +2 -0
- package/dist/plugins/compressAssets/index.cjs +1 -0
- package/dist/plugins/compressAssets/index.d.cts +132 -0
- package/dist/plugins/compressAssets/index.d.mts +132 -0
- package/dist/plugins/compressAssets/index.d.ts +132 -0
- package/dist/plugins/compressAssets/index.mjs +1 -0
- package/dist/plugins/copyFile/index.cjs +1 -0
- package/dist/plugins/copyFile/index.d.cts +78 -0
- package/dist/plugins/copyFile/index.d.mts +78 -0
- package/dist/plugins/copyFile/index.d.ts +78 -0
- package/dist/plugins/copyFile/index.mjs +1 -0
- package/dist/plugins/faviconManager/index.cjs +1 -0
- package/dist/plugins/faviconManager/index.d.cts +143 -0
- package/dist/plugins/faviconManager/index.d.mts +143 -0
- package/dist/plugins/faviconManager/index.d.ts +143 -0
- package/dist/plugins/faviconManager/index.mjs +1 -0
- package/dist/plugins/generateRouter/index.cjs +35 -0
- package/dist/plugins/generateRouter/index.d.cts +215 -0
- package/dist/plugins/generateRouter/index.d.mts +215 -0
- package/dist/plugins/generateRouter/index.d.ts +215 -0
- package/dist/plugins/generateRouter/index.mjs +35 -0
- package/dist/plugins/generateVersion/index.cjs +1 -0
- package/dist/plugins/generateVersion/index.d.cts +184 -0
- package/dist/plugins/generateVersion/index.d.mts +184 -0
- package/dist/plugins/generateVersion/index.d.ts +184 -0
- package/dist/plugins/generateVersion/index.mjs +1 -0
- package/dist/plugins/htmlInject/index.cjs +7 -0
- package/dist/plugins/htmlInject/index.d.cts +278 -0
- package/dist/plugins/htmlInject/index.d.mts +278 -0
- package/dist/plugins/htmlInject/index.d.ts +278 -0
- package/dist/plugins/htmlInject/index.mjs +7 -0
- package/dist/plugins/index.cjs +1 -1
- package/dist/plugins/index.d.cts +11 -1714
- package/dist/plugins/index.d.mts +11 -1714
- package/dist/plugins/index.d.ts +11 -1714
- package/dist/plugins/index.mjs +1 -1
- package/dist/plugins/loadingManager/index.cjs +487 -0
- package/dist/plugins/loadingManager/index.d.cts +769 -0
- package/dist/plugins/loadingManager/index.d.mts +769 -0
- package/dist/plugins/loadingManager/index.d.ts +769 -0
- package/dist/plugins/loadingManager/index.mjs +487 -0
- package/dist/plugins/versionUpdateChecker/index.cjs +185 -0
- package/dist/plugins/versionUpdateChecker/index.d.cts +200 -0
- package/dist/plugins/versionUpdateChecker/index.d.mts +200 -0
- package/dist/plugins/versionUpdateChecker/index.d.ts +200 -0
- package/dist/plugins/versionUpdateChecker/index.mjs +185 -0
- package/dist/shared/vite-plugin.Bcg6RW2N.cjs +3 -0
- package/dist/shared/{vite-plugin.CiHfwMiN.d.ts → vite-plugin.DRRlWY8P.d.cts} +50 -0
- package/dist/shared/{vite-plugin.CiHfwMiN.d.cts → vite-plugin.DRRlWY8P.d.mts} +50 -0
- package/dist/shared/{vite-plugin.CiHfwMiN.d.mts → vite-plugin.DRRlWY8P.d.ts} +50 -0
- package/dist/shared/{vite-plugin.B88RyRN8.mjs → vite-plugin.DcExl6jd.mjs} +2 -2
- package/package.json +80 -3
- package/dist/shared/vite-plugin.CawoITTT.cjs +0 -1
- package/dist/shared/vite-plugin.D6Law9Ke.mjs +0 -706
- package/dist/shared/vite-plugin.D8L9KzuW.cjs +0 -706
- package/dist/shared/vite-plugin.DFjf9wFM.mjs +0 -2
- package/dist/shared/vite-plugin.DSb6XzBn.mjs +0 -1
- package/dist/shared/vite-plugin.IGZeStMa.cjs +0 -3
- package/dist/shared/vite-plugin.Tab4qcIM.cjs +0 -2
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 复制操作的选项接口
|
|
3
|
+
*/
|
|
4
|
+
interface CopyOptions {
|
|
5
|
+
/**
|
|
6
|
+
* 是否支持递归复制
|
|
7
|
+
*/
|
|
8
|
+
recursive: boolean;
|
|
9
|
+
/**
|
|
10
|
+
* 是否覆盖同名文件
|
|
11
|
+
*/
|
|
12
|
+
overwrite: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* 是否启用增量复制
|
|
15
|
+
*/
|
|
16
|
+
incremental?: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* 并行处理的最大文件数
|
|
19
|
+
*/
|
|
20
|
+
parallelLimit?: number;
|
|
21
|
+
/**
|
|
22
|
+
* 是否跳过空目录
|
|
23
|
+
*/
|
|
24
|
+
skipEmptyDirs?: boolean;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* 复制结果接口
|
|
28
|
+
*/
|
|
29
|
+
interface CopyResult {
|
|
30
|
+
/**
|
|
31
|
+
* 复制的文件数量
|
|
32
|
+
*/
|
|
33
|
+
copiedFiles: number;
|
|
34
|
+
/**
|
|
35
|
+
* 跳过的文件数量
|
|
36
|
+
*/
|
|
37
|
+
skippedFiles: number;
|
|
38
|
+
/**
|
|
39
|
+
* 复制的目录数量
|
|
40
|
+
*/
|
|
41
|
+
copiedDirs: number;
|
|
42
|
+
/**
|
|
43
|
+
* 总执行时间(毫秒)
|
|
44
|
+
*/
|
|
45
|
+
executionTime: number;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* 文件/目录条目信息
|
|
50
|
+
*/
|
|
51
|
+
interface FileEntry {
|
|
52
|
+
/** 完整路径 */
|
|
53
|
+
path: string;
|
|
54
|
+
/** 是否为文件 */
|
|
55
|
+
isFile: boolean;
|
|
56
|
+
/** 是否为目录 */
|
|
57
|
+
isDirectory: boolean;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* 检查源文件是否存在
|
|
61
|
+
* @param sourcePath 源文件路径
|
|
62
|
+
* @throws 当源文件不存在或无法访问时抛出异常
|
|
63
|
+
*/
|
|
64
|
+
declare function checkSourceExists(sourcePath: string): Promise<void>;
|
|
65
|
+
/**
|
|
66
|
+
* 创建目标目录
|
|
67
|
+
* @param targetPath 目标目录路径
|
|
68
|
+
* @throws 当无法创建目标目录时抛出异常
|
|
69
|
+
*/
|
|
70
|
+
declare function ensureTargetDir(targetPath: string): Promise<void>;
|
|
71
|
+
/**
|
|
72
|
+
* 读取目录内容(优化版:一次性获取文件类型信息)
|
|
73
|
+
* @param dirPath 目录路径
|
|
74
|
+
* @param recursive 是否递归读取
|
|
75
|
+
* @returns 文件和目录条目列表
|
|
76
|
+
*/
|
|
77
|
+
declare function readDirRecursive(dirPath: string, recursive: boolean): Promise<FileEntry[]>;
|
|
78
|
+
/**
|
|
79
|
+
* 检查文件是否需要更新
|
|
80
|
+
* @param sourceFile 源文件路径
|
|
81
|
+
* @param targetFile 目标文件路径
|
|
82
|
+
* @returns 是否需要更新
|
|
83
|
+
*/
|
|
84
|
+
declare function shouldUpdateFile(sourceFile: string, targetFile: string): Promise<boolean>;
|
|
85
|
+
/**
|
|
86
|
+
* 检查文件是否存在
|
|
87
|
+
* @param filePath 文件路径
|
|
88
|
+
* @returns 是否存在
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* ```typescript
|
|
92
|
+
* if (await fileExists('/path/to/file')) {
|
|
93
|
+
* console.log('文件存在')
|
|
94
|
+
* }
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
declare function fileExists(filePath: string): Promise<boolean>;
|
|
98
|
+
/**
|
|
99
|
+
* 带并发限制的批量执行
|
|
100
|
+
*
|
|
101
|
+
* @param items 待处理项
|
|
102
|
+
* @param handler 处理函数
|
|
103
|
+
* @param concurrency 并发数
|
|
104
|
+
* @returns 处理结果数组,顺序与输入项对应
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* ```typescript
|
|
108
|
+
* const urls = ['url1', 'url2', 'url3', 'url4', 'url5']
|
|
109
|
+
* const results = await runWithConcurrency(
|
|
110
|
+
* urls,
|
|
111
|
+
* async (url) => fetch(url),
|
|
112
|
+
* 3 // 最多同时处理3个请求
|
|
113
|
+
* )
|
|
114
|
+
* ```
|
|
115
|
+
*/
|
|
116
|
+
declare function runWithConcurrency<T, R>(items: T[], handler: (item: T) => Promise<R>, concurrency: number): Promise<R[]>;
|
|
117
|
+
/**
|
|
118
|
+
* 执行文件复制操作(优化版:并行IO)
|
|
119
|
+
* @param sourcePath 源文件或目录路径
|
|
120
|
+
* @param targetPath 目标文件或目录路径
|
|
121
|
+
* @param options 复制选项
|
|
122
|
+
* @returns 复制结果
|
|
123
|
+
* @throws 当复制过程中出现错误时抛出异常
|
|
124
|
+
*/
|
|
125
|
+
declare function copySourceToTarget(sourcePath: string, targetPath: string, options: CopyOptions): Promise<CopyResult>;
|
|
126
|
+
/**
|
|
127
|
+
* 写入文件内容
|
|
128
|
+
* @param filePath 文件路径
|
|
129
|
+
* @param content 文件内容
|
|
130
|
+
* @throws 当写入过程中出现错误时抛出异常
|
|
131
|
+
*/
|
|
132
|
+
declare function writeFileContent(filePath: string, content: string): Promise<void>;
|
|
133
|
+
/**
|
|
134
|
+
* 读取文件内容
|
|
135
|
+
* @param filePath 文件路径
|
|
136
|
+
* @returns 文件内容字符串
|
|
137
|
+
* @throws 当读取过程中出现错误时抛出异常
|
|
138
|
+
*/
|
|
139
|
+
declare function readFileContent(filePath: string): Promise<string>;
|
|
140
|
+
/**
|
|
141
|
+
* 同步读取文件内容
|
|
142
|
+
* @param filePath 文件路径
|
|
143
|
+
* @returns 文件内容字符串
|
|
144
|
+
* @throws 当读取过程中出现错误时抛出异常
|
|
145
|
+
* @deprecated 请使用异步版本 readFileContent
|
|
146
|
+
*/
|
|
147
|
+
declare function readFileSync(filePath: string): string;
|
|
148
|
+
|
|
149
|
+
export { checkSourceExists, copySourceToTarget, ensureTargetDir, fileExists, readDirRecursive, readFileContent, readFileSync, runWithConcurrency, shouldUpdateFile, writeFileContent };
|
|
150
|
+
export type { CopyOptions, CopyResult };
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 复制操作的选项接口
|
|
3
|
+
*/
|
|
4
|
+
interface CopyOptions {
|
|
5
|
+
/**
|
|
6
|
+
* 是否支持递归复制
|
|
7
|
+
*/
|
|
8
|
+
recursive: boolean;
|
|
9
|
+
/**
|
|
10
|
+
* 是否覆盖同名文件
|
|
11
|
+
*/
|
|
12
|
+
overwrite: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* 是否启用增量复制
|
|
15
|
+
*/
|
|
16
|
+
incremental?: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* 并行处理的最大文件数
|
|
19
|
+
*/
|
|
20
|
+
parallelLimit?: number;
|
|
21
|
+
/**
|
|
22
|
+
* 是否跳过空目录
|
|
23
|
+
*/
|
|
24
|
+
skipEmptyDirs?: boolean;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* 复制结果接口
|
|
28
|
+
*/
|
|
29
|
+
interface CopyResult {
|
|
30
|
+
/**
|
|
31
|
+
* 复制的文件数量
|
|
32
|
+
*/
|
|
33
|
+
copiedFiles: number;
|
|
34
|
+
/**
|
|
35
|
+
* 跳过的文件数量
|
|
36
|
+
*/
|
|
37
|
+
skippedFiles: number;
|
|
38
|
+
/**
|
|
39
|
+
* 复制的目录数量
|
|
40
|
+
*/
|
|
41
|
+
copiedDirs: number;
|
|
42
|
+
/**
|
|
43
|
+
* 总执行时间(毫秒)
|
|
44
|
+
*/
|
|
45
|
+
executionTime: number;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* 文件/目录条目信息
|
|
50
|
+
*/
|
|
51
|
+
interface FileEntry {
|
|
52
|
+
/** 完整路径 */
|
|
53
|
+
path: string;
|
|
54
|
+
/** 是否为文件 */
|
|
55
|
+
isFile: boolean;
|
|
56
|
+
/** 是否为目录 */
|
|
57
|
+
isDirectory: boolean;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* 检查源文件是否存在
|
|
61
|
+
* @param sourcePath 源文件路径
|
|
62
|
+
* @throws 当源文件不存在或无法访问时抛出异常
|
|
63
|
+
*/
|
|
64
|
+
declare function checkSourceExists(sourcePath: string): Promise<void>;
|
|
65
|
+
/**
|
|
66
|
+
* 创建目标目录
|
|
67
|
+
* @param targetPath 目标目录路径
|
|
68
|
+
* @throws 当无法创建目标目录时抛出异常
|
|
69
|
+
*/
|
|
70
|
+
declare function ensureTargetDir(targetPath: string): Promise<void>;
|
|
71
|
+
/**
|
|
72
|
+
* 读取目录内容(优化版:一次性获取文件类型信息)
|
|
73
|
+
* @param dirPath 目录路径
|
|
74
|
+
* @param recursive 是否递归读取
|
|
75
|
+
* @returns 文件和目录条目列表
|
|
76
|
+
*/
|
|
77
|
+
declare function readDirRecursive(dirPath: string, recursive: boolean): Promise<FileEntry[]>;
|
|
78
|
+
/**
|
|
79
|
+
* 检查文件是否需要更新
|
|
80
|
+
* @param sourceFile 源文件路径
|
|
81
|
+
* @param targetFile 目标文件路径
|
|
82
|
+
* @returns 是否需要更新
|
|
83
|
+
*/
|
|
84
|
+
declare function shouldUpdateFile(sourceFile: string, targetFile: string): Promise<boolean>;
|
|
85
|
+
/**
|
|
86
|
+
* 检查文件是否存在
|
|
87
|
+
* @param filePath 文件路径
|
|
88
|
+
* @returns 是否存在
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* ```typescript
|
|
92
|
+
* if (await fileExists('/path/to/file')) {
|
|
93
|
+
* console.log('文件存在')
|
|
94
|
+
* }
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
declare function fileExists(filePath: string): Promise<boolean>;
|
|
98
|
+
/**
|
|
99
|
+
* 带并发限制的批量执行
|
|
100
|
+
*
|
|
101
|
+
* @param items 待处理项
|
|
102
|
+
* @param handler 处理函数
|
|
103
|
+
* @param concurrency 并发数
|
|
104
|
+
* @returns 处理结果数组,顺序与输入项对应
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* ```typescript
|
|
108
|
+
* const urls = ['url1', 'url2', 'url3', 'url4', 'url5']
|
|
109
|
+
* const results = await runWithConcurrency(
|
|
110
|
+
* urls,
|
|
111
|
+
* async (url) => fetch(url),
|
|
112
|
+
* 3 // 最多同时处理3个请求
|
|
113
|
+
* )
|
|
114
|
+
* ```
|
|
115
|
+
*/
|
|
116
|
+
declare function runWithConcurrency<T, R>(items: T[], handler: (item: T) => Promise<R>, concurrency: number): Promise<R[]>;
|
|
117
|
+
/**
|
|
118
|
+
* 执行文件复制操作(优化版:并行IO)
|
|
119
|
+
* @param sourcePath 源文件或目录路径
|
|
120
|
+
* @param targetPath 目标文件或目录路径
|
|
121
|
+
* @param options 复制选项
|
|
122
|
+
* @returns 复制结果
|
|
123
|
+
* @throws 当复制过程中出现错误时抛出异常
|
|
124
|
+
*/
|
|
125
|
+
declare function copySourceToTarget(sourcePath: string, targetPath: string, options: CopyOptions): Promise<CopyResult>;
|
|
126
|
+
/**
|
|
127
|
+
* 写入文件内容
|
|
128
|
+
* @param filePath 文件路径
|
|
129
|
+
* @param content 文件内容
|
|
130
|
+
* @throws 当写入过程中出现错误时抛出异常
|
|
131
|
+
*/
|
|
132
|
+
declare function writeFileContent(filePath: string, content: string): Promise<void>;
|
|
133
|
+
/**
|
|
134
|
+
* 读取文件内容
|
|
135
|
+
* @param filePath 文件路径
|
|
136
|
+
* @returns 文件内容字符串
|
|
137
|
+
* @throws 当读取过程中出现错误时抛出异常
|
|
138
|
+
*/
|
|
139
|
+
declare function readFileContent(filePath: string): Promise<string>;
|
|
140
|
+
/**
|
|
141
|
+
* 同步读取文件内容
|
|
142
|
+
* @param filePath 文件路径
|
|
143
|
+
* @returns 文件内容字符串
|
|
144
|
+
* @throws 当读取过程中出现错误时抛出异常
|
|
145
|
+
* @deprecated 请使用异步版本 readFileContent
|
|
146
|
+
*/
|
|
147
|
+
declare function readFileSync(filePath: string): string;
|
|
148
|
+
|
|
149
|
+
export { checkSourceExists, copySourceToTarget, ensureTargetDir, fileExists, readDirRecursive, readFileContent, readFileSync, runWithConcurrency, shouldUpdateFile, writeFileContent };
|
|
150
|
+
export type { CopyOptions, CopyResult };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import s from"fs";import E from"path";const k=10;async function v(u){try{await s.promises.access(u,s.constants.F_OK)}catch(t){const r=t;throw r.code==="ENOENT"?new Error(`\u590D\u5236\u6587\u4EF6\u5931\u8D25\uFF1A\u6E90\u6587\u4EF6\u4E0D\u5B58\u5728 - ${u}`):r.code==="EACCES"?new Error(`\u590D\u5236\u6587\u4EF6\u5931\u8D25\uFF1A\u6CA1\u6709\u6743\u9650\u8BBF\u95EE\u6E90\u6587\u4EF6 - ${u}`):new Error(`\u590D\u5236\u6587\u4EF6\u5931\u8D25\uFF1A\u68C0\u67E5\u6E90\u6587\u4EF6\u65F6\u51FA\u9519 - ${u}\uFF0C\u9519\u8BEF\uFF1A${r.message}`)}}async function m(u){try{await s.promises.mkdir(u,{recursive:!0})}catch(t){const r=t;throw r.code==="EACCES"?new Error(`\u590D\u5236\u6587\u4EF6\u5931\u8D25\uFF1A\u6CA1\u6709\u6743\u9650\u521B\u5EFA\u76EE\u6807\u76EE\u5F55 - ${u}`):new Error(`\u590D\u5236\u6587\u4EF6\u5931\u8D25\uFF1A\u521B\u5EFA\u76EE\u6807\u76EE\u5F55\u65F6\u51FA\u9519 - ${u}\uFF0C\u9519\u8BEF\uFF1A${r.message}`)}}async function D(u,t){const r=await s.promises.readdir(u,{withFileTypes:!0}),e=[];for(const a of r){const o=E.join(u,a.name),l=a.isFile(),F=a.isDirectory();if(e.push({path:o,isFile:l,isDirectory:F}),F&&t){const c=await D(o,t);e.push(...c)}}return e}async function y(u,t){try{const[r,e]=await Promise.all([s.promises.stat(u),s.promises.stat(t)]);return r.mtimeMs>e.mtimeMs||r.size!==e.size}catch{return!0}}async function d(u){try{return await s.promises.access(u,s.constants.F_OK),!0}catch{return!1}}async function $(u,t,r){const e=[];let a=0;async function o(){for(;a<u.length;){const F=a++,c=await t(u[F]);e[F]=c}}const l=Array(Math.min(r,u.length)).fill(null).map(()=>o());return await Promise.all(l),e}async function T(u,t,r){const e=Date.now(),{recursive:a,overwrite:o,incremental:l=!1,parallelLimit:F=k}=r;let c=0,f=0,h=0;if((await s.promises.stat(u)).isDirectory()){await m(t);const n=await D(u,a),B=n.filter(i=>i.isFile);h=n.filter(i=>i.isDirectory).length;const C=new Set;for(const i of B){const A=E.relative(u,i.path),w=E.dirname(E.join(t,A));C.add(w)}await Promise.all([...C].map(i=>m(i)));const S=await $(B,async i=>{const A=E.relative(u,i.path),w=E.join(t,A);let p=o;return p||(p=!await d(w)),l&&p&&(p=await y(i.path,w)),p?(await s.promises.copyFile(i.path,w),{copied:!0,skipped:!1}):{copied:!1,skipped:!0}},F);for(const i of S)i.copied&&c++,i.skipped&&f++}else{await m(E.dirname(t));let n=o;n||(n=!await d(t)),l&&n&&(n=await y(u,t)),n?(await s.promises.copyFile(u,t),c++):f++}const g=Date.now()-e;return{copiedFiles:c,skippedFiles:f,copiedDirs:h,executionTime:g}}async function x(u,t){try{await s.promises.writeFile(u,t,"utf-8")}catch(r){const e=r;throw e.code==="EACCES"?new Error(`\u5199\u5165\u6587\u4EF6\u5931\u8D25\uFF1A\u6CA1\u6709\u6743\u9650\u5199\u5165\u6587\u4EF6 - ${u}`):new Error(`\u5199\u5165\u6587\u4EF6\u5931\u8D25\uFF1A\u5199\u5165\u6587\u4EF6\u65F6\u51FA\u9519 - ${u}\uFF0C\u9519\u8BEF\uFF1A${e.message}`)}}async function j(u){try{return await s.promises.readFile(u,"utf-8")}catch(t){const r=t;throw r.code==="EACCES"?new Error(`\u8BFB\u53D6\u6587\u4EF6\u5931\u8D25\uFF1A\u6CA1\u6709\u6743\u9650\u8BFB\u53D6\u6587\u4EF6 - ${u}`):new Error(`\u8BFB\u53D6\u6587\u4EF6\u5931\u8D25\uFF1A\u8BFB\u53D6\u6587\u4EF6\u65F6\u51FA\u9519 - ${u}\uFF0C\u9519\u8BEF\uFF1A${r.message}`)}}function M(u){try{return s.readFileSync(u,"utf-8")}catch(t){const r=t;throw r.code==="EACCES"?new Error(`\u8BFB\u53D6\u6587\u4EF6\u5931\u8D25\uFF1A\u6CA1\u6709\u6743\u9650\u8BFB\u53D6\u6587\u4EF6 - ${u}`):new Error(`\u8BFB\u53D6\u6587\u4EF6\u5931\u8D25\uFF1A\u8BFB\u53D6\u6587\u4EF6\u65F6\u51FA\u9519 - ${u}\uFF0C\u9519\u8BEF\uFF1A${r.message}`)}}export{v as checkSourceExists,T as copySourceToTarget,m as ensureTargetDir,d as fileExists,D as readDirRecursive,j as readFileContent,M as readFileSync,$ as runWithConcurrency,y as shouldUpdateFile,x as writeFileContent};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";function injectBeforeTag(e,t,l){const n=new RegExp(t,"i");return n.test(e)?{html:e.replace(n,`${l}
|
|
2
|
+
${t}`),injected:!0}:{html:e,injected:!1}}function injectHtmlByPriority(e,t,l=["</head>","</body>","</html>"]){for(const n of l){const c=injectBeforeTag(e,n,t);if(c.injected)return c}return{html:e+t,injected:!0}}function injectBeforeTagWithFallback(e,t,l){const n=injectBeforeTag(e,"</body>",t);if(n.injected)return{...n,usedFallback:!1};const c=injectBeforeTag(e,"</html>",t);return c.injected?{...c,usedFallback:!1}:{html:e+t,injected:!0,usedFallback:!0}}function injectHeadAndBody(e,t,l){let n=e,c=!1;if(t){const i=injectBeforeTag(n,"</head>",t);i.injected&&(n=i.html,c=!0)}const r=injectBeforeTagWithFallback(n,l);return{html:r.html,headInjected:c,bodyInjected:r.injected,usedFallback:r.usedFallback}}exports.injectBeforeTag=injectBeforeTag,exports.injectBeforeTagWithFallback=injectBeforeTagWithFallback,exports.injectHeadAndBody=injectHeadAndBody,exports.injectHtmlByPriority=injectHtmlByPriority;
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTML 注入结果
|
|
3
|
+
*/
|
|
4
|
+
interface HtmlInjectResult {
|
|
5
|
+
/** 注入后的 HTML 内容 */
|
|
6
|
+
html: string;
|
|
7
|
+
/** 是否成功注入 */
|
|
8
|
+
injected: boolean;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* 双区域 HTML 注入结果
|
|
12
|
+
*/
|
|
13
|
+
interface DualInjectResult {
|
|
14
|
+
/** 注入后的 HTML 内容 */
|
|
15
|
+
html: string;
|
|
16
|
+
/** head 区域是否成功注入 */
|
|
17
|
+
headInjected: boolean;
|
|
18
|
+
/** body 区域是否成功注入 */
|
|
19
|
+
bodyInjected: boolean;
|
|
20
|
+
/** body 注入是否使用了回退策略(追加到末尾) */
|
|
21
|
+
usedFallback: boolean;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* 在 HTML 中指定闭合标签前注入代码
|
|
26
|
+
*
|
|
27
|
+
* @param html - 原始 HTML 内容
|
|
28
|
+
* @param tag - 目标闭合标签(如 `</head>`、`</body>`、`</html>`)
|
|
29
|
+
* @param code - 要注入的代码
|
|
30
|
+
* @returns 注入结果对象
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* // 在 </head> 前注入 CSS
|
|
35
|
+
* const result = injectBeforeTag(html, '</head>', '<style>...</style>')
|
|
36
|
+
*
|
|
37
|
+
* // 在 </body> 前注入 JS
|
|
38
|
+
* const result = injectBeforeTag(html, '</body>', '<script>...</script>')
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
declare function injectBeforeTag(html: string, tag: string, code: string): HtmlInjectResult;
|
|
42
|
+
/**
|
|
43
|
+
* 按优先级向 HTML 中注入代码
|
|
44
|
+
*
|
|
45
|
+
* @description 依次尝试在 `</head>`、`</body>`、`</html>` 前注入代码,
|
|
46
|
+
* 优先注入到靠前的标签位置。适用于需要注入到页面中但无特定位置要求的场景
|
|
47
|
+
*
|
|
48
|
+
* @param html - 原始 HTML 内容
|
|
49
|
+
* @param code - 要注入的代码
|
|
50
|
+
* @param targets - 目标标签优先级列表,默认为 `['</head>', '</body>', '</html>']`
|
|
51
|
+
* @returns 注入结果对象
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```typescript
|
|
55
|
+
* // 优先注入到 </body> 前
|
|
56
|
+
* const result = injectHtmlByPriority(html, scriptCode, ['</body>', '</html>'])
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
declare function injectHtmlByPriority(html: string, code: string, targets?: string[]): HtmlInjectResult;
|
|
60
|
+
/**
|
|
61
|
+
* 带回退策略的 HTML 注入
|
|
62
|
+
*
|
|
63
|
+
* @description 依次尝试在 `</body>`、`</html>` 前注入代码,
|
|
64
|
+
* 如果均未找到目标标签,则将代码追加到 HTML 末尾。
|
|
65
|
+
* 适用于需要注入到页面底部但不确定 HTML 结构是否完整的场景。
|
|
66
|
+
*
|
|
67
|
+
* @param html - 原始 HTML 内容
|
|
68
|
+
* @param code - 要注入的代码
|
|
69
|
+
* @param fallbackMessage - 回退到末尾时的警告信息,为空则不输出警告
|
|
70
|
+
* @returns 注入结果对象,包含注入后的 HTML、是否成功标志和是否使用了回退策略
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```typescript
|
|
74
|
+
* // 注入 JS 脚本到页面底部
|
|
75
|
+
* const result = injectBeforeTagWithFallback(html, '<script>...</script>')
|
|
76
|
+
*
|
|
77
|
+
* // 带自定义警告信息
|
|
78
|
+
* const result = injectBeforeTagWithFallback(html, scriptCode, '未找到 </body> 标签,代码追加到文件末尾')
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
declare function injectBeforeTagWithFallback(html: string, code: string, _fallbackMessage?: string): HtmlInjectResult & {
|
|
82
|
+
usedFallback: boolean;
|
|
83
|
+
};
|
|
84
|
+
/**
|
|
85
|
+
* 双区域 HTML 注入(head + body)
|
|
86
|
+
*
|
|
87
|
+
* @description 将代码分别注入到 HTML 的 `</head>` 前和 `</body>` 前(带回退策略)。
|
|
88
|
+
* 这是插件中常见的注入模式:CSS/HTML 注入到 head,JS 注入到 body。
|
|
89
|
+
*
|
|
90
|
+
* @param html - 原始 HTML 内容
|
|
91
|
+
* @param headCode - 注入到 `</head>` 前的代码(如 CSS、meta 标签),不提供则跳过 head 注入
|
|
92
|
+
* @param bodyCode - 注入到 `</body>` 前的代码(如 JS 脚本),回退到 `</html>` 前或末尾
|
|
93
|
+
* @returns 双区域注入结果对象
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```typescript
|
|
97
|
+
* // CSS 注入到 head,JS 注入到 body
|
|
98
|
+
* const result = injectHeadAndBody(html, '<style>...</style>', '<script>...</script>')
|
|
99
|
+
* if (!result.headInjected) logger.warn('未找到 </head> 标签')
|
|
100
|
+
* if (result.usedFallback) logger.warn('代码追加到文件末尾')
|
|
101
|
+
*
|
|
102
|
+
* // 仅注入到 body
|
|
103
|
+
* const result = injectHeadAndBody(html, undefined, '<script>...</script>')
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
declare function injectHeadAndBody(html: string, headCode: string | undefined, bodyCode: string): DualInjectResult;
|
|
107
|
+
|
|
108
|
+
export { injectBeforeTag, injectBeforeTagWithFallback, injectHeadAndBody, injectHtmlByPriority };
|
|
109
|
+
export type { DualInjectResult, HtmlInjectResult };
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTML 注入结果
|
|
3
|
+
*/
|
|
4
|
+
interface HtmlInjectResult {
|
|
5
|
+
/** 注入后的 HTML 内容 */
|
|
6
|
+
html: string;
|
|
7
|
+
/** 是否成功注入 */
|
|
8
|
+
injected: boolean;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* 双区域 HTML 注入结果
|
|
12
|
+
*/
|
|
13
|
+
interface DualInjectResult {
|
|
14
|
+
/** 注入后的 HTML 内容 */
|
|
15
|
+
html: string;
|
|
16
|
+
/** head 区域是否成功注入 */
|
|
17
|
+
headInjected: boolean;
|
|
18
|
+
/** body 区域是否成功注入 */
|
|
19
|
+
bodyInjected: boolean;
|
|
20
|
+
/** body 注入是否使用了回退策略(追加到末尾) */
|
|
21
|
+
usedFallback: boolean;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* 在 HTML 中指定闭合标签前注入代码
|
|
26
|
+
*
|
|
27
|
+
* @param html - 原始 HTML 内容
|
|
28
|
+
* @param tag - 目标闭合标签(如 `</head>`、`</body>`、`</html>`)
|
|
29
|
+
* @param code - 要注入的代码
|
|
30
|
+
* @returns 注入结果对象
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* // 在 </head> 前注入 CSS
|
|
35
|
+
* const result = injectBeforeTag(html, '</head>', '<style>...</style>')
|
|
36
|
+
*
|
|
37
|
+
* // 在 </body> 前注入 JS
|
|
38
|
+
* const result = injectBeforeTag(html, '</body>', '<script>...</script>')
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
declare function injectBeforeTag(html: string, tag: string, code: string): HtmlInjectResult;
|
|
42
|
+
/**
|
|
43
|
+
* 按优先级向 HTML 中注入代码
|
|
44
|
+
*
|
|
45
|
+
* @description 依次尝试在 `</head>`、`</body>`、`</html>` 前注入代码,
|
|
46
|
+
* 优先注入到靠前的标签位置。适用于需要注入到页面中但无特定位置要求的场景
|
|
47
|
+
*
|
|
48
|
+
* @param html - 原始 HTML 内容
|
|
49
|
+
* @param code - 要注入的代码
|
|
50
|
+
* @param targets - 目标标签优先级列表,默认为 `['</head>', '</body>', '</html>']`
|
|
51
|
+
* @returns 注入结果对象
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```typescript
|
|
55
|
+
* // 优先注入到 </body> 前
|
|
56
|
+
* const result = injectHtmlByPriority(html, scriptCode, ['</body>', '</html>'])
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
declare function injectHtmlByPriority(html: string, code: string, targets?: string[]): HtmlInjectResult;
|
|
60
|
+
/**
|
|
61
|
+
* 带回退策略的 HTML 注入
|
|
62
|
+
*
|
|
63
|
+
* @description 依次尝试在 `</body>`、`</html>` 前注入代码,
|
|
64
|
+
* 如果均未找到目标标签,则将代码追加到 HTML 末尾。
|
|
65
|
+
* 适用于需要注入到页面底部但不确定 HTML 结构是否完整的场景。
|
|
66
|
+
*
|
|
67
|
+
* @param html - 原始 HTML 内容
|
|
68
|
+
* @param code - 要注入的代码
|
|
69
|
+
* @param fallbackMessage - 回退到末尾时的警告信息,为空则不输出警告
|
|
70
|
+
* @returns 注入结果对象,包含注入后的 HTML、是否成功标志和是否使用了回退策略
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```typescript
|
|
74
|
+
* // 注入 JS 脚本到页面底部
|
|
75
|
+
* const result = injectBeforeTagWithFallback(html, '<script>...</script>')
|
|
76
|
+
*
|
|
77
|
+
* // 带自定义警告信息
|
|
78
|
+
* const result = injectBeforeTagWithFallback(html, scriptCode, '未找到 </body> 标签,代码追加到文件末尾')
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
declare function injectBeforeTagWithFallback(html: string, code: string, _fallbackMessage?: string): HtmlInjectResult & {
|
|
82
|
+
usedFallback: boolean;
|
|
83
|
+
};
|
|
84
|
+
/**
|
|
85
|
+
* 双区域 HTML 注入(head + body)
|
|
86
|
+
*
|
|
87
|
+
* @description 将代码分别注入到 HTML 的 `</head>` 前和 `</body>` 前(带回退策略)。
|
|
88
|
+
* 这是插件中常见的注入模式:CSS/HTML 注入到 head,JS 注入到 body。
|
|
89
|
+
*
|
|
90
|
+
* @param html - 原始 HTML 内容
|
|
91
|
+
* @param headCode - 注入到 `</head>` 前的代码(如 CSS、meta 标签),不提供则跳过 head 注入
|
|
92
|
+
* @param bodyCode - 注入到 `</body>` 前的代码(如 JS 脚本),回退到 `</html>` 前或末尾
|
|
93
|
+
* @returns 双区域注入结果对象
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```typescript
|
|
97
|
+
* // CSS 注入到 head,JS 注入到 body
|
|
98
|
+
* const result = injectHeadAndBody(html, '<style>...</style>', '<script>...</script>')
|
|
99
|
+
* if (!result.headInjected) logger.warn('未找到 </head> 标签')
|
|
100
|
+
* if (result.usedFallback) logger.warn('代码追加到文件末尾')
|
|
101
|
+
*
|
|
102
|
+
* // 仅注入到 body
|
|
103
|
+
* const result = injectHeadAndBody(html, undefined, '<script>...</script>')
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
declare function injectHeadAndBody(html: string, headCode: string | undefined, bodyCode: string): DualInjectResult;
|
|
107
|
+
|
|
108
|
+
export { injectBeforeTag, injectBeforeTagWithFallback, injectHeadAndBody, injectHtmlByPriority };
|
|
109
|
+
export type { DualInjectResult, HtmlInjectResult };
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTML 注入结果
|
|
3
|
+
*/
|
|
4
|
+
interface HtmlInjectResult {
|
|
5
|
+
/** 注入后的 HTML 内容 */
|
|
6
|
+
html: string;
|
|
7
|
+
/** 是否成功注入 */
|
|
8
|
+
injected: boolean;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* 双区域 HTML 注入结果
|
|
12
|
+
*/
|
|
13
|
+
interface DualInjectResult {
|
|
14
|
+
/** 注入后的 HTML 内容 */
|
|
15
|
+
html: string;
|
|
16
|
+
/** head 区域是否成功注入 */
|
|
17
|
+
headInjected: boolean;
|
|
18
|
+
/** body 区域是否成功注入 */
|
|
19
|
+
bodyInjected: boolean;
|
|
20
|
+
/** body 注入是否使用了回退策略(追加到末尾) */
|
|
21
|
+
usedFallback: boolean;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* 在 HTML 中指定闭合标签前注入代码
|
|
26
|
+
*
|
|
27
|
+
* @param html - 原始 HTML 内容
|
|
28
|
+
* @param tag - 目标闭合标签(如 `</head>`、`</body>`、`</html>`)
|
|
29
|
+
* @param code - 要注入的代码
|
|
30
|
+
* @returns 注入结果对象
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* // 在 </head> 前注入 CSS
|
|
35
|
+
* const result = injectBeforeTag(html, '</head>', '<style>...</style>')
|
|
36
|
+
*
|
|
37
|
+
* // 在 </body> 前注入 JS
|
|
38
|
+
* const result = injectBeforeTag(html, '</body>', '<script>...</script>')
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
declare function injectBeforeTag(html: string, tag: string, code: string): HtmlInjectResult;
|
|
42
|
+
/**
|
|
43
|
+
* 按优先级向 HTML 中注入代码
|
|
44
|
+
*
|
|
45
|
+
* @description 依次尝试在 `</head>`、`</body>`、`</html>` 前注入代码,
|
|
46
|
+
* 优先注入到靠前的标签位置。适用于需要注入到页面中但无特定位置要求的场景
|
|
47
|
+
*
|
|
48
|
+
* @param html - 原始 HTML 内容
|
|
49
|
+
* @param code - 要注入的代码
|
|
50
|
+
* @param targets - 目标标签优先级列表,默认为 `['</head>', '</body>', '</html>']`
|
|
51
|
+
* @returns 注入结果对象
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```typescript
|
|
55
|
+
* // 优先注入到 </body> 前
|
|
56
|
+
* const result = injectHtmlByPriority(html, scriptCode, ['</body>', '</html>'])
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
declare function injectHtmlByPriority(html: string, code: string, targets?: string[]): HtmlInjectResult;
|
|
60
|
+
/**
|
|
61
|
+
* 带回退策略的 HTML 注入
|
|
62
|
+
*
|
|
63
|
+
* @description 依次尝试在 `</body>`、`</html>` 前注入代码,
|
|
64
|
+
* 如果均未找到目标标签,则将代码追加到 HTML 末尾。
|
|
65
|
+
* 适用于需要注入到页面底部但不确定 HTML 结构是否完整的场景。
|
|
66
|
+
*
|
|
67
|
+
* @param html - 原始 HTML 内容
|
|
68
|
+
* @param code - 要注入的代码
|
|
69
|
+
* @param fallbackMessage - 回退到末尾时的警告信息,为空则不输出警告
|
|
70
|
+
* @returns 注入结果对象,包含注入后的 HTML、是否成功标志和是否使用了回退策略
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```typescript
|
|
74
|
+
* // 注入 JS 脚本到页面底部
|
|
75
|
+
* const result = injectBeforeTagWithFallback(html, '<script>...</script>')
|
|
76
|
+
*
|
|
77
|
+
* // 带自定义警告信息
|
|
78
|
+
* const result = injectBeforeTagWithFallback(html, scriptCode, '未找到 </body> 标签,代码追加到文件末尾')
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
declare function injectBeforeTagWithFallback(html: string, code: string, _fallbackMessage?: string): HtmlInjectResult & {
|
|
82
|
+
usedFallback: boolean;
|
|
83
|
+
};
|
|
84
|
+
/**
|
|
85
|
+
* 双区域 HTML 注入(head + body)
|
|
86
|
+
*
|
|
87
|
+
* @description 将代码分别注入到 HTML 的 `</head>` 前和 `</body>` 前(带回退策略)。
|
|
88
|
+
* 这是插件中常见的注入模式:CSS/HTML 注入到 head,JS 注入到 body。
|
|
89
|
+
*
|
|
90
|
+
* @param html - 原始 HTML 内容
|
|
91
|
+
* @param headCode - 注入到 `</head>` 前的代码(如 CSS、meta 标签),不提供则跳过 head 注入
|
|
92
|
+
* @param bodyCode - 注入到 `</body>` 前的代码(如 JS 脚本),回退到 `</html>` 前或末尾
|
|
93
|
+
* @returns 双区域注入结果对象
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```typescript
|
|
97
|
+
* // CSS 注入到 head,JS 注入到 body
|
|
98
|
+
* const result = injectHeadAndBody(html, '<style>...</style>', '<script>...</script>')
|
|
99
|
+
* if (!result.headInjected) logger.warn('未找到 </head> 标签')
|
|
100
|
+
* if (result.usedFallback) logger.warn('代码追加到文件末尾')
|
|
101
|
+
*
|
|
102
|
+
* // 仅注入到 body
|
|
103
|
+
* const result = injectHeadAndBody(html, undefined, '<script>...</script>')
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
declare function injectHeadAndBody(html: string, headCode: string | undefined, bodyCode: string): DualInjectResult;
|
|
107
|
+
|
|
108
|
+
export { injectBeforeTag, injectBeforeTagWithFallback, injectHeadAndBody, injectHtmlByPriority };
|
|
109
|
+
export type { DualInjectResult, HtmlInjectResult };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
function d(e,t,l){const n=new RegExp(t,"i");return n.test(e)?{html:e.replace(n,`${l}
|
|
2
|
+
${t}`),injected:!0}:{html:e,injected:!1}}function o(e,t,l=["</head>","</body>","</html>"]){for(const n of l){const c=d(e,n,t);if(c.injected)return c}return{html:e+t,injected:!0}}function a(e,t,l){const n=d(e,"</body>",t);if(n.injected)return{...n,usedFallback:!1};const c=d(e,"</html>",t);return c.injected?{...c,usedFallback:!1}:{html:e+t,injected:!0,usedFallback:!0}}function u(e,t,l){let n=e,c=!1;if(t){const i=d(n,"</head>",t);i.injected&&(n=i.html,c=!0)}const r=a(n,l);return{html:r.html,headInjected:c,bodyInjected:r.injected,usedFallback:r.usedFallback}}export{d as injectBeforeTag,a as injectBeforeTagWithFallback,u as injectHeadAndBody,o as injectHtmlByPriority};
|
package/dist/common/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const
|
|
1
|
+
"use strict";const common_fs_index=require("./fs/index.cjs"),common_format_index=require("./format/index.cjs"),common_html_index=require("./html/index.cjs"),common_object_index=require("./object/index.cjs"),common_script_index=require("./script/index.cjs"),validator=require("../shared/vite-plugin.Bcg6RW2N.cjs"),common_validation_index=require("./validation/index.cjs");require("fs"),require("path"),require("crypto"),exports.checkSourceExists=common_fs_index.checkSourceExists,exports.copySourceToTarget=common_fs_index.copySourceToTarget,exports.ensureTargetDir=common_fs_index.ensureTargetDir,exports.fileExists=common_fs_index.fileExists,exports.readDirRecursive=common_fs_index.readDirRecursive,exports.readFileContent=common_fs_index.readFileContent,exports.readFileSync=common_fs_index.readFileSync,exports.runWithConcurrency=common_fs_index.runWithConcurrency,exports.shouldUpdateFile=common_fs_index.shouldUpdateFile,exports.writeFileContent=common_fs_index.writeFileContent,exports.escapeHtmlAttr=common_format_index.escapeHtmlAttr,exports.formatDate=common_format_index.formatDate,exports.generateRandomHash=common_format_index.generateRandomHash,exports.getDateFormatParams=common_format_index.getDateFormatParams,exports.padNumber=common_format_index.padNumber,exports.parseTemplate=common_format_index.parseTemplate,exports.stripJsonComments=common_format_index.stripJsonComments,exports.toCamelCase=common_format_index.toCamelCase,exports.toPascalCase=common_format_index.toPascalCase,exports.injectBeforeTag=common_html_index.injectBeforeTag,exports.injectBeforeTagWithFallback=common_html_index.injectBeforeTagWithFallback,exports.injectHeadAndBody=common_html_index.injectHeadAndBody,exports.injectHtmlByPriority=common_html_index.injectHtmlByPriority,exports.deepMerge=common_object_index.deepMerge,exports.containsScriptTag=common_script_index.containsScriptTag,exports.makeCallback=common_script_index.makeCallback,exports.validateIdentifierName=common_script_index.validateIdentifierName,exports.Validator=validator.Validator,exports.validateCallbackFields=common_validation_index.validateCallbackFields,exports.validateEnumValue=common_validation_index.validateEnumValue,exports.validateGlobalName=common_validation_index.validateGlobalName,exports.validateNestedDuration=common_validation_index.validateNestedDuration,exports.validateNoScriptInTemplate=common_validation_index.validateNoScriptInTemplate,exports.validateNonNegativeNumber=common_validation_index.validateNonNegativeNumber;
|