MCPcopy Create free account
hub / github.com/altic-dev/Pilot / detectBuildConfig

Function detectBuildConfig

src/lib/build-detector.ts:146–194  ·  view source on GitHub ↗
(sessionId: string)

Source from the content-addressed store, hash-verified

144 * Auto-detect build configuration from package.json
145 */
146export async function detectBuildConfig(sessionId: string): Promise<BuildConfig> {
147 try {
148 logger.info('Detecting build configuration', { sessionId });
149
150 // Read package.json
151 const packageJsonContent = await readFile(sessionId, '/workspace/package.json');
152 const packageJson: PackageJson = JSON.parse(packageJsonContent);
153
154 // Detect framework
155 const framework = detectFramework(packageJson);
156 logger.info('Framework detected', { framework });
157
158 // Detect package manager
159 const packageManager = await detectPackageManager(sessionId);
160 logger.info('Package manager detected', { packageManager });
161
162 // Detect commands
163 const devScriptName = detectDevCommand(framework, packageJson.scripts);
164 const buildScriptName = detectBuildCommand(packageJson.scripts);
165 const defaultPort = detectDefaultPort(framework, packageJson.scripts);
166
167 const buildConfig: BuildConfig = {
168 framework,
169 packageManager,
170 installCommand: packageManager === 'npm' ? 'npm install'
171 : packageManager === 'pnpm' ? 'pnpm install'
172 : 'yarn install',
173 buildCommand: buildScriptName
174 ? `${packageManager} run ${buildScriptName}`
175 : undefined,
176 devCommand: `${packageManager} run ${devScriptName}`,
177 defaultPort,
178 };
179
180 logger.info('Build configuration detected', buildConfig);
181 return buildConfig;
182 } catch (error) {
183 logger.error('Failed to detect build configuration', { sessionId, error });
184
185 // Return sensible defaults
186 return {
187 framework: 'Unknown',
188 packageManager: 'npm',
189 installCommand: 'npm install',
190 devCommand: 'npm run dev',
191 defaultPort: 3000,
192 };
193 }
194}

Callers 1

repo-setup.tsFile · 0.90

Calls 6

readFileFunction · 0.90
detectFrameworkFunction · 0.85
detectPackageManagerFunction · 0.85
detectDevCommandFunction · 0.85
detectBuildCommandFunction · 0.85
detectDefaultPortFunction · 0.85

Tested by

no test coverage detected