From a33e1851467cfe352f8db4345fd65693622da718 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Valderrama?= Date: Fri, 1 Mar 2024 12:38:42 +0100 Subject: [PATCH] feat: parser library --- libs/plugins-data-parser/.eslintrc.json | 7 ++- libs/plugins-data-parser/package.json | 4 +- libs/plugins-data-parser/project.json | 13 +---- libs/plugins-data-parser/src/index.ts | 3 +- .../src/lib/models/file.model.ts | 13 +++++ .../src/lib/models/index.ts | 5 +- .../src/lib/models/page.model.ts | 7 +++ .../{parsed-file.model.ts => parsed.model.ts} | 17 ++++--- .../src/lib/models/utils.model.ts | 11 +++++ .../src/lib/plugins-data-parser.ts | 2 - .../src/lib/utils/parse-arr.util.ts | 13 +---- .../src/lib/utils/parse.util.ts | 8 ++-- libs/plugins-data-parser/tsconfig.json | 22 ++++++--- libs/plugins-data-parser/tsconfig.lib.json | 2 +- libs/plugins-data-parser/vite.config.ts | 47 +++++++++++++++++++ tsconfig.base.json | 3 +- 16 files changed, 124 insertions(+), 53 deletions(-) create mode 100644 libs/plugins-data-parser/src/lib/models/file.model.ts create mode 100644 libs/plugins-data-parser/src/lib/models/page.model.ts rename libs/plugins-data-parser/src/lib/models/{parsed-file.model.ts => parsed.model.ts} (84%) create mode 100644 libs/plugins-data-parser/src/lib/models/utils.model.ts delete mode 100644 libs/plugins-data-parser/src/lib/plugins-data-parser.ts create mode 100644 libs/plugins-data-parser/vite.config.ts diff --git a/libs/plugins-data-parser/.eslintrc.json b/libs/plugins-data-parser/.eslintrc.json index adbe7ae..0dc93dd 100644 --- a/libs/plugins-data-parser/.eslintrc.json +++ b/libs/plugins-data-parser/.eslintrc.json @@ -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}"] + } + ] } } ] diff --git a/libs/plugins-data-parser/package.json b/libs/plugins-data-parser/package.json index a59ea4c..b1aaaf2 100644 --- a/libs/plugins-data-parser/package.json +++ b/libs/plugins-data-parser/package.json @@ -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" diff --git a/libs/plugins-data-parser/project.json b/libs/plugins-data-parser/project.json index dfa4f3a..42c2e24 100644 --- a/libs/plugins-data-parser/project.json +++ b/libs/plugins-data-parser/project.json @@ -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": [] } diff --git a/libs/plugins-data-parser/src/index.ts b/libs/plugins-data-parser/src/index.ts index 2ed39dd..0cef2bb 100644 --- a/libs/plugins-data-parser/src/index.ts +++ b/libs/plugins-data-parser/src/index.ts @@ -1 +1,2 @@ -export * from './lib/plugins-data-parser'; +export { parse } from './lib/utils'; +export * from './lib/models'; diff --git a/libs/plugins-data-parser/src/lib/models/file.model.ts b/libs/plugins-data-parser/src/lib/models/file.model.ts new file mode 100644 index 0000000..79436f3 --- /dev/null +++ b/libs/plugins-data-parser/src/lib/models/file.model.ts @@ -0,0 +1,13 @@ +import { Data, ParsedData } from '.'; + +export type FileDataType = + | 'colors' + | 'typographies' + | 'pages' + | 'media' + | 'pagesIndex' + | 'components'; + +export interface ParsedFile extends Omit { + data: Pick; +} diff --git a/libs/plugins-data-parser/src/lib/models/index.ts b/libs/plugins-data-parser/src/lib/models/index.ts index cf28d34..a8621cd 100644 --- a/libs/plugins-data-parser/src/lib/models/index.ts +++ b/libs/plugins-data-parser/src/lib/models/index.ts @@ -1 +1,4 @@ -export * from './parsed-file.model'; +export * from './parsed.model'; +export * from './utils.model'; +export * from './file.model'; +export * from './page.model'; diff --git a/libs/plugins-data-parser/src/lib/models/page.model.ts b/libs/plugins-data-parser/src/lib/models/page.model.ts new file mode 100644 index 0000000..1db1b48 --- /dev/null +++ b/libs/plugins-data-parser/src/lib/models/page.model.ts @@ -0,0 +1,7 @@ +import { Data, ParsedData } from '.'; + +export type PageDataType = 'options' | 'objects' | 'name' | 'id'; + +export interface ParsedPage extends Omit { + data: Pick; +} diff --git a/libs/plugins-data-parser/src/lib/models/parsed-file.model.ts b/libs/plugins-data-parser/src/lib/models/parsed.model.ts similarity index 84% rename from libs/plugins-data-parser/src/lib/models/parsed-file.model.ts rename to libs/plugins-data-parser/src/lib/models/parsed.model.ts index 1ec71f1..7586370 100644 --- a/libs/plugins-data-parser/src/lib/models/parsed-file.model.ts +++ b/libs/plugins-data-parser/src/lib/models/parsed.model.ts @@ -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[]; - typographies: IdData[]; - pages: RootTail; // Tail is an array of uuid (string) + colors?: IdData[]; + typographies?: IdData[]; + pages?: RootTail; // Tail is an array of uuid (string) pagesIndex?: IdData[]; - components: IdData[]; + components?: IdData[]; media?: IdData[]; + options?: IdData