veslx 0.0.23 → 0.0.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/lib/build.ts +37 -4
- package/bin/lib/serve.ts +2 -1
- package/package.json +1 -1
package/bin/lib/build.ts
CHANGED
|
@@ -1,9 +1,29 @@
|
|
|
1
1
|
|
|
2
2
|
import { build } from 'vite'
|
|
3
3
|
import path from 'path'
|
|
4
|
+
import fs from 'fs'
|
|
4
5
|
import importConfig from "./import-config";
|
|
5
6
|
import veslxPlugin from '../../plugin/src/plugin'
|
|
6
7
|
|
|
8
|
+
/**
|
|
9
|
+
* Recursively copy a directory
|
|
10
|
+
*/
|
|
11
|
+
function copyDirSync(src: string, dest: string) {
|
|
12
|
+
fs.mkdirSync(dest, { recursive: true })
|
|
13
|
+
const entries = fs.readdirSync(src, { withFileTypes: true })
|
|
14
|
+
|
|
15
|
+
for (const entry of entries) {
|
|
16
|
+
const srcPath = path.join(src, entry.name)
|
|
17
|
+
const destPath = path.join(dest, entry.name)
|
|
18
|
+
|
|
19
|
+
if (entry.isDirectory()) {
|
|
20
|
+
copyDirSync(srcPath, destPath)
|
|
21
|
+
} else {
|
|
22
|
+
fs.copyFileSync(srcPath, destPath)
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
7
27
|
export default async function buildApp() {
|
|
8
28
|
const cwd = process.cwd()
|
|
9
29
|
|
|
@@ -17,7 +37,11 @@ export default async function buildApp() {
|
|
|
17
37
|
}
|
|
18
38
|
|
|
19
39
|
const veslxRoot = new URL('../..', import.meta.url).pathname;
|
|
20
|
-
const
|
|
40
|
+
const configFile = new URL('../../vite.config.ts', import.meta.url).pathname;
|
|
41
|
+
|
|
42
|
+
// Build inside veslxRoot first (Vite requires outDir to be within or relative to root)
|
|
43
|
+
const tempOutDir = path.join(veslxRoot, '.veslx-build')
|
|
44
|
+
const finalOutDir = path.join(cwd, 'dist')
|
|
21
45
|
|
|
22
46
|
// Resolve content directory relative to user's cwd (where config lives)
|
|
23
47
|
const contentDir = path.isAbsolute(config.dir)
|
|
@@ -26,9 +50,9 @@ export default async function buildApp() {
|
|
|
26
50
|
|
|
27
51
|
await build({
|
|
28
52
|
root: veslxRoot,
|
|
29
|
-
configFile
|
|
53
|
+
configFile,
|
|
30
54
|
build: {
|
|
31
|
-
outDir,
|
|
55
|
+
outDir: tempOutDir,
|
|
32
56
|
emptyOutDir: true,
|
|
33
57
|
},
|
|
34
58
|
plugins: [
|
|
@@ -36,5 +60,14 @@ export default async function buildApp() {
|
|
|
36
60
|
],
|
|
37
61
|
})
|
|
38
62
|
|
|
39
|
-
|
|
63
|
+
// Copy built files to user's dist directory
|
|
64
|
+
if (fs.existsSync(finalOutDir)) {
|
|
65
|
+
fs.rmSync(finalOutDir, { recursive: true })
|
|
66
|
+
}
|
|
67
|
+
copyDirSync(tempOutDir, finalOutDir)
|
|
68
|
+
|
|
69
|
+
// Clean up temp build directory
|
|
70
|
+
fs.rmSync(tempOutDir, { recursive: true })
|
|
71
|
+
|
|
72
|
+
console.log(`\nBuild complete: ${finalOutDir}`)
|
|
40
73
|
}
|
package/bin/lib/serve.ts
CHANGED
|
@@ -17,6 +17,7 @@ export default async function start() {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
const veslxRoot = new URL('../..', import.meta.url).pathname;
|
|
20
|
+
const configFile = new URL('../../vite.config.ts', import.meta.url).pathname;
|
|
20
21
|
|
|
21
22
|
// Resolve content directory relative to user's cwd (where config lives)
|
|
22
23
|
const contentDir = path.isAbsolute(config.dir)
|
|
@@ -25,7 +26,7 @@ export default async function start() {
|
|
|
25
26
|
|
|
26
27
|
const server = await preview({
|
|
27
28
|
root: veslxRoot,
|
|
28
|
-
configFile
|
|
29
|
+
configFile,
|
|
29
30
|
plugins: [
|
|
30
31
|
veslxPlugin(contentDir)
|
|
31
32
|
],
|