create-tririga-react-ts-vite-app 1.0.8 → 1.1.0

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/index.js CHANGED
@@ -96,6 +96,8 @@ async function configureApp() {
96
96
  const envPath = path.join(projectDir, '.env');
97
97
  if (fs.existsSync(envExamplePath)) {
98
98
  let envContent = fs.readFileSync(envExamplePath, 'utf8');
99
+ envContent = envContent.replace(/VITE_TRIRIGA_PROXY_TARGET=.*/g, `VITE_TRIRIGA_PROXY_TARGET=${triUrl}`);
100
+ envContent = envContent.replace(/VITE_MODEL_AND_VIEW=.*/g, `VITE_MODEL_AND_VIEW=${modelAndView}`);
99
101
  envContent = envContent.replace(/TRI_URL=.*/g, `TRI_URL=${triUrl}`);
100
102
  envContent = envContent.replace(/TRI_USER=.*/g, `TRI_USER=${triUser}`);
101
103
  envContent = envContent.replace(/TRI_PASSWORD=.*/g, `TRI_PASSWORD=${triPassword}`);
@@ -108,22 +110,31 @@ async function configureApp() {
108
110
  const tririgaServicePath = path.join(projectDir, 'src', 'services', 'tririgaService.ts');
109
111
  if (fs.existsSync(tririgaServicePath)) {
110
112
  let tsContent = fs.readFileSync(tririgaServicePath, 'utf8');
113
+ // Update production config values
111
114
  tsContent = tsContent.replace(/modelAndView:\s*"[^"]*"/, `modelAndView: "${modelAndView}"`);
112
115
  tsContent = tsContent.replace(/appExposedName:\s*"[^"]*"/, `appExposedName: "${appExposedName}"`);
116
+ // Update dev config fallback values
117
+ tsContent = tsContent.replace(/\|\| 'appName'/g, `|| '${appExposedName}'`);
118
+ tsContent = tsContent.replace(/\/app\/appName\//g, `/app/${appExposedName}/`);
113
119
  fs.writeFileSync(tririgaServicePath, tsContent);
114
120
  }
115
121
 
116
- // 7. Update vite.config.ts base path
122
+ // 7. Update vite.config.ts base path and proxy target
117
123
  const viteConfigPath = path.join(projectDir, 'vite.config.ts');
118
124
  if (fs.existsSync(viteConfigPath)) {
119
125
  let viteContent = fs.readFileSync(viteConfigPath, 'utf8');
120
- // Regex matches the whole base line and replaces it, handling single or double quotes
126
+ // Update base path
121
127
  viteContent = viteContent.replace(/base:\s*['"]\/app\/[^/]+\/['"],/, `base: '/app/${appExposedName}/',`);
128
+ // Update default proxy target
129
+ viteContent = viteContent.replace(
130
+ /const tririgaTarget = process\.env\.VITE_TRIRIGA_PROXY_TARGET \|\| '[^']*'/,
131
+ `const tririgaTarget = process.env.VITE_TRIRIGA_PROXY_TARGET || '${triUrl}'`
132
+ );
122
133
  fs.writeFileSync(viteConfigPath, viteContent);
123
134
  }
124
135
 
125
136
  console.log(`\nSuccess! Created and configured ${projectName}.`);
126
- console.log(`\nTo get started:\n cd ${projectName}\n npm install -g pnpm\n pnpm install\n pnpm run build:deploy\n`);
137
+ console.log(`\nTo get started:\n cd ${projectName}\n npm install -g pnpm\n pnpm install\n pnpm run dev # Local dev server with TRIRIGA API proxy\n pnpm run build:deploy # Build and deploy to TRIRIGA\n`);
127
138
  }
128
139
 
129
140
  configureApp();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-tririga-react-ts-vite-app",
3
- "version": "1.0.8",
3
+ "version": "1.1.0",
4
4
  "description": "Scaffold a TRIRIGA React app with Vite and TypeScript",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -1,13 +1,15 @@
1
1
  # Local Development Config
2
- VITE_TRIRIGA_URL=http://localhost:8001
2
+ # Leave VITE_TRIRIGA_URL empty — Vite proxy handles API forwarding to TRIRIGA
3
+ VITE_TRIRIGA_URL=
3
4
  VITE_INSTANCE_ID=-1
4
- VITE_CONTEXT_PATH=/app
5
- VITE_MODEL_AND_VIEW=devView
6
- VITE_BASE_PATH=/app/devView
7
- VITE_EXPOSED_NAME=devView
5
+ VITE_CONTEXT_PATH=
6
+ VITE_MODEL_AND_VIEW=appName
8
7
  VITE_SSO=false
9
8
  VITE_AUTO_LOGIN=true
10
9
 
10
+ # Vite proxy target — the TRIRIGA server URL for local dev API proxying
11
+ VITE_TRIRIGA_PROXY_TARGET=https://your-tririga-server.com
12
+
11
13
  # Deployment Config (used by tri-deploy)
12
14
  TRI_URL=https://your-tririga-server.com
13
15
  TRI_USER=your-username
@@ -5,6 +5,14 @@
5
5
  <link rel="icon" type="image/svg+xml" href="/vite.svg" />
6
6
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
7
  <title>Tririga React App</title>
8
+ <script>
9
+ // Apply theme early to prevent Flash of Unstyled Content (FOUC)
10
+ if (localStorage.getItem('theme') === 'dark' || (!('theme' in localStorage) && window.matchMedia('(prefers-color-scheme: dark)').matches)) {
11
+ document.documentElement.classList.add('dark');
12
+ } else {
13
+ document.documentElement.classList.remove('dark');
14
+ }
15
+ </script>
8
16
  </head>
9
17
  <body>
10
18
  <div id="root"></div>
@@ -8,11 +8,11 @@ export async function initTriAppConfig(): Promise<TriAppConfig> {
8
8
  if (import.meta.env.DEV) {
9
9
  const config: TriAppConfig = {
10
10
  instanceId: import.meta.env.VITE_INSTANCE_ID || '-1',
11
- tririgaUrl: import.meta.env.VITE_TRIRIGA_URL || 'http://localhost:8001',
12
- contextPath: import.meta.env.VITE_CONTEXT_PATH || '/dev',
13
- modelAndView: import.meta.env.VITE_MODEL_AND_VIEW || 'unknown',
14
- appPath: import.meta.env.VITE_BASE_PATH,
15
- appExposedName: import.meta.env.VITE_EXPOSED_NAME,
11
+ tririgaUrl: import.meta.env.VITE_TRIRIGA_URL || window.location.origin,
12
+ contextPath: import.meta.env.VITE_CONTEXT_PATH ?? '',
13
+ modelAndView: import.meta.env.VITE_MODEL_AND_VIEW || 'appName',
14
+ appPath: import.meta.env.VITE_BASE_PATH || '/app/appName/',
15
+ appExposedName: import.meta.env.VITE_EXPOSED_NAME || 'appName',
16
16
  sso: String(import.meta.env.VITE_SSO).toLowerCase() === 'true',
17
17
  };
18
18
  setTriAppConfig(config);
@@ -3,14 +3,27 @@ import { defineConfig } from 'vite'
3
3
  import tailwindcss from '@tailwindcss/vite'
4
4
  import react from '@vitejs/plugin-react'
5
5
 
6
+ // TRIRIGA paths that need to be proxied during local development
7
+ const tririgaTarget = process.env.VITE_TRIRIGA_PROXY_TARGET || 'https://your-tririga-server.com';
8
+ const tririgaProxyPaths = ['/p/', '/api/', '/getCompanyFile.jsp', '/html/en/default/'];
9
+ const tririgaProxyConfig = Object.fromEntries(
10
+ tririgaProxyPaths.map((p) => [
11
+ p,
12
+ { target: tririgaTarget, changeOrigin: true, secure: false },
13
+ ])
14
+ );
15
+
6
16
  // https://vite.dev/config/
7
17
  export default defineConfig({
8
- // Base path must match the TRIRIGA view name /app/<appName>/
9
- base: '/app/appName/',
18
+ // Base path must match the TRIRIGA view name /app/<appName>/
19
+ base: '/app/appName/',
10
20
  plugins: [react(), tailwindcss()],
11
21
  resolve: {
12
22
  alias: {
13
23
  "@": path.resolve(__dirname, "./src"),
14
24
  },
15
25
  },
26
+ server: {
27
+ proxy: tririgaProxyConfig,
28
+ },
16
29
  })