@i18n-micro/types-generator 1.1.0 → 1.1.2
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/dist/core/generator.d.ts +8 -8
- package/dist/core/generator.d.ts.map +1 -1
- package/dist/core/parser.d.ts +4 -4
- package/dist/core/parser.d.ts.map +1 -1
- package/dist/{generator-D2pTueXl.cjs → generator-CAQjf5De.cjs} +2 -3
- package/dist/{generator-D56a37C-.js → generator-CSjBe25p.js} +11 -12
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +5 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +6 -6
- package/dist/nuxt.cjs +1 -1
- package/dist/nuxt.d.cts +7 -0
- package/dist/nuxt.d.ts.map +1 -1
- package/dist/nuxt.mjs +1 -1
- package/dist/unplugin.d.ts.map +1 -1
- package/package.json +47 -24
package/dist/core/generator.d.ts
CHANGED
|
@@ -4,19 +4,19 @@ export interface GeneratorOptions {
|
|
|
4
4
|
outputFile?: string;
|
|
5
5
|
}
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
8
|
-
*
|
|
7
|
+
* Generates a string with TypeScript types for translation keys.
|
|
8
|
+
* Does not write a file, only returns content.
|
|
9
9
|
*
|
|
10
|
-
* @param options -
|
|
11
|
-
* @returns
|
|
10
|
+
* @param options - Generator options
|
|
11
|
+
* @returns String with .d.ts file content
|
|
12
12
|
*/
|
|
13
13
|
export declare function getTypesString(options: GeneratorOptions): Promise<string>;
|
|
14
14
|
/**
|
|
15
|
-
*
|
|
16
|
-
*
|
|
15
|
+
* Generates TypeScript types for translation keys from JSON files.
|
|
16
|
+
* Writes the result to a file.
|
|
17
17
|
*
|
|
18
|
-
* @param options -
|
|
19
|
-
* @returns
|
|
18
|
+
* @param options - Generator options
|
|
19
|
+
* @returns Path to the generated file
|
|
20
20
|
*/
|
|
21
21
|
export declare function generateTypes(options: GeneratorOptions): Promise<string>;
|
|
22
22
|
//# 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;IACtB,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB;AAED;;;;;;GAMG;AACH,wBAAsB,cAAc,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,MAAM,CAAC,
|
|
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;IACtB,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB;AAED;;;;;;GAMG;AACH,wBAAsB,cAAc,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,MAAM,CAAC,CA4C/E;AAED;;;;;;GAMG;AACH,wBAAsB,aAAa,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,MAAM,CAAC,CAiB9E"}
|
package/dist/core/parser.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Recursively traverses a JSON object and creates a flat list of dot-separated keys.
|
|
3
3
|
*
|
|
4
|
-
* @param obj - JSON
|
|
5
|
-
* @param prefix -
|
|
6
|
-
* @returns
|
|
4
|
+
* @param obj - JSON object with translations
|
|
5
|
+
* @param prefix - Prefix for nested keys (used recursively)
|
|
6
|
+
* @returns Array of strings with flat keys (e.g. ['greeting', 'header.title', 'errors.404'])
|
|
7
7
|
*
|
|
8
8
|
* @example
|
|
9
9
|
* ```typescript
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../../src/core/parser.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,WAAW,
|
|
1
|
+
{"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../../src/core/parser.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,SAAK,GAAG,MAAM,EAAE,CAqB/E"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
"use strict";const
|
|
2
|
-
/* prettier-ignore */
|
|
1
|
+
"use strict";const i=require("node:fs"),a=require("node:path"),p=require("globby");function y(e,s=""){const t=[];for(const n in e){if(!Object.hasOwn(e,n))continue;const o=e[n],r=s?`${s}.${n}`:n;typeof o=="object"&&o!==null&&!Array.isArray(o)?t.push(...y(o,r)):t.push(r)}return t}async function u(e){const s=a.resolve(e.srcDir,e.translationDir),t=await p.globby("**/*.json",{cwd:s,absolute:!0,ignore:["node_modules/**","dist/**",".nuxt/**"]}),n=new Set;for(const r of t)try{const c=JSON.parse(i.readFileSync(r,"utf-8")),l=y(c);for(const f of l)n.add(f)}catch(c){console.warn(`[i18n-types] Failed to parse ${r}:`,c)}return`/* prettier-ignore */
|
|
3
2
|
// @ts-nocheck
|
|
4
3
|
// Generated by @i18n-micro/types-generator
|
|
5
4
|
// DO NOT EDIT THIS FILE MANUALLY
|
|
@@ -12,4 +11,4 @@ ${Array.from(n).sort().map(r=>` '${r}': string;`).join(`
|
|
|
12
11
|
`)}
|
|
13
12
|
}
|
|
14
13
|
}
|
|
15
|
-
`}async function
|
|
14
|
+
`}async function d(e){const s=await u(e),t=e.outputFile||a.resolve(e.srcDir,"i18n-micro.d.ts"),n=a.dirname(t);try{i.mkdirSync(n,{recursive:!0})}catch{}return i.writeFileSync(t,s,"utf-8"),t}exports.flattenKeys=y;exports.generateTypes=d;exports.getTypesString=u;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { readFileSync as l, mkdirSync as f, writeFileSync as p } from "node:fs";
|
|
2
|
+
import { resolve as i, dirname as m } from "node:path";
|
|
3
|
+
import { globby as d } from "globby";
|
|
4
4
|
function a(e, o = "") {
|
|
5
5
|
const t = [];
|
|
6
6
|
for (const n in e) {
|
|
@@ -11,21 +11,20 @@ function a(e, o = "") {
|
|
|
11
11
|
return t;
|
|
12
12
|
}
|
|
13
13
|
async function g(e) {
|
|
14
|
-
const o =
|
|
14
|
+
const o = i(e.srcDir, e.translationDir), t = await d("**/*.json", {
|
|
15
15
|
cwd: o,
|
|
16
16
|
absolute: !0,
|
|
17
17
|
ignore: ["node_modules/**", "dist/**", ".nuxt/**"]
|
|
18
18
|
}), n = /* @__PURE__ */ new Set();
|
|
19
19
|
for (const r of t)
|
|
20
20
|
try {
|
|
21
|
-
const
|
|
22
|
-
for (const
|
|
23
|
-
n.add(
|
|
24
|
-
} catch (
|
|
25
|
-
console.warn(`[i18n-types] Failed to parse ${r}:`,
|
|
21
|
+
const c = JSON.parse(l(r, "utf-8")), y = a(c);
|
|
22
|
+
for (const u of y)
|
|
23
|
+
n.add(u);
|
|
24
|
+
} catch (c) {
|
|
25
|
+
console.warn(`[i18n-types] Failed to parse ${r}:`, c);
|
|
26
26
|
}
|
|
27
|
-
return `/*
|
|
28
|
-
/* prettier-ignore */
|
|
27
|
+
return `/* prettier-ignore */
|
|
29
28
|
// @ts-nocheck
|
|
30
29
|
// Generated by @i18n-micro/types-generator
|
|
31
30
|
// DO NOT EDIT THIS FILE MANUALLY
|
|
@@ -41,7 +40,7 @@ ${Array.from(n).sort().map((r) => ` '${r}': string;`).join(`
|
|
|
41
40
|
`;
|
|
42
41
|
}
|
|
43
42
|
async function h(e) {
|
|
44
|
-
const o = await g(e), t = e.outputFile ||
|
|
43
|
+
const o = await g(e), t = e.outputFile || i(e.srcDir, "i18n-micro.d.ts"), n = m(t);
|
|
45
44
|
try {
|
|
46
45
|
f(n, { recursive: !0 });
|
|
47
46
|
} catch {
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("./generator-CAQjf5De.cjs"),s=require("node:path"),c=require("chokidar"),u=require("unplugin");let r=null,e=null;function y(t,n){return function(...o){const a=()=>{e&&clearTimeout(e),e=null,t(...o)};e&&clearTimeout(e),e=setTimeout(a,n)}}const g=u.createUnplugin(t=>({name:"i18n-micro-types-generator",async buildStart(){try{await i.generateTypes(t)}catch(n){console.warn("[i18n-types] Failed to generate types:",n)}if(process.env.NODE_ENV==="development"||process.env.NODE_ENV!=="production"){const n=s.resolve(t.srcDir,t.translationDir),l=y(async()=>{try{await i.generateTypes(t)}catch(o){console.warn("[i18n-types] Failed to regenerate types:",o)}},300);r=c.watch(n,{ignoreInitial:!0,ignored:["node_modules/**","dist/**",".nuxt/**"]}),r.on("all",async(o,a)=>{a.endsWith(".json")&&l()})}},buildEnd(){r&&(r.close(),r=null),e&&(clearTimeout(e),e=null)}}));exports.flattenKeys=i.flattenKeys;exports.generateTypes=i.generateTypes;exports.getTypesString=i.getTypesString;exports.I18nTypesPlugin=g;
|
package/dist/index.d.cts
ADDED
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { I18nTypesPlugin } from './unplugin';
|
|
2
|
-
export { generateTypes, getTypesString } from './core/generator';
|
|
3
1
|
export type { GeneratorOptions } from './core/generator';
|
|
2
|
+
export { generateTypes, getTypesString } from './core/generator';
|
|
4
3
|
export { flattenKeys } from './core/parser';
|
|
4
|
+
export { I18nTypesPlugin } from './unplugin';
|
|
5
5
|
//# 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,
|
|
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,aAAa,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAChE,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAC3C,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { g as l } from "./generator-CSjBe25p.js";
|
|
2
|
+
import { f as w, a as v } from "./generator-CSjBe25p.js";
|
|
3
|
+
import { resolve as c } from "node:path";
|
|
4
4
|
import s from "chokidar";
|
|
5
|
-
import {
|
|
5
|
+
import { createUnplugin as u } from "unplugin";
|
|
6
6
|
let r = null, e = null;
|
|
7
7
|
function m(t, n) {
|
|
8
8
|
return function(...o) {
|
|
@@ -12,7 +12,7 @@ function m(t, n) {
|
|
|
12
12
|
e && clearTimeout(e), e = setTimeout(i, n);
|
|
13
13
|
};
|
|
14
14
|
}
|
|
15
|
-
const g =
|
|
15
|
+
const g = u((t) => ({
|
|
16
16
|
name: "i18n-micro-types-generator",
|
|
17
17
|
async buildStart() {
|
|
18
18
|
try {
|
|
@@ -21,7 +21,7 @@ const g = c((t) => ({
|
|
|
21
21
|
console.warn("[i18n-types] Failed to generate types:", n);
|
|
22
22
|
}
|
|
23
23
|
if (process.env.NODE_ENV === "development" || process.env.NODE_ENV !== "production") {
|
|
24
|
-
const n =
|
|
24
|
+
const n = c(t.srcDir, t.translationDir), a = m(async () => {
|
|
25
25
|
try {
|
|
26
26
|
await l(t);
|
|
27
27
|
} catch (o) {
|
package/dist/nuxt.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const a=require("@nuxt/kit"),c=require("./generator-
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const a=require("@nuxt/kit"),c=require("./generator-CAQjf5De.cjs"),d=a.defineNuxtModule({meta:{name:"@i18n-micro/types-generator",configKey:"i18nTypes"},defaults:{translationDir:"locales"},async setup(o,t){const i=t.options.i18n,n=o.translationDir||i?.translationDir||"locales";a.addTypeTemplate({filename:"types/i18n-micro.d.ts",getContents:async()=>{try{return await c.getTypesString({srcDir:t.options.rootDir,translationDir:n})}catch(e){return console.warn("[i18n-types] Failed to generate types:",e),`// Failed to generate types: ${e instanceof Error?e.message:String(e)}`}}}),t.hook("builder:watch",async(e,s)=>{const r=s.replace(/\\/g,"/"),l=n.replace(/\\/g,"/");r.includes(l)&&r.endsWith(".json")&&await t.callHook("builder:generateApp")})}});exports.default=d;
|
package/dist/nuxt.d.cts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export interface I18nTypesGeneratorOptions {
|
|
2
|
+
translationDir?: string;
|
|
3
|
+
outputFile?: string;
|
|
4
|
+
}
|
|
5
|
+
declare const _default: import('@nuxt/schema').NuxtModule<I18nTypesGeneratorOptions, I18nTypesGeneratorOptions, false>;
|
|
6
|
+
export default _default;
|
|
7
|
+
//# sourceMappingURL=nuxt.d.ts.map
|
package/dist/nuxt.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nuxt.d.ts","sourceRoot":"","sources":["../src/nuxt.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,yBAAyB;IACxC,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB;;AAED,
|
|
1
|
+
{"version":3,"file":"nuxt.d.ts","sourceRoot":"","sources":["../src/nuxt.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,yBAAyB;IACxC,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB;;AAED,wBA+CE"}
|
package/dist/nuxt.mjs
CHANGED
package/dist/unplugin.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unplugin.d.ts","sourceRoot":"","sources":["../src/unplugin.ts"],"names":[],"mappings":"
|
|
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,gEAgD1B,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,25 +1,53 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@i18n-micro/types-generator",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"description": "Type generator for i18n-micro translation keys",
|
|
5
5
|
"type": "module",
|
|
6
|
+
"sideEffects": false,
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/s00d/nuxt-i18n-micro.git",
|
|
11
|
+
"directory": "packages/types-generator"
|
|
12
|
+
},
|
|
13
|
+
"homepage": "https://github.com/s00d/nuxt-i18n-micro/tree/main/packages/types-generator#readme",
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/s00d/nuxt-i18n-micro/issues"
|
|
16
|
+
},
|
|
17
|
+
"engines": {
|
|
18
|
+
"node": ">=18.17.0"
|
|
19
|
+
},
|
|
6
20
|
"main": "./dist/index.cjs",
|
|
7
|
-
"module": "./dist/index.mjs",
|
|
8
21
|
"types": "./dist/index.d.ts",
|
|
9
22
|
"exports": {
|
|
10
23
|
".": {
|
|
11
|
-
"
|
|
12
|
-
|
|
13
|
-
|
|
24
|
+
"import": {
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"default": "./dist/index.mjs"
|
|
27
|
+
},
|
|
28
|
+
"require": {
|
|
29
|
+
"types": "./dist/index.d.cts",
|
|
30
|
+
"default": "./dist/index.cjs"
|
|
31
|
+
},
|
|
32
|
+
"default": "./dist/index.mjs"
|
|
14
33
|
},
|
|
15
34
|
"./nuxt": {
|
|
16
|
-
"
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
35
|
+
"import": {
|
|
36
|
+
"types": "./dist/nuxt.d.ts",
|
|
37
|
+
"default": "./dist/nuxt.mjs"
|
|
38
|
+
},
|
|
39
|
+
"require": {
|
|
40
|
+
"types": "./dist/nuxt.d.cts",
|
|
41
|
+
"default": "./dist/nuxt.cjs"
|
|
42
|
+
},
|
|
43
|
+
"default": "./dist/nuxt.mjs"
|
|
44
|
+
},
|
|
45
|
+
"./package.json": "./package.json"
|
|
20
46
|
},
|
|
21
47
|
"files": [
|
|
22
|
-
"dist"
|
|
48
|
+
"dist",
|
|
49
|
+
"README.md",
|
|
50
|
+
"LICENSE"
|
|
23
51
|
],
|
|
24
52
|
"publishConfig": {
|
|
25
53
|
"access": "public"
|
|
@@ -28,40 +56,35 @@
|
|
|
28
56
|
"i18n",
|
|
29
57
|
"typescript",
|
|
30
58
|
"type-generator",
|
|
31
|
-
"translation"
|
|
59
|
+
"translation",
|
|
60
|
+
"nuxt"
|
|
32
61
|
],
|
|
33
62
|
"author": {
|
|
34
63
|
"name": "s00d",
|
|
35
64
|
"email": "Virus191288@gmail.com",
|
|
36
65
|
"url": "https://s00d.github.io/"
|
|
37
66
|
},
|
|
38
|
-
"license": "MIT",
|
|
39
|
-
"repository": {
|
|
40
|
-
"type": "git",
|
|
41
|
-
"url": "https://github.com/s00d/nuxt-i18n-micro"
|
|
42
|
-
},
|
|
43
67
|
"dependencies": {
|
|
44
|
-
"globby": "^14.1.0",
|
|
45
68
|
"chokidar": "^3.6.0",
|
|
69
|
+
"globby": "^14.1.0",
|
|
46
70
|
"unplugin": "^1.16.1"
|
|
47
71
|
},
|
|
48
72
|
"peerDependencies": {
|
|
49
73
|
"@nuxt/kit": "^3.18.1 || ^4.0.0"
|
|
50
74
|
},
|
|
51
|
-
"engines": {
|
|
52
|
-
"node": ">=18.17.0"
|
|
53
|
-
},
|
|
54
75
|
"devDependencies": {
|
|
76
|
+
"@types/jest": "^29.5.14",
|
|
55
77
|
"@types/node": "^20.19.26",
|
|
56
|
-
"vite": "^7.3.1",
|
|
57
|
-
"vite-plugin-dts": "^4.5.4",
|
|
58
|
-
"typescript": "^5.9.3",
|
|
59
78
|
"jest": "^29.7.0",
|
|
79
|
+
"publint": "^0.3.17",
|
|
60
80
|
"ts-jest": "^29.4.6",
|
|
61
|
-
"
|
|
81
|
+
"typescript": "^5.9.3",
|
|
82
|
+
"vite": "^7.3.1",
|
|
83
|
+
"vite-plugin-dts": "^4.5.4"
|
|
62
84
|
},
|
|
63
85
|
"scripts": {
|
|
64
86
|
"build": "vite build",
|
|
87
|
+
"check:package": "publint",
|
|
65
88
|
"test": "jest",
|
|
66
89
|
"typecheck": "tsc --noEmit"
|
|
67
90
|
}
|