vue-component-meta
## Usage
Last updated 4 years ago by johnsoncodehk .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install vue-component-meta 
SYNC missed versions from official npm registry.

vue-component-meta

NPM version License

Statically extract metadata such as props, events, slots, and exposed from Vue components. Useful for auto-generating component documentation or displaying component APIs in tools like Storybook.

Installation

npm install vue-component-meta typescript

Usage

Create a Checker from tsconfig.json

import { createChecker } from 'vue-component-meta';

const checker = createChecker('/path/to/tsconfig.json', {
  schema: true, // Enable schema parsing
});

const meta = checker.getComponentMeta('/path/to/MyComponent.vue');

Create a Checker from JSON Configuration

import { createCheckerByJson } from 'vue-component-meta';

const checker = createCheckerByJson('/project/root', {
  include: ['src/**/*.vue'],
  compilerOptions: { /* ... */ },
  vueCompilerOptions: { /* ... */ },
});

API

checker.getComponentMeta(filePath, exportName?)

Get the metadata of a component. exportName defaults to 'default'.

The returned ComponentMeta object contains:

interface ComponentMeta {
  name?: string;
  description?: string;
  type: TypeMeta;
  props: PropertyMeta[];
  events: EventMeta[];
  slots: SlotMeta[];
  exposed: ExposeMeta[];
}

checker.getExportNames(filePath)

Get all export names of a file.

checker.updateFile(filePath, content)

Update file content (for virtual files or live editing).

checker.deleteFile(filePath)

Remove a file from the project.

checker.reload()

Reload the tsconfig.json configuration.

checker.clearCache()

Clear cached file content.

checker.getProgram()

Get the underlying TypeScript Program instance.

Metadata Structures

PropertyMeta (Props)

interface PropertyMeta {
  name: string;
  description: string;      // Read from JSDoc
  type: string;             // Type string
  default?: string;         // Default value
  required: boolean;
  global: boolean;          // Whether it's a global prop
  tags: { name: string; text?: string }[];  // JSDoc tags
  schema: PropertyMetaSchema;
  getDeclarations(): Declaration[];
  getTypeObject(): ts.Type;
}

EventMeta

interface EventMeta {
  name: string;
  description: string;
  type: string;
  signature: string;
  tags: { name: string; text?: string }[];
  schema: PropertyMetaSchema[];
  getDeclarations(): Declaration[];
  getTypeObject(): ts.Type | undefined;
}

SlotMeta

interface SlotMeta {
  name: string;
  description: string;
  type: string;
  tags: { name: string; text?: string }[];
  schema: PropertyMetaSchema;
  getDeclarations(): Declaration[];
  getTypeObject(): ts.Type;
}

ExposeMeta

interface ExposeMeta {
  name: string;
  description: string;
  type: string;
  tags: { name: string; text?: string }[];
  schema: PropertyMetaSchema;
  getDeclarations(): Declaration[];
  getTypeObject(): ts.Type;
}

Options

interface MetaCheckerOptions {
  schema?: boolean | {
    ignore?: (string | ((name: string, type: ts.Type, typeChecker: ts.TypeChecker) => boolean))[];
  };
  printer?: ts.PrinterOptions;
}

schema

Controls whether to parse the schema structure of types. Set to true to enable, or pass an object to configure types to ignore.

const checker = createChecker(tsconfig, {
  schema: {
    ignore: ['HTMLElement', (name) => name.startsWith('Internal')],
  },
});

Related Packages

License

MIT License

Current Tags

  • 1.8.27                                ...           latest (2 years ago)

