@gringow/gringow-vite 0.0.1

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.
@@ -0,0 +1,3 @@
1
+ declare function buildGringowCache(): Promise<void>;
2
+
3
+ export { buildGringowCache };
@@ -0,0 +1,36 @@
1
+ import Gringow2, { awaitedConfig } from '@gringow/gringow';
2
+ import { globby } from 'globby';
3
+ import fs from 'fs/promises';
4
+
5
+ // src/build-gringow-cache.ts
6
+
7
+ // src/get-matches-in-code.ts
8
+ function getMatchesInCode(code) {
9
+ const regex = /g`((?:\\`|[^`])+)`/g;
10
+ return [...new Set([...code.matchAll(regex)].map(([, value = ""]) => value))];
11
+ }
12
+ async function getMatchesFromFile(filePath) {
13
+ const code = await fs.readFile(filePath, "utf-8");
14
+ return getMatchesInCode(code);
15
+ }
16
+
17
+ // src/index.ts
18
+ var localCache = /* @__PURE__ */ new Set();
19
+
20
+ // src/build-gringow-cache.ts
21
+ async function buildGringowCache() {
22
+ const gringowConfig = await awaitedConfig;
23
+ const files = await globby(String(gringowConfig.globby) ?? "./src/**/*.{js,jsx,ts,tsx}");
24
+ for await (const file of files) {
25
+ const matches = await getMatchesFromFile(file);
26
+ for await (const match of matches) {
27
+ if (!String(match).trim()) continue;
28
+ const { cacheId } = await Gringow2(String(match).trim());
29
+ if (!localCache.has(cacheId)) {
30
+ localCache.add(cacheId);
31
+ }
32
+ }
33
+ }
34
+ }
35
+
36
+ export { buildGringowCache };
@@ -0,0 +1,3 @@
1
+ declare function getMatchesFromFile(filePath: string): Promise<string[]>;
2
+
3
+ export { getMatchesFromFile };
@@ -0,0 +1,17 @@
1
+ import fs from 'fs/promises';
2
+
3
+ // src/get-matches-from-file.ts
4
+
5
+ // src/get-matches-in-code.ts
6
+ function getMatchesInCode(code) {
7
+ const regex = /g`((?:\\`|[^`])+)`/g;
8
+ return [...new Set([...code.matchAll(regex)].map(([, value = ""]) => value))];
9
+ }
10
+
11
+ // src/get-matches-from-file.ts
12
+ async function getMatchesFromFile(filePath) {
13
+ const code = await fs.readFile(filePath, "utf-8");
14
+ return getMatchesInCode(code);
15
+ }
16
+
17
+ export { getMatchesFromFile };
@@ -0,0 +1,3 @@
1
+ declare function getMatchesInCode(code: string): string[];
2
+
3
+ export { getMatchesInCode };
@@ -0,0 +1,7 @@
1
+ // src/get-matches-in-code.ts
2
+ function getMatchesInCode(code) {
3
+ const regex = /g`((?:\\`|[^`])+)`/g;
4
+ return [...new Set([...code.matchAll(regex)].map(([, value = ""]) => value))];
5
+ }
6
+
7
+ export { getMatchesInCode };
@@ -0,0 +1,3 @@
1
+ declare function getSourceIds(): Promise<Map<string, string>>;
2
+
3
+ export { getSourceIds };
@@ -0,0 +1,35 @@
1
+ import { awaitedConfig, createCacheId } from '@gringow/gringow';
2
+ import { globby } from 'globby';
3
+ import fs from 'fs/promises';
4
+
5
+ // src/get-source-ids.ts
6
+
7
+ // src/get-matches-in-code.ts
8
+ function getMatchesInCode(code) {
9
+ const regex = /g`((?:\\`|[^`])+)`/g;
10
+ return [...new Set([...code.matchAll(regex)].map(([, value = ""]) => value))];
11
+ }
12
+
13
+ // src/get-matches-from-file.ts
14
+ async function getMatchesFromFile(filePath) {
15
+ const code = await fs.readFile(filePath, "utf-8");
16
+ return getMatchesInCode(code);
17
+ }
18
+
19
+ // src/get-source-ids.ts
20
+ async function getSourceIds() {
21
+ const gringowConfig = await awaitedConfig;
22
+ const files = await globby(String(gringowConfig.globby) ?? "./src/**/*.{js,jsx,ts,tsx}");
23
+ const sourceIds = /* @__PURE__ */ new Map();
24
+ for await (const file of files) {
25
+ const matches = await getMatchesFromFile(file);
26
+ for await (const match of matches) {
27
+ if (!String(match).trim()) continue;
28
+ const cacheId = createCacheId(String(match).trim());
29
+ sourceIds.set(cacheId, String(match).trim());
30
+ }
31
+ }
32
+ return sourceIds;
33
+ }
34
+
35
+ export { getSourceIds };
@@ -0,0 +1,9 @@
1
+ import { Plugin } from 'vite';
2
+
3
+ type GringowVitePluginOptions = {
4
+ debug?: boolean;
5
+ };
6
+ declare const localCache: Set<string>;
7
+ declare function GringowVitePlugin(options?: GringowVitePluginOptions): Plugin;
8
+
9
+ export { type GringowVitePluginOptions, GringowVitePlugin as default, localCache };
package/dist/index.mjs ADDED
@@ -0,0 +1,112 @@
1
+ import Gringow2, { getOrCreateCache, deleteCacheItem, createCacheId, clearCache, awaitedConfig } from '@gringow/gringow';
2
+ import { globby } from 'globby';
3
+ import fs from 'fs/promises';
4
+
5
+ // src/index.ts
6
+
7
+ // src/get-matches-in-code.ts
8
+ function getMatchesInCode(code) {
9
+ const regex = /g`((?:\\`|[^`])+)`/g;
10
+ return [...new Set([...code.matchAll(regex)].map(([, value = ""]) => value))];
11
+ }
12
+
13
+ // src/get-matches-from-file.ts
14
+ async function getMatchesFromFile(filePath) {
15
+ const code = await fs.readFile(filePath, "utf-8");
16
+ return getMatchesInCode(code);
17
+ }
18
+
19
+ // src/build-gringow-cache.ts
20
+ async function buildGringowCache() {
21
+ const gringowConfig = await awaitedConfig;
22
+ const files = await globby(String(gringowConfig.globby) ?? "./src/**/*.{js,jsx,ts,tsx}");
23
+ for await (const file of files) {
24
+ const matches = await getMatchesFromFile(file);
25
+ for await (const match of matches) {
26
+ if (!String(match).trim()) continue;
27
+ const { cacheId } = await Gringow2(String(match).trim());
28
+ if (!localCache.has(cacheId)) {
29
+ localCache.add(cacheId);
30
+ }
31
+ }
32
+ }
33
+ }
34
+ async function getSourceIds() {
35
+ const gringowConfig = await awaitedConfig;
36
+ const files = await globby(String(gringowConfig.globby) ?? "./src/**/*.{js,jsx,ts,tsx}");
37
+ const sourceIds = /* @__PURE__ */ new Map();
38
+ for await (const file of files) {
39
+ const matches = await getMatchesFromFile(file);
40
+ for await (const match of matches) {
41
+ if (!String(match).trim()) continue;
42
+ const cacheId = createCacheId(String(match).trim());
43
+ sourceIds.set(cacheId, String(match).trim());
44
+ }
45
+ }
46
+ return sourceIds;
47
+ }
48
+
49
+ // src/is-source-code.ts
50
+ function isSourceCode(filePath) {
51
+ return /\.(js|jsx|ts|tsx)$/.test(filePath) && !filePath.includes("node_modules");
52
+ }
53
+
54
+ // src/index.ts
55
+ var localCache = /* @__PURE__ */ new Set();
56
+ function GringowVitePlugin(options = { debug: false }) {
57
+ const { debug } = options;
58
+ if (debug) {
59
+ console.log("GringowVitePlugin, loaded with options:");
60
+ Object.keys(options).forEach((key) => {
61
+ console.log(`${key}: ${options[key]}`);
62
+ });
63
+ }
64
+ return {
65
+ name: "gringow-vite-plugin",
66
+ enforce: "pre",
67
+ async buildStart() {
68
+ const gringowArg = process.argv.find((arg) => arg.startsWith("--gringow="));
69
+ if (gringowArg) {
70
+ const gringowValue = gringowArg.split("=").pop();
71
+ if (gringowValue === "build") {
72
+ await buildGringowCache();
73
+ } else if (gringowValue === "clear") {
74
+ await clearCache();
75
+ } else if (gringowValue === "reset") {
76
+ await clearCache();
77
+ await new Promise((resolve) => setTimeout(resolve, 500));
78
+ await buildGringowCache();
79
+ }
80
+ return process.exit(0);
81
+ }
82
+ },
83
+ async transform(code, fileId) {
84
+ if (!isSourceCode(fileId)) return;
85
+ const codeMatches = getMatchesInCode(code);
86
+ for await (const text of codeMatches) {
87
+ const id = createCacheId(text);
88
+ if (localCache.has(id)) continue;
89
+ const { cacheId: gringowId } = await Gringow2(text);
90
+ localCache.add(gringowId);
91
+ }
92
+ },
93
+ async buildEnd() {
94
+ const cache = await getOrCreateCache();
95
+ const jsonIds = Object.keys(cache);
96
+ const sourceIds = await getSourceIds();
97
+ for await (const id of jsonIds) {
98
+ if (!sourceIds.has(id)) {
99
+ await deleteCacheItem(id);
100
+ }
101
+ }
102
+ for await (const [id, text] of sourceIds) {
103
+ if (!jsonIds.includes(id)) {
104
+ const { cacheId: gringowId } = await Gringow2(text);
105
+ localCache.add(gringowId);
106
+ }
107
+ }
108
+ }
109
+ };
110
+ }
111
+
112
+ export { GringowVitePlugin as default, localCache };
@@ -0,0 +1,3 @@
1
+ declare function isSourceCode(filePath: string): boolean;
2
+
3
+ export { isSourceCode };
@@ -0,0 +1,6 @@
1
+ // src/is-source-code.ts
2
+ function isSourceCode(filePath) {
3
+ return /\.(js|jsx|ts|tsx)$/.test(filePath) && !filePath.includes("node_modules");
4
+ }
5
+
6
+ export { isSourceCode };
package/package.json ADDED
@@ -0,0 +1,57 @@
1
+ {
2
+ "name": "@gringow/gringow-vite",
3
+ "version": "0.0.1",
4
+ "description": "A Vite plugin for Gringow AI-powered translation tool",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.mjs",
7
+ "types": "dist/index.d.ts",
8
+ "files": [
9
+ "dist",
10
+ "README.md"
11
+ ],
12
+ "exports": {
13
+ ".": {
14
+ "import": "./dist/index.mjs",
15
+ "require": "./dist/index.js"
16
+ }
17
+ },
18
+ "keywords": [
19
+ "gringow",
20
+ "vite",
21
+ "translation",
22
+ "i18n",
23
+ "internationalization",
24
+ "llm",
25
+ "ai",
26
+ "vite-plugin",
27
+ "react",
28
+ "vue"
29
+ ],
30
+ "repository": {
31
+ "type": "git",
32
+ "url": "https://github.com/rntgspr/gringow.git",
33
+ "directory": "gringow-vite"
34
+ },
35
+ "author": "Renato Gaspar <rntgspr@gmail.com>",
36
+ "license": "MIT",
37
+ "publishConfig": {
38
+ "access": "public"
39
+ },
40
+ "dependencies": {
41
+ "@gringow/gringow": "0.0.8",
42
+ "globby": "14.1.0",
43
+ "vite": "7.0.0"
44
+ },
45
+ "devDependencies": {
46
+ "@types/node": "22.15.0",
47
+ "tsc-alias": "1.8.16",
48
+ "tsup": "8.5.0",
49
+ "typescript": "5.8.3"
50
+ },
51
+ "scripts": {
52
+ "build": "rm -rf ./dist/* ./tsconfig.tsbuildinfo && tsup",
53
+ "watch": "pnpm run build && tsup --watch --config ../tsup.config.ts",
54
+ "__postinstall": "pnpm run build",
55
+ "test": "echo \"Warning: no test specified\" && exit 0"
56
+ }
57
+ }