@gringow/gringow-vite 0.0.2 → 0.0.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 +63 -0
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +2 -2
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# @gringow/gringow-vite
|
|
2
|
+
|
|
3
|
+
Vite plugin that scans your project for Gringow template literals, keeps the translation cache in sync, and lets you drive builds with the Gringow CLI-style flags. Pair it with the core `@gringow/gringow` package to automate translation discovery during development or CI builds.
|
|
4
|
+
|
|
5
|
+
## Highlights
|
|
6
|
+
- Pre-transform hook that extracts every `g` tagged template literal from your source graph
|
|
7
|
+
- Automatically calls the Gringow runtime to populate `gringow/gringow.json`
|
|
8
|
+
- Removes stale cache entries when strings disappear from source
|
|
9
|
+
- Supports fast cache bootstrap via `--gringow=build|clear|reset` flags
|
|
10
|
+
- Small surface area: Vite 7 compatible, tree-shakeable ESM/CJS exports
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
```bash
|
|
14
|
+
pnpm add -D @gringow/gringow @gringow/gringow-vite
|
|
15
|
+
# npm install -D @gringow/gringow @gringow/gringow-vite
|
|
16
|
+
# yarn add -D @gringow/gringow @gringow/gringow-vite
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
Add the plugin to your Vite config and run Vite as usual. The plugin relies on the Gringow config file (`gringow.config.js` or similar) to know which files to scan.
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
// vite.config.ts
|
|
24
|
+
import { defineConfig } from 'vite'
|
|
25
|
+
import Gringow from '@gringow/gringow-vite'
|
|
26
|
+
|
|
27
|
+
export default defineConfig({
|
|
28
|
+
plugins: [Gringow({ debug: false })],
|
|
29
|
+
})
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
During development the plugin parses transformed modules, calculates cache IDs, and asks the Gringow core library to ensure translations exist. The generated cache lives at `./gringow/gringow.json` by default.
|
|
33
|
+
|
|
34
|
+
### Command line helpers
|
|
35
|
+
Run Vite with extra flags to control the cache lifecycle without leaving your workflow:
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
vite build --gringow=build # Scan all sources up front and build the cache
|
|
39
|
+
vite build --gringow=clear # Delete the cache file and exit
|
|
40
|
+
vite build --gringow=reset # Clear then rebuild the cache in one go
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
These commands exit after completing the requested action so they can be used in CI scripts.
|
|
44
|
+
|
|
45
|
+
## Configuration reference
|
|
46
|
+
- `debug?: boolean` (default `false`): log plugin options during startup for troubleshooting.
|
|
47
|
+
|
|
48
|
+
The plugin reads the Gringow workspace configuration to locate files:
|
|
49
|
+
- `globby`: glob pattern that determines which source files are scanned (defaults to `./src/**/*.{js,jsx,ts,tsx}`).
|
|
50
|
+
|
|
51
|
+
## How it works
|
|
52
|
+
- `transform`: checks each loaded module, finds `g\`...\`` usage, and seeds the translation cache via `@gringow/gringow`.
|
|
53
|
+
- `buildEnd`: prunes cache entries that no longer exist in source and backfills any new strings discovered by static scanning.
|
|
54
|
+
- `buildStart`: watches for the `--gringow=` flag to run cache maintenance chores outside of normal Vite flows.
|
|
55
|
+
|
|
56
|
+
## Development scripts
|
|
57
|
+
```bash
|
|
58
|
+
pnpm run build # Emit dist/ with tsup
|
|
59
|
+
pnpm run watch # Continuous rebuild for local development
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## License
|
|
63
|
+
MIT © Renato Gaspar
|
package/dist/index.d.mts
CHANGED
|
@@ -4,6 +4,6 @@ type GringowVitePluginOptions = {
|
|
|
4
4
|
debug?: boolean;
|
|
5
5
|
};
|
|
6
6
|
declare const localCache: Set<string>;
|
|
7
|
-
declare function GringowVitePlugin(options?: GringowVitePluginOptions): Plugin
|
|
7
|
+
declare function GringowVitePlugin(options?: GringowVitePluginOptions): Plugin<unknown>;
|
|
8
8
|
|
|
9
9
|
export { type GringowVitePluginOptions, GringowVitePlugin as default, localCache };
|
package/dist/index.mjs
CHANGED
|
@@ -53,8 +53,8 @@ function isSourceCode(filePath) {
|
|
|
53
53
|
|
|
54
54
|
// src/index.ts
|
|
55
55
|
var localCache = /* @__PURE__ */ new Set();
|
|
56
|
-
function GringowVitePlugin(options = {
|
|
57
|
-
const { debug } = options;
|
|
56
|
+
function GringowVitePlugin(options = {}) {
|
|
57
|
+
const { debug = false } = options;
|
|
58
58
|
if (debug) {
|
|
59
59
|
console.log("GringowVitePlugin, loaded with options:");
|
|
60
60
|
Object.keys(options).forEach((key) => {
|