@chao-component/bag-animation-ui 1.0.2 → 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/package.json +8 -3
- package/scripts/copy-assets.js +66 -0
- package/vite-plugin.js +86 -0
- package/webpack-plugin.js +70 -0
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,10 +9,15 @@
|
|
|
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"
|
|
13
15
|
},
|
|
14
16
|
"files": [
|
|
15
|
-
"dist"
|
|
17
|
+
"dist",
|
|
18
|
+
"vite-plugin.js",
|
|
19
|
+
"webpack-plugin.js",
|
|
20
|
+
"scripts"
|
|
16
21
|
],
|
|
17
22
|
"directories": {
|
|
18
23
|
"assets": "dist/assets"
|
|
@@ -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
|
+
|