Remove mock data files and consolidate into single mock module

Delete separate dev and prod mock files, create unified mock module with fullMockState and minimalState exports, and update store to select appropriate mock based on environment. Remove mock-data alias from Vite config.
This commit is contained in:
grove5_admin committed 2026-04-27 18:39:38 -07:00
1 parent 093d5b2a11
commit b4278523f2
4 files changed
+61 -73

No files matched your search

-46
View File
@@ -1,46 +0,0 @@
import type { CultivarState } from './types';
const NOW = Math.floor(Date.now() / 1000);
export const initialState: CultivarState = {
meta: {
device_id: '',
firmware_version: '',
uptime_s: 0,
wifi_rssi: 0,
timestamp_utc: NOW,
},
environment: {
history: [],
live: { temp_c: 0, rh_pct: 0, co2_ppm: 0, co2e_ppm: 0, voc_ppb: 0, vpd: 0 },
targets: { temp_c: 0, rh_pct: 0, co2_ppm: 0 },
alerts: [],
},
chambers: [],
hardware: {
fans: [],
humidifier: { active: false, mode: 'auto', reservoir_pct: 0 },
lights: [],
doors: [],
cameras: [],
},
recipe: {
id: '',
name: '',
species: '',
stage: 'inoculation',
stage_started_ts: 0,
stage_target_duration_h: 0,
stage_history: [],
next_actions: [],
},
maintenance: {
last_wipe_ts: 0,
last_reservoir_clean_ts: 0,
},
ui: {
scrubber_ts: null,
selected_bag_id: null,
onboarding_complete: false,
},
};
+46 -1
View File
@@ -72,7 +72,7 @@ const inoculatedF_A2 = NOW - 28 * HOUR * 24;
const inoculatedF_B2 = NOW - 20 * HOUR * 24;
const inoculatedF_C1 = NOW - 22 * HOUR * 24;
export const initialState: CultivarState = {
const fullMockState: CultivarState = {
meta: {
device_id: 'CVR-0042',
firmware_version: '0.9.4',
@@ -413,3 +413,48 @@ export const initialState: CultivarState = {
onboarding_complete: localStorage.getItem('onboarding_complete') === 'true',
},
};
const minimalState: CultivarState = {
meta: {
device_id: '',
firmware_version: '',
uptime_s: 0,
wifi_rssi: 0,
timestamp_utc: NOW,
},
environment: {
history: [],
live: { temp_c: 0, rh_pct: 0, co2_ppm: 0, co2e_ppm: 0, voc_ppb: 0, vpd: 0 },
targets: { temp_c: 0, rh_pct: 0, co2_ppm: 0 },
alerts: [],
},
chambers: [],
hardware: {
fans: [],
humidifier: { active: false, mode: 'auto', reservoir_pct: 0 },
lights: [],
doors: [],
cameras: [],
},
recipe: {
id: '',
name: '',
species: '',
stage: 'inoculation',
stage_started_ts: 0,
stage_target_duration_h: 0,
stage_history: [],
next_actions: [],
},
maintenance: {
last_wipe_ts: 0,
last_reservoir_clean_ts: 0,
},
ui: {
scrubber_ts: null,
selected_bag_id: null,
onboarding_complete: false,
},
};
export { fullMockState, minimalState };
+3 -1
View File
@@ -1,4 +1,4 @@
import { initialState } from '@mock-data';
import { fullMockState, minimalState } from './mock';
import type { CultivarState, EnvironmentReading, WsDiff } from './types';
function deepClone<T>(v: T): T {
@@ -6,6 +6,8 @@ function deepClone<T>(v: T): T {
}
function createStore() {
// @ts-ignore - Vite provides import.meta.env.DEV
const initialState = (import.meta as any).env?.DEV ? fullMockState : minimalState;
let state = $state<CultivarState>(deepClone(initialState));
// Mock WS diff interval
+12 -25
View File
@@ -1,31 +1,18 @@
import { svelte } from '@sveltejs/vite-plugin-svelte';
import { defineConfig } from 'vite';
import path from 'path';
import { fileURLToPath } from 'url';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
export default defineConfig(({ mode }) => {
const mockFile = mode === 'development' ? './src/lib/mock.dev.ts' : './src/lib/mock.prod.ts';
return {
plugins: [svelte()],
// Svelte convention — serve /static/* at the web root (fonts, img, etc.)
publicDir: 'static',
resolve: {
alias: {
'@mock-data': path.resolve(__dirname, mockFile),
},
},
build: {
outDir: 'dist',
target: 'es2020',
cssCodeSplit: false,
rollupOptions: {
output: {
manualChunks: undefined,
}
export default defineConfig({
plugins: [svelte()],
// Svelte convention — serve /static/* at the web root (fonts, img, etc.)
publicDir: 'static',
build: {
outDir: 'dist',
target: 'es2020',
cssCodeSplit: false,
rollupOptions: {
output: {
manualChunks: undefined,
}
}
};
}
});