How to use the pkg.exec function in pkg

To help you get started, we’ve selected a few pkg examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github balena-io / balena-cli / automation / build-bin.ts View on Github external
async function buildPkg() {
	const args = [
		'--target',
		'host',
		'--output',
		'build-bin/balena',
		'package.json',
	];
	console.log('=======================================================');
	console.log(`execPkg ${args.join(' ')}`);
	console.log(`cwd="${process.cwd()}" ROOT="${ROOT}"`);
	console.log('=======================================================');

	await execPkg(args);

	const xpaths: Array<[string, string[]]> = [
		// [platform, [path, to, file]]
		['*', ['opn', 'xdg-open']],
		['darwin', ['denymount', 'bin', 'denymount']],
	];
	await Bluebird.map(xpaths, ([platform, xpath]) => {
		if (platform === '*' || platform === process.platform) {
			// eg copy from node_modules/opn/xdg-open to build-bin/xdg-open
			return fs.copy(
				path.join(ROOT, 'node_modules', ...xpath),
				path.join(ROOT, 'build-bin', xpath.pop()!),
			);
		}
	});
	const nativeExtensionPaths: string[] = await filehound
github klemola / foobar2000-web-ui / release / index.js View on Github external
/* eslint-disable @typescript-eslint/no-var-requires */
const { exec } = require('pkg')

const SERVER_ENTRYPOINT = '../build/main.js'
const TARGET = 'node12-win-x64'
const PKG_OUTPUT = './dist/foobar2000-web-ui.exe'

exec([
    SERVER_ENTRYPOINT,
    '--target',
    TARGET,
    '--output',
    PKG_OUTPUT,
    '--config',
    'pkg-config.json'
])
    .then(() => console.info('✅ .exe built!'))
    .catch(console.error)
github ChatPlug / ChatPlug / build-tool / PkgPackagingTarget.ts View on Github external
async packageApp(distBinPath: string) {
    loggingHelper.info(`Packaging app for ${this.platform}-${this.arch}`)
    await fs.mkdirp(this.distPostTempPath)
    const binaryName =
      this.platform === OutputPlatform.windows ? 'chatplug.exe' : 'chatplug'
    const target =
      `${OutputTypesUtils.platformToPkgName(this.platform)},${OutputTypesUtils.archToPkgNames(this.arch)}`

    await pkg([
      this.distPreTempPath,
      '--output',
      path.join(this.distPostTempPath, binaryName),
      '--target',
      target,
      '--public',
    ])

    const nativeAddonsToCopy = await glob(
      path.join(this.distPreTempPath, 'node_modules/**/*.node'),
      { absolute: true },
    )

    // copy native addons
    await Promise.all(
      nativeAddonsToCopy.map(nativeAddon =>
github pedromsilvapt / unicast / fuse.js View on Github external
async function package ( platform ) {
    // sharp: https://github.com/lovell/sharp/releases
    // lipvips: https://github.com/lovell/sharp-libvips/releases/
    await fetch( platform, [ 'ffmpeg', 'rethinkdb', 'libvips', 'sharp' ] );

    const buildFolder = `builds/${ platform }/`;

    await reset( buildFolder );

    await tsc( __dirname, {
        ...JSON.parse( ( await fs.readFile( 'tsconfig.json', 'utf8' ) ) ).compilerOptions
    } );

    await pkg( [ '.', '--target', getPackageHost( platform ), '--out-path', buildFolder ] );

    for ( let native of nativeFolders ) {
        await makeDir( path.join( buildFolder, native ) );

        await src( path.join( native, '**/*' ), { base: "." } )
            .dest( buildFolder )
            .exec();
    }

    
    await copy( 
        './lib/Extensions',
        path.join( buildFolder, 'Extensions' )
    );

    await copy(
github CleverCloud / clever-tools / scripts / build-release.js View on Github external
async function buildRelease (arch) {

  console.log(`Building release for ${arch}...\n`);

  const cleverTools = (arch === 'win') ? `clever.exe` : 'clever';
  const archiveExt = (arch === 'win') ? '.zip' : '.tar.gz';
  const buildDir = `${releasesDir}/${cleverToolsVersion}`;
  const archivePath = `${buildDir}/clever-tools-${cleverToolsVersion}_${arch}${archiveExt}`;
  const latestArchivePath = `${releasesDir}/latest/clever-tools-latest_${arch}${archiveExt}`;

  await pkg([`.`, `-t`, `node${nodeVersion}-${arch}`, `-o`, `${buildDir}/${arch}/${cleverTools}`]);

  if (arch === 'win') {
    await asyncExec(`zip -j ${archivePath} ${buildDir}/${arch}/${cleverTools}`);
  }
  else {
    await asyncExec(`tar czf "${archivePath}" -C ${buildDir}/${arch} ${cleverTools}`);
  }

  if (arch === 'linux') {
    await buildRpm(buildDir);
    await buildDeb(buildDir);
  }

  await del(`${buildDir}/${arch}`);

  const sum = await checksum(`${archivePath}`);
github atabel / carlo-nativefier / cli.js View on Github external
console.log("Icon not found");
  }

  let file = fs
    .readFileSync(path.join(__dirname, "app.template.js"), "utf8")
    .replace(/__URL__/g, JSON.stringify(url))
    .replace(/__NAME__/g, JSON.stringify(name))
    .replace(/__ICON__/g, JSON.stringify(iconFileName));

  const appFilePath = path.join(__dirname, "app.js");

  fs.writeFileSync(appFilePath, file);

  console.log("building...");

  pkg.exec([appFilePath, "--target", "host", "--output", name]).then(() => {
    fs.unlinkSync(appFilePath);
    if (iconFilePath) {
      fs.unlinkSync(iconFilePath);
    }
    console.log("done!");
  });
})();
github fmiras / next-pkg / lib / next-pkg.js View on Github external
const compile = async () => {
  const spinner = ora('Compiling server with pkg').start()
  try {
    const execution = exec([
      finalServerPath,
      '--target',
      'host',
      '--output',
      `${binaryFilePath}`
    ])
    spinner.stop()
    readline.moveCursor(process.stderr, 0, -1)
    readline.clearLine(process.stderr)
    spinner.start()
    await execution
    spinner.succeed(`Server compiled`)
  } catch (error) {
    spinner.fail(`Error during pkg compiling process: ${error}`)
    throw error
  }
github mozilla / Spoke / package.js View on Github external
function buildRelease(targets, outPath, opts) {
  const args = ["bin/spoke", "--config", ".pkg.json", "--target", targets.join(","), "--out-path", outPath];
  return exec(args.concat(opts));
}
github mi-g / vdhcoapp / gulpfile.js View on Github external
function Pkg(platform,arch) {
	var { target, binaryName } = PkgNames(platform,arch);
	return execPkg(["index.js","--target",target,"--output","bin/"+binaryName]);
}