vite-plugin-fvtt 0.1.1 → 0.1.2
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/index.js +40 -28
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import fs from "fs-extra";
|
|
2
2
|
import posix from "path/posix";
|
|
3
3
|
import dotenv from "dotenv";
|
|
4
|
-
import {
|
|
4
|
+
import { globSync } from "tinyglobby";
|
|
5
5
|
import { Server } from "socket.io";
|
|
6
6
|
import { io } from "socket.io-client";
|
|
7
7
|
|
|
@@ -22,28 +22,6 @@ function loadEnv() {
|
|
|
22
22
|
};
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
//#endregion
|
|
26
|
-
//#region src/config/foundryvtt-manifest.ts
|
|
27
|
-
function loadManifest(config) {
|
|
28
|
-
if (context?.manifest) return context.manifest;
|
|
29
|
-
const publicDir = config.publicDir || "public";
|
|
30
|
-
const MANIFEST_LOCATIONS = [
|
|
31
|
-
"system.json",
|
|
32
|
-
"module.json",
|
|
33
|
-
`${publicDir}/system.json`,
|
|
34
|
-
`${publicDir}/module.json`
|
|
35
|
-
];
|
|
36
|
-
const foundPath = MANIFEST_LOCATIONS.map((relPath) => posix.resolve(process.cwd(), relPath)).find((absPath) => fs.pathExistsSync(absPath));
|
|
37
|
-
if (!foundPath) throw new Error(`Could not find a manifest file (system.json or module.json) in project root or ${publicDir}/.`);
|
|
38
|
-
try {
|
|
39
|
-
const data = fs.readJsonSync(foundPath);
|
|
40
|
-
data.manifestType = foundPath.includes("module.json") ? "module" : "system";
|
|
41
|
-
return data;
|
|
42
|
-
} catch (err) {
|
|
43
|
-
throw new Error(`Failed to read manifest at ${foundPath}: ${err?.message || err}`);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
25
|
//#endregion
|
|
48
26
|
//#region src/utils/logger.ts
|
|
49
27
|
var Logger = class {
|
|
@@ -53,7 +31,7 @@ var Logger = class {
|
|
|
53
31
|
warn: "\x1B[33m",
|
|
54
32
|
error: "\x1B[31m"
|
|
55
33
|
};
|
|
56
|
-
constructor({ namespace = "vite-plugin-
|
|
34
|
+
constructor({ namespace = "vite-plugin-fvtt" } = {}) {
|
|
57
35
|
this.namespace = namespace;
|
|
58
36
|
}
|
|
59
37
|
format(level, message) {
|
|
@@ -77,6 +55,40 @@ var Logger = class {
|
|
|
77
55
|
};
|
|
78
56
|
var logger_default = new Logger();
|
|
79
57
|
|
|
58
|
+
//#endregion
|
|
59
|
+
//#region src/config/foundryvtt-manifest.ts
|
|
60
|
+
function loadManifest(config) {
|
|
61
|
+
if (context?.manifest) return context.manifest;
|
|
62
|
+
const publicDir = config.publicDir || "public";
|
|
63
|
+
const MANIFEST_LOCATIONS = [
|
|
64
|
+
"system.json",
|
|
65
|
+
"module.json",
|
|
66
|
+
`${publicDir}/system.json`,
|
|
67
|
+
`${publicDir}/module.json`
|
|
68
|
+
];
|
|
69
|
+
const foundPath = MANIFEST_LOCATIONS.map((relPath) => posix.resolve(process.cwd(), relPath)).find((absPath) => fs.pathExistsSync(absPath));
|
|
70
|
+
if (!foundPath) logger_default.fail(`Could not find a manifest file (system.json or module.json) in project root or ${publicDir}/.`);
|
|
71
|
+
try {
|
|
72
|
+
const data = fs.readJsonSync(foundPath);
|
|
73
|
+
if (!data.id || typeof data.id !== "string") logger_default.fail(`Manifest at ${foundPath} is missing required "id" field.`);
|
|
74
|
+
const hasEsmodules = Array.isArray(data.esmodules) && data.esmodules.length > 0;
|
|
75
|
+
const hasScripts = Array.isArray(data.scripts) && data.scripts.length > 0;
|
|
76
|
+
if (hasEsmodules === hasScripts) logger_default.fail(`Manifest at ${foundPath} must define exactly one of "esmodules" or "scripts".`);
|
|
77
|
+
const result = {
|
|
78
|
+
manifestType: foundPath.includes("module.json") ? "module" : "system",
|
|
79
|
+
id: data.id,
|
|
80
|
+
esmodules: Array.isArray(data.esmodules) ? data.esmodules : [],
|
|
81
|
+
scripts: Array.isArray(data.scripts) ? data.scripts : [],
|
|
82
|
+
styles: Array.isArray(data.styles) ? data.styles : [],
|
|
83
|
+
languages: Array.isArray(data.languages) ? data.languages : [],
|
|
84
|
+
packs: Array.isArray(data.packs) ? data.packs : []
|
|
85
|
+
};
|
|
86
|
+
return result;
|
|
87
|
+
} catch (err) {
|
|
88
|
+
logger_default.fail(`Failed to read manifest at ${foundPath}: ${err?.message || err}`);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
80
92
|
//#endregion
|
|
81
93
|
//#region src/config/vite-options.ts
|
|
82
94
|
function createPartialViteConfig(config) {
|
|
@@ -86,7 +98,7 @@ function createPartialViteConfig(config) {
|
|
|
86
98
|
const fileName = (useEsModules ? context.manifest?.esmodules[0] : context.manifest?.scripts?.[0]) ?? "bundle";
|
|
87
99
|
if (fileName === "bundle") logger_default.warn("No output file specified in manifest, using default \"bundle\"");
|
|
88
100
|
if (!context.manifest?.styles?.length) logger_default.warn("No CSS file found in manifest");
|
|
89
|
-
const cssFileName = posix.parse(context.manifest?.styles[0] ?? "").name;
|
|
101
|
+
const cssFileName = posix.parse(context.manifest?.styles[0] ?? "bundle.css").name;
|
|
90
102
|
const foundryPort = context.env?.foundryPort ?? 3e4;
|
|
91
103
|
const foundryUrl = context.env?.foundryUrl ?? "localhost";
|
|
92
104
|
const entry = (config.build?.lib)?.entry;
|
|
@@ -330,7 +342,7 @@ function getLocalLanguageFiles(lang, outDir = false) {
|
|
|
330
342
|
logger_default.warn(`No language folder found at: ${sourcePath}`);
|
|
331
343
|
return [];
|
|
332
344
|
}
|
|
333
|
-
return
|
|
345
|
+
return globSync(posix.join(sourcePath, "**/*.json"));
|
|
334
346
|
}
|
|
335
347
|
function loadLanguage(lang, outDir = false) {
|
|
336
348
|
const files = getLocalLanguageFiles(lang, outDir);
|
|
@@ -486,9 +498,9 @@ function validator() {
|
|
|
486
498
|
function foundryVTTPlugin() {
|
|
487
499
|
context.env = loadEnv();
|
|
488
500
|
return {
|
|
489
|
-
name: "vite-plugin-
|
|
501
|
+
name: "vite-plugin-fvtt",
|
|
490
502
|
config(config) {
|
|
491
|
-
context.manifest = loadManifest(config);
|
|
503
|
+
context.manifest = loadManifest(config) ?? void 0;
|
|
492
504
|
return createPartialViteConfig(config);
|
|
493
505
|
},
|
|
494
506
|
configResolved(config) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-plugin-fvtt",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "A Vite plugin for module and system development for Foundry VTT",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"vite",
|
|
@@ -43,9 +43,9 @@
|
|
|
43
43
|
"dependencies": {
|
|
44
44
|
"dotenv": "^17.2.1",
|
|
45
45
|
"fs-extra": "^11.3.1",
|
|
46
|
-
"glob": "^11.0.3",
|
|
47
46
|
"socket.io": "^4.8.1",
|
|
48
|
-
"socket.io-client": "^4.8.1"
|
|
47
|
+
"socket.io-client": "^4.8.1",
|
|
48
|
+
"tinyglobby": "^0.2.14"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
51
|
"vite": "^7.0.0"
|