Created
September 1, 2019 17:58
-
-
Save vegarringdal/c12ccf64b6f2f87943d8ddc4542d347c to your computer and use it in GitHub Desktop.
sss
This file contains hidden or 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
/* How to use | |
* This script assumes you have all you npm projects in 1 common folder like my document/home | |
* Put this in side project you want to use linked module and call it `symlink` | |
* Run `node symlink name-of-module-you-want-to-link` | |
*/ | |
/* | |
MIT License | |
Copyright (c) 2016 Vegar Ringdal <[email protected]> | |
Permission is hereby granted, free of charge, to any person obtaining a copy | |
of this software and associated documentation files (the "Software"), to deal | |
in the Software without restriction, including without limitation the rights | |
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
copies of the Software, and to permit persons to whom the Software is | |
furnished to do so, subject to the following conditions: | |
The above copyright notice and this permission notice shall be included in all | |
copies or substantial portions of the Software. | |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
SOFTWARE. | |
*/ | |
const packagename = process.argv[2]; | |
const fs = require('fs'); | |
const path = require('path'); | |
const deleteFolder = folder => { | |
const delPath = path.resolve(folder); | |
if (fs.existsSync(delPath)) { | |
let x; | |
try { | |
x = fs.readdirSync(delPath); | |
} catch (e) { | |
debugger; | |
} | |
if (x) { | |
x.forEach((file, index) => { | |
const currentPath = path.resolve(delPath, `./${file}`); | |
if (fs.existsSync(delPath)) { | |
if (fs.lstatSync(currentPath).isDirectory()) { | |
deleteFolder(currentPath); | |
} else { | |
fs.unlinkSync(currentPath); | |
} | |
} | |
}); | |
} | |
fs.rmdirSync(delPath); | |
} | |
}; | |
const main = async () => { | |
// first remove if it exist | |
console.log('Deleting bootstrap- if any', 'green'); | |
deleteFolder(`./node_modules/${packagename}`); | |
console.log('Linking'); | |
fs.symlink( | |
path.resolve(`../${packagename}`), | |
`./node_modules/${packagename}`, | |
'junction', // <- can not use dir on windows | |
err => { | |
if (err) { | |
console.log(err); | |
} | |
} | |
); | |
console.log('Done'); | |
}; | |
main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment