'fs.copyFileSync doesn't do anything
I'm using Node.js to copy a few files for one of my packages. My OS is Windows 10 Pro. When I run the JS file (tried in cmd, powershell and cmd with admin) absolutely nothing happens. No error, no copy. Here's the code:
#! /usr/bin/env node
let fs = require("fs");
let path = require("path");
let rootPath = path.join(__dirname, "..");
let root = fs.readdirSync(rootPath);
let exclude = [
".git",
".gitignore",
".prettierrc",
"bin",
"node_modules",
"dist",
];
root = root.filter((item) => exclude.indexOf(item) === -1);
let rootFiles = root.filter((item) =>
fs.statSync(path.join(__dirname, "..", item)).isFile()
);
let rootFolders = root.filter((item) =>
fs.statSync(path.join(__dirname, "..", item)).isDirectory()
);
for (let file of rootFiles) {
let filePath = path.join(rootPath, file);
let destinationPath = path.join(process.cwd(), file);
if (!fs.existsSync(filePath)) {
fs.copyFileSync(filePath, destinationPath);
}
}
process.exit(0);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
