|
1 | 1 | import { execa } from "execa"; |
2 | | -import { readFile, writeFile, access } from "fs/promises"; |
| 2 | +import { readFile, writeFile } from "fs/promises"; |
3 | 3 | import { join } from "path"; |
4 | 4 |
|
5 | 5 | export async function buildFramework() { |
6 | | - if (process.argv.includes('create')) return; |
7 | | - |
8 | 6 | const projectDir = process.cwd(); |
9 | | - const tsconfigPath = join(projectDir, "tsconfig.json"); |
10 | 7 |
|
11 | 8 | try { |
12 | | - await access(tsconfigPath); |
13 | | - |
14 | 9 | await execa("npx", ["tsc"], { |
15 | 10 | stdio: "inherit", |
16 | 11 | reject: true, |
17 | 12 | }); |
18 | 13 |
|
19 | | - const distPath = join(projectDir, "dist"); |
| 14 | + const indexPath = join(projectDir, "dist", "index.js"); |
20 | 15 | const shebang = "#!/usr/bin/env node\n"; |
21 | 16 |
|
22 | | - const files = [ |
23 | | - join(distPath, "index.js"), |
24 | | - join(distPath, "cli", "index.js") |
25 | | - ]; |
26 | | - |
27 | | - await Promise.all(files.map(async (file) => { |
28 | | - try { |
29 | | - const content = await readFile(file, "utf8"); |
30 | | - if (!content.startsWith(shebang)) { |
31 | | - await writeFile(file, shebang + content); |
32 | | - } |
33 | | - } catch (error) { |
34 | | - if (file.includes("cli")) return; |
35 | | - throw error; |
36 | | - } |
37 | | - })); |
| 17 | + const content = await readFile(indexPath, "utf8"); |
| 18 | + if (!content.startsWith(shebang)) { |
| 19 | + await writeFile(indexPath, shebang + content); |
| 20 | + } |
38 | 21 | } catch (error) { |
39 | 22 | console.error("Build failed:", error instanceof Error ? error.message : error); |
40 | 23 | process.exit(1); |
|
0 commit comments