Skip to content

Commit 8daf985

Browse files
koenpuntfacebook-github-bot
authored andcommitted
match plist indentation with xcode format
Summary: xcode has its own way of indentation of the plist. fixes facebook#11668 Closes facebook#11670 Differential Revision: D4410865 fbshipit-source-id: 8c65e7719d228b07f58b1ccb86b369e319067f02
1 parent 01a0e10 commit 8daf985

File tree

5 files changed

+92
-12
lines changed

5 files changed

+92
-12
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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>CFBundleDevelopmentRegion</key>
6+
<string>en</string>
7+
<key>UISupportedInterfaceOrientations</key>
8+
<array>
9+
<string>UIInterfaceOrientationPortrait</string>
10+
</array>
11+
</dict>
12+
</plist>
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
'use strict';
2+
3+
jest.autoMockOff();
4+
jest.mock('fs');
5+
6+
let plistPath = null;
7+
jest.mock('../../ios/getPlistPath', () => () => plistPath);
8+
9+
const { readFileSync } = require.requireActual('fs')
10+
const fs = require('fs');
11+
12+
const xcode = require('xcode');
13+
const path = require('path');
14+
const writePlist = require('../../ios/writePlist');
15+
16+
const projectPath = path.join(__dirname, '../../__fixtures__/project.pbxproj');
17+
const infoPlistPath = path.join(__dirname, '../../__fixtures__/Info.plist');
18+
19+
fs.__setMockFilesystem({
20+
'Basic': {
21+
'project.pbxproj': readFileSync(projectPath).toString(),
22+
}
23+
});
24+
25+
const project = xcode.project('/Basic/project.pbxproj');
26+
27+
const plist = {
28+
CFBundleDevelopmentRegion: 'en',
29+
UISupportedInterfaceOrientations: [
30+
'UIInterfaceOrientationPortrait'
31+
]
32+
};
33+
34+
describe('ios::writePlist', () => {
35+
beforeEach(() => {
36+
project.parseSync();
37+
fs.writeFileSync.mockReset();
38+
});
39+
40+
it('should write a `.plist` file', () => {
41+
plistPath = '/Basic/Info.plist';
42+
const result = writePlist(project, '/', plist);
43+
const infoPlist = readFileSync(infoPlistPath).toString();
44+
expect(fs.writeFileSync).toHaveBeenCalledWith(plistPath, infoPlist);
45+
});
46+
47+
it('when plistPath is null it should return null', () => {
48+
plistPath = null;
49+
expect(writePlist(project, '/', plist)).toBeNull();
50+
expect(fs.writeFileSync).not.toHaveBeenCalled();
51+
});
52+
});

local-cli/link/ios/copyAssets.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@ const fs = require('fs-extra');
22
const path = require('path');
33
const xcode = require('xcode');
44
const log = require('npmlog');
5-
const plistParser = require('plist');
65
const groupFilesByType = require('../groupFilesByType');
76
const createGroupWithMessage = require('./createGroupWithMessage');
87
const getPlist = require('./getPlist');
9-
const getPlistPath = require('./getPlistPath');
8+
const writePlist = require('./writePlist');
109

1110
/**
1211
* This function works in a similar manner to its Android version,
@@ -38,8 +37,5 @@ module.exports = function linkAssetsIOS(files, projectConfig) {
3837
project.writeSync()
3938
);
4039

41-
fs.writeFileSync(
42-
getPlistPath(project, projectConfig.sourceDir),
43-
plistParser.build(plist)
44-
);
40+
writePlist(project, projectConfig.sourceDir, plist);
4541
};

local-cli/link/ios/unlinkAssets.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@ const fs = require('fs-extra');
22
const path = require('path');
33
const xcode = require('xcode');
44
const log = require('npmlog');
5-
const plistParser = require('plist');
65
const groupFilesByType = require('../groupFilesByType');
76
const getPlist = require('./getPlist');
8-
const getPlistPath = require('./getPlistPath');
7+
const writePlist = require('./writePlist');
98
const difference = require('lodash').difference;
109

1110
/**
@@ -47,8 +46,5 @@ module.exports = function unlinkAssetsIOS(files, projectConfig) {
4746
project.writeSync()
4847
);
4948

50-
fs.writeFileSync(
51-
getPlistPath(project, projectConfig.sourceDir),
52-
plistParser.build(plist)
53-
);
49+
writePlist(project, projectConfig.sourceDir, plist);
5450
};

local-cli/link/ios/writePlist.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
const plistParser = require('plist');
2+
const getPlistPath = require('./getPlistPath');
3+
const fs = require('fs');
4+
5+
/**
6+
* Writes to Info.plist located in the iOS project
7+
*
8+
* Returns `null` if INFOPLIST_FILE is not specified or file is non-existent.
9+
*/
10+
module.exports = function writePlist(project, sourceDir, plist) {
11+
const plistPath = getPlistPath(project, sourceDir);
12+
13+
if (!plistPath) {
14+
return null;
15+
}
16+
17+
// We start with an offset of -1, because Xcode maintains a custom
18+
// indentation of the plist.
19+
// Ref: https://github.com/facebook/react-native/issues/11668
20+
return fs.writeFileSync(
21+
plistPath,
22+
plistParser.build(plist, { indent: '\t', offset: -1 }) + '\n'
23+
);
24+
};

0 commit comments

Comments
 (0)