Skip to content

Commit

Permalink
feat(cli): supports secure live updates in Portals for Capacitor conf…
Browse files Browse the repository at this point in the history
…ig (#5955)
  • Loading branch information
carlpoole authored Oct 3, 2022
1 parent 6d4e620 commit a309b45
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 12 deletions.
1 change: 1 addition & 0 deletions cli/src/declarations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,7 @@ export interface PluginsConfig {
Portals?: {
shell: Portal;
apps: Portal[];
liveUpdatesKey?: string;
};

/**
Expand Down
45 changes: 33 additions & 12 deletions cli/src/tasks/copy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,31 +97,53 @@ export async function copy(
if (platformName === config.ios.name) {
if (usesCapacitorPortals) {
await copyFederatedWebDirs(config, await config.ios.webDirAbs);
if (config.app.extConfig?.plugins?.Portals?.liveUpdatesKey) {
await copySecureLiveUpdatesKey(
config.app.extConfig.plugins.Portals.liveUpdatesKey,
config.app.rootDir,
config.ios.nativeTargetDirAbs,
);
}
} else {
await copyWebDir(
config,
await config.ios.webDirAbs,
config.app.webDirAbs,
);
}
if (usesLiveUpdates) {
await copySecureLiveUpdatesKey(config, config.ios.nativeTargetDirAbs);
if (usesLiveUpdates && config.app.extConfig?.plugins?.LiveUpdates?.key) {
await copySecureLiveUpdatesKey(
config.app.extConfig.plugins.LiveUpdates.key,
config.app.rootDir,
config.ios.nativeTargetDirAbs,
);
}
await copyCapacitorConfig(config, config.ios.nativeTargetDirAbs);
const cordovaPlugins = await getCordovaPlugins(config, platformName);
await handleCordovaPluginsJS(cordovaPlugins, config, platformName);
} else if (platformName === config.android.name) {
if (usesCapacitorPortals) {
await copyFederatedWebDirs(config, config.android.webDirAbs);
if (config.app.extConfig?.plugins?.Portals?.liveUpdatesKey) {
await copySecureLiveUpdatesKey(
config.app.extConfig.plugins.Portals.liveUpdatesKey,
config.app.rootDir,
config.android.assetsDirAbs,
);
}
} else {
await copyWebDir(
config,
config.android.webDirAbs,
config.app.webDirAbs,
);
}
if (usesLiveUpdates) {
await copySecureLiveUpdatesKey(config, config.android.assetsDirAbs);
if (usesLiveUpdates && config.app.extConfig?.plugins?.LiveUpdates?.key) {
await copySecureLiveUpdatesKey(
config.app.extConfig.plugins.LiveUpdates.key,
config.app.rootDir,
config.android.assetsDirAbs,
);
}
await copyCapacitorConfig(config, config.android.assetsDirAbs);
const cordovaPlugins = await getCordovaPlugins(config, platformName);
Expand Down Expand Up @@ -229,15 +251,14 @@ function isPortal(config: any): config is Portal {
);
}

async function copySecureLiveUpdatesKey(config: Config, nativeAbsDir: string) {
if (!config.app.extConfig?.plugins?.LiveUpdates?.key) {
return;
}

const secureLiveUpdatesKeyFile = config.app.extConfig.plugins.LiveUpdates.key;
const keyAbsFromPath = join(config.app.rootDir, secureLiveUpdatesKeyFile);
async function copySecureLiveUpdatesKey(
secureLiveUpdatesKeyFile: string,
rootDir: string,
nativeAbsDir: string,
) {
const keyAbsFromPath = join(rootDir, secureLiveUpdatesKeyFile);
const keyAbsToPath = join(nativeAbsDir, basename(keyAbsFromPath));
const keyRelToDir = relative(config.app.rootDir, nativeAbsDir);
const keyRelToDir = relative(rootDir, nativeAbsDir);

if (!(await pathExists(keyAbsFromPath))) {
logger.warn(
Expand Down

0 comments on commit a309b45

Please sign in to comment.