How to use the ern-orchestrator.parseJsonFromStringOrFile function in ern-orchestrator

To help you get started, we’ve selected a few ern-orchestrator 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-local-cli / src / commands / cauldron / add / publisher.ts View on Github external
}
      // ... and that it is a properly formatted json file
      const cauldronFile = await cauldron.getFile({ cauldronFilePath: extra })
      await parseJsonFromStringOrFile(cauldronFile.toString())
      extraObj = extra
    } else {
      // Local file path to json file or json string.
      // In that case, the extra property set for this publisher
      // in Cauldron, will be the the json string, or the
      // content of the json file, as such
      // For example :
      // "extra": {
      //   "artifactId": "app-container",
      //   "groupId": "com.company.app"
      // }
      extraObj = await parseJsonFromStringOrFile(extra)
    }
  }

  const p: ContainerPublisher = await getPublisher(publisher)

  if (descriptor && !p.platforms.includes(descriptor.platform!)) {
    throw new Error(
      `The ${p.name} publisher does not support ${descriptor.platform} platform`
    )
  }

  await cauldron.addPublisher(publisher, p.platforms, descriptor, url, extraObj)
  log.info(`${publisher} publisher successfully added to ${descriptor}`)
}
github electrode-io / electrode-native / ern-local-cli / src / commands / create-container.ts View on Github external
`${outDir} directory exists and is not empty.
Output directory should either not exist (it will be created) or should be empty.`
      )
    }
  }

  compositeDir = compositeDir || createTmpDir()

  const cauldron = await getActiveCauldron({ throwIfNoActiveCauldron: false })
  if (!cauldron && !miniapps) {
    throw new Error(
      "A Cauldron must be active, if you don't explicitly provide miniapps"
    )
  }

  const extraObj = (extra && (await parseJsonFromStringOrFile(extra))) || {}

  // Full native application selector was not provided.
  // Ask the user to select a completeNapDescriptor from a list
  // containing all the native applications versions in the cauldron
  // Not needed if miniapps are directly provided
  if (!descriptor && !miniapps) {
    descriptor = await askUserToChooseANapDescriptorFromCauldron({
      onlyNonReleasedVersions: true,
    })
  }

  if (descriptor) {
    await logErrorAndExitIfNotSatisfied({
      napDescriptorExistInCauldron: {
        descriptor,
        extraErrorMessage:
github electrode-io / electrode-native / ern-local-cli / src / commands / cauldron / add / publisher.ts View on Github external
//
      // Cauldron file path.
      // In that case, the extra property set for this publisher
      // in Cauldron, will be a string, with its value being
      // the path to the json extra config file stored in
      // Cauldron.
      // For example :
      //  "extra": "cauldron://config/publishers/maven.json"

      // We just validate that the file exist in Cauldron ...
      if (!(await cauldron.hasFile({ cauldronFilePath: extra }))) {
        throw new Error(`File ${extra} does not exist in Cauldron.`)
      }
      // ... and that it is a properly formatted json file
      const cauldronFile = await cauldron.getFile({ cauldronFilePath: extra })
      await parseJsonFromStringOrFile(cauldronFile.toString())
      extraObj = extra
    } else {
      // Local file path to json file or json string.
      // In that case, the extra property set for this publisher
      // in Cauldron, will be the the json string, or the
      // content of the json file, as such
      // For example :
      // "extra": {
      //   "artifactId": "app-container",
      //   "groupId": "com.company.app"
      // }
      extraObj = await parseJsonFromStringOrFile(extra)
    }
  }

  const p: ContainerPublisher = await getPublisher(publisher)
github electrode-io / electrode-native / ern-local-cli / src / commands / run-android.ts View on Github external
}: {
  baseComposite?: PackagePath
  extra?: string
  descriptor?: AppVersionDescriptor
  dev?: boolean
  host?: string
  mainMiniAppName?: string
  miniapps?: PackagePath[]
  port?: string
  usePreviousDevice?: boolean
}) => {
  deviceConfig.updateDeviceConfig('android', usePreviousDevice)

  const miniAppPackageJson = await readPackageJson(process.cwd())
  const extraObj =
    (extra && (await parseJsonFromStringOrFile(extra))) ||
    miniAppPackageJson.ern
      ? miniAppPackageJson.ern
      : {}

  await runMiniApp('android', {
    baseComposite,
    descriptor,
    dev,
    extra: extraObj,
    host,
    mainMiniAppName,
    miniapps,
    port,
  })
  process.exit(0)
}
github electrode-io / electrode-native / ern-local-cli / src / commands / publish-container.ts View on Github external
platform: NativePlatform
  publisher: PackagePath
  url: string
  version: string
}) => {
  containerPath =
    containerPath || Platform.getContainerGenOutDirectory(platform)

  await logErrorAndExitIfNotSatisfied({
    isContainerPath: {
      extraErrorMessage: `Make sure that ${containerPath} is the root of a Container project`,
      p: containerPath!,
    },
  })

  const extraObj = extra && (await parseJsonFromStringOrFile(extra))

  if (
    publisher.isRegistryPath &&
    !publisher.basePath.startsWith(publisherPackagePrefix)
  ) {
    publisher = publisher.version
      ? PackagePath.fromString(
          `${publisherPackagePrefix}${publisher.basePath}@${publisher.version}`
        )
      : PackagePath.fromString(`${publisherPackagePrefix}${publisher.basePath}`)
  }

  await publishContainer({
    containerPath,
    containerVersion: version,
    extra: extraObj,
github electrode-io / electrode-native / ern-local-cli / src / commands / cauldron / add / nativeapp.ts View on Github external
))
  ) {
    const mostRecentVersion = await cauldron.getMostRecentNativeApplicationVersion(
      descriptor
    )
    if (
      mostRecentVersion &&
      (await askUserConfirmation(
        `Do you want to copy data from version (${mostRecentVersion.name}) ?`
      ))
    ) {
      copyFromVersion = mostRecentVersion.name
    }
  }

  config = config && (await parseJsonFromStringOrFile(config))

  await kax.task(`Adding ${descriptor}`).run(
    cauldron.addNativeApplicationVersion(descriptor, {
      config,
      copyFromVersion,
      description,
    })
  )

  await kax
    .task('Updating Cauldron')
    .run(cauldron.commitTransaction(`Add ${descriptor} native application`))
  log.info(`${descriptor} successfully added to the the Cauldron`)
}
github electrode-io / electrode-native / ern-local-cli / src / lib / parseArgValue.ts View on Github external
export async function parseArgValue(v: number | string): Promise {
  if (typeof v === 'number') {
    return v
  } else if (v.startsWith(cauldronFileUriScheme)) {
    return parseJsonFromStringOrFile(v)
  } else if (v === 'true') {
    return true
  } else if (v === 'false') {
    return false
  } else if (await fs.pathExists(v)) {
    return parseJsonFromStringOrFile(v)
  } else {
    try {
      return JSON.parse(v)
    } catch (e) {
      return v
    }
  }
}
github electrode-io / electrode-native / ern-local-cli / src / commands / transform-container.ts View on Github external
containerPath?: string
  extra?: string
  platform: NativePlatform
  transformer: PackagePath
}) => {
  containerPath =
    containerPath || Platform.getContainerGenOutDirectory(platform)

  await logErrorAndExitIfNotSatisfied({
    isContainerPath: {
      extraErrorMessage: `Make sure that ${containerPath} is the root of a Container project`,
      p: containerPath!,
    },
  })

  const extraObj = extra && (await parseJsonFromStringOrFile(extra))

  if (
    transformer.isRegistryPath &&
    !transformer.basePath.startsWith(transformerPackagePrefix)
  ) {
    transformer = transformer.version
      ? PackagePath.fromString(
          `${transformerPackagePrefix}${transformer.basePath}@${
            transformer.version
          }`
        )
      : PackagePath.fromString(
          `${transformerPackagePrefix}${transformer.basePath}`
        )
  }