Files
cypress/scripts/link-packages.js
Ben Kucera ec25c7dff8 chore(windows): make install portable to windows (#4779)
* chore(install)
- make preinstall hook windows portable
- make link-packages script use junction symlinks for windows

* use npx

* run preinstll in appveyor

* remove win32 check, pin dep (and update .npmrc)
2019-07-22 12:30:52 -04:00

57 lines
1.3 KiB
JavaScript

/* eslint-disable no-console */
const fse = require('fs-extra')
const path = require('path')
const globber = require('glob')
const Promise = require('bluebird')
const fs = Promise.promisifyAll(fse)
const glob = Promise.promisify(globber)
const pathToPackages = path.join(__dirname, '..', 'node_modules', '@packages')
function deleteOutputFolder () {
console.log('deleting ', pathToPackages)
return fs.remove(pathToPackages)
}
function makeLinks () {
return fs.ensureDir(pathToPackages)
.then(() => {
return glob('./packages/*/package.json')
.map((filename) => {
return fs.readJsonAsync(filename)
.then((json) => {
return { filename, json }
})
})
.map(({ filename }) => {
const dirname = path.dirname(filename)
const basename = path.basename(dirname)
const destinationLink = path.join(pathToPackages, basename)
const relativePathToDest = path.relative(path.dirname(destinationLink), dirname)
console.log(destinationLink, '->', relativePathToDest)
return fs.symlink(relativePathToDest, destinationLink, 'junction')
})
})
}
function linkPackages () {
return deleteOutputFolder()
.then(makeLinks)
.then(() => {
console.log('✅ require("@packages/<name>") should work now!')
})
}
module.exports = linkPackages
if (!module.parent) {
linkPackages()
}