1. ts-meta-extract
In the following example we defined a custom function to serilize ts files.
ts-meta-extract
Package: ts-meta-extract
Last modified: Sun, 22 May 2022 07:27:01 GMT
Version: 0.7.3
Downloads: 9

Install

npm install ts-meta-extract
yarn add ts-meta-extract

Example

In the following example we defined a custom function to serilize ts files.

 import {
  serializeTsFiles,
  serializeVueFiles,
  customEntryFilters,
  customDecoratorSerilize
} from "ts-meta-extract";

export function customSerializeTsFiles(entries: string[]) {
  const output = serializeTsFiles(entries, {
    classEntryFilter: customEntryFilters.isDecoratedBy(["Component"]),
    serializeDecorator: customDecoratorSerilize.serializeLiteralDecorator(["Component", "Prop", "Inject"])
  });
  return output;
}

The function provide a custom serialization which meets two conditions:

  1. Only serialize classes decorated by decorator named by "Component"; (by defining classEntryFilter)

  2. Serialize all decorators named by "Component", "Prop" and "Inject". (by defining serializeDecorator)

Interface

serializeTsFiles(files, [config])recieves a dozens of entry files of typescript and extract all classes meta data into json string.The first parameter files is a string array for entry file names. And the second parameter config is an optional object contains hooks for some custom process.

The custom hooks includes:

  • classEntryFilter(node)accepts a class declaration node of type ts.ClassDeclaration, and return true if this class should be serialized. If no function was provided, all classes included in files will be serialized.

  • serializeDecorator(node)accepts a node of type ts.Decorator, and should return a string type. If a function is provided, the function will be use to serialize decorators.

  • compilerHostGenerator(compilerOptions)accepts a object of type ts.CompilerOptions, and return a object of type ts.CompilerHost. This is for some occasions that customising a compiler host for program generation is needed for some purpose like changing source file getter or customising module resolver.

serializeVueFiles(files, [config])is the same as serializeTsFiles except adding support of ".vue" vue single file components like files.

Dependencies

RELATED POST

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin