Skip to content

Commit

Permalink
Pure ESM package
Browse files Browse the repository at this point in the history
  • Loading branch information
demsking committed May 4, 2022
1 parent a1bb080 commit 859fd2a
Show file tree
Hide file tree
Showing 86 changed files with 5,299 additions and 13,175 deletions.
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use nix
64 changes: 37 additions & 27 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,47 +4,53 @@ include:
- template: SAST.gitlab-ci.yml

stages:
- test
- tests
- security
- publish

code quality:
stage: test
stage: tests
script:
- npm ci
- npm run lint
- yarn install
- yarn run lint

npm outdated:
stage: test
dependencies outdated:
stage: tests
script:
- npm ci
- npm outdated
- yarn install
- yarn outdated
allow_failure: true

security scan:
stage: test
tests & coverage:
stage: tests
script:
- npm audit --production

test on nodejs lts:
stage: test
image: node:lts-alpine
script:
- npm it
coverage: '/All files[^|]*\|[^|]*\s+([\d\.]+)/'

test & coverage:
stage: test
script:
- npm it
- yarn install
- yarn test
coverage: '/All files[^|]*\|[^|]*\s+([\d\.]+)/'
artifacts:
paths:
- coverage/

dependencies check:
stage: security
needs: &tests-jobs
- code quality
- dependencies outdated
- tests & coverage
dependencies: *tests-jobs
script:
- yarn audit --production

sast:
stage: security
needs: *tests-jobs
dependencies: *tests-jobs

pages:
stage: publish
dependencies:
- test & coverage
needs: &security-jobs
- sast
dependencies: *security-jobs
script:
- mv coverage/lcov-report/ public/
artifacts:
Expand All @@ -58,20 +64,24 @@ pages:

