Skip to content

Commit 5d34bdb

Browse files
authored
Bump to 1.2.0 (#25)
1 parent 41c9b5e commit 5d34bdb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+11675
-4332
lines changed

README.md

Lines changed: 85 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ or TypeScript components.
1212

1313
Learn more about Wonderland Engine at [https://wonderlandengine.com](https://wonderlandengine.com).
1414

15+
> 💡 The Wonderland Engine Runtime is compatible on all patch versions of the API, but the
16+
> major and minor versions are required to match.
17+
>
18+
> **Example:** You will be able to use Wonderland Editor 1.0.4 with API
19+
> version 1.0.0 or 1.0.9 for example, but not with API 1.1.0. 💡
20+
1521
## Usage
1622

1723
Wonderland Engine projects usually come with this package pre-installed.
@@ -45,10 +51,10 @@ class Forward extends Component {
4551

4652
update(dt) {
4753
this.object.getForward(this._forward);
48-
this._forward[0] *= this.speed;
49-
this._forward[1] *= this.speed;
50-
this._forward[2] *= this.speed;
51-
this.object.translate(this._forward);
54+
this._forward[0] *= this.speed*dt;
55+
this._forward[1] *= this.speed*dt;
56+
this._forward[2] *= this.speed*dt;
57+
this.object.translateLocal(this._forward);
5258
}
5359
}
5460
```
@@ -65,14 +71,14 @@ class Forward extends Component {
6571
@property.float(1.5)
6672
speed!: number;
6773

68-
_forward = new Float32Array(3);
74+
private _forward = new Float32Array(3);
6975

7076
update(dt) {
7177
this.object.getForward(this._forward);
72-
this._forward[0] *= this.speed;
73-
this._forward[1] *= this.speed;
74-
this._forward[2] *= this.speed;
75-
this.object.translate(this._forward);
78+
this._forward[0] *= this.speed*dt;
79+
this._forward[1] *= this.speed*dt;
80+
this._forward[2] *= this.speed*dt;
81+
this.object.translateLocal(this._forward);
7682
}
7783
}
7884
```
@@ -82,16 +88,16 @@ For more information, please refer to the [JavaScript Quick Start Guide](https:/
8288
### For Library Maintainers
8389

8490
To ensure the user of your library can use a range of API versions with your library,
85-
use `"peerDepenedencies"` in your `package.json`:
91+
use `"peerDependencies"` in your `package.json`:
8692

8793
```json
8894
"peerDependencies": {
8995
"@wonderlandengine/api": ">= 1.0.0 < 2"
9096
},
9197
```
9298

93-
Which signals that your package works with any API version `>= 1.0.0` (choose whichever
94-
version has all the features you need) until `2.0.0`.
99+
Which signals that your package works with any API version `>= 1.0.0`
100+
(choose the lowest version that provides all features you need) until `2.0.0`.
95101

96102
Also see the [Writing JavaScript Libraries Tutorial](https://wonderlandengine.com/tutorials/writing-js-library/).
97103

@@ -100,32 +106,90 @@ Also see the [Writing JavaScript Libraries Tutorial](https://wonderlandengine.co
100106
### Installation
101107

102108
Make sure to install dependencies first:
109+
103110
```sh
104111
npm i
105112
```
106113

107114
### Build
108115

109-
To build the TypeScript, use one of:
116+
To build the TypeScript code, use one of:
117+
110118
```sh
111119
npm run build
112120
npm run build:watch
113121
```
114122

115123
### Test
116124

117-
To run the tests, use one of:
125+
To run all the tests, use:
126+
127+
```sh
128+
npm run test -- --deploy path/to/wonderland/deploy
129+
```
130+
131+
It's required to pass the Wonderland Editor deploy folder as a CLI argument using
132+
the `--deploy` argument.
133+
134+
If no such flag is passed, the test framework will assume
135+
that the deploy folder is located in `../../deploy`.
136+
137+
#### Test Projects
138+
139+
Some tests use projects as inputs, e.g.,
140+
* `animation.tests.ts`
141+
* `component.tests.ts`
142+
* `mesh.tests.ts`
143+
* `scene.test.ts`
144+
* `scene-gltf.test.ts`
145+
146+
Those projects are required to be built before the tests can run. You can build all projects using:
147+
148+
```sh
149+
npm run test:build -- path/to/wonderlandengine
150+
```
151+
152+
Each projects `deploy/` will be copied into `test/resources/projects`.
153+
154+
#### Test File
155+
156+
To run the tests in a file, use:
157+
118158
```sh
119-
npm run test
120-
npm run test:watch
159+
npm run test -- [PATH] --deploy path/to/wonderland/deploy
121160
```
122161

123-
## API <> Runtime Versioning
162+
Example with the component file:
163+
164+
```sh
165+
npm run test -- ./test/component.test.ts --deploy path/to/wonderland/deploy
166+
```
167+
168+
#### Watch
169+
170+
It's possible to watch one/multiple test(s) using `--watch`:
171+
172+
```sh
173+
npm run test -- --deploy path/to/wonderland/deploy --watch
174+
```
175+
176+
#### Grep
177+
178+
The runner uses Mocha, which supports filtering tests using [regexp](https://mochajs.org/api/mocha#grep).
179+
180+
You can provide a regexp using `--grep` or `-g`:
181+
182+
```sh
183+
npm run test -- -g 'MeshComponent'
184+
```
185+
186+
The `grep` flag can be mixed with the positional file argument:
187+
188+
```sh
189+
npm run test -- ./test/component.test.ts -g 'MeshComponent'
190+
```
124191

125-
The Wonderland Engine Runtime is compatible on all patch versions of the API, but the
126-
major and minor versions are required to match. Example: you will be able to use
127-
Wonderland Editor 1.0.4 with API version 1.0.0 or 1.0.9 for example, but probably not
128-
with API 1.1.0.
192+
This command will only run the tests matching the "MeshComponent" string in the `test/component.test.ts` file.
129193

130194
## License
131195

package-lock.json

Lines changed: 15 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@wonderlandengine/api",
3-
"version": "1.1.5",
3+
"version": "1.2.0",
44
"description": "Wonderland Engine's JavaScript API.",
55
"main": "./dist/index.js",
66
"module": "./dist/index.js",
@@ -27,18 +27,17 @@
2727
"url": "https://github.com/WonderlandEngine/api/issues"
2828
},
2929
"homepage": "https://github.com/WonderlandEngine/api#readme",
30+
"prettier": "@wonderlandengine/prettier-config",
3031
"scripts": {
3132
"build": "tsc",
3233
"build:watch": "tsc --watch",
33-
"prebuild": "node write-version.mjs",
34-
"test": "npm run build && npm run test:typecheck && wtr",
35-
"test:watch": "npm run build && wtr --watch",
34+
"prebuild": "node ./scripts/pre-build.mjs",
35+
"test": "npm run build && npm run test:typecheck && node ./scripts/run-tests.mjs",
3636
"test:typecheck": "tsc --project ./test/tsconfig.json --noEmit",
37-
"pretty": "prettier --config ./prettierrc.json --write \"src/**/*.ts\" \"test/**/*.ts\"",
38-
"pretty:check": "prettier --config ./prettierrc.json --check \"src/**/*.ts\" \"test/**/*.ts\"",
39-
"prepublishOnly": "npm run build",
40-
"prepack": "npm run build",
41-
"prepare": "npm run prebuild",
37+
"test:build": "node ./scripts/build-projects.mjs",
38+
"pretty": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
39+
"pretty:check": "prettier --check \"src/**/*.ts\" \"test/**/*.ts\"",
40+
"prepare": "npm run build",
4241
"doc": "typedoc --entryPoints ./src/index.ts --tsconfig tsconfig.json --json ./doc.json --treatWarningsAsErrors"
4342
},
4443
"files": [
@@ -55,6 +54,7 @@
5554
"@types/node": "^18.11.9",
5655
"@web/dev-server-esbuild": "^0.4.1",
5756
"@web/test-runner": "0.17.0",
57+
"@wonderlandengine/prettier-config": "^1.0.0",
5858
"esbuild": "^0.11.14",
5959
"prettier": "^2.8.0",
6060
"typedoc": "^0.23.21",

prettierrc.json

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

scripts/build-projects.mjs

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
#!/usr/bin/env node
2+
3+
/* This script is used to build the Wonderland Engine test projects
4+
* located in test/projects/ */
5+
6+
import {spawn} from 'node:child_process';
7+
import {readdir} from 'node:fs/promises';
8+
import {basename, dirname, resolve} from 'node:path';
9+
import {fileURLToPath} from 'node:url';
10+
11+
if (!process.argv[2]) {
12+
console.error('WonderlandEditor executable not provided');
13+
console.error('Usage: npm run test:build -- path/to/wonderlandengine');
14+
process.exit(1);
15+
}
16+
17+
const scriptPath = dirname(fileURLToPath(import.meta.url));
18+
const paths = {
19+
editor: resolve(process.argv[2]),
20+
test: resolve(scriptPath, '..', 'test'),
21+
projects: resolve(scriptPath, '..', 'test', 'projects'),
22+
output: resolve(scriptPath, '..', 'test', 'resources', 'projects'),
23+
};
24+
25+
let commands = [];
26+
try {
27+
/* Read each project's directory. This doesn't recursively search for projects
28+
* on purpose, but instead search only the first layer of directories. */
29+
const wlps = await readdir(paths.projects, {withFileTypes: true}).then((dirs) => {
30+
const promises = dirs
31+
.filter((dir) => dir.isDirectory())
32+
.map((dir) => {
33+
const path = resolve(dir.path, dir.name);
34+
return readdir(path).then((files) =>
35+
files.filter((f) => f.endsWith('.wlp')).map((f) => resolve(path, f))
36+
);
37+
});
38+
return Promise.all(promises).then((data) => data.flat());
39+
});
40+
commands = wlps.map((path) => ({path, filename: basename(path), logs: []}));
41+
} catch (e) {
42+
console.error('Failed to search for .wlp files in test/projects/, reason:', e);
43+
process.exit(1);
44+
}
45+
46+
const promises = [];
47+
for (const command of commands) {
48+
promises.push(
49+
new Promise((res, rej) => {
50+
const cmd = spawn(paths.editor, [
51+
'--project',
52+
command.path,
53+
'--windowless',
54+
'--package',
55+
'--preferences',
56+
`${paths.projects}/preferences.json`,
57+
'--output',
58+
paths.output,
59+
]);
60+
cmd.stderr.on('data', (data) => {
61+
command.logs.push(data);
62+
});
63+
cmd.stdout.on('data', (data) => {
64+
command.logs.push(data);
65+
});
66+
cmd.on('error', rej);
67+
cmd.on('close', res);
68+
cmd.on('exit', res);
69+
}).then(() => {
70+
console.log(`================ ${command.filename} ================`);
71+
console.log(command.logs.join(''));
72+
command.logs.length = 0;
73+
})
74+
);
75+
}
76+
77+
let failed = false;
78+
const results = await Promise.allSettled(promises);
79+
for (let i = 0; i < results.length; ++i) {
80+
const result = results[i];
81+
if (result.status !== 'fulfilled') {
82+
console.error('Failed to run editor command, reason: ', result.reason.message);
83+
failed = true;
84+
continue;
85+
}
86+
if (!result.value) continue;
87+
88+
const cmd = commands[i];
89+
console.error(`Project '${cmd.filename}' failed with exit code '${result.value}'`);
90+
failed = true;
91+
}
92+
93+
process.exit(failed ? 1 : 0);

0 commit comments

Comments
 (0)