How to use the ern-core.createTmpDir function in ern-core

To help you get started, we’ve selected a few ern-core 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 electrode-io / electrode-native / ern-container-publisher / src / publishContainer.ts View on Github external
export default async function publishContainer(conf: ContainerPublisherConfig) {
  // Duplicate the directory containing generated Container to a temporary
  // directory, and pass this temporary directory to the publisher.
  // This is done because Container generation and publication are
  // clearly distinct (separation of concerns), we don't want the publisher
  // to update the Container generated code for its publication needs.
  // It also ensures that this function can be called multiple times
  // with different publishers for the same Container (idempotent).
  // Otherwise, if publication changes were made to the original Container
  // path, it would be much harder to use a different publisher for the
  // same Container.
  const publicationWorkingDir = createTmpDir()
  shell.cp(
    '-Rf',
    path.join(conf.containerPath, '{.*,*}'),
    publicationWorkingDir
  )
  conf.containerPath = publicationWorkingDir
  conf.ernVersion = Platform.currentVersion

  const publisher = await getPublisher(conf.publisher)

  if (!publisher.platforms.includes(conf.platform)) {
    throw new Error(
      `The ${publisher.name} publisher does not support publication of ${
        conf.platform
      } Containers`
    )
github electrode-io / electrode-native / ern-local-cli / src / commands / list / dependencies.ts View on Github external
}: {
  module?: string
  manifestId?: string
  json?: boolean
}) => {
  if (manifestId) {
    await logErrorAndExitIfNotSatisfied({
      manifestIdExists: {
        id: manifestId,
      },
    })
  }

  let pathToModule = process.cwd()
  if (module) {
    pathToModule = createTmpDir()
    shell.pushd(pathToModule)
    try {
      await yarn.init()
      await yarn.add(PackagePath.fromString(module))
    } finally {
      shell.popd()
    }
  }
  const dependencies = await findNativeDependencies(
    path.join(pathToModule, 'node_modules'),
    { manifestId }
  )

  if (json) {
    process.stdout.write(JSON.stringify(dependencies))
  } else {
github electrode-io / electrode-native / ern-container-gen-android / src / AndroidGenerator.ts View on Github external
public async injectJavaScriptCoreEngine(config: ContainerGeneratorConfig) {
    const jscVersion =
      (config.androidConfig && config.androidConfig.jscVersion) ||
      android.DEFAULT_JSC_VERSION
    const jscVariant =
      (config.androidConfig && config.androidConfig.jscVariant) ||
      android.DEFAULT_JSC_VARIANT
    const workingDir = createTmpDir()
    try {
      shell.pushd(workingDir)
      await yarn.init()
      await yarn.add(PackagePath.fromString(`jsc-android@${jscVersion}.0.0`))
      const jscVersionPath = path.resolve(
        `./node_modules/jsc-android/dist/org/webkit/${jscVariant}/r${jscVersion}`
      )
      const jscAARPath = path.join(
        jscVersionPath,
        `${jscVariant}-r${jscVersion}.aar`
      )
      return new Promise((resolve, reject) => {
        const unzipper = new DecompressZip(jscAARPath)
        const unzipOutDir = createTmpDir()
        const containerJniLibsPath = path.join(
          config.outDir,
github electrode-io / electrode-native / ern-container-gen-android / src / AndroidGenerator.ts View on Github external
public async injectHermesEngine(config: ContainerGeneratorConfig) {
    const hermesVersion =
      (config.androidConfig && config.androidConfig.hermesVersion) ||
      android.DEFAULT_HERMES_VERSION
    const workingDir = createTmpDir()
    try {
      shell.pushd(workingDir)
      await yarn.init()
      await yarn.add(PackagePath.fromString(`hermes-engine@${hermesVersion}`))
      const hermesAarPath = path.resolve(
        `./node_modules/hermes-engine/android/hermes-release.aar`
      )
      return new Promise((resolve, reject) => {
        const unzipper = new DecompressZip(hermesAarPath)
        const unzipOutDir = createTmpDir()
        const containerJniLibsPath = path.join(
          config.outDir,
          'lib/src/main/jniLibs'
        )
        const unzippedJniPath = path.join(unzipOutDir, 'jni')
        unzipper.on('error', err => reject(err))
github electrode-io / electrode-native / ern-orchestrator / src / container.ts View on Github external
napDescriptor,
        constants.CONTAINER_YARN_KEY
      )
    } else {
      log.debug(
        'Bypassing yarn.lock usage as bypassYarnLock flag is set in Cauldron config'
      )
    }
    if (!napDescriptor.platform) {
      throw new Error(`${napDescriptor} does not specify a platform`)
    }

    return kax.task('Bundling MiniApps').run(
      bundleMiniApps(
        miniapps,
        compositeDir || createTmpDir(),
        outDir,
        napDescriptor.platform,
        {
          baseComposite,
          jsApiImplDependencies: jsApiImpls,
          pathToYarnLock: pathToYarnLock || undefined,
          resolutions,
        }
      )
    )
  } catch (e) {
    log.error(`runCauldronBundleGen failed: ${e}`)
    throw e
  }
}
github electrode-io / electrode-native / ern-container-publisher-git / src / index.ts View on Github external
public async publish({
    containerPath,
    containerVersion,
    url,
  }: {
    containerPath: string
    containerVersion: string
    url?: string
  }) {
    const workingGitDir = createTmpDir()

    if (!url) {
      throw new Error('url is required')
    }

    try {
      shell.pushd(workingGitDir)
      const git = gitCli()
      log.debug(`Cloning git repository(${url}) to ${workingGitDir}`)
      await gitCli().cloneAsync(url, '.')
      shell.rm('-rf', `${workingGitDir}/*`)
      shell.cp('-Rf', path.join(containerPath, '{.*,*}'), workingGitDir)
      await git.addAsync('./*')
      await git.commitAsync(`Container v${containerVersion}`)
      await git.tagAsync([`v${containerVersion}`])
      await git.pushAsync('origin', 'master')
github electrode-io / electrode-native / ern-local-cli / src / commands / bundlestore / upload.ts View on Github external
const compositeDir = createTmpDir()
    await kax.task('Generating Composite').run(
      generateComposite({
        baseComposite,
        extraJsDependencies,
        jsApiImplDependencies: jsApiImpls,
        miniApps: miniapps!,
        outDir: compositeDir,
        pathToYarnLock,
        resolutions,
      })
    )

    for (const curPlatform of platforms) {
      const outDir = createTmpDir()
      const bundlePath = path.join(outDir, 'index.bundle')
      const sourceMapPath = path.join(outDir, 'index.map')
      await kax.task(`Bundling MiniApps for ${curPlatform}`).run(
        bundleMiniAppsFromComposite({
          bundleOutput: bundlePath,
          compositeDir,
          dev: !prod,
          outDir,
          platform: curPlatform,
          sourceMapOutput: path.join(outDir, 'index.map'),
        })
      )
      const bundleId = await kax
        .task(`Uploading ${curPlatform} bundle`)
        .run(
          engine.upload({ bundlePath, platform: curPlatform, sourceMapPath })
github electrode-io / electrode-native / ern-local-cli / src / commands / bundlestore / upload.ts View on Github external
)
      } else {
        log.debug(
          'Bypassing yarn.lock usage as bypassYarnLock flag is set in config'
        )
      }
      const compositeGenConfig = await cauldron.getCompositeGeneratorConfig(
        descriptor
      )
      baseComposite =
        baseComposite ||
        (compositeGenConfig && compositeGenConfig.baseComposite)
      resolutions = compositeGenConfig && compositeGenConfig.resolutions
    }

    const compositeDir = createTmpDir()
    await kax.task('Generating Composite').run(
      generateComposite({
        baseComposite,
        extraJsDependencies,
        jsApiImplDependencies: jsApiImpls,
        miniApps: miniapps!,
        outDir: compositeDir,
        pathToYarnLock,
        resolutions,
      })
    )

    for (const curPlatform of platforms) {
      const outDir = createTmpDir()
      const bundlePath = path.join(outDir, 'index.bundle')
      const sourceMapPath = path.join(outDir, 'index.map')
github electrode-io / electrode-native / ern-cauldron-api / src / EphemeralFileStore.ts View on Github external
constructor({ storePath }: { storePath?: string } = {}) {
    this.storePath = storePath || createTmpDir()
    this.transactionPending = false
  }
github electrode-io / electrode-native / ern-container-gen-android / src / AndroidGenerator.ts View on Github external
return new Promise((resolve, reject) => {
        const unzipper = new DecompressZip(jscAARPath)
        const unzipOutDir = createTmpDir()
        const containerJniLibsPath = path.join(
          config.outDir,
          'lib/src/main/jniLibs'
        )
        const unzippedJniPath = path.join(unzipOutDir, 'jni')
        unzipper.on('error', err => reject(err))
        unzipper.on('extract', () => {
          shell.cp('-Rf', unzippedJniPath, containerJniLibsPath)
          resolve()
        })
        unzipper.extract({ path: unzipOutDir })
      })
    } finally {