@lukasss93/larex-watcher 1.0.0
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/vite.cjs +108 -0
- package/dist/vite.d.cts +25 -0
- package/dist/vite.d.ts +25 -0
- package/dist/vite.js +77 -0
- package/package.json +38 -0
package/dist/vite.cjs
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/vite.ts
|
|
31
|
+
var vite_exports = {};
|
|
32
|
+
__export(vite_exports, {
|
|
33
|
+
default: () => larex
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(vite_exports);
|
|
36
|
+
var import_path = __toESM(require("path"), 1);
|
|
37
|
+
var import_fs = __toESM(require("fs"), 1);
|
|
38
|
+
var import_node_child_process = require("child_process");
|
|
39
|
+
var import_node_util = require("util");
|
|
40
|
+
function larex(options) {
|
|
41
|
+
const targetPath = options?.path || "lang/localization.csv";
|
|
42
|
+
const command = options?.command || "composer run larex";
|
|
43
|
+
const runOnBuild = options?.build || true;
|
|
44
|
+
const runOnDev = options?.dev || true;
|
|
45
|
+
let fileWatcher = null;
|
|
46
|
+
let debounceTimer = null;
|
|
47
|
+
let isBuild = false;
|
|
48
|
+
return {
|
|
49
|
+
name: "larex-watcher",
|
|
50
|
+
config: (config, env) => {
|
|
51
|
+
isBuild = env.command === "build";
|
|
52
|
+
return {
|
|
53
|
+
server: {
|
|
54
|
+
watch: {
|
|
55
|
+
ignored: [
|
|
56
|
+
"**/lang/**/*.php",
|
|
57
|
+
"**/resources/lang/**/*.php",
|
|
58
|
+
"**/" + targetPath
|
|
59
|
+
]
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
},
|
|
64
|
+
buildStart() {
|
|
65
|
+
if (!isBuild || !runOnBuild) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
console.log((0, import_node_util.styleText)(["bold", "cyan"], "[larex] ") + (0, import_node_util.styleText)("yellow", "Updating localization files..."));
|
|
69
|
+
(0, import_node_child_process.execSync)(command);
|
|
70
|
+
console.log((0, import_node_util.styleText)(["bold", "cyan"], "[larex] ") + (0, import_node_util.styleText)("green", "Localization files updated successfully!"));
|
|
71
|
+
},
|
|
72
|
+
configureServer(server) {
|
|
73
|
+
if (!runOnDev) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
const targetFile = import_path.default.resolve(process.cwd(), targetPath);
|
|
77
|
+
try {
|
|
78
|
+
fileWatcher = import_fs.default.watch(targetFile, { persistent: true }, (eventType) => {
|
|
79
|
+
if (eventType !== "change") {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
if (debounceTimer) {
|
|
83
|
+
clearTimeout(debounceTimer);
|
|
84
|
+
}
|
|
85
|
+
debounceTimer = setTimeout(() => {
|
|
86
|
+
console.log("");
|
|
87
|
+
console.log((0, import_node_util.styleText)(["bold", "cyan"], "[larex] ") + (0, import_node_util.styleText)("yellow", "Updating localization files..."));
|
|
88
|
+
(0, import_node_child_process.exec)(command, (err, stdout, stderr) => {
|
|
89
|
+
if (err) {
|
|
90
|
+
console.error("Larex failed:", err, stderr);
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
console.log((0, import_node_util.styleText)(["bold", "cyan"], "[larex] ") + (0, import_node_util.styleText)("green", "Localization files updated successfully!"));
|
|
94
|
+
console.log("");
|
|
95
|
+
server.moduleGraph.invalidateAll();
|
|
96
|
+
server.ws.send({ type: "full-reload" });
|
|
97
|
+
});
|
|
98
|
+
}, 200);
|
|
99
|
+
});
|
|
100
|
+
} catch (e) {
|
|
101
|
+
console.error("Failed to watch localization file:", e);
|
|
102
|
+
}
|
|
103
|
+
server.httpServer?.once("close", () => {
|
|
104
|
+
fileWatcher?.close();
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
}
|
package/dist/vite.d.cts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { UserConfig, ViteDevServer } from 'vite';
|
|
2
|
+
|
|
3
|
+
interface PluginConfig {
|
|
4
|
+
path: string;
|
|
5
|
+
command: string;
|
|
6
|
+
build: boolean;
|
|
7
|
+
dev: boolean;
|
|
8
|
+
}
|
|
9
|
+
declare function larex(options?: PluginConfig): {
|
|
10
|
+
name: string;
|
|
11
|
+
config: (config: UserConfig, env: {
|
|
12
|
+
mode: string;
|
|
13
|
+
command: string;
|
|
14
|
+
}) => {
|
|
15
|
+
server: {
|
|
16
|
+
watch: {
|
|
17
|
+
ignored: string[];
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
buildStart(): void;
|
|
22
|
+
configureServer(server: ViteDevServer): void;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export { larex as default };
|
package/dist/vite.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { UserConfig, ViteDevServer } from 'vite';
|
|
2
|
+
|
|
3
|
+
interface PluginConfig {
|
|
4
|
+
path: string;
|
|
5
|
+
command: string;
|
|
6
|
+
build: boolean;
|
|
7
|
+
dev: boolean;
|
|
8
|
+
}
|
|
9
|
+
declare function larex(options?: PluginConfig): {
|
|
10
|
+
name: string;
|
|
11
|
+
config: (config: UserConfig, env: {
|
|
12
|
+
mode: string;
|
|
13
|
+
command: string;
|
|
14
|
+
}) => {
|
|
15
|
+
server: {
|
|
16
|
+
watch: {
|
|
17
|
+
ignored: string[];
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
buildStart(): void;
|
|
22
|
+
configureServer(server: ViteDevServer): void;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export { larex as default };
|
package/dist/vite.js
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
// src/vite.ts
|
|
2
|
+
import path from "path";
|
|
3
|
+
import fs from "fs";
|
|
4
|
+
import { exec, execSync } from "child_process";
|
|
5
|
+
import { styleText } from "util";
|
|
6
|
+
function larex(options) {
|
|
7
|
+
const targetPath = options?.path || "lang/localization.csv";
|
|
8
|
+
const command = options?.command || "composer run larex";
|
|
9
|
+
const runOnBuild = options?.build || true;
|
|
10
|
+
const runOnDev = options?.dev || true;
|
|
11
|
+
let fileWatcher = null;
|
|
12
|
+
let debounceTimer = null;
|
|
13
|
+
let isBuild = false;
|
|
14
|
+
return {
|
|
15
|
+
name: "larex-watcher",
|
|
16
|
+
config: (config, env) => {
|
|
17
|
+
isBuild = env.command === "build";
|
|
18
|
+
return {
|
|
19
|
+
server: {
|
|
20
|
+
watch: {
|
|
21
|
+
ignored: [
|
|
22
|
+
"**/lang/**/*.php",
|
|
23
|
+
"**/resources/lang/**/*.php",
|
|
24
|
+
"**/" + targetPath
|
|
25
|
+
]
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
},
|
|
30
|
+
buildStart() {
|
|
31
|
+
if (!isBuild || !runOnBuild) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
console.log(styleText(["bold", "cyan"], "[larex] ") + styleText("yellow", "Updating localization files..."));
|
|
35
|
+
execSync(command);
|
|
36
|
+
console.log(styleText(["bold", "cyan"], "[larex] ") + styleText("green", "Localization files updated successfully!"));
|
|
37
|
+
},
|
|
38
|
+
configureServer(server) {
|
|
39
|
+
if (!runOnDev) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const targetFile = path.resolve(process.cwd(), targetPath);
|
|
43
|
+
try {
|
|
44
|
+
fileWatcher = fs.watch(targetFile, { persistent: true }, (eventType) => {
|
|
45
|
+
if (eventType !== "change") {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
if (debounceTimer) {
|
|
49
|
+
clearTimeout(debounceTimer);
|
|
50
|
+
}
|
|
51
|
+
debounceTimer = setTimeout(() => {
|
|
52
|
+
console.log("");
|
|
53
|
+
console.log(styleText(["bold", "cyan"], "[larex] ") + styleText("yellow", "Updating localization files..."));
|
|
54
|
+
exec(command, (err, stdout, stderr) => {
|
|
55
|
+
if (err) {
|
|
56
|
+
console.error("Larex failed:", err, stderr);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
console.log(styleText(["bold", "cyan"], "[larex] ") + styleText("green", "Localization files updated successfully!"));
|
|
60
|
+
console.log("");
|
|
61
|
+
server.moduleGraph.invalidateAll();
|
|
62
|
+
server.ws.send({ type: "full-reload" });
|
|
63
|
+
});
|
|
64
|
+
}, 200);
|
|
65
|
+
});
|
|
66
|
+
} catch (e) {
|
|
67
|
+
console.error("Failed to watch localization file:", e);
|
|
68
|
+
}
|
|
69
|
+
server.httpServer?.once("close", () => {
|
|
70
|
+
fileWatcher?.close();
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
export {
|
|
76
|
+
larex as default
|
|
77
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@lukasss93/larex-watcher",
|
|
3
|
+
"description": "Laravel Larex Watcher for Vite",
|
|
4
|
+
"version": "1.0.0",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/Lukasss93/larex-watcher.git"
|
|
8
|
+
},
|
|
9
|
+
"author": "Luca Patera",
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/Lukasss93/larex-watcher/issues"
|
|
13
|
+
},
|
|
14
|
+
"homepage": "https://github.com/Lukasss93/larex-watcher#readme",
|
|
15
|
+
"main": "index.js",
|
|
16
|
+
"type": "module",
|
|
17
|
+
"files": [
|
|
18
|
+
"dist/"
|
|
19
|
+
],
|
|
20
|
+
"typesVersions": {
|
|
21
|
+
"*": {
|
|
22
|
+
"vite": [
|
|
23
|
+
"dist/vite.d.ts"
|
|
24
|
+
]
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"scripts": {
|
|
28
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
29
|
+
"prepublishOnly": "tsup ./src --external virtual-laravel-translations,vue --format cjs,esm --dts"
|
|
30
|
+
},
|
|
31
|
+
"keywords": [],
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@types/node": "^25.2.2",
|
|
34
|
+
"tsup": "^8.5.1",
|
|
35
|
+
"typescript": "^5.9.3",
|
|
36
|
+
"vite": "^7.3.1"
|
|
37
|
+
}
|
|
38
|
+
}
|