Simplify package.json build and start scripts

Move reading readme and versions out of package.json
This commit is contained in:
Przemek Więch
2026-04-29 00:11:06 +02:00
parent 70982305ce
commit d39143e21d
4 changed files with 22 additions and 7 deletions

View File

@@ -83,12 +83,8 @@
"vite-tsconfig-paths": "^5.1.4" "vite-tsconfig-paths": "^5.1.4"
}, },
"scripts": { "scripts": {
"start": "run-script-os", "start": "vite",
"start:default": "GENERATE_SOURCEMAP=false VITE_CHANGELOG=`cat CHANGELOG.md` VITE_GIT_SHA=`git rev-parse --short HEAD` VITE_GIT_TIME=`git log -1 --format=%ci` vite", "build": "tsc && vite build",
"start:windows": "powershell -Command \"Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser; $env:GENERATE_SOURCEMAP='false'; $env:VITE_CHANGELOG = Get-Content -Path \"CHANGELOG.md\" -Raw; $env:VITE_GIT_SHA=$(git rev-parse --short HEAD); $env:VITE_GIT_TIME=$(git log -1 --format='%ci'); vite\"",
"build": "run-script-os",
"build:default": "tsc && GENERATE_SOURCEMAP=false VITE_CHANGELOG=`cat CHANGELOG.md` VITE_GIT_SHA=`git rev-parse --short HEAD` VITE_GIT_TIME=`git log -1 --format=%ci` vite build",
"build:windows": "powershell -Command \"Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser; tsc; if ($?) { $env:GENERATE_SOURCEMAP='false'; $env:VITE_CHANGELOG = Get-Content -Path \"CHANGELOG.md\" -Raw; $env:VITE_GIT_SHA=$(git rev-parse --short HEAD); $env:VITE_GIT_TIME=$(git log -1 --format='%ci'); vite build }",
"test": "jest", "test": "jest",
"prettier": "prettier --write \"src/**/*.{ts,tsx,json}\"", "prettier": "prettier --write \"src/**/*.{ts,tsx,json}\"",
"lint": "eslint src --ext .ts,.tsx", "lint": "eslint src --ext .ts,.tsx",

View File

@@ -5,6 +5,7 @@ import remarkParse from 'remark-parse';
import remarkRehype from 'remark-rehype'; import remarkRehype from 'remark-rehype';
import {Button, Header, Modal} from 'semantic-ui-react'; import {Button, Header, Modal} from 'semantic-ui-react';
import {unified} from 'unified'; import {unified} from 'unified';
import changelog from '../CHANGELOG.md?raw';
const LAST_SEEN_VERSION_KEY = 'last_seen_version'; const LAST_SEEN_VERSION_KEY = 'last_seen_version';
@@ -19,7 +20,6 @@ export async function getChangelog(maxVersions: number, seenVersion?: string) {
? Date.parse(seenVersion.slice(0, 10)) ? Date.parse(seenVersion.slice(0, 10))
: 0; : 0;
const changelog = import.meta.env.VITE_CHANGELOG as string;
const changes = const changes =
changelog changelog
.split('##') .split('##')

5
src/imports.d.ts vendored
View File

@@ -1,2 +1,7 @@
declare module '*.jpg'; declare module '*.jpg';
declare module '*.png'; declare module '*.png';
declare module '*?raw' {
const content: string;
export default content;
}

View File

@@ -2,10 +2,24 @@ import {defineConfig} from 'vite';
import {resolve} from 'path'; import {resolve} from 'path';
import react from '@vitejs/plugin-react'; import react from '@vitejs/plugin-react';
import viteTsconfigPaths from 'vite-tsconfig-paths'; import viteTsconfigPaths from 'vite-tsconfig-paths';
import {execSync} from 'child_process';
let gitSha = '';
let gitTime = '';
try {
gitSha = execSync('git rev-parse --short HEAD').toString().trim();
gitTime = execSync('git log -1 --format=%ci').toString().trim();
} catch (e) {
console.error('Failed to get git info', e);
}
export default defineConfig({ export default defineConfig({
// depending on your application, base can also be "/" // depending on your application, base can also be "/"
base: '', base: '',
define: {
'import.meta.env.VITE_GIT_SHA': JSON.stringify(gitSha),
'import.meta.env.VITE_GIT_TIME': JSON.stringify(gitTime),
},
plugins: [ plugins: [
react(), react(),
viteTsconfigPaths(), viteTsconfigPaths(),