Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 55 additions & 52 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,68 +1,71 @@
name: CI

on:
push:
branches: [main]
pull_request:
branches: [main]
push:
branches: [main]
pull_request:
branches: [main]

jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v7
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v7

- name: Set up Node.js
uses: actions/setup-node@v6
with:
node-version: 24.x
cache: "npm"
registry-url: "https://registry.npmjs.org/"
- name: Set up Node.js
uses: actions/setup-node@v6
with:
node-version: 24.x
cache: 'npm'
registry-url: 'https://registry.npmjs.org/'

- name: Install Dependencies
run: npm ci
- name: Install Dependencies
run: npm ci

- name: Build PlayCanvas Attribute Parser
run: npm run build
- name: Build PlayCanvas Attribute Parser
run: npm run build

lint:
name: Lint
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v7
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v7

- name: Set up Node.js
uses: actions/setup-node@v6
with:
node-version: 24.x
cache: "npm"
registry-url: "https://registry.npmjs.org/"
- name: Set up Node.js
uses: actions/setup-node@v6
with:
node-version: 24.x
cache: 'npm'
registry-url: 'https://registry.npmjs.org/'

- name: Install Dependencies
run: npm ci
- name: Install Dependencies
run: npm ci

- name: Run ESLint
run: npm run lint
- name: Run Prettier
run: npm run fmt

test:
name: Test
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v7
- name: Run ESLint
run: npm run lint

- name: Set up Node.js
uses: actions/setup-node@v6
with:
node-version: 24.x
cache: "npm"
registry-url: "https://registry.npmjs.org/"
test:
name: Test
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v7

- name: Install Dependencies
run: npm ci
- name: Set up Node.js
uses: actions/setup-node@v6
with:
node-version: 24.x
cache: 'npm'
registry-url: 'https://registry.npmjs.org/'

- name: Run Tests
run: npm test
- name: Install Dependencies
run: npm ci

- name: Run Tests
run: npm test
84 changes: 42 additions & 42 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,47 +1,47 @@
name: Publish

on:
push:
tags:
- "v[0-9]+.[0-9]+.[0-9]+"
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+'

jobs:
publish:
name: Publish
runs-on: ubuntu-latest
if: ${{ github.repository_owner == 'playcanvas' }}
permissions:
contents: write
id-token: write
steps:
- name: Check out code
uses: actions/checkout@v7

- name: Set up Node.js
uses: actions/setup-node@v6
with:
node-version: 24.x
cache: "npm"
registry-url: "https://registry.npmjs.org/"

- name: Install Dependencies
run: npm ci

- name: Build PlayCanvas Attribute Parser
run: npm run build
env:
NODE_ENV: production

- name: Run Publint
run: npm run publint

- name: Publish to npm
run: npm publish --provenance

- name: Create GitHub Release
uses: softprops/action-gh-release@v3
with:
generate_release_notes: true
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
publish:
name: Publish
runs-on: ubuntu-latest
if: ${{ github.repository_owner == 'playcanvas' }}
permissions:
contents: write
id-token: write
steps:
- name: Check out code
uses: actions/checkout@v7

- name: Set up Node.js
uses: actions/setup-node@v6
with:
node-version: 24.x
cache: 'npm'
registry-url: 'https://registry.npmjs.org/'

- name: Install Dependencies
run: npm ci

- name: Build PlayCanvas Attribute Parser
run: npm run build
env:
NODE_ENV: production

- name: Run Publint
run: npm run publint

- name: Publish to npm
run: npm publish --provenance

- name: Create GitHub Release
uses: softprops/action-gh-release@v3
with:
generate_release_notes: true
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4 changes: 4 additions & 0 deletions .mocharc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"spec": "test/**/*.test.js",
"timeout": 10000
}
4 changes: 4 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
dist
types
package-lock.json
test/fixtures
71 changes: 34 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,52 +19,51 @@ Given a script like this:

```javascript
class Rotator extends ScriptType {
/**
* @attribute
* Speed determines how fast to rotate things
*/
speed = new Vec3();

/**
* @attribute
* An array of Entities to rotate
*
* @type {Entity[]}
*/
thingsToRotate;
/**
* @attribute
* Speed determines how fast to rotate things
*/
speed = new Vec3();

/**
* @attribute
* An array of Entities to rotate
*
* @type {Entity[]}
*/
thingsToRotate;
}
```

The parser outputs:


```json
{
"rotator": {
"attributes": {
"speed": {
"type": "vec3",
"name": "speed",
"array": false,
"description": "Speed determines how fast to rotate things",
"default": [0, 0, 0]
},
"thingsToRotate": {
"type": "entity",
"name": "thingsToRotate",
"array": true,
"description": "An array of Entities to rotate",
"default": null
}
},
"errors": []
}
"rotator": {
"attributes": {
"speed": {
"type": "vec3",
"name": "speed",
"array": false,
"description": "Speed determines how fast to rotate things",
"default": [0, 0, 0]
},
"thingsToRotate": {
"type": "entity",
"name": "thingsToRotate",
"array": true,
"description": "An array of Entities to rotate",
"default": null
}
},
"errors": []
}
}
```

JSDocs tags are parsed and values and outputs the metadata in a serializable format.

### Usage
### Usage

```javascript
// Initialise the parser
Expand All @@ -79,7 +78,7 @@ const scripts = await fetchScripts([...paths, './playcanvas.d.ts']);
parser.updateProgram(scripts);

// Parse attributes from the entry point
const [attributes, errors] = parser.parseAttributes("./index.js");
const [attributes, errors] = parser.parseAttributes('./index.js');
```

### Attribute structure
Expand All @@ -89,5 +88,3 @@ See the [test fixtures](https://github.com/playcanvas/attribute-parser/tree/main
### Tests

This project includes good test coverage for all supported tag formats and edge cases.


10 changes: 6 additions & 4 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import playcanvasConfig from '@playcanvas/eslint-config';
import javascriptConfig from '@playcanvas/eslint-config/javascript';
import prettierConfig from 'eslint-config-prettier/flat';
import globals from 'globals';

export default [
...playcanvasConfig,
...javascriptConfig,
{
ignores: ['**/program.invalid.js'] // Exclude specific files
ignores: ['dist/**', 'types/**', 'test/fixtures/**']
},
{
languageOptions: {
Expand Down Expand Up @@ -42,5 +43,6 @@ export default [
rules: {
'prefer-arrow-callback': 'off' // Allow function expressions in test files
}
}
},
prettierConfig
];
Loading