@inglorious/create-app 1.3.0 → 1.4.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.
@@ -252,9 +252,7 @@ export function messageSource(app) {
252
252
  }
253
253
  if (app.i18n) imports.push('import { t } from "../i18n"')
254
254
  const greeting = app.i18n ? '{t("message.hello", { who })}' : "Hello {who}"
255
- const declaration = app.isTypeScript
256
- ? "export const Message: MessageType = {"
257
- : "export const Message = {"
255
+ const annotation = app.isTypeScript ? ": MessageType" : ""
258
256
 
259
257
  const span = app.i18n
260
258
  ? ` <span onClick={() => api.notify(\`#\${entity.id}:click\`)}>
@@ -264,7 +262,7 @@ export function messageSource(app) {
264
262
 
265
263
  const head = imports.length ? `${importBlock(imports)}\n\n` : ""
266
264
 
267
- return `${head}${declaration}
265
+ return `${head}export const Message${annotation} = {
268
266
  click(entity) {
269
267
  entity.isUpperCase = !entity.isUpperCase
270
268
  },
@@ -187,7 +187,7 @@ export function homeSource(app, { showcase }) {
187
187
  imports.push('import { Icon } from "@inglorious/ui/icon"')
188
188
  }
189
189
  if (app.isTypeScript) {
190
- imports.push('import type { AppApi, HomeEntity } from "../../types"')
190
+ imports.push('import type { HomeType } from "../../types"')
191
191
  }
192
192
  if (app.i18n) imports.push('import { t } from "../i18n"')
193
193
 
@@ -207,14 +207,12 @@ ${showcase
207
207
  </p>`
208
208
  : ""
209
209
 
210
- const signature = app.isTypeScript
211
- ? "render(entity: HomeEntity, api: AppApi)"
212
- : "render(entity, api)"
210
+ const annotation = app.isTypeScript ? ": HomeType" : ""
213
211
 
214
212
  return `${importBlock(imports)}
215
213
 
216
- export const Home = {
217
- ${signature} {
214
+ export const Home${annotation} = {
215
+ render(entity, api) {
218
216
  return html\`
219
217
  <h1>${text("home.title", "Welcome")}</h1>
220
218
  <p>
@@ -253,13 +251,11 @@ export function messageSource(app) {
253
251
  }
254
252
  if (app.i18n) imports.push('import { t } from "../i18n"')
255
253
  const greeting = app.i18n ? '${t("message.hello", { who })}' : "Hello ${who}"
256
- const declaration = app.isTypeScript
257
- ? "export const Message: MessageType = {"
258
- : "export const Message = {"
254
+ const annotation = app.isTypeScript ? ": MessageType" : ""
259
255
 
260
256
  return `${importBlock(imports)}
261
257
 
