Files
noodl/scripts/build-pack.ts
Michael Cartner b9c60b07dc Initial commit
Co-Authored-By: Eric Tuvesson <eric.tuvesson@gmail.com>
Co-Authored-By: mikaeltellhed <2311083+mikaeltellhed@users.noreply.github.com>
Co-Authored-By: kotte <14197736+mrtamagotchi@users.noreply.github.com>
Co-Authored-By: Anders Larsson <64838990+anders-topp@users.noreply.github.com>
Co-Authored-By: Johan  <4934465+joolsus@users.noreply.github.com>
Co-Authored-By: Tore Knudsen <18231882+torekndsn@users.noreply.github.com>
Co-Authored-By: victoratndl <99176179+victoratndl@users.noreply.github.com>
2024-01-26 11:52:55 +01:00

61 lines
1.7 KiB
TypeScript

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);