Skip to content

Commit f66415a

Browse files
committed
Add new XML operations to ios. Closes #79
1 parent 4f93eda commit f66415a

File tree

4 files changed

+115
-0
lines changed

4 files changed

+115
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>com.apple.developer.parent-application-identifiers</key>
6+
<array>
7+
<string>$(AppIdentifierPrefix)io.ionic.wowzaStarter</string>
8+
</array>
9+
</dict>
10+
</plist>

packages/configure/src/operations/ios/xml.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ export default async function execute(ctx: Context, op: Operation) {
1212
throw new Error(`No such XML file for xml operation: ${entry.file}`);
1313
}
1414

15+
await xmlFile.load();
16+
1517
if (entry.attrs) {
1618
await xmlFile.setAttrs(entry.target, entry.merge);
1719
} else if (entry.inject) {
@@ -20,6 +22,10 @@ export default async function execute(ctx: Context, op: Operation) {
2022
await xmlFile.mergeFragment(entry.target, entry.merge);
2123
} else if (entry.replace) {
2224
await xmlFile.replaceFragment(entry.target, entry.replace);
25+
} else if (entry.delete) {
26+
await xmlFile.deleteNodes(entry.delete);
27+
} else if (entry.deleteAttributes) {
28+
await xmlFile.deleteAttributes(entry.target, entry.deleteAttributes);
2329
}
2430
}
2531
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import { copy, readFile } from '@ionic/utils-fs';
2+
import { join } from 'path';
3+
import tempy from 'tempy';
4+
5+
import { Context, loadContext } from '../../src/ctx';
6+
import { IosXmlOperation, Operation } from '../../src/definitions';
7+
import Op from '../../src/operations/ios/xml';
8+
import { makeOp } from '../utils';
9+
10+
describe('op: ios.xml', () => {
11+
let dir: string;
12+
let ctx: Context;
13+
14+
beforeEach(async () => {
15+
dir = tempy.directory();
16+
17+
await copy('../common/test/fixtures/ios-and-android', dir);
18+
19+
ctx = await loadContext(dir);
20+
ctx.args.quiet = true;
21+
});
22+
23+
it('should delete attributes', async () => {
24+
const op: IosXmlOperation = makeOp('ios', 'xml', [
25+
{
26+
file: 'xml-file.xml',
27+
target: '//plist',
28+
deleteAttributes: [
29+
'version'
30+
]
31+
},
32+
]);
33+
34+
await Op(ctx, op as Operation);
35+
36+
await ctx.project.commit();
37+
38+
const file = await readFile(join(dir, 'ios', 'App', 'xml-file.xml'), { encoding: 'utf-8' });
39+
//console.log(file);
40+
expect(file.trim()).toBe(`
41+
<?xml version="1.0" encoding="UTF-8" ?>
42+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
43+
<plist>
44+
<dict>
45+
<key>com.apple.developer.parent-application-identifiers</key>
46+
<array>
47+
<string>$(AppIdentifierPrefix)io.ionic.wowzaStarter</string>
48+
</array>
49+
</dict>
50+
</plist>
51+
`.trim());
52+
});
53+
54+
it('should delete nodes', async () => {
55+
const op: IosXmlOperation = makeOp('ios', 'xml', [
56+
{
57+
file: 'xml-file.xml',
58+
delete: '//array'
59+
},
60+
]);
61+
62+
await Op(ctx, op as Operation);
63+
64+
await ctx.project.commit();
65+
66+
const file = await readFile(join(dir, 'ios', 'App', 'xml-file.xml'), { encoding: 'utf-8' });
67+
//console.log(file);
68+
expect(file.trim()).toBe(`
69+
<?xml version="1.0" encoding="UTF-8" ?>
70+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
71+
<plist version="1.0">
72+
<dict>
73+
<key>com.apple.developer.parent-application-identifiers</key>
74+
</dict>
75+
</plist>
76+
`.trim());
77+
});
78+
79+
});

packages/website/docs/configuration-tool.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,3 +491,23 @@ platforms:
491491
data:
492492
field: "MY_FIELD"
493493
```
494+
495+
### `xml`
496+
497+
Modifies XML files relative to the root of the iOS project. This operation supports the following XML file modifications:
498+
499+
- `attrs` updates the attributes of the given `target` node.
500+
- `merge` merges the given XML tree supplied to `merge` with the given `target`
501+
- `inject` injects the given XML tree supplied to `inject` inside of the given `target`
502+
- `delete` deletes nodes specified by `delete` in XPath format.
503+
- `deleteAttributes` deletes the given attributes in `deleteAttributes` inside of the given `target`
504+
505+
```yaml
506+
platforms:
507+
android:
508+
xml:
509+
- file: file.xml
510+
target: entries/field
511+
merge: |
512+
<string>Value</string>
513+
```

0 commit comments

Comments
 (0)