How to run npm pack
command from my node application?
something like this:
const npm = require('npm')
const result = npm.pack('sourcefolder', 'targetdir');
//result ==== down..
How to run npm pack
command from my node application?
something like this:
const npm = require('npm')
const result = npm.pack('sourcefolder', 'targetdir');
//result ==== down..
Everything that can be ran from command line can be ran from JS, so yes:
require('child_process').exec('npm pack', console.log)
You don't have to run npm pack
command to create tarball.
Just use tar
package:
const tar = require('tar');
const fstream = require('fstream');
function pack({ path, target }) {
fstream
.Reader({ path, type: 'Directory' })
.pipe(tar.Pack({ noProprietary: true }))
.pipe(fs.createWriteStream(target));
}
const name = 'your-folder-package';
pack({
path: path.join(__dirname, 'packages', name),
target: path.join(__dirname, 'dist/packages', `${name}.tar`),
});