Skip to content

Commit 5b9a13d

Browse files
committed
chore: wip
1 parent 5e11fe1 commit 5b9a13d

File tree

3 files changed

+172
-156
lines changed

3 files changed

+172
-156
lines changed

packages/launchpad/src/php/auto-detector.ts

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import fs from 'node:fs'
22
import path from 'node:path'
3+
import process from 'node:process'
34
import { config } from '../config'
45

56
export interface ProjectAnalysis {
@@ -77,8 +78,8 @@ export class PHPAutoDetector {
7778
*/
7879
private detectFramework(): ProjectAnalysis['framework'] {
7980
// Check for Laravel
80-
if (fs.existsSync(path.join(this.projectRoot, 'artisan')) &&
81-
fs.existsSync(path.join(this.projectRoot, 'composer.json'))) {
81+
if (fs.existsSync(path.join(this.projectRoot, 'artisan'))
82+
&& fs.existsSync(path.join(this.projectRoot, 'composer.json'))) {
8283
try {
8384
const composerJson = JSON.parse(fs.readFileSync(path.join(this.projectRoot, 'composer.json'), 'utf-8'))
8485
if (composerJson.require?.['laravel/framework']) {
@@ -94,14 +95,14 @@ export class PHPAutoDetector {
9495
}
9596

9697
// Check for WordPress
97-
if (fs.existsSync(path.join(this.projectRoot, 'wp-config.php')) ||
98-
fs.existsSync(path.join(this.projectRoot, 'wp-config-sample.php'))) {
98+
if (fs.existsSync(path.join(this.projectRoot, 'wp-config.php'))
99+
|| fs.existsSync(path.join(this.projectRoot, 'wp-config-sample.php'))) {
99100
return 'wordpress'
100101
}
101102

102103
// Check for Symfony
103-
if (fs.existsSync(path.join(this.projectRoot, 'symfony.lock')) ||
104-
fs.existsSync(path.join(this.projectRoot, 'config', 'bundles.php'))) {
104+
if (fs.existsSync(path.join(this.projectRoot, 'symfony.lock'))
105+
|| fs.existsSync(path.join(this.projectRoot, 'config', 'bundles.php'))) {
105106
return 'symfony'
106107
}
107108

@@ -120,10 +121,9 @@ export class PHPAutoDetector {
120121
try {
121122
const envContent = fs.readFileSync(envPath, 'utf-8')
122123

123-
if (envContent.includes('DB_CONNECTION=mysql') ||
124-
envContent.includes('DB_CONNECTION=pgsql') ||
125-
envContent.includes('DB_CONNECTION=sqlite')) {
126-
124+
if (envContent.includes('DB_CONNECTION=mysql')
125+
|| envContent.includes('DB_CONNECTION=pgsql')
126+
|| envContent.includes('DB_CONNECTION=sqlite')) {
127127
if (envContent.includes('DB_CONNECTION=mysql')) {
128128
databases.push('mysql')
129129
}
@@ -141,8 +141,8 @@ export class PHPAutoDetector {
141141
}
142142

143143
// Check for database files
144-
if (fs.existsSync(path.join(this.projectRoot, 'database.sqlite')) ||
145-
fs.existsSync(path.join(this.projectRoot, 'database', 'database.sqlite'))) {
144+
if (fs.existsSync(path.join(this.projectRoot, 'database.sqlite'))
145+
|| fs.existsSync(path.join(this.projectRoot, 'database', 'database.sqlite'))) {
146146
if (!databases.includes('sqlite')) {
147147
databases.push('sqlite')
148148
}
@@ -169,7 +169,8 @@ export class PHPAutoDetector {
169169
const userPref = config.services?.php?.autoDetect?.preferredDatabase
170170
if (userPref && userPref !== 'auto') {
171171
databases.push(userPref)
172-
} else {
172+
}
173+
else {
173174
// Default to SQLite for development
174175
databases.push('sqlite')
175176
}
@@ -243,7 +244,7 @@ export class PHPAutoDetector {
243244
* Determine the optimal PHP configuration based on analysis
244245
*/
245246
private determineOptimalConfig(analysis: ProjectAnalysis): string {
246-
const { framework, databases, hasApi, hasWebInterface, hasImageProcessing, hasEnterpriseFeatures } = analysis
247+
const { framework, databases, hasApi, hasWebInterface, hasEnterpriseFeatures } = analysis
247248

248249
// Framework-specific configurations
249250
if (framework === 'wordpress') {
@@ -298,12 +299,12 @@ export class PHPAutoDetector {
298299
* Get human-readable explanation of the configuration choice
299300
*/
300301
getConfigurationExplanation(analysis: ProjectAnalysis): string {
301-
const { framework, databases, recommendedConfig, reasoning } = analysis
302+
const { recommendedConfig, reasoning } = analysis
302303

303304
let explanation = `🎯 Recommended PHP Configuration: ${recommendedConfig}\n\n`
304305

305306
explanation += `📋 Analysis:\n`
306-
reasoning.forEach(reason => {
307+
reasoning.forEach((reason) => {
307308
explanation += ` • ${reason}\n`
308309
})
309310

scripts/check-php-updates.ts

Lines changed: 88 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -7,101 +7,110 @@
77
* if a rebuild is needed. It compares current versions with the latest available.
88
*/
99

10-
interface PHPVersion {
11-
version: string;
12-
status: 'stable' | 'security' | 'eol';
13-
releaseDate?: string;
10+
// Unused interface - keeping for future use
11+
interface _PHPVersion {
12+
version: string
13+
status: 'stable' | 'security' | 'eol'
14+
releaseDate?: string
1415
}
1516

1617
interface BuildInfo {
17-
currentVersions: string[];
18-
latestVersions: string[];
19-
hasNewVersions: boolean;
20-
newVersions: string[];
21-
rebuildNeeded: boolean;
22-
reason: string;
18+
currentVersions: string[]
19+
latestVersions: string[]
20+
hasNewVersions: boolean
21+
newVersions: string[]
22+
rebuildNeeded: boolean
23+
reason: string
2324
}
2425

2526
async function getCurrentVersions(): Promise<string[]> {
2627
try {
2728
// Read current versions from the script
28-
const { readFileSync } = await import('fs');
29-
const scriptContent = readFileSync('scripts/get-php-versions.ts', 'utf8');
29+
const { readFileSync } = await import('node:fs')
30+
const scriptContent = readFileSync('scripts/get-php-versions.ts', 'utf8')
3031

3132
// Extract fallback versions from the script
32-
const fallbackMatch = scriptContent.match(/return \['([^']+)', '([^']+)', '([^']+)', '([^']+)'\]/);
33+
const fallbackMatch = scriptContent.match(/return \['([^']+)', '([^']+)', '([^']+)', '([^']+)'\]/)
3334
if (fallbackMatch) {
34-
return [fallbackMatch[1], fallbackMatch[2], fallbackMatch[3], fallbackMatch[4]];
35+
return [fallbackMatch[1], fallbackMatch[2], fallbackMatch[3], fallbackMatch[4]]
3536
}
3637

3738
// If we can't parse from script, use hardcoded fallback
38-
return ['8.4.11', '8.3.14', '8.2.26', '8.1.30'];
39-
} catch (error) {
40-
console.error('Failed to read current versions:', error);
41-
return ['8.4.11', '8.3.14', '8.2.26', '8.1.30'];
39+
return ['8.4.11', '8.3.14', '8.2.26', '8.1.30']
40+
}
41+
catch (error) {
42+
console.error('Failed to read current versions:', error)
43+
return ['8.4.11', '8.3.14', '8.2.26', '8.1.30']
4244
}
4345
}
4446

4547
async function getLatestVersions(): Promise<string[]> {
4648
try {
4749
// Use ts-pkgx to get PHP versions
48-
const { execSync } = await import('child_process');
49-
const output = execSync('bunx ts-pkgx get-php-versions', { encoding: 'utf8' });
50+
const { execSync } = await import('node:child_process')
51+
const output = execSync('bunx ts-pkgx get-php-versions', { encoding: 'utf8' })
5052

5153
// Parse the output - assuming it returns a JSON array or comma-separated string
52-
let versions: string[];
54+
let versions: string[]
5355
try {
54-
versions = JSON.parse(output);
55-
} catch {
56+
versions = JSON.parse(output)
57+
}
58+
catch {
5659
// If not JSON, split by comma
57-
versions = output.trim().split(',').map(v => v.trim());
60+
versions = output.trim().split(',').map(v => v.trim())
5861
}
5962

6063
// Filter to only stable versions and sort by version
6164
const stableVersions = versions
6265
.filter(v => v.match(/^\d+\.\d+\.\d+$/))
6366
.sort((a, b) => {
64-
const [aMajor, aMinor, aPatch] = a.split('.').map(Number);
65-
const [bMajor, bMinor, bPatch] = b.split('.').map(Number);
66-
67-
if (aMajor !== bMajor) return bMajor - aMajor;
68-
if (aMinor !== bMinor) return bMinor - aMinor;
69-
return bPatch - aPatch;
67+
const [aMajor, aMinor, aPatch] = a.split('.').map(Number)
68+
const [bMajor, bMinor, bPatch] = b.split('.').map(Number)
69+
70+
if (aMajor !== bMajor)
71+
return bMajor - aMajor
72+
if (aMinor !== bMinor)
73+
return bMinor - aMinor
74+
return bPatch - aPatch
7075
})
71-
.slice(0, 4); // Keep only the 4 most recent versions
76+
.slice(0, 4) // Keep only the 4 most recent versions
7277

73-
return stableVersions;
74-
} catch (error) {
75-
console.error('Failed to fetch latest PHP versions from ts-pkgx:', error);
78+
return stableVersions
79+
}
80+
catch (error) {
81+
console.error('Failed to fetch latest PHP versions from ts-pkgx:', error)
7682

7783
// Fallback to current versions
78-
return await getCurrentVersions();
84+
return await getCurrentVersions()
7985
}
8086
}
8187

8288
function compareVersions(current: string[], latest: string[]): BuildInfo {
83-
const currentSet = new Set(current);
84-
const latestSet = new Set(latest);
89+
const currentSet = new Set(current)
90+
const latestSet = new Set(latest)
8591

8692
// Find new versions
87-
const newVersions = latest.filter(v => !currentSet.has(v));
93+
const newVersions = latest.filter(v => !currentSet.has(v))
8894

8995
// Find removed versions
90-
const removedVersions = current.filter(v => !latestSet.has(v));
96+
const removedVersions = current.filter(v => !latestSet.has(v))
9197

92-
const hasNewVersions = newVersions.length > 0;
93-
const hasRemovedVersions = removedVersions.length > 0;
94-
const rebuildNeeded = hasNewVersions || hasRemovedVersions;
98+
const hasNewVersions = newVersions.length > 0
99+
const hasRemovedVersions = removedVersions.length > 0
100+
const rebuildNeeded = hasNewVersions || hasRemovedVersions
95101

96-
let reason = '';
102+
let reason = ''
97103
if (hasNewVersions && hasRemovedVersions) {
98-
reason = `New versions available: ${newVersions.join(', ')}. Removed versions: ${removedVersions.join(', ')}`;
99-
} else if (hasNewVersions) {
100-
reason = `New versions available: ${newVersions.join(', ')}`;
101-
} else if (hasRemovedVersions) {
102-
reason = `Versions removed: ${removedVersions.join(', ')}`;
103-
} else {
104-
reason = 'No changes detected';
104+
reason = `New versions available: ${newVersions.join(', ')}. Removed versions: ${removedVersions.join(', ')}`
105+
}
106+
else if (hasNewVersions) {
107+
reason = `New versions available: ${newVersions.join(', ')}`
108+
}
109+
else if (hasRemovedVersions) {
110+
reason = `Versions removed: ${removedVersions.join(', ')}`
111+
}
112+
else {
113+
reason = 'No changes detected'
105114
}
106115

107116
return {
@@ -110,55 +119,56 @@ function compareVersions(current: string[], latest: string[]): BuildInfo {
110119
hasNewVersions,
111120
newVersions,
112121
rebuildNeeded,
113-
reason
114-
};
122+
reason,
123+
}
115124
}
116125

117126
async function checkForUpdates(): Promise<BuildInfo> {
118-
const currentVersions = await getCurrentVersions();
119-
const latestVersions = await getLatestVersions();
127+
const currentVersions = await getCurrentVersions()
128+
const latestVersions = await getLatestVersions()
120129

121-
return compareVersions(currentVersions, latestVersions);
130+
return compareVersions(currentVersions, latestVersions)
122131
}
123132

124133
function generateOutput(buildInfo: BuildInfo): void {
125-
console.log('🔍 PHP Version Update Check');
126-
console.log('');
127-
console.log('📊 Version Comparison:');
128-
console.log(` Current: ${buildInfo.currentVersions.join(', ')}`);
129-
console.log(` Latest: ${buildInfo.latestVersions.join(', ')}`);
130-
console.log('');
134+
console.log('🔍 PHP Version Update Check')
135+
console.log('')
136+
console.log('📊 Version Comparison:')
137+
console.log(` Current: ${buildInfo.currentVersions.join(', ')}`)
138+
console.log(` Latest: ${buildInfo.latestVersions.join(', ')}`)
139+
console.log('')
131140

132141
if (buildInfo.rebuildNeeded) {
133-
console.log('🔄 Rebuild Required: YES');
134-
console.log(` Reason: ${buildInfo.reason}`);
142+
console.log('🔄 Rebuild Required: YES')
143+
console.log(` Reason: ${buildInfo.reason}`)
135144

136145
if (buildInfo.hasNewVersions) {
137-
console.log(` New versions: ${buildInfo.newVersions.join(', ')}`);
146+
console.log(` New versions: ${buildInfo.newVersions.join(', ')}`)
138147
}
139-
} else {
140-
console.log('✅ Rebuild Required: NO');
141-
console.log(` Reason: ${buildInfo.reason}`);
148+
}
149+
else {
150+
console.log('✅ Rebuild Required: NO')
151+
console.log(` Reason: ${buildInfo.reason}`)
142152
}
143153

144154
// Output for GitHub Actions
145-
console.log('');
146-
console.log('GitHub Actions Output:');
147-
console.log(`rebuild_needed=${buildInfo.rebuildNeeded}`);
148-
console.log(`reason=${buildInfo.reason}`);
149-
console.log(`current_versions=${JSON.stringify(buildInfo.currentVersions)}`);
150-
console.log(`latest_versions=${JSON.stringify(buildInfo.latestVersions)}`);
151-
console.log(`new_versions=${JSON.stringify(buildInfo.newVersions)}`);
155+
console.log('')
156+
console.log('GitHub Actions Output:')
157+
console.log(`rebuild_needed=${buildInfo.rebuildNeeded}`)
158+
console.log(`reason=${buildInfo.reason}`)
159+
console.log(`current_versions=${JSON.stringify(buildInfo.currentVersions)}`)
160+
console.log(`latest_versions=${JSON.stringify(buildInfo.latestVersions)}`)
161+
console.log(`new_versions=${JSON.stringify(buildInfo.newVersions)}`)
152162
}
153163

154164
async function main(): Promise<void> {
155-
const buildInfo = await checkForUpdates();
156-
generateOutput(buildInfo);
165+
const buildInfo = await checkForUpdates()
166+
generateOutput(buildInfo)
157167
}
158168

159169
// Run the script
160170
if (import.meta.main) {
161-
main().catch(console.error);
171+
main().catch(console.error)
162172
}
163173

164-
export { checkForUpdates, compareVersions, getCurrentVersions, getLatestVersions };
174+
export { checkForUpdates, compareVersions, getCurrentVersions, getLatestVersions }

0 commit comments

Comments
 (0)