Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
prepareDirectories (config: ContainerGeneratorConfig) {
if (!fs.existsSync(config.outDir)) {
shell.mkdir('-p', config.outDir)
} else {
shell.rm('-rf', path.join(config.outDir, '{.*,*}'))
}
if (!fs.existsSync(config.compositeMiniAppDir)) {
shell.mkdir('-p', config.compositeMiniAppDir)
} else {
shell.rm('-rf', path.join(config.compositeMiniAppDir, '{.*,*}'))
}
if (!fs.existsSync(config.pluginsDownloadDir)) {
shell.mkdir('-p', config.pluginsDownloadDir)
} else {
shell.rm('-rf', path.join(config.pluginsDownloadDir, '{.*,*}'))
}
}
pathToYarnLock?: string
} = {}) {
const PLUGINS_DOWNLOAD_DIRECTORY = path.join(workingDirectory, 'plugins')
const OUT_DIRECTORY = path.join(workingDirectory, 'out', generator.platform)
const COMPOSITE_MINIAPP_DIRECTORY = path.join(workingDirectory, 'compositeMiniApp')
const paths : ContainerGeneratorPaths = {
compositeMiniApp: COMPOSITE_MINIAPP_DIRECTORY,
pluginsDownloadDirectory: PLUGINS_DOWNLOAD_DIRECTORY,
outDirectory: OUT_DIRECTORY
}
shell.rm('-rf', PLUGINS_DOWNLOAD_DIRECTORY)
shell.rm('-rf', OUT_DIRECTORY)
shell.rm('-rf', COMPOSITE_MINIAPP_DIRECTORY)
shell.mkdir('-p', PLUGINS_DOWNLOAD_DIRECTORY)
shell.mkdir('-p', OUT_DIRECTORY)
shell.mkdir('-p', COMPOSITE_MINIAPP_DIRECTORY)
sortPlugins(plugins)
const reactNativePlugin = _.find(plugins, p => p.name === 'react-native')
if (!reactNativePlugin) {
throw new Error('react-native was not found in plugins list !')
}
mustacheView = {
nativeAppName,
containerVersion,
miniapps
}
copyPluginToOutput (paths: Object, pluginOutputDirectory: string, pluginPath: PackagePath, pluginConfig: PluginConfig) {
log.debug(`injecting ${pluginPath.basePath} code.`)
const pluginSrcDirectory = path.join(paths.pluginsDownloadDirectory, 'node_modules', pluginPath.basePath, 'android', pluginConfig.android.moduleName, SRC_MAIN_JAVA_DIR, '*')
if (!fs.existsSync(pluginOutputDirectory)) {
shell.mkdir('-p', pluginOutputDirectory)
}
log.debug(`Copying code from ${pluginSrcDirectory} to ${pluginOutputDirectory}`)
shell.cp('-Rf', pluginSrcDirectory, pluginOutputDirectory)
}
async fillHull (apiDependency: PackagePath,
paths: Object,
reactNativeVersion: string,
pluginsPaths: Array,
apis: Array) {
try {
log.debug(`[=== Starting hull filling for api impl gen for ${this.platform} ===]`)
shell.cd(ROOT_DIR)
const outputDirectory = path.join(paths.outDirectory, 'android')
log.debug(`Creating out directory(${outputDirectory}) for android and copying container hull to it.`)
if (!fs.existsSync(outputDirectory)) {
shell.mkdir(outputDirectory)
}
fileUtils.chmodr(READ_WRITE_EXECUTE, outputDirectory)
shell.cp('-Rf', path.join(paths.apiImplHull, 'android', '{.*,*}'), outputDirectory)
const srcOutputDirectory = path.join(outputDirectory, 'lib', SRC_MAIN_JAVA_DIR)
for (let pluginPath: PackagePath of pluginsPaths) {
log.debug(`Copying ${pluginPath.basePath} to ${outputDirectory}`)
await manifest.getPluginConfig(pluginPath).then((pluginConfig) => {
this.copyPluginToOutput(paths, srcOutputDirectory, pluginPath, pluginConfig)
})
}
const editableFiles = await this.generateRequestHandlerClasses(apiDependency, paths, apis)
await this.updateFilePermissions(srcOutputDirectory, editableFiles)
await this.updateBuildGradle(paths, reactNativeVersion, outputDirectory)
function createPluginsDownloadDirectory (pluginsDownloadPath: string) {
shell.rm('-rf', pluginsDownloadPath)
shell.mkdir('-p', pluginsDownloadPath)
}
export async function generateMiniAppsComposite (
miniappsPaths: Array,
outDir: string, {
pathToYarnLock,
extraJsDependencies = []
} : {
pathToYarnLock?: string,
extraJsDependencies?: Array
} = {},
jsApiImplDependencies?: Array) {
if (fs.existsSync(outDir)) {
cleanupMiniAppsCompositeDir(outDir)
} else {
shell.mkdir('-p', outDir)
}
shell.cd(outDir)
let compositePackageJson = {}
if (pathToYarnLock && (_.some(miniappsPaths, p => p.isFilePath || p.isGitPath))) {
log.warn('Yarn lock will not be used as some of the MiniApp paths are file or git based')
pathToYarnLock = undefined
}
if (pathToYarnLock) {
if (_.some(miniappsPaths, m => !m.version)) {
throw new Error('[generateMiniAppsComposite] When providing a yarn lock you cannot pass MiniApps without an explicit version')
}
prepareDirectories (config: ContainerGeneratorConfig) {
if (!fs.existsSync(config.outDir)) {
shell.mkdir('-p', config.outDir)
} else {
shell.rm('-rf', path.join(config.outDir, '{.*,*}'))
}
if (!fs.existsSync(config.compositeMiniAppDir)) {
shell.mkdir('-p', config.compositeMiniAppDir)
} else {
shell.rm('-rf', path.join(config.compositeMiniAppDir, '{.*,*}'))
}
if (!fs.existsSync(config.pluginsDownloadDir)) {
shell.mkdir('-p', config.pluginsDownloadDir)
} else {
shell.rm('-rf', path.join(config.pluginsDownloadDir, '{.*,*}'))
}
}
if (!shouldRegenerate) {
throw Error('An implementation directory already exists')
} else {
forceGenerate = true
}
}
if (forceGenerate && fs.existsSync(outputDirectoryPath)) {
log.info(`Deleting the existing directory and recreating a new one in ${outputDirectoryPath}`)
fileUtils.chmodr('777', outputDirectoryPath)
shell.rm('-Rf', outputDirectoryPath)
} else {
log.debug(`creating output dir: ${outputDirectoryPath}`)
}
shell.mkdir('-p', outputDirectoryPath)
}
static createImplDirectoryAndCopyCommonClasses (paths) {
const outputDir = path.join(paths.outDirectory, 'android', 'lib', SRC_MAIN_JAVA_DIR, API_IMPL_PACKAGE)
if (!fs.existsSync(outputDir)) {
shell.mkdir('-p', outputDir)
}
const resourceDir = path.join(Platform.currentPlatformVersionPath, 'ern-api-impl-gen', 'resources', 'android')
shell.cp(path.join(resourceDir, 'RequestHandlerConfig.java'), outputDir)
shell.cp(path.join(resourceDir, 'RequestHandlerProvider.java'), outputDir)
return {outputDir, resourceDir}
}
}