262
- ${declaration}
258
+ export const Message${annotation} = {
263
259
  click(entity) {
264
260
  entity.isUpperCase = !entity.isUpperCase
265
261
  },
package/bin/lib/app.js CHANGED
@@ -227,9 +227,7 @@ main {
227
227
 
228
228
  function storeSource(app) {
229
229
  const imports = [
230
- app.isTypeScript
231
- ? 'import { createStore, type TypesConfig } from "@inglorious/store"'
232
- : 'import { createStore } from "@inglorious/store"',
230
+ 'import { createStore } from "@inglorious/store"',
233
231
  componentImport(app, "Home", "../pages/home"),
234
232
  componentImport(app, "Message", "../types/message"),
235
233
  'import { entities } from "./entities"',
@@ -250,14 +248,13 @@ function storeSource(app) {
250
248
  const types = ["Message", "Home"]
251
249
  if (app.routing) types.push("About", "Router")
252
250
  if (app.i18n) types.push("I18n")
253
- const cast = app.isTypeScript ? " as unknown as TypesConfig<AppEntity>" : ""
254
- const oneLine = ` types: { ${types.join(", ")} }${cast},`
251
+ const oneLine = ` types: { ${types.join(", ")} },`
255
252
  const typesValue =
256
253
  oneLine.length <= LINE_WIDTH
257
254
  ? oneLine
258
255
  : ` types: {
259
256
  ${types.map((type) => ` ${type},`).join("\n")}
260
- }${cast},`
257
+ },`
261
258
  const generics = app.isTypeScript ? "<AppEntity, AppState>" : ""
262
259
 
263
260
  return `${importBlock(imports)}
@@ -333,14 +330,13 @@ export const { I18n, t, ready } = createI18n({
333
330
  function typesSource(app) {
334
331
  const imports = [
335
332
  'import "./vite-end"',
336
- 'import type { BaseEntity, EntitiesState } from "@inglorious/store"',
333
+ 'import type {\n BaseEntity,\n EntitiesState,\n EntityType,\n} from "@inglorious/store"',
337
334
  'import type { Api, TemplateResult } from "@inglorious/web"',
338
335
  ]
339
336
  const entities = ["MessageEntity", "HomeEntity"]
340
337
  const declarations = [
341
338
  `export interface MessageEntity extends BaseEntity {
342
339
  type: "Message"
343
- id?: string
344
340
  who: string
345
341
  isUpperCase?: boolean
346
342
  }`,
@@ -362,7 +358,7 @@ function typesSource(app) {
362
358
  `export interface AboutEntity extends BaseEntity {
363
359
  type: "About"
364
360
  }`,
365
- `export interface AppRouterEntity extends BaseEntity, Omit<RouterEntity, "id"> {
361
+ `export interface AppRouterEntity extends RouterEntity {
366
362
  type: "Router"
367
363
  }`,
368
364
  )
@@ -373,7 +369,7 @@ function typesSource(app) {
373
369
  imports.push('import type { I18nEntity } from "@inglorious/i18n"')
374
370
  entities.push("AppI18nEntity")
375
371
  declarations.push(
376
- `export interface AppI18nEntity extends BaseEntity, Omit<I18nEntity, "id"> {
372
+ `export interface AppI18nEntity extends I18nEntity {
377
373
  type: "I18n"
378
374
  }`,
379
375
  )
@@ -394,9 +390,23 @@ ${state.join("\n")}
394
390
 
395
391
  export type AppApi = Api<AppEntity, AppState>
396
392
 
397
- export interface MessageType {
393
+ // Each type's events and their payloads. Declare types with \`type\`, not
394
+ // \`interface\`: an interface does not fit the store's \`types\`.
395
+ export type MessageType = {
398
396
  click: (entity: MessageEntity) => void
399
- render: (entity: MessageEntity, api: AppApi) => TemplateResult | null
397
+ render: (entity: MessageEntity, api: AppApi) => TemplateResult
398
+ }
399
+ ${
400
+ app.renderer === "lit-html"
401
+ ? `
402
+ export type HomeType = {
403
+ render: (entity: HomeEntity, api: AppApi) => TemplateResult
404
+ }
405
+ `
406
+ : ""
400
407
  }
408
+ // A shorthand for a type: \`{ ... } satisfies AppType<MessageEntity>\` infers
409
+ // its handlers' parameters, but neither lists its events nor types payloads.
410
+ export type AppType<TEntity extends AppEntity> = EntityType<TEntity, AppApi>
401
411
  `
402
412
  }
package/bin/lib/pwa.js CHANGED
@@ -93,7 +93,9 @@ export function writePwaRegistration(targetDir) {
93
93
 
94
94
  export function createPwaRegistrationSource(extension) {
95
95
  if (extension === ".ts") {
96
- return `/// <reference types="vite-plugin-pwa/client" />
96
+ return `// Only the framework-free helpers: "client" also loads React's and Preact's
97
+ // typings, whose global JSX would replace Inglorious's.
98
+ /// <reference types="vite-plugin-pwa/vanillajs" />
97
99
  import { isNative } from "@inglorious/web/mobile"
98
100
  import { registerSW } from "virtual:pwa-register"
99
101
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inglorious/create-app",
3
- "version": "1.3.0",
3
+ "version": "1.4.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",
@@ -37,7 +37,7 @@
37
37
  "prompts": "^2.4.2"
38
38
  },
39
39
  "devDependencies": {
40
- "@inglorious/eslint-config": "1.1.3",
40
+ "@inglorious/eslint-config": "1.1.4",
41
41
  "prettier": "^3.9.6"
42
42
  },
43
43
  "scripts": {
@@ -1,13 +1,13 @@
1
- import { Api, html } from "@inglorious/web"
1
+ import { html } from "@inglorious/web"
2
2
 
3
- import type { AboutEntity } from "../../types"
3
+ import type { AboutType } from "../../types"
4
4
 
5
- export const About = {
6
- click(entity: AboutEntity) {
5
+ export const About: AboutType = {
6
+ click(entity) {
7
7
  entity.name += "!"
8
8
  },
9
9
 
10
- render(entity: AboutEntity, api: Api) {
10
+ render(entity, api) {
11
11
  return html`
12
12
  <div>
13
13
  <h1>
@@ -1,9 +1,9 @@
1
- import { BaseEntity, EntitiesState } from "@inglorious/store"
1
+ import type { BaseEntity, EntitiesState, EntityType } from "@inglorious/store"
2
+ import type { Api, TemplateResult } from "@inglorious/web"
2
3
 
3
4
  // Define your entity types
4
5
  export interface AboutEntity extends BaseEntity {
5
6
  type: "About"
6
- id?: string
7
7
  name: string
8
8
  }
9
9
 
@@ -15,9 +15,15 @@ export interface AppState extends EntitiesState<AppEntity> {
15
15
  about: AboutEntity
16
16
  }
17
17
 
18
- // Types configuration
19
- export interface AppTypes {
20
- About: {
21
- click: (entity: AboutEntity) => void
22
- }
18
+ export type AppApi = Api<AppEntity, AppState>
19
+
20
+ // Each type's events and their payloads. Declare types with `type`, not
21
+ // `interface`: an interface does not fit the store's `types`.
22
+ export type AboutType = {
23
+ click: (entity: AboutEntity) => void
24
+ render: (entity: AboutEntity, api: AppApi) => TemplateResult
23
25
  }
26
+
27
+ // A shorthand for a type: `{ ... } satisfies AppType<AboutEntity>` infers
28
+ // its handlers' parameters, but neither lists its events nor types payloads.
29
+ export type AppType<TEntity extends AppEntity> = EntityType<TEntity, AppApi>
@@ -1,4 +1,4 @@
1
- import { createStore, type TypesConfig } from "@inglorious/store"
1
+ import { createStore } from "@inglorious/store"
2
2
 
3
3
  import type { AppEntity, AppState } from "../../types"
4
4
  import { Message } from "../types/message"
@@ -6,7 +6,7 @@ import { entities } from "./entities"
6
6
  import { middlewares } from "./middlewares"
7
7
 
8
8
  export const store = createStore<AppEntity, AppState>({
9
- types: { Message } as unknown as TypesConfig<AppEntity>,
9
+ types: { Message },
10
10
  entities,
11
11
  middlewares,
12
12
  })
@@ -1,12 +1,11 @@
1
1
  import "./vite-end"
2
2
 
3
- import { BaseEntity, EntitiesState } from "@inglorious/store"
4
- import { Api, TemplateResult } from "@inglorious/web"
3
+ import type { BaseEntity, EntitiesState, EntityType } from "@inglorious/store"
4
+ import type { Api, TemplateResult } from "@inglorious/web"
5
5
 
6
6
  // Define your entity types
7
7
  export interface MessageEntity extends BaseEntity {
8
8
  type: "Message"
9
- id?: string
10
9
  who: string
11
10
  isUpperCase?: boolean
12
11
  }
@@ -23,8 +22,13 @@ export interface AppState extends EntitiesState<AppEntity> {
23
22
 
24
23
  export type AppApi = Api<AppEntity, AppState>
25
24
 
26
- // Types configuration
27
- export interface MessageType {
25
+ // Each type's events and their payloads. Declare types with `type`, not
26
+ // `interface`: an interface does not fit the store's `types`.
27
+ export type MessageType = {
28
28
  click: (entity: MessageEntity) => void
29
- render: (entity: MessageEntity, api: AppApi) => TemplateResult | null
29
+ render: (entity: MessageEntity, api: AppApi) => TemplateResult
30
30
  }
31
+
32
+ // A shorthand for a type: `{ ... } satisfies AppType<MessageEntity>` infers
33
+ // its handlers' parameters, but neither lists its events nor types payloads.
34
+ export type AppType<TEntity extends AppEntity> = EntityType<TEntity, AppApi>
@@ -1,4 +1,4 @@
1
- import { createStore, type TypesConfig } from "@inglorious/store"
1
+ import { createStore } from "@inglorious/store"
2
2
 
3
3
  import type { AppEntity, AppState } from "../../types"
4
4
  import { Message } from "../types/message"
@@ -6,7 +6,7 @@ import { entities } from "./entities"
6
6
  import { middlewares } from "./middlewares"
7
7
 
8
8
  export const store = createStore<AppEntity, AppState>({
9
- types: { Message } as unknown as TypesConfig<AppEntity>,
9
+ types: { Message },
10
10
  entities,
11
11
  middlewares,
12
12
  })
@@ -1,12 +1,11 @@
1
1
  import "./vite-end"
2
2
 
3
- import { BaseEntity, EntitiesState } from "@inglorious/store"
4
- import { Api, TemplateResult } from "@inglorious/web"
3
+ import type { BaseEntity, EntitiesState, EntityType } from "@inglorious/store"
4
+ import type { Api, TemplateResult } from "@inglorious/web"
5
5
 
6
6
  // Define your entity types
7
7
  export interface MessageEntity extends BaseEntity {
8
8
  type: "Message"
9
- id?: string
10
9
  who: string
11
10
  isUpperCase?: boolean
12
11
  }
@@ -23,8 +22,13 @@ export interface AppState extends EntitiesState<AppEntity> {
23
22
 
24
23
  export type AppApi = Api<AppEntity, AppState>
25
24
 
26
- // Types configuration
27
- export interface MessageType {
25
+ // Each type's events and their payloads. Declare types with `type`, not
26
+ // `interface`: an interface does not fit the store's `types`.
27
+ export type MessageType = {
28
28
  click: (entity: MessageEntity) => void
29
- render: (entity: MessageEntity, api: AppApi) => TemplateResult | null
29
+ render: (entity: MessageEntity, api: AppApi) => TemplateResult
30
30
  }
31
+
32
+ // A shorthand for a type: `{ ... } satisfies AppType<MessageEntity>` infers
33
+ // its handlers' parameters, but neither lists its events nor types payloads.
34
+ export type AppType<TEntity extends AppEntity> = EntityType<TEntity, AppApi>
@@ -1,4 +1,4 @@
1
- import { createStore, type TypesConfig } from "@inglorious/store"
1
+ import { createStore } from "@inglorious/store"
2
2
 
3
3
  import type { AppEntity, AppState } from "../../types"
4
4
  // @ts-expect-error - Handled by @inglorious/vite-plugin-vue
@@ -7,7 +7,7 @@ import { entities } from "./entities"
7
7
  import { middlewares } from "./middlewares"
8
8
 
9
9
  export const store = createStore<AppEntity, AppState>({
10
- types: { Message } as unknown as TypesConfig<AppEntity>,
10
+ types: { Message },
11
11
  entities,
12
12
  middlewares,
13
13
  })
@@ -1,12 +1,11 @@
1
1
  import "./vite-end"
2
2
 
3
- import { BaseEntity, EntitiesState } from "@inglorious/store"
4
- import { Api, TemplateResult } from "@inglorious/web"
3
+ import type { BaseEntity, EntitiesState, EntityType } from "@inglorious/store"
4
+ import type { Api } from "@inglorious/web"
5
5
 
6
6
  // Define your entity types
7
7
  export interface MessageEntity extends BaseEntity {
8
8
  type: "Message"
9
- id?: string
10
9
  who: string
11
10
  isUpperCase?: boolean
12
11
  }
@@ -23,8 +22,7 @@ export interface AppState extends EntitiesState<AppEntity> {
23
22
 
24
23
  export type AppApi = Api<AppEntity, AppState>
25
24
 
26
- // Types configuration
27
- export interface MessageType {
28
- click: (entity: MessageEntity) => void
29
- render: (entity: MessageEntity, api: AppApi) => TemplateResult | null
30
- }
25
+ // A type for one of the app's entities. For rigour, declare a type alias
26
+ // listing its events and payloads; this shorthand infers its handlers'
27
+ // parameters with `{ ... } satisfies AppType<MessageEntity>`.
28
+ export type AppType<TEntity extends AppEntity> = EntityType<TEntity, AppApi>