Skip to content

Commit 0f17177

Browse files
authored
feat(cli): copy signature when using secure live updates (#5896)
1 parent 9658fe1 commit 0f17177

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

cli/src/declarations.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,7 @@ export interface LiveUpdateConfig {
523523
channel: string;
524524
autoUpdateMethod: AutoUpdateMethod;
525525
maxVersions?: number;
526+
key?: string;
526527
}
527528

528529
export type AutoUpdateMethod = 'none' | 'background';
@@ -548,4 +549,11 @@ export interface PluginsConfig {
548549
shell: Portal;
549550
apps: Portal[];
550551
};
552+
553+
/**
554+
* Capacitor Live Updates plugin configuration
555+
*
556+
* @since 4.2.0
557+
*/
558+
LiveUpdates?: LiveUpdateConfig;
551559
}

cli/src/tasks/copy.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,14 @@ export async function copy(
8282
usesCapacitorPortals = true;
8383
}
8484

85+
let usesLiveUpdates = false;
86+
if (
87+
allPlugins.filter(plugin => plugin.id === '@capacitor/live-updates')
88+
.length > 0
89+
) {
90+
usesLiveUpdates = true;
91+
}
92+
8593
if (platformName === config.ios.name) {
8694
if (usesCapacitorPortals) {
8795
await copyFederatedWebDirs(config, await config.ios.webDirAbs);
@@ -92,6 +100,9 @@ export async function copy(
92100
config.app.webDirAbs,
93101
);
94102
}
103+
if (usesLiveUpdates) {
104+
await copySecureLiveUpdatesKey(config, config.ios.nativeTargetDirAbs);
105+
}
95106
await copyCapacitorConfig(config, config.ios.nativeTargetDirAbs);
96107
const cordovaPlugins = await getCordovaPlugins(config, platformName);
97108
await handleCordovaPluginsJS(cordovaPlugins, config, platformName);
@@ -105,6 +116,9 @@ export async function copy(
105116
config.app.webDirAbs,
106117
);
107118
}
119+
if (usesLiveUpdates) {
120+
await copySecureLiveUpdatesKey(config, config.android.assetsDirAbs);
121+
}
108122
await copyCapacitorConfig(config, config.android.assetsDirAbs);
109123
const cordovaPlugins = await getCordovaPlugins(config, platformName);
110124
await handleCordovaPluginsJS(cordovaPlugins, config, platformName);
@@ -207,3 +221,34 @@ function isPortal(config: any): config is Portal {
207221
(config as Portal).name !== undefined
208222
);
209223
}
224+
225+
async function copySecureLiveUpdatesKey(config: Config, nativeAbsDir: string) {
226+
if (!config.app.extConfig?.plugins?.LiveUpdates?.key) {
227+
return;
228+
}
229+
230+
const secureLiveUpdatesKeyFile = config.app.extConfig.plugins.LiveUpdates.key;
231+
const keyAbsFromPath = join(config.app.rootDir, secureLiveUpdatesKeyFile);
232+
const keyAbsToPath = join(nativeAbsDir, basename(keyAbsFromPath));
233+
const keyRelToDir = relative(config.app.rootDir, nativeAbsDir);
234+
235+
if (!(await pathExists(keyAbsFromPath))) {
236+
logger.warn(
237+
`Cannot copy Secure Live Updates signature file from ${c.strong(
238+
keyAbsFromPath,
239+
)} to ${keyRelToDir}\n` +
240+
`Signature file does not exist at specified key path.`,
241+
);
242+
243+
return;
244+
}
245+
246+
await runTask(
247+
`Copying Secure Live Updates key from ${c.strong(
248+
secureLiveUpdatesKeyFile,
249+
)} to ${keyRelToDir}`,
250+
async () => {
251+
return fsCopy(keyAbsFromPath, keyAbsToPath);
252+
},
253+
);
254+
}

0 commit comments

Comments
 (0)