@gringow/gringow-vite 0.0.4 โ 0.0.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/README.md +307 -28
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,57 +1,260 @@
|
|
|
1
1
|
# @gringow/gringow-vite
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/@gringow/gringow-vite)
|
|
4
|
+
[](https://opensource.org/licenses/MIT)
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
-
|
|
10
|
-
-
|
|
6
|
+
Vite plugin for Gringow that automatically extracts translation strings during development and build. Scans your source code for `g` tagged templates, manages cache synchronization, and provides CLI flags for cache maintenance.
|
|
7
|
+
|
|
8
|
+
## Features
|
|
9
|
+
|
|
10
|
+
- ๐ **Automatic Extraction** - Finds all `g` tagged templates in your code
|
|
11
|
+
- ๐ **Cache Synchronization** - Keeps translations in sync with source code
|
|
12
|
+
- ๐งน **Smart Cleanup** - Removes unused translations automatically
|
|
13
|
+
- โก **Build-Time Translation** - Generates cache during Vite builds
|
|
14
|
+
- ๐ ๏ธ **CLI Flags** - `--gringow=build|clear|reset` for cache management
|
|
15
|
+
- ๐ฆ **Vite 7 Compatible** - Works with latest Vite version
|
|
11
16
|
|
|
12
17
|
## Installation
|
|
18
|
+
|
|
13
19
|
```bash
|
|
20
|
+
# Using pnpm (recommended)
|
|
14
21
|
pnpm add -D @gringow/gringow @gringow/gringow-vite
|
|
15
|
-
|
|
16
|
-
#
|
|
22
|
+
|
|
23
|
+
# Using npm
|
|
24
|
+
npm install -D @gringow/gringow @gringow/gringow-vite
|
|
25
|
+
|
|
26
|
+
# Using yarn
|
|
27
|
+
yarn add -D @gringow/gringow @gringow/gringow-vite
|
|
17
28
|
```
|
|
18
29
|
|
|
19
|
-
##
|
|
20
|
-
|
|
30
|
+
## Quick Start
|
|
31
|
+
|
|
32
|
+
### 1. Add Plugin to Vite Config
|
|
21
33
|
|
|
22
|
-
```
|
|
34
|
+
```typescript
|
|
23
35
|
// vite.config.ts
|
|
24
36
|
import { defineConfig } from 'vite'
|
|
37
|
+
import react from '@vitejs/plugin-react'
|
|
25
38
|
import Gringow from '@gringow/gringow-vite'
|
|
26
39
|
|
|
27
40
|
export default defineConfig({
|
|
28
|
-
plugins: [
|
|
41
|
+
plugins: [
|
|
42
|
+
react(),
|
|
43
|
+
Gringow({ debug: false })
|
|
44
|
+
]
|
|
29
45
|
})
|
|
30
46
|
```
|
|
31
47
|
|
|
32
|
-
|
|
48
|
+
### 2. Create Gringow Config (Optional)
|
|
49
|
+
|
|
50
|
+
```javascript
|
|
51
|
+
// gringow.config.js
|
|
52
|
+
export default {
|
|
53
|
+
llm: {
|
|
54
|
+
choice: 'huggingface',
|
|
55
|
+
model: 'Xenova/nllb-200-distilled-600M',
|
|
56
|
+
},
|
|
57
|
+
languages: ['pt-BR', 'es-ES', 'fr-CA'],
|
|
58
|
+
sourceLanguage: 'en-US',
|
|
59
|
+
globby: './src/**/*.{js,jsx,ts,tsx}', // Files to scan
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### 3. Use in Your Code
|
|
64
|
+
|
|
65
|
+
```tsx
|
|
66
|
+
// App.tsx
|
|
67
|
+
import { g } from '@gringow/gringow-react'
|
|
68
|
+
|
|
69
|
+
export default function App() {
|
|
70
|
+
return <h1>{g`Welcome to Gringow`}</h1>
|
|
71
|
+
}
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### 4. Build or Develop
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
# Development mode - extracts translations on the fly
|
|
78
|
+
pnpm run dev
|
|
79
|
+
|
|
80
|
+
# Build mode - generates complete cache
|
|
81
|
+
pnpm run build
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
The plugin automatically:
|
|
85
|
+
- Scans your source files for `g` tagged templates
|
|
86
|
+
- Generates translations using configured LLM
|
|
87
|
+
- Writes to `./gringow/gringow.json`
|
|
88
|
+
- Updates cache as you code
|
|
89
|
+
|
|
90
|
+
## CLI Flags
|
|
91
|
+
|
|
92
|
+
Control cache lifecycle with special flags during Vite builds or dev server startup.
|
|
93
|
+
|
|
94
|
+
### Build Cache
|
|
95
|
+
|
|
96
|
+
Scan all source files and generate complete translation cache.
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
vite build --gringow=build
|
|
100
|
+
|
|
101
|
+
# Useful for:
|
|
102
|
+
# - CI/CD pipelines
|
|
103
|
+
# - Initial cache generation
|
|
104
|
+
# - Pre-deployment translation updates
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### Clear Cache
|
|
33
108
|
|
|
34
|
-
|
|
35
|
-
Run Vite with extra flags to control the cache lifecycle without leaving your workflow:
|
|
109
|
+
Delete the entire cache file and exit.
|
|
36
110
|
|
|
37
111
|
```bash
|
|
38
|
-
vite build --gringow=
|
|
39
|
-
|
|
40
|
-
|
|
112
|
+
vite build --gringow=clear
|
|
113
|
+
|
|
114
|
+
# Use when:
|
|
115
|
+
# - Starting fresh
|
|
116
|
+
# - Cleaning up old translations
|
|
117
|
+
# - Debugging cache issues
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### Reset Cache
|
|
121
|
+
|
|
122
|
+
Clear existing cache and rebuild from scratch in one command.
|
|
123
|
+
|
|
124
|
+
```bash
|
|
125
|
+
vite build --gringow=reset
|
|
126
|
+
|
|
127
|
+
# Equivalent to:
|
|
128
|
+
# vite build --gringow=clear && vite build --gringow=build
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
**Note**: These commands exit immediately after completing the operation, making them perfect for CI scripts.
|
|
132
|
+
|
|
133
|
+
## Configuration
|
|
134
|
+
|
|
135
|
+
### Plugin Options
|
|
136
|
+
|
|
137
|
+
```typescript
|
|
138
|
+
interface GringowVitePluginOptions {
|
|
139
|
+
debug?: boolean // Log plugin operations (default: false)
|
|
140
|
+
}
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
**Example:**
|
|
144
|
+
```typescript
|
|
145
|
+
Gringow({ debug: true }) // Logs file scanning and extraction
|
|
41
146
|
```
|
|
42
147
|
|
|
43
|
-
|
|
148
|
+
### Gringow Config Options
|
|
44
149
|
|
|
45
|
-
|
|
46
|
-
- `debug?: boolean` (default `false`): log plugin options during startup for troubleshooting.
|
|
150
|
+
The plugin reads your `gringow.config.js` for:
|
|
47
151
|
|
|
48
|
-
|
|
49
|
-
-
|
|
152
|
+
- **`globby`** - File pattern to scan (default: `'./src/**/*.{js,jsx,ts,tsx}'`)
|
|
153
|
+
- **`cache.dir`** - Cache directory (default: `'./gringow'`)
|
|
154
|
+
- **`cache.file`** - Cache filename (default: `'gringow.json'`)
|
|
155
|
+
- **`llm.*`** - LLM provider configuration
|
|
156
|
+
- **`languages`** - Target languages array
|
|
50
157
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
158
|
+
See [@gringow/gringow](https://www.npmjs.com/package/@gringow/gringow) for full config schema.
|
|
159
|
+
|
|
160
|
+
## How It Works
|
|
161
|
+
|
|
162
|
+
The plugin hooks into Vite's transform pipeline:
|
|
163
|
+
|
|
164
|
+
### Transform Hook
|
|
165
|
+
|
|
166
|
+
- **Scans modules** - Checks each transformed file for `g` tagged templates
|
|
167
|
+
- **Extracts strings** - Parses template literals and dynamic values
|
|
168
|
+
- **Generates IDs** - Creates content-based cache IDs
|
|
169
|
+
- **Calls core library** - Invokes `@gringow/gringow` to translate and cache
|
|
170
|
+
|
|
171
|
+
### Build End Hook
|
|
172
|
+
|
|
173
|
+
- **Static analysis** - Scans all files matching `globby` pattern
|
|
174
|
+
- **Cache pruning** - Removes translations no longer in source code
|
|
175
|
+
- **Backfill** - Ensures all discovered strings are translated
|
|
176
|
+
|
|
177
|
+
### Build Start Hook
|
|
178
|
+
|
|
179
|
+
- **CLI flag detection** - Watches for `--gringow=build|clear|reset`
|
|
180
|
+
- **Cache operations** - Executes maintenance tasks
|
|
181
|
+
- **Early exit** - Terminates Vite after flag operations
|
|
182
|
+
|
|
183
|
+
## Usage Examples
|
|
184
|
+
|
|
185
|
+
### Basic React + Vite Setup
|
|
186
|
+
|
|
187
|
+
```typescript
|
|
188
|
+
// vite.config.ts
|
|
189
|
+
import { defineConfig } from 'vite'
|
|
190
|
+
import react from '@vitejs/plugin-react'
|
|
191
|
+
import Gringow from '@gringow/gringow-vite'
|
|
192
|
+
|
|
193
|
+
export default defineConfig({
|
|
194
|
+
plugins: [react(), Gringow()]
|
|
195
|
+
})
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
```tsx
|
|
199
|
+
// src/App.tsx
|
|
200
|
+
import { g } from '@gringow/gringow-react'
|
|
201
|
+
|
|
202
|
+
export default function App() {
|
|
203
|
+
const user = { name: 'Alice' }
|
|
204
|
+
return (
|
|
205
|
+
<div>
|
|
206
|
+
{g`Hello ${user.name}!`}
|
|
207
|
+
{g`Welcome to our platform`}
|
|
208
|
+
</div>
|
|
209
|
+
)
|
|
210
|
+
}
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
### CI/CD Pipeline
|
|
214
|
+
|
|
215
|
+
```yaml
|
|
216
|
+
# .github/workflows/deploy.yml
|
|
217
|
+
- name: Generate translations
|
|
218
|
+
run: pnpm vite build --gringow=build
|
|
219
|
+
|
|
220
|
+
- name: Build application
|
|
221
|
+
run: pnpm vite build
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
### Custom File Patterns
|
|
225
|
+
|
|
226
|
+
```javascript
|
|
227
|
+
// gringow.config.js
|
|
228
|
+
export default {
|
|
229
|
+
// Scan TypeScript files only
|
|
230
|
+
globby: './src/**/*.{ts,tsx}',
|
|
231
|
+
|
|
232
|
+
// Or include multiple patterns
|
|
233
|
+
globby: [
|
|
234
|
+
'./src/**/*.{ts,tsx}',
|
|
235
|
+
'./components/**/*.{ts,tsx}',
|
|
236
|
+
'!./src/**/*.test.tsx'
|
|
237
|
+
],
|
|
238
|
+
|
|
239
|
+
languages: ['pt-BR', 'es-ES'],
|
|
240
|
+
}
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
### Multi-Environment Setup
|
|
244
|
+
|
|
245
|
+
```typescript
|
|
246
|
+
// vite.config.ts
|
|
247
|
+
import { defineConfig } from 'vite'
|
|
248
|
+
import Gringow from '@gringow/gringow-vite'
|
|
249
|
+
|
|
250
|
+
export default defineConfig(({ mode }) => ({
|
|
251
|
+
plugins: [
|
|
252
|
+
Gringow({
|
|
253
|
+
debug: mode === 'development'
|
|
254
|
+
})
|
|
255
|
+
]
|
|
256
|
+
}))
|
|
257
|
+
```
|
|
55
258
|
|
|
56
259
|
## Development scripts
|
|
57
260
|
```bash
|
|
@@ -61,3 +264,79 @@ pnpm run watch # Continuous rebuild for local development
|
|
|
61
264
|
|
|
62
265
|
## License
|
|
63
266
|
MIT ยฉ Renato Gaspar
|
|
267
|
+
|
|
268
|
+
## Best Practices
|
|
269
|
+
|
|
270
|
+
1. **Run build flag before deployment** - `vite build --gringow=build` ensures complete cache
|
|
271
|
+
2. **Gitignore cache file** - Add `/gringow/gringow.json` to `.gitignore` if regenerating in CI
|
|
272
|
+
3. **Or commit cache** - Commit cache file for faster deploys without LLM calls
|
|
273
|
+
4. **Use glob patterns wisely** - Exclude test files and node_modules
|
|
274
|
+
5. **Enable debug mode** - Use `debug: true` when troubleshooting extraction issues
|
|
275
|
+
|
|
276
|
+
## Troubleshooting
|
|
277
|
+
|
|
278
|
+
### Translations Not Extracted
|
|
279
|
+
|
|
280
|
+
```typescript
|
|
281
|
+
// โ Won't work - not using g tag
|
|
282
|
+
const text = `Hello world`
|
|
283
|
+
|
|
284
|
+
// โ
Works - using g tag
|
|
285
|
+
const text = g`Hello world`
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
### Cache Not Updating
|
|
289
|
+
|
|
290
|
+
```bash
|
|
291
|
+
# Clear and rebuild
|
|
292
|
+
pnpm vite build --gringow=reset
|
|
293
|
+
|
|
294
|
+
# Or manually delete
|
|
295
|
+
rm -rf gringow/gringow.json
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
### Missing Translations
|
|
299
|
+
|
|
300
|
+
Check your `globby` pattern includes all source files:
|
|
301
|
+
|
|
302
|
+
```javascript
|
|
303
|
+
// gringow.config.js
|
|
304
|
+
export default {
|
|
305
|
+
globby: './src/**/*.{js,jsx,ts,tsx}', // Adjust to your structure
|
|
306
|
+
}
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
## Development
|
|
310
|
+
|
|
311
|
+
```bash
|
|
312
|
+
# Install dependencies
|
|
313
|
+
pnpm install
|
|
314
|
+
|
|
315
|
+
# Build the plugin
|
|
316
|
+
pnpm run build
|
|
317
|
+
|
|
318
|
+
# Watch mode
|
|
319
|
+
pnpm run watch
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
## Related Packages
|
|
323
|
+
|
|
324
|
+
- **[@gringow/gringow](https://www.npmjs.com/package/@gringow/gringow)** - Core translation library
|
|
325
|
+
- **[@gringow/gringow-react](https://www.npmjs.com/package/@gringow/gringow-react)** - React bindings
|
|
326
|
+
- **[@gringow/gringow-shadow](https://www.npmjs.com/package/@gringow/gringow-shadow)** - Web Component layer
|
|
327
|
+
- **[@gringow/cli](https://www.npmjs.com/package/@gringow/gringow-cli)** - CLI tool
|
|
328
|
+
- **[@gringow/gringow-nextjs](https://www.npmjs.com/package/@gringow/gringow-nextjs)** - Next.js plugin (experimental)
|
|
329
|
+
|
|
330
|
+
## Resources
|
|
331
|
+
|
|
332
|
+
- [Documentation](https://gringow.dev)
|
|
333
|
+
- [GitHub Repository](https://github.com/rntgspr/gringow)
|
|
334
|
+
- [Example: Vite + React](https://github.com/rntgspr/gringow/tree/main/example-gringow-vite)
|
|
335
|
+
|
|
336
|
+
## License
|
|
337
|
+
|
|
338
|
+
MIT ยฉ [Renato Gaspar](https://github.com/rntgspr)
|
|
339
|
+
|
|
340
|
+
---
|
|
341
|
+
|
|
342
|
+
**Questions?** Open an issue on [GitHub](https://github.com/rntgspr/gringow/issues)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gringow/gringow-vite",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6",
|
|
4
4
|
"description": "A Vite plugin for Gringow AI-powered translation tool",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"dependencies": {
|
|
41
41
|
"globby": "14.1.0",
|
|
42
42
|
"vite": "7.0.0",
|
|
43
|
-
"@gringow/gringow": "0.1.
|
|
43
|
+
"@gringow/gringow": "0.1.4"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@types/node": "22.15.0",
|