How to use @electron/get - 6 common examples

To help you get started, we’ve selected a few @electron/get 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 castlabs / electron-releases / install.js View on Github external
const path = require('path')
const extract = require('extract-zip')
const { downloadArtifact } = require('@electron/get')

if (process.env.ELECTRON_SKIP_BINARY_DOWNLOAD) {
  process.exit(0)
}

const platformPath = getPlatformPath()

if (isInstalled()) {
  process.exit(0)
}

// downloads if not cached
downloadArtifact({
  version,
  artifactName: 'electron',
  mirrorOptions: { mirror: "https://github.com/castlabs/electron-releases/releases/download/" },
  force: process.env.force_no_cache === 'true',
  cacheRoot: process.env.electron_config_cache,
  platform: process.env.npm_config_platform || process.platform,
  arch: process.env.npm_config_arch || process.arch
}).then(extractFile).catch(err => {
  console.error(err.stack)
  process.exit(1)
})

function isInstalled () {
  try {
    if (fs.readFileSync(path.join(__dirname, 'dist', 'version'), 'utf-8').replace(/^v/, '') !== version) {
      return false
github electron / electron / npm / install.js View on Github external
}

if (process.env.ELECTRON_SKIP_BINARY_DOWNLOAD) {
  process.exit(0)
}

const platformPath = getPlatformPath()

const electronPath = process.env.ELECTRON_OVERRIDE_DIST_PATH || path.join(__dirname, 'dist', platformPath)

if (installedVersion === version && fs.existsSync(electronPath)) {
  process.exit(0)
}

// downloads if not cached
downloadArtifact({
  version,
  artifactName: 'electron',
  force: process.env.force_no_cache === 'true',
  cacheRoot: process.env.electron_config_cache,
  platform: process.env.npm_config_platform || process.platform,
  arch: process.env.npm_config_arch || process.arch
}).then((zipPath) => extractFile(zipPath)).catch((err) => onerror(err))

// unzips and makes path.txt point at the correct executable
function extractFile (zipPath) {
  extract(zipPath, { dir: path.join(__dirname, 'dist') }, function (err) {
    if (err) return onerror(err)
    fs.writeFile(path.join(__dirname, 'path.txt'), platformPath, function (err) {
      if (err) return onerror(err)
    })
  })
github electron / electron-packager / test / _setup.js View on Github external
async function downloadElectronChecksum (version) {
  return downloadArtifact({
    isGeneric: true,
    version,
    artifactName: 'SHASUMS256.txt'
  })
}
github electron / electron-packager / test / basic.js View on Github external
test.serial('defaults', util.testSinglePlatform(async (t, opts) => {
  opts.name = 'defaultsTest'
  opts.dir = util.fixtureSubdir('basic')
  delete opts.platform
  delete opts.arch

  const defaultOpts = {
    arch: getHostArch(),
    name: opts.name,
    platform: process.platform
  }

  const paths = await packager(opts)
  t.true(Array.isArray(paths), 'packager call should resolve to an array')
  t.is(paths.length, 1, 'Single-target run should resolve to a 1-item array')

  const finalPath = paths[0]
  t.is(finalPath, path.join(t.context.workDir, common.generateFinalBasename(defaultOpts)),
       'Path should follow the expected format and be in the cwd')
  await util.assertDirectory(t, finalPath, 'The expected output directory should exist')
  const resourcesPath = path.join(finalPath, util.generateResourcesPath(defaultOpts))
  const appPath = path.join(finalPath, generateNamePath(defaultOpts))

  if (common.isPlatformMac(defaultOpts.platform)) {
github electron / electron-packager / src / cli.js View on Github external
}
    }

    if (args.help) {
      await printUsageAndExit(false)
    } else if (args.version) {
      if (typeof args.version !== 'boolean') {
        console.error('--version does not take an argument. Perhaps you meant --app-version or --electron-version?\n')
      }
      console.log(hostInfo())
      process.exit(0)
    } else if (!args.dir) {
      await printUsageAndExit(true)
    }

    initializeProxy()

    try {
      const appPaths = await packager(args)
      if (appPaths.length > 1) {
        console.error(`Wrote new apps to:\n${appPaths.join('\n')}`)
      } else if (appPaths.length === 1) {
        console.error('Wrote new app to', appPaths[0])
      }
    } catch (err) {
      if (err.message) {
        console.error(err.message)
      } else {
        console.error(err, err.stack)
      }
      process.exit(1)
    }
github electron / electron-packager / src / targets.js View on Github external
validateListFromOptions: function validateListFromOptions (opts, name) {
    if (opts.all) return Array.from(supported[name].values())

    let list = opts[name]
    if (!list) {
      if (name === 'arch') {
        list = getHostArch()
      } else {
        list = process[name]
      }
    } else if (list === 'all') {
      return Array.from(supported[name].values())
    }

    if (!Array.isArray(list)) {
      if (typeof list === 'string') {
        list = list.split(/,\s*/)
      } else {
        return unsupportedListOption(name, list, supported[name])
      }
    }

    const officialElectronPackages = usingOfficialElectronPackages(opts)

@electron/get

Utility for downloading artifacts from different versions of Electron

MIT
Latest version published 5 months ago

Package Health Score

84 / 100
Full package analysis