@i18n-micro/types-generator 1.1.9 โ 2.0.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/LICENSE +1 -1
- package/README.md +7 -34
- package/dist/core/generator.d.cts +31 -0
- package/dist/core/generator.d.ts +6 -3
- package/dist/core/generator.d.ts.map +1 -1
- package/dist/generator-DWzG9LPu.js +48 -0
- package/dist/generator-sMSFgdbQ.cjs +14 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +3 -4
- package/dist/index.d.ts +3 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +20 -38
- package/dist/nuxt.cjs +1 -1
- package/dist/nuxt.d.cts +1 -1
- package/dist/nuxt.d.ts +1 -1
- package/dist/nuxt.d.ts.map +1 -1
- package/dist/nuxt.mjs +36 -17
- package/dist/plugin.d.cts +5 -0
- package/dist/plugin.d.ts +5 -0
- package/dist/plugin.d.ts.map +1 -0
- package/package.json +25 -11
- package/dist/core/parser.d.ts +0 -25
- package/dist/core/parser.d.ts.map +0 -1
- package/dist/generator-BonabDld.cjs +0 -14
- package/dist/generator-CWXsEVLn.js +0 -69
- package/dist/unplugin.d.ts +0 -3
- package/dist/unplugin.d.ts.map +0 -1
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,57 +1,30 @@
|
|
|
1
1
|
# @i18n-micro/types-generator
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
## Installation
|
|
3
|
+
Generates a declaration with every translation key from your JSON files, so `t()`, `$t()` and `<I18nT keypath>` autocomplete them. Works as a Nuxt module and as a Vite or Rollup plugin.
|
|
6
4
|
|
|
7
5
|
```bash
|
|
8
|
-
npm install -D @i18n-micro/types-generator
|
|
9
|
-
# or
|
|
10
6
|
pnpm add -D @i18n-micro/types-generator
|
|
11
|
-
# or
|
|
12
|
-
yarn add -D @i18n-micro/types-generator
|
|
13
7
|
```
|
|
14
8
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
### Nuxt
|
|
9
|
+
Nuxt:
|
|
18
10
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
```typescript
|
|
11
|
+
```ts
|
|
22
12
|
export default defineNuxtConfig({
|
|
23
13
|
modules: ['nuxt-i18n-micro', '@i18n-micro/types-generator/nuxt'],
|
|
24
14
|
})
|
|
25
15
|
```
|
|
26
16
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
Add to `vite.config.ts`:
|
|
17
|
+
Vite:
|
|
30
18
|
|
|
31
|
-
```
|
|
19
|
+
```ts
|
|
32
20
|
import { I18nTypesPlugin } from '@i18n-micro/types-generator'
|
|
33
21
|
|
|
34
22
|
export default defineConfig({
|
|
35
|
-
plugins: [
|
|
36
|
-
I18nTypesPlugin({
|
|
37
|
-
srcDir: 'src',
|
|
38
|
-
translationDir: 'locales',
|
|
39
|
-
}),
|
|
40
|
-
],
|
|
23
|
+
plugins: [I18nTypesPlugin({ srcDir: process.cwd(), translationDir: 'src/locales' })],
|
|
41
24
|
})
|
|
42
25
|
```
|
|
43
26
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
- ๐ Automatic type generation from JSON files
|
|
47
|
-
- โ
Full type safety for translation keys
|
|
48
|
-
- ๐ฏ IDE autocomplete support
|
|
49
|
-
- ๐ Hot reload on file changes
|
|
50
|
-
- ๐ Zero runtime overhead
|
|
51
|
-
|
|
52
|
-
## Documentation
|
|
53
|
-
|
|
54
|
-
See [full documentation](../../docs/integrations/types-generator.md) for detailed usage and examples.
|
|
27
|
+
Docs: [https://s00d.github.io/nuxt-i18n-micro/integrations/types-generator](https://s00d.github.io/nuxt-i18n-micro/integrations/types-generator) ยท Repository: [github.com/s00d/nuxt-i18n-micro](https://github.com/s00d/nuxt-i18n-micro)
|
|
55
28
|
|
|
56
29
|
## License
|
|
57
30
|
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export interface GeneratorOptions {
|
|
2
|
+
srcDir: string;
|
|
3
|
+
/** One folder or several (layers, additional dirs); each is resolved against `srcDir`. */
|
|
4
|
+
translationDir: string | string[];
|
|
5
|
+
/** Folders of which only the top-level `{locale}.json` count, as `additionalTranslationDirs` of the module. */
|
|
6
|
+
additionalDirs?: string[];
|
|
7
|
+
outputFile?: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Emit a TS property name from a translation key.
|
|
11
|
+
* JSON.stringify covers quotes/newlines/null bytes; U+2028/U+2029 need an extra escape
|
|
12
|
+
* so the .d.ts stays safe when embedded in older JS tooling.
|
|
13
|
+
*/
|
|
14
|
+
export declare function formatKeyProperty(key: string): string;
|
|
15
|
+
/**
|
|
16
|
+
* Generates a string with TypeScript types for translation keys.
|
|
17
|
+
* Does not write a file, only returns content.
|
|
18
|
+
*
|
|
19
|
+
* @param options - Generator options
|
|
20
|
+
* @returns String with .d.ts file content
|
|
21
|
+
*/
|
|
22
|
+
export declare function getTypesString(options: GeneratorOptions): string;
|
|
23
|
+
/**
|
|
24
|
+
* Generates TypeScript types for translation keys from JSON files.
|
|
25
|
+
* Writes the result to a file.
|
|
26
|
+
*
|
|
27
|
+
* @param options - Generator options
|
|
28
|
+
* @returns Path to the generated file
|
|
29
|
+
*/
|
|
30
|
+
export declare function generateTypes(options: GeneratorOptions): string;
|
|
31
|
+
//# sourceMappingURL=generator.d.ts.map
|
package/dist/core/generator.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
export interface GeneratorOptions {
|
|
2
2
|
srcDir: string;
|
|
3
|
-
|
|
3
|
+
/** One folder or several (layers, additional dirs); each is resolved against `srcDir`. */
|
|
4
|
+
translationDir: string | string[];
|
|
5
|
+
/** Folders of which only the top-level `{locale}.json` count, as `additionalTranslationDirs` of the module. */
|
|
6
|
+
additionalDirs?: string[];
|
|
4
7
|
outputFile?: string;
|
|
5
8
|
}
|
|
6
9
|
/**
|
|
@@ -16,7 +19,7 @@ export declare function formatKeyProperty(key: string): string;
|
|
|
16
19
|
* @param options - Generator options
|
|
17
20
|
* @returns String with .d.ts file content
|
|
18
21
|
*/
|
|
19
|
-
export declare function getTypesString(options: GeneratorOptions):
|
|
22
|
+
export declare function getTypesString(options: GeneratorOptions): string;
|
|
20
23
|
/**
|
|
21
24
|
* Generates TypeScript types for translation keys from JSON files.
|
|
22
25
|
* Writes the result to a file.
|
|
@@ -24,5 +27,5 @@ export declare function getTypesString(options: GeneratorOptions): Promise<strin
|
|
|
24
27
|
* @param options - Generator options
|
|
25
28
|
* @returns Path to the generated file
|
|
26
29
|
*/
|
|
27
|
-
export declare function generateTypes(options: GeneratorOptions):
|
|
30
|
+
export declare function generateTypes(options: GeneratorOptions): string;
|
|
28
31
|
//# sourceMappingURL=generator.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../../src/core/generator.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,MAAM,CAAA;IACd,cAAc,EAAE,MAAM,CAAA;
|
|
1
|
+
{"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../../src/core/generator.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,MAAM,CAAA;IACd,0FAA0F;IAC1F,cAAc,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;IACjC,+GAA+G;IAC/G,cAAc,CAAC,EAAE,MAAM,EAAE,CAAA;IACzB,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAErD;AA6BD;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,gBAAgB,GAAG,MAAM,CA4BhE;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,gBAAgB,GAAG,MAAM,CAK/D"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { mkdirSync as e, writeFileSync as t } from "node:fs";
|
|
2
|
+
import { dirname as n, resolve as r } from "node:path";
|
|
3
|
+
import { collectTranslationPaths as i, getByPath as a } from "@i18n-micro/core";
|
|
4
|
+
import { listTranslationFiles as o, loadTranslationDir as s, loadTranslationFiles as c } from "@i18n-micro/utils/load-dir";
|
|
5
|
+
// src/core/generator.ts
|
|
6
|
+
function l(e) {
|
|
7
|
+
return JSON.stringify(e).split("\u2028").join("\\u2028").split("\u2029").join("\\u2029");
|
|
8
|
+
}
|
|
9
|
+
function u(e) {
|
|
10
|
+
return e === null ? "null" : Array.isArray(e) ? "unknown[]" : typeof e;
|
|
11
|
+
}
|
|
12
|
+
function d(e, t) {
|
|
13
|
+
let n = /* @__PURE__ */ new Set();
|
|
14
|
+
i(t, n);
|
|
15
|
+
for (let r of n) {
|
|
16
|
+
let n = a(t, r);
|
|
17
|
+
n !== void 0 && e.set(r, (e.get(r) ?? /* @__PURE__ */ new Set()).add(u(n)));
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
function f(e) {
|
|
21
|
+
let { root: t, routes: n } = s(e);
|
|
22
|
+
return [t, ...Object.values(n)].flatMap((e) => Object.values(e));
|
|
23
|
+
}
|
|
24
|
+
function p(e) {
|
|
25
|
+
return Object.values(c(o(e).filter((e) => !e.relativePath.includes("/"))).root);
|
|
26
|
+
}
|
|
27
|
+
function m(e) {
|
|
28
|
+
let t = /* @__PURE__ */ new Map(), n = (t) => r(e.srcDir, t), i = [...[e.translationDir].flat().flatMap((e) => f(n(e))), ...(e.additionalDirs ?? []).flatMap((e) => p(n(e)))];
|
|
29
|
+
for (let e of i) d(t, e);
|
|
30
|
+
return `/* prettier-ignore */
|
|
31
|
+
// @ts-nocheck
|
|
32
|
+
// Generated by @i18n-micro/types-generator
|
|
33
|
+
// DO NOT EDIT THIS FILE MANUALLY
|
|
34
|
+
|
|
35
|
+
import '@i18n-micro/types';
|
|
36
|
+
|
|
37
|
+
declare module '@i18n-micro/types' {
|
|
38
|
+
export interface DefineLocaleMessage {
|
|
39
|
+
${[...t].sort(([e], [t]) => e < t ? -1 : 1).map(([e, t]) => ` ${l(e)}: ${[...t].sort().join(" | ")};`).join("\n")}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
`;
|
|
43
|
+
}
|
|
44
|
+
function h(i) {
|
|
45
|
+
let a = r(i.srcDir, i.outputFile || "i18n-micro.d.ts");
|
|
46
|
+
return e(n(a), { recursive: !0 }), t(a, m(i), "utf-8"), a;
|
|
47
|
+
}
|
|
48
|
+
export { h as n, m as r, l as t };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
let e=require("node:fs"),t=require("node:path"),n=require("@i18n-micro/core"),r=require("@i18n-micro/utils/load-dir");function i(e){return JSON.stringify(e).split(`\u2028`).join(`\\u2028`).split(`\u2029`).join(`\\u2029`)}function a(e){return e===null?`null`:Array.isArray(e)?`unknown[]`:typeof e}function o(e,t){let r=new Set;(0,n.collectTranslationPaths)(t,r);for(let i of r){let r=(0,n.getByPath)(t,i);r!==void 0&&e.set(i,(e.get(i)??new Set).add(a(r)))}}function s(e){let{root:t,routes:n}=(0,r.loadTranslationDir)(e);return[t,...Object.values(n)].flatMap(e=>Object.values(e))}function c(e){return Object.values((0,r.loadTranslationFiles)((0,r.listTranslationFiles)(e).filter(e=>!e.relativePath.includes(`/`))).root)}function l(e){let n=new Map,r=n=>(0,t.resolve)(e.srcDir,n),a=[...[e.translationDir].flat().flatMap(e=>s(r(e))),...(e.additionalDirs??[]).flatMap(e=>c(r(e)))];for(let e of a)o(n,e);return`/* prettier-ignore */
|
|
2
|
+
// @ts-nocheck
|
|
3
|
+
// Generated by @i18n-micro/types-generator
|
|
4
|
+
// DO NOT EDIT THIS FILE MANUALLY
|
|
5
|
+
|
|
6
|
+
import '@i18n-micro/types';
|
|
7
|
+
|
|
8
|
+
declare module '@i18n-micro/types' {
|
|
9
|
+
export interface DefineLocaleMessage {
|
|
10
|
+
${[...n].sort(([e],[t])=>e<t?-1:1).map(([e,t])=>` ${i(e)}: ${[...t].sort().join(` | `)};`).join(`
|
|
11
|
+
`)}
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
`}function u(n){let r=(0,t.resolve)(n.srcDir,n.outputFile||`i18n-micro.d.ts`);return(0,e.mkdirSync)((0,t.dirname)(r),{recursive:!0}),(0,e.writeFileSync)(r,l(n),`utf-8`),r}Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return u}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return l}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return i}});
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./generator-
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./generator-sMSFgdbQ.cjs");let t=require("node:path"),n=require("@i18n-micro/utils/load-dir");var r=300;function i(i){let a=()=>{try{e.n(i)}catch(e){console.warn(`[i18n-types] Failed to generate types:`,e)}};return{name:`i18n-micro-types-generator`,buildStart:a,configureServer(e){let o=[...[i.translationDir].flat(),...i.additionalDirs??[]].map(e=>(0,t.resolve)(i.srcDir,e)),s,c=e=>{e.endsWith(`.json`)&&o.some(t=>(0,n.isInsideDir)(e,t))&&(clearTimeout(s),s=setTimeout(a,r))};e.watcher.add(o),e.watcher.on(`add`,c).on(`change`,c).on(`unlink`,c),e.httpServer?.once(`close`,()=>clearTimeout(s))}}}exports.I18nTypesPlugin=i,exports.formatKeyProperty=e.t,exports.generateTypes=e.n,exports.getTypesString=e.r;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
export type { GeneratorOptions } from './core/generator';
|
|
2
|
-
export { formatKeyProperty, generateTypes, getTypesString } from './core/generator';
|
|
3
|
-
export {
|
|
4
|
-
export { I18nTypesPlugin } from './unplugin';
|
|
1
|
+
export type { GeneratorOptions } from './core/generator.cjs';
|
|
2
|
+
export { formatKeyProperty, generateTypes, getTypesString } from './core/generator.cjs';
|
|
3
|
+
export { I18nTypesPlugin } from './plugin.cjs';
|
|
5
4
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
export type { GeneratorOptions } from './core/generator';
|
|
2
|
-
export { formatKeyProperty, generateTypes, getTypesString } from './core/generator';
|
|
3
|
-
export {
|
|
4
|
-
export { I18nTypesPlugin } from './unplugin';
|
|
1
|
+
export type { GeneratorOptions } from './core/generator.js';
|
|
2
|
+
export { formatKeyProperty, generateTypes, getTypesString } from './core/generator.js';
|
|
3
|
+
export { I18nTypesPlugin } from './plugin.js';
|
|
5
4
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AACxD,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AACnF,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AACxD,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AACnF,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,43 +1,25 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { resolve as
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
return function(...n) {
|
|
9
|
-
l && clearTimeout(l), l = setTimeout(() => {
|
|
10
|
-
l && clearTimeout(l), l = null, e(...n);
|
|
11
|
-
}, t);
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
var d = s((e) => ({
|
|
15
|
-
name: "i18n-micro-types-generator",
|
|
16
|
-
async buildStart() {
|
|
1
|
+
import { n as e, r as t, t as n } from "./generator-DWzG9LPu.js";
|
|
2
|
+
import { resolve as r } from "node:path";
|
|
3
|
+
import { isInsideDir as i } from "@i18n-micro/utils/load-dir";
|
|
4
|
+
// src/plugin.ts
|
|
5
|
+
var a = 300;
|
|
6
|
+
function o(t) {
|
|
7
|
+
let n = () => {
|
|
17
8
|
try {
|
|
18
|
-
|
|
9
|
+
e(t);
|
|
19
10
|
} catch (e) {
|
|
20
11
|
console.warn("[i18n-types] Failed to generate types:", e);
|
|
21
12
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
c
|
|
31
|
-
ignoreInitial: !0,
|
|
32
|
-
ignored: (e) => /(?:^|[/\\])(?:node_modules|dist|\.nuxt)(?:[/\\]|$)/.test(e)
|
|
33
|
-
}), c.on("all", async (e, t) => {
|
|
34
|
-
t.endsWith(".json") && r();
|
|
35
|
-
});
|
|
13
|
+
};
|
|
14
|
+
return {
|
|
15
|
+
name: "i18n-micro-types-generator",
|
|
16
|
+
buildStart: n,
|
|
17
|
+
configureServer(e) {
|
|
18
|
+
let o = [...[t.translationDir].flat(), ...t.additionalDirs ?? []].map((e) => r(t.srcDir, e)), s, c = (e) => {
|
|
19
|
+
e.endsWith(".json") && o.some((t) => i(e, t)) && (clearTimeout(s), s = setTimeout(n, a));
|
|
20
|
+
};
|
|
21
|
+
e.watcher.add(o), e.watcher.on("add", c).on("change", c).on("unlink", c), e.httpServer?.once("close", () => clearTimeout(s));
|
|
36
22
|
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
}));
|
|
42
|
-
//#endregion
|
|
43
|
-
export { d as I18nTypesPlugin, t as flattenKeys, i as formatKeyProperty, n as generateTypes, r as getTypesString, e as isPlainTranslationObject };
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
export { o as I18nTypesPlugin, n as formatKeyProperty, e as generateTypes, t as getTypesString };
|
package/dist/nuxt.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require("./generator-
|
|
1
|
+
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require("./generator-sMSFgdbQ.cjs");let t=require("node:fs"),n=require("node:path"),r=require("@i18n-micro/utils/load-dir"),i=require("@nuxt/kit");function a(e){return{...e.options.modules.find(e=>Array.isArray(e)&&String(e[0]).includes(`nuxt-i18n-micro`))?.[1],...e.options.i18n}}function o(e,r){if(r)return{dirs:[(0,n.resolve)(e.options.rootDir,r)],additionalDirs:[]};let{translationDir:i=`locales`,additionalTranslationDirs:o=[]}=a(e),s=e.options._layers.map(e=>e.config.rootDir);return{dirs:s.map(e=>(0,n.join)(e,i)),additionalDirs:o.flatMap(e=>s.map(t=>(0,n.resolve)(t,e))).filter(e=>(0,t.existsSync)(e))}}var s=(0,i.defineNuxtModule)({meta:{name:`@i18n-micro/types-generator`,configKey:`i18nTypes`},setup(t,a){let{dirs:s,additionalDirs:c}=o(a,t.translationDir),l=t.outputFile;typeof l==`string`&&l.length>0&&console.warn("[i18n-types] `i18nTypes.outputFile` is ignored in Nuxt; generated types are written to `.nuxt/types/i18n-micro.d.ts`."),a.options.typescript.hoist||=[],a.options.typescript.hoist.includes(`@i18n-micro/types`)||a.options.typescript.hoist.push(`@i18n-micro/types`),(0,i.addTypeTemplate)({filename:`types/i18n-micro.d.ts`,getContents:()=>{try{return e.r({srcDir:a.options.rootDir,translationDir:s,additionalDirs:c})}catch(e){return console.warn(`[i18n-types] Failed to generate types:`,e),`// Failed to generate types: ${e instanceof Error?e.message:String(e)}`}}}),a.hook(`builder:watch`,async(e,t)=>{let i=(0,n.isAbsolute)(t)?t:(0,n.join)(a.options.srcDir,t);i.endsWith(`.json`)&&[...s,...c].some(e=>(0,r.isInsideDir)(i,e))&&await a.callHook(`builder:generateApp`)})}});exports.default=s;
|
package/dist/nuxt.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export interface I18nTypesGeneratorOptions {
|
|
2
|
-
/** Translation directory relative to the project root. Defaults to `i18n
|
|
2
|
+
/** Translation directory relative to the project root. Defaults to where `nuxt-i18n-micro` reads translations. */
|
|
3
3
|
translationDir?: string;
|
|
4
4
|
}
|
|
5
5
|
declare const _default: import('@nuxt/schema').NuxtModule<I18nTypesGeneratorOptions, I18nTypesGeneratorOptions, false>;
|
package/dist/nuxt.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export interface I18nTypesGeneratorOptions {
|
|
2
|
-
/** Translation directory relative to the project root. Defaults to `i18n
|
|
2
|
+
/** Translation directory relative to the project root. Defaults to where `nuxt-i18n-micro` reads translations. */
|
|
3
3
|
translationDir?: string;
|
|
4
4
|
}
|
|
5
5
|
declare const _default: import('@nuxt/schema').NuxtModule<I18nTypesGeneratorOptions, I18nTypesGeneratorOptions, false>;
|
package/dist/nuxt.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nuxt.d.ts","sourceRoot":"","sources":["../src/nuxt.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"nuxt.d.ts","sourceRoot":"","sources":["../src/nuxt.ts"],"names":[],"mappings":"AAOA,MAAM,WAAW,yBAAyB;IACxC,kHAAkH;IAClH,cAAc,CAAC,EAAE,MAAM,CAAA;CACxB;;AAyBD,wBAsCE"}
|
package/dist/nuxt.mjs
CHANGED
|
@@ -1,31 +1,50 @@
|
|
|
1
|
-
import { r as e } from "./generator-
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { r as e } from "./generator-DWzG9LPu.js";
|
|
2
|
+
import { existsSync as t } from "node:fs";
|
|
3
|
+
import { isAbsolute as n, join as r, resolve as i } from "node:path";
|
|
4
|
+
import { isInsideDir as a } from "@i18n-micro/utils/load-dir";
|
|
5
|
+
import { addTypeTemplate as o, defineNuxtModule as s } from "@nuxt/kit";
|
|
6
|
+
// src/nuxt.ts
|
|
7
|
+
function c(e) {
|
|
8
|
+
return {
|
|
9
|
+
...e.options.modules.find((e) => Array.isArray(e) && String(e[0]).includes("nuxt-i18n-micro"))?.[1],
|
|
10
|
+
...e.options.i18n
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
function l(e, n) {
|
|
14
|
+
if (n) return {
|
|
15
|
+
dirs: [i(e.options.rootDir, n)],
|
|
16
|
+
additionalDirs: []
|
|
17
|
+
};
|
|
18
|
+
let { translationDir: a = "locales", additionalTranslationDirs: o = [] } = c(e), s = e.options._layers.map((e) => e.config.rootDir);
|
|
19
|
+
return {
|
|
20
|
+
dirs: s.map((e) => r(e, a)),
|
|
21
|
+
additionalDirs: o.flatMap((e) => s.map((t) => i(t, e))).filter((e) => t(e))
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
var u = s({
|
|
5
25
|
meta: {
|
|
6
26
|
name: "@i18n-micro/types-generator",
|
|
7
27
|
configKey: "i18nTypes"
|
|
8
28
|
},
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
typeof o == "string" && o.length > 0 && console.warn("[i18n-types] `i18nTypes.outputFile` is ignored in Nuxt; generated types are written to `.nuxt/types/i18n-micro.d.ts`."), r.options.typescript.hoist ||= [], r.options.typescript.hoist.includes("@i18n-micro/types") || r.options.typescript.hoist.push("@i18n-micro/types"), t({
|
|
29
|
+
setup(t, i) {
|
|
30
|
+
let { dirs: s, additionalDirs: c } = l(i, t.translationDir), u = t.outputFile;
|
|
31
|
+
typeof u == "string" && u.length > 0 && console.warn("[i18n-types] `i18nTypes.outputFile` is ignored in Nuxt; generated types are written to `.nuxt/types/i18n-micro.d.ts`."), i.options.typescript.hoist ||= [], i.options.typescript.hoist.includes("@i18n-micro/types") || i.options.typescript.hoist.push("@i18n-micro/types"), o({
|
|
13
32
|
filename: "types/i18n-micro.d.ts",
|
|
14
|
-
getContents:
|
|
33
|
+
getContents: () => {
|
|
15
34
|
try {
|
|
16
|
-
return
|
|
17
|
-
srcDir:
|
|
18
|
-
translationDir:
|
|
35
|
+
return e({
|
|
36
|
+
srcDir: i.options.rootDir,
|
|
37
|
+
translationDir: s,
|
|
38
|
+
additionalDirs: c
|
|
19
39
|
});
|
|
20
40
|
} catch (e) {
|
|
21
41
|
return console.warn("[i18n-types] Failed to generate types:", e), `// Failed to generate types: ${e instanceof Error ? e.message : String(e)}`;
|
|
22
42
|
}
|
|
23
43
|
}
|
|
24
|
-
}),
|
|
25
|
-
let
|
|
26
|
-
|
|
44
|
+
}), i.hook("builder:watch", async (e, t) => {
|
|
45
|
+
let o = n(t) ? t : r(i.options.srcDir, t);
|
|
46
|
+
o.endsWith(".json") && [...s, ...c].some((e) => a(o, e)) && await i.callHook("builder:generateApp");
|
|
27
47
|
});
|
|
28
48
|
}
|
|
29
49
|
});
|
|
30
|
-
|
|
31
|
-
export { r as default };
|
|
50
|
+
export { u as default };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Plugin } from 'vite';
|
|
2
|
+
import { GeneratorOptions } from './core/generator.cjs';
|
|
3
|
+
/** A Vite (and Rollup) plugin: generates at build start, and again in dev after a locale file changes. */
|
|
4
|
+
export declare function I18nTypesPlugin(options: GeneratorOptions): Plugin;
|
|
5
|
+
//# sourceMappingURL=plugin.d.ts.map
|
package/dist/plugin.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Plugin } from 'vite';
|
|
2
|
+
import { GeneratorOptions } from './core/generator.js';
|
|
3
|
+
/** A Vite (and Rollup) plugin: generates at build start, and again in dev after a locale file changes. */
|
|
4
|
+
export declare function I18nTypesPlugin(options: GeneratorOptions): Plugin;
|
|
5
|
+
//# sourceMappingURL=plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAClC,OAAO,EAAE,KAAK,gBAAgB,EAAiB,MAAM,kBAAkB,CAAA;AAIvE,0GAA0G;AAC1G,wBAAgB,eAAe,CAAC,OAAO,EAAE,gBAAgB,GAAG,MAAM,CAyBjE"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@i18n-micro/types-generator",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Type generator for i18n-micro translation keys",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"i18n",
|
|
@@ -62,23 +62,37 @@
|
|
|
62
62
|
"access": "public"
|
|
63
63
|
},
|
|
64
64
|
"dependencies": {
|
|
65
|
-
"
|
|
66
|
-
"
|
|
67
|
-
"unplugin": "^1.16.1 || ^2.0.0 || ^3.3.0"
|
|
65
|
+
"@i18n-micro/core": "^2.0.0",
|
|
66
|
+
"@i18n-micro/utils": "^2.0.0"
|
|
68
67
|
},
|
|
69
68
|
"devDependencies": {
|
|
70
|
-
"@
|
|
71
|
-
"
|
|
69
|
+
"@nuxt/kit": "^3.18.0 || ^4.0.0",
|
|
70
|
+
"@nuxt/schema": "^3.18.0 || ^4.0.0",
|
|
71
|
+
"@types/node": "^22.19.0",
|
|
72
|
+
"publint": "^0.3.25",
|
|
72
73
|
"typescript": "6.0.3",
|
|
73
|
-
"vite": "^8.
|
|
74
|
-
"vite-plugin-dts": "^5.1.
|
|
75
|
-
"vitest": "^
|
|
74
|
+
"vite": "^8.3.5",
|
|
75
|
+
"vite-plugin-dts": "^5.1.2",
|
|
76
|
+
"vitest": "^5.1.0"
|
|
76
77
|
},
|
|
77
78
|
"peerDependencies": {
|
|
78
|
-
"@nuxt/kit": "^3.18.
|
|
79
|
+
"@nuxt/kit": "^3.18.0 || ^4.0.0",
|
|
80
|
+
"@nuxt/schema": "^3.18.0 || ^4.0.0",
|
|
81
|
+
"vite": ">=5.4.0"
|
|
82
|
+
},
|
|
83
|
+
"peerDependenciesMeta": {
|
|
84
|
+
"@nuxt/schema": {
|
|
85
|
+
"optional": true
|
|
86
|
+
},
|
|
87
|
+
"vite": {
|
|
88
|
+
"optional": true
|
|
89
|
+
},
|
|
90
|
+
"@nuxt/kit": {
|
|
91
|
+
"optional": true
|
|
92
|
+
}
|
|
79
93
|
},
|
|
80
94
|
"engines": {
|
|
81
|
-
"node": ">=
|
|
95
|
+
"node": ">=20"
|
|
82
96
|
},
|
|
83
97
|
"scripts": {
|
|
84
98
|
"build": "vite build",
|
package/dist/core/parser.d.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* True for plain objects suitable as translation maps (not arrays, Date, null, etc.).
|
|
3
|
-
*/
|
|
4
|
-
export declare function isPlainTranslationObject(value: unknown): value is Record<string, unknown>;
|
|
5
|
-
/**
|
|
6
|
-
* Recursively traverses a JSON object and creates a flat list of dot-separated keys.
|
|
7
|
-
*
|
|
8
|
-
* @param obj - JSON object with translations
|
|
9
|
-
* @param prefix - Prefix for nested keys (used recursively)
|
|
10
|
-
* @returns Array of strings with flat keys (e.g. ['greeting', 'header.title', 'errors.404'])
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* ```typescript
|
|
14
|
-
* const obj = {
|
|
15
|
-
* greeting: 'Hello',
|
|
16
|
-
* header: {
|
|
17
|
-
* title: 'Welcome',
|
|
18
|
-
* subtitle: 'Subtitle'
|
|
19
|
-
* }
|
|
20
|
-
* }
|
|
21
|
-
* flattenKeys(obj) // ['greeting', 'header.title', 'header.subtitle']
|
|
22
|
-
* ```
|
|
23
|
-
*/
|
|
24
|
-
export declare function flattenKeys(obj: Record<string, unknown>, prefix?: string): string[];
|
|
25
|
-
//# sourceMappingURL=parser.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../../src/core/parser.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAEzF;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,SAAK,GAAG,MAAM,EAAE,CAwB/E"}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
let e=require("node:fs"),t=require("node:path"),n=require("globby");function r(e){return typeof e==`object`&&!!e&&!Array.isArray(e)&&Object.getPrototypeOf(e)===Object.prototype}function i(e,t=``){if(!r(e))return[];let n=[];for(let a in e){if(!Object.hasOwn(e,a))continue;let o=e[a],s=t?`${t}.${a}`:a;r(o)?n.push(...i(o,s)):n.push(s)}return n}function a(e){return e.charCodeAt(0)===65279?e.slice(1):e}function o(e){return JSON.stringify(e).replace(/\u2028/g,`\\u2028`).replace(/\u2029/g,`\\u2029`)}async function s(s){let c=(0,t.resolve)(s.srcDir,s.translationDir),l=await(0,n.globby)(`**/*.json`,{cwd:c,absolute:!0,ignore:[`node_modules/**`,`dist/**`,`.nuxt/**`]}),u=new Set;for(let t of l)try{let n=JSON.parse(a((0,e.readFileSync)(t,`utf-8`)));if(!r(n)){console.warn(`[i18n-types] Skipping ${t}: root value must be a plain JSON object`);continue}let o=i(n);for(let e of o)u.add(e)}catch(e){console.warn(`[i18n-types] Failed to parse ${t}:`,e)}return`/* prettier-ignore */
|
|
2
|
-
// @ts-nocheck
|
|
3
|
-
// Generated by @i18n-micro/types-generator
|
|
4
|
-
// DO NOT EDIT THIS FILE MANUALLY
|
|
5
|
-
|
|
6
|
-
import '@i18n-micro/types';
|
|
7
|
-
|
|
8
|
-
declare module '@i18n-micro/types' {
|
|
9
|
-
export interface DefineLocaleMessage {
|
|
10
|
-
${Array.from(u).sort().map(e=>` ${o(e)}: string;`).join(`
|
|
11
|
-
`)}
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
`}async function c(n){let r=await s(n),i=n.outputFile||(0,t.resolve)(n.srcDir,`i18n-micro.d.ts`),a=(0,t.dirname)(i);try{(0,e.mkdirSync)(a,{recursive:!0})}catch{}return(0,e.writeFileSync)(i,r,`utf-8`),i}Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return r}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return i}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return c}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return s}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return o}});
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { mkdirSync as e, readFileSync as t, writeFileSync as n } from "node:fs";
|
|
2
|
-
import { dirname as r, resolve as i } from "node:path";
|
|
3
|
-
import { globby as a } from "globby";
|
|
4
|
-
//#region src/core/parser.ts
|
|
5
|
-
function o(e) {
|
|
6
|
-
return typeof e == "object" && !!e && !Array.isArray(e) && Object.getPrototypeOf(e) === Object.prototype;
|
|
7
|
-
}
|
|
8
|
-
function s(e, t = "") {
|
|
9
|
-
if (!o(e)) return [];
|
|
10
|
-
let n = [];
|
|
11
|
-
for (let r in e) {
|
|
12
|
-
if (!Object.hasOwn(e, r)) continue;
|
|
13
|
-
let i = e[r], a = t ? `${t}.${r}` : r;
|
|
14
|
-
o(i) ? n.push(...s(i, a)) : n.push(a);
|
|
15
|
-
}
|
|
16
|
-
return n;
|
|
17
|
-
}
|
|
18
|
-
//#endregion
|
|
19
|
-
//#region src/core/generator.ts
|
|
20
|
-
function c(e) {
|
|
21
|
-
return e.charCodeAt(0) === 65279 ? e.slice(1) : e;
|
|
22
|
-
}
|
|
23
|
-
function l(e) {
|
|
24
|
-
return JSON.stringify(e).replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029");
|
|
25
|
-
}
|
|
26
|
-
async function u(e) {
|
|
27
|
-
let n = i(e.srcDir, e.translationDir), r = await a("**/*.json", {
|
|
28
|
-
cwd: n,
|
|
29
|
-
absolute: !0,
|
|
30
|
-
ignore: [
|
|
31
|
-
"node_modules/**",
|
|
32
|
-
"dist/**",
|
|
33
|
-
".nuxt/**"
|
|
34
|
-
]
|
|
35
|
-
}), u = /* @__PURE__ */ new Set();
|
|
36
|
-
for (let e of r) try {
|
|
37
|
-
let n = JSON.parse(c(t(e, "utf-8")));
|
|
38
|
-
if (!o(n)) {
|
|
39
|
-
console.warn(`[i18n-types] Skipping ${e}: root value must be a plain JSON object`);
|
|
40
|
-
continue;
|
|
41
|
-
}
|
|
42
|
-
let r = s(n);
|
|
43
|
-
for (let e of r) u.add(e);
|
|
44
|
-
} catch (t) {
|
|
45
|
-
console.warn(`[i18n-types] Failed to parse ${e}:`, t);
|
|
46
|
-
}
|
|
47
|
-
return `/* prettier-ignore */
|
|
48
|
-
// @ts-nocheck
|
|
49
|
-
// Generated by @i18n-micro/types-generator
|
|
50
|
-
// DO NOT EDIT THIS FILE MANUALLY
|
|
51
|
-
|
|
52
|
-
import '@i18n-micro/types';
|
|
53
|
-
|
|
54
|
-
declare module '@i18n-micro/types' {
|
|
55
|
-
export interface DefineLocaleMessage {
|
|
56
|
-
${Array.from(u).sort().map((e) => ` ${l(e)}: string;`).join("\n")}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
`;
|
|
60
|
-
}
|
|
61
|
-
async function d(t) {
|
|
62
|
-
let a = await u(t), o = t.outputFile || i(t.srcDir, "i18n-micro.d.ts"), s = r(o);
|
|
63
|
-
try {
|
|
64
|
-
e(s, { recursive: !0 });
|
|
65
|
-
} catch {}
|
|
66
|
-
return n(o, a, "utf-8"), o;
|
|
67
|
-
}
|
|
68
|
-
//#endregion
|
|
69
|
-
export { o as a, s as i, d as n, u as r, l as t };
|
package/dist/unplugin.d.ts
DELETED
package/dist/unplugin.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"unplugin.d.ts","sourceRoot":"","sources":["../src/unplugin.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,gBAAgB,EAAiB,MAAM,kBAAkB,CAAA;AAkBvE,eAAO,MAAM,eAAe,gEAiD1B,CAAA"}
|