mirror of
https://github.com/penpot/penpot-plugins.git
synced 2025-01-21 06:02:34 -05:00
feat: parser library
This commit is contained in:
parent
6616fc45c8
commit
a33e185146
16 changed files with 124 additions and 53 deletions
|
@ -18,7 +18,12 @@
|
|||
"files": ["*.json"],
|
||||
"parser": "jsonc-eslint-parser",
|
||||
"rules": {
|
||||
"@nx/dependency-checks": "error"
|
||||
"@nx/dependency-checks": [
|
||||
"error",
|
||||
{
|
||||
"ignoredFiles": ["{projectRoot}/vite.config.{js,ts,mjs,mts}"]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
{
|
||||
"name": "plugins-data-parser",
|
||||
"version": "0.0.1",
|
||||
"dependencies": {
|
||||
"tslib": "^2.3.0"
|
||||
},
|
||||
"dependencies": {},
|
||||
"type": "commonjs",
|
||||
"main": "./src/index.js",
|
||||
"typings": "./src/index.d.ts"
|
||||
|
|
|
@ -3,17 +3,6 @@
|
|||
"$schema": "../../node_modules/nx/schemas/project-schema.json",
|
||||
"sourceRoot": "libs/plugins-data-parser/src",
|
||||
"projectType": "library",
|
||||
"targets": {
|
||||
"build": {
|
||||
"executor": "@nx/js:tsc",
|
||||
"outputs": ["{options.outputPath}"],
|
||||
"options": {
|
||||
"outputPath": "dist/libs/plugins-data-parser",
|
||||
"main": "libs/plugins-data-parser/src/index.ts",
|
||||
"tsConfig": "libs/plugins-data-parser/tsconfig.lib.json",
|
||||
"assets": ["libs/plugins-data-parser/*.md"]
|
||||
}
|
||||
}
|
||||
},
|
||||
"targets": {},
|
||||
"tags": []
|
||||
}
|
||||
|
|
|
@ -1 +1,2 @@
|
|||
export * from './lib/plugins-data-parser';
|
||||
export { parse } from './lib/utils';
|
||||
export * from './lib/models';
|
||||
|
|
13
libs/plugins-data-parser/src/lib/models/file.model.ts
Normal file
13
libs/plugins-data-parser/src/lib/models/file.model.ts
Normal file
|
@ -0,0 +1,13 @@
|
|||
import { Data, ParsedData } from '.';
|
||||
|
||||
export type FileDataType =
|
||||
| 'colors'
|
||||
| 'typographies'
|
||||
| 'pages'
|
||||
| 'media'
|
||||
| 'pagesIndex'
|
||||
| 'components';
|
||||
|
||||
export interface ParsedFile extends Omit<ParsedData, 'data'> {
|
||||
data: Pick<Data, FileDataType>;
|
||||
}
|
|
@ -1 +1,4 @@
|
|||
export * from './parsed-file.model';
|
||||
export * from './parsed.model';
|
||||
export * from './utils.model';
|
||||
export * from './file.model';
|
||||
export * from './page.model';
|
||||
|
|
7
libs/plugins-data-parser/src/lib/models/page.model.ts
Normal file
7
libs/plugins-data-parser/src/lib/models/page.model.ts
Normal file
|
@ -0,0 +1,7 @@
|
|||
import { Data, ParsedData } from '.';
|
||||
|
||||
export type PageDataType = 'options' | 'objects' | 'name' | 'id';
|
||||
|
||||
export interface ParsedPage extends Omit<ParsedData, 'data'> {
|
||||
data: Pick<Data, PageDataType>;
|
||||
}
|
|
@ -1,18 +1,21 @@
|
|||
export interface ParsedFile {
|
||||
export interface ParsedData {
|
||||
id: string;
|
||||
name: string;
|
||||
data: FileData;
|
||||
data: Data;
|
||||
}
|
||||
|
||||
export interface FileData {
|
||||
export interface Data {
|
||||
id: string;
|
||||
version: number;
|
||||
colors: IdData<Color>[];
|
||||
typographies: IdData<Typhography>[];
|
||||
pages: RootTail<unknown, string[]>; // Tail is an array of uuid (string)
|
||||
colors?: IdData<Color>[];
|
||||
typographies?: IdData<Typhography>[];
|
||||
pages?: RootTail<unknown, string[]>; // Tail is an array of uuid (string)
|
||||
pagesIndex?: IdData<PageIndex>[];
|
||||
components: IdData<Components>[];
|
||||
components?: IdData<Components>[];
|
||||
media?: IdData<Media>[];
|
||||
options?: IdData<Option>[];
|
||||
objects?: IdData<ObjectI>[];
|
||||
name?: string;
|
||||
}
|
||||
|
||||
export interface Color {
|
11
libs/plugins-data-parser/src/lib/models/utils.model.ts
Normal file
11
libs/plugins-data-parser/src/lib/models/utils.model.ts
Normal file
|
@ -0,0 +1,11 @@
|
|||
export interface Name {
|
||||
name: string;
|
||||
}
|
||||
|
||||
export interface Uuid {
|
||||
uuid: string;
|
||||
}
|
||||
|
||||
export interface Arr {
|
||||
arr: unknown[];
|
||||
}
|
|
@ -1,2 +0,0 @@
|
|||
export { parseFile } from './utils';
|
||||
export * from './models';
|
|
@ -1,18 +1,7 @@
|
|||
import { Arr, Name, Uuid } from '../models';
|
||||
import { isObject, toCamelCase } from './object.util';
|
||||
import { isSingleObjectWithProperty } from './parse-properties.util';
|
||||
|
||||
interface Name {
|
||||
name: string;
|
||||
}
|
||||
|
||||
interface Uuid {
|
||||
uuid: string;
|
||||
}
|
||||
|
||||
interface Arr {
|
||||
arr: unknown[];
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if "arr" property can be turned into an object
|
||||
*/
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { ParsedFile } from '../models/parsed-file.model';
|
||||
import { ParsedData } from '../models/parsed.model';
|
||||
import { isObject, toCamelCase } from './object.util';
|
||||
import { flattenNestedArrays, parseObjArr } from './parse-arr.util';
|
||||
import {
|
||||
|
@ -87,8 +87,8 @@ export function parseObject(obj: unknown): unknown {
|
|||
}
|
||||
|
||||
/**
|
||||
* Parse a file object into a more typescript friendly object
|
||||
* Parse object into a more typescript friendly object
|
||||
*/
|
||||
export function parseFile(file: unknown): ParsedFile {
|
||||
return parseObject(cleanObject(file)) as ParsedFile;
|
||||
export function parse(file: unknown): ParsedData {
|
||||
return parseObject(cleanObject(file)) as ParsedData;
|
||||
}
|
||||
|
|
|
@ -1,16 +1,24 @@
|
|||
{
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"target": "ESNext",
|
||||
"useDefineForClassFields": true,
|
||||
"module": "ESNext",
|
||||
"strict": true,
|
||||
"noImplicitOverride": true,
|
||||
"noPropertyAccessFromIndexSignature": true,
|
||||
"noImplicitReturns": true,
|
||||
"noFallthroughCasesInSwitch": true
|
||||
"moduleResolution": "Node",
|
||||
"resolveJsonModule": true,
|
||||
"isolatedModules": true,
|
||||
"types": ["vite/client"],
|
||||
"noEmit": true,
|
||||
"lib": ["ESNext", "DOM"],
|
||||
"skipLibCheck": true,
|
||||
"esModuleInterop": true,
|
||||
"noUnusedLocals": true,
|
||||
"noUnusedParameters": true,
|
||||
"noImplicitReturns": true
|
||||
},
|
||||
"files": [],
|
||||
"include": [],
|
||||
"include": ["src"],
|
||||
"references": [
|
||||
{
|
||||
"path": "./tsconfig.lib.json"
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
"compilerOptions": {
|
||||
"outDir": "../../dist/out-tsc",
|
||||
"declaration": true,
|
||||
"types": ["node"]
|
||||
"types": ["node", "vite/client"]
|
||||
},
|
||||
"include": ["src/**/*.ts"],
|
||||
"exclude": ["src/**/*.spec.ts", "src/**/*.test.ts"]
|
||||
|
|
47
libs/plugins-data-parser/vite.config.ts
Normal file
47
libs/plugins-data-parser/vite.config.ts
Normal file
|
@ -0,0 +1,47 @@
|
|||
/// <reference types='vitest' />
|
||||
import { defineConfig } from 'vite';
|
||||
import dts from 'vite-plugin-dts';
|
||||
import * as path from 'path';
|
||||
import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';
|
||||
|
||||
export default defineConfig({
|
||||
root: __dirname,
|
||||
cacheDir: '../node_modules/.vite/plugins-data-parser',
|
||||
|
||||
plugins: [
|
||||
nxViteTsPaths(),
|
||||
dts({
|
||||
entryRoot: 'src',
|
||||
tsConfigFilePath: path.join(__dirname, 'tsconfig.lib.json'),
|
||||
skipDiagnostics: true,
|
||||
}),
|
||||
],
|
||||
|
||||
// Uncomment this if you are using workers.
|
||||
// worker: {
|
||||
// plugins: [ nxViteTsPaths() ],
|
||||
// },
|
||||
|
||||
// Configuration for building your library.
|
||||
// See: https://vitejs.dev/guide/build.html#library-mode
|
||||
build: {
|
||||
outDir: '../../dist/libs/plugins-data-parser',
|
||||
reportCompressedSize: true,
|
||||
commonjsOptions: {
|
||||
transformMixedEsModules: true,
|
||||
},
|
||||
lib: {
|
||||
// Could also be a dictionary or array of multiple entry points.
|
||||
entry: 'src/index.ts',
|
||||
name: 'plugins-data-parser',
|
||||
fileName: 'index',
|
||||
// Change this to the formats you want to support.
|
||||
// Don't forget to update your package.json as well.
|
||||
formats: ['es', 'cjs'],
|
||||
},
|
||||
rollupOptions: {
|
||||
// External packages that should not be bundled into your library.
|
||||
external: [],
|
||||
},
|
||||
},
|
||||
});
|
|
@ -15,8 +15,7 @@
|
|||
"skipDefaultLibCheck": true,
|
||||
"baseUrl": ".",
|
||||
"paths": {
|
||||
"plugins-data-parser": ["libs/plugins-data-parser/src/index.ts"],
|
||||
"plugins-parser": ["libs/plugins-parser/src/index.ts"],
|
||||
"plugins-parser": ["libs/plugins-data-parser/src/index.ts"],
|
||||
"plugins-runtime": ["libs/plugins-runtime/src/index.ts"],
|
||||
"plugins-styles/*": ["libs/plugins-styles/src/*"]
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue