Skip to content

Instantly share code, notes, and snippets.

@chaseholdren
Created July 29, 2019 03:48
Show Gist options
  • Save chaseholdren/82817d1a93b7f90cd9385fadf8cd31da to your computer and use it in GitHub Desktop.
Save chaseholdren/82817d1a93b7f90cd9385fadf8cd31da to your computer and use it in GitHub Desktop.
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