@123ishatest/louter 0.1.0 → 0.2.1
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.
- package/README.md +101 -0
- package/dist/export/LouterJsonSchemaWriter.d.ts.map +1 -1
- package/dist/loader/LouterFileLoader.d.ts.map +1 -1
- package/dist/node.cjs.js +1 -1
- package/dist/node.es.js +2 -2
- package/dist/parser/LouterYamlParser.d.ts +1 -1
- package/dist/parser/LouterYamlParser.d.ts.map +1 -1
- package/package.json +18 -4
package/README.md
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
# Louter
|
|
2
|
+
|
|
3
|
+
> Louter is a zod-based content parser that transforms YAML into type-safe runtime data.
|
|
4
|
+
|
|
5
|
+
It consists of 2 parts:
|
|
6
|
+
|
|
7
|
+
- A build step, running in a node-only context such as a vite plugin or the `server` context of SvelteKit.
|
|
8
|
+
- A content manager, providing fully-typed access to your content at run-time.
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npm install @123ishatest/louter
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Setup
|
|
17
|
+
|
|
18
|
+
Define your content kinds, a mapping between the `kind` of content and the Zod schema that represents it.
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
import { z } from 'zod';
|
|
22
|
+
|
|
23
|
+
const schemas = {
|
|
24
|
+
currency: z.strictObject({ id: z.string(), name: z.string() }),
|
|
25
|
+
upgrade: z.strictObject({
|
|
26
|
+
id: z.string(),
|
|
27
|
+
name: z.string(),
|
|
28
|
+
cost: z.strictObject({
|
|
29
|
+
currency: z.string(),
|
|
30
|
+
amount: z.number().default(4),
|
|
31
|
+
}),
|
|
32
|
+
}),
|
|
33
|
+
};
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Add your content!
|
|
37
|
+
|
|
38
|
+
```yaml
|
|
39
|
+
# money.currency.yaml
|
|
40
|
+
id: /currency/money
|
|
41
|
+
name: Money
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
```yaml
|
|
45
|
+
# more-money.upgrade.yaml
|
|
46
|
+
id: /upgrade/more-money
|
|
47
|
+
name: More money
|
|
48
|
+
cost:
|
|
49
|
+
currency: /currency/money
|
|
50
|
+
amount: 4
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Usage (node)
|
|
54
|
+
|
|
55
|
+
Louter comes with a composable pipeline, so you can add or remove behaviour to your heart's desire.
|
|
56
|
+
|
|
57
|
+
```ts
|
|
58
|
+
import { Louter, LouterValidator, LouterYamlParser } from '@123ishatest/louter';
|
|
59
|
+
import { LouterContentWriter, LouterFileLoader, LouterJsonSchemaWriter } from '@123ishatest/louter/node';
|
|
60
|
+
|
|
61
|
+
const louter = new Louter([
|
|
62
|
+
// Loads all files in the specified folder
|
|
63
|
+
new LouterFileLoader('content'),
|
|
64
|
+
|
|
65
|
+
// Parses the YAML that was found
|
|
66
|
+
new LouterYamlParser(),
|
|
67
|
+
|
|
68
|
+
// Validates it against the schemas
|
|
69
|
+
new LouterValidator(),
|
|
70
|
+
|
|
71
|
+
// Writes a big content object to the specified folder
|
|
72
|
+
new LouterContentWriter('.generated'),
|
|
73
|
+
|
|
74
|
+
// Writes utility JSON Schemas to the specified folder
|
|
75
|
+
new LouterJsonSchemaWriter('.generated'),
|
|
76
|
+
]);
|
|
77
|
+
|
|
78
|
+
const result = louter.run(schemas);
|
|
79
|
+
|
|
80
|
+
// Check for warnings
|
|
81
|
+
result.warnings.forEach(console.warn);
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
This result contains all parsed content, which can be used by your game!
|
|
85
|
+
|
|
86
|
+
## Usage (browser)
|
|
87
|
+
|
|
88
|
+
```ts
|
|
89
|
+
import { ContentManager } from '@123ishatest/louter';
|
|
90
|
+
|
|
91
|
+
const manager = new ContentManager(schemas);
|
|
92
|
+
manager.load(result.content);
|
|
93
|
+
|
|
94
|
+
// Type-safe accessors
|
|
95
|
+
const currencies = manager.getList('currency');
|
|
96
|
+
const currencyMap = manager.getMap('currency');
|
|
97
|
+
|
|
98
|
+
// Fully typed objects
|
|
99
|
+
const money = manager.get('/currency/money', 'currency');
|
|
100
|
+
console.log(money.name);
|
|
101
|
+
```
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LouterJsonSchemaWriter.d.ts","sourceRoot":"","sources":["../../src/export/LouterJsonSchemaWriter.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"LouterJsonSchemaWriter.d.ts","sourceRoot":"","sources":["../../src/export/LouterJsonSchemaWriter.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAEnE;;GAEG;AACH,qBAAa,sBAAuB,YAAW,WAAW;IACxD,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;gBAExB,SAAS,GAAE,MAAkB;IAIzC,GAAG,CAAC,KAAK,SAAS,eAAe,EAAE,GAAG,EAAE,aAAa,CAAC,KAAK,CAAC,GAAG,IAAI;CAUpE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LouterFileLoader.d.ts","sourceRoot":"","sources":["../../src/loader/LouterFileLoader.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAEhE;;GAEG;AACH,qBAAa,gBAAiB,YAAW,WAAW;IAClD,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAC;gBAElB,WAAW,EAAE,MAAM;IAIxB,GAAG,CAAC,KAAK,SAAS,eAAe,EAAE,GAAG,EAAE,aAAa,CAAC,KAAK,CAAC,GAAG,IAAI;IAU1E;;OAEG;IACH,OAAO,CAAC,WAAW;
|
|
1
|
+
{"version":3,"file":"LouterFileLoader.d.ts","sourceRoot":"","sources":["../../src/loader/LouterFileLoader.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAEhE;;GAEG;AACH,qBAAa,gBAAiB,YAAW,WAAW;IAClD,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAC;gBAElB,WAAW,EAAE,MAAM;IAIxB,GAAG,CAAC,KAAK,SAAS,eAAe,EAAE,GAAG,EAAE,aAAa,CAAC,KAAK,CAAC,GAAG,IAAI;IAU1E;;OAEG;IACH,OAAO,CAAC,WAAW;CAkBpB"}
|
package/dist/node.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("node:fs"),n=require("node:path");class l{_contentRoot;constructor(
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("node:fs"),n=require("node:path");class l{_contentRoot;constructor(t){this._contentRoot=t}run(t){const r=this.getAllFiles(this._contentRoot);t.files=r.map(e=>({path:e,data:o.readFileSync(e,"utf-8")}))}getAllFiles(t){const r=o.readdirSync(t,{withFileTypes:!0}),e=[];for(const i of r){const c=n.join(t,i.name);i.isDirectory()&&e.push(...this.getAllFiles(c)),i.isFile()&&e.push(c)}return e}}class u{_directory;constructor(t=".louter"){this._directory=t}run(t){t.warnings.forEach(i=>{console.warn(i.path,i.message)}),o.mkdirSync(this._directory,{recursive:!0});const r=t.content,e=n.join(this._directory,"content.generated.json");o.writeFileSync(e,JSON.stringify(r,null,2))}}class a{_directory;constructor(t=".louter"){this._directory=t}run(t){o.mkdirSync(this._directory,{recursive:!0});for(const r in t.kinds){const e=t.kinds[r].toJSONSchema({io:"input"}),i=n.join(this._directory,`${r}.schema.json`);o.writeFileSync(i,JSON.stringify(e,null,2))}}}exports.LouterContentWriter=u;exports.LouterFileLoader=l;exports.LouterJsonSchemaWriter=a;
|
package/dist/node.es.js
CHANGED
|
@@ -18,8 +18,8 @@ class f {
|
|
|
18
18
|
getAllFiles(t) {
|
|
19
19
|
const r = a(t, { withFileTypes: !0 }), e = [];
|
|
20
20
|
for (const o of r) {
|
|
21
|
-
const
|
|
22
|
-
o.isDirectory()
|
|
21
|
+
const s = i.join(t, o.name);
|
|
22
|
+
o.isDirectory() && e.push(...this.getAllFiles(s)), o.isFile() && e.push(s);
|
|
23
23
|
}
|
|
24
24
|
return e;
|
|
25
25
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { KindDefinitions } from '../core/types';
|
|
2
|
-
import { LouterContext } from '../core/LouterContext';
|
|
3
2
|
import { LouterStage } from '../core/LouterStage';
|
|
3
|
+
import { LouterContext } from '../core/LouterContext';
|
|
4
4
|
/**
|
|
5
5
|
* Turns loaded files into objects by parsing YAML parsing them
|
|
6
6
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LouterYamlParser.d.ts","sourceRoot":"","sources":["../../src/parser/LouterYamlParser.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"LouterYamlParser.d.ts","sourceRoot":"","sources":["../../src/parser/LouterYamlParser.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAE1D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAG5D,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAE3D;;GAEG;AACH,qBAAa,gBAAiB,YAAW,WAAW;IAC3C,GAAG,CAAC,KAAK,SAAS,eAAe,EAAE,GAAG,EAAE,aAAa,CAAC,KAAK,CAAC,GAAG,IAAI;CAgD3E"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@123ishatest/louter",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.1
|
|
4
|
+
"version": "0.2.1",
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"access": "public",
|
|
7
|
+
"provenance": true
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"url": "https://github.com/123ishaTest/louter"
|
|
11
|
+
},
|
|
5
12
|
"files": [
|
|
6
13
|
"dist"
|
|
7
14
|
],
|
|
@@ -25,15 +32,22 @@
|
|
|
25
32
|
"check": "tsc -p ./tsconfig.build.json --noEmit",
|
|
26
33
|
"dev": "vite build --watch",
|
|
27
34
|
"lint": "prettier --check . && eslint .",
|
|
35
|
+
"format": "prettier --write .",
|
|
28
36
|
"test": "vitest",
|
|
29
|
-
"coverage": "vitest run --coverage"
|
|
37
|
+
"coverage": "vitest run --coverage",
|
|
38
|
+
"publish-packages": "npm run build && npm run lint && npm run test && changeset version && changeset publish"
|
|
30
39
|
},
|
|
31
40
|
"devDependencies": {
|
|
32
|
-
"@
|
|
33
|
-
"@
|
|
41
|
+
"@changesets/cli": "^2.29.5",
|
|
42
|
+
"@eslint/js": "^10.0.1",
|
|
43
|
+
"@types/node": "^25.5.0",
|
|
34
44
|
"@vitest/coverage-v8": "^4.0.6",
|
|
45
|
+
"eslint": "^10.0.3",
|
|
46
|
+
"globals": "^17.4.0",
|
|
47
|
+
"jiti": "^2.6.1",
|
|
35
48
|
"jsdom": "^27.1.0",
|
|
36
49
|
"memfs": "^4.56.11",
|
|
50
|
+
"typescript-eslint": "^8.57.0",
|
|
37
51
|
"vite": "^7.0.5",
|
|
38
52
|
"vite-plugin-dts": "^4.5.4",
|
|
39
53
|
"vite-tsconfig-paths": "^5.1.4",
|