-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcopy-assets.js
More file actions
198 lines (165 loc) · 4.49 KB
/
copy-assets.js
File metadata and controls
198 lines (165 loc) · 4.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#!/usr/bin/env node
/**
* Unity AI Lab
* Creators: Hackall360, Sponge, GFourteen
* https://www.unityailab.com
* unityailabcontact@gmail.com
* Version: v2.1.5
*/
/**
* Copy Additional Assets to Dist
* Uses BLACKLIST approach - copies everything EXCEPT excluded items
* Vite handles HTML files, this copies all other assets
*/
const fs = require('fs');
const path = require('path');
const DIST_DIR = 'dist';
// BLACKLIST: Files and directories to EXCLUDE from copying
const EXCLUDE = [
// Build/Dev folders
'node_modules',
'dist',
'.git',
'.github',
'.vscode',
// Config files (not needed in production)
'vite.config.js',
'package.json',
'package-lock.json',
'copy-assets.js',
'cache-bust.js',
'generate-sitemap.js',
// Scripts folder (build/dev tools, not needed in production)
'scripts',
'.gitignore',
'.gitattributes',
'.eslintrc.js',
'.prettierrc',
'tsconfig.json',
'jsconfig.json',
// Documentation (README stays out, but Docs folder deploys for prompts)
'CLAUDE.md',
'README.md',
// Archived/legacy content (not needed in production)
'Archived',
'playwright-report',
// Python library (not needed for web)
'PolliLibPy',
// Minified versions (originals are fine, Vite handles optimization)
'styles.min.css',
'script.min.js',
// Test files
'tests',
'test',
'*.test.js',
'*.spec.js',
// Temp/cache files
'.DS_Store',
'Thumbs.db',
'*.log',
'*.tmp',
];
// File extensions to always exclude
const EXCLUDE_EXTENSIONS = [
'.md', // Markdown docs (except in specific folders we want)
'.log',
'.tmp',
];
/**
* Check if a path should be excluded
*/
function shouldExclude(itemPath, itemName) {
// Check exact matches in exclude list
if (EXCLUDE.includes(itemName)) {
return true;
}
// Check if it's a hidden file/folder (starts with .)
// Allow .htaccess, _headers, .nojekyll, and .claude.zip (download file)
const allowedDotFiles = ['.htaccess', '_headers', '.nojekyll', '.claude.zip'];
if (itemName.startsWith('.') && !allowedDotFiles.includes(itemName)) {
return true;
}
// Check excluded extensions
const ext = path.extname(itemName).toLowerCase();
if (EXCLUDE_EXTENSIONS.includes(ext)) {
return true;
}
// Check glob patterns in exclude list
for (const pattern of EXCLUDE) {
if (pattern.startsWith('*') && itemName.endsWith(pattern.slice(1))) {
return true;
}
}
return false;
}
/**
* Check if file already exists in dist (Vite already processed it)
*/
function alreadyInDist(relativePath) {
const distPath = path.join(DIST_DIR, relativePath);
return fs.existsSync(distPath);
}
/**
* Copy directory recursively with exclusions
*/
function copyDirRecursive(src, dest, relativePath = '') {
let copiedCount = 0;
if (!fs.existsSync(src)) {
return copiedCount;
}
const entries = fs.readdirSync(src, { withFileTypes: true });
for (const entry of entries) {
const srcPath = path.join(src, entry.name);
const destPath = path.join(dest, entry.name);
const relPath = path.join(relativePath, entry.name);
// Check exclusions
if (shouldExclude(srcPath, entry.name)) {
continue;
}
if (entry.isDirectory()) {
// Create directory and recurse
fs.mkdirSync(destPath, { recursive: true });
copiedCount += copyDirRecursive(srcPath, destPath, relPath);
} else {
// Skip if already exists in dist (Vite handled it)
if (!alreadyInDist(relPath)) {
fs.mkdirSync(dest, { recursive: true });
fs.copyFileSync(srcPath, destPath);
copiedCount++;
}
}
}
return copiedCount;
}
/**
* Main execution
*/
function main() {
console.log('📋 Copying assets to dist (blacklist mode)...');
console.log('');
// Check if dist exists
if (!fs.existsSync(DIST_DIR)) {
console.error(`❌ Error: ${DIST_DIR} directory not found!`);
console.error(' Run this script after Vite build.');
process.exit(1);
}
console.log(' 🚫 Excluded patterns:');
EXCLUDE.slice(0, 10).forEach(item => console.log(` - ${item}`));
if (EXCLUDE.length > 10) {
console.log(` ... and ${EXCLUDE.length - 10} more`);
}
console.log('');
// Copy everything from root, respecting exclusions
const copiedCount = copyDirRecursive('.', DIST_DIR);
console.log('');
console.log(`✅ Asset copying complete!`);
console.log(` Files copied: ${copiedCount}`);
}
// Run
try {
main();
process.exit(0);
} catch (error) {
console.error('❌ Error copying assets:', error);
process.exit(1);
}