forked from Matdata-eu/Yasgui
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdistributeBuildFiles.js
More file actions
85 lines (67 loc) · 2.21 KB
/
distributeBuildFiles.js
File metadata and controls
85 lines (67 loc) · 2.21 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
#!/usr/bin/env node
import fs from "fs";
import path from "path";
// Define packages
const packages = ["yasgui", "yasr", "yasqe", "utils"];
// Helper function to recursively remove directory
function removeDir(dirPath) {
if (fs.existsSync(dirPath)) {
fs.rmSync(dirPath, { recursive: true, force: true });
}
}
// Helper function to recursively copy directory
function copyDir(src, dest) {
if (!fs.existsSync(src)) {
return;
}
fs.mkdirSync(dest, { recursive: true });
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);
if (entry.isDirectory()) {
copyDir(srcPath, destPath);
} else {
fs.copyFileSync(srcPath, destPath);
}
}
}
// Helper function to copy files matching a pattern
function copyMatchingFiles(sourceDir, pattern, destDir) {
if (!fs.existsSync(sourceDir)) {
return;
}
const files = fs.readdirSync(sourceDir);
const matchingFiles = files.filter((file) => file.startsWith(pattern));
if (matchingFiles.length > 0) {
fs.mkdirSync(destDir, { recursive: true });
matchingFiles.forEach((file) => {
const srcPath = path.join(sourceDir, file);
const destPath = path.join(destDir, file);
fs.copyFileSync(srcPath, destPath);
});
}
}
// Main logic
packages.forEach((pkg) => {
console.log(`Processing package: ${pkg}`);
const packageBuildDir = path.join("packages", pkg, "build");
const buildTsSource = path.join("build", "ts", "packages", pkg);
const buildTsDest = path.join(packageBuildDir, "ts");
const buildDir = "build";
// Remove existing build directory
removeDir(packageBuildDir);
// Create build directory
fs.mkdirSync(packageBuildDir, { recursive: true });
// Copy TypeScript build files
if (fs.existsSync(buildTsSource)) {
copyDir(buildTsSource, buildTsDest);
console.log(` Copied TypeScript files for ${pkg}`);
} else {
console.log(` No TypeScript files found for ${pkg}`);
}
// Copy package-specific build files
copyMatchingFiles(buildDir, pkg, packageBuildDir);
console.log(` Copied build files for ${pkg}`);
});
console.log("Distribution complete!");