32 lines
1.1 KiB
JavaScript
32 lines
1.1 KiB
JavaScript
const os = require('os');
|
|
const fs = require('fs-extra');
|
|
const path = require('path');
|
|
|
|
async function main() {
|
|
console.log('npm pre running');
|
|
|
|
const links = fs.readFileSync("conf/links.csv")
|
|
.toString()
|
|
.trim()
|
|
.split('\n')
|
|
.map(line => line.trim())
|
|
.map(line => line.split(',').map(v => v.trim()));
|
|
|
|
if (os.platform() === 'win32') {
|
|
// convert links to the contents of the files/directories they reference
|
|
for (let [link, target] of links) {
|
|
const absoluteTarget = path.resolve(path.dirname(link), target);
|
|
try {
|
|
console.log({ win32_replace: link });
|
|
await fs.remove(link).catch(error => console.log({ remove_error: error }));
|
|
await fs.copy(absoluteTarget, link, { dereference: true }).catch(error => console.log({ copy_error: error }));
|
|
} catch (err) {
|
|
console.error(`Error creating symlink: ${link} -> ${absoluteTarget}`, err);
|
|
}
|
|
}
|
|
} else {
|
|
console.log('skipping symlink conversion');
|
|
}
|
|
}
|
|
|
|
main().catch(err => console.error('Error', err));
|