@abi-software/simulationvuer 2.0.5 → 2.0.7

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