-
-
Notifications
You must be signed in to change notification settings - Fork 85
Expand file tree
/
Copy pathbuild-utils.js
More file actions
68 lines (62 loc) · 2.15 KB
/
Copy pathbuild-utils.js
File metadata and controls
68 lines (62 loc) · 2.15 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
const fs = require("fs");
const path = require("path");
const { execSync } = require("child_process");
// Utility: Copy files
function copyFile(src, dest) {
console.log(`📁 Copying from "${src}" to "${dest}"...`);
fs.mkdirSync(path.dirname(dest), { recursive: true });
fs.copyFileSync(src, dest);
console.log(`✅ Copied file.`);
}
// Utility: Delete folder
function deleteFolder(targetPath) {
console.log(`🗑️ Deleting folder: "${targetPath}"...`);
if (fs.existsSync(targetPath)) {
console.log(`✅ Folder deleted.`);
fs.rmSync(targetPath, { recursive: true, force: true });
} else {
console.log(`ℹ️ Folder not found, skipping delete: "${targetPath}"`);
}
}
// Utility: Delete all *.min.js or *.min.css
//
// `excludeDirs` is an optional array of directory names that should not be
// recursed into. Paths under `assets/js/lib/` and `assets/css/lib/` hold
// vendored libraries from node_modules and must not be deleted by the
// pre-uglify / pre-cleancss clean step (see issue #1221).
function cleanMinified(dir, ext, excludeDirs) {
const exclude = Array.isArray(excludeDirs) ? excludeDirs : [];
console.log(`🧹 Cleaning *.min.${ext} files in "${dir}"...`);
if (exclude.length > 0) {
console.log(` (excluding: ${exclude.join(", ")})`);
}
const walk = (dirPath) => {
fs.readdirSync(dirPath).forEach((file) => {
const fullPath = path.join(dirPath, file);
if (fs.statSync(fullPath).isDirectory()) {
if (exclude.includes(file)) {
console.log(`⏭️ Skipping excluded directory: ${fullPath}`);
return;
}
walk(fullPath);
} else if (file.endsWith(`.min.${ext}`)) {
console.log(`🗑️ Deleting file: ${fullPath}`);
fs.unlinkSync(fullPath);
}
});
};
walk(dir);
console.log(`✅ Minified *.${ext} cleanup complete.`);
}
// Utility: Post archive process - no longer needed with composer-archive-project plugin
function postArchive(packageName) {
console.log(`✅ Archive ready: ${packageName}.zip\n`);
}
console.log(`🏁 Build process finished`);
// Exports
module.exports = {
copyFile,
deleteFolder,
cleanMinified,
postArchive,
};