package:
stage: publish
needs: *security-jobs
dependencies: *security-jobs
script:
- npm pack
- yarn pack
artifacts:
paths:
- ./*.tgz

publish:
stage: publish
needs: *security-jobs
dependencies: *security-jobs
only:
- tags
- triggers
script:
- echo '//registry.npmjs.org/:_authToken=${NPM_TOKEN}' > .npmrc
- npm publish
- yarn publish
environment:
name: npm
url: https://www.npmjs.com/package/@vuedoc/parser
31 changes: 16 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,13 @@ See [test/fixtures/checkbox.vue](https://gitlab.com/vuedoc/parser/blob/master/te
for an Vue Component decoration example.

```js
const Vuedoc = require('@vuedoc/parser')
import { parse } from '@vuedoc/parser';

const options = {
filename: 'test/fixtures/checkbox.vue'
}
};

Vuedoc.parse(options)
parse(options)
.then((component) => console.log(component))
.catch((err) => console.error(err))
```
Expand Down Expand Up @@ -835,12 +836,12 @@ To parse a mixin, you need to parse its file as a standalone component and then
merge the parsing result with the result of the initial component:

```js
const Vuedoc = require('@vuedoc/parser')
const merge = require('deepmerge')
import { parse } from '@vuedoc/parser';
import merge from 'deepmerge';

const parsers = [
Vuedoc.parse({ filename: 'mixinFile.js' })
Vuedoc.parse({ filename: 'componentUsingMixin.vue' })
parse({ filename: 'mixinFile.js' })
parse({ filename: 'componentUsingMixin.vue' })
]

Promise.all(parsers)
Expand Down Expand Up @@ -899,14 +900,14 @@ The default value is defined by `Vuedoc.Parser.SUPPORTED_FEATURES` array.
Only parse `name`, `props`, `computed properties`, `slots` and `events`:

```js
const Vuedoc = require('@vuedoc/parser')
import { parse } from '@vuedoc/parser';

const options = {
filename: 'test/fixtures/checkbox.vue',
features: [ 'name', 'props', 'computed', 'slots', 'events' ]
}

Vuedoc.parse(options)
parse(options)
.then((component) => Object.keys(component))
.then((keys) => console.log(keys))
// => [ 'name', 'props', 'computed', 'slots', 'events' ]
Expand All @@ -915,14 +916,14 @@ Vuedoc.parse(options)
Parse all features except `data`:

```js
const Vuedoc = require('@vuedoc/parser')
import { parse } from '@vuedoc/parser';

const options = {
filename: 'test/fixtures/checkbox.vue',
features: Vuedoc.Parser.SUPPORTED_FEATURES.filter((feature) => feature !== 'data')
}

Vuedoc.parse(options)
parse(options)
.then((component) => Object.keys(component))
.then((keys) => console.log(keys))
// => [ 'name', 'description', 'keywords', 'model',
Expand Down Expand Up @@ -967,9 +968,9 @@ specialized class to handle a template with the
It uses the built-in `PugLoader` to load Pug template:

```js
const Vuedoc = require('@vuedoc/parser')
const PugLoader = require('@vuedoc/parser/loader/pug')
const CoffeeScript = require('coffeescript')
import { parse } from '@vuedoc/parser';
import { PugLoader } from '@vuedoc/parser/loader/pug';
import CoffeeScript from 'coffeescript';

class CoffeeScriptLoader extends Vuedoc.Loader {
load (source) {
Expand Down Expand Up @@ -1010,7 +1011,7 @@ const options = {
]
}

Vuedoc.parse(options).then((component) => {
parse(options).then((component) => {
console.log(component)
})
```
Expand Down
42 changes: 24 additions & 18 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
const path = require('path');

const Loader = require('./lib/Loader');
const VueLoader = require('./loader/vue');
const HtmlLoader = require('./loader/html');
const JavaScriptLoader = require('./loader/javascript');
const TypeScriptLoader = require('./loader/typescript');

const { Parser } = require('./lib/parser/Parser');
const { Feature, DEFAULT_IGNORED_VISIBILITIES, DEFAULT_ENCODING } = require('./lib/Enum');
const { KeywordsUtils } = require('./lib/utils/KeywordsUtils');
import path from 'path';

import { Loader } from './lib/Loader';
import { Parser } from './lib/parser/Parser';
export { Loader } from './lib/Loader';
export { Parser } from './lib/parser/Parser';
import { VueLoader } from './loader/vue';
import { HtmlLoader } from './loader/html';
import { JavaScriptLoader } from './loader/javascript';
import { TypeScriptLoader } from './loader/typescript';
import { Feature, DEFAULT_IGNORED_VISIBILITIES, DEFAULT_ENCODING } from './lib/Enum';
import { KeywordsUtils } from './lib/utils/KeywordsUtils';

const DEFAULT_LOADERS = [
Loader.extend('js', JavaScriptLoader),
Expand All @@ -17,10 +18,7 @@ const DEFAULT_LOADERS = [
Loader.extend('vue', VueLoader)
];

module.exports.Loader = Loader;
module.exports.Parser = Parser;

module.exports.parseOptions = (options) => {
export function parseOptions(options) {
if (!options) {
/* eslint-disable max-len */
throw new Error('Missing options argument');
Expand Down Expand Up @@ -67,9 +65,9 @@ module.exports.parseOptions = (options) => {
} catch (e) {
return Promise.reject(e);
}
};
}

module.exports.parse = (options) => this.parseOptions(options).then(() => new Promise((resolve) => {
export const parse = (options) => parseOptions(options).then(() => new Promise((resolve) => {
const component = {
inheritAttrs: true,
errors: [],
Expand Down Expand Up @@ -122,7 +120,15 @@ module.exports.parse = (options) => this.parseOptions(options).then(() => new Pr

component[feature] = [];

parser.on(eventName, (entry) => component[feature].push(entry));
parser.on(eventName, (entry) => {
const index = component[feature].findIndex((item) => item.name === entry.name);

if (index > -1) {
component[feature].splice(index, 1, entry);
} else {
component[feature].push(entry);
}
});
}
}
});
Expand Down
18 changes: 18 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export default {
expand: true,
notify: false,
transform: {},
testMatch: [
'<rootDir>/test/**/*.spec.js'
],
collectCoverageFrom: [
'index.js',
'lib/**',
'schema/**',
'loader/**'
],
moduleFileExtensions: [
'js',
'json'
]
}
Loading

0 comments on commit 859fd2a

Please sign in to comment.