Skip to content

Commit 3a8806b

Browse files
committed
Add copy from URL support to ios copy command. #114
1 parent 52b5afe commit 3a8806b

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

packages/project/src/ios/project.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import plist from 'plist';
22
import path, { join } from 'path';
3+
import fetch from 'cross-fetch';
34
import { copy, pathExists, readdir, writeFile } from '@ionic/utils-fs';
45

56
import { parsePbxProject, pbxReadString, pbxSerializeString } from "../util/pbx";
@@ -482,12 +483,18 @@ export class IosProject extends PlatformProject {
482483
this.project.vfs.set(filename, parsed);
483484
}
484485

485-
copyFile(src: string, dest: string): Promise<void> {
486+
async copyFile(src: string, dest: string): Promise<void> {
486487
if (!this.project?.config?.ios?.path) {
487488
return Promise.reject();
488489
}
489-
const srcPath = join(this.project.config.ios.path, src);
490+
490491
const destPath = join(this.project.config.ios.path, dest);
492+
493+
if (/^(https?:\/\/)/.test(src)) {
494+
const res = await fetch(src);
495+
return writeFile(destPath, Buffer.from(await res.arrayBuffer()));
496+
}
497+
const srcPath = join(this.project.config.ios.path, src);
491498
return copy(srcPath, destPath);
492499
}
493500

packages/project/test/project.ios.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,13 @@ describe('project - ios standard', () => {
374374
const destContents = await readFile(dest);
375375
expect(srcContents).toEqual(destContents);
376376
});
377+
378+
it('should copy URL', async () => {
379+
await project.ios?.copyFile('https://via.placeholder.com/150C', 'placeholder.png');
380+
const dest = join(dir, 'ios/App', 'placeholder.png');
381+
const destContents = await readFile(dest);
382+
expect(destContents.length).toBeGreaterThan(0);
383+
});
377384
});
378385

379386
describe('ios - no info plist case', () => {

0 commit comments

Comments
 (0)