Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
)
log.info('Regenerating JS bundle only')
await runCaudronBundleGen(napDescriptor, {
compositeMiniAppDir,
outDir,
})
// Update container metadata
const metadata = await fileUtils.readJSON(
getContainerMetadataPath(outDir)
)
const miniapps = await cauldron.getContainerMiniApps(napDescriptor)
const jsApiImpls = await cauldron.getContainerJsApiImpls(napDescriptor)
metadata.miniApps = miniapps.map(m => m.fullPath)
metadata.jsApiImpls = jsApiImpls.map(j => j.fullPath)
metadata.ernVersion = Platform.currentVersion
await fileUtils.writeJSON(getContainerMetadataPath(outDir), metadata)
} catch (e) {
log.error(`Something went wrong trying to regenerate JS bundle only`)
log.error(e)
log.error(`Falling back to full Container generation`)
jsBundleOnly = false
}
} else if (publishOnly) {
log.info(`No changes from ${currentContainerVersion}`)
log.info('Only publishing')
// Update container metadata
const metadata = await fileUtils.readJSON(
getContainerMetadataPath(outDir)
)
metadata.ernVersion = Platform.currentVersion
await fileUtils.writeJSON(getContainerMetadataPath(outDir), metadata)
}
const compositeMiniAppDir = createTmpDir()
// Only regenerate bundle if possible
if (jsBundleOnly) {
try {
log.info(
`No native dependencies changes from ${currentContainerVersion}`
)
log.info('Regenerating JS bundle only')
await runCaudronBundleGen(napDescriptor, {
compositeMiniAppDir,
outDir,
})
// Update container metadata
const metadata = await fileUtils.readJSON(
getContainerMetadataPath(outDir)
)
const miniapps = await cauldron.getContainerMiniApps(napDescriptor)
const jsApiImpls = await cauldron.getContainerJsApiImpls(napDescriptor)
metadata.miniApps = miniapps.map(m => m.fullPath)
metadata.jsApiImpls = jsApiImpls.map(j => j.fullPath)
metadata.ernVersion = Platform.currentVersion
await fileUtils.writeJSON(getContainerMetadataPath(outDir), metadata)
} catch (e) {
log.error(`Something went wrong trying to regenerate JS bundle only`)
log.error(e)
log.error(`Falling back to full Container generation`)
jsBundleOnly = false
}
} else if (publishOnly) {
log.info(`No changes from ${currentContainerVersion}`)
log.info('Only publishing')
const pluginSourcePath = await config.composite.getNativeDependencyPath(
plugin
)
if (!pluginSourcePath) {
throw new Error(`path to ${plugin.basePath} not found in composite`)
}
if (await coreUtils.isDependencyPathNativeApiImpl(pluginSourcePath)) {
// For native api implementations, if a 'ern.pluginConfig' object
// exists in its package.json, replace pluginConfig with this one.
const pluginPackageJson = await readPackageJson(pluginSourcePath)
if (pluginPackageJson.ern.pluginConfig) {
pluginConfig = pluginPackageJson.ern.pluginConfig
}
populateApiImplMustacheView(pluginSourcePath, mustacheView, true)
}
pathToPluginProject = path.join(
pluginSourcePath,
pluginConfig.android.root
)
shell.pushd(pathToPluginProject)
try {
if (await coreUtils.isDependencyPathNativeApiImpl(pluginSourcePath)) {
// Special handling for native api implementation as we don't
// want to copy the API and bridge code (part of native api implementations projects)
const relPathToApiImplSource = path.normalize(
'lib/src/main/java/com/ern'
)
const absPathToCopyPluginSourceTo = path.join(
// If force or skipFinalConfirmation was not provided as option, we ask user for confirmation before proceeding
// with code-push publication
const userConfirmedCodePushPublication = force || skipConfirmation || await askUserToConfirmCodePushPublication(miniAppsToBeCodePushed, jsApiImplsToBeCodePushed)
if (!userConfirmedCodePushPublication) {
return log.info('CodePush publication aborted')
} else {
log.info('Getting things ready for CodePush publication')
}
const pathsToMiniAppsToBeCodePushed = _.map(miniAppsToBeCodePushed, m => PackagePath.fromString(m.toString()))
const pathToJsApiImplsToBeCodePushed = _.map(jsApiImplsToBeCodePushed, j => PackagePath.fromString(j.toString()))
await spin('Generating composite module',
generateMiniAppsComposite(pathsToMiniAppsToBeCodePushed, tmpWorkingDir, {pathToYarnLock}, pathToJsApiImplsToBeCodePushed))
const bundleOutputDirectory = path.join(tmpWorkingDir, 'bundleOut')
shell.mkdir('-p', bundleOutputDirectory)
const platform = napDescriptor.platform || ''
const bundleOutputPath = platform === 'android'
? path.join(bundleOutputDirectory, 'index.android.bundle')
: path.join(bundleOutputDirectory, 'MiniApp.jsbundle')
await spin('Generating composite bundle for miniapps', reactnative.bundle({
entryFile: `index.${platform}.js`,
dev: false,
bundleOutput: bundleOutputPath,
platform,
assetsDest: bundleOutputDirectory
}))
public async buildAndroidPluginsViews(
plugins: PackagePath[],
mustacheView: any
): Promise {
mustacheView.plugins = await generatePluginsMustacheViews(
plugins,
'android'
)
const reactNativeCodePushPlugin = _.find(
plugins,
p => p.basePath === 'react-native-code-push'
)
if (reactNativeCodePushPlugin) {
mustacheView.isCodePushPluginIncluded = true
}
}
}
public async buildiOSPluginsViews(
plugins: PackagePath[],
mustacheView: any
): Promise {
mustacheView.plugins = await generatePluginsMustacheViews(plugins, 'ios')
}
function getGeneratorForPlatform (platform: string) : ContainerGenerator {
switch (platform) {
case 'android': return new AndroidGenerator()
case 'ios': return new IosGenerator()
default: throw new Error(`Unsupported platform : ${platform}`)
}
}
function getGeneratorForPlatform (platform: string) : ContainerGenerator {
switch (platform) {
case 'android': return new AndroidGenerator()
case 'ios': return new IosGenerator()
default: throw new Error(`Unsupported platform : ${platform}`)
}
}
public static isContainerPath(path: string, extraErrorMessage: string = '') {
if (!fs.existsSync(getContainerMetadataPath(path))) {
throw new Error(
`${path} is not a path to a Container\n${extraErrorMessage}`
)
}
}
for (const plugin of plugins) {
const pluginConfig = await manifest.getPluginConfig(
plugin,
projectSpec.projectName
)
if (!pluginConfig) {
continue
}
const pluginSourcePath = await composite.getNativeDependencyPath(plugin)
if (!pluginSourcePath) {
throw new Error(`path to ${plugin.basePath} not found in composite`)
}
if (await utils.isDependencyPathNativeApiImpl(pluginSourcePath)) {
populateApiImplMustacheView(pluginSourcePath, mustacheView, true)
}
}
if (mustacheView.apiImplementations) {
mustacheView.hasApiImpl = true
for (const api of mustacheView.apiImplementations) {
if (api.hasConfig) {
mustacheView.hasAtleastOneApiImplConfig = true
break
}
}
}
}
}