xcparse
v0.0.3
Published
pbxproj parser
Downloads
16,355
Readme
xcparse
This project is a ~~work in progress / proof of concept~~ seemingly spec compliant
pbxproj
parser. The API is subject to breaking changes.
yarn add xcparse
Website https://xcode-seven.vercel.app/
Here is a diagram of the grammar used for parsing:
Why
The most popular solution for parsing pbxproj files is a very old package by Cordova called xcode.
But xcode
has some major issues:
- Inaccurate parsing: strings can be quoted incorrectly very often, lists often don't work.
- Outdated: values for App Clips, iMessage Sticker packs, etc are missing.
- Untyped: TypeScript is a crutch I proudly support.
- Slow: PEG.js is not very fast (benchmark).
- Feature Incomplete: Missing the
Data
type (<xx xx xx>
).
Solution
- Unlike the xcode package which uses PEG.js, this implementation uses Chevrotain.
- This project support the Data type
<xx xx xx>
. - Unopinionated: this could change in the future :] but if it does we'll use modern graph API patterns that are typed.
- This implementation also appears to be more stable since we follow the best guess pbxproj spec.
- String parsing is the trickiest part. This package uses a port of the actual CFOldStylePlist parser which is an approach first used at scale by the CocoaPods team (originally credited to Samantha Marshall).
How
The parsing is very simple (simplicity is the key).
pbxproj
is an "old-style plist" (or ASCII Plist), this means it should be possible to represent it as any other static configuration file type like JSON or XML.
We support the following types: Object
, Array
, Data
, String
. Notably, we avoid dealing with Integer
, Double
, Boolean since they appear to not exist in the format.
TODO
- [x] Reading.
- [x] Writing.
- [x] Escaping scripts and header search paths.
- [x] Use a fork of chevrotain -- it's way too large for what it offers.
- [ ] Generating UUIDs.
- [ ] The API would probably be implemented using unist
- [ ] Docs
Docs
Docs are in the works. For now, you can refer to the types and the estimated pbxproj
spec.
The API will change in the future, for now we have two methods:
import {
/** Given a stringified `pbxproj`, return a JSON representation of the object. */
parse,
/** Given a JSON representation of a `pbxproj`, return a `.pbxproj` string that can be parsed by Xcode. */
build
} from 'xctrace'
import fs from 'fs';
import path from 'path';
const pbxproj = parse(fs.readFileSync('/path/to/project.pbxproj'));
const pbxprojString = build(pbxproj);