|
20 | 20 |
|
21 | 21 | import { execSync } from 'node:child_process'; |
22 | 22 | import { existsSync, globSync, readFileSync, readdirSync, statSync } from 'node:fs'; |
23 | | -import { copyFile, mkdir, readFile, rename, rm, writeFile } from 'node:fs/promises'; |
| 23 | +import { copyFile, mkdir, readFile, rm, writeFile } from 'node:fs/promises'; |
24 | 24 | import { dirname, join } from 'node:path'; |
25 | 25 | import { fileURLToPath } from 'node:url'; |
26 | 26 | import { parseArgs } from 'node:util'; |
@@ -60,6 +60,7 @@ const napiArgs = process.argv |
60 | 60 |
|
61 | 61 | if (!skipTs) { |
62 | 62 | await buildCli(); |
| 63 | + await copyCliAssets(); |
63 | 64 | buildGlobalModules(); |
64 | 65 | generateLicenseFile({ |
65 | 66 | title: 'Vite-Plus CLI license', |
@@ -165,10 +166,11 @@ async function buildCli() { |
165 | 166 | console.error(formatDiagnostics(cjsDiagnostics, cjsHost)); |
166 | 167 | process.exit(1); |
167 | 168 | } |
168 | | - await rename( |
169 | | - join(projectDir, 'dist/define-config.js'), |
170 | | - join(projectDir, 'dist/define-config.cjs'), |
171 | | - ); |
| 169 | + const defineConfigJsPath = join(projectDir, 'dist/define-config.js'); |
| 170 | + const defineConfigCjsPath = join(projectDir, 'dist/define-config.cjs'); |
| 171 | + if (existsSync(defineConfigJsPath)) { |
| 172 | + await copyFile(defineConfigJsPath, defineConfigCjsPath); |
| 173 | + } |
172 | 174 |
|
173 | 175 | const host = createCompilerHost(options); |
174 | 176 |
|
@@ -196,6 +198,30 @@ async function buildCli() { |
196 | 198 | console.error(formatDiagnostics(diagnostics, host)); |
197 | 199 | process.exit(1); |
198 | 200 | } |
| 201 | + |
| 202 | + if (existsSync(defineConfigJsPath)) { |
| 203 | + await copyFile(defineConfigJsPath, defineConfigCjsPath); |
| 204 | + } else if (existsSync(defineConfigCjsPath)) { |
| 205 | + await copyFile(defineConfigCjsPath, defineConfigJsPath); |
| 206 | + } |
| 207 | +} |
| 208 | + |
| 209 | +async function copyCliAssets() { |
| 210 | + const assetsDir = join(projectDir, 'assets'); |
| 211 | + if (!existsSync(assetsDir)) { |
| 212 | + return; |
| 213 | + } |
| 214 | + |
| 215 | + const distAssetsDir = join(projectDir, 'dist', 'assets'); |
| 216 | + await mkdir(distAssetsDir, { recursive: true }); |
| 217 | + |
| 218 | + for (const entry of readdirSync(assetsDir)) { |
| 219 | + const sourcePath = join(assetsDir, entry); |
| 220 | + if (!statSync(sourcePath).isFile()) { |
| 221 | + continue; |
| 222 | + } |
| 223 | + await copyFile(sourcePath, join(distAssetsDir, entry)); |
| 224 | + } |
199 | 225 | } |
200 | 226 |
|
201 | 227 | function buildGlobalModules() { |
|
0 commit comments