js-waku-examples/packages/create-waku-app/build.js

44 lines
1.2 KiB
JavaScript
Raw Normal View History

#!/usr/bin/env node
const path = require("path");
const fs = require("fs-extra");
const packageJson = require("./package.json");
const examplesFolder = path.resolve("./examples");
async function run() {
fs.ensureDirSync(examplesFolder);
const supportedExamples = Object.entries(packageJson.wakuExamples);
console.log("Started copying supported Waku examples.");
2022-12-08 17:34:38 +00:00
const copyPromises = supportedExamples.map(async ([name, relativePath]) => {
const resolvedPath = path.resolve(__dirname, relativePath);
const destinationPath = path.resolve(examplesFolder, name);
2022-12-08 17:34:38 +00:00
try {
await fs.copy(resolvedPath, destinationPath, { filter: nodeModulesFiler });
} catch (error) {
console.error(`Failed to copy example ${name} to ${destinationPath} with ${error.message}`);
throw Error(error.message);
2022-12-08 17:34:38 +00:00
}
});
2022-12-08 17:34:38 +00:00
try {
await Promise.all(copyPromises);
console.log("Finished copying examples.");
} catch (error) {
console.error("Failed to copy examples due to " + error.message);
}
}
function nodeModulesFiler(src) {
if (src.includes("node_modules")) {
return false;
}
return true;
}
run();