155 Versions

  • 1.8.27                                ...           2 years ago
  • 1.8.26                                ...           2 years ago
  • 1.8.25                                ...           2 years ago
  • 1.8.24                                ...           2 years ago
  • 1.9.0-alpha.3                                ...           2 years ago
  • 1.9.0-alpha.2                                ...           2 years ago
  • 1.9.0-alpha.1                                ...           2 years ago
  • 1.9.0-alpha.0                                ...           2 years ago
  • 1.8.22                                ...           2 years ago
  • 1.8.21                                ...           2 years ago
  • 1.8.20                                ...           2 years ago
  • 1.8.19                                ...           3 years ago
  • 1.8.18                                ...           3 years ago
  • 1.8.17                                ...           3 years ago
  • 1.8.16                                ...           3 years ago
  • 1.8.15                                ...           3 years ago
  • 1.8.14                                ...           3 years ago
  • 1.8.13                                ...           3 years ago
  • 1.8.12                                ...           3 years ago
  • 1.8.11                                ...           3 years ago
  • 1.8.10                                ...           3 years ago
  • 1.8.8                                ...           3 years ago
  • 1.8.7                                ...           3 years ago
  • 1.8.6                                ...           3 years ago
  • 1.8.5                                ...           3 years ago
  • 1.8.4                                ...           3 years ago
  • 1.8.3                                ...           3 years ago
  • 1.8.2                                ...           3 years ago
  • 1.8.1                                ...           3 years ago
  • 1.8.0-patch.1                                ...           3 years ago
  • 1.8.0                                ...           3 years ago
  • 1.7.14                                ...           3 years ago
  • 1.7.13                                ...           3 years ago
  • 1.7.12                                ...           3 years ago
  • 1.7.11                                ...           3 years ago
  • 1.7.10                                ...           3 years ago
  • 1.7.9                                ...           3 years ago
  • 1.7.8                                ...           3 years ago
  • 1.7.7                                ...           3 years ago
  • 1.7.6                                ...           3 years ago
  • 1.7.5                                ...           3 years ago
  • 1.7.4                                ...           3 years ago
  • 1.7.3                                ...           3 years ago
  • 1.6.5                                ...           3 years ago
  • 1.7.1                                ...           3 years ago
  • 1.7.0                                ...           3 years ago
  • 1.7.0-alpha.0                                ...           3 years ago
  • 1.6.4                                ...           3 years ago
  • 1.6.3                                ...           3 years ago
  • 1.6.2                                ...           3 years ago
  • 1.6.1                                ...           3 years ago
  • 1.6.0                                ...           3 years ago
  • 1.5.4                                ...           3 years ago
  • 1.5.3                                ...           3 years ago
  • 1.5.2                                ...           3 years ago
  • 1.5.1                                ...           3 years ago
  • 1.5.0                                ...           3 years ago
  • 1.4.4                                ...           3 years ago
  • 1.4.3                                ...           3 years ago
  • 1.4.2                                ...           3 years ago
  • 1.4.1                                ...           3 years ago
  • 1.4.0                                ...           3 years ago
  • 1.3.19                                ...           3 years ago
  • 1.3.18                                ...           3 years ago
  • 1.3.17                                ...           3 years ago
  • 1.3.16                                ...           3 years ago
  • 1.3.15                                ...           3 years ago
  • 1.3.14                                ...           3 years ago
  • 1.3.13                                ...           3 years ago
  • 1.3.12                                ...           3 years ago
  • 1.3.11                                ...           3 years ago
  • 1.3.10                                ...           3 years ago
  • 1.3.9                                ...           3 years ago
  • 1.3.8                                ...           3 years ago
  • 1.3.7                                ...           3 years ago
  • 1.3.6                                ...           3 years ago
  • 1.3.5                                ...           3 years ago
  • 1.3.4                                ...           3 years ago
  • 1.3.3                                ...           3 years ago
  • 1.3.2                                ...           3 years ago
  • 1.3.1                                ...           3 years ago
  • 1.3.0                                ...           3 years ago
  • 1.2.2-alpha.2                                ...           3 years ago
  • 1.2.2-alpha.1                                ...           3 years ago
  • 1.2.2-alpha.0                                ...           3 years ago
  • 1.2.1                                ...           3 years ago
  • 1.2.0                                ...           3 years ago
  • 1.1.7                                ...           3 years ago
  • 1.1.6                                ...           3 years ago
  • 1.1.5                                ...           3 years ago
  • 1.1.4                                ...           3 years ago
  • 1.1.3                                ...           3 years ago
  • 1.1.2                                ...           3 years ago
  • 1.1.0                                ...           3 years ago
  • 1.0.24                                ...           3 years ago
  • 1.0.22                                ...           3 years ago
  • 1.0.21                                ...           3 years ago
  • 1.0.20                                ...           3 years ago
  • 1.0.19                                ...           3 years ago
  • 1.0.18                                ...           3 years ago
  • 1.0.17                                ...           3 years ago
  • 1.0.16                                ...           3 years ago
  • 1.0.14                                ...           3 years ago
  • 1.0.13                                ...           3 years ago
  • 1.0.12                                ...           3 years ago
  • 1.0.11                                ...           3 years ago
  • 1.0.10                                ...           3 years ago
  • 1.0.9                                ...           3 years ago
  • 1.0.8                                ...           4 years ago
  • 1.0.7                                ...           4 years ago
  • 1.0.6                                ...           4 years ago
  • 1.0.5                                ...           4 years ago
  • 1.0.4                                ...           4 years ago
  • 1.0.3                                ...           4 years ago
  • 1.0.2                                ...           4 years ago
  • 1.0.1                                ...           4 years ago
  • 1.0.0                                ...           4 years ago
  • 1.0.0-rc.5                                ...           4 years ago
  • 1.0.0-rc.4                                ...           4 years ago
  • 1.0.0-rc.3                                ...           4 years ago
  • 1.0.0-rc.2                                ...           4 years ago
  • 1.0.0-rc.0                                ...           4 years ago
  • 1.0.0-beta.8                                ...           4 years ago
  • 1.0.0-beta.7                                ...           4 years ago
  • 1.0.0-beta.6                                ...           4 years ago
  • 1.0.0-beta.4                                ...           4 years ago
  • 1.0.0-beta.3                                ...           4 years ago
  • 1.0.0-beta.2                                ...           4 years ago
  • 1.0.0-beta.1                                ...           4 years ago
  • 1.0.0-beta.0                                ...           4 years ago
  • 1.0.0-alpha.5                                ...           4 years ago
  • 1.0.0-alpha.4                                ...           4 years ago
  • 1.0.0-alpha.3                                ...           4 years ago
  • 1.0.0-alpha.2                                ...           4 years ago
  • 1.0.0-alpha.1                                ...           4 years ago
  • 1.0.0-alpha.0                                ...           4 years ago
  • 0.40.13                                ...           4 years ago
  • 0.40.12                                ...           4 years ago
  • 0.40.11                                ...           4 years ago
  • 0.40.10                                ...           4 years ago
  • 0.40.9                                ...           4 years ago
  • 0.40.8                                ...           4 years ago
  • 0.40.7                                ...           4 years ago
  • 0.40.6                                ...           4 years ago
  • 0.40.5                                ...           4 years ago
  • 0.40.4                                ...           4 years ago
  • 0.40.3                                ...           4 years ago
  • 0.40.2                                ...           4 years ago
  • 0.40.1                                ...           4 years ago
  • 0.40.0                                ...           4 years ago
  • 0.39.5                                ...           4 years ago
  • 0.39.4                                ...           4 years ago
  • 0.39.3                                ...           4 years ago
  • 0.39.2                                ...           4 years ago
  • 0.39.0                                ...           4 years ago
Downloads
Today 0
This Week 1
This Month 4
Last Day 1
Last Week 0
Last Month 156
Dependencies (1)
Dev Dependencies (0)
None

Copyright 2013 - present © cnpmjs.org | Home |