gardenjs 1.5.0 → 1.6.1
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/servegarden.js +16 -11
- package/package.json +3 -2
- package/src/codegenerator/base_generator.js +34 -3
- package/src/codegenerator/das_file_finder.js +31 -4
- package/src/codegenerator/watch.js +20 -11
- package/src/server.js +21 -2
package/bin/servegarden.js
CHANGED
|
@@ -249,6 +249,22 @@ export default {
|
|
|
249
249
|
${renderer}
|
|
250
250
|
},
|
|
251
251
|
|
|
252
|
+
// Option to generate component names in the component tree from dasFileName using your own function. e.g.:
|
|
253
|
+
// getComponentName: (dasFileName) => {
|
|
254
|
+
// return dasFileName.substring(0, dasFileName.indexOf('.das')
|
|
255
|
+
// }
|
|
256
|
+
//
|
|
257
|
+
// Option to generate component file names from dasFileName using your own function. Must return an array. First match will be used. e.g.:
|
|
258
|
+
// getComponentFileNames: (dasFileName) => {
|
|
259
|
+
// const nameWithoutExtension = dasFileName.substring(0, dasFileName.indexOf('.das')
|
|
260
|
+
// return [
|
|
261
|
+
// nameWithoutExtension + '.svelte',
|
|
262
|
+
// nameWithoutExtension + '.vue',
|
|
263
|
+
// nameWithoutExtension + '.tsx',
|
|
264
|
+
// nameWithoutExtension,
|
|
265
|
+
// ]
|
|
266
|
+
// }
|
|
267
|
+
|
|
252
268
|
// Add global style files needed for your project:
|
|
253
269
|
// additional_style_files: [
|
|
254
270
|
// 'src/assets/scss/main.scss'
|
|
@@ -336,19 +352,8 @@ ${viteLibs.importStmts.join('\n')}
|
|
|
336
352
|
export default defineConfig(({ command, mode }) => {
|
|
337
353
|
return {
|
|
338
354
|
plugins: [${viteLibs.pluginStmts.join(', ')}],
|
|
339
|
-
root: ".garden",
|
|
340
|
-
assetsInclude: ['**/*.md'],
|
|
341
|
-
publicDir: "../public",
|
|
342
355
|
${sveltekit_alias}
|
|
343
356
|
${optimizeDeps}
|
|
344
|
-
build: {
|
|
345
|
-
rollupOptions: {
|
|
346
|
-
input: {
|
|
347
|
-
app: ".garden/index.html",
|
|
348
|
-
frame: ".garden/frame.html",
|
|
349
|
-
},
|
|
350
|
-
},
|
|
351
|
-
},
|
|
352
357
|
};
|
|
353
358
|
});
|
|
354
359
|
`
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gardenjs",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.1",
|
|
4
4
|
"description": "A component library explorer for UI development, testing and documentation.",
|
|
5
5
|
"repository": "https://github.com/gardenjs/gardenjs",
|
|
6
6
|
"homepage": "https://gardenjs.org/",
|
|
@@ -52,8 +52,8 @@
|
|
|
52
52
|
"lint": "eslint src/."
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
|
-
"@sveltejs/vite-plugin-svelte": "6.1.0",
|
|
56
55
|
"@eslint/compat": "1.2.5",
|
|
56
|
+
"@sveltejs/vite-plugin-svelte": "6.1.0",
|
|
57
57
|
"eslint": "9.31.0",
|
|
58
58
|
"eslint-config-prettier": "10.1.5",
|
|
59
59
|
"eslint-plugin-svelte": "3.11.0",
|
|
@@ -70,6 +70,7 @@
|
|
|
70
70
|
"@inquirer/checkbox": "1.5.0",
|
|
71
71
|
"@inquirer/prompts": "3.3.0",
|
|
72
72
|
"@inquirer/select": "^2.0.0",
|
|
73
|
+
"chokidar": "^5.0.0",
|
|
73
74
|
"highlight.js": "11.11.1",
|
|
74
75
|
"marked": "4.3.0",
|
|
75
76
|
"node-watch": "0.7.4",
|
|
@@ -7,8 +7,14 @@ const pathRelativeToGarden = '../'
|
|
|
7
7
|
const destination = '.garden/'
|
|
8
8
|
|
|
9
9
|
export async function generateGardenBase() {
|
|
10
|
-
const {
|
|
11
|
-
|
|
10
|
+
const {
|
|
11
|
+
structure,
|
|
12
|
+
additional_style_files,
|
|
13
|
+
welcome_page,
|
|
14
|
+
devmodus,
|
|
15
|
+
getComponentFileNames,
|
|
16
|
+
getComponentName,
|
|
17
|
+
} = await getConfig()
|
|
12
18
|
const targetBaseFile = destination + 'base.js'
|
|
13
19
|
const targetComponentMapFile = destination + 'component_import_map.js'
|
|
14
20
|
const targetRawComponentMapFile = destination + 'raw_component_import_map.js'
|
|
@@ -18,8 +24,29 @@ export async function generateGardenBase() {
|
|
|
18
24
|
|
|
19
25
|
const basefolders = getDasBaseFolders(structure)
|
|
20
26
|
|
|
27
|
+
const defaultGetComponentFileNames = (dasFilename) => {
|
|
28
|
+
const name = dasFilename.substring(0, dasFilename.indexOf('.das'))
|
|
29
|
+
return [
|
|
30
|
+
name + '.svelte',
|
|
31
|
+
name + '.vue',
|
|
32
|
+
name + '.tsx',
|
|
33
|
+
name + '.jsx',
|
|
34
|
+
name + '.ts',
|
|
35
|
+
name + '.js',
|
|
36
|
+
name,
|
|
37
|
+
]
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const defaultGetComponentName = (dasFilename) => {
|
|
41
|
+
return dasFilename.substring(0, dasFilename.indexOf('.das'))
|
|
42
|
+
}
|
|
43
|
+
|
|
21
44
|
const cds = await basefolders.reduce(async (acc, basePathAndNode) => {
|
|
22
|
-
const filemetaAndDasArray = await findAndReadDasFiles(
|
|
45
|
+
const filemetaAndDasArray = await findAndReadDasFiles(
|
|
46
|
+
basePathAndNode,
|
|
47
|
+
getComponentName ?? defaultGetComponentName,
|
|
48
|
+
getComponentFileNames ?? defaultGetComponentFileNames
|
|
49
|
+
)
|
|
23
50
|
try {
|
|
24
51
|
return (await acc).concat(
|
|
25
52
|
filemetaAndDasArray.map(createComponentDescription)
|
|
@@ -267,6 +294,8 @@ function createComponentMapEntry(description) {
|
|
|
267
294
|
function createDasMapEntry(description) {
|
|
268
295
|
return `'${description.fullname}': {
|
|
269
296
|
...${description.fullname}Das,
|
|
297
|
+
name: '${description.name}',
|
|
298
|
+
file: '${description.file}',
|
|
270
299
|
${
|
|
271
300
|
description.decorators
|
|
272
301
|
? 'decorators: [' +
|
|
@@ -312,6 +341,7 @@ function createComponentDescription({
|
|
|
312
341
|
const file = das.file
|
|
313
342
|
? path.join(basepath, relativepath, das.file)
|
|
314
343
|
: undefined
|
|
344
|
+
const relativeFile = das.file
|
|
315
345
|
const dasfile = path.join(basepath, relativepath, filename)
|
|
316
346
|
const descriptionfile = das.description?.endsWith('.md')
|
|
317
347
|
? path.join(basepath, relativepath, das.description)
|
|
@@ -365,6 +395,7 @@ function createComponentDescription({
|
|
|
365
395
|
relativepath,
|
|
366
396
|
fullpath,
|
|
367
397
|
file,
|
|
398
|
+
relativeFile,
|
|
368
399
|
dasfile,
|
|
369
400
|
descriptionfile,
|
|
370
401
|
extension,
|
|
@@ -2,11 +2,19 @@ import fs from 'fs'
|
|
|
2
2
|
import path from 'path'
|
|
3
3
|
import { createHash } from 'crypto'
|
|
4
4
|
|
|
5
|
-
export async function findAndReadDasFiles(
|
|
5
|
+
export async function findAndReadDasFiles(
|
|
6
|
+
{ basepath, navbasenode },
|
|
7
|
+
getComponentName,
|
|
8
|
+
getComponentFileNames
|
|
9
|
+
) {
|
|
6
10
|
const uniqueNames = {}
|
|
7
11
|
const promises = (await findDasFiles(basepath)).map(async (file) => {
|
|
8
12
|
try {
|
|
9
|
-
const das = await readDasFile(
|
|
13
|
+
const das = await readDasFile(
|
|
14
|
+
file,
|
|
15
|
+
getComponentName,
|
|
16
|
+
getComponentFileNames
|
|
17
|
+
)
|
|
10
18
|
await validate(das, file)
|
|
11
19
|
makeNameUnique(das, navbasenode, file.relativepath, uniqueNames)
|
|
12
20
|
uniqueNames[navbasenode + file.relativepath + das.name] = true
|
|
@@ -157,7 +165,11 @@ async function findDasFiles(
|
|
|
157
165
|
})
|
|
158
166
|
}
|
|
159
167
|
|
|
160
|
-
async function readDasFile(
|
|
168
|
+
async function readDasFile(
|
|
169
|
+
{ filename, relativepath, basepath },
|
|
170
|
+
getComponentName,
|
|
171
|
+
getComponentFileNames
|
|
172
|
+
) {
|
|
161
173
|
let content = await fs.promises.readFile(
|
|
162
174
|
path.resolve(basepath, relativepath, filename),
|
|
163
175
|
{ encoding: 'utf-8' }
|
|
@@ -169,7 +181,22 @@ async function readDasFile({ filename, relativepath, basepath }) {
|
|
|
169
181
|
'?' +
|
|
170
182
|
createMd5Hash(content)
|
|
171
183
|
)
|
|
172
|
-
|
|
184
|
+
const dasContent = module.default
|
|
185
|
+
if (!dasContent.name) {
|
|
186
|
+
dasContent.name = getComponentName(filename)
|
|
187
|
+
}
|
|
188
|
+
if (!dasContent.file) {
|
|
189
|
+
const potentialFileNames = getComponentFileNames(filename)
|
|
190
|
+
let allFiles = await fs.promises.readdir(
|
|
191
|
+
path.resolve(basepath, relativepath)
|
|
192
|
+
)
|
|
193
|
+
dasContent.file = potentialFileNames.find((candidate) => {
|
|
194
|
+
return allFiles.some((file) => {
|
|
195
|
+
return file === candidate
|
|
196
|
+
})
|
|
197
|
+
}, null)
|
|
198
|
+
}
|
|
199
|
+
return dasContent
|
|
173
200
|
}
|
|
174
201
|
|
|
175
202
|
function createMd5Hash(str) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import chokidar from 'chokidar'
|
|
2
2
|
|
|
3
3
|
export function watch(directories, options = {}, onChange) {
|
|
4
4
|
directories.forEach((dir) => doWatch(dir, options, onChange))
|
|
@@ -6,17 +6,26 @@ export function watch(directories, options = {}, onChange) {
|
|
|
6
6
|
|
|
7
7
|
let waitForUpdate = false
|
|
8
8
|
|
|
9
|
+
const handleChange = (options, onChange) => (path) => {
|
|
10
|
+
if (waitForUpdate) {
|
|
11
|
+
return
|
|
12
|
+
}
|
|
13
|
+
if (watchFileType(path, options)) {
|
|
14
|
+
waitForUpdate = true
|
|
15
|
+
onChange()
|
|
16
|
+
setTimeout(() => (waitForUpdate = false), 400)
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
9
20
|
function doWatch(dir, options, onChange) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
})
|
|
21
|
+
const onChangeFunc = handleChange(options, onChange)
|
|
22
|
+
chokidar
|
|
23
|
+
.watch(dir)
|
|
24
|
+
.on('change', onChangeFunc)
|
|
25
|
+
.on('add', onChangeFunc)
|
|
26
|
+
.on('addDir', onChangeFunc)
|
|
27
|
+
.on('unlink', onChangeFunc)
|
|
28
|
+
.on('unlinkDir', onChangeFunc)
|
|
20
29
|
}
|
|
21
30
|
|
|
22
31
|
function watchFileType(filename, options) {
|
package/src/server.js
CHANGED
|
@@ -15,17 +15,33 @@ export async function createServer() {
|
|
|
15
15
|
const configFile = vite_config || './vite.config.js'
|
|
16
16
|
|
|
17
17
|
const server = await createViteServer({
|
|
18
|
-
configFile,
|
|
18
|
+
configFile: configFile,
|
|
19
|
+
root: path.resolve('.garden'),
|
|
20
|
+
base: '/',
|
|
21
|
+
assetsInclude: ['**/*.md'],
|
|
22
|
+
publicDir: '../public',
|
|
19
23
|
optimizeDeps: {
|
|
20
24
|
noDiscovery: true,
|
|
21
25
|
},
|
|
26
|
+
build: {
|
|
27
|
+
rollupOptions: {
|
|
28
|
+
input: {
|
|
29
|
+
app: path.resolve('.garden/index.html'),
|
|
30
|
+
frame: path.resolve('.garden/frame.html'),
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
},
|
|
22
34
|
server: {
|
|
23
35
|
port: serverport,
|
|
24
36
|
fs: {
|
|
25
|
-
|
|
37
|
+
allow: [path.resolve('.garden')],
|
|
38
|
+
},
|
|
39
|
+
watch: {
|
|
40
|
+
ignored: ['!**/.garden/**'],
|
|
26
41
|
},
|
|
27
42
|
},
|
|
28
43
|
})
|
|
44
|
+
|
|
29
45
|
await runWatch(server)
|
|
30
46
|
|
|
31
47
|
if (devmodus) {
|
|
@@ -33,6 +49,9 @@ export async function createServer() {
|
|
|
33
49
|
}
|
|
34
50
|
|
|
35
51
|
server.listen()
|
|
52
|
+
|
|
53
|
+
// vite-Bug, if we don't restart server.watch.ignored will not work
|
|
54
|
+
server.restart()
|
|
36
55
|
if (!no_open_browser) open(`http://localhost:${serverport}`)
|
|
37
56
|
}
|
|
38
57
|
|