From 1f66336c0d6ab429c74ea89cd2e5c80c8704d284 Mon Sep 17 00:00:00 2001 From: Volker Schmitt Date: Tue, 11 Mar 2025 12:14:12 +0100 Subject: [PATCH 1/4] -``` - -## Supported templates - -The rendering engine has been rewritten in v2, it can supports every JSDoc templates that exists. - -Actually, it supports 4 templates: -- Default -- [Docstrap](https://github.com/docstrap/docstrap) -- [Minami](https://github.com/nijikokun/minami) -- [Tui](https://github.com/nhnent/tui.jsdoc-template) - -If you use a template that is not supported, it will use the default one as a fallback. - -Feel free to open an issue/pull request if your template is not supported! - -
-Default - -![](./screenshots/templates/default.png) - -
- -
-Docstrap - -![](./screenshots/templates/docstrap.png) - -
- -
-Minami - -![](./screenshots/templates/minami.png) - -
- -
-Tui - -![](./screenshots/templates/tui.png) - -
- -## Testing - -### Install Dependencies - -```bash -$ git clone https://github.com/Kocal/jsdoc-vuejs -$ cd jsdoc-vuejs -$ yarn install - -# For testing the example docs -$ cd example -$ yarn install -``` - -#### Generate documentations - -```bash -$ cd example - -# Generate docs for every renderer -$ yarn docs:all - -# or one by one -$ yarn docs # default jsdoc template -$ yarn docs:docstrap -$ yarn docs:minami -$ yarn docs:tui -``` - -### Unit - -```bash -$ yarn test -``` - -### E2E - -Before running integration tests with [Cypress](https://cypress.io), -you should generate documentation with all renderers: - -```bash -$ cd example -$ yarn docs:all -``` - -And then run Cypress: - -```bash -$ cd .. -$ yarn cypress run -``` - -## License - -MIT. diff --git a/lib/core/seekExportDefaultLine.js b/lib/core/seekExportDefaultLine.js index 8bbe2629..3e5ad532 100644 --- a/lib/core/seekExportDefaultLine.js +++ b/lib/core/seekExportDefaultLine.js @@ -18,6 +18,10 @@ module.exports = function seekExportDefaultLine(source, filename) { if (inScript && /export\s+default/.test(line)) { return i + 1; // index starts at 0, but file's lines start at 1 } + + if (inScript && //.test(line)) { + return i; + } } return 0; diff --git a/lib/core/vueScriptExtractor.js b/lib/core/vueScriptExtractor.js index 7d501c6b..9e36a50b 100644 --- a/lib/core/vueScriptExtractor.js +++ b/lib/core/vueScriptExtractor.js @@ -4,7 +4,7 @@ const compiler = require('@vue/compiler-sfc'); module.exports = function extractVueScript(filename) { const source = fs.readFileSync(filename, 'utf8'); const parsedComponent = compiler.parse(source); - const scriptContent = parsedComponent.descriptor.script ? parsedComponent.descriptor.script.content : ''; - + let scriptContent = parsedComponent.descriptor.script ? parsedComponent.descriptor.script.content : null; + scriptContent ??= parsedComponent.descriptor.scriptSetup ? parsedComponent.descriptor.scriptSetup.content : ''; return scriptContent; }; From bfb8d94ca7ba21d483c43c5bb2752a069cdb7b3d Mon Sep 17 00:00:00 2001 From: Volker Schmitt Date: Tue, 11 Mar 2025 12:15:11 +0100 Subject: [PATCH 2/4] typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index eb24eee4..0bbd3982 100644 --- a/README.md +++ b/README.md @@ -2,5 +2,5 @@ This is a fork from JSDoc for VueJS [Kocal/jsdoc-vuejs](https://github.com/Kocal/jsdoc-vuejs) It adds ability to parse the ` +``` + +## Supported templates + +The rendering engine has been rewritten in v2, it can supports every JSDoc templates that exists. + +Actually, it supports 4 templates: +- Default +- [Docstrap](https://github.com/docstrap/docstrap) +- [Minami](https://github.com/nijikokun/minami) +- [Tui](https://github.com/nhnent/tui.jsdoc-template) + +If you use a template that is not supported, it will use the default one as a fallback. + +Feel free to open an issue/pull request if your template is not supported! + +
+Default + +![](./screenshots/templates/default.png) + +
+ +
+Docstrap + +![](./screenshots/templates/docstrap.png) + +
+ +
+Minami + +![](./screenshots/templates/minami.png) + +
+ +
+Tui + +![](./screenshots/templates/tui.png) + +
+ +## Testing + +### Install Dependencies + +```bash +$ git clone https://github.com/Kocal/jsdoc-vuejs +$ cd jsdoc-vuejs +$ yarn install + +# For testing the example docs +$ cd example +$ yarn install +``` + +#### Generate documentations + +```bash +$ cd example + +# Generate docs for every renderer +$ yarn docs:all + +# or one by one +$ yarn docs # default jsdoc template +$ yarn docs:docstrap +$ yarn docs:minami +$ yarn docs:tui +``` + +### Unit + +```bash +$ yarn test +``` + +### E2E + +Before running integration tests with [Cypress](https://cypress.io), +you should generate documentation with all renderers: + +```bash +$ cd example +$ yarn docs:all +``` + +And then run Cypress: + +```bash +$ cd .. +$ yarn cypress run +``` + +## License + +MIT. From bb458b39086b35906583d8eb05feb8736277d742 Mon Sep 17 00:00:00 2001 From: Volker Schmitt Date: Tue, 11 Mar 2025 13:17:29 +0100 Subject: [PATCH 4/4] test for script setup extruction added --- __tests__/core/__fixtures__/ComponentScriptSetup.vue | 10 ++++++++++ .../core/__snapshots__/vueScriptSetupExtractor.js.snap | 10 ++++++++++ __tests__/core/vueScriptSetupExtractor.js | 10 ++++++++++ 3 files changed, 30 insertions(+) create mode 100644 __tests__/core/__fixtures__/ComponentScriptSetup.vue create mode 100644 __tests__/core/__snapshots__/vueScriptSetupExtractor.js.snap create mode 100644 __tests__/core/vueScriptSetupExtractor.js diff --git a/__tests__/core/__fixtures__/ComponentScriptSetup.vue b/__tests__/core/__fixtures__/ComponentScriptSetup.vue new file mode 100644 index 00000000..f5f928d0 --- /dev/null +++ b/__tests__/core/__fixtures__/ComponentScriptSetup.vue @@ -0,0 +1,10 @@ + + + diff --git a/__tests__/core/__snapshots__/vueScriptSetupExtractor.js.snap b/__tests__/core/__snapshots__/vueScriptSetupExtractor.js.snap new file mode 100644 index 00000000..dd25df67 --- /dev/null +++ b/__tests__/core/__snapshots__/vueScriptSetupExtractor.js.snap @@ -0,0 +1,10 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`core.extractVueScript extract script 1`] = ` +" +/** + * @vue-event {String} foo - Emit foo event + */ + const emit = defineEmits(['foo']) +" +`; diff --git a/__tests__/core/vueScriptSetupExtractor.js b/__tests__/core/vueScriptSetupExtractor.js new file mode 100644 index 00000000..32f59059 --- /dev/null +++ b/__tests__/core/vueScriptSetupExtractor.js @@ -0,0 +1,10 @@ +const path = require('path'); +const extractVueScript = require('../../lib/core/vueScriptExtractor'); + +describe('core.extractVueScript', () => { + const filename = path.join(__dirname, '__fixtures__', 'ComponentScriptSetup.vue'); + + test('extract script', () => { + expect(extractVueScript(filename)).toMatchSnapshot(); + }); +});