@i18n-micro/types-generator 1.1.1 → 1.1.3
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/README.md +1 -5
- package/dist/core/generator.d.ts +8 -8
- package/dist/core/parser.d.ts +4 -4
- package/dist/{generator-CUX1kjyj.js → generator-CSjBe25p.js} +4 -4
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +5 -0
- package/dist/index.mjs +19 -19
- package/dist/nuxt.d.cts +7 -0
- package/dist/nuxt.mjs +1 -1
- package/dist/unplugin.d.ts.map +1 -1
- package/package.json +59 -38
package/README.md
CHANGED
|
@@ -20,10 +20,7 @@ Add to `nuxt.config.ts`:
|
|
|
20
20
|
|
|
21
21
|
```typescript
|
|
22
22
|
export default defineNuxtConfig({
|
|
23
|
-
modules: [
|
|
24
|
-
'nuxt-i18n-micro',
|
|
25
|
-
'@i18n-micro/types-generator/nuxt',
|
|
26
|
-
],
|
|
23
|
+
modules: ['nuxt-i18n-micro', '@i18n-micro/types-generator/nuxt'],
|
|
27
24
|
})
|
|
28
25
|
```
|
|
29
26
|
|
|
@@ -59,4 +56,3 @@ See [full documentation](../../docs/integrations/types-generator.md) for detaile
|
|
|
59
56
|
## License
|
|
60
57
|
|
|
61
58
|
MIT
|
|
62
|
-
|
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
|
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,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { readFileSync as l, mkdirSync as f, writeFileSync as p } from "node:fs";
|
|
2
2
|
import { resolve as i, dirname as m } from "node:path";
|
|
3
3
|
import { globby as d } from "globby";
|
|
4
4
|
function a(e, o = "") {
|
|
@@ -18,7 +18,7 @@ async function g(e) {
|
|
|
18
18
|
}), n = /* @__PURE__ */ new Set();
|
|
19
19
|
for (const r of t)
|
|
20
20
|
try {
|
|
21
|
-
const c = JSON.parse(
|
|
21
|
+
const c = JSON.parse(l(r, "utf-8")), y = a(c);
|
|
22
22
|
for (const u of y)
|
|
23
23
|
n.add(u);
|
|
24
24
|
} catch (c) {
|
|
@@ -42,10 +42,10 @@ ${Array.from(n).sort().map((r) => ` '${r}': string;`).join(`
|
|
|
42
42
|
async function h(e) {
|
|
43
43
|
const o = await g(e), t = e.outputFile || i(e.srcDir, "i18n-micro.d.ts"), n = m(t);
|
|
44
44
|
try {
|
|
45
|
-
|
|
45
|
+
f(n, { recursive: !0 });
|
|
46
46
|
} catch {
|
|
47
47
|
}
|
|
48
|
-
return
|
|
48
|
+
return p(t, o, "utf-8"), t;
|
|
49
49
|
}
|
|
50
50
|
export {
|
|
51
51
|
g as a,
|
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 o=require("./generator-CAQjf5De.cjs"),l=require("node:path"),c=require("chokidar"),u=require("unplugin");let i=null,e=null;function y(t,r){return function(...n){const a=()=>{e&&clearTimeout(e),e=null,t(...n)};e&&clearTimeout(e),e=setTimeout(a,r)}}const g=u.createUnplugin(t=>({name:"i18n-micro-types-generator",async buildStart(){try{await o.generateTypes(t)}catch(r){console.warn("[i18n-types] Failed to generate types:",r)}if(process.env.NODE_ENV==="development"||process.env.NODE_ENV!=="production"){const r=l.resolve(t.srcDir,t.translationDir),s=y(async()=>{try{await o.generateTypes(t)}catch(n){console.warn("[i18n-types] Failed to regenerate types:",n)}},300);i=c.watch(r,{ignoreInitial:!0,ignored:n=>/(?:^|[/\\])(?:node_modules|dist|\.nuxt)(?:[/\\]|$)/.test(n)}),i.on("all",async(n,a)=>{a.endsWith(".json")&&s()})}},buildEnd(){i&&(i.close(),i=null),e&&(clearTimeout(e),e=null)}}));exports.flattenKeys=o.flattenKeys;exports.generateTypes=o.generateTypes;exports.getTypesString=o.getTypesString;exports.I18nTypesPlugin=g;
|
package/dist/index.d.cts
ADDED
package/dist/index.mjs
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { g as l } from "./generator-
|
|
2
|
-
import { f as
|
|
3
|
-
import { resolve as
|
|
4
|
-
import
|
|
1
|
+
import { g as l } from "./generator-CSjBe25p.js";
|
|
2
|
+
import { f as h, a as v } from "./generator-CSjBe25p.js";
|
|
3
|
+
import { resolve as s } from "node:path";
|
|
4
|
+
import { watch as c } from "chokidar";
|
|
5
5
|
import { createUnplugin as u } from "unplugin";
|
|
6
|
-
let
|
|
7
|
-
function m(t,
|
|
8
|
-
return function(...
|
|
6
|
+
let o = null, e = null;
|
|
7
|
+
function m(t, r) {
|
|
8
|
+
return function(...n) {
|
|
9
9
|
const i = () => {
|
|
10
|
-
e && clearTimeout(e), e = null, t(...
|
|
10
|
+
e && clearTimeout(e), e = null, t(...n);
|
|
11
11
|
};
|
|
12
|
-
e && clearTimeout(e), e = setTimeout(i,
|
|
12
|
+
e && clearTimeout(e), e = setTimeout(i, r);
|
|
13
13
|
};
|
|
14
14
|
}
|
|
15
15
|
const g = u((t) => ({
|
|
@@ -17,32 +17,32 @@ const g = u((t) => ({
|
|
|
17
17
|
async buildStart() {
|
|
18
18
|
try {
|
|
19
19
|
await l(t);
|
|
20
|
-
} catch (
|
|
21
|
-
console.warn("[i18n-types] Failed to generate types:",
|
|
20
|
+
} catch (r) {
|
|
21
|
+
console.warn("[i18n-types] Failed to generate types:", r);
|
|
22
22
|
}
|
|
23
23
|
if (process.env.NODE_ENV === "development" || process.env.NODE_ENV !== "production") {
|
|
24
|
-
const
|
|
24
|
+
const r = s(t.srcDir, t.translationDir), a = m(async () => {
|
|
25
25
|
try {
|
|
26
26
|
await l(t);
|
|
27
|
-
} catch (
|
|
28
|
-
console.warn("[i18n-types] Failed to regenerate types:",
|
|
27
|
+
} catch (n) {
|
|
28
|
+
console.warn("[i18n-types] Failed to regenerate types:", n);
|
|
29
29
|
}
|
|
30
30
|
}, 300);
|
|
31
|
-
|
|
31
|
+
o = c(r, {
|
|
32
32
|
ignoreInitial: !0,
|
|
33
|
-
ignored: [
|
|
34
|
-
}),
|
|
33
|
+
ignored: (n) => /(?:^|[/\\])(?:node_modules|dist|\.nuxt)(?:[/\\]|$)/.test(n)
|
|
34
|
+
}), o.on("all", async (n, i) => {
|
|
35
35
|
i.endsWith(".json") && a();
|
|
36
36
|
});
|
|
37
37
|
}
|
|
38
38
|
},
|
|
39
39
|
buildEnd() {
|
|
40
|
-
|
|
40
|
+
o && (o.close(), o = null), e && (clearTimeout(e), e = null);
|
|
41
41
|
}
|
|
42
42
|
}));
|
|
43
43
|
export {
|
|
44
44
|
g as I18nTypesPlugin,
|
|
45
|
-
|
|
45
|
+
h as flattenKeys,
|
|
46
46
|
l as generateTypes,
|
|
47
47
|
v as getTypesString
|
|
48
48
|
};
|
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.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":"AAGA,OAAO,EAAE,KAAK,gBAAgB,EAAiB,MAAM,kBAAkB,CAAA;AAkBvE,eAAO,MAAM,eAAe,
|
|
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"}
|
package/package.json
CHANGED
|
@@ -1,68 +1,89 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@i18n-micro/types-generator",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.3",
|
|
4
4
|
"description": "Type generator for i18n-micro translation keys",
|
|
5
|
-
"type": "module",
|
|
6
|
-
"main": "./dist/index.cjs",
|
|
7
|
-
"module": "./dist/index.mjs",
|
|
8
|
-
"types": "./dist/index.d.ts",
|
|
9
|
-
"exports": {
|
|
10
|
-
".": {
|
|
11
|
-
"types": "./dist/index.d.ts",
|
|
12
|
-
"import": "./dist/index.mjs",
|
|
13
|
-
"require": "./dist/index.cjs"
|
|
14
|
-
},
|
|
15
|
-
"./nuxt": {
|
|
16
|
-
"types": "./dist/nuxt.d.ts",
|
|
17
|
-
"import": "./dist/nuxt.mjs",
|
|
18
|
-
"require": "./dist/nuxt.cjs"
|
|
19
|
-
}
|
|
20
|
-
},
|
|
21
|
-
"files": [
|
|
22
|
-
"dist"
|
|
23
|
-
],
|
|
24
|
-
"publishConfig": {
|
|
25
|
-
"access": "public"
|
|
26
|
-
},
|
|
27
5
|
"keywords": [
|
|
28
6
|
"i18n",
|
|
29
|
-
"
|
|
7
|
+
"nuxt",
|
|
8
|
+
"translation",
|
|
30
9
|
"type-generator",
|
|
31
|
-
"
|
|
10
|
+
"typescript"
|
|
32
11
|
],
|
|
12
|
+
"homepage": "https://github.com/s00d/nuxt-i18n-micro/tree/main/packages/types-generator#readme",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/s00d/nuxt-i18n-micro/issues"
|
|
15
|
+
},
|
|
16
|
+
"license": "MIT",
|
|
33
17
|
"author": {
|
|
34
18
|
"name": "s00d",
|
|
35
19
|
"email": "Virus191288@gmail.com",
|
|
36
20
|
"url": "https://s00d.github.io/"
|
|
37
21
|
},
|
|
38
|
-
"license": "MIT",
|
|
39
22
|
"repository": {
|
|
40
23
|
"type": "git",
|
|
41
|
-
"url": "https://github.com/s00d/nuxt-i18n-micro"
|
|
24
|
+
"url": "git+https://github.com/s00d/nuxt-i18n-micro.git",
|
|
25
|
+
"directory": "packages/types-generator"
|
|
26
|
+
},
|
|
27
|
+
"files": [
|
|
28
|
+
"dist",
|
|
29
|
+
"README.md",
|
|
30
|
+
"LICENSE"
|
|
31
|
+
],
|
|
32
|
+
"type": "module",
|
|
33
|
+
"sideEffects": false,
|
|
34
|
+
"main": "./dist/index.cjs",
|
|
35
|
+
"types": "./dist/index.d.ts",
|
|
36
|
+
"exports": {
|
|
37
|
+
".": {
|
|
38
|
+
"import": {
|
|
39
|
+
"types": "./dist/index.d.ts",
|
|
40
|
+
"default": "./dist/index.mjs"
|
|
41
|
+
},
|
|
42
|
+
"require": {
|
|
43
|
+
"types": "./dist/index.d.cts",
|
|
44
|
+
"default": "./dist/index.cjs"
|
|
45
|
+
},
|
|
46
|
+
"default": "./dist/index.mjs"
|
|
47
|
+
},
|
|
48
|
+
"./nuxt": {
|
|
49
|
+
"import": {
|
|
50
|
+
"types": "./dist/nuxt.d.ts",
|
|
51
|
+
"default": "./dist/nuxt.mjs"
|
|
52
|
+
},
|
|
53
|
+
"require": {
|
|
54
|
+
"types": "./dist/nuxt.d.cts",
|
|
55
|
+
"default": "./dist/nuxt.cjs"
|
|
56
|
+
},
|
|
57
|
+
"default": "./dist/nuxt.mjs"
|
|
58
|
+
},
|
|
59
|
+
"./package.json": "./package.json"
|
|
60
|
+
},
|
|
61
|
+
"publishConfig": {
|
|
62
|
+
"access": "public"
|
|
42
63
|
},
|
|
43
64
|
"dependencies": {
|
|
65
|
+
"chokidar": "^4.0.3",
|
|
44
66
|
"globby": "^14.1.0",
|
|
45
|
-
"chokidar": "^3.6.0",
|
|
46
67
|
"unplugin": "^1.16.1"
|
|
47
68
|
},
|
|
69
|
+
"devDependencies": {
|
|
70
|
+
"@types/node": "^20.19.26",
|
|
71
|
+
"publint": "^0.3.17",
|
|
72
|
+
"typescript": "^5.9.3",
|
|
73
|
+
"vite": "^7.3.6",
|
|
74
|
+
"vite-plugin-dts": "^4.5.4",
|
|
75
|
+
"vitest": "^4.1.10"
|
|
76
|
+
},
|
|
48
77
|
"peerDependencies": {
|
|
49
78
|
"@nuxt/kit": "^3.18.1 || ^4.0.0"
|
|
50
79
|
},
|
|
51
80
|
"engines": {
|
|
52
81
|
"node": ">=18.17.0"
|
|
53
82
|
},
|
|
54
|
-
"devDependencies": {
|
|
55
|
-
"@types/node": "^20.19.26",
|
|
56
|
-
"vite": "^7.3.1",
|
|
57
|
-
"vite-plugin-dts": "^4.5.4",
|
|
58
|
-
"typescript": "^5.9.3",
|
|
59
|
-
"jest": "^29.7.0",
|
|
60
|
-
"ts-jest": "^29.4.6",
|
|
61
|
-
"@types/jest": "^29.5.14"
|
|
62
|
-
},
|
|
63
83
|
"scripts": {
|
|
64
84
|
"build": "vite build",
|
|
65
|
-
"
|
|
85
|
+
"check:package": "publint",
|
|
86
|
+
"test": "vitest run",
|
|
66
87
|
"typecheck": "tsc --noEmit"
|
|
67
88
|
}
|
|
68
89
|
}
|