0
Fork 0
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:
María Valderrama 2024-03-01 12:38:42 +01:00
parent 6616fc45c8
commit a33e185146
16 changed files with 124 additions and 53 deletions

View file

@ -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}"]
}
]
}
}
]

View file

@ -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"

View file

@ -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": []
}

View file

@ -1 +1,2 @@
export * from './lib/plugins-data-parser';
export { parse } from './lib/utils';
export * from './lib/models';

View 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>;
}

View file

@ -1 +1,4 @@
export * from './parsed-file.model';
export * from './parsed.model';
export * from './utils.model';
export * from './file.model';
export * from './page.model';

View 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>;
}

View file

@ -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 {

View file

@ -0,0 +1,11 @@
export interface Name {
name: string;
}
export interface Uuid {
uuid: string;
}
export interface Arr {
arr: unknown[];
}

View file

@ -1,2 +0,0 @@
export { parseFile } from './utils';
export * from './models';

View file

@ -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
*/

View file

@ -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;
}

View file

@ -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"

View file

@ -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"]

View 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: [],
},
},
});

View file

@ -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/*"]
}