nuxt-ignis 0.1.4 → 0.1.5

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/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.1.5 (2024-12-21)
4
+ - feat: more flexible config for `i18n` and `formkit`
5
+ - docs: improved instructions for using as a layer
6
+
3
7
  ## 0.1.4 (2024-12-07)
4
8
  - feat: include `elrh-pslo` text utility
5
9
  - docs: add instructions for using as a layer
package/README.md CHANGED
@@ -20,20 +20,34 @@ Aside from being "forked", `nuxt-ignis` is also available as [NPM package](https
20
20
 
21
21
  1) Add following dependency into your `package.json`:
22
22
  ```
23
- "nuxt-ignis": "0.1.4"
23
+ "nuxt-ignis": "0.1.5"
24
24
  ```
25
25
 
26
26
  2) Add following section into your `nuxt.config.ts`:
27
27
  ```
28
28
  extends: [
29
- `nuxt-ignis`
29
+ 'nuxt-ignis'
30
30
  ]
31
31
  ```
32
32
 
33
- 3) Setup your `.env` to fit your project needs. Check [Configuration](#Configuration) section for reference.
33
+ 3) Add `.npmrc` file with following content (if you don't have it yet):
34
+ ```
35
+ shamefully-hoist=true
36
+ strict-peer-dependencies=false
37
+ ```
38
+
39
+ 4) Setup your `.env` to fit your project needs. Check [Configuration](#Configuration) section for reference.
34
40
 
35
41
  You are ready to build your next awesome project in Nuxt!
36
42
 
43
+ #### Netlify deployment note
44
+ If you use [Netlify](https://www.netlify.com/) for deployment then for some reasons [not yet clear to me](https://github.com/nuxt/nuxt/discussions/30187) after extending from Nuxt Ignis you have to add two explicit dependencies into your `package.json`, namely:
45
+ ```
46
+ "vue": "latest",
47
+ "vue-router": "latest"
48
+ ```
49
+ Without this workaround the project builds and deploys but will hit runtime error 500 upon loading the page. Hopefully, this is just a temporary issue (12/2024).
50
+
37
51
  ## Overview
38
52
 
39
53
  **Fundamentals**
@@ -92,12 +106,21 @@ Currently, following modules are opinionated:
92
106
  - `@nuxtjs/tailwindcss` - set `NUXT_PUBLIC_IGNIS_TAILWIND` to `true | false` (ignored if `NUXT_PUBLIC_IGNIS_UI=true`)
93
107
  - `nuxt-neon` - set `NUXT_PUBLIC_IGNIS_NEON` to `true | false`
94
108
  - `@nuxtjs/supabase` - set `NUXT_PUBLIC_IGNIS_SUPABASE` to `true | false`
95
- - `@nuxtjs/i18n` - set `NUXT_PUBLIC_IGNIS_I18N` to `true | false`
96
- - `@formkit/nuxt` - set `NUXT_PUBLIC_IGNIS_FORMKIT` to `true | false`
109
+ - `@nuxtjs/i18n` - set `NUXT_PUBLIC_IGNIS_I18N_ENABLED` to `true | false`
110
+ - `@formkit/nuxt` - set `NUXT_PUBLIC_IGNIS_FORMKIT_ENABLED` to `true | false`
97
111
  - `@nuxt/content` - set `NUXT_PUBLIC_IGNIS_CONTENT` to `true | false`
98
112
 
99
113
  Default values are **false** (not included) for all optional modules.
100
114
 
115
+ #### I18N options
116
+ - you can select default language locale via `NUXT_PUBLIC_IGNIS_I18N_LOCALE`
117
+ - all `.json` files with messages in `@assets/lang` folder will be auto-scanned
118
+ - if [default config file](https://github.com/AloisSeckar/nuxt-ignis/blob/main/i18n.config.ts) is not suitable for your project, you may specify path to your own using `NUXT_PUBLIC_IGNIS_I18N_CONFIG`
119
+
120
+ #### Formkit options
121
+ - you can select default language locale via `NUXT_PUBLIC_IGNIS_FORMKIT_LOCALE`
122
+ - if [default config file](https://github.com/AloisSeckar/nuxt-ignis/blob/main/i18n.config.ts) is not suitable for your project, you may specify path to your own using `NUXT_PUBLIC_IGNIS_FORMKIT_CONFIG`
123
+
101
124
  ### Optional features
102
125
  Currently, following extra features (not using separate Nuxt Modules) are opinionated:
103
126
  - `Open Props CSS` - set `NUXT_PUBLIC_IGNIS_OPENPROPS` to `true | false`
package/app.vue CHANGED
@@ -25,8 +25,8 @@ useHead({
25
25
  lang: 'en',
26
26
  },
27
27
  bodyAttrs: {
28
- class: 'bg-slate-900 m-auto text-center text-white'
29
- }
28
+ class: 'bg-slate-900 m-auto text-center text-white',
29
+ },
30
30
  })
31
31
  initConsola()
32
32
  log.info('Nuxt Ignis was here!')
@@ -35,9 +35,9 @@
35
35
  * Macro `defineProps()` comes from Vue.js API
36
36
  * (https://vuejs.org/api/sfc-script-setup.html#defineprops-defineemits).
37
37
  * This is how to pass variables inside components in Vue.
38
- *
38
+ *
39
39
  * `required` - value has to be provided, otherwise an error will occur
40
- *
40
+ *
41
41
  * `default` - will have this value, unless overwritten by caller
42
42
  */
43
43
  const props = defineProps({
@@ -48,7 +48,8 @@ const props = defineProps({
48
48
  /**
49
49
  * `Icon` component can only be used if `@nuxt/ui` module is activated.
50
50
  */
51
- const showIcon = useRuntimeConfig().public.ignis.ui === 'nuxt-ui'
51
+ const config = useRuntimeConfig().public.ignis
52
+ const showIcon = config.preset.ui === 'nuxt-ui' || config.ui
52
53
 
53
54
  // In setup section, you have to adress properties like this.
54
55
  // You cannot reach them directly like in template.
@@ -20,8 +20,7 @@
20
20
  day="2-digit"
21
21
  hour="2-digit"
22
22
  minute="2-digit"
23
- second="2-digit"
24
- />
23
+ second="2-digit" />
25
24
  </div>
26
25
  </template>
27
26
 
@@ -2,47 +2,46 @@ import lang from '@/assets/lang/en.json'
2
2
 
3
3
  /**
4
4
  * An adapter above `t` function from `i18n` module.
5
- *
5
+ *
6
6
  * This function is basically a shorthand for obtaining `i18n` translation in scripts.
7
7
  * In templates `$t` function is available, but in scripts we normally have to
8
8
  * access the `t` function via the instance of `$i18n` living inside current Nuxt App.
9
- *
10
- * Since $i18n is an optional dependency in Nuxt Ignis setup, this also gracefully handles
9
+ *
10
+ * Since $i18n is an optional dependency in Nuxt Ignis setup, this also gracefully handles
11
11
  * cases when user turns the module off while still using the translations in the code.
12
- *
12
+ *
13
13
  * @param key identifier of text that should be displayed
14
14
  * @returns translated text from i18n sources
15
15
  */
16
16
  export function useT(key: string): string {
17
- if (useRuntimeConfig().public.ignis.i18n) {
17
+ if (useRuntimeConfig().public.ignis.i18n.enabled) {
18
18
  // i18n available => just use it
19
- // @ts-ignore (in case i18n is turned off, type of $i18n cannot be infered)
20
19
  return useNuxtApp().$i18n.t(key)
21
20
  } else {
22
21
  // backdoor for Nuxt Ignis to display values on demo index page
23
22
  const backdoorValue = searchLang(key)
24
23
  if (backdoorValue) {
25
- return backdoorValue as string
24
+ return backdoorValue as string
26
25
  }
27
26
  // for other custom values a warning will be produced and a placeholder will be returned
28
27
  log.warn('@nuxtjs/i18n turned off, translations are not available (set NUXT_PUBLIC_IGNIS_I18N=true)')
29
- return "Translation not available"
28
+ return 'Translation not available'
30
29
  }
31
30
  }
32
31
 
33
32
  /** AI-generated helper to search a value for given key in JSON lang file. */
34
33
  function searchLang(key: string): unknown {
35
- const keys = key.split(".")
34
+ const keys = key.split('.')
36
35
 
37
- let current = lang
38
- for (const key of keys) {
39
- if (current && key in current) {
40
- // @ts-expect-error TODO this should be fixed
41
- current = current[key]
42
- } else {
43
- return undefined
44
- }
36
+ let current = lang
37
+ for (const key of keys) {
38
+ if (current && key in current) {
39
+ // @ts-expect-error TODO this should be fixed
40
+ current = current[key]
41
+ } else {
42
+ return undefined
45
43
  }
44
+ }
46
45
 
47
- return current
46
+ return current
48
47
  }
package/features.ts CHANGED
@@ -61,22 +61,28 @@ export function setFeatures() {
61
61
  }
62
62
 
63
63
  // i18n
64
- if (process.env.NUXT_PUBLIC_IGNIS_I18N === 'true') {
64
+ if (process.env.NUXT_PUBLIC_IGNIS_I18N_ENABLED === 'true') {
65
65
  // module definition
66
66
  nuxtConfig.modules.push('@nuxtjs/i18n')
67
67
  // module-specific config key
68
68
  nuxtConfig = defu({
69
69
  i18n: {
70
- vueI18n: './i18n.config.ts',
71
- locales: ['en'],
72
- defaultLocale: 'en',
70
+ vueI18n: process.env.NUXT_PUBLIC_IGNIS_I18N_CONFIG || './i18n.config.ts',
73
71
  },
74
72
  }, nuxtConfig)
75
73
  }
76
74
 
77
75
  // formkit
78
- if (process.env.NUXT_PUBLIC_IGNIS_FORMKIT === 'true') {
76
+ if (process.env.NUXT_PUBLIC_IGNIS_FORMKIT_ENABLED === 'true') {
77
+ // module definition
79
78
  nuxtConfig.modules.push('@formkit/nuxt')
79
+ // module-specific config key
80
+ nuxtConfig = defu({
81
+ formkit: {
82
+ autoImport: true,
83
+ configFile: process.env.NUXT_PUBLIC_IGNIS_FORMKIT_CONFIG || './formkit.config.ts',
84
+ },
85
+ }, nuxtConfig)
80
86
  }
81
87
 
82
88
  // content
package/formkit.config.ts CHANGED
@@ -1,11 +1,12 @@
1
1
  // https://formkit.com/guides/optimizing-for-production#using-the-nuxt-module
2
- import { en, de } from '@formkit/i18n'
2
+ import { en, de, cs } from '@formkit/i18n'
3
3
  import type { DefaultConfigOptions } from '@formkit/vue'
4
4
 
5
+ const ignisLocale = process.env.NUXT_PUBLIC_IGNIS_FORMKIT_DEFAULT || 'en'
6
+
5
7
  const config: DefaultConfigOptions = {
6
- // example of importing different message translations and set the default one
7
- locales: { en, de },
8
- locale: 'en',
8
+ locales: { en, de, cs }, // TODO allow multiple locales
9
+ locale: ignisLocale,
9
10
  }
10
11
 
11
12
  export default config
package/i18n.config.ts CHANGED
@@ -1,12 +1,12 @@
1
- import en from '@/assets/lang/en.json'
2
- // create and load more language files if needed
1
+ const ignisLocale = process.env.NUXT_PUBLIC_IGNIS_I18N_DEFAULT || 'en'
3
2
 
3
+ // https://i18n.nuxtjs.org/docs/composables/define-i18n-config
4
4
  export default defineI18nConfig(() => ({
5
5
  legacy: false,
6
6
  strategy: 'no_prefix',
7
- locale: 'en',
8
- defaultLocale: 'en',
9
- fallbackLocale: 'en',
10
- messages: { en }, // allowe more language if needed
7
+ locale: ignisLocale,
8
+ defaultLocale: ignisLocale,
9
+ fallbackLocale: ignisLocale,
10
+ messages: scanI18NSources(), // will dynamically load all .jsons from @/assets/lang/*
11
11
  warnHtmlMessage: false,
12
12
  }))
package/nuxt.config.ts CHANGED
@@ -26,6 +26,7 @@ const nuxtConfig = defu(ignisFeatures, {
26
26
  // NOTE: due to static-like nature of nuxt.config.ts file
27
27
  // actual values MUST BE provided via .env file (or production equivalent)
28
28
  ignis: {
29
+ // presets
29
30
  preset: {
30
31
  ui: 'off', // nuxt-ui/tailwind/off
31
32
  db: 'off', // neon/supabase/off
@@ -35,8 +36,16 @@ const nuxtConfig = defu(ignisFeatures, {
35
36
  tailwind: false, // true/false (ignored, if ui=true)
36
37
  neon: false, // true/false
37
38
  supabase: false, // true/false
38
- i18n: false, // true/false
39
- formkit: false, // true/false
39
+ i18n: {
40
+ enabled: false, // true/false
41
+ default: 'en', // default locale (should be same as formkit)
42
+ config: './i18n.config.ts', // path to config file
43
+ },
44
+ formkit: {
45
+ enabled: false, // true/false
46
+ default: 'en', // default locale (should be same as i18n)
47
+ config: './formkit.config.ts', // path to config file
48
+ },
40
49
  content: false, // true/false
41
50
  openprops: false, // true/false
42
51
  pslo: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nuxt-ignis",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "description": "Enhanced and customizable Nuxt application starter pack",
5
5
  "repository": "github:AloisSeckar/nuxt-ignis",
6
6
  "license": "MIT",
package/pages/index.vue CHANGED
@@ -48,8 +48,8 @@ const nuxtui = ui === 'nuxt-ui' || setup.ui
48
48
  const tailwind = ui !== 'off' || setup.ui || setup.tailwind
49
49
  const neon = db === 'neon' || setup.neon
50
50
  const supabase = db === 'supabase' || setup.supabase
51
- const i18n = setup.i18n
52
- const formkit = setup.formkit
51
+ const i18n = setup.i18n.enabled
52
+ const formkit = setup.formkit.enabled
53
53
  const content = setup.content
54
54
  const openprops = setup.openprops
55
55
  </script>
@@ -0,0 +1,18 @@
1
+ // scans @/assets/lang/* for all .json files with i18n messages
2
+ // and makes them available for i18n.config.ts
3
+
4
+ import type { LocaleMessage } from '@intlify/core-base'
5
+
6
+ export function scanI18NSources() {
7
+ const modules = import.meta.glob('@/assets/lang/*.json', { eager: true })
8
+
9
+ const messages = {} as { [x: string]: LocaleMessage<unknown> }
10
+ for (const path in modules) {
11
+ const locale = path.match(/\/([^/]+)\.json$/)
12
+ if (locale && locale[1]) {
13
+ messages[locale[1]] = modules[path] as LocaleMessage<unknown>
14
+ }
15
+ }
16
+
17
+ return messages
18
+ }
@@ -1,21 +1,21 @@
1
1
  /**
2
2
  * Available variants for UI libraries.
3
- *
3
+ *
4
4
  * `nuxt-ui` - full https://ui.nuxt.com/ via `@nuxt/ui` connector module **[RECOMMENDED]**
5
- *
5
+ *
6
6
  * `tailwind` - only https://tailwindcss.com/ via `@nuxtjs/tailwindcss` connector module
7
- *
7
+ *
8
8
  * `off` - no UI library **[DEFAULT]**
9
9
  */
10
10
  export type UIOptions = 'nuxt-ui' | 'tailwind' | 'off'
11
11
 
12
12
  /**
13
13
  * Available variants for Database connector.
14
- *
14
+ *
15
15
  * `neon` - https://neon.tech/ via `nuxt-neon` connector module **[RECOMMENDED]**
16
16
  *
17
17
  * `supabase` - https://supabase.com/ via `@nuxtjs/supabase` connector module
18
- *
18
+ *
19
19
  * `off` - no database module **[DEFAULT]**
20
20
  */
21
21
  export type DBOptions = 'neon' | 'supabase' | 'off'