2022-12-06 20:03:34 +00:00
|
|
|
#!/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]) => {
|
2022-12-06 20:03:34 +00:00
|
|
|
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) {
|
2022-12-06 20:03:34 +00:00
|
|
|
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-06 20:03:34 +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);
|
|
|
|
}
|
2022-12-06 20:03:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function nodeModulesFiler(src) {
|
|
|
|
if (src.includes("node_modules")) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
run();
|