@inglorious/create-app 1.10.0 → 1.11.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.
- package/bin/lib/app.js +43 -8
- package/package.json +1 -1
- package/templates/ssx-ts/types/index.d.ts +10 -2
- package/templates/ssx-ts-jsx/types/index.d.ts +10 -2
- package/templates/ts/src/app/index.ts +1 -1
- package/templates/ts/src/main.ts +6 -1
- package/templates/ts/src/store/index.ts +2 -2
- package/templates/ts/types/index.d.ts +10 -2
- package/templates/ts-jsx/src/main.ts +1 -1
- package/templates/ts-jsx/src/store/index.ts +2 -2
- package/templates/ts-jsx/types/index.d.ts +10 -2
- package/templates/ts-vue/src/main.ts +6 -1
package/bin/lib/app.js
CHANGED
|
@@ -333,7 +333,9 @@ function storeSource(app) {
|
|
|
333
333
|
)
|
|
334
334
|
}
|
|
335
335
|
if (app.isTypeScript) {
|
|
336
|
-
imports.push(
|
|
336
|
+
imports.push(
|
|
337
|
+
'import type { AppEntity, AppEvents, AppState } from "../../types"',
|
|
338
|
+
)
|
|
337
339
|
}
|
|
338
340
|
if (app.i18n) imports.push('import { I18n } from "../i18n"')
|
|
339
341
|
if (app.analytics) {
|
|
@@ -359,7 +361,7 @@ function storeSource(app) {
|
|
|
359
361
|
: ` types: {
|
|
360
362
|
${types.map((type) => ` ${type},`).join("\n")}
|
|
361
363
|
},`
|
|
362
|
-
const generics = app.isTypeScript ? "<AppEntity, AppState>" : ""
|
|
364
|
+
const generics = app.isTypeScript ? "<AppEntity, AppState, AppEvents>" : ""
|
|
363
365
|
|
|
364
366
|
return `${importBlock(imports)}
|
|
365
367
|
${app.routing ? "\nsetRoutes(routes)\n" : ""}
|
|
@@ -425,13 +427,35 @@ export const { I18n, t, ready } = createI18n({
|
|
|
425
427
|
`
|
|
426
428
|
}
|
|
427
429
|
|
|
430
|
+
/**
|
|
431
|
+
* `export type AppEvents = EventsOf<...>`, wrapped as Prettier would: on one
|
|
432
|
+
* line if it fits, then with the types on a line of their own, then one per
|
|
433
|
+
* line.
|
|
434
|
+
*/
|
|
435
|
+
function eventsOf(types) {
|
|
436
|
+
const head = "export type AppEvents = EventsOf<"
|
|
437
|
+
const oneLine = `${head}${types.join(" | ")}>`
|
|
438
|
+
if (oneLine.length <= LINE_WIDTH) return oneLine
|
|
439
|
+
const inner = ` ${types.join(" | ")}`
|
|
440
|
+
if (inner.length <= LINE_WIDTH) return `${head}\n${inner}\n>`
|
|
441
|
+
return `${head}\n${types.map((type) => ` | ${type}`).join("\n")}\n>`
|
|
442
|
+
}
|
|
443
|
+
|
|
428
444
|
function typesSource(app) {
|
|
429
445
|
const imports = [
|
|
430
446
|
'import "./vite-env"',
|
|
431
|
-
|
|
447
|
+
`import type {
|
|
448
|
+
BaseEntity,
|
|
449
|
+
EntitiesState,
|
|
450
|
+
EntityType,
|
|
451
|
+
EventsOf,
|
|
452
|
+
} from "@inglorious/store"`,
|
|
432
453
|
'import type { Api, TemplateResult } from "@inglorious/web"',
|
|
433
454
|
]
|
|
434
455
|
const entities = ["MessageEntity", "HomeEntity"]
|
|
456
|
+
// The types whose events the app sends: its own, then the libraries'.
|
|
457
|
+
const eventTypes = ["MessageType"]
|
|
458
|
+
if (app.renderer === "lit-html") eventTypes.push("HomeType")
|
|
435
459
|
const declarations = [
|
|
436
460
|
`export interface MessageEntity extends BaseEntity {
|
|
437
461
|
type: "Message"
|
|
@@ -450,7 +474,10 @@ function typesSource(app) {
|
|
|
450
474
|
]
|
|
451
475
|
|
|
452
476
|
if (app.routing) {
|
|
453
|
-
imports.push(
|
|
477
|
+
imports.push(
|
|
478
|
+
'import type { RouterEntity, RouterType } from "@inglorious/web/router"',
|
|
479
|
+
)
|
|
480
|
+
eventTypes.push("RouterType")
|
|
454
481
|
entities.push("AboutEntity", "AppRouterEntity")
|
|
455
482
|
declarations.push(
|
|
456
483
|
`export interface AboutEntity extends BaseEntity {
|
|
@@ -464,7 +491,8 @@ function typesSource(app) {
|
|
|
464
491
|
state.push(" about: AboutEntity")
|
|
465
492
|
}
|
|
466
493
|
if (app.i18n) {
|
|
467
|
-
imports.push('import type { I18nEntity } from "@inglorious/i18n"')
|
|
494
|
+
imports.push('import type { I18nEntity, I18nType } from "@inglorious/i18n"')
|
|
495
|
+
eventTypes.push("I18nType")
|
|
468
496
|
entities.push("AppI18nEntity")
|
|
469
497
|
declarations.push(
|
|
470
498
|
`export interface AppI18nEntity extends I18nEntity {
|
|
@@ -475,8 +503,9 @@ function typesSource(app) {
|
|
|
475
503
|
}
|
|
476
504
|
if (app.analytics) {
|
|
477
505
|
imports.push(
|
|
478
|
-
'import type { AnalyticsEntity } from "@inglorious/web/analytics"',
|
|
506
|
+
'import type { AnalyticsEntity, AnalyticsType } from "@inglorious/web/analytics"',
|
|
479
507
|
)
|
|
508
|
+
eventTypes.push("AnalyticsType")
|
|
480
509
|
entities.push("AppAnalyticsEntity")
|
|
481
510
|
declarations.push(
|
|
482
511
|
`export interface AppAnalyticsEntity extends AnalyticsEntity {
|
|
@@ -486,7 +515,10 @@ function typesSource(app) {
|
|
|
486
515
|
state.push(" analytics: AppAnalyticsEntity")
|
|
487
516
|
}
|
|
488
517
|
if (app.push) {
|
|
489
|
-
imports.push(
|
|
518
|
+
imports.push(
|
|
519
|
+
'import type { PushPromptEntity, PushPromptType } from "@inglorious/web/push"',
|
|
520
|
+
)
|
|
521
|
+
eventTypes.push("PushPromptType")
|
|
490
522
|
entities.push("AppPushPromptEntity")
|
|
491
523
|
declarations.push(
|
|
492
524
|
`export interface AppPushPromptEntity extends PushPromptEntity {
|
|
@@ -508,7 +540,10 @@ export interface AppState extends EntitiesState<AppEntity> {
|
|
|
508
540
|
${state.join("\n")}
|
|
509
541
|
}
|
|
510
542
|
|
|
511
|
-
|
|
543
|
+
// The events the app's types answer, so that \`notify\` checks them.
|
|
544
|
+
${eventsOf(eventTypes)}
|
|
545
|
+
|
|
546
|
+
export type AppApi = Api<AppEntity, AppState, AppEvents>
|
|
512
547
|
|
|
513
548
|
// Each type's events and their payloads. Declare types with \`type\`, not
|
|
514
549
|
// \`interface\`: an interface does not fit the store's \`types\`.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inglorious/create-app",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.11.0",
|
|
4
4
|
"description": "A scaffolding tool to quickly create a new app with Inglorious Web.",
|
|
5
5
|
"author": "Matteo Antony Mistretta <antony.mistretta@gmail.com> (https://ingloriouscoderz.it)",
|
|
6
6
|
"license": "MIT",
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {
|
|
2
|
+
BaseEntity,
|
|
3
|
+
EntitiesState,
|
|
4
|
+
EntityType,
|
|
5
|
+
EventsOf,
|
|
6
|
+
} from "@inglorious/store"
|
|
2
7
|
import type { Api, TemplateResult } from "@inglorious/web"
|
|
3
8
|
|
|
4
9
|
export interface AboutEntity extends BaseEntity {
|
|
@@ -12,7 +17,10 @@ export interface AppState extends EntitiesState<AppEntity> {
|
|
|
12
17
|
about: AboutEntity
|
|
13
18
|
}
|
|
14
19
|
|
|
15
|
-
|
|
20
|
+
// The events the types below answer, so that `notify` checks them.
|
|
21
|
+
export type AppEvents = EventsOf<AboutType>
|
|
22
|
+
|
|
23
|
+
export type AppApi = Api<AppEntity, AppState, AppEvents>
|
|
16
24
|
|
|
17
25
|
export type AboutType = {
|
|
18
26
|
click: (entity: AboutEntity) => void
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
/// <reference types="@inglorious/jsx/jsx-runtime" />
|
|
2
2
|
|
|
3
|
-
import type {
|
|
3
|
+
import type {
|
|
4
|
+
BaseEntity,
|
|
5
|
+
EntitiesState,
|
|
6
|
+
EntityType,
|
|
7
|
+
EventsOf,
|
|
8
|
+
} from "@inglorious/store"
|
|
4
9
|
import type { Api, TemplateResult } from "@inglorious/web"
|
|
5
10
|
|
|
6
11
|
export interface AboutEntity extends BaseEntity {
|
|
@@ -14,7 +19,10 @@ export interface AppState extends EntitiesState<AppEntity> {
|
|
|
14
19
|
about: AboutEntity
|
|
15
20
|
}
|
|
16
21
|
|
|
17
|
-
|
|
22
|
+
// The events the types below answer, so that `notify` checks them.
|
|
23
|
+
export type AppEvents = EventsOf<AboutType>
|
|
24
|
+
|
|
25
|
+
export type AppApi = Api<AppEntity, AppState, AppEvents>
|
|
18
26
|
|
|
19
27
|
export type AboutType = {
|
|
20
28
|
click: (entity: AboutEntity) => void
|
|
@@ -3,7 +3,7 @@ import { html } from "@inglorious/web"
|
|
|
3
3
|
import type { AppApi } from "../../types"
|
|
4
4
|
|
|
5
5
|
export const App = {
|
|
6
|
-
render(
|
|
6
|
+
render(_props: Record<string, unknown> | null, api: AppApi) {
|
|
7
7
|
return html`<h1>
|
|
8
8
|
${api.render("message1")}, ${api.render("message2")},
|
|
9
9
|
${api.render("message3")}!
|
package/templates/ts/src/main.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { mount } from "@inglorious/web"
|
|
2
2
|
|
|
3
|
+
import type { AppApi } from "../types"
|
|
3
4
|
import { App } from "./app"
|
|
4
5
|
import { store } from "./store"
|
|
5
6
|
|
|
6
|
-
mount(
|
|
7
|
+
mount(
|
|
8
|
+
store,
|
|
9
|
+
(api: AppApi) => App.render(null, api),
|
|
10
|
+
document.getElementById("root")!,
|
|
11
|
+
)
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { createStore } from "@inglorious/store"
|
|
2
2
|
|
|
3
|
-
import type { AppEntity, AppState } from "../../types"
|
|
3
|
+
import type { AppEntity, AppEvents, AppState } from "../../types"
|
|
4
4
|
import { Message } from "../app/message"
|
|
5
5
|
import { entities } from "./entities"
|
|
6
6
|
import { middlewares } from "./middlewares"
|
|
7
7
|
|
|
8
|
-
export const store = createStore<AppEntity, AppState>({
|
|
8
|
+
export const store = createStore<AppEntity, AppState, AppEvents>({
|
|
9
9
|
types: { Message },
|
|
10
10
|
entities,
|
|
11
11
|
middlewares,
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import "./vite-env"
|
|
2
2
|
|
|
3
|
-
import type {
|
|
3
|
+
import type {
|
|
4
|
+
BaseEntity,
|
|
5
|
+
EntitiesState,
|
|
6
|
+
EntityType,
|
|
7
|
+
EventsOf,
|
|
8
|
+
} from "@inglorious/store"
|
|
4
9
|
import type { Api, TemplateResult } from "@inglorious/web"
|
|
5
10
|
|
|
6
11
|
export interface MessageEntity extends BaseEntity {
|
|
@@ -17,7 +22,10 @@ export interface AppState extends EntitiesState<AppEntity> {
|
|
|
17
22
|
message3: MessageEntity
|
|
18
23
|
}
|
|
19
24
|
|
|
20
|
-
|
|
25
|
+
// The events the types below answer, so that `notify` checks them.
|
|
26
|
+
export type AppEvents = EventsOf<MessageType>
|
|
27
|
+
|
|
28
|
+
export type AppApi = Api<AppEntity, AppState, AppEvents>
|
|
21
29
|
|
|
22
30
|
export type MessageType = {
|
|
23
31
|
click: (entity: MessageEntity) => void
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { createStore } from "@inglorious/store"
|
|
2
2
|
|
|
3
|
-
import type { AppEntity, AppState } from "../../types"
|
|
3
|
+
import type { AppEntity, AppEvents, AppState } from "../../types"
|
|
4
4
|
import { Message } from "../app/message"
|
|
5
5
|
import { entities } from "./entities"
|
|
6
6
|
import { middlewares } from "./middlewares"
|
|
7
7
|
|
|
8
|
-
export const store = createStore<AppEntity, AppState>({
|
|
8
|
+
export const store = createStore<AppEntity, AppState, AppEvents>({
|
|
9
9
|
types: { Message },
|
|
10
10
|
entities,
|
|
11
11
|
middlewares,
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import "./vite-env"
|
|
2
2
|
|
|
3
|
-
import type {
|
|
3
|
+
import type {
|
|
4
|
+
BaseEntity,
|
|
5
|
+
EntitiesState,
|
|
6
|
+
EntityType,
|
|
7
|
+
EventsOf,
|
|
8
|
+
} from "@inglorious/store"
|
|
4
9
|
import type { Api, TemplateResult } from "@inglorious/web"
|
|
5
10
|
|
|
6
11
|
export interface MessageEntity extends BaseEntity {
|
|
@@ -17,7 +22,10 @@ export interface AppState extends EntitiesState<AppEntity> {
|
|
|
17
22
|
message3: MessageEntity
|
|
18
23
|
}
|
|
19
24
|
|
|
20
|
-
|
|
25
|
+
// The events the types below answer, so that `notify` checks them.
|
|
26
|
+
export type AppEvents = EventsOf<MessageType>
|
|
27
|
+
|
|
28
|
+
export type AppApi = Api<AppEntity, AppState, AppEvents>
|
|
21
29
|
|
|
22
30
|
export type MessageType = {
|
|
23
31
|
click: (entity: MessageEntity) => void
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import { mount } from "@inglorious/web"
|
|
2
2
|
|
|
3
|
+
import type { AppApi } from "../types"
|
|
3
4
|
// @ts-expect-error - Handled by @inglorious/vite-plugin-vue
|
|
4
5
|
import { App } from "./app/index.vue"
|
|
5
6
|
import { store } from "./store"
|
|
6
7
|
|
|
7
|
-
mount(
|
|
8
|
+
mount(
|
|
9
|
+
store,
|
|
10
|
+
(api: AppApi) => App.render(null, api),
|
|
11
|
+
document.getElementById("root")!,
|
|
12
|
+
)
|