@chao-component/bag-animation-ui 1.0.1 → 1.0.3
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/assets/bag/blind_box_open.png +0 -0
- package/dist/assets/bag/blind_box_spin.png +0 -0
- package/dist/assets/bag/blind_box_tear_off.png +0 -0
- package/dist/assets/bag/blind_box_unopen.png +0 -0
- package/dist/assets/bag.png +0 -0
- package/dist/index.d.mts +26 -3
- package/dist/index.d.ts +26 -3
- package/dist/index.js +35 -12
- package/dist/index.mjs +31 -11
- package/package.json +13 -3
- package/scripts/copy-assets.js +66 -0
- package/vite-plugin.js +86 -0
- package/webpack-plugin.js +70 -0
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/dist/index.d.mts
CHANGED
|
@@ -1,9 +1,32 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
interface BagAnimationProps {
|
|
4
4
|
isAnimating: boolean;
|
|
5
5
|
setIsAnimating: (isAnimating: boolean) => void;
|
|
6
6
|
doneFunction: () => void;
|
|
7
|
-
|
|
7
|
+
frames?: string[];
|
|
8
|
+
defaultImage?: string;
|
|
9
|
+
defaultImageAlt?: string;
|
|
10
|
+
swipeHintText?: string;
|
|
11
|
+
}
|
|
12
|
+
declare function BagAnimation({ isAnimating, setIsAnimating, doneFunction, frames, defaultImage, defaultImageAlt, swipeHintText }: BagAnimationProps): react_jsx_runtime.JSX.Element;
|
|
8
13
|
|
|
9
|
-
|
|
14
|
+
/**
|
|
15
|
+
* 获取打包后的资源路径
|
|
16
|
+
* 这些资源会被打包到 dist/assets 目录中
|
|
17
|
+
*
|
|
18
|
+
* 使用方式:
|
|
19
|
+
* 1. 如果使用默认资源,可以通过 getAssetPath 获取路径
|
|
20
|
+
* 2. 或者直接传入自定义路径覆盖默认值
|
|
21
|
+
*/
|
|
22
|
+
declare function getAssetPath(relativePath: string): string;
|
|
23
|
+
/**
|
|
24
|
+
* 默认的动画帧路径
|
|
25
|
+
*/
|
|
26
|
+
declare const defaultAnimationFrames: string[];
|
|
27
|
+
/**
|
|
28
|
+
* 默认的图片路径
|
|
29
|
+
*/
|
|
30
|
+
declare const defaultImagePath = "/assets/bag.png";
|
|
31
|
+
|
|
32
|
+
export { BagAnimation, type BagAnimationProps, defaultAnimationFrames, defaultImagePath, getAssetPath };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,32 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
interface BagAnimationProps {
|
|
4
4
|
isAnimating: boolean;
|
|
5
5
|
setIsAnimating: (isAnimating: boolean) => void;
|
|
6
6
|
doneFunction: () => void;
|
|
7
|
-
|
|
7
|
+
frames?: string[];
|
|
8
|
+
defaultImage?: string;
|
|
9
|
+
defaultImageAlt?: string;
|
|
10
|
+
swipeHintText?: string;
|
|
11
|
+
}
|
|
12
|
+
declare function BagAnimation({ isAnimating, setIsAnimating, doneFunction, frames, defaultImage, defaultImageAlt, swipeHintText }: BagAnimationProps): react_jsx_runtime.JSX.Element;
|
|
8
13
|
|
|
9
|
-
|
|
14
|
+
/**
|
|
15
|
+
* 获取打包后的资源路径
|
|
16
|
+
* 这些资源会被打包到 dist/assets 目录中
|
|
17
|
+
*
|
|
18
|
+
* 使用方式:
|
|
19
|
+
* 1. 如果使用默认资源,可以通过 getAssetPath 获取路径
|
|
20
|
+
* 2. 或者直接传入自定义路径覆盖默认值
|
|
21
|
+
*/
|
|
22
|
+
declare function getAssetPath(relativePath: string): string;
|
|
23
|
+
/**
|
|
24
|
+
* 默认的动画帧路径
|
|
25
|
+
*/
|
|
26
|
+
declare const defaultAnimationFrames: string[];
|
|
27
|
+
/**
|
|
28
|
+
* 默认的图片路径
|
|
29
|
+
*/
|
|
30
|
+
declare const defaultImagePath = "/assets/bag.png";
|
|
31
|
+
|
|
32
|
+
export { BagAnimation, type BagAnimationProps, defaultAnimationFrames, defaultImagePath, getAssetPath };
|
package/dist/index.js
CHANGED
|
@@ -775,21 +775,41 @@ var require_lib = __commonJS({
|
|
|
775
775
|
// src/index.ts
|
|
776
776
|
var index_exports = {};
|
|
777
777
|
__export(index_exports, {
|
|
778
|
-
BagAnimation: () => BagAnimation
|
|
778
|
+
BagAnimation: () => BagAnimation,
|
|
779
|
+
defaultAnimationFrames: () => defaultAnimationFrames,
|
|
780
|
+
defaultImagePath: () => defaultImagePath,
|
|
781
|
+
getAssetPath: () => getAssetPath
|
|
779
782
|
});
|
|
780
783
|
module.exports = __toCommonJS(index_exports);
|
|
781
784
|
|
|
782
785
|
// src/BagAnimation.tsx
|
|
783
786
|
var import_react = require("react");
|
|
784
787
|
var import_apng_js = __toESM(require_lib());
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
"/
|
|
789
|
-
|
|
790
|
-
|
|
788
|
+
|
|
789
|
+
// src/assets.ts
|
|
790
|
+
function getAssetPath(relativePath) {
|
|
791
|
+
const cleanPath = relativePath.startsWith("/") ? relativePath.slice(1) : relativePath;
|
|
792
|
+
return `/assets/${cleanPath}`;
|
|
793
|
+
}
|
|
794
|
+
var defaultAnimationFrames = [
|
|
795
|
+
"/assets/bag/blind_box_spin.png",
|
|
796
|
+
"/assets/bag/blind_box_unopen.png",
|
|
797
|
+
"/assets/bag/blind_box_tear_off.png",
|
|
798
|
+
"/assets/bag/blind_box_open.png"
|
|
791
799
|
];
|
|
792
|
-
|
|
800
|
+
var defaultImagePath = "/assets/bag.png";
|
|
801
|
+
|
|
802
|
+
// src/BagAnimation.tsx
|
|
803
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
804
|
+
function BagAnimation({
|
|
805
|
+
isAnimating,
|
|
806
|
+
setIsAnimating,
|
|
807
|
+
doneFunction,
|
|
808
|
+
frames = defaultAnimationFrames,
|
|
809
|
+
defaultImage = defaultImagePath,
|
|
810
|
+
defaultImageAlt = "Weedza Mystery Box",
|
|
811
|
+
swipeHintText = "Swipe to open"
|
|
812
|
+
}) {
|
|
793
813
|
const [frame, setFrame] = (0, import_react.useState)(0);
|
|
794
814
|
const [isPausedAtThird, setIsPausedAtThird] = (0, import_react.useState)(false);
|
|
795
815
|
const [thirdFrameProgress, setThirdFrameProgress] = (0, import_react.useState)(0);
|
|
@@ -802,8 +822,8 @@ function BagAnimation({ isAnimating, setIsAnimating, doneFunction }) {
|
|
|
802
822
|
const thirdFrameApngRef = (0, import_react.useRef)(null);
|
|
803
823
|
const thirdFrameOriginalSizeRef = (0, import_react.useRef)(null);
|
|
804
824
|
const hasTriggeredFourthFrame = (0, import_react.useRef)(false);
|
|
805
|
-
const mysteryBoxImage =
|
|
806
|
-
const mysteryBoxAlt =
|
|
825
|
+
const mysteryBoxImage = defaultImage;
|
|
826
|
+
const mysteryBoxAlt = defaultImageAlt;
|
|
807
827
|
(0, import_react.useEffect)(() => {
|
|
808
828
|
if (isAnimating) {
|
|
809
829
|
setFrame(0);
|
|
@@ -1079,7 +1099,7 @@ function BagAnimation({ isAnimating, setIsAnimating, doneFunction }) {
|
|
|
1079
1099
|
)
|
|
1080
1100
|
}
|
|
1081
1101
|
),
|
|
1082
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children:
|
|
1102
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: swipeHintText })
|
|
1083
1103
|
] }) })
|
|
1084
1104
|
] }),
|
|
1085
1105
|
!isAnimating && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
@@ -1094,5 +1114,8 @@ function BagAnimation({ isAnimating, setIsAnimating, doneFunction }) {
|
|
|
1094
1114
|
}
|
|
1095
1115
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1096
1116
|
0 && (module.exports = {
|
|
1097
|
-
BagAnimation
|
|
1117
|
+
BagAnimation,
|
|
1118
|
+
defaultAnimationFrames,
|
|
1119
|
+
defaultImagePath,
|
|
1120
|
+
getAssetPath
|
|
1098
1121
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -769,14 +769,31 @@ var require_lib = __commonJS({
|
|
|
769
769
|
// src/BagAnimation.tsx
|
|
770
770
|
var import_apng_js = __toESM(require_lib());
|
|
771
771
|
import { useEffect, useRef, useState } from "react";
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
"/
|
|
776
|
-
|
|
777
|
-
|
|
772
|
+
|
|
773
|
+
// src/assets.ts
|
|
774
|
+
function getAssetPath(relativePath) {
|
|
775
|
+
const cleanPath = relativePath.startsWith("/") ? relativePath.slice(1) : relativePath;
|
|
776
|
+
return `/assets/${cleanPath}`;
|
|
777
|
+
}
|
|
778
|
+
var defaultAnimationFrames = [
|
|
779
|
+
"/assets/bag/blind_box_spin.png",
|
|
780
|
+
"/assets/bag/blind_box_unopen.png",
|
|
781
|
+
"/assets/bag/blind_box_tear_off.png",
|
|
782
|
+
"/assets/bag/blind_box_open.png"
|
|
778
783
|
];
|
|
779
|
-
|
|
784
|
+
var defaultImagePath = "/assets/bag.png";
|
|
785
|
+
|
|
786
|
+
// src/BagAnimation.tsx
|
|
787
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
788
|
+
function BagAnimation({
|
|
789
|
+
isAnimating,
|
|
790
|
+
setIsAnimating,
|
|
791
|
+
doneFunction,
|
|
792
|
+
frames = defaultAnimationFrames,
|
|
793
|
+
defaultImage = defaultImagePath,
|
|
794
|
+
defaultImageAlt = "Weedza Mystery Box",
|
|
795
|
+
swipeHintText = "Swipe to open"
|
|
796
|
+
}) {
|
|
780
797
|
const [frame, setFrame] = useState(0);
|
|
781
798
|
const [isPausedAtThird, setIsPausedAtThird] = useState(false);
|
|
782
799
|
const [thirdFrameProgress, setThirdFrameProgress] = useState(0);
|
|
@@ -789,8 +806,8 @@ function BagAnimation({ isAnimating, setIsAnimating, doneFunction }) {
|
|
|
789
806
|
const thirdFrameApngRef = useRef(null);
|
|
790
807
|
const thirdFrameOriginalSizeRef = useRef(null);
|
|
791
808
|
const hasTriggeredFourthFrame = useRef(false);
|
|
792
|
-
const mysteryBoxImage =
|
|
793
|
-
const mysteryBoxAlt =
|
|
809
|
+
const mysteryBoxImage = defaultImage;
|
|
810
|
+
const mysteryBoxAlt = defaultImageAlt;
|
|
794
811
|
useEffect(() => {
|
|
795
812
|
if (isAnimating) {
|
|
796
813
|
setFrame(0);
|
|
@@ -1066,7 +1083,7 @@ function BagAnimation({ isAnimating, setIsAnimating, doneFunction }) {
|
|
|
1066
1083
|
)
|
|
1067
1084
|
}
|
|
1068
1085
|
),
|
|
1069
|
-
/* @__PURE__ */ jsx("span", { children:
|
|
1086
|
+
/* @__PURE__ */ jsx("span", { children: swipeHintText })
|
|
1070
1087
|
] }) })
|
|
1071
1088
|
] }),
|
|
1072
1089
|
!isAnimating && /* @__PURE__ */ jsx(
|
|
@@ -1080,5 +1097,8 @@ function BagAnimation({ isAnimating, setIsAnimating, doneFunction }) {
|
|
|
1080
1097
|
] });
|
|
1081
1098
|
}
|
|
1082
1099
|
export {
|
|
1083
|
-
BagAnimation
|
|
1100
|
+
BagAnimation,
|
|
1101
|
+
defaultAnimationFrames,
|
|
1102
|
+
defaultImagePath,
|
|
1103
|
+
getAssetPath
|
|
1084
1104
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chao-component/bag-animation-ui",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"module": "dist/index.mjs",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -9,9 +9,19 @@
|
|
|
9
9
|
"types": "./dist/index.d.ts",
|
|
10
10
|
"import": "./dist/index.mjs",
|
|
11
11
|
"require": "./dist/index.js"
|
|
12
|
-
}
|
|
12
|
+
},
|
|
13
|
+
"./vite-plugin": "./vite-plugin.js",
|
|
14
|
+
"./webpack-plugin": "./webpack-plugin.js"
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist",
|
|
18
|
+
"vite-plugin.js",
|
|
19
|
+
"webpack-plugin.js",
|
|
20
|
+
"scripts"
|
|
21
|
+
],
|
|
22
|
+
"directories": {
|
|
23
|
+
"assets": "dist/assets"
|
|
13
24
|
},
|
|
14
|
-
"files": ["dist"],
|
|
15
25
|
"scripts": {
|
|
16
26
|
"build": "tsup",
|
|
17
27
|
"dev": "tsup --watch"
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 安装脚本:自动复制资源文件到项目的 public 目录
|
|
5
|
+
*
|
|
6
|
+
* 使用方法:
|
|
7
|
+
* 1. 在 package.json 中添加 postinstall 脚本:
|
|
8
|
+
* "scripts": {
|
|
9
|
+
* "postinstall": "node node_modules/@chao-component/bag-animation-ui/scripts/copy-assets.js"
|
|
10
|
+
* }
|
|
11
|
+
*
|
|
12
|
+
* 2. 或者手动运行:
|
|
13
|
+
* node node_modules/@chao-component/bag-animation-ui/scripts/copy-assets.js
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
const { copyFileSync, mkdirSync, readdirSync, existsSync } = require('fs');
|
|
17
|
+
const { join, resolve } = require('path');
|
|
18
|
+
|
|
19
|
+
function copyDir(src, dest) {
|
|
20
|
+
if (!existsSync(src)) {
|
|
21
|
+
console.warn(`⚠️ Source directory not found: ${src}`);
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (!existsSync(dest)) {
|
|
26
|
+
mkdirSync(dest, { recursive: true });
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const entries = readdirSync(src, { withFileTypes: true });
|
|
30
|
+
|
|
31
|
+
for (const entry of entries) {
|
|
32
|
+
const srcPath = join(src, entry.name);
|
|
33
|
+
const destPath = join(dest, entry.name);
|
|
34
|
+
|
|
35
|
+
if (entry.isDirectory()) {
|
|
36
|
+
copyDir(srcPath, destPath);
|
|
37
|
+
} else {
|
|
38
|
+
copyFileSync(srcPath, destPath);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function main() {
|
|
44
|
+
const packageName = '@chao-component/bag-animation-ui';
|
|
45
|
+
const publicDir = process.argv[2] || 'public';
|
|
46
|
+
|
|
47
|
+
// 查找包的位置
|
|
48
|
+
const packagePath = resolve(__dirname, '..', 'dist', 'assets');
|
|
49
|
+
const targetPath = resolve(process.cwd(), publicDir, 'assets');
|
|
50
|
+
|
|
51
|
+
console.log(`📦 Copying assets from ${packageName}...`);
|
|
52
|
+
console.log(` Source: ${packagePath}`);
|
|
53
|
+
console.log(` Target: ${targetPath}`);
|
|
54
|
+
|
|
55
|
+
if (existsSync(packagePath)) {
|
|
56
|
+
copyDir(packagePath, targetPath);
|
|
57
|
+
console.log(`✅ Assets copied successfully to ${publicDir}/assets`);
|
|
58
|
+
} else {
|
|
59
|
+
console.error(`❌ Error: Package assets not found at ${packagePath}`);
|
|
60
|
+
console.error(` Make sure ${packageName} is installed correctly.`);
|
|
61
|
+
process.exit(1);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
main();
|
|
66
|
+
|
package/vite-plugin.js
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vite 插件:自动复制 @chao-component/bag-animation-ui 的资源文件到 public 目录
|
|
3
|
+
*
|
|
4
|
+
* 使用方法:
|
|
5
|
+
* 在 vite.config.js/ts 中:
|
|
6
|
+
*
|
|
7
|
+
* import { bagAnimationAssets } from '@chao-component/bag-animation-ui/vite-plugin';
|
|
8
|
+
*
|
|
9
|
+
* export default {
|
|
10
|
+
* plugins: [
|
|
11
|
+
* bagAnimationAssets(),
|
|
12
|
+
* // ... 其他插件
|
|
13
|
+
* ]
|
|
14
|
+
* }
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { copyFileSync, mkdirSync, readdirSync, existsSync, statSync } from 'fs';
|
|
18
|
+
import { join, dirname, resolve } from 'path';
|
|
19
|
+
import { fileURLToPath } from 'url';
|
|
20
|
+
|
|
21
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
22
|
+
const __dirname = dirname(__filename);
|
|
23
|
+
|
|
24
|
+
function copyDir(src, dest) {
|
|
25
|
+
if (!existsSync(src)) return;
|
|
26
|
+
|
|
27
|
+
if (!existsSync(dest)) {
|
|
28
|
+
mkdirSync(dest, { recursive: true });
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const entries = readdirSync(src, { withFileTypes: true });
|
|
32
|
+
|
|
33
|
+
for (const entry of entries) {
|
|
34
|
+
const srcPath = join(src, entry.name);
|
|
35
|
+
const destPath = join(dest, entry.name);
|
|
36
|
+
|
|
37
|
+
if (entry.isDirectory()) {
|
|
38
|
+
copyDir(srcPath, destPath);
|
|
39
|
+
} else {
|
|
40
|
+
copyFileSync(srcPath, destPath);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function bagAnimationAssets(options = {}) {
|
|
46
|
+
const {
|
|
47
|
+
publicDir = 'public',
|
|
48
|
+
packageName = '@chao-component/bag-animation-ui'
|
|
49
|
+
} = options;
|
|
50
|
+
|
|
51
|
+
return {
|
|
52
|
+
name: 'bag-animation-assets',
|
|
53
|
+
apply: 'serve', // 只在开发服务器时应用
|
|
54
|
+
buildStart() {
|
|
55
|
+
try {
|
|
56
|
+
// 查找 node_modules 中的包
|
|
57
|
+
const packagePath = resolve(process.cwd(), 'node_modules', packageName, 'dist', 'assets');
|
|
58
|
+
const targetPath = resolve(process.cwd(), publicDir, 'assets');
|
|
59
|
+
|
|
60
|
+
if (existsSync(packagePath)) {
|
|
61
|
+
copyDir(packagePath, targetPath);
|
|
62
|
+
console.log(`✅ [bag-animation-assets] Assets copied to ${publicDir}/assets`);
|
|
63
|
+
} else {
|
|
64
|
+
console.warn(`⚠️ [bag-animation-assets] Package assets not found at ${packagePath}`);
|
|
65
|
+
}
|
|
66
|
+
} catch (error) {
|
|
67
|
+
console.error(`❌ [bag-animation-assets] Error copying assets:`, error);
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
buildEnd() {
|
|
71
|
+
// 构建时也复制资源
|
|
72
|
+
try {
|
|
73
|
+
const packagePath = resolve(process.cwd(), 'node_modules', packageName, 'dist', 'assets');
|
|
74
|
+
const targetPath = resolve(process.cwd(), publicDir, 'assets');
|
|
75
|
+
|
|
76
|
+
if (existsSync(packagePath)) {
|
|
77
|
+
copyDir(packagePath, targetPath);
|
|
78
|
+
console.log(`✅ [bag-animation-assets] Assets copied to ${publicDir}/assets`);
|
|
79
|
+
}
|
|
80
|
+
} catch (error) {
|
|
81
|
+
console.error(`❌ [bag-animation-assets] Error copying assets:`, error);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Webpack 插件:自动复制 @chao-component/bag-animation-ui 的资源文件到 public 目录
|
|
3
|
+
*
|
|
4
|
+
* 使用方法:
|
|
5
|
+
* 在 webpack.config.js 中:
|
|
6
|
+
*
|
|
7
|
+
* const { BagAnimationAssetsPlugin } = require('@chao-component/bag-animation-ui/webpack-plugin');
|
|
8
|
+
*
|
|
9
|
+
* module.exports = {
|
|
10
|
+
* plugins: [
|
|
11
|
+
* new BagAnimationAssetsPlugin(),
|
|
12
|
+
* // ... 其他插件
|
|
13
|
+
* ]
|
|
14
|
+
* }
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
const { copyFileSync, mkdirSync, readdirSync, existsSync } = require('fs');
|
|
18
|
+
const { join, resolve } = require('path');
|
|
19
|
+
|
|
20
|
+
function copyDir(src, dest) {
|
|
21
|
+
if (!existsSync(src)) return;
|
|
22
|
+
|
|
23
|
+
if (!existsSync(dest)) {
|
|
24
|
+
mkdirSync(dest, { recursive: true });
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const entries = readdirSync(src, { withFileTypes: true });
|
|
28
|
+
|
|
29
|
+
for (const entry of entries) {
|
|
30
|
+
const srcPath = join(src, entry.name);
|
|
31
|
+
const destPath = join(dest, entry.name);
|
|
32
|
+
|
|
33
|
+
if (entry.isDirectory()) {
|
|
34
|
+
copyDir(srcPath, destPath);
|
|
35
|
+
} else {
|
|
36
|
+
copyFileSync(srcPath, destPath);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
class BagAnimationAssetsPlugin {
|
|
42
|
+
constructor(options = {}) {
|
|
43
|
+
this.options = {
|
|
44
|
+
publicDir: options.publicDir || 'public',
|
|
45
|
+
packageName: options.packageName || '@chao-component/bag-animation-ui'
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
apply(compiler) {
|
|
50
|
+
compiler.hooks.beforeRun.tapAsync('BagAnimationAssetsPlugin', (compilation, callback) => {
|
|
51
|
+
try {
|
|
52
|
+
const packagePath = resolve(process.cwd(), 'node_modules', this.options.packageName, 'dist', 'assets');
|
|
53
|
+
const targetPath = resolve(process.cwd(), this.options.publicDir, 'assets');
|
|
54
|
+
|
|
55
|
+
if (existsSync(packagePath)) {
|
|
56
|
+
copyDir(packagePath, targetPath);
|
|
57
|
+
console.log(`✅ [bag-animation-assets] Assets copied to ${this.options.publicDir}/assets`);
|
|
58
|
+
} else {
|
|
59
|
+
console.warn(`⚠️ [bag-animation-assets] Package assets not found at ${packagePath}`);
|
|
60
|
+
}
|
|
61
|
+
} catch (error) {
|
|
62
|
+
console.error(`❌ [bag-animation-assets] Error copying assets:`, error);
|
|
63
|
+
}
|
|
64
|
+
callback();
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
module.exports = { BagAnimationAssetsPlugin };
|
|
70
|
+
|