UNPKG

@arc-fusion/cli

Version:

CLI for running Arc Fusion on your local machine

50 lines (41 loc) 1.23 kB
'use strict' const fs = require('fs') const path = require('path') const { promisify } = require('util') const lstat = promisify(fs.lstat) const realpath = promisify(fs.realpath) const glob = promisify(require('glob')) const isLink = async (filePath) => { const stats = await lstat(filePath) return stats.isSymbolicLink() } async function getLinks (globPattern) { // the glob module requires forward slashes, even on Windows const entries = await glob(globPattern.replace(/\\/g, '/')) const links = await Promise.all( entries .map(async (entry) => (await isLink(entry)) ? entry : null ) ) return links.filter((entry) => entry) } async function getLinkedModules (projectRoot) { const modulesRoot = path.resolve(projectRoot, 'node_modules') const links = await Promise.all( [].concat( await getLinks(path.join(modulesRoot, '*/')), await getLinks(path.join(modulesRoot, '@*', '*/')) ) .map(async (link) => ({ [path.relative(modulesRoot, link)]: await realpath(link) })) ) return Object.assign({}, ...links) } module.exports = getLinkedModules if (module === require.main) { getLinkedModules('.').then(console.log) }