forked from noodlapp/noodl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-pack.ts
60 lines (50 loc) · 1.66 KB
/
build-pack.ts
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
import * as fs from 'fs';
import * as path from 'path';
import { promisify } from 'util';
const readdir = promisify(fs.readdir);
const stat = promisify(fs.stat);
const copyFile = promisify(fs.copyFile);
async function copyFilesMatchingRegex(
sourceFolder: string,
destinationFolder: string,
regexList: RegExp[]
): Promise<void> {
try {
// Ensure the destination folder exists
if (!fs.existsSync(destinationFolder)) {
fs.mkdirSync(destinationFolder, { recursive: true });
}
// Read the files in the source folder
const files = await readdir(sourceFolder);
// Iterate through each file
for (const file of files) {
const filePath = path.join(sourceFolder, file);
// Check if it is a file
const stats = await stat(filePath);
if (stats.isFile()) {
// Check if the file matches any regex in the list
if (regexList.some((regex) => regex.test(file))) {
// Copy the file to the destination folder
const destinationPath = path.join(destinationFolder, file);
await copyFile(filePath, destinationPath);
console.log(`Copied: ${file}`);
}
}
}
console.log('Copy operation completed.');
} catch (error) {
console.error('Error:', error.message);
}
}
const sourceFolder = path.join(__dirname, '..', 'packages/noodl-editor/dist');
const destinationFolder = path.join(__dirname, '..', 'publish');
const regexList: RegExp[] = [
/* Windows */
/.*Setup.*\.exe$/,
/.*Setup.*\.blockmap$/,
/* MacOS */
/.*\.dmg$/,
/.*\.blockmap$/
];
fs.mkdirSync(destinationFolder, { recursive: true });
copyFilesMatchingRegex(sourceFolder, destinationFolder, regexList);