@abi-software/scaffoldvuer 1.4.1 → 1.5.0

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.
@@ -8,7 +8,8 @@
8
8
  import fs from 'fs'
9
9
  import path from 'path'
10
10
  import chokidar from 'chokidar'
11
- import { parser } from '@vuese/parser'
11
+ // import { parser } from '@vuese/parser'
12
+ import { parseSource } from 'vue-docgen-api'
12
13
  import { Render } from '@vuese/markdown-render'
13
14
 
14
15
  const watchMode = process.argv.find((argv) => argv === 'watch')
@@ -22,29 +23,87 @@ function generateMarkdown(file) {
22
23
  const fileContent = fs.readFileSync(fileWithPath, 'utf-8')
23
24
 
24
25
  try {
25
- const parserResult = parser(fileContent)
26
- const r = new Render(parserResult)
27
- const renderResult = r.render()
28
- const markdownResult = r.renderMarkdown()
29
- const markdownContent = markdownResult.content
30
- const componentName = path.basename(fileWithPath, '.vue')
31
-
32
- if (!fs.existsSync(outputDir)) {
33
- fs.mkdirSync(outputDir)
34
- }
26
+ // const parserResult = parser(fileContent)
27
+ const parserResult = parseSource(fileContent, fileWithPath)
28
+ parserResult.then((result) => {
29
+ const {
30
+ displayName: name,
31
+ description: desc,
32
+ props,
33
+ events,
34
+ methods
35
+ } = result
36
+
37
+ // transform props to vuese styles
38
+ const parseResult = {
39
+ name: name,
40
+ componentDesc: {
41
+ default: [desc]
42
+ },
43
+ props: transformData(props),
44
+ events: transformData(events),
45
+ methods: transformData(methods),
46
+ }
47
+ const r = new Render(parseResult)
48
+ const renderResult = r.render()
49
+ const markdownResult = r.renderMarkdown()
50
+ const markdownContent = markdownResult.content
51
+ const componentName = path.basename(fileWithPath, '.vue')
35
52
 
36
- fs.writeFile(`${outputDir}/${componentName}.md`, markdownContent, (err) => {
37
- if (err) {
38
- console.error(`Error writing markdown file for ${componentName}`, err)
39
- } else {
40
- console.log(`Markdown file for ${componentName} is generated!`)
53
+ if (!fs.existsSync(outputDir)) {
54
+ fs.mkdirSync(outputDir)
41
55
  }
56
+
57
+ fs.writeFile(`${outputDir}/${componentName}.md`, markdownContent, (err) => {
58
+ if (err) {
59
+ console.error(`Error writing markdown file for ${componentName}`, err)
60
+ } else {
61
+ console.log(`Markdown file for ${componentName} is generated!`)
62
+ }
63
+ })
42
64
  })
43
65
  } catch(e) {
44
66
  console.error(e)
45
67
  }
46
68
  }
47
69
 
70
+ function transformData(data = []) {
71
+ data.forEach((prop) => {
72
+ prop.name = prop.name
73
+
74
+ if (prop.description) {
75
+ prop.describe = [prop.description.replaceAll('\n', ' ')]
76
+ }
77
+
78
+ if (prop.type) {
79
+ prop.type = prop.type.name
80
+ }
81
+
82
+ if (prop.defaultValue) {
83
+ prop.default = prop.defaultValue.value.replaceAll('\n', ' ')
84
+ }
85
+
86
+ // events
87
+ if (prop.properties) {
88
+ prop.argumentsDesc = []
89
+ prop.properties.forEach((param) => {
90
+ const argName = param.name || param.description
91
+ prop.argumentsDesc.push(argName)
92
+ })
93
+ }
94
+
95
+ // methods
96
+ if (prop.params) {
97
+ prop.argumentsDesc = []
98
+ prop.params.forEach((param) => {
99
+ const argName = param.description || param.name
100
+ prop.argumentsDesc.push(argName)
101
+ })
102
+ }
103
+ })
104
+ return data
105
+ }
106
+
48
107
  // To generate markdown files - one time
49
108
  components.forEach((component) => {
50
109
  console.log(`Write markdown file for ${component} on first load.`)