Last active
March 23, 2022 16:03
-
-
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')
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(() => { | |
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