Skip to content

Commit ca3d1d2

Browse files
authored
chore: improve ci workflow, ensure built parser committed, cleanup (#166)
* chore: create npm build run-script * chore: update npm test to include linting * chore: add DEVELOPMENT.md * chore: update README.md * chore(workflow): check for uncommited changes * chore: commit build diff (license header & new-lines) * fix(workflow): setup-node's node-version arg
1 parent 9c89212 commit ca3d1d2

7 files changed

Lines changed: 203 additions & 56 deletions

File tree

.github/workflows/ci.yml

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,36 @@ jobs:
8080

8181
- uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
8282
with:
83-
node.version: ${{ matrix.node.version }}
83+
node-version: ${{ matrix.node.version }}
8484

8585
- name: Environment Information
8686
run: |
8787
node --version
8888
npm --version
8989
90-
- name: npm install and test
91-
run: npm cit
90+
- name: npm install
91+
run: npm ci
92+
env:
93+
CI: true
94+
NODE_OPTIONS: ${{ matrix.node.options }}
95+
96+
- name: Build parser
97+
run: npm run build
98+
env:
99+
CI: true
100+
NODE_OPTIONS: ${{ matrix.node.options }}
101+
102+
- name: Check for uncommitted changes
103+
run: |
104+
if ! git diff --exit-code; then
105+
echo ""
106+
echo "::error::Detected changes that appear to not be committed."
107+
echo "::error::Please run 'npm run build' and commit the built parser."
108+
exit 1
109+
fi
110+
111+
- name: npm test
112+
run: npm t
92113
env:
93114
CI: true
94115
NODE_OPTIONS: ${{ matrix.node.options }}

DEVELOPMENT.md

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
<!--
2+
#
3+
# Licensed to the Apache Software Foundation (ASF) under one
4+
# or more contributor license agreements. See the NOTICE file
5+
# distributed with this work for additional information
6+
# regarding copyright ownership. The ASF licenses this file
7+
# to you under the Apache License, Version 2.0 (the
8+
# "License"); you may not use this file except in compliance
9+
# with the License. You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing,
14+
# software distributed under the License is distributed on an
15+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
# KIND, either express or implied. See the License for the
17+
# specific language governing permissions and limitations
18+
# under the License.
19+
#
20+
-->
21+
22+
# Development
23+
24+
## Setup
25+
26+
1. Install npm dependencies.
27+
28+
```bash
29+
npm install
30+
```
31+
32+
## Updating the parser
33+
34+
If there's a problem parsing, you will want to edit the grammar under `lib/parser/pbxproj.pegjs`.
35+
36+
Tests under the `test/parser` directory will compile the parser from the grammar. The other tests will use the prebuilt parser (`lib/parser/pbxproj.js`).
37+
38+
To build the parser js file after editing the grammar, run:
39+
40+
```bash
41+
npm run build
42+
```
43+
44+
## Unit Testing
45+
46+
Our projects include unit tests, which can be run with:
47+
48+
```bash
49+
npm test
50+
```
51+
52+
## Linting
53+
54+
During development, you should run the linter to ensure the code follows our coding standards:
55+
56+
```bash
57+
npm run lint
58+
```
59+
60+
> [!NOTE]
61+
> Running `npm test` will also execute the linter before running the tests.
62+
63+
### Fixing Lint Issues
64+
65+
In many cases, lint warnings can be fixed automatically with:
66+
67+
```bash
68+
npm run lint:fix
69+
```
70+
71+
If an issue cannot be resolved automatically, it will require manual review and correction.
72+
73+
## Building from Source
74+
75+
1. **Clone the repository** locally.
76+
77+
2. **Change to the repository directory.**
78+
79+
3. **Install dependencies:**
80+
81+
```bash
82+
npm install
83+
```
84+
85+
Installs all production and development dependencies required for using and developing the package.
86+
87+
4. **Update sub-dependencies:**
88+
89+
```bash
90+
npm update
91+
```
92+
93+
Over time, `package-lock.json` can become stale and may trigger audit warnings. `npm update` refreshes dependencies within the pinned versions.
94+
95+
Under normal circumstances, users install the published package from the npm registry, which does **not** include its own `package-lock.json`. Instead, npm resolves and installs the latest compatible dependency versions at install time, which may result in no audit warnings.
96+
97+
Running `npm update` locally can provide a more accurate representation of current npm audit results for the project.
98+
99+
5. **Generate a tarball:**
100+
101+
```bash
102+
npm pack
103+
```
104+
105+
Creates a `.tgz` tarball file in the `.asf-release` directory.

Makefile

Lines changed: 0 additions & 22 deletions
This file was deleted.

README.md

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -37,39 +37,23 @@ based on donated code from [alunny / node-xcode](https://github.com/alunny/node-
3737
## Example
3838

3939
```js
40-
// API is a bit wonky right now
41-
var xcode = require('xcode'),
42-
fs = require('fs'),
43-
projectPath = 'myproject.xcodeproj/project.pbxproj',
44-
myProj = xcode.project(projectPath);
40+
const fs = require('node:fs');
41+
const xcode = require('xcode');
4542

46-
// parsing is async, in a different process
43+
// Path to the Xcode project's project.pbxproj file.
44+
const projectPath = 'myproject.xcodeproj/project.pbxproj';
45+
// Create a PBXProject instance for the project.
46+
const myProj = xcode.project(projectPath);
47+
48+
// Parse the project file asynchronously before making changes.
4749
myProj.parse(function (err) {
4850
myProj.addHeaderFile('foo.h');
4951
myProj.addSourceFile('foo.m');
5052
myProj.addFramework('FooKit.framework');
5153

54+
// Write the updated project back to disk.
5255
fs.writeFileSync(projectPath, myProj.writeSync());
53-
console.log('new project written');
56+
57+
console.log('New project written');
5458
});
5559
```
56-
57-
## Working on the parser
58-
59-
If there's a problem parsing, you will want to edit the grammar under
60-
`lib/parser/pbxproj.pegjs`. You can test it online with the PEGjs online thingy
61-
at https://pegjs.org/online - I have had some mixed results though.
62-
63-
Tests under the `test/parser` directory will compile the parser from the
64-
grammar. Other tests will use the prebuilt parser (`lib/parser/pbxproj.js`).
65-
66-
To rebuild the parser js file after editing the grammar, run:
67-
68-
npm run pegjs
69-
70-
(and be sure to restore the Apache license notice in
71-
`lib/parser/pbxproj.js` before committing)
72-
73-
## License
74-
75-
Apache V2

bin/generate-pbxproj-parser.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
Licensed to the Apache Software Foundation (ASF) under one
3+
or more contributor license agreements. See the NOTICE file
4+
distributed with this work for additional information
5+
regarding copyright ownership. The ASF licenses this file
6+
to you under the Apache License, Version 2.0 (the
7+
"License"); you may not use this file except in compliance
8+
with the License. You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing,
13+
software distributed under the License is distributed on an
14+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
KIND, either express or implied. See the License for the
16+
specific language governing permissions and limitations
17+
under the License.
18+
*/
19+
20+
const fs = require('node:fs');
21+
const path = require('node:path');
22+
const peg = require('pegjs');
23+
24+
const ROOT_DIR = path.join(__dirname, '..');
25+
const parserDir = path.join(ROOT_DIR, 'lib/parser');
26+
27+
// Path to grammar file
28+
const grammarFilePath = path.join(parserDir, 'pbxproj.pegjs');
29+
// Path to where the parser file is outputted
30+
const outputFilePath = path.join(parserDir, 'pbxproj.js');
31+
32+
// Fetches the grammar file content and builds the output data.
33+
const grammarData = fs.readFileSync(grammarFilePath, 'utf8');
34+
const outputData = peg.generate(grammarData, {
35+
output: 'source',
36+
format: 'commonjs'
37+
});
38+
39+
const asfLicenseHeader = `/*
40+
Licensed to the Apache Software Foundation (ASF) under one
41+
or more contributor license agreements. See the NOTICE file
42+
distributed with this work for additional information
43+
regarding copyright ownership. The ASF licenses this file
44+
to you under the Apache License, Version 2.0 (the
45+
"License"); you may not use this file except in compliance
46+
with the License. You may obtain a copy of the License at
47+
48+
http://www.apache.org/licenses/LICENSE-2.0
49+
50+
Unless required by applicable law or agreed to in writing,
51+
software distributed under the License is distributed on an
52+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
53+
KIND, either express or implied. See the License for the
54+
specific language governing permissions and limitations
55+
under the License.
56+
*/
57+
`;
58+
59+
// Append the Apache license header to the top of the built file.
60+
fs.writeFileSync(outputFilePath, `${asfLicenseHeader}${outputData}`);

lib/parser/pbxproj.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/**
1+
/*
22
Licensed to the Apache Software Foundation (ASF) under one
33
or more contributor license agreements. See the NOTICE file
44
distributed with this work for additional information
@@ -16,7 +16,6 @@
1616
specific language governing permissions and limitations
1717
under the License.
1818
*/
19-
2019
/*
2120
* Generated by PEG.js 0.10.0.
2221
*

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
"pegjs": "^0.10.0"
1818
},
1919
"scripts": {
20-
"pegjs": "node_modules/.bin/pegjs lib/parser/pbxproj.pegjs",
20+
"build": "node bin/generate-pbxproj-parser.js",
2121
"lint": "eslint .",
2222
"lint:fix": "npm run lint -- --fix",
23-
"test": "node --test --experimental-test-coverage --test-reporter=spec --test-reporter=lcov --test-reporter-destination=stdout --test-reporter-destination=lcov.info"
23+
"test": "npm run lint && node --test --experimental-test-coverage --test-reporter=spec --test-reporter=lcov --test-reporter-destination=stdout --test-reporter-destination=lcov.info"
2424
},
2525
"license": "Apache-2.0"
2626
}

0 commit comments

Comments
 (0)