Skip to content

Commit

Permalink
chore: Include changelog in module.
Browse files Browse the repository at this point in the history
  • Loading branch information
xdy committed Dec 18, 2023
1 parent d536fc4 commit fa4479f
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 46 deletions.
44 changes: 33 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"@types/jquery": "^3.5.29",
"@types/jsdom": "^21.1.6",
"@types/luxon": "^3.3.7",
"@types/node": "^18.19.3",
"@types/node": "20.10.4",
"@types/prompts": "^2.4.9",
"@types/sortablejs": "^1.15.7",
"@types/tooltipster": "^0.0.35",
Expand Down Expand Up @@ -72,7 +72,7 @@
"typescript": "^5.3.3",
"vite": "^5.0.10",
"vite-plugin-checker": "^0.6.2",
"vite-plugin-static-copy": "^0.17.1",
"vite-plugin-static-copy": "^1.0.0",
"vite-tsconfig-paths": "^4.2.2",
"yargs": "^17.7.2"
},
Expand All @@ -88,7 +88,8 @@
"prosemirror-transform": "^1.8.0",
"prosemirror-view": "^1.32.6",
"remeda": "^1.30.0",
"sortablejs": "^1.15.1"
"sortablejs": "^1.15.1",
"uuid": "^9.0.1"
},
"homepage": "https://github.com/xdy/xdy-pf2e-workbench",
"repository": {
Expand Down
7 changes: 4 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
"dom.iterable",
"esnext"
],
"module": "nodenext",
"moduleResolution": "nodenext",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"noEmit": true,
"noErrorTruncation": true,
"noFallthroughCasesInSwitch": true,
"noImplicitOverride": true,
"noImplicitReturns": true,
Expand Down Expand Up @@ -64,7 +65,7 @@
"strictFunctionTypes": false,
"strictNullChecks": true,
"strictPropertyInitialization": true,
"target": "es2022",
"target": "ES2022",
"typeRoots": [
"node_modules/@types",
"types/types/foundry"
Expand Down
81 changes: 52 additions & 29 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import esbuild from "esbuild";
import fs from "fs-extra";
import path from "path";
import * as Vite from "vite";
import tsconfigPaths from "vite-tsconfig-paths";
// eslint-disable-next-line import/default
import checker from "vite-plugin-checker";
import path from "path";
import packageJSON from "./package.json";
import esbuild from "esbuild";
import { viteStaticCopy } from "vite-plugin-static-copy";
import tsconfigPaths from "vite-tsconfig-paths";
import packageJSON from "./package.json" assert { type: "json" };

const EN_JSON = JSON.parse(fs.readFileSync("./static/lang/en.json", { encoding: "utf-8" }));

const config = Vite.defineConfig(({ command, mode }): Vite.UserConfig => {
const buildMode = mode === "production" ? "production" : "development";
Expand All @@ -16,23 +18,31 @@ const config = Vite.defineConfig(({ command, mode }): Vite.UserConfig => {
// "Note the build.minify option does not minify whitespaces when using the 'es' format in lib mode, as it removes
// pure annotations and breaks tree-shaking."
if (buildMode === "production") {
plugins.push({
name: "minify",
renderChunk: {
order: "post",
async handler(code, chunk) {
return chunk.fileName.endsWith(".mjs")
? esbuild.transform(code, {
keepNames: true,
minifyIdentifiers: false,
minifySyntax: true,
minifyWhitespace: true,
sourcemap: true,
})
: code;
plugins.push(
{
name: "minify",
renderChunk: {
order: "post",
async handler(code, chunk) {
return chunk.fileName.endsWith(".mjs")
? esbuild.transform(code, {
keepNames: true,
minifyIdentifiers: false,
minifySyntax: true,
minifyWhitespace: true,
sourcemap: true,
})
: code;
},
},
},
});
...viteStaticCopy({
targets: [
{ src: "CHANGELOG.md", dest: "." },
{ src: "README.md", dest: "." },
],
}),
);
} else {
plugins.push(
// Foundry expects all esm files listed in system.json to exist: create empty vendor module when in dev mode
Expand All @@ -50,9 +60,21 @@ const config = Vite.defineConfig(({ command, mode }): Vite.UserConfig => {
name: "hmr-handler",
apply: "serve",
handleHotUpdate(context) {
if (context.file.endsWith(".hbs") && !context.file.startsWith(outDir)) {
if (context.file.startsWith(outDir)) return;

if (context.file.endsWith("en.json")) {
const basePath = context.file.slice(context.file.indexOf("lang/"));
console.log(`Updating lang file at ${basePath}`);
fs.promises.copyFile(context.file, `${outDir}/${basePath}`).then(() => {
context.server.ws.send({
type: "custom",
event: "lang-update",
data: { path: `modules/xdy-pf2e-workbench/${basePath}` },
});
});
} else if (context.file.endsWith(".hbs")) {
const basePath = context.file.slice(context.file.indexOf("templates/"));
console.log(`Updating template at ${basePath}`);
console.log(`Updating template file at ${basePath}`);
fs.promises.copyFile(context.file, `${outDir}/${basePath}`).then(() => {
context.server.ws.send({
type: "custom",
Expand All @@ -62,7 +84,7 @@ const config = Vite.defineConfig(({ command, mode }): Vite.UserConfig => {
});
}
},
}
},
);
}

Expand All @@ -71,22 +93,23 @@ const config = Vite.defineConfig(({ command, mode }): Vite.UserConfig => {
const message = "This file is for a running vite dev server and is not copied to a build";
fs.writeFileSync("./index.html", `<h1>${message}</h1>\n`);
if (!fs.existsSync("./styles")) fs.mkdirSync("./styles");
fs.writeFileSync("./xdy-pf2e-workbench.css", `/** ${message} */\n`);
fs.writeFileSync("./xdy-pf2e-workbench", `/** ${message} */\n\nimport "./src/xdy-pf2e-workbench.ts";\n`);
fs.writeFileSync("./styles/xdy-pf2e-workbench.css", `/** ${message} */\n`);
fs.writeFileSync("./xdy-pf2e-workbench.mjs", `/** ${message} */\n\nimport "./src/xdy-pf2e-workbench.ts";\n`);
fs.writeFileSync("./vendor.mjs", `/** ${message} */\n`);
}

return {
root: "./",
base: command === "build" ? "./" : "/modules/xdy-pf2e-workbench/",
publicDir: "static",
define: {
BUILD_MODE: JSON.stringify(buildMode),
EN_JSON: JSON.stringify(EN_JSON),
fu: "foundry.utils",
},
esbuild: { keepNames: true },
build: {
outDir,
emptyOutDir: false, //build-packs.ts handles this
emptyOutDir: false, // fails if world is running due to compendium locks. We do it in "npm run clean" instead.
minify: false,
sourcemap: true,
lib: {
Expand All @@ -97,8 +120,7 @@ const config = Vite.defineConfig(({ command, mode }): Vite.UserConfig => {
},
rollupOptions: {
output: {
assetFileNames: ({ name }): string =>
name === "style.css" ? "styles/xdy-pf2e-workbench.css" : name!,
assetFileNames: ({ name }): string => (name === "style.css" ? "styles/xdy-pf2e-workbench.css" : name ?? ""),
chunkFileNames: "[name].mjs",
entryFileNames: "xdy-pf2e-workbench.mjs",
manualChunks: {
Expand All @@ -107,6 +129,7 @@ const config = Vite.defineConfig(({ command, mode }): Vite.UserConfig => {
},
watch: { buildDelay: 100 },
},
target: "es2022",
},
server: {
port: 30001,
Expand Down

0 comments on commit fa4479f

Please sign in to comment.