feat: Initial commit of KROW Workforce Web client (Base44 export)
This commit is contained in:
138
scripts/prepare-export.js
Normal file
138
scripts/prepare-export.js
Normal file
@@ -0,0 +1,138 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const { execSync } = require('child_process');
|
||||
|
||||
const projectRoot = path.join(__dirname, '..');
|
||||
|
||||
// --- Fonctions de Patch ---
|
||||
|
||||
function applyPatch(filePath, patches) {
|
||||
const fullPath = path.join(projectRoot, filePath);
|
||||
if (!fs.existsSync(fullPath)) {
|
||||
console.warn(`🟡 Fichier non trouvé, patch ignoré : ${filePath}`);
|
||||
return;
|
||||
}
|
||||
|
||||
let content = fs.readFileSync(fullPath, 'utf8');
|
||||
let changed = false;
|
||||
|
||||
patches.forEach(patch => {
|
||||
if (content.includes(patch.new_string)) {
|
||||
console.log(`✅ Patch déjà appliqué dans ${filePath} (recherche de '${patch.search_string}').`);
|
||||
} else if (content.includes(patch.old_string)) {
|
||||
content = content.replace(patch.old_string, patch.new_string);
|
||||
changed = true;
|
||||
console.log(`🟢 Patch appliqué dans ${filePath} (remplacement de '${patch.search_string}').`);
|
||||
} else {
|
||||
console.error(`🔴 Impossible d'appliquer le patch dans ${filePath}. Chaîne non trouvée : '${patch.search_string}'.`);
|
||||
}
|
||||
});
|
||||
|
||||
if (changed) {
|
||||
fs.writeFileSync(fullPath, content, 'utf8');
|
||||
}
|
||||
}
|
||||
|
||||
// --- Définition des Patches ---
|
||||
|
||||
const patches = [
|
||||
{
|
||||
file: 'src/api/base44Client.js',
|
||||
search_string: 'createClient',
|
||||
old_string: `import { createClient } from '@base44/sdk';
|
||||
// import { getAccessToken } from '@base44/sdk/utils/auth-utils';
|
||||
|
||||
// Create a client with authentication required
|
||||
export const base44 = createClient({
|
||||
appId: "68fc6cf01386035c266e7a5d",
|
||||
requiresAuth: true // Ensure authentication is required for all operations
|
||||
});`,
|
||||
new_string: `// import { createClient } from '@base44/sdk';
|
||||
|
||||
// --- MIGRATION MOCK ---
|
||||
// This mock completely disables the Base44 SDK to allow for local development.
|
||||
export const base44 = {
|
||||
auth: {
|
||||
me: () => Promise.resolve(null),
|
||||
logout: () => {},
|
||||
},
|
||||
entities: {
|
||||
ActivityLog: {
|
||||
filter: () => Promise.resolve([]),
|
||||
},
|
||||
},
|
||||
};
|
||||
`
|
||||
},
|
||||
{
|
||||
file: 'src/main.jsx',
|
||||
search_string: `ReactDOM.createRoot(document.getElementById('root')).render(`,
|
||||
old_string: `import React from 'react'
|
||||
import ReactDOM from 'react-dom/client'
|
||||
import App from '@/App.jsx'
|
||||
import '@/index.css'
|
||||
|
||||
ReactDOM.createRoot(document.getElementById('root')).render(
|
||||
<App />
|
||||
)`,
|
||||
new_string: `import React from 'react'
|
||||
import ReactDOM from 'react-dom/client'
|
||||
import App from '@/App.jsx'
|
||||
import '@/index.css'
|
||||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
||||
|
||||
const queryClient = new QueryClient();
|
||||
|
||||
ReactDOM.createRoot(document.getElementById('root')).render(
|
||||
<React.StrictMode>
|
||||
<QueryClientProvider client={queryClient}>
|
||||
<App />
|
||||
</QueryClientProvider>
|
||||
</React.StrictMode>,
|
||||
)
|
||||
`
|
||||
},
|
||||
{
|
||||
file: 'src/pages/Layout.jsx',
|
||||
search_string: `const { data: user } = useQuery`,
|
||||
old_string: ` const { data: user } = useQuery({
|
||||
queryKey: ['current-user-layout'],
|
||||
queryFn: () => base44.auth.me(),
|
||||
});`,
|
||||
new_string: ` // const { data: user } = useQuery({
|
||||
// queryKey: ['current-user-layout'],
|
||||
// queryFn: () => base44.auth.me(),
|
||||
// });
|
||||
|
||||
// Mock user data to prevent redirection and allow local development
|
||||
const user = {
|
||||
full_name: "Dev User",
|
||||
email: "dev@example.com",
|
||||
user_role: "admin", // You can change this to 'procurement', 'operator', 'client', etc. to test different navigation menus
|
||||
profile_picture: "https://i.pravatar.cc/150?u=a042581f4e29026024d",
|
||||
};`
|
||||
},
|
||||
{
|
||||
file: 'src/pages/Layout.jsx',
|
||||
search_string: `const { data: unreadCount = 0 } = useQuery`,
|
||||
old_string: ` const { data: unreadCount = 0 } = useQuery({
|
||||
queryKey: ['unread-notifications', user?.id],
|
||||
queryFn: async () => {
|
||||
if (!user?.id) return 0;
|
||||
// Assuming ActivityLog entity is used for user notifications
|
||||
// and has user_id and is_read fields.
|
||||
const notifications = await base44.entities.ActivityLog.filter({
|
||||
user_id: user?.id,
|
||||
is_read: false
|
||||
});
|
||||
return notifications.length;
|
||||
},
|
||||
enabled: !!user?.id,
|
||||
initialData: 0,
|
||||
refetchInterval: 10000, // Refresh every 10 seconds
|
||||
});`,
|
||||
new_string: ` // Get unread notification count
|
||||
// const { data: unreadCount = 0 } = useQuery({ ... });
|
||||
const unreadCount = 0; // Mocked value`
|
||||
}
|
||||
];
|
||||
Reference in New Issue
Block a user