-
Notifications
You must be signed in to change notification settings - Fork 892
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
match plist indentation with xcode format
Summary: xcode has its own way of indentation of the plist. fixes #11668 Closes facebook/react-native#11670 Differential Revision: D4410865 fbshipit-source-id: 8c65e7719d228b07f58b1ccb86b369e319067f02
- Loading branch information
1 parent
69bd272
commit 5b41cdb
Showing
5 changed files
with
92 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>CFBundleDevelopmentRegion</key> | ||
<string>en</string> | ||
<key>UISupportedInterfaceOrientations</key> | ||
<array> | ||
<string>UIInterfaceOrientationPortrait</string> | ||
</array> | ||
</dict> | ||
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
'use strict'; | ||
|
||
jest.autoMockOff(); | ||
jest.mock('fs'); | ||
|
||
let plistPath = null; | ||
jest.mock('../../ios/getPlistPath', () => () => plistPath); | ||
|
||
const { readFileSync } = require.requireActual('fs') | ||
const fs = require('fs'); | ||
|
||
const xcode = require('xcode'); | ||
const path = require('path'); | ||
const writePlist = require('../../ios/writePlist'); | ||
|
||
const projectPath = path.join(__dirname, '../../__fixtures__/project.pbxproj'); | ||
const infoPlistPath = path.join(__dirname, '../../__fixtures__/Info.plist'); | ||
|
||
fs.__setMockFilesystem({ | ||
'Basic': { | ||
'project.pbxproj': readFileSync(projectPath).toString(), | ||
} | ||
}); | ||
|
||
const project = xcode.project('/Basic/project.pbxproj'); | ||
|
||
const plist = { | ||
CFBundleDevelopmentRegion: 'en', | ||
UISupportedInterfaceOrientations: [ | ||
'UIInterfaceOrientationPortrait' | ||
] | ||
}; | ||
|
||
describe('ios::writePlist', () => { | ||
beforeEach(() => { | ||
project.parseSync(); | ||
fs.writeFileSync.mockReset(); | ||
}); | ||
|
||
it('should write a `.plist` file', () => { | ||
plistPath = '/Basic/Info.plist'; | ||
const result = writePlist(project, '/', plist); | ||
const infoPlist = readFileSync(infoPlistPath).toString(); | ||
expect(fs.writeFileSync).toHaveBeenCalledWith(plistPath, infoPlist); | ||
}); | ||
|
||
it('when plistPath is null it should return null', () => { | ||
plistPath = null; | ||
expect(writePlist(project, '/', plist)).toBeNull(); | ||
expect(fs.writeFileSync).not.toHaveBeenCalled(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
const plistParser = require('plist'); | ||
const getPlistPath = require('./getPlistPath'); | ||
const fs = require('fs'); | ||
|
||
/** | ||
* Writes to Info.plist located in the iOS project | ||
* | ||
* Returns `null` if INFOPLIST_FILE is not specified or file is non-existent. | ||
*/ | ||
module.exports = function writePlist(project, sourceDir, plist) { | ||
const plistPath = getPlistPath(project, sourceDir); | ||
|
||
if (!plistPath) { | ||
return null; | ||
} | ||
|
||
// We start with an offset of -1, because Xcode maintains a custom | ||
// indentation of the plist. | ||
// Ref: https://github.com/facebook/react-native/issues/11668 | ||
return fs.writeFileSync( | ||
plistPath, | ||
plistParser.build(plist, { indent: '\t', offset: -1 }) + '\n' | ||
); | ||
}; |