Created
July 29, 2019 03:48
-
-
Save chaseholdren/82817d1a93b7f90cd9385fadf8cd31da to your computer and use it in GitHub Desktop.
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
const process = require("process"); | |
const fs = require("fs"); | |
const path = require("path"); | |
const child_process = require("child_process"); | |
const targetFileOrFolder = path.resolve(...process.argv); | |
console.log(targetFileOrFolder); | |
const runShellCommand = (command, ...args) => { | |
return new Promise((resolve, reject) => { | |
const childProcess = child_process.exec( | |
command, | |
{ | |
shell: true, | |
cwd: targetFileOrFolder | |
}, | |
(error, stdout, stderr) => { | |
resolve(stdout); | |
} | |
); | |
childProcess.once('error', (err) => { | |
reject(err); | |
}); | |
}); | |
}; | |
const run = async () => { | |
let packageJsonDirectory = await runShellCommand("npm prefix"); | |
packageJsonDirectory = packageJsonDirectory.trim(); | |
console.log('ting'+packageJsonDirectory); | |
const packageJson = await require(`${packageJsonDirectory}\\package.json`); | |
const packageName = packageJson.name; | |
console.log(packageName); | |
var child = child_process.spawn('clip'); | |
child.stdin.write(packageName); | |
child.stdin.end(); | |
}; | |
run().catch(e => {console.error(e)}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment