-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrelease.mjs
More file actions
68 lines (58 loc) · 2.31 KB
/
release.mjs
File metadata and controls
68 lines (58 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import { fileURLToPath } from 'url';
import fs from 'fs';
import path from 'path';
import { execSync } from 'child_process';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
// Actual project paths
const rootDir = path.resolve(__dirname);
const uiDir = path.join(rootDir, 'vertigo-ui');
const backendDir = path.join(rootDir, 'vertigo-backend');
const buildDir = path.resolve(rootDir, '../Build');
// Step 1: Read version
const pkg = JSON.parse(fs.readFileSync(path.join(uiDir, 'package.json'), 'utf8'));
const version = pkg.version;
const versionedBuildPath = path.join(buildDir, `vertigo_${version}`);
// Step 2: Build frontend
console.log('📦 Building frontend...');
try {
// Changed to use absolute path and proper Windows commands
const buildCommand = process.platform === 'win32' ? 'npm.cmd run build' : 'npm run build';
execSync(buildCommand, {
cwd: uiDir, // Fixed path
stdio: 'inherit',
shell: true,
env: process.env // Explicitly pass environment
});
} catch (error) {
console.error('🚨 Frontend build failed!');
process.exit(1);
}
// Step 3: Prepare versioned folder
console.log(`📁 Creating versioned folder: ${versionedBuildPath}`);
if (!fs.existsSync(buildDir)) fs.mkdirSync(buildDir, { recursive: true });
if (fs.existsSync(versionedBuildPath)) fs.rmSync(versionedBuildPath, { recursive: true });
fs.mkdirSync(versionedBuildPath);
// Step 4: Copy folders
console.log('📤 Copying backend and (optionally) frontend sources...');
try {
// Windows-safe copy command
const copyCommand = process.platform === 'win32'
? `xcopy /E /I "${backendDir}" "${versionedBuildPath}"`
: `cp -r "${backendDir}" "${versionedBuildPath}/vertigo-backend"`;
execSync(copyCommand, { stdio: 'inherit', shell: true });
} catch (error) {
console.error('🚨 Copy operation failed!');
process.exit(1);
}
// Step 5: Remove unwanted folders from backend copy
const backendCopyPath = path.join(versionedBuildPath);
const removeDirs = ['Config', 'env','__pycache__',"tests"];
removeDirs.forEach(dir => {
const fullPath = path.join(backendCopyPath, dir);
if (fs.existsSync(fullPath)) {
fs.rmSync(fullPath, { recursive: true, force: true });
console.log(`🧹 Removed ${dir} from backend copy.`);
}
});
console.log('✅ Release completed successfully.');