veslx 0.0.4 → 0.0.6
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 +35 -0
- package/bin/lib/serve.ts +1 -4
- package/bin/veslx.ts +10 -5
- package/package.json +3 -3
- package/plugin/src/client.tsx +1 -1
- package/plugin/src/plugin.ts +39 -3
- package/test-content/.vesl.json +0 -49
package/bin/lib/build.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
|
|
2
|
+
import { build } from 'vite'
|
|
3
|
+
import path from 'path'
|
|
4
|
+
import importConfig from "./import-config";
|
|
5
|
+
import veslxPlugin from '../../plugin/src/plugin'
|
|
6
|
+
|
|
7
|
+
export default async function buildApp() {
|
|
8
|
+
const cwd = process.cwd()
|
|
9
|
+
|
|
10
|
+
console.log(`Building veslx app in ${cwd}`);
|
|
11
|
+
|
|
12
|
+
const config = await importConfig(cwd);
|
|
13
|
+
|
|
14
|
+
if (!config) {
|
|
15
|
+
console.error("Configuration file 'veslx.config.ts' not found in the current directory.");
|
|
16
|
+
return
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const veslxRoot = new URL('../..', import.meta.url).pathname;
|
|
20
|
+
const outDir = path.join(cwd, 'dist')
|
|
21
|
+
|
|
22
|
+
await build({
|
|
23
|
+
root: veslxRoot,
|
|
24
|
+
configFile: new URL('../../vite.config.ts', import.meta.url).pathname,
|
|
25
|
+
build: {
|
|
26
|
+
outDir,
|
|
27
|
+
emptyOutDir: true,
|
|
28
|
+
},
|
|
29
|
+
plugins: [
|
|
30
|
+
veslxPlugin(config.dir)
|
|
31
|
+
],
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
console.log(`\nBuild complete: ${outDir}`)
|
|
35
|
+
}
|
package/bin/lib/serve.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { createServer } from 'vite'
|
|
|
3
3
|
import importConfig from "./import-config";
|
|
4
4
|
import veslxPlugin from '../../plugin/src/plugin'
|
|
5
5
|
|
|
6
|
-
export default async function
|
|
6
|
+
export default async function start() {
|
|
7
7
|
const cwd = process.cwd()
|
|
8
8
|
|
|
9
9
|
console.log(`Starting veslx server in ${cwd}`);
|
|
@@ -23,9 +23,6 @@ export default async function startServer() {
|
|
|
23
23
|
plugins: [
|
|
24
24
|
veslxPlugin(config.dir)
|
|
25
25
|
],
|
|
26
|
-
env: {
|
|
27
|
-
cwd,
|
|
28
|
-
}
|
|
29
26
|
})
|
|
30
27
|
|
|
31
28
|
await server.listen()
|
package/bin/veslx.ts
CHANGED
|
@@ -6,14 +6,15 @@ import init from "./lib/init";
|
|
|
6
6
|
import serve from "./lib/serve";
|
|
7
7
|
import start from "./lib/start";
|
|
8
8
|
import stop from "./lib/stop";
|
|
9
|
+
import build from "./lib/build";
|
|
9
10
|
|
|
10
11
|
const cli = cac("veslx");
|
|
11
12
|
|
|
12
|
-
console.log(`▗▖ ▗▖▗▄▄▄▖ ▗▄▄▖▗▖
|
|
13
|
-
▐▌ ▐▌▐▌ ▐▌ ▐▌
|
|
14
|
-
▐▌ ▐▌▐▛▀▀▘ ▝▀▚▖▐▌
|
|
15
|
-
▝▚▞▘
|
|
16
|
-
|
|
13
|
+
console.log(`▗▖ ▗▖▗▄▄▄▖ ▗▄▄▖▗▖ ▗▖ ▗▖
|
|
14
|
+
▐▌ ▐▌▐▌ ▐▌ ▐▌ ▝▚▞▘
|
|
15
|
+
▐▌ ▐▌▐▛▀▀▘ ▝▀▚▖▐▌ ▐▌
|
|
16
|
+
▝▚▞▘ ▐▙▄▄▖▗▄▄▞▘▐▙▄▄▖▗▞▘▝▚▖
|
|
17
|
+
`);
|
|
17
18
|
|
|
18
19
|
cli
|
|
19
20
|
.command("init", "Initialize a new veslx project")
|
|
@@ -31,6 +32,10 @@ cli
|
|
|
31
32
|
.command("stop", "Stop the veslx deamon")
|
|
32
33
|
.action(stop);
|
|
33
34
|
|
|
35
|
+
cli
|
|
36
|
+
.command("build", "Build the veslx app")
|
|
37
|
+
.action(build)
|
|
38
|
+
|
|
34
39
|
cli.help();
|
|
35
40
|
cli.version(pkg.version);
|
|
36
41
|
cli.parse();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "veslx",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"bin": {
|
|
6
6
|
"veslx": "bin/veslx.ts"
|
|
@@ -54,7 +54,8 @@
|
|
|
54
54
|
"remark-gfm": "^4.0.1",
|
|
55
55
|
"remark-math": "^6.0.0",
|
|
56
56
|
"remark-mdx-frontmatter": "^5.2.0",
|
|
57
|
-
"shiki": "^3.15.0"
|
|
57
|
+
"shiki": "^3.15.0",
|
|
58
|
+
"gray-matter": "^4.0.3"
|
|
58
59
|
},
|
|
59
60
|
"devDependencies": {
|
|
60
61
|
"@eslint/js": "^9.39.1",
|
|
@@ -73,7 +74,6 @@
|
|
|
73
74
|
"eslint-plugin-react-hooks": "^7.0.1",
|
|
74
75
|
"eslint-plugin-react-refresh": "^0.4.24",
|
|
75
76
|
"globals": "^16.5.0",
|
|
76
|
-
"gray-matter": "^4.0.3",
|
|
77
77
|
"lucide-react": "^0.554.0",
|
|
78
78
|
"postcss": "^8.5.6",
|
|
79
79
|
"tailwind-merge": "^3.4.0",
|
package/plugin/src/client.tsx
CHANGED
|
@@ -179,7 +179,7 @@ export function useFileContent(path: string) {
|
|
|
179
179
|
if (err instanceof Error && err.name === 'AbortError') {
|
|
180
180
|
return; // Ignore abort errors
|
|
181
181
|
}
|
|
182
|
-
setError(err instanceof Error ? err :
|
|
182
|
+
setError(err instanceof Error ? err.message : 'Unknown error');
|
|
183
183
|
} finally {
|
|
184
184
|
setLoading(false);
|
|
185
185
|
}
|
package/plugin/src/plugin.ts
CHANGED
|
@@ -5,12 +5,34 @@ import { buildAll } from './lib'
|
|
|
5
5
|
import chokidar from 'chokidar'
|
|
6
6
|
import type { IncomingMessage, ServerResponse } from 'http'
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
+
|
|
27
|
+
export default function contentPlugin(inputDir: string): Plugin {
|
|
28
|
+
|
|
29
|
+
if (!inputDir) {
|
|
11
30
|
throw new Error('Content directory must be specified.')
|
|
12
31
|
}
|
|
13
32
|
|
|
33
|
+
// Resolve dir to absolute path from user's cwd
|
|
34
|
+
const dir = path.isAbsolute(inputDir) ? inputDir : path.resolve(process.cwd(), inputDir)
|
|
35
|
+
|
|
14
36
|
const buildFn = () => buildAll([dir])
|
|
15
37
|
|
|
16
38
|
let watchers: chokidar.FSWatcher[] = []
|
|
@@ -105,5 +127,19 @@ export default function contentPlugin(dir: string): Plugin {
|
|
|
105
127
|
await Promise.all(watchers.map(w => w.close()))
|
|
106
128
|
watchers = []
|
|
107
129
|
},
|
|
130
|
+
writeBundle(options) {
|
|
131
|
+
// Copy content directory to dist/raw during production build
|
|
132
|
+
const outDir = options.dir || 'dist'
|
|
133
|
+
const destDir = path.join(outDir, 'raw')
|
|
134
|
+
|
|
135
|
+
console.log(`Copying content from ${dir} to ${destDir}`)
|
|
136
|
+
|
|
137
|
+
if (fs.existsSync(dir)) {
|
|
138
|
+
copyDirSync(dir, destDir)
|
|
139
|
+
console.log(`Content copied successfully`)
|
|
140
|
+
} else {
|
|
141
|
+
console.warn(`Content directory not found: ${dir}`)
|
|
142
|
+
}
|
|
143
|
+
},
|
|
108
144
|
}
|
|
109
145
|
}
|
package/test-content/.vesl.json
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"type": "directory",
|
|
3
|
-
"name": "test-content",
|
|
4
|
-
"path": ".",
|
|
5
|
-
"children": [
|
|
6
|
-
{
|
|
7
|
-
"type": "file",
|
|
8
|
-
"name": "README.md",
|
|
9
|
-
"path": "README.md",
|
|
10
|
-
"size": 472
|
|
11
|
-
},
|
|
12
|
-
{
|
|
13
|
-
"type": "directory",
|
|
14
|
-
"name": "test-slides",
|
|
15
|
-
"path": "test-slides",
|
|
16
|
-
"children": [
|
|
17
|
-
{
|
|
18
|
-
"type": "file",
|
|
19
|
-
"name": "SLIDES.mdx",
|
|
20
|
-
"path": "test-slides/SLIDES.mdx",
|
|
21
|
-
"size": 122,
|
|
22
|
-
"frontmatter": {
|
|
23
|
-
"title": "Test Slides",
|
|
24
|
-
"description": "These are test slides for testing purposes.",
|
|
25
|
-
"date": "2024-06-15"
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
]
|
|
29
|
-
},
|
|
30
|
-
{
|
|
31
|
-
"type": "directory",
|
|
32
|
-
"name": "test-post",
|
|
33
|
-
"path": "test-post",
|
|
34
|
-
"children": [
|
|
35
|
-
{
|
|
36
|
-
"type": "file",
|
|
37
|
-
"name": "README.mdx",
|
|
38
|
-
"path": "test-post/README.mdx",
|
|
39
|
-
"size": 115,
|
|
40
|
-
"frontmatter": {
|
|
41
|
-
"title": "Test Post",
|
|
42
|
-
"description": "This is a test post for testing purposes.",
|
|
43
|
-
"date": "2024-06-15"
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
]
|
|
47
|
-
}
|
|
48
|
-
]
|
|
49
|
-
}
|