https://github.com/sinamfe/sina-meta-serialize
A tool to serialize meta data of ts classes in compiling stage.
https://github.com/sinamfe/sina-meta-serialize
compile design meta-data serialization typescript
Last synced: 9 months ago
JSON representation
A tool to serialize meta data of ts classes in compiling stage.
- Host: GitHub
- URL: https://github.com/sinamfe/sina-meta-serialize
- Owner: SinaMFE
- Created: 2019-04-08T08:19:55.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2019-12-24T07:07:26.000Z (about 6 years ago)
- Last Synced: 2025-04-02T20:11:16.492Z (10 months ago)
- Topics: compile, design, meta-data, serialization, typescript
- Language: TypeScript
- Size: 118 KB
- Stars: 7
- Watchers: 5
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# sina-meta-serialize
A tool to serilize classes in vue files and can be used for designer. All processes are in compiling stage.
## Usage
To serialize dozens of vue files:
```javascript
const {
customSerializeVueFiles,
} = require("sina-meta-serialize");
const fs = require("fs");
const path = require("path");
const glob = require("glob");
const config: CustomSerializerConfig = {
serializeDecoratorNameList: ["Component", "Prop", "Inject", "Design"],
entryDecoratorFilters: ["Component"],
withSinaFormatTransformer: true
};
function main() {
const output = customSerializeVueFiles(["./src/index.vue", "./src/card.vue"], config);
fs.writeFileSync("classes.json", JSON.stringify(output, undefined, 2));
}
main()
```
Or you can just pass a directory to a export function `customSerializeVueByDirectory`:
```javascript
const { customSerializeVueByDirectory } = require("sina-meta-serialize");
const fs = require("fs");
const path = require("path")
const config = {
serializeDecoratorNameList: [
"SComponent",
"Design",
"dataType"
],
entryDecoratorFilters: ["SComponent"],
withSinaFormatTransformer: true
};
main();
async function main() {
const output = await customSerializeVueByDirectory(path.join(__dirname, "./src"), config);
fs.writeFileSync("./result.json", JSON.stringify(output, undefined, 2));
}
```
## Interface
**customSerializeVueByDirectory**`(path, config)`accept a directory path and process all vue files in it. Parameter `path` is the location of target directory. Parameter `config` is some configuration to specify serialization functions.
`config` includes:
- **serializeDecoratorNameList**: Accept a string array to specify decorators which should be serialized.
- **entryDecoratorFilters**: Accept a string array to define decorators which entry class should be decorated by. Only classes with those decorators will be serialized.
- **withSinaFormatTransformer**: Accept a boolean. If this is `true` then the output will be transformed into format sina desire. Otherwise it will be normal format.