Skip to content

Commit edcc1f1

Browse files
committed
Add prettier check to npm check script; fix prettier formatting
1 parent ce8b0d9 commit edcc1f1

File tree

5 files changed

+41
-32
lines changed

5 files changed

+41
-32
lines changed

.prettierignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
**/*.json

README.md

+33-27
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ The generator uses both the Factorio api docs JSON and manually defined addition
1010
To use in your [TypescriptToLua](https://typescripttolua.github.io/) project:
1111

1212
1. Install this package: `npm install typed-factorio`
13-
- Note: When types are updated for a new factorio version, you will need to update this package.
13+
14+
- Note: When types are updated for a new factorio version, you will need to update this package.
1415

1516
2. Add types for the [stages](https://lua-api.factorio.com/1.1.89/index.html) used to `tsconfig.json > compilerOptions > types`.
1617
The available stages are `"typed-factorio/settings"`, `"typed-factorio/prototype"`, and `"typed-factorio/runtime"`.
@@ -35,7 +36,8 @@ Here are some notes on using the types:
3536

3637
### Types for other stages
3738

38-
No matter which stage(s) are selected, _type_ definitions for all stages are available in the modules `"factorio:settings"`, `"factorio:prototype"`, and `"factorio:runtime"`:
39+
No matter which stage(s) are selected, _type_ definitions for all stages are available in the modules `"factorio:settings"`, `"factorio:prototype"`, and `"factorio:runtime"`:
40+
3941
```ts
4042
import { BoolSettingDefinition } from "factorio:settings"
4143
import { ItemPrototype } from "factorio:prototype"
@@ -45,40 +47,46 @@ import { LuaEntity } from "factorio:runtime"
4547
You can also include just `"typed-factorio"` in your `types` field. This will include only global variables available to _all_ stages.
4648

4749
### `data.extend()` types
48-
In the settings and prototype stages, the `data` global variable is available.
50+
51+
In the settings and prototype stages, the `data` global variable is available.
4952

5053
For [performance reasons](https://github.com/microsoft/TypeScript/wiki/Performance#preferring-base-types-over-unions), `data.extend()` is by default loosely typed.
5154
To get full type checking, you can use specific types in one of the following ways:
55+
5256
```ts
5357
// Use `satisfies` to check types:
5458
data.extend([
55-
{
56-
type: "ammo-category",
57-
name: "foo",
58-
} satisfies AmmoCategory,
59-
{
60-
type: "item",
61-
name: "bar",
62-
// ...other fields
63-
} satisfies ItemPrototype,
59+
{
60+
type: "ammo-category",
61+
name: "foo",
62+
} satisfies AmmoCategory,
63+
{
64+
type: "item",
65+
name: "bar",
66+
// ...other fields
67+
} satisfies ItemPrototype,
6468
])
6569

6670
// List types as a type argument to `extend`:
6771
data.extend<AmmoCategory | ItemPrototype>([
68-
{
69-
type: "ammo-category",
70-
name: "foo"
71-
},
72-
{
73-
type: "item",
74-
name: "bar",
75-
// ...other fields
76-
}
72+
{
73+
type: "ammo-category",
74+
name: "foo",
75+
},
76+
{
77+
type: "item",
78+
name: "bar",
79+
// ...other fields
80+
},
7781
])
7882

7983
// Use types on separate variables:
80-
const fooCategory: AmmoCategory = {/* ... */}
81-
const barItem: ItemPrototype = {/* ... */}
84+
const fooCategory: AmmoCategory = {
85+
/* ... */
86+
}
87+
const barItem: ItemPrototype = {
88+
/* ... */
89+
}
8290
data.extend([fooCategory, barItem])
8391
```
8492

@@ -149,6 +157,7 @@ Event IDs (`defines.events`) hold type info for their corresponding event type a
149157
You can pass an event data type parameter to `script.generate_event_name<T>()`, and it will return a `CustomEventId` that includes type info.
150158
151159
### Optional custominput name checking
160+
152161
You can optionally enable type-checking for custom input names (for `script.on_event` and `CustomInputPrototype`).
153162
To do so, specify names by extending the CustomInputNames interface like so:
154163
@@ -159,7 +168,7 @@ declare module "factorio:common" {
159168
}
160169
}
161170

162-
script.on_event("my-custom-input", ()=>{}) // type-checked
171+
script.on_event("my-custom-input", () => {}) // type-checked
163172
```
164173

165174
If not specified, `CustomInputName` defaults to just `string`.
@@ -201,11 +210,8 @@ Similarly, `GuiSpec` (the table passed to `LuaGuiElement.add`), is also a discri
201210

202211
This is done both to provide more accurate types, and for possible integration with [JSX](https://typescripttolua.github.io/docs/jsx/).
203212

204-
205213
## Support
206214

207215
If you find this project useful, consider tipping me on Kofi!
208216

209217
<a href='https://ko-fi.com/Z8Z1VI6P8' target='_blank'><img height='36' style='border:0px;height:36px;' src='https://storage.ko-fi.com/cdn/kofi2.png?v=3' border='0' alt='Buy Me a Coffee at ko-fi.com' /></a>
210-
211-

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"generate-no-format": "tsx --tsconfig generator/tsconfig.json generator/main.ts --no-format",
2727
"clean": "rimraf runtime/generated prototype/generated",
2828
"lint": "eslint .",
29-
"check": "tsc --noEmit && npm run lint",
29+
"check": "tsc --noEmit && npm run lint && prettier --check .",
3030
"prepublishOnly": "npm run generate && npm run check",
3131
"script": "tsx --tsconfig scripts/tsconfig.json",
3232
"download-latest-json-apis": "npm run script ./scripts/download-latest.ts",

scripts/download-latest.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ const destinationFolder = path.resolve(__dirname, "../generator/input")
1212
async function downloadApi(stage: string) {
1313
const url = `https://lua-api.factorio.com/latest/${stage}-api.json`
1414
console.log("downloading", url)
15-
const result = (await download(url, {
16-
timeout: 5000
17-
})).toString("utf8")
15+
const result = (
16+
await download(url, {
17+
timeout: 5000,
18+
})
19+
).toString("utf8")
1820
const contents = JSON.parse(result) as {
1921
application: string
2022
stage: string

tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@
1313
"types": [],
1414
"noEmit": true
1515
},
16-
"include": ["**/index.d.ts"],
16+
"include": ["**/index.d.ts"]
1717
}

0 commit comments

Comments
 (0)