@playcanvas/attribute-parser 1.6.1 → 1.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. package/LICENSE.md +19 -0
  2. package/dist/index.js +194566 -0
  3. package/dist/libs.d.ts +50978 -0
  4. package/package.json +49 -9
  5. package/types/index.d.ts +55 -0
  6. package/types/parsers/attribute-parser.d.ts +55 -0
  7. package/types/parsers/parsing-error.d.ts +6 -0
  8. package/types/parsers/script-parser.d.ts +124 -0
  9. package/types/utils/attribute-utils.d.ts +5 -0
  10. package/{src/utils/generic-utils.js → types/utils/generic-utils.d.ts} +1 -10
  11. package/types/utils/tag-utils.d.ts +16 -0
  12. package/types/utils/ts-utils.d.ts +103 -0
  13. package/.github/workflows/ci.yml +0 -49
  14. package/eslint.config.mjs +0 -35
  15. package/renovate.json +0 -25
  16. package/src/parsers/attribute-parser.js +0 -197
  17. package/src/parsers/parsing-error.js +0 -14
  18. package/src/parsers/script-parser.js +0 -432
  19. package/src/utils/attribute-utils.js +0 -53
  20. package/src/utils/tag-utils.js +0 -73
  21. package/src/utils/ts-utils.js +0 -634
  22. package/test/fixtures/asset.invalid.js +0 -27
  23. package/test/fixtures/asset.invalid.ts +0 -24
  24. package/test/fixtures/asset.valid.js +0 -26
  25. package/test/fixtures/asset.valid.ts +0 -21
  26. package/test/fixtures/checkbox.valid.js +0 -23
  27. package/test/fixtures/color.valid.js +0 -23
  28. package/test/fixtures/conditional.valid.js +0 -22
  29. package/test/fixtures/curve.invalid.js +0 -29
  30. package/test/fixtures/curve.valid.js +0 -49
  31. package/test/fixtures/empty.valid.js +0 -0
  32. package/test/fixtures/entity.valid.js +0 -23
  33. package/test/fixtures/enum.valid.js +0 -66
  34. package/test/fixtures/enum.valid.ts +0 -50
  35. package/test/fixtures/example.dep.js +0 -9
  36. package/test/fixtures/export.import.js +0 -8
  37. package/test/fixtures/export.valid.js +0 -26
  38. package/test/fixtures/inherit.valid.js +0 -45
  39. package/test/fixtures/intellisense.valid.js +0 -40
  40. package/test/fixtures/json.invalid.js +0 -23
  41. package/test/fixtures/json.valid.js +0 -115
  42. package/test/fixtures/json.valid.ts +0 -81
  43. package/test/fixtures/misc.invalid.js +0 -24
  44. package/test/fixtures/misc.valid.js +0 -51
  45. package/test/fixtures/numeric.invalid.js +0 -38
  46. package/test/fixtures/numeric.valid.js +0 -63
  47. package/test/fixtures/playcanvas.d.ts +0 -47963
  48. package/test/fixtures/program.invalid.js +0 -12
  49. package/test/fixtures/program.valid.js +0 -27
  50. package/test/fixtures/text.valid.js +0 -31
  51. package/test/fixtures/vector.invalid.js +0 -14
  52. package/test/fixtures/vector.valid.js +0 -24
  53. package/test/tests/invalid/asset.test.js +0 -47
  54. package/test/tests/invalid/curve.test.js +0 -23
  55. package/test/tests/invalid/json.test.js +0 -27
  56. package/test/tests/invalid/misc.test.js +0 -41
  57. package/test/tests/invalid/numeric.test.js +0 -55
  58. package/test/tests/invalid/program.test.js +0 -17
  59. package/test/tests/invalid/vector.test.js +0 -28
  60. package/test/tests/valid/asset.test.js +0 -59
  61. package/test/tests/valid/checkbox.test.js +0 -57
  62. package/test/tests/valid/color.test.js +0 -49
  63. package/test/tests/valid/conditional.test.js +0 -45
  64. package/test/tests/valid/curve.test.js +0 -76
  65. package/test/tests/valid/empty.test.js +0 -17
  66. package/test/tests/valid/entity.test.js +0 -49
  67. package/test/tests/valid/enum.test.js +0 -79
  68. package/test/tests/valid/export.test.js +0 -67
  69. package/test/tests/valid/inherit.test.js +0 -110
  70. package/test/tests/valid/intellisense.test.js +0 -39
  71. package/test/tests/valid/json.test.js +0 -315
  72. package/test/tests/valid/misc.test.js +0 -54
  73. package/test/tests/valid/numeric.test.js +0 -103
  74. package/test/tests/valid/program.test.js +0 -23
  75. package/test/tests/valid/text.test.js +0 -58
  76. package/test/tests/valid/vector.test.js +0 -53
  77. package/test/utils.js +0 -54
@@ -1,54 +0,0 @@
1
- import { expect } from 'chai';
2
- import { describe, it, before } from 'mocha';
3
-
4
- import { parseAttributes } from '../../utils.js';
5
-
6
- describe('VALID: Misc attribute types', function () {
7
- let data;
8
- before(async function () {
9
- data = await parseAttributes('./misc.valid.js');
10
- });
11
-
12
- it('only results should exist', function () {
13
- expect(data).to.exist;
14
- expect(data[0]).to.not.be.empty;
15
- expect(data[1]).to.be.empty;
16
- });
17
-
18
- it('Example: should exist without errors', function () {
19
- expect(data[0]?.example).to.exist;
20
- expect(data[0].example.attributes).to.not.be.empty;
21
- expect(data[0].example.errors).to.be.empty;
22
- });
23
-
24
- it('a: should be a numeric attribute with a title and description', function () {
25
- expect(data[0].example.attributes.a).to.exist;
26
- expect(data[0].example.attributes.a.name).to.equal('a');
27
- expect(data[0].example.attributes.a.type).to.equal('number');
28
- expect(data[0].example.attributes.a.array).to.equal(false);
29
- expect(data[0].example.attributes.a.default).to.equal(0);
30
- expect(data[0].example.attributes.a.title).to.equal('A number');
31
- expect(data[0].example.attributes.a.description).to.equal('This is a description of the attribute. It can be multi-sentence.\n\nAnd multi-line too');
32
- });
33
-
34
- it('b: should be a numeric attribute with a getter and setter', function () {
35
- expect(data[0].example.attributes.b).to.exist;
36
- expect(data[0].example.attributes.b.name).to.equal('b');
37
- expect(data[0].example.attributes.b.type).to.equal('number');
38
- expect(data[0].example.attributes.b.array).to.equal(false);
39
- expect(data[0].example.attributes.b.default).to.equal(0);
40
- });
41
-
42
- it('c: should not be recognised as an attribute (no attribute tag)', function () {
43
- expect(data[0].example.attributes.c).to.not.exist;
44
- });
45
-
46
- it('d: should be a numeric attribute with a getter and setter defined in reverse order', function () {
47
- expect(data[0].example.attributes.d).to.exist;
48
- expect(data[0].example.attributes.d.name).to.equal('d');
49
- expect(data[0].example.attributes.d.type).to.equal('number');
50
- expect(data[0].example.attributes.d.array).to.equal(false);
51
- expect(data[0].example.attributes.d.default).to.equal(0);
52
- });
53
-
54
- });
@@ -1,103 +0,0 @@
1
- import { expect } from 'chai';
2
- import { describe, it, before } from 'mocha';
3
-
4
- import { parseAttributes } from '../../utils.js';
5
-
6
- describe('VALID: Numeric attribute', function () {
7
- let data;
8
- before(async function () {
9
- data = await parseAttributes('./numeric.valid.js');
10
- });
11
-
12
- it('only results should exist', function () {
13
- expect(data).to.exist;
14
- expect(data[0]).to.not.be.empty;
15
- expect(data[1]).to.be.empty;
16
- });
17
-
18
- it('Example: should exist without errors', function () {
19
- expect(data[0]?.example).to.exist;
20
- expect(data[0].example.attributes).to.not.be.empty;
21
- expect(data[0].example.errors).to.be.empty;
22
- });
23
-
24
- it('a: should be a numeric attribute', function () {
25
- expect(data[0].example.attributes.a).to.exist;
26
- expect(data[0].example.attributes.a.name).to.equal('a');
27
- expect(data[0].example.attributes.a.type).to.equal('number');
28
- expect(data[0].example.attributes.a.array).to.equal(false);
29
- expect(data[0].example.attributes.a.default).to.equal(0);
30
- });
31
-
32
- it('b: should be a numeric attribute with a default value', function () {
33
- expect(data[0].example.attributes.b).to.exist;
34
- expect(data[0].example.attributes.b.name).to.equal('b');
35
- expect(data[0].example.attributes.b.type).to.equal('number');
36
- expect(data[0].example.attributes.b.array).to.equal(false);
37
- expect(data[0].example.attributes.b.default).to.equal(1);
38
- });
39
-
40
- it('c: should be a numeric attribute with a precision and step', function () {
41
- expect(data[0].example.attributes.c).to.exist;
42
- expect(data[0].example.attributes.c.name).to.equal('c');
43
- expect(data[0].example.attributes.c.type).to.equal('number');
44
- expect(data[0].example.attributes.c.array).to.equal(false);
45
- expect(data[0].example.attributes.c.default).to.equal(0);
46
- expect(data[0].example.attributes.c.precision).to.equal(2);
47
- expect(data[0].example.attributes.c.step).to.equal(0.01);
48
- });
49
-
50
- it('d: should be a numeric attribute with a range, precision and step', function () {
51
- expect(data[0].example.attributes.d).to.exist;
52
- expect(data[0].example.attributes.d.name).to.equal('d');
53
- expect(data[0].example.attributes.d.type).to.equal('number');
54
- expect(data[0].example.attributes.d.array).to.equal(false);
55
- expect(data[0].example.attributes.d.default).to.equal(0);
56
- expect(data[0].example.attributes.d.min).to.equal(0);
57
- expect(data[0].example.attributes.d.max).to.equal(1);
58
- expect(data[0].example.attributes.d.precision).to.equal(2);
59
- expect(data[0].example.attributes.d.step).to.equal(0.01);
60
- });
61
-
62
- it('e: should be a numeric attribute array with a size', function () {
63
- expect(data[0].example.attributes.e).to.exist;
64
- expect(data[0].example.attributes.e.name).to.equal('e');
65
- expect(data[0].example.attributes.e.type).to.equal('number');
66
- expect(data[0].example.attributes.e.array).to.equal(true);
67
- expect(data[0].example.attributes.e.size).to.equal(2);
68
- expect(data[0].example.attributes.e.default).equal(null);
69
- });
70
-
71
- it('f: should be a numeric attribute in an unusual format', function () {
72
- expect(data[0].example.attributes.f).to.exist;
73
- expect(data[0].example.attributes.f.name).to.equal('f');
74
- expect(data[0].example.attributes.f.type).to.equal('number');
75
- expect(data[0].example.attributes.f.array).to.equal(false);
76
- expect(data[0].example.attributes.f.default).to.equal(0);
77
- expect(data[0].example.attributes.f.min).to.equal(-255);
78
- expect(data[0].example.attributes.f.max).to.equal(0);
79
- expect(data[0].example.attributes.f.precision).to.equal(2);
80
- expect(data[0].example.attributes.f.step).to.equal(0.01);
81
- });
82
-
83
- it('g: should be a numeric attribute with single value in range', function () {
84
- expect(data[0].example.attributes.g).to.exist;
85
- expect(data[0].example.attributes.g.name).to.equal('g');
86
- expect(data[0].example.attributes.g.type).to.equal('number');
87
- expect(data[0].example.attributes.g.array).to.equal(false);
88
- expect(data[0].example.attributes.g.default).to.equal(0);
89
- expect(data[0].example.attributes.g.min).to.equal(1);
90
- expect(data[0].example.attributes.g.max).to.not.exist;
91
- });
92
-
93
- it('h: should be a numeric attribute with empty range', function () {
94
- expect(data[0].example.attributes.h).to.exist;
95
- expect(data[0].example.attributes.h.name).to.equal('h');
96
- expect(data[0].example.attributes.h.type).to.equal('number');
97
- expect(data[0].example.attributes.h.array).to.equal(false);
98
- expect(data[0].example.attributes.h.default).to.equal(0);
99
- expect(data[0].example.attributes.h.min).to.not.exist;
100
- expect(data[0].example.attributes.h.max).to.not.exist;
101
- });
102
-
103
- });
@@ -1,23 +0,0 @@
1
- import { expect } from 'chai';
2
- import { describe, it, before } from 'mocha';
3
-
4
- import { parseAttributes } from '../../utils.js';
5
-
6
- describe('VALID: Program ', function () {
7
- let data;
8
- before(async function () {
9
- data = await parseAttributes('./program.valid.js');
10
- });
11
-
12
- it('should have a customExample script', function () {
13
- expect(data[0].customExample).to.exist;
14
- expect(data[0].customExample.errors).to.be.empty;
15
- });
16
-
17
- it('only results should exist', function () {
18
- expect(data).to.exist;
19
- expect(data[0]).to.not.be.empty;
20
- expect(data[1]).to.be.empty;
21
- expect(data[0].customExample.errors).to.be.empty;
22
- });
23
- });
@@ -1,58 +0,0 @@
1
- import { expect } from 'chai';
2
- import { describe, it, before } from 'mocha';
3
-
4
- import { parseAttributes } from '../../utils.js';
5
-
6
- describe('VALID: Text attribute', function () {
7
- let data;
8
- before(async function () {
9
- data = await parseAttributes('./text.valid.js');
10
- });
11
-
12
- it('only results should exist', function () {
13
- expect(data).to.exist;
14
- expect(data[0]).to.not.be.empty;
15
- expect(data[1]).to.be.empty;
16
- });
17
-
18
- it('Example: should exist without errors', function () {
19
- expect(data[0]?.example).to.exist;
20
- expect(data[0].example.attributes).to.not.be.empty;
21
- expect(data[0].example.errors).to.be.empty;
22
- });
23
-
24
- it('a: should be a string attribute', function () {
25
- expect(data[0].example.attributes.a).to.exist;
26
- expect(data[0].example.attributes.a.name).to.equal('a');
27
- expect(data[0].example.attributes.a.type).to.equal('string');
28
- expect(data[0].example.attributes.a.array).to.equal(false);
29
- expect(data[0].example.attributes.a.default).to.equal('');
30
- });
31
-
32
- it('b: should be a string attribute with a default value', function () {
33
- expect(data[0].example.attributes.b).to.exist;
34
- expect(data[0].example.attributes.b.name).to.equal('b');
35
- expect(data[0].example.attributes.b.type).to.equal('string');
36
- expect(data[0].example.attributes.b.array).to.equal(false);
37
- expect(data[0].example.attributes.b.default).to.equal('example');
38
- });
39
-
40
- it('c: should be a string attribute with a placeholder', function () {
41
- expect(data[0].example.attributes.c).to.exist;
42
- expect(data[0].example.attributes.c.name).to.equal('c');
43
- expect(data[0].example.attributes.c.type).to.equal('string');
44
- expect(data[0].example.attributes.c.array).to.equal(false);
45
- expect(data[0].example.attributes.c.default).to.equal('');
46
- expect(data[0].example.attributes.c.placeholder).to.equal('Example text');
47
- });
48
-
49
- it('d: should be a string attribute array with a size', function () {
50
- expect(data[0].example.attributes.d).to.exist;
51
- expect(data[0].example.attributes.d.name).to.equal('d');
52
- expect(data[0].example.attributes.d.type).to.equal('string');
53
- expect(data[0].example.attributes.d.array).to.equal(true);
54
- expect(data[0].example.attributes.d.size).to.equal(2);
55
- expect(data[0].example.attributes.d.default).equal(null);
56
- });
57
-
58
- });
@@ -1,53 +0,0 @@
1
- import { expect } from 'chai';
2
- import { describe, it, before } from 'mocha';
3
-
4
- import { parseAttributes } from '../../utils.js';
5
-
6
- describe('VALID: Vector attribute', function () {
7
- let data;
8
- before(async function () {
9
- data = await parseAttributes('./vector.valid.js');
10
- });
11
-
12
- it('only results should exist', function () {
13
- expect(data).to.exist;
14
- expect(data[0]).to.not.be.empty;
15
- expect(data[1]).to.be.empty;
16
- });
17
-
18
- it('Example: should exist without errors', function () {
19
- expect(data[0]?.example).to.exist;
20
- expect(data[0].example.attributes).to.not.be.empty;
21
- expect(data[0].example.errors).to.be.empty;
22
- });
23
-
24
- it('a: should be a vector attribute', function () {
25
- expect(data[0].example.attributes.a).to.exist;
26
- expect(data[0].example.attributes.a.name).to.equal('a');
27
- expect(data[0].example.attributes.a.type).to.equal('vec2');
28
- expect(data[0].example.attributes.a.array).to.equal(false);
29
- expect(data[0].example.attributes.a.default).to.eql([0, 0]);
30
- });
31
-
32
- it('b: should be a vector attribute with a default value', function () {
33
- expect(data[0].example.attributes.b).to.exist;
34
- expect(data[0].example.attributes.b.name).to.equal('b');
35
- expect(data[0].example.attributes.b.type).to.equal('vec3');
36
- expect(data[0].example.attributes.b.array).to.equal(false);
37
- expect(data[0].example.attributes.b.default).to.eql([1, 2, 3]);
38
- });
39
-
40
- it('c: should be a vector attribute array with a size', function () {
41
- expect(data[0].example.attributes.c).to.exist;
42
- expect(data[0].example.attributes.c.name).to.equal('c');
43
- expect(data[0].example.attributes.c.type).to.equal('vec4');
44
- expect(data[0].example.attributes.c.array).to.equal(true);
45
- expect(data[0].example.attributes.c.size).to.equal(2);
46
- expect(data[0].example.attributes.c.default).equal(null);
47
- });
48
-
49
- it('d: should not be recognized as an attribute (extends vector and not is vector)', function () {
50
- expect(data[0].example.attributes.d).to.not.exist;
51
- });
52
-
53
- });
package/test/utils.js DELETED
@@ -1,54 +0,0 @@
1
- import fs from 'fs/promises';
2
- import path, { dirname } from 'path';
3
- import { fileURLToPath } from 'url';
4
-
5
- import { JSDocParser } from '../src/index.js';
6
-
7
- const __filename = fileURLToPath(import.meta.url);
8
- const __dirname = dirname(__filename);
9
-
10
- /**
11
- * Reads the contents of a file and returns an array containing the file name and its contents.
12
- * @param {string} filePath - The path to the file.
13
- * @returns {Promise<[string, string]>} A promise that resolves to an array containing the file name and its contents.
14
- */
15
- async function getFileData(filePath) {
16
- try {
17
- const contents = await fs.readFile(path.join(__dirname, 'fixtures', filePath), 'utf8');
18
- return [path.join('/', filePath), contents];
19
- } catch (error) {
20
- console.error(`Error reading file ${filePath}: ${error}`);
21
- return [path.basename(filePath), null]; // Return null for contents if there was an error
22
- }
23
- }
24
-
25
- /**
26
- * Fetches the contents of multiple files.
27
- * @param {string[]} filePaths - An array of file paths.
28
- * @returns {Promise<[string, string][]>} A promise that resolves to an array containing the file names and their contents.
29
- */
30
- export function fetchScripts(filePaths) {
31
- return Promise.all(filePaths.map(getFileData));
32
- }
33
-
34
- /**
35
- * @param {string[]} paths - The path to the example file.
36
- * @returns {Promise<[results: any,
37
- * errors: import('../src/parsers/script-parser.js').ValidationError[]]>} A promise that resolves to
38
- * an array of attribute data.
39
- */
40
- export async function parseAttributes(...paths) {
41
- const parser = new JSDocParser();
42
- await parser.init();
43
- const scriptContents = await fetchScripts([...paths, './playcanvas.d.ts']);
44
- parser.updateProgram(scriptContents);
45
- return parser.parseAttributes(paths[0]);
46
- }
47
-
48
- export async function getAttributes(...paths) {
49
- const parser = new JSDocParser();
50
- await parser.init();
51
- const scriptContents = await fetchScripts([...paths, './playcanvas.d.ts']);
52
- parser.updateProgram(scriptContents);
53
- return parser.getAttributes(paths[0]);
54
- }