@i18n-micro/types-generator 1.1.4 → 1.1.6
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/generator-BRNo9fkZ.js +54 -0
- package/dist/generator-Cqp8Bpki.cjs +14 -0
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +41 -46
- package/dist/nuxt.cjs +1 -1
- package/dist/nuxt.mjs +30 -32
- package/package.json +7 -7
- package/dist/generator-CAQjf5De.cjs +0 -14
- package/dist/generator-CSjBe25p.js +0 -54
|
@@ -0,0 +1,54 @@
|
|
|
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, t = "") {
|
|
6
|
+
let n = [];
|
|
7
|
+
for (let r in e) {
|
|
8
|
+
if (!Object.hasOwn(e, r)) continue;
|
|
9
|
+
let i = e[r], a = t ? `${t}.${r}` : r;
|
|
10
|
+
typeof i == "object" && i && !Array.isArray(i) ? n.push(...o(i, a)) : n.push(a);
|
|
11
|
+
}
|
|
12
|
+
return n;
|
|
13
|
+
}
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region src/core/generator.ts
|
|
16
|
+
async function s(e) {
|
|
17
|
+
let n = i(e.srcDir, e.translationDir), r = await a("**/*.json", {
|
|
18
|
+
cwd: n,
|
|
19
|
+
absolute: !0,
|
|
20
|
+
ignore: [
|
|
21
|
+
"node_modules/**",
|
|
22
|
+
"dist/**",
|
|
23
|
+
".nuxt/**"
|
|
24
|
+
]
|
|
25
|
+
}), s = /* @__PURE__ */ new Set();
|
|
26
|
+
for (let e of r) try {
|
|
27
|
+
let n = o(JSON.parse(t(e, "utf-8")));
|
|
28
|
+
for (let e of n) s.add(e);
|
|
29
|
+
} catch (t) {
|
|
30
|
+
console.warn(`[i18n-types] Failed to parse ${e}:`, t);
|
|
31
|
+
}
|
|
32
|
+
return `/* prettier-ignore */
|
|
33
|
+
// @ts-nocheck
|
|
34
|
+
// Generated by @i18n-micro/types-generator
|
|
35
|
+
// DO NOT EDIT THIS FILE MANUALLY
|
|
36
|
+
|
|
37
|
+
import '@i18n-micro/types';
|
|
38
|
+
|
|
39
|
+
declare module '@i18n-micro/types' {
|
|
40
|
+
export interface DefineLocaleMessage {
|
|
41
|
+
${Array.from(s).sort().map((e) => ` '${e}': string;`).join("\n")}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
`;
|
|
45
|
+
}
|
|
46
|
+
async function c(t) {
|
|
47
|
+
let a = await s(t), o = t.outputFile || i(t.srcDir, "i18n-micro.d.ts"), c = r(o);
|
|
48
|
+
try {
|
|
49
|
+
e(c, { recursive: !0 });
|
|
50
|
+
} catch {}
|
|
51
|
+
return n(o, a, "utf-8"), o;
|
|
52
|
+
}
|
|
53
|
+
//#endregion
|
|
54
|
+
export { s as n, o as r, c as t };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
let e=require("node:fs"),t=require("node:path"),n=require("globby");function r(e,t=``){let n=[];for(let i in e){if(!Object.hasOwn(e,i))continue;let a=e[i],o=t?`${t}.${i}`:i;typeof a==`object`&&a&&!Array.isArray(a)?n.push(...r(a,o)):n.push(o)}return n}async function i(i){let a=(0,t.resolve)(i.srcDir,i.translationDir),o=await(0,n.globby)(`**/*.json`,{cwd:a,absolute:!0,ignore:[`node_modules/**`,`dist/**`,`.nuxt/**`]}),s=new Set;for(let t of o)try{let n=r(JSON.parse((0,e.readFileSync)(t,`utf-8`)));for(let e of n)s.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(s).sort().map(e=>` '${e}': string;`).join(`
|
|
11
|
+
`)}
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
`}async function a(n){let r=await i(n),a=n.outputFile||(0,t.resolve)(n.srcDir,`i18n-micro.d.ts`),o=(0,t.dirname)(a);try{(0,e.mkdirSync)(o,{recursive:!0})}catch{}return(0,e.writeFileSync)(a,r,`utf-8`),a}Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return i}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return r}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return a}});
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./generator-Cqp8Bpki.cjs");let t=require("node:path"),n=require("chokidar"),r=require("unplugin");var i=null,a=null;function o(e,t){return function(...n){a&&clearTimeout(a),a=setTimeout(()=>{a&&clearTimeout(a),a=null,e(...n)},t)}}var s=(0,r.createUnplugin)(r=>({name:`i18n-micro-types-generator`,async buildStart(){try{await e.t(r)}catch(e){console.warn(`[i18n-types] Failed to generate types:`,e)}if(process.env.NODE_ENV===`development`||process.env.NODE_ENV!==`production`){let a=(0,t.resolve)(r.srcDir,r.translationDir),s=o(async()=>{try{await e.t(r)}catch(e){console.warn(`[i18n-types] Failed to regenerate types:`,e)}},300);i=(0,n.watch)(a,{ignoreInitial:!0,ignored:e=>/(?:^|[/\\])(?:node_modules|dist|\.nuxt)(?:[/\\]|$)/.test(e)}),i.on(`all`,async(e,t)=>{t.endsWith(`.json`)&&s()})}},buildEnd(){i&&=(i.close(),null),a&&=(clearTimeout(a),null)}}));exports.I18nTypesPlugin=s,exports.flattenKeys=e.r,exports.generateTypes=e.t,exports.getTypesString=e.n;
|
package/dist/index.mjs
CHANGED
|
@@ -1,48 +1,43 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
function
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
};
|
|
1
|
+
import { n as e, r as t, t as n } from "./generator-BRNo9fkZ.js";
|
|
2
|
+
import { resolve as r } from "node:path";
|
|
3
|
+
import { watch as i } from "chokidar";
|
|
4
|
+
import { createUnplugin as a } from "unplugin";
|
|
5
|
+
//#region src/unplugin.ts
|
|
6
|
+
var o = null, s = null;
|
|
7
|
+
function c(e, t) {
|
|
8
|
+
return function(...n) {
|
|
9
|
+
s && clearTimeout(s), s = setTimeout(() => {
|
|
10
|
+
s && clearTimeout(s), s = null, e(...n);
|
|
11
|
+
}, t);
|
|
12
|
+
};
|
|
14
13
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
14
|
+
var l = a((e) => ({
|
|
15
|
+
name: "i18n-micro-types-generator",
|
|
16
|
+
async buildStart() {
|
|
17
|
+
try {
|
|
18
|
+
await n(e);
|
|
19
|
+
} catch (e) {
|
|
20
|
+
console.warn("[i18n-types] Failed to generate types:", e);
|
|
21
|
+
}
|
|
22
|
+
if (process.env.NODE_ENV === "development" || process.env.NODE_ENV !== "production") {
|
|
23
|
+
let t = r(e.srcDir, e.translationDir), a = c(async () => {
|
|
24
|
+
try {
|
|
25
|
+
await n(e);
|
|
26
|
+
} catch (e) {
|
|
27
|
+
console.warn("[i18n-types] Failed to regenerate types:", e);
|
|
28
|
+
}
|
|
29
|
+
}, 300);
|
|
30
|
+
o = i(t, {
|
|
31
|
+
ignoreInitial: !0,
|
|
32
|
+
ignored: (e) => /(?:^|[/\\])(?:node_modules|dist|\.nuxt)(?:[/\\]|$)/.test(e)
|
|
33
|
+
}), o.on("all", async (e, t) => {
|
|
34
|
+
t.endsWith(".json") && a();
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
buildEnd() {
|
|
39
|
+
o &&= (o.close(), null), s &&= (clearTimeout(s), null);
|
|
40
|
+
}
|
|
42
41
|
}));
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
h as flattenKeys,
|
|
46
|
-
l as generateTypes,
|
|
47
|
-
v as getTypesString
|
|
48
|
-
};
|
|
42
|
+
//#endregion
|
|
43
|
+
export { l as I18nTypesPlugin, t as flattenKeys, n as generateTypes, e as getTypesString };
|
package/dist/nuxt.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require("./generator-Cqp8Bpki.cjs");let t=require("@nuxt/kit");var n=(0,t.defineNuxtModule)({meta:{name:`@i18n-micro/types-generator`,configKey:`i18nTypes`},defaults:{translationDir:`locales`},async setup(n,r){let i=r.options.i18n,a=n.translationDir||i?.translationDir||`locales`;(0,t.addTypeTemplate)({filename:`types/i18n-micro.d.ts`,getContents:async()=>{try{return await e.n({srcDir:r.options.rootDir,translationDir:a})}catch(e){return console.warn(`[i18n-types] Failed to generate types:`,e),`// Failed to generate types: ${e instanceof Error?e.message:String(e)}`}}}),r.hook(`builder:watch`,async(e,t)=>{let n=t.replace(/\\/g,`/`),i=a.replace(/\\/g,`/`);n.includes(i)&&n.endsWith(`.json`)&&await r.callHook(`builder:generateApp`)})}});exports.default=n;
|
package/dist/nuxt.mjs
CHANGED
|
@@ -1,33 +1,31 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
1
|
+
import { n as e } from "./generator-BRNo9fkZ.js";
|
|
2
|
+
import { addTypeTemplate as t, defineNuxtModule as n } from "@nuxt/kit";
|
|
3
|
+
//#region src/nuxt.ts
|
|
4
|
+
var r = n({
|
|
5
|
+
meta: {
|
|
6
|
+
name: "@i18n-micro/types-generator",
|
|
7
|
+
configKey: "i18nTypes"
|
|
8
|
+
},
|
|
9
|
+
defaults: { translationDir: "locales" },
|
|
10
|
+
async setup(n, r) {
|
|
11
|
+
let i = r.options.i18n, a = n.translationDir || i?.translationDir || "locales";
|
|
12
|
+
t({
|
|
13
|
+
filename: "types/i18n-micro.d.ts",
|
|
14
|
+
getContents: async () => {
|
|
15
|
+
try {
|
|
16
|
+
return await e({
|
|
17
|
+
srcDir: r.options.rootDir,
|
|
18
|
+
translationDir: a
|
|
19
|
+
});
|
|
20
|
+
} catch (e) {
|
|
21
|
+
return console.warn("[i18n-types] Failed to generate types:", e), `// Failed to generate types: ${e instanceof Error ? e.message : String(e)}`;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}), r.hook("builder:watch", async (e, t) => {
|
|
25
|
+
let n = t.replace(/\\/g, "/"), i = a.replace(/\\/g, "/");
|
|
26
|
+
n.includes(i) && n.endsWith(".json") && await r.callHook("builder:generateApp");
|
|
27
|
+
});
|
|
28
|
+
}
|
|
30
29
|
});
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
};
|
|
30
|
+
//#endregion
|
|
31
|
+
export { r as default };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@i18n-micro/types-generator",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.6",
|
|
4
4
|
"description": "Type generator for i18n-micro translation keys",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"i18n",
|
|
@@ -68,14 +68,14 @@
|
|
|
68
68
|
},
|
|
69
69
|
"devDependencies": {
|
|
70
70
|
"@types/node": "^20.19.26",
|
|
71
|
-
"publint": "^0.3.
|
|
72
|
-
"typescript": "^
|
|
73
|
-
"vite": "^
|
|
74
|
-
"vite-plugin-dts": "^
|
|
75
|
-
"vitest": "^4.1.
|
|
71
|
+
"publint": "^0.3.24",
|
|
72
|
+
"typescript": "^6.0.3",
|
|
73
|
+
"vite": "^8.2.2",
|
|
74
|
+
"vite-plugin-dts": "^5.1.0",
|
|
75
|
+
"vitest": "^4.1.11"
|
|
76
76
|
},
|
|
77
77
|
"peerDependencies": {
|
|
78
|
-
"@nuxt/kit": "^3.18.1 || ^4.
|
|
78
|
+
"@nuxt/kit": "^3.18.1 || ^4.5.2"
|
|
79
79
|
},
|
|
80
80
|
"engines": {
|
|
81
81
|
"node": ">=18.17.0"
|
|
@@ -1,14 +0,0 @@
|
|
|
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 */
|
|
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(n).sort().map(r=>` '${r}': string;`).join(`
|
|
11
|
-
`)}
|
|
12
|
-
}
|
|
13
|
-
}
|
|
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,54 +0,0 @@
|
|
|
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
|
-
function a(e, o = "") {
|
|
5
|
-
const t = [];
|
|
6
|
-
for (const n in e) {
|
|
7
|
-
if (!Object.hasOwn(e, n)) continue;
|
|
8
|
-
const s = e[n], r = o ? `${o}.${n}` : n;
|
|
9
|
-
typeof s == "object" && s !== null && !Array.isArray(s) ? t.push(...a(s, r)) : t.push(r);
|
|
10
|
-
}
|
|
11
|
-
return t;
|
|
12
|
-
}
|
|
13
|
-
async function g(e) {
|
|
14
|
-
const o = i(e.srcDir, e.translationDir), t = await d("**/*.json", {
|
|
15
|
-
cwd: o,
|
|
16
|
-
absolute: !0,
|
|
17
|
-
ignore: ["node_modules/**", "dist/**", ".nuxt/**"]
|
|
18
|
-
}), n = /* @__PURE__ */ new Set();
|
|
19
|
-
for (const r of t)
|
|
20
|
-
try {
|
|
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
|
-
}
|
|
27
|
-
return `/* prettier-ignore */
|
|
28
|
-
// @ts-nocheck
|
|
29
|
-
// Generated by @i18n-micro/types-generator
|
|
30
|
-
// DO NOT EDIT THIS FILE MANUALLY
|
|
31
|
-
|
|
32
|
-
import '@i18n-micro/types';
|
|
33
|
-
|
|
34
|
-
declare module '@i18n-micro/types' {
|
|
35
|
-
export interface DefineLocaleMessage {
|
|
36
|
-
${Array.from(n).sort().map((r) => ` '${r}': string;`).join(`
|
|
37
|
-
`)}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
`;
|
|
41
|
-
}
|
|
42
|
-
async function h(e) {
|
|
43
|
-
const o = await g(e), t = e.outputFile || i(e.srcDir, "i18n-micro.d.ts"), n = m(t);
|
|
44
|
-
try {
|
|
45
|
-
f(n, { recursive: !0 });
|
|
46
|
-
} catch {
|
|
47
|
-
}
|
|
48
|
-
return p(t, o, "utf-8"), t;
|
|
49
|
-
}
|
|
50
|
-
export {
|
|
51
|
-
g as a,
|
|
52
|
-
a as f,
|
|
53
|
-
h as g
|
|
54
|
-
};
|