diff --git a/apps/stage-pocket/package.json b/apps/stage-pocket/package.json index 02ceb8b14..6c2caeeff 100644 --- a/apps/stage-pocket/package.json +++ b/apps/stage-pocket/package.json @@ -37,6 +37,7 @@ "@proj-airi/pipelines-audio": "workspace:^", "@proj-airi/server-sdk": "workspace:^", "@proj-airi/stage-layouts": "workspace:^", + "@proj-airi/stage-shared": "workspace:^", "@proj-airi/stage-ui": "workspace:^", "@proj-airi/stage-ui-three": "workspace:^", "@proj-airi/stage-ui-three-performance-runtime": "workspace:^", diff --git a/apps/stage-pocket/src/main.ts b/apps/stage-pocket/src/main.ts index 0a4d6602a..eed612f0a 100644 --- a/apps/stage-pocket/src/main.ts +++ b/apps/stage-pocket/src/main.ts @@ -5,6 +5,7 @@ import Tres from '@tresjs/core' import NProgress from 'nprogress' import { autoAnimatePlugin } from '@formkit/auto-animate/vue' +import { isEnvTruthy } from '@proj-airi/stage-shared' import { MotionPlugin } from '@vueuse/motion' import { createPinia } from 'pinia' import { setupLayouts } from 'virtual:generated-layouts' @@ -17,8 +18,6 @@ import App from './App.vue' import { i18n } from './modules/i18n' import './modules/posthog' - -// eslint-disable-next-line perfectionist/sort-imports import '@proj-airi/font-cjkfonts-allseto/index.css' import '@proj-airi/font-xiaolai/index.css' import '@unocss/reset/tailwind.css' @@ -33,7 +32,7 @@ const pinia = createPinia() const routeRecords = setupLayouts(routes as RouteRecordRaw[]) let router: Router -if (import.meta.env.VITE_APP_TARGET_HUGGINGFACE_SPACE) +if (isEnvTruthy(import.meta.env.VITE_APP_TARGET_HUGGINGFACE_SPACE)) router = createRouter({ routes: routeRecords, history: createWebHashHistory() }) else router = createRouter({ routes: routeRecords, history: createWebHistory() }) diff --git a/apps/stage-pocket/vite.config.ts b/apps/stage-pocket/vite.config.ts index 112ab592e..662b38677 100644 --- a/apps/stage-pocket/vite.config.ts +++ b/apps/stage-pocket/vite.config.ts @@ -18,6 +18,7 @@ import VueDevTools from 'vite-plugin-vue-devtools' import Layouts from 'vite-plugin-vue-layouts' import VueMacros from 'vue-macros/vite' +import { isEnvTruthy } from '@proj-airi/stage-shared' import { Download } from '@proj-airi/unplugin-fetch/vite' import { DownloadLive2DSDK } from '@proj-airi/unplugin-live2d-sdk/vite' import { templateCompilerOptions } from '@tresjs/core' @@ -88,7 +89,7 @@ export default defineConfig({ }, plugins: [ - .../^1|true|yes$/i.test(process.env.VITE_SKIP_MKCERT ?? '') ? [] : [mkcert()], + ...isEnvTruthy(process.env.VITE_SKIP_MKCERT ?? '') ? [] : [mkcert()], Info(), @@ -145,7 +146,7 @@ export default defineConfig({ Download('https://dist.ayaka.moe/vrm-models/VRoid-Hub/AvatarSample-A/AvatarSample_A.vrm', 'AvatarSample_A.vrm', 'vrm/models/AvatarSample-A', { parentDir: stageUIAssetsRoot, cacheDir: sharedCacheDir }), Download('https://dist.ayaka.moe/vrm-models/VRoid-Hub/AvatarSample-B/AvatarSample_B.vrm', 'AvatarSample_B.vrm', 'vrm/models/AvatarSample-B', { parentDir: stageUIAssetsRoot, cacheDir: sharedCacheDir }), - .../^1|true|yes$/i.test(process.env.VITE_CAP_SYNC_IOS_AFTER_BUILD ?? '') + ...isEnvTruthy(process.env.VITE_CAP_SYNC_IOS_AFTER_BUILD ?? '') ? [{ name: 'proj-airi:capacitor-sync', closeBundle: { diff --git a/apps/stage-web/src/main.ts b/apps/stage-web/src/main.ts index 8dfe58c12..b7f7490d3 100644 --- a/apps/stage-web/src/main.ts +++ b/apps/stage-web/src/main.ts @@ -5,6 +5,7 @@ import Tres from '@tresjs/core' import NProgress from 'nprogress' import { autoAnimatePlugin } from '@formkit/auto-animate/vue' +import { isEnvTruthy } from '@proj-airi/stage-shared' import { MotionPlugin } from '@vueuse/motion' import { createPinia } from 'pinia' import { setupLayouts } from 'virtual:generated-layouts' @@ -17,8 +18,6 @@ import App from './App.vue' import { i18n } from './modules/i18n' import './modules/posthog' - -// eslint-disable-next-line perfectionist/sort-imports import '@proj-airi/font-cjkfonts-allseto/index.css' import '@proj-airi/font-xiaolai/index.css' import '@unocss/reset/tailwind.css' @@ -33,7 +32,7 @@ const pinia = createPinia() const routeRecords = setupLayouts(routes as RouteRecordRaw[]) let router: Router -if (import.meta.env.VITE_APP_TARGET_HUGGINGFACE_SPACE) +if (isEnvTruthy(import.meta.env.VITE_APP_TARGET_HUGGINGFACE_SPACE)) router = createRouter({ routes: routeRecords, history: createWebHashHistory() }) else router = createRouter({ routes: routeRecords, history: createWebHistory() }) diff --git a/apps/stage-web/src/stores/pwa.ts b/apps/stage-web/src/stores/pwa.ts index 6f47a9965..c7032e9e1 100644 --- a/apps/stage-web/src/stores/pwa.ts +++ b/apps/stage-web/src/stores/pwa.ts @@ -1,3 +1,4 @@ +import { isEnvTruthy } from '@proj-airi/stage-shared' import { ToasterPWAUpdateReady } from '@proj-airi/stage-ui/components' import { breakpointsTailwind, useBreakpoints } from '@vueuse/core' import { nanoid } from 'nanoid' @@ -14,7 +15,7 @@ export const usePWAStore = defineStore('pwa', () => { if (import.meta.env.SSR) { return } - if (import.meta.env.VITE_APP_TARGET_HUGGINGFACE_SPACE) { + if (isEnvTruthy(import.meta.env.VITE_APP_TARGET_HUGGINGFACE_SPACE)) { return } diff --git a/packages/stage-shared/src/env-vars.ts b/packages/stage-shared/src/env-vars.ts new file mode 100644 index 000000000..dd856c57b --- /dev/null +++ b/packages/stage-shared/src/env-vars.ts @@ -0,0 +1,10 @@ +/** + * Returns true if the provided environment variable represents a truthy value. + * + * Truthy values: `true`, `t`, `yes`, `y`, `on`, `1` + */ +export function isEnvTruthy(value: string | undefined | null): boolean { + if (value == null) + return false + return /^(?:1|true|t|yes|y|on)$/i.test(value.trim()) +} diff --git a/packages/stage-shared/src/index.ts b/packages/stage-shared/src/index.ts index 703d7e71f..703d521fb 100644 --- a/packages/stage-shared/src/index.ts +++ b/packages/stage-shared/src/index.ts @@ -1,3 +1,4 @@ +export * from './env-vars' export * from './environment' export * from './export-csv' export * from './perf/tracer' diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 2720d2143..01f688ea8 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -568,6 +568,9 @@ importers: '@proj-airi/stage-layouts': specifier: workspace:^ version: link:../../packages/stage-layouts + '@proj-airi/stage-shared': + specifier: workspace:^ + version: link:../../packages/stage-shared '@proj-airi/stage-ui': specifier: workspace:^ version: link:../../packages/stage-ui