Skip to content

Instantly share code, notes, and snippets.

@adica
Last active March 23, 2022 16:03
Show Gist options
  • Save adica/0ceddc17cbfc4c94b299d4e76a6092aa to your computer and use it in GitHub Desktop.
Save adica/0ceddc17cbfc4c94b299d4e76a6092aa to your computer and use it in GitHub Desktop.
Small Node.js script that copy 'dist' folder from current package into parent level other modules that depend on it (notice - you need to install 'fs-extra' for 'fs.copySync')
(() => {
const fs = require('fs-extra'),
path = require('path'),
pjson = require('./package.json'),
pname = pjson.name,
currentModuleDistFiles = path.join(__dirname, '/dist'),
otherProjects = path.join(__dirname, '/../');
// Run over all other projects on the parent folder
fs.readdir(otherProjects, (err, folders) => {
if (err) {
console.log(err);
}
folders.forEach((folder) => {
// Build the path to this packages 'dist' folder on other project
const sourcePath = path.join(otherProjects, folder, '/node_modules/', pname, '/dist');
if (fs.existsSync(sourcePath)) {
// If other project use this package - copy updated dist into it
copyDist(sourcePath, folder);
}
});
});
function copyDist(folderPath, pkgName) {
try {
// Copy 'dist' files of this package into 'node_modules' folder on the project who depened on it
fs.copySync(currentModuleDistFiles, folderPath);
console.log(`dist folder was copied to ${pkgName}`);
} catch (err) {}
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment