How to use pkg - 10 common examples

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 louis-tru / ngui / node_modules / ngui / url.js View on Github external
* @func cwd()
   * @ret {String}
   */
  cwd: util.cwd,

  /**
   * @func chdir(path)
   * @arg path {String}
   * @ret {bool}
   */
  chdir: util.chdir,

  /** 
   * @func isAbsolute() is absolute path
   */
  isAbsolute: pkg.isAbsolute, // func
  
  /**
   * @func resolve() resolve path 
   */
  resolve: pkg.resolve, // func

  /**
   * full filename
   */
  filename: function (path) {
    return get_path(path).filename;
  },

  /**
   * full path
   */
github piobyte / flamingo / src / addon / discovery.js View on Github external
function fromPackage(packagePath/*: string */)/*: ?Addon */ {
  var pkg = path.join(packagePath, 'package.json');
  if (fs.existsSync(pkg)) {
    // $DisableFlow: flow wants string require :(
    var content = require(pkg);
    var keywords = content.keywords || [];

    if (keywords.indexOf(ADDON_KEYWORD) > -1) {
      return {
        path: packagePath,
        pkg: content
      };
    }
  } else {
    logger.debug('no package.json found at ' + packagePath);
  }
}
github piobyte / flamingo / src / addon / loader.ts View on Github external
fromPackage(packagePath: string): Addon | undefined {
    // load packagejson if exists
    const pkg = path.join(packagePath, 'package.json');
    if (fs.existsSync(pkg)) {
      const packageJson = require(pkg);
      const keywords = packageJson.keywords || [];

      if (keywords.indexOf(this.ADDON_KEYWORD) > -1) {
        return {
          path: packagePath,
          pkg: packageJson,
          hooks: {}
        };
      }
    } else {
      addonLoaderLogger.debug('no package.json found at ' + packagePath);
    }
  }
github louis-tru / ngui / node_modules / ngui / util.js View on Github external
// @func temp()
	// @func resources()
	// @func fallbackPath()
	// @func cwd()
	// @func chdir()
	// @func log()

	/**
	 * @current timezone
	 */
	timezone: currentTimezone,

	/**
	 * @has dev mode
	 */
	dev: !!_pkg.options.dev,
	
	/**
	 * @start argv options
	 */
	options: _pkg.options,
	
	/**
	 * @func resolve(...args)
	 */
	resolve: _pkg.resolve,

	/**
	 * @func isAbsolute(path)
	 */
	isAbsolute: _pkg.isAbsolute,
github louis-tru / ngui / node_modules / ngui / util.js View on Github external
// @func log()

	/**
	 * @current timezone
	 */
	timezone: currentTimezone,

	/**
	 * @has dev mode
	 */
	dev: !!_pkg.options.dev,
	
	/**
	 * @start argv options
	 */
	options: _pkg.options,
	
	/**
	 * @func resolve(...args)
	 */
	resolve: _pkg.resolve,

	/**
	 * @func isAbsolute(path)
	 */
	isAbsolute: _pkg.isAbsolute,
	
	/**
	 * Empty function
	 */
	noop: function() { },
github wxajs / wxa / packages / wxa-compiler-babel / src / index.js View on Github external
// default match file path.
        this.test = /\.js$|\.wxs$/;

        this.current = cwd;
        // get configuration from .babelrc, package.json or wxa.config.js
        // find .babelrc first then babel.config.js
        let babelrc = path.join(this.current, '.babelrc');
        let babeljs = path.join(this.current, 'babel.config.js');
        let pkg = path.join(this.current, 'package.json');

        if (fs.existsSync(babelrc)) {
            this.configs = JSON.parse(fs.readFileSync(babelrc, 'utf-8'));
        } else if (fs.existsSync(babeljs)){
            this.configs = require(babeljs);
        } else if (fs.existsSync(pkg)){
            this.configs = require(pkg).babel;
        } 

        // setup default babel config
        this.configs = this.configs || configs || {};
        // process ignore to compat babel6
        if (
            typeof this.configs.ignore === 'string' || 
            this.configs.ignore instanceof RegExp
        ) {
            this.configs.ignore = [this.configs.ignore];
        } else if ( 
            this.configs.ignore && 
            !Array.isArray(this.configs.ignore)
        ) {
            throw new Error(`babel 配置 ignore 必须为Array类型`);
        } else {