diff --git a/.env b/.env index 3e1a20f60..352ecb639 100644 --- a/.env +++ b/.env @@ -44,6 +44,9 @@ INFISICAL_ENVIRONMENT="prod" READINESS_CHECK_PATH="/readiness" HEALTH_CHECK_PATH="/healthcheck" +LOG_LEVEL="debug" +# LOG_PATH="C:\\Development\\open-system\\logs" + PNPM_VERSION="8.7.4" DEV_EDITOR_ID="vscode" diff --git a/apps/workers/contact-api/.dev.vars b/apps/workers/contact-api/.dev.vars index 5f06ac2d5..dc21e61d8 100644 --- a/apps/workers/contact-api/.dev.vars +++ b/apps/workers/contact-api/.dev.vars @@ -45,7 +45,11 @@ READINESS_CHECK_PATH="/readiness" HEALTH_CHECK_PATH="/healthcheck" LOG_LEVEL="debug" +LOG_PATH="C:\\Development\\open-system\\logs" PNPM_VERSION="8.7.4" -NODE_ENV=development +DEV_EDITOR_ID="vscode" +DEV_REPO_ROOT="C:\\Development\\open-system" + +NODE_ENV="development" diff --git a/apps/workers/contact-api/package.json b/apps/workers/contact-api/package.json index d035c6fb1..8bf8b4949 100644 --- a/apps/workers/contact-api/package.json +++ b/apps/workers/contact-api/package.json @@ -9,6 +9,7 @@ "fs": "0.0.1-security", "http": "0.0.1-security", "process": "^0.11.10", + "reflect-metadata": "^0.1.13", "wrangler": "^3.2.0", "zlib": "^1.0.5" } diff --git a/apps/workers/contact-api/src/dependencies.ts b/apps/workers/contact-api/src/dependencies.ts new file mode 100644 index 000000000..369ec38a8 --- /dev/null +++ b/apps/workers/contact-api/src/dependencies.ts @@ -0,0 +1,8 @@ +import { InfisicalEnvManager } from "@open-system/core-server-infisical/infisical-env-manager"; +import { EnvManager } from "@open-system/core-shared-env/env-manager"; +import { bindService } from "@open-system/core-shared-injection/utilities/bind-service"; +import { ConsoleLogger } from "@open-system/core-shared-logging/console"; +import { Logger } from "@open-system/core-shared-logging/logger"; + +bindService(EnvManager, InfisicalEnvManager); +bindService(Logger, ConsoleLogger); diff --git a/apps/workers/contact-api/src/index.ts b/apps/workers/contact-api/src/index.ts index 62c329a1b..ab7671619 100644 --- a/apps/workers/contact-api/src/index.ts +++ b/apps/workers/contact-api/src/index.ts @@ -1,6 +1,7 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ import "reflect-metadata"; +import "./dependencies"; import { InitialServerContext } from "@open-system/core-server-application"; import { CloudflareServerBindings } from "@open-system/core-server-cloudflare/types"; @@ -8,17 +9,12 @@ import { GraphQLActiveServerContext, GraphQLServerContext } from "@open-system/core-server-graphql/context"; -import { PinoLogger } from "@open-system/core-server-pino-logging"; -import { Injector } from "@open-system/core-shared-injection/injector"; -import { Logger } from "@open-system/core-shared-utilities/logging"; import { createServer } from "./server"; export interface Env extends CloudflareServerBindings { DB: any; } -Injector.bind(Logger).to(PinoLogger); - export default { async fetch( request: Request, diff --git a/apps/workers/contact-api/wrangler.toml b/apps/workers/contact-api/wrangler.toml index 8b10c7d16..923578ffc 100644 --- a/apps/workers/contact-api/wrangler.toml +++ b/apps/workers/contact-api/wrangler.toml @@ -1,6 +1,6 @@ name = "contact-api" # main = "src/index.ts" -main = "./index.mjs" +main = "./index.js" # ip = "127.0.0.1" # port = 4008 diff --git a/apps/workers/contact-attachments-upload/src/handler.ts b/apps/workers/contact-attachments-upload/src/handler.ts index df40a2914..7ba3cb4be 100644 --- a/apps/workers/contact-attachments-upload/src/handler.ts +++ b/apps/workers/contact-attachments-upload/src/handler.ts @@ -1,12 +1,12 @@ export { Headers } from "@open-system/core-client-data-access"; export { - BaseCloudflareEnv, + CloudflareServerBindings, R2Bucket, - R2ListOptions, -} from "@open-system/core-shared-cloudflare"; -export { ConsoleLogger } from "@open-system/core-shared-utilities"; + R2ListOptions +} from "@open-system/core-server-cloudflare"; +export { ConsoleLogger } from "@open-system/core-shared-logging"; -interface Env extends BaseCloudflareEnv { +interface Env extends CloudflareServerBindings { CONTACT_ATTACHMENTS_BUCKET: R2Bucket; } @@ -16,8 +16,8 @@ function objectNotFound(objectName: string): Response { { status: 404, headers: { - "content-type": "text/html; charset=UTF-8", - }, + "content-type": "text/html; charset=UTF-8" + } } ); } @@ -43,22 +43,22 @@ export async function handleRequest( prefix: url.searchParams.get("prefix") ?? undefined, delimiter: url.searchParams.get("delimiter") ?? undefined, cursor: url.searchParams.get("cursor") ?? undefined, - include: ["customMetadata", "httpMetadata"], + include: ["customMetadata", "httpMetadata"] }; ConsoleLogger.log(JSON.stringify(options)); const listing = await bucket.list(options); return new Response(JSON.stringify(listing), { headers: { - "content-type": "application/json; charset=UTF-8", - }, + "content-type": "application/json; charset=UTF-8" + } }); } if (request.method === "GET") { const object = await bucket.get(objectName, { range: request.headers, - onlyIf: request.headers, + onlyIf: request.headers }); if (object === null) { @@ -81,7 +81,7 @@ export async function handleRequest( : 304; return new Response(object.body, { headers, - status, + status }); } @@ -95,17 +95,17 @@ export async function handleRequest( object.writeHttpMetadata(headers); headers.set("etag", object.httpEtag); return new Response(null, { - headers, + headers }); } if (request.method === "PUT" || request.method == "POST") { const object = await bucket.put(objectName, request.body, { - httpMetadata: request.headers, + httpMetadata: request.headers }); return new Response(null, { headers: { - "etag": object.httpEtag, - }, + "etag": object.httpEtag + } }); } if (request.method === "DELETE") { @@ -114,6 +114,6 @@ export async function handleRequest( } return new Response(`Unsupported method`, { - status: 400, + status: 400 }); } diff --git a/libs/contact/typescript/server/attachment/src/plugins/use-extend-contact-graphql-server-context.ts b/libs/contact/typescript/server/attachment/src/plugins/use-extend-contact-graphql-server-context.ts index 135b5e946..0ae158eb2 100644 --- a/libs/contact/typescript/server/attachment/src/plugins/use-extend-contact-graphql-server-context.ts +++ b/libs/contact/typescript/server/attachment/src/plugins/use-extend-contact-graphql-server-context.ts @@ -10,6 +10,7 @@ import { GraphQLActiveServerContext, GraphQLServerContext } from "@open-system/core-server-graphql/context"; +import { bindService } from "@open-system/core-shared-injection/utilities/bind-service"; import { IContactAttachmentEntity, IContactEntity @@ -41,17 +42,14 @@ export const useExtendContactGraphQLServerContext = < async onContextBuilding(params) { const pluginHook = await basePlugin.onContextBuilding?.(params); - params.context.injector - .bind>( - Repository - ) - .to(ContactAttachmentRepository) - .inSingletonScope(); - - params.context.injector - .bind>(Repository) - .to(ContactRepository) - .inSingletonScope(); + bindService>( + Repository, + ContactAttachmentRepository + ); + bindService>( + Repository, + ContactRepository + ); return pluginHook; } diff --git a/libs/core/typescript/server/application/src/commands/command-factory.ts b/libs/core/typescript/server/application/src/commands/command-factory.ts index c1c420fd5..af2226fcc 100644 --- a/libs/core/typescript/server/application/src/commands/command-factory.ts +++ b/libs/core/typescript/server/application/src/commands/command-factory.ts @@ -1,5 +1,6 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ -import { Logger, UniqueIdGenerator } from "@open-system/core-shared-utilities"; +import { Logger } from "@open-system/core-shared-logging/logger"; +import { UniqueIdGenerator } from "@open-system/core-shared-utilities/common"; import { ICommand } from "./command"; export const commandFactory = diff --git a/libs/core/typescript/server/application/src/context/initial-context.ts b/libs/core/typescript/server/application/src/context/initial-context.ts index 970b919a0..ee086fa73 100644 --- a/libs/core/typescript/server/application/src/context/initial-context.ts +++ b/libs/core/typescript/server/application/src/context/initial-context.ts @@ -1,20 +1,18 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ import { IEntity } from "@open-system/core-server-domain"; import { EnvManager, EnvironmentType } from "@open-system/core-shared-env"; -import { Injector } from "@open-system/core-shared-injection/injector"; +import { Injector } from "@open-system/core-shared-injection/injector/injector"; import { Injector as InjectorType } from "@open-system/core-shared-injection/types"; +import { ConsoleLogger, Logger } from "@open-system/core-shared-logging"; import { JSON_PARSER_SYMBOL, JsonParser } from "@open-system/core-shared-serialization"; import { ArrayElement, - ConsoleLogger, DateTime, - Logger, UniqueIdGenerator } from "@open-system/core-shared-utilities"; -// import { ICommand } from "../commands"; import { Service } from "../services"; import { EntityName, SYSTEM_TOKEN } from "../types"; diff --git a/libs/core/typescript/server/application/src/providers/event-publisher.ts b/libs/core/typescript/server/application/src/providers/event-publisher.ts index 2511d9cde..a1a999340 100644 --- a/libs/core/typescript/server/application/src/providers/event-publisher.ts +++ b/libs/core/typescript/server/application/src/providers/event-publisher.ts @@ -1,5 +1,6 @@ import { IAggregateRoot, IDomainEvent } from "@open-system/core-server-domain"; -import { BaseUtilityClass, Logger } from "@open-system/core-shared-utilities"; +import { Logger } from "@open-system/core-shared-logging/logger"; +import { BaseUtilityClass } from "@open-system/core-shared-utilities/common"; import { EVENT_PUBLISHER_TOKEN } from "../types"; import { EventStore } from "./event-store"; import { MessageBroker } from "./message-broker"; diff --git a/libs/core/typescript/server/application/src/providers/event-store.ts b/libs/core/typescript/server/application/src/providers/event-store.ts index e1ffd7739..797d6954e 100644 --- a/libs/core/typescript/server/application/src/providers/event-store.ts +++ b/libs/core/typescript/server/application/src/providers/event-store.ts @@ -1,8 +1,8 @@ import { IAggregateRoot, IDomainEvent } from "@open-system/core-server-domain"; +import { Logger } from "@open-system/core-shared-logging/logger"; import { ArrayElement, - BaseUtilityClass, - Logger + BaseUtilityClass } from "@open-system/core-shared-utilities"; import { EVENT_STORE_TOKEN } from "../types"; diff --git a/libs/core/typescript/server/application/src/providers/message-broker.ts b/libs/core/typescript/server/application/src/providers/message-broker.ts index a15bacba9..1cc056531 100644 --- a/libs/core/typescript/server/application/src/providers/message-broker.ts +++ b/libs/core/typescript/server/application/src/providers/message-broker.ts @@ -1,4 +1,5 @@ -import { BaseUtilityClass, Logger } from "@open-system/core-shared-utilities"; +import { Logger } from "@open-system/core-shared-logging/logger"; +import { BaseUtilityClass } from "@open-system/core-shared-utilities/common"; import { MESSAGE_BROKER_TOKEN } from "../types"; export abstract class MessageBroker< diff --git a/libs/core/typescript/server/application/src/repositories/repository-data-loader.ts b/libs/core/typescript/server/application/src/repositories/repository-data-loader.ts index 5ad4b116a..41269d24c 100644 --- a/libs/core/typescript/server/application/src/repositories/repository-data-loader.ts +++ b/libs/core/typescript/server/application/src/repositories/repository-data-loader.ts @@ -1,11 +1,11 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ import { IEntity } from "@open-system/core-server-domain/types"; +import { Logger } from "@open-system/core-shared-logging/logger"; import { BaseUtilityClass, - Logger, isArrayLike, isEmpty -} from "@open-system/core-shared-utilities"; +} from "@open-system/core-shared-utilities/common"; import { MemCacheClient } from "../providers/mem-cache-client"; import { BatchLoadFn, diff --git a/libs/core/typescript/server/application/src/repositories/repository.ts b/libs/core/typescript/server/application/src/repositories/repository.ts index 13421ad6b..e11bac994 100644 --- a/libs/core/typescript/server/application/src/repositories/repository.ts +++ b/libs/core/typescript/server/application/src/repositories/repository.ts @@ -1,20 +1,20 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ import { IEntity } from "@open-system/core-server-domain"; -import { Provider } from "@open-system/core-shared-injection"; +import { EnvManager } from "@open-system/core-shared-env"; +import { Injected, Provider } from "@open-system/core-shared-injection"; +import { Logger } from "@open-system/core-shared-logging/logger"; import { JsonParser } from "@open-system/core-shared-serialization"; import { BaseErrorCode, BaseUtilityClass, FieldValidationError, IncorrectTypeError, - Logger, ModelValidationError, NotFoundError, isError, isValidInteger } from "@open-system/core-shared-utilities"; import { map } from "radash"; -import { ActiveContext, ServerContext } from "../context"; import { BatchLoadKey, CreateParams, @@ -43,13 +43,14 @@ export abstract class Repository< protected readonly options!: RepositoryOptions; protected readonly logger: Logger; - protected readonly active: ActiveContext; - constructor(context: ServerContext) { + constructor( + @Injected(Logger) _logger: Logger, + @Injected(EnvManager) _env: EnvManager + ) { super(REPOSITORY_TOKEN); - this.logger = context.utils.logger; - this.active = context.active; + this.logger = _logger; this.dataLoader = new RepositoryDataLoader( async ( @@ -58,7 +59,7 @@ export abstract class Repository< return map(keys, async (key: BatchLoadKey) => { key.take ??= isValidInteger(key.take, true) ? key.take - : context.env.defaultQuerySize; + : _env.defaultQuerySize; key.orderBy ??= { id: SortOrder.asc } as Record< EntityKeys, string @@ -74,7 +75,7 @@ export abstract class Repository< }, this.logger, this.options, - context.system.info.instanceId + _env.serviceId ); } diff --git a/libs/core/typescript/server/application/src/services/service.ts b/libs/core/typescript/server/application/src/services/service.ts index dd00dda63..52167f404 100644 --- a/libs/core/typescript/server/application/src/services/service.ts +++ b/libs/core/typescript/server/application/src/services/service.ts @@ -13,7 +13,7 @@ import { ModelValidationError, NotFoundError } from "@open-system/core-shared-utilities/errors"; -import { Logger } from "@open-system/core-shared-utilities/logging"; +import { Logger } from "@open-system/core-shared-logging"; import { UserContext } from "../context"; import { Repository } from "../repositories/repository"; import { diff --git a/libs/core/typescript/server/cloudflare/src/utilities/wrangler-deploy.ts b/libs/core/typescript/server/cloudflare/src/utilities/wrangler-deploy.ts index 802affdd2..5a09a6b48 100644 --- a/libs/core/typescript/server/cloudflare/src/utilities/wrangler-deploy.ts +++ b/libs/core/typescript/server/cloudflare/src/utilities/wrangler-deploy.ts @@ -2,7 +2,7 @@ import { ExecutorContext, workspaceRoot } from "@nx/devkit"; import { formatDate } from "@open-system/core-shared-utilities/common/date-fns"; import { ConfigurationError } from "@open-system/core-shared-utilities/errors"; -import { ConsoleLogger } from "@open-system/core-shared-utilities/logging"; +import { ConsoleLogger } from "@open-system/core-shared-logging"; import Path from "path"; import { WranglerCommand } from "../types"; import { runWranglerCommand } from "./wrangler"; @@ -33,6 +33,6 @@ export async function runWranglerDeploy( "no-bundle": false, ...options }, - Path.join(workspaceRoot, buildTarget?.options?.outputPath, "index.mjs") + Path.join(workspaceRoot, buildTarget?.options?.outputPath, "index.js") ); } diff --git a/libs/core/typescript/server/cloudflare/src/utilities/wrangler-serve.ts b/libs/core/typescript/server/cloudflare/src/utilities/wrangler-serve.ts index 2675fc629..12a905594 100644 --- a/libs/core/typescript/server/cloudflare/src/utilities/wrangler-serve.ts +++ b/libs/core/typescript/server/cloudflare/src/utilities/wrangler-serve.ts @@ -1,7 +1,7 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ import { ExecutorContext, workspaceRoot } from "@nx/devkit"; import { ConfigurationError } from "@open-system/core-shared-utilities"; -import { ConsoleLogger } from "@open-system/core-shared-utilities/logging"; +import { ConsoleLogger } from "@open-system/core-shared-logging"; import Path from "path"; import { WranglerCommand } from "../types"; import { runWranglerCommand } from "./wrangler"; @@ -30,6 +30,6 @@ export async function runWranglerServe( "no-bundle": false, ...options }, - Path.join(workspaceRoot, buildTarget?.options?.outputPath, "index.mjs") + Path.join(workspaceRoot, buildTarget?.options?.outputPath, "index.js") ); } diff --git a/libs/core/typescript/server/cloudflare/src/utilities/wrangler.ts b/libs/core/typescript/server/cloudflare/src/utilities/wrangler.ts index 65c0a93b1..018d4ada5 100644 --- a/libs/core/typescript/server/cloudflare/src/utilities/wrangler.ts +++ b/libs/core/typescript/server/cloudflare/src/utilities/wrangler.ts @@ -6,7 +6,7 @@ import { EMPTY_STRING } from "@open-system/core-shared-utilities"; import { isSet } from "@open-system/core-shared-utilities/common/type-checks"; -import { ConsoleLogger } from "@open-system/core-shared-utilities/logging"; +import { ConsoleLogger } from "@open-system/core-shared-logging"; import { WranglerCommand } from "../types"; export async function runWranglerCommand( diff --git a/libs/core/typescript/server/domain/src/aggregates/aggregate-factory.ts b/libs/core/typescript/server/domain/src/aggregates/aggregate-factory.ts index 3afe0addd..f4b456ccc 100644 --- a/libs/core/typescript/server/domain/src/aggregates/aggregate-factory.ts +++ b/libs/core/typescript/server/domain/src/aggregates/aggregate-factory.ts @@ -1,8 +1,8 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ +import { Logger } from "@open-system/core-shared-logging/logger"; import { IIdentity, - Logger, - UniqueIdGenerator, + UniqueIdGenerator } from "@open-system/core-shared-utilities"; import { AggregateRoot } from "./aggregate-root"; diff --git a/libs/core/typescript/server/drizzle/src/repositories/drizzle-repository.ts b/libs/core/typescript/server/drizzle/src/repositories/drizzle-repository.ts index 153c9b1a7..150a02f03 100644 --- a/libs/core/typescript/server/drizzle/src/repositories/drizzle-repository.ts +++ b/libs/core/typescript/server/drizzle/src/repositories/drizzle-repository.ts @@ -38,7 +38,7 @@ export abstract class DrizzleRepository< } constructor(context: ServerContext) { - super(context); + super(context.utils.logger, context.env); this.bindings = context.bindings as BindingsWithDatabase< TEntity, @@ -109,9 +109,9 @@ export abstract class DrizzleRepository< }; protected override innerDelete = async (params: DeleteParams) => { - const result = await this.db - .delete(this.schema) - .where(formatWhereParams(this.schema, params.where)); + const result = await (this.db.delete(this.schema) as any).where( + formatWhereParams(this.schema, params.where) + ); return result.id; }; @@ -119,9 +119,9 @@ export abstract class DrizzleRepository< protected override innerDeleteMany = async ( params: DeleteManyParams ) => { - const result = await this.db - .delete(this.schema) - .where(formatWhereParams(this.schema, params.where)); + const result = await (this.db.delete(this.schema) as any).where( + formatWhereParams(this.schema, params.where) + ); return [result.id]; }; diff --git a/libs/core/typescript/server/drizzle/src/utilities/format-params.ts b/libs/core/typescript/server/drizzle/src/utilities/format-params.ts index ff377d0b2..01deea541 100644 --- a/libs/core/typescript/server/drizzle/src/utilities/format-params.ts +++ b/libs/core/typescript/server/drizzle/src/utilities/format-params.ts @@ -5,9 +5,9 @@ import { NumberNullableFilter, StringNullableFilter, WhereParams -} from "@open-system/core-server-application"; +} from "@open-system/core-server-application/types"; import { IEntity } from "@open-system/core-server-domain/types"; -import { ConsoleLogger } from "@open-system/core-shared-utilities"; +import { ConsoleLogger } from "@open-system/core-shared-logging/console"; import { SQL, and, diff --git a/libs/core/typescript/server/graphql/src/plugins/use-extend-graphql-server-context.ts b/libs/core/typescript/server/graphql/src/plugins/use-extend-graphql-server-context.ts index ab675ff75..fbf9e636f 100644 --- a/libs/core/typescript/server/graphql/src/plugins/use-extend-graphql-server-context.ts +++ b/libs/core/typescript/server/graphql/src/plugins/use-extend-graphql-server-context.ts @@ -9,7 +9,7 @@ import { import { InfisicalEnvManager } from "@open-system/core-server-infisical"; import { PinoLogger } from "@open-system/core-server-pino-logging"; import { EnvManager } from "@open-system/core-shared-env/env-manager"; -import { Logger } from "@open-system/core-shared-utilities/logging/logger"; +import { Logger } from "@open-system/core-shared-logging/logger"; import { GraphQLActiveServerContext, GraphQLServerContext diff --git a/libs/core/typescript/server/graphql/src/server/handler.ts b/libs/core/typescript/server/graphql/src/server/handler.ts index fa3b7b435..a02a6abeb 100644 --- a/libs/core/typescript/server/graphql/src/server/handler.ts +++ b/libs/core/typescript/server/graphql/src/server/handler.ts @@ -4,7 +4,7 @@ import { extractSystem } from "@open-system/core-server-application/context"; import { Injector } from "@open-system/core-shared-injection"; -import { Logger } from "@open-system/core-shared-utilities/logging/logger"; +import { Logger } from "@open-system/core-shared-logging/logger"; import * as fetchAPI from "@whatwg-node/node-fetch"; import { createYoga } from "graphql-yoga"; import { GraphQLActiveServerContext, GraphQLServerContext } from "../context"; diff --git a/libs/core/typescript/server/infisical/src/infisical-env-manager.ts b/libs/core/typescript/server/infisical/src/infisical-env-manager.ts index 62d67a507..11d645a37 100644 --- a/libs/core/typescript/server/infisical/src/infisical-env-manager.ts +++ b/libs/core/typescript/server/infisical/src/infisical-env-manager.ts @@ -8,7 +8,10 @@ import { EnvironmentType } from "@open-system/core-shared-env/types"; import { Provider } from "@open-system/core-shared-injection"; -import { Logger, isEmpty, isPromise } from "@open-system/core-shared-utilities"; +import { + isEmpty, + isPromise +} from "@open-system/core-shared-utilities/common/type-checks"; import { EnvConfigurationError } from "@open-system/core-shared-utilities/errors/env-configuration-error"; import { getInfisicalClient } from "./infisical-client"; @@ -41,8 +44,8 @@ export class InfisicalEnvManager< Required> = Omit & Required> > extends EnvManager { - constructor(logger: Logger, options = DEFAULT_OPTIONS) { - super(logger, { ...DEFAULT_OPTIONS, ...options } as TOptions); + constructor() { + super(DEFAULT_OPTIONS as TOptions); } public override get environment(): EnvironmentType { diff --git a/libs/core/typescript/server/pino-logging/src/index.ts b/libs/core/typescript/server/pino-logging/src/index.ts index 842b6add3..c5b57328d 100644 --- a/libs/core/typescript/server/pino-logging/src/index.ts +++ b/libs/core/typescript/server/pino-logging/src/index.ts @@ -1 +1,2 @@ -export * from "./pino-logger"; +export * from "./logger"; +export * from "./transports"; diff --git a/libs/core/typescript/server/pino-logging/src/logger/index.ts b/libs/core/typescript/server/pino-logging/src/logger/index.ts new file mode 100644 index 000000000..842b6add3 --- /dev/null +++ b/libs/core/typescript/server/pino-logging/src/logger/index.ts @@ -0,0 +1 @@ +export * from "./pino-logger"; diff --git a/libs/core/typescript/server/pino-logging/src/pino-logger.ts b/libs/core/typescript/server/pino-logging/src/logger/pino-logger.ts similarity index 86% rename from libs/core/typescript/server/pino-logging/src/pino-logger.ts rename to libs/core/typescript/server/pino-logging/src/logger/pino-logger.ts index a72d674e2..e753f3897 100644 --- a/libs/core/typescript/server/pino-logging/src/pino-logger.ts +++ b/libs/core/typescript/server/pino-logging/src/logger/pino-logger.ts @@ -1,23 +1,25 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ import { EnvManager } from "@open-system/core-shared-env/env-manager"; -import { Provider } from "@open-system/core-shared-injection"; -import { - formatDate, - titleCase -} from "@open-system/core-shared-utilities/common"; -import { Logger } from "@open-system/core-shared-utilities/logging"; +import { Injected, Provider } from "@open-system/core-shared-injection"; +import { Logger } from "@open-system/core-shared-logging"; +import { titleCase } from "@open-system/core-shared-utilities/common"; import pino from "pino"; +import { createFileTransport } from "../transports/file-transport"; @Provider(Logger) export class PinoLogger extends Logger { #logger: pino.BaseLogger; - constructor(private readonly env: EnvManager, _name = "root") { + constructor( + @Injected(EnvManager) private readonly env: EnvManager, + _name = "root" + ) { super(_name); this.#logger = pino( { - level: this.env.get("LOG_LEVEL") || "info", + level: + this.env.get("LOG_LEVEL") || this.env.get("PINO_LOG_LEVEL") || "info", formatters: { level: label => { return { level: titleCase(label) }; @@ -38,14 +40,7 @@ export class PinoLogger extends Logger { } } }, - pino.destination({ - dest: `${this.env.get("LOG_PATH")}/${formatDate().replaceAll( - "/", - "-" - )}`, - minLength: 4096, - sync: false - }) + createFileTransport(env) ); this.#logger.debug(`Logging has been initialized - ${_name}`); } diff --git a/libs/core/typescript/server/pino-logging/src/transports/file-transport.ts b/libs/core/typescript/server/pino-logging/src/transports/file-transport.ts new file mode 100644 index 000000000..dcae998b2 --- /dev/null +++ b/libs/core/typescript/server/pino-logging/src/transports/file-transport.ts @@ -0,0 +1,41 @@ +import { EnvManager } from "@open-system/core-shared-env/env-manager"; +import { + DateTime, + formatDate, + isString +} from "@open-system/core-shared-utilities/common"; +import { tmpdir } from "node:os"; +import Path from "node:path"; +import pino from "pino"; + +export const createFileTransport = (env: EnvManager) => { + let logPath = env.get("LOG_PATH") + ? env.get("LOG_PATH") + : env.get("PINO_LOG_PATH"); + + if (!logPath || !isString(logPath)) { + logPath = Path.join(tmpdir(), "open-system"); + } + + let logFilePrefix = env.get("LOG_FILE_PREFIX"); + if (!logFilePrefix || !isString(logFilePrefix)) { + logFilePrefix = "open-system"; + } + + return pino.transport({ + target: "pino/file", + options: { + destination: pino.destination({ + dest: Path.join( + logPath, + formatDate().replaceAll("/", "-"), + `${logFilePrefix}-${DateTime.current.toString({ + smallestUnit: "millisecond" + })}.log` + ), + minLength: 4096, + sync: false + }) + } + }); +}; diff --git a/libs/core/typescript/server/pino-logging/src/transports/index.ts b/libs/core/typescript/server/pino-logging/src/transports/index.ts new file mode 100644 index 000000000..7f3cf11cd --- /dev/null +++ b/libs/core/typescript/server/pino-logging/src/transports/index.ts @@ -0,0 +1 @@ +export * from "./file-transport"; diff --git a/libs/core/typescript/server/utilities/src/copy-files.ts b/libs/core/typescript/server/utilities/src/copy-files.ts index 74d54f0b2..6d04310e6 100644 --- a/libs/core/typescript/server/utilities/src/copy-files.ts +++ b/libs/core/typescript/server/utilities/src/copy-files.ts @@ -1,5 +1,5 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ -import { ConsoleLogger } from "@open-system/core-shared-utilities/logging"; +import { ConsoleLogger } from "@open-system/core-shared-logging"; import fs, { CopyOptionsSync, copyFileSync, copySync } from "fs-extra"; export const copyFiles = ( diff --git a/libs/core/typescript/server/utilities/src/execute.ts b/libs/core/typescript/server/utilities/src/execute.ts index aed4453b4..6e292d324 100644 --- a/libs/core/typescript/server/utilities/src/execute.ts +++ b/libs/core/typescript/server/utilities/src/execute.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ +import { ConsoleLogger } from "@open-system/core-shared-logging"; import { isEmptyObject } from "@open-system/core-shared-utilities/common"; -import { ConsoleLogger } from "@open-system/core-shared-utilities/logging"; import { ExecOptions, StdioOptions, diff --git a/libs/core/typescript/server/utilities/src/mutex.ts b/libs/core/typescript/server/utilities/src/mutex.ts index a99b81677..459eb66ad 100644 --- a/libs/core/typescript/server/utilities/src/mutex.ts +++ b/libs/core/typescript/server/utilities/src/mutex.ts @@ -1,6 +1,6 @@ import { Provider } from "@open-system/core-shared-injection"; // import Redlock, { ResourceLockedError } from 'redlock'; -import { Logger } from "@open-system/core-shared-utilities/logging"; +import { Logger } from "@open-system/core-shared-logging"; // import type { Redis } from './redis'; // import { REDIS_INSTANCE } from './redis'; diff --git a/libs/core/typescript/shared/env/src/env-manager.ts b/libs/core/typescript/shared/env/src/env-manager.ts index b40d4c477..6e498cc96 100644 --- a/libs/core/typescript/shared/env/src/env-manager.ts +++ b/libs/core/typescript/shared/env/src/env-manager.ts @@ -1,8 +1,9 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ +import { LazyInjected } from "@open-system/core-shared-injection/decorators/lazy-injected"; +import { Logger } from "@open-system/core-shared-logging/logger"; import { BaseUtilityClass, - Logger, isEmpty, parseInteger } from "@open-system/core-shared-utilities"; @@ -15,23 +16,23 @@ export abstract class EnvManager< > extends BaseUtilityClass { protected proxy: EnvProxy; - constructor( - protected readonly logger: Logger, - public readonly options = DEFAULT_OPTIONS as TOptions - ) { + @LazyInjected(Logger) + protected logger!: Logger; + + constructor(public readonly options = DEFAULT_OPTIONS as TOptions) { super(ENV_TOKEN); this.proxy = createEnvProxy({ ...DEFAULT_OPTIONS, ...this.options }); } public get = (name: string): T | undefined => { - this.logger.debug(`Getting environment variable "${name}".`); + this.logger?.debug(`Getting environment variable "${name}".`); return this.innerGet(name); }; public getAsync = (name: string): Promise => { - this.logger.debug( + this.logger?.debug( `Getting external environment variable/secret "${name}".` ); @@ -42,7 +43,9 @@ export abstract class EnvManager< name: string, value: T ) => { - this.logger.debug(`Updating environment variable "${name}" to "${value}".`); + this.logger?.debug( + `Updating environment variable "${name}" to "${value}".` + ); this.proxy[name] = value; }; @@ -57,7 +60,7 @@ export abstract class EnvManager< public get environment(): EnvironmentType { const _environment = this.get("NODE_ENV"); if (isEmpty(_environment)) { - this.logger.error("Environment variable NODE_ENV is not defined."); + this.logger?.error("Environment variable NODE_ENV is not defined."); } // Default to production since the rules are stricter. diff --git a/libs/core/typescript/shared/injection/package.json b/libs/core/typescript/shared/injection/package.json index cf9827d96..c4c687d4d 100644 --- a/libs/core/typescript/shared/injection/package.json +++ b/libs/core/typescript/shared/injection/package.json @@ -3,6 +3,7 @@ "version": "0.0.1", "type": "commonjs", "dependencies": { - "inversify": "^6.0.1" + "inversify": "^6.0.1", + "inversify-inject-decorators": "^3.1.0" } } diff --git a/libs/core/typescript/shared/injection/src/decorators/index.ts b/libs/core/typescript/shared/injection/src/decorators/index.ts index f5111577f..917104481 100644 --- a/libs/core/typescript/shared/injection/src/decorators/index.ts +++ b/libs/core/typescript/shared/injection/src/decorators/index.ts @@ -1,3 +1,4 @@ export * from "./injectable"; export * from "./injected"; +export * from "./lazy-injected"; export * from "./service"; diff --git a/libs/core/typescript/shared/injection/src/decorators/injectable.ts b/libs/core/typescript/shared/injection/src/decorators/injectable.ts index d33c499d1..efe636e11 100644 --- a/libs/core/typescript/shared/injection/src/decorators/injectable.ts +++ b/libs/core/typescript/shared/injection/src/decorators/injectable.ts @@ -1,4 +1,6 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ +import "reflect-metadata"; + import { injectable } from "inversify"; export type InjectableContext = { diff --git a/libs/core/typescript/shared/injection/src/decorators/injected.ts b/libs/core/typescript/shared/injection/src/decorators/injected.ts index a51807620..7a57a0ae1 100644 --- a/libs/core/typescript/shared/injection/src/decorators/injected.ts +++ b/libs/core/typescript/shared/injection/src/decorators/injected.ts @@ -1,4 +1,6 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ +import "reflect-metadata"; + import { inject } from "inversify"; import { ServiceIdentifierOrFunc } from "inversify/lib/annotation/lazy_service_identifier"; diff --git a/libs/core/typescript/shared/injection/src/decorators/lazy-injected.ts b/libs/core/typescript/shared/injection/src/decorators/lazy-injected.ts new file mode 100644 index 000000000..39e96cd46 --- /dev/null +++ b/libs/core/typescript/shared/injection/src/decorators/lazy-injected.ts @@ -0,0 +1,28 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ +import "reflect-metadata"; + +import getDecorators from "inversify-inject-decorators"; +import { Injector } from "../injector/injector"; +import { ServiceIdentifier } from "../types"; + +export type LazyInjectedContext = { + kind: string; + name: string | symbol; + access: { + get?(): unknown; + set?(value: unknown): void; + }; + private?: boolean; + static?: boolean; + addInitializer?(initializer: () => void): void; +}; + +const { lazyInject } = getDecorators(Injector); + +export const LazyInjected = ( + serviceIdentifier: ServiceIdentifier +) => { + return (target: any, targetKey: string) => { + return lazyInject(serviceIdentifier)(target, targetKey); + }; +}; diff --git a/libs/core/typescript/shared/injection/src/decorators/service.ts b/libs/core/typescript/shared/injection/src/decorators/service.ts index 55b568e09..820f74f03 100644 --- a/libs/core/typescript/shared/injection/src/decorators/service.ts +++ b/libs/core/typescript/shared/injection/src/decorators/service.ts @@ -1,12 +1,14 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ +import "reflect-metadata"; + import { BaseUtilityClass } from "@open-system/core-shared-utilities/common/base-utility-class"; -import { Injector } from "../injector"; +import { bindService } from "../utilities/bind-service"; import { Injectable, InjectableContext } from "./injectable"; export const Provider = (baseType?: typeof BaseUtilityClass | any) => { return (target: any, context?: InjectableContext) => { if (context?.kind === "class" && baseType) { - Injector.bind(target).to(baseType); + bindService(baseType, target); } return Injectable()(target, context); diff --git a/libs/core/typescript/shared/injection/src/injector/index.ts b/libs/core/typescript/shared/injection/src/injector/index.ts new file mode 100644 index 000000000..16a8d56ce --- /dev/null +++ b/libs/core/typescript/shared/injection/src/injector/index.ts @@ -0,0 +1 @@ +export * from "./injector"; diff --git a/libs/core/typescript/shared/injection/src/injector.ts b/libs/core/typescript/shared/injection/src/injector/injector.ts similarity index 52% rename from libs/core/typescript/shared/injection/src/injector.ts rename to libs/core/typescript/shared/injection/src/injector/injector.ts index d11d9ee68..c584b9b7d 100644 --- a/libs/core/typescript/shared/injection/src/injector.ts +++ b/libs/core/typescript/shared/injection/src/injector/injector.ts @@ -1,6 +1,7 @@ import { Container } from "inversify"; -import * as InjectionInterfaces from "./types"; +import * as InjectionInterfaces from "../types"; export const Injector: InjectionInterfaces.Injector = new Container({ - autoBindInjectable: true + autoBindInjectable: true, + skipBaseClassChecks: true }); diff --git a/libs/core/typescript/shared/injection/src/utilities/bind-service.ts b/libs/core/typescript/shared/injection/src/utilities/bind-service.ts new file mode 100644 index 000000000..ee3a7560b --- /dev/null +++ b/libs/core/typescript/shared/injection/src/utilities/bind-service.ts @@ -0,0 +1,14 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ +import "reflect-metadata"; + +import { InjectionInterfaces } from ".."; +import { Injector } from "../injector/injector"; + +export const bindService = ( + serviceIdentifier: InjectionInterfaces.ServiceIdentifier, + service: any, + injector: InjectionInterfaces.Injector = Injector +) => { + injector.isBound(serviceIdentifier) && injector.unbind(serviceIdentifier); + injector.bind(serviceIdentifier).to(service); +}; diff --git a/libs/core/typescript/shared/injection/src/utilities/index.ts b/libs/core/typescript/shared/injection/src/utilities/index.ts new file mode 100644 index 000000000..804a4e1c9 --- /dev/null +++ b/libs/core/typescript/shared/injection/src/utilities/index.ts @@ -0,0 +1 @@ +export * from "./bind-service"; diff --git a/libs/core/typescript/shared/logging/.eslintrc.json b/libs/core/typescript/shared/logging/.eslintrc.json new file mode 100644 index 000000000..4ccefbad8 --- /dev/null +++ b/libs/core/typescript/shared/logging/.eslintrc.json @@ -0,0 +1,21 @@ +{ + "extends": ["../../../../../.eslintrc.json"], + "ignorePatterns": ["!**/*"], + "overrides": [ + { + "files": ["*.ts", "*.tsx", "*.js", "*.jsx"], + "parserOptions": { + "project": ["libs/core/typescript/shared/logging/tsconfig.*?.json"] + }, + "rules": {} + }, + { + "files": ["*.ts", "*.tsx"], + "rules": {} + }, + { + "files": ["*.js", "*.jsx"], + "rules": {} + } + ] +} diff --git a/libs/core/typescript/shared/logging/README.md b/libs/core/typescript/shared/logging/README.md new file mode 100644 index 000000000..eff43de97 --- /dev/null +++ b/libs/core/typescript/shared/logging/README.md @@ -0,0 +1,149 @@ + + + + + +
+ + + +
+The Open System is a monorepo containing modern, scalable web application code, additional utility applications/tools, various libraries, and a fully featured, serverless back-end framework. The Open System is built using Nx, a set of extensible dev tools for monorepos, which helps you develop like Google, Facebook, and Microsoft. Building on top of Nx, the Open System provides a set of tools and patterns that help you scale your monorepo to many teams while keeping the codebase maintainable. + +

๐Ÿ’ป Visit patsullivan.org to stay up to date with this developer

+ +[![Version](https://img.shields.io/badge/version-0.0.1-10B981.svg?style=for-the-badge&color=10B981)](https://prettier.io/)  +[![Nx](https://img.shields.io/badge/Nx-14.4.2-lightgrey?style=for-the-badge&logo=nx&logoWidth=20&&color=10B981)](http://nx.dev/) [![NextJs](https://img.shields.io/badge/Next.js-13.0.5-lightgrey?style=for-the-badge&logo=nextdotjs&logoWidth=20&color=10B981)](https://nextjs.org/) [![codecov.io](https://img.shields.io/codecov/c/github/commitizen/cz-cli.svg?style=for-the-badge&color=10B981)](https://codecov.io/github/commitizen/cz-cli?branch=master) [![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg?style=for-the-badge&logo=commitlint&color=10B981)](http://commitizen.github.io/cz-cli/) ![Semantic-Release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=for-the-badge&color=10B981) [![documented with docusaurus](https://img.shields.io/badge/documented_with-docusaurus-success.svg?style=for-the-badge&logo=readthedocs&color=10B981)](https://docusaurus.io/) + + + + + + + +# Core Logging Library (Shared) + +This library was generated with [Nx](https://nx.dev). + + + + +## Table of Contents + +- [Core Logging Library (Shared)](#core-logging-library-shared) + - [Table of Contents](#table-of-contents) + - [Building](#building) + - [Running unit tests](#running-unit-tests) + - [Roadmap](#roadmap) + - [Support](#support) + - [License](#license) + - [Changelog](#changelog) + - [Contributing](#contributing) + - [Contributors](#contributors) + + + +## Building + +Run `nx build core-shared-logging` to build the library. + +## Running unit tests + +Run `nx test core-shared-logging` to execute the unit tests via [Jest](https://jestjs.io). + + + + + + +## Roadmap + +See the [open issues](https://github.com/sullivanpj/open-system/issues) for a list of proposed features (and known issues). + +- [Top Feature Requests](https://github.com/sullivanpj/open-system/issues?q=label%3Aenhancement+is%3Aopen+sort%3Areactions-%2B1-desc) (Add your votes using the ๐Ÿ‘ reaction) +- [Top Bugs](https://github.com/sullivanpj/open-system/issues?q=is%3Aissue+is%3Aopen+label%3Abug+sort%3Areactions-%2B1-desc) (Add your votes using the ๐Ÿ‘ reaction) +- [Newest Bugs](https://github.com/sullivanpj/open-system/issues?q=is%3Aopen+is%3Aissue+label%3Abug) + +## Support + +Reach out to the maintainer at one of the following places: + +- [Contact](https://www.patsullivan.org/contact) +- [GitHub discussions](https://github.com/sullivanpj/open-system/discussions) +- + +## License + +This project is licensed under the **BSD-2-Clause license**. Feel free to edit and distribute this template as you like. + +See [LICENSE](LICENSE) for more information. + +## Changelog + +This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). Every release, along with the migration instructions, is documented in the [CHANGELOG](CHANGELOG.md) file + +## Contributing + +First off, thanks for taking the time to contribute! Contributions are what makes the open-source community such an amazing place to learn, inspire, and create. Any contributions you make will benefit everybody else and are **greatly appreciated**. + +Please try to create bug reports that are: + +- _Reproducible._ Include steps to reproduce the problem. +- _Specific._ Include as much detail as possible: which version, what environment, etc. +- _Unique._ Do not duplicate existing opened issues. +- _Scoped to a Single Bug._ One bug per report. + +Please adhere to this project's [code of conduct](.github/CODE_OF_CONDUCT.md). + +You can use [markdownlint-cli](https://github.com/sullivanpj/open-system/markdownlint-cli) to check for common markdown style inconsistency. + +## Contributors + +Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)): + + + + + + + + + + + + + + + +
Patrick Sullivan
Patrick Sullivan

๐ŸŽจ ๐Ÿ’ป ๐Ÿ”ง ๐Ÿ“– โš ๏ธ
Tyler Benning
Tyler Benning

๐ŸŽจ
+ + + Add your contributions +
+ + + +This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome! + +
+
+
+ +
+ + +
+

Fingerprint: 1BD2 7192 7770 2549 F4C9 F238 E6AD C420 DA5C 4C2D

+
+ +

๐Ÿ’ป Visit patsullivan.org to stay up to date with this developer

+ + + + + + diff --git a/libs/core/typescript/shared/logging/jest.config.ts b/libs/core/typescript/shared/logging/jest.config.ts new file mode 100644 index 000000000..fdf045a53 --- /dev/null +++ b/libs/core/typescript/shared/logging/jest.config.ts @@ -0,0 +1,31 @@ +/* eslint-disable */ +import { readFileSync } from "fs"; + +// Reading the SWC compilation config and remove the "exclude" +// for the test files to be compiled by SWC +const { exclude: _, ...swcJestConfig } = JSON.parse( + readFileSync(`${__dirname}/.swcrc`, "utf-8") +); + +// disable .swcrc look-up by SWC core because we're passing in swcJestConfig ourselves. +// If we do not disable this, SWC Core will read .swcrc and won't transform our test files due to "exclude" +if (swcJestConfig.swcrc === undefined) { + swcJestConfig.swcrc = false; +} + +// Uncomment if using global setup/teardown files being transformed via swc +// https://nx.dev/packages/jest/documents/overview#global-setup/teardown-with-nx-libraries +// jest needs EsModule Interop to find the default exported setup/teardown functions +// swcJestConfig.module.noInterop = false; + +export default { + displayName: "core-shared-logging", + preset: "../../../../../testing/jest.preset.js", + transform: { + "^.+\\.[tj]s$": ["@swc/jest", swcJestConfig] + }, + moduleFileExtensions: ["ts", "js", "html"], + testEnvironment: "node", + coverageDirectory: + "../../../../../coverage/libs/core/typescript/shared/logging" +}; diff --git a/libs/core/typescript/shared/logging/package.json b/libs/core/typescript/shared/logging/package.json new file mode 100644 index 000000000..65a4da08c --- /dev/null +++ b/libs/core/typescript/shared/logging/package.json @@ -0,0 +1,10 @@ +{ + "name": "@open-system/core-shared-logging", + "version": "0.0.1", + "dependencies": { + "chalk": "4.1.0" + }, + "devDependencies": { + "@types/jest": "29.5.3" + } +} diff --git a/libs/core/typescript/shared/logging/project.json b/libs/core/typescript/shared/logging/project.json new file mode 100644 index 000000000..8d0c5e25e --- /dev/null +++ b/libs/core/typescript/shared/logging/project.json @@ -0,0 +1,55 @@ +{ + "name": "core-shared-logging", + "$schema": "../../../../../node_modules/nx/schemas/project-schema.json", + "sourceRoot": "libs/core/typescript/shared/logging/src", + "projectType": "library", + "targets": { + "build": { + "executor": "@nx/esbuild:esbuild", + "outputs": ["{options.outputPath}"], + "options": { + "outputPath": "dist/libs/core/typescript/shared/logging", + "main": "libs/core/typescript/shared/logging/src/index.ts", + "tsConfig": "libs/core/typescript/shared/logging/tsconfig.lib.json", + "assets": ["libs/core/typescript/shared/logging/*.md"], + "deleteOutputPath": true, + "bundle": true, + "metafile": true, + "minify": true, + "format": ["esm", "cjs"] + } + }, + "lint": { + "executor": "@nx/linter:eslint", + "outputs": ["{options.outputFile}"], + "options": { + "lintFilePatterns": ["libs/core/typescript/shared/logging/**/*.ts"] + } + }, + "test": { + "executor": "@nx/jest:jest", + "outputs": ["{workspaceRoot}/coverage/{projectRoot}"], + "options": { + "jestConfig": "libs/core/typescript/shared/logging/jest.config.ts", + "passWithNoTests": true + }, + "configurations": { + "ci": { + "ci": true, + "codeCoverage": true + } + } + }, + "semantic-release": { + "executor": "@theunderscorer/nx-semantic-release:semantic-release", + "options": { + "github": true, + "npm": false, + "changelog": true, + "tagFormat": "core-shared-logging-v${VERSION}" + } + } + }, + "tags": ["scope:core", "platform:shared", "level:utilities"], + "implicitDependencies": ["core-shared-utilities"] +} diff --git a/libs/core/typescript/shared/utilities/src/logging/console-logger.spec.ts b/libs/core/typescript/shared/logging/src/console/console-logger.spec.ts similarity index 100% rename from libs/core/typescript/shared/utilities/src/logging/console-logger.spec.ts rename to libs/core/typescript/shared/logging/src/console/console-logger.spec.ts diff --git a/libs/core/typescript/shared/utilities/src/logging/console-logger.ts b/libs/core/typescript/shared/logging/src/console/console-logger.ts similarity index 97% rename from libs/core/typescript/shared/utilities/src/logging/console-logger.ts rename to libs/core/typescript/shared/logging/src/console/console-logger.ts index 3f53a8bd2..fecf3ec7e 100644 --- a/libs/core/typescript/shared/utilities/src/logging/console-logger.ts +++ b/libs/core/typescript/shared/logging/src/console/console-logger.ts @@ -1,6 +1,7 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ /* eslint-disable @typescript-eslint/no-empty-function */ -import { Logger } from "./logger"; +import { Provider } from "@open-system/core-shared-injection/decorators"; +import { Logger } from "../logger"; import { endGroup, print, @@ -11,6 +12,7 @@ import { startGroup } from "./print"; +@Provider(Logger) export class ConsoleLogger extends Logger { /** * It takes a string as an argument and prints it to the console. diff --git a/libs/core/typescript/shared/utilities/src/logging/index.ts b/libs/core/typescript/shared/logging/src/console/index.ts similarity index 69% rename from libs/core/typescript/shared/utilities/src/logging/index.ts rename to libs/core/typescript/shared/logging/src/console/index.ts index c3f5a1b2c..c96d2ab15 100644 --- a/libs/core/typescript/shared/utilities/src/logging/index.ts +++ b/libs/core/typescript/shared/logging/src/console/index.ts @@ -1,3 +1,2 @@ export * from "./console-logger"; -export * from "./logger"; export * from "./print"; diff --git a/libs/core/typescript/shared/utilities/src/logging/print.spec.ts b/libs/core/typescript/shared/logging/src/console/print.spec.ts similarity index 100% rename from libs/core/typescript/shared/utilities/src/logging/print.spec.ts rename to libs/core/typescript/shared/logging/src/console/print.spec.ts diff --git a/libs/core/typescript/shared/utilities/src/logging/print.ts b/libs/core/typescript/shared/logging/src/console/print.ts similarity index 97% rename from libs/core/typescript/shared/utilities/src/logging/print.ts rename to libs/core/typescript/shared/logging/src/console/print.ts index 8ee66c244..5c19febe5 100644 --- a/libs/core/typescript/shared/utilities/src/logging/print.ts +++ b/libs/core/typescript/shared/logging/src/console/print.ts @@ -1,8 +1,13 @@ +import { + DateTime, + formatDateTime, + isBaseType, + isEmpty, + isError, + isObject, + isProduction +} from "@open-system/core-shared-utilities/common"; import chalk from "chalk"; -import { formatDateTime } from "../common/date-fns"; -import { DateTime } from "../common/date-time"; -import { isProduction } from "../common/env-fns"; -import { isBaseType, isEmpty, isError, isObject } from "../common/type-checks"; /** * `print` is a function that takes a `message` of type `string`, a `newLine` of type `boolean` diff --git a/libs/core/typescript/shared/logging/src/index.ts b/libs/core/typescript/shared/logging/src/index.ts new file mode 100644 index 000000000..85afe826f --- /dev/null +++ b/libs/core/typescript/shared/logging/src/index.ts @@ -0,0 +1,3 @@ +export * from "./console"; +export * from "./logger"; +export * from "./types"; diff --git a/libs/core/typescript/shared/logging/src/logger/index.ts b/libs/core/typescript/shared/logging/src/logger/index.ts new file mode 100644 index 000000000..41c7bf273 --- /dev/null +++ b/libs/core/typescript/shared/logging/src/logger/index.ts @@ -0,0 +1 @@ +export * from "./logger"; diff --git a/libs/core/typescript/shared/utilities/src/logging/logger.ts b/libs/core/typescript/shared/logging/src/logger/logger.ts similarity index 88% rename from libs/core/typescript/shared/utilities/src/logging/logger.ts rename to libs/core/typescript/shared/logging/src/logger/logger.ts index d553b8563..947f712b3 100644 --- a/libs/core/typescript/shared/utilities/src/logging/logger.ts +++ b/libs/core/typescript/shared/logging/src/logger/logger.ts @@ -1,22 +1,10 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ +import { Provider } from "@open-system/core-shared-injection/decorators"; +import { BaseUtilityClass } from "@open-system/core-shared-utilities/common"; import chalk from "chalk"; -import { BaseUtilityClass } from "../common"; import { LOGGER_SYMBOL } from "../types"; -/** - * LogObject specifies the interface that optional structured objects - * passed to logging functions must conform to. Additionally, if LogObject - * is an instance of Error, its field will be expanded into the log message. - */ -export interface LogObject extends Object { - /** - * Optional Error instance to unwrap when formatting the log message. - * See also LogObject for some particularities on how Error instances - * are handled. - */ - error?: Error; -} - +@Provider() export abstract class Logger extends BaseUtilityClass { public get name(): string { return this._name; diff --git a/libs/core/typescript/shared/logging/src/types.ts b/libs/core/typescript/shared/logging/src/types.ts new file mode 100644 index 000000000..8657ef1f5 --- /dev/null +++ b/libs/core/typescript/shared/logging/src/types.ts @@ -0,0 +1,15 @@ +export const LOGGER_SYMBOL = Symbol.for("OS_LOGGER_SYMBOL"); + +/** + * LogObject specifies the interface that optional structured objects + * passed to logging functions must conform to. Additionally, if LogObject + * is an instance of Error, its field will be expanded into the log message. + */ +export interface LogObject extends Object { + /** + * Optional Error instance to unwrap when formatting the log message. + * See also LogObject for some particularities on how Error instances + * are handled. + */ + error?: Error; +} diff --git a/libs/core/typescript/shared/logging/tsconfig.json b/libs/core/typescript/shared/logging/tsconfig.json new file mode 100644 index 000000000..820bb4582 --- /dev/null +++ b/libs/core/typescript/shared/logging/tsconfig.json @@ -0,0 +1,24 @@ +{ + "extends": "../../../../../tsconfig.base.json", + "compilerOptions": { + "esModuleInterop": true, + "allowSyntheticDefaultImports": true, + "forceConsistentCasingInFileNames": true, + "strict": false, + "noImplicitOverride": false, + "noPropertyAccessFromIndexSignature": false, + "noImplicitReturns": true, + "noFallthroughCasesInSwitch": true, + "types": ["jest", "node"] + }, + "files": [], + "include": [], + "references": [ + { + "path": "./tsconfig.lib.json" + }, + { + "path": "./tsconfig.spec.json" + } + ] +} diff --git a/libs/core/typescript/shared/logging/tsconfig.lib.json b/libs/core/typescript/shared/logging/tsconfig.lib.json new file mode 100644 index 000000000..0ba98ce98 --- /dev/null +++ b/libs/core/typescript/shared/logging/tsconfig.lib.json @@ -0,0 +1,10 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "../../../../../dist/out-tsc", + "declaration": true, + "types": ["node", "reflect-metadata"] + }, + "include": ["**/*.js", "**/*.jsx", "**/*.ts", "**/*.tsx"], + "exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"] +} diff --git a/libs/core/typescript/shared/logging/tsconfig.spec.json b/libs/core/typescript/shared/logging/tsconfig.spec.json new file mode 100644 index 000000000..30c798463 --- /dev/null +++ b/libs/core/typescript/shared/logging/tsconfig.spec.json @@ -0,0 +1,14 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "../../../../../dist/out-tsc", + "module": "commonjs", + "types": ["jest", "node"] + }, + "include": [ + "jest.config.ts", + "src/**/*.test.ts", + "src/**/*.spec.ts", + "src/**/*.d.ts" + ] +} diff --git a/libs/core/typescript/shared/serialization/src/json-parser.ts b/libs/core/typescript/shared/serialization/src/json-parser.ts index bd31cd5e0..c1c559970 100644 --- a/libs/core/typescript/shared/serialization/src/json-parser.ts +++ b/libs/core/typescript/shared/serialization/src/json-parser.ts @@ -1,5 +1,4 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ -import { Provider } from "@open-system/core-shared-injection"; import { BaseError, BaseUtilityClass, @@ -9,7 +8,6 @@ import { Decimal } from "decimal.js"; import { parse, registerCustom, stringify } from "superjson"; import { JSON_PARSER_SYMBOL, JsonValue } from "./types"; -@Provider(JSON_PARSER_SYMBOL) export class JsonParser extends BaseUtilityClass { constructor() { super(JSON_PARSER_SYMBOL); diff --git a/libs/core/typescript/shared/utilities/package.json b/libs/core/typescript/shared/utilities/package.json index 7a24e8da5..9c9f05e87 100644 --- a/libs/core/typescript/shared/utilities/package.json +++ b/libs/core/typescript/shared/utilities/package.json @@ -3,7 +3,6 @@ "version": "0.0.1", "dependencies": { "@js-temporal/polyfill": "^0.4.4", - "chalk": "4.1.0", "stacktracey": "^2.1.8", "type-detect": "^4.0.8" }, diff --git a/libs/core/typescript/shared/utilities/src/common/date-time.ts b/libs/core/typescript/shared/utilities/src/common/date-time.ts index 3e7a713e1..ccf12507f 100644 --- a/libs/core/typescript/shared/utilities/src/common/date-time.ts +++ b/libs/core/typescript/shared/utilities/src/common/date-time.ts @@ -74,7 +74,9 @@ export class DateTime extends Temporal.Instant implements IDateTime { * @param {DateTime} dateTime - DateTime * @returns A PlainDate object. */ - public static getPlainDate(dateTime: DateTime): Temporal.PlainDate { + public static getPlainDate( + dateTime: DateTime = DateTime.current + ): Temporal.PlainDate { return Temporal.PlainDate.from( dateTime.toZonedDateTimeISO(Temporal.Now.timeZoneId()) ); @@ -85,7 +87,9 @@ export class DateTime extends Temporal.Instant implements IDateTime { * @param {DateTime} dateTime - DateTime * @returns A PlainTime object. */ - public static getPlainTime(dateTime: DateTime): Temporal.PlainTime { + public static getPlainTime( + dateTime: DateTime = DateTime.current + ): Temporal.PlainTime { return Temporal.PlainTime.from( dateTime.toZonedDateTimeISO(Temporal.Now.timeZoneId()) ); diff --git a/libs/core/typescript/shared/utilities/src/index.ts b/libs/core/typescript/shared/utilities/src/index.ts index 57a007c39..7c7261c58 100644 --- a/libs/core/typescript/shared/utilities/src/index.ts +++ b/libs/core/typescript/shared/utilities/src/index.ts @@ -3,5 +3,4 @@ export * from "./common"; export * from "./cookie-utilities"; export * from "./errors"; -export * from "./logging"; export * from "./types"; diff --git a/libs/core/typescript/shared/utilities/src/types.ts b/libs/core/typescript/shared/utilities/src/types.ts index 274fe80b9..bb12c035b 100644 --- a/libs/core/typescript/shared/utilities/src/types.ts +++ b/libs/core/typescript/shared/utilities/src/types.ts @@ -16,8 +16,6 @@ export const Tokens = { COOKIE_PARSER: Symbol.for("OS_COOKIE_PARSER_SYMBOL") }; -export const LOGGER_SYMBOL = Symbol.for("OS_LOGGER_SYMBOL"); - /** * The valid types of the index for an `Indexable` type object */ diff --git a/libs/core/typescript/shared/utilities/tsconfig.lib.json b/libs/core/typescript/shared/utilities/tsconfig.lib.json index c43563a16..8abe03d10 100644 --- a/libs/core/typescript/shared/utilities/tsconfig.lib.json +++ b/libs/core/typescript/shared/utilities/tsconfig.lib.json @@ -3,7 +3,7 @@ "compilerOptions": { "outDir": "../../../../../dist/out-tsc", "declaration": true, - "types": ["node", "reflect-metadata"] + "types": ["node"] }, "exclude": [ "jest.config.ts", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 81ab9ff16..edeef7457 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -122,10 +122,10 @@ importers: version: 0.3.0 "@wundergraph/react-relay": specifier: ^0.4.0 - version: 0.4.13(@wundergraph/sdk@0.174.5)(react-relay@15.0.0)(react@18.2.0) + version: 0.4.13(@wundergraph/sdk@0.175.0)(react-relay@15.0.0)(react@18.2.0) "@wundergraph/sdk": - specifier: ^0.174.0 - version: 0.174.5(@swc/core@1.3.83)(@swc/wasm@1.3.83)(react-native@0.72.4) + specifier: ^0.175.0 + version: 0.175.0(@swc/core@1.3.83)(@swc/wasm@1.3.83)(react-native@0.72.4) attr-accept: specifier: ^2.2.2 version: 2.2.2 @@ -785,6 +785,9 @@ importers: process: specifier: ^0.11.10 version: 0.11.10 + reflect-metadata: + specifier: ^0.1.13 + version: 0.1.13 wrangler: specifier: ^3.2.0 version: 3.7.0 @@ -1034,6 +1037,19 @@ importers: inversify: specifier: ^6.0.1 version: 6.0.1 + inversify-inject-decorators: + specifier: ^3.1.0 + version: 3.1.0 + + libs/core/typescript/shared/logging: + dependencies: + chalk: + specifier: 4.1.0 + version: 4.1.0 + devDependencies: + "@types/jest": + specifier: 29.5.3 + version: 29.5.3 libs/core/typescript/shared/serialization: dependencies: @@ -1049,9 +1065,6 @@ importers: "@js-temporal/polyfill": specifier: ^0.4.4 version: 0.4.4 - chalk: - specifier: 4.1.0 - version: 4.1.0 stacktracey: specifier: ^2.1.8 version: 2.1.8 @@ -5836,7 +5849,7 @@ packages: "@commitlint/types": 17.4.4 "@types/node": 20.4.7 chalk: 4.1.0 - cosmiconfig: 8.3.5(typescript@5.2.2) + cosmiconfig: 8.3.5(typescript@5.2.0-beta) cosmiconfig-typescript-loader: 4.4.0(@types/node@20.4.7)(cosmiconfig@8.3.5)(ts-node@10.9.1)(typescript@5.2.2) lodash.isplainobject: 4.0.6 lodash.merge: 4.6.2 @@ -22459,7 +22472,7 @@ packages: ts-proto: 1.157.0 dev: false - /@wundergraph/react-relay@0.4.13(@wundergraph/sdk@0.174.5)(react-relay@15.0.0)(react@18.2.0): + /@wundergraph/react-relay@0.4.13(@wundergraph/sdk@0.175.0)(react-relay@15.0.0)(react@18.2.0): resolution: { integrity: sha512-JoIyVHWD9/HqiIQpqNQoZ0xHfaM2cVryt0/sJZcMKgvvMkmHPA+AvXVJGwcgRXOELfeBMC53l9TF3fjZ26G/jQ== @@ -22469,15 +22482,15 @@ packages: react: ^16.9.0 || ^17 || ^18 react-relay: ">=15.0.0" dependencies: - "@wundergraph/sdk": 0.174.5(@swc/core@1.3.83)(@swc/wasm@1.3.83)(react-native@0.72.4) + "@wundergraph/sdk": 0.175.0(@swc/core@1.3.83)(@swc/wasm@1.3.83)(react-native@0.72.4) react: 18.2.0 react-relay: 15.0.0(react@18.2.0) dev: false - /@wundergraph/sdk@0.174.5(@swc/core@1.3.83)(@swc/wasm@1.3.83)(react-native@0.72.4): + /@wundergraph/sdk@0.175.0(@swc/core@1.3.83)(@swc/wasm@1.3.83)(react-native@0.72.4): resolution: { - integrity: sha512-LApS/xJsEQrWTaq/NFaVKg2PaZL1a67bvt+SC5GJpBkFi3dOyD8xGjS0H23xfGl+0pKMgrx/0s+//GxErUqZGQ== + integrity: sha512-dj1nBjelI71kGN4HuDpFaVjDOTY7RVZY60szMusvWSCvJMMA8oEMy++5+GTlsWTj/zXAe3rwB1b59Acr44HGZw== } hasBin: true dependencies: @@ -22504,7 +22517,7 @@ packages: "@wundergraph/orm": 0.3.1 "@wundergraph/protobuf": 0.118.2 "@wundergraph/straightforward": 4.2.5 - "@wundergraph/wunderctl": 0.170.0 + "@wundergraph/wunderctl": 0.171.0 axios: 0.26.1(debug@4.3.4) axios-retry: 3.7.0 close-with-grace: 1.2.0 @@ -22524,6 +22537,7 @@ packages: js-yaml: 4.1.0 json-schema: 0.4.0 json-schema-to-typescript: 11.0.5 + json-stream-stringify: 3.1.0 lodash: 4.17.21 long: 5.2.3 object-hash: 2.2.0 @@ -22566,10 +22580,10 @@ packages: - supports-color dev: false - /@wundergraph/wunderctl@0.170.0: + /@wundergraph/wunderctl@0.171.0: resolution: { - integrity: sha512-N/cAZZ2G55eLZQDDWx+HgGXLj++3fPukzUoz2D4KPw/uPsTYgGfWIo2+4BPLiJ0KMJD6+DaCeEBXmMwy3M1Jog== + integrity: sha512-DWrPEBzactEOHKNLRSvXxsAU/R9LO02iYhLse3tuPC5KzAHN9kdle4B4mAih1V4j9LxZ2rFBZiZ6Nft1wvNHtA== } hasBin: true requiresBuild: true @@ -27282,7 +27296,7 @@ packages: typescript: ">=4" dependencies: "@types/node": 20.4.7 - cosmiconfig: 8.3.5(typescript@5.2.2) + cosmiconfig: 8.3.5(typescript@5.2.0-beta) ts-node: 10.9.1(@swc/core@1.3.83)(@swc/wasm@1.3.83)(@types/node@20.4.7)(typescript@5.2.2) typescript: 5.2.2 @@ -27367,7 +27381,6 @@ packages: parse-json: 5.2.0 path-type: 4.0.0(patch_hash=t2y4p5c63ifj2lrtth34hk3bda) typescript: 5.2.0-beta - dev: true /cosmiconfig@8.3.5(typescript@5.2.2): resolution: @@ -27386,6 +27399,7 @@ packages: parse-json: 5.2.0 path-type: 4.0.0(patch_hash=t2y4p5c63ifj2lrtth34hk3bda) typescript: 5.2.2 + dev: false /crc-32@1.2.2: resolution: @@ -35851,6 +35865,13 @@ packages: dependencies: loose-envify: 1.4.0 + /inversify-inject-decorators@3.1.0: + resolution: + { + integrity: sha512-/seBlVp5bXrLQS3DpKEmlgeZL6C7Tf/QITd+IMQrbBBGuCbxb7k3hRAWu9XSreNpFzLgSboz3sClLSEmGwHphw== + } + dev: false + /inversify@6.0.1: resolution: { @@ -38114,6 +38135,14 @@ packages: dependencies: jsonify: 0.0.1 + /json-stream-stringify@3.1.0: + resolution: + { + integrity: sha512-ilynhoPlWa29XqgWJTD8V3bOF8k4Ybm3U9Oc7o/CG8qvFMGUzPlh9P4mOj9Ss3VtisA6N2OYevCWa14VRpJtQQ== + } + engines: { node: ">=7.10.1" } + dev: false + /json-stringify-nice@1.1.4: resolution: { @@ -48639,7 +48668,6 @@ packages: { integrity: sha512-Ts1Y/anZELhSsjMcU605fU9RE4Oi3p5ORujwbIKXfWa+0Zxs510Qrmrce5/Jowq3cHSZSJqBjypxmHarc+vEWg== } - dev: true /reflect.getprototypeof@1.0.4: resolution: @@ -52086,7 +52114,7 @@ packages: engines: { node: ">=12.0.0" } hasBin: true dependencies: - chalk: 4.1.2 + chalk: 4.1.0 change-case: 4.1.2 commander: 8.3.0 fs-extra: 10.1.0 diff --git a/tools/executors/typescript/client-api-sync/impl.ts b/tools/executors/typescript/client-api-sync/impl.ts index fac7b645b..adf088391 100644 --- a/tools/executors/typescript/client-api-sync/impl.ts +++ b/tools/executors/typescript/client-api-sync/impl.ts @@ -1,6 +1,6 @@ import { ExecutorContext } from "@nx/devkit"; -import { executeAsync } from "@open-system/core-server-utilities"; -import { ConsoleLogger } from "@open-system/core-shared-utilities"; +import { executeAsync } from "@open-system/core-server-utilities/execute"; +import { ConsoleLogger } from "@open-system/core-shared-logging/console"; import { existsSync } from "fs"; import Path from "path"; import { ClientApiSyncExecutorSchema } from "./schema"; diff --git a/tools/executors/typescript/cloudflare-worker-build/impl.ts b/tools/executors/typescript/cloudflare-worker-build/impl.ts index de4f8ff7d..131d646b7 100644 --- a/tools/executors/typescript/cloudflare-worker-build/impl.ts +++ b/tools/executors/typescript/cloudflare-worker-build/impl.ts @@ -3,7 +3,7 @@ import { buildEsbuildOptions } from "@nx/esbuild/src/executors/esbuild/lib/build import { normalizeOptions } from "@nx/esbuild/src/executors/esbuild/lib/normalize"; import { EsBuildExecutorOptions } from "@nx/esbuild/src/executors/esbuild/schema"; import { copyFile } from "@open-system/core-server-utilities/copy-files"; -import { ConsoleLogger } from "@open-system/core-shared-utilities"; +import { ConsoleLogger } from "@open-system/core-shared-logging/console"; import { build } from "esbuild"; import { polyfillNode } from "esbuild-plugin-polyfill-node"; import { existsSync } from "fs"; diff --git a/tools/executors/typescript/cloudflare-worker-deploy/impl.ts b/tools/executors/typescript/cloudflare-worker-deploy/impl.ts index df7aa996d..5e0d6e5cb 100644 --- a/tools/executors/typescript/cloudflare-worker-deploy/impl.ts +++ b/tools/executors/typescript/cloudflare-worker-deploy/impl.ts @@ -1,6 +1,6 @@ import { ExecutorContext } from "@nx/devkit"; import { runWranglerDeploy } from "@open-system/core-server-cloudflare/utilities/wrangler-deploy"; -import { ConsoleLogger } from "@open-system/core-shared-utilities/logging"; +import { ConsoleLogger } from "@open-system/core-shared-logging"; import { CloudflareWorkerDeployExecutorSchema } from "./schema"; export default async function ( diff --git a/tools/executors/typescript/cloudflare-worker-serve/impl.ts b/tools/executors/typescript/cloudflare-worker-serve/impl.ts index ad3fea9ce..1df0cfba3 100644 --- a/tools/executors/typescript/cloudflare-worker-serve/impl.ts +++ b/tools/executors/typescript/cloudflare-worker-serve/impl.ts @@ -1,6 +1,6 @@ import { ExecutorContext } from "@nx/devkit"; import { runWranglerServe } from "@open-system/core-server-cloudflare"; -import { ConsoleLogger } from "@open-system/core-shared-utilities/logging"; +import { ConsoleLogger } from "@open-system/core-shared-logging"; export default async function (options: any, context: ExecutorContext) { try { diff --git a/tools/executors/typescript/design-components-clean/impl.ts b/tools/executors/typescript/design-components-clean/impl.ts index 6f158c9b1..f43c0297c 100644 --- a/tools/executors/typescript/design-components-clean/impl.ts +++ b/tools/executors/typescript/design-components-clean/impl.ts @@ -1,6 +1,6 @@ import { ExecutorContext } from "@nx/devkit"; import { executeAsync } from "@open-system/core-server-utilities"; -import { ConsoleLogger } from "@open-system/core-shared-utilities"; +import { ConsoleLogger } from "@open-system/core-shared-logging/console"; import { DesignComponentsCleanExecutorSchema } from "./schema"; export default async function ( diff --git a/tools/executors/typescript/design-tokens-build/impl.ts b/tools/executors/typescript/design-tokens-build/impl.ts deleted file mode 100644 index 721a85011..000000000 --- a/tools/executors/typescript/design-tokens-build/impl.ts +++ /dev/null @@ -1,454 +0,0 @@ -import { ExecutorContext, joinPathFragments } from "@nx/devkit"; -import { executeAsync } from "@open-system/core-server-utilities"; -import { ConsoleLogger } from "@open-system/core-shared-utilities"; -import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs"; -import { toCssFontImportParser, toTailwindParser } from "../utilities"; -import { InputDataType as ToCssFontImportParserInputDataType } from "../utilities/design-token-parsers/parsers/to-css-font-import"; -import { InputDataType as ToTailwindInputDataType } from "../utilities/design-token-parsers/parsers/to-tailwind"; -import { IToken } from "../utilities/design-token-parsers/types"; -import { DesignTokensBuildExecutorSchema } from "./schema"; - -export default async function ( - options: DesignTokensBuildExecutorSchema, - context: ExecutorContext -) { - try { - const { tokensDir, tokensFile, fontsDir, clean, verbose } = options; - - ConsoleLogger.info("Executing design-tokens-build executor..."); - verbose && - ConsoleLogger.info(`Options: ${JSON.stringify(options, null, 2)}`); - verbose && ConsoleLogger.info(`Current Directory: ${__dirname}`); - - const themeName = context.configurationName - ? context.configurationName - : "default"; - - const tokenJson = joinPathFragments(tokensDir, tokensFile); - if (!tokenJson) { - ConsoleLogger.error( - `No JSON file could be found at ${tokenJson}. Halting execution early.` - ); - return { success: false }; - } - - const outputPath = - context.workspace?.projects?.[context.projectName]?.targets?.["build"] - ?.options?.outputPath; - if (!outputPath) { - ConsoleLogger.error( - "No `outputPath` option was provided. Halting execution early." - ); - return { success: false }; - } - - ConsoleLogger.info(`Design Tokens JSON: ${tokensDir}`); - ConsoleLogger.info("Starting design tokens build..."); - - let result; - if (clean) { - ConsoleLogger.info("Cleaning previous design tokens build..."); - - result = await executeAsync( - `rimraf ./dist/design-system/tokens -v !("package.json")` - ); - if (result) { - ConsoleLogger.error(result); - return { success: false }; - } - } - - verbose && - ConsoleLogger.info(`Loading design tokens file for theme: ${themeName}`); - - const tokenJsonStr = readFileSync(tokenJson, "utf-8"); - verbose && ConsoleLogger.info(tokenJsonStr); - - const dataArray = JSON.parse(tokenJsonStr); - verbose && ConsoleLogger.info(JSON.stringify(dataArray, null, 2)); - - ConsoleLogger.info("Building latest design tokens..."); - - (dataArray["color"] || - dataArray["font"] || - dataArray["spacing"] || - dataArray["gradient"]) && - (result = await toTailwindParser( - [ - ...(dataArray["color"] - ? Object.entries(dataArray["color"]).reduce( - ( - ret: ToTailwindInputDataType, - [name, token]: [ - name: string, - token: Omit & - Partial - ] - ) => { - ConsoleLogger.info("Building color design tokens..."); - - if (name && token.value) { - ret.push({ - id: name, - type: "color", - name, - ...token - }); - - verbose && - ConsoleLogger.info( - JSON.stringify( - { - id: name, - type: "color", - name, - ...token - }, - null, - 2 - ) - ); - } - - return ret; - }, - [] - ) - : []), - ...(dataArray["font"] - ? Object.entries(dataArray["font"]).reduce( - ( - ret: ToTailwindInputDataType, - [name, token]: [name: string, token: any] - ) => { - ConsoleLogger.info("Building font design tokens..."); - - if (name && token.value) { - const item = { - id: name, - name, - ...token, - type: "textStyle", - value: { - font: { - name: token.value?.fontFamily - ?.replaceAll(/[_]/g, "") - ?.replaceAll(/\s/g, ""), - value: { - ...token.value - } - } - } - }; - - ret.push(item); - verbose && - ConsoleLogger.info(JSON.stringify(item, null, 2)); - } - - return ret; - }, - [] - ) - : []), - ...(dataArray["spacing"] - ? Object.entries(dataArray["spacing"]).reduce( - ( - ret: ToTailwindInputDataType, - [name, token]: [name: string, token: any] - ) => { - ConsoleLogger.info("Building spacing design tokens..."); - - if (name && token.value) { - const item = { - id: name, - name, - ...token, - type: "measurement" - }; - - ret.push(item); - verbose && - ConsoleLogger.info(JSON.stringify(item, null, 2)); - } - - return ret; - }, - [] - ) - : []), - /*...(dataArray["gradient"] - ? Object.entries(dataArray["gradient"]).reduce( - ( - ret: ToTailwindInputDataType, - [name, token]: [name: string, token: any] - ) => { - ConsoleLogger.info("Building gradient design tokens..."); - - if (name && token.value) { - Object.entries(dataArray[name]).forEach( - ([child, gradient]: [child: string, gradient: any]) => { - if (child && gradient?.stops) { - const item = { - ...token, - ...gradient, - id: `${name}-${child}`, - name: `${name}-${child}`, - type: "gradient", - value: { - colors: gradient.stops, - }, - }; - - ret.push(item); - verbose && - ConsoleLogger.info(JSON.stringify(item, null, 2)); - } - } - ); - } - - return ret; - }, - [] - ) - : []),*/ - ...(dataArray["effect"] - ? Object.entries(dataArray["effect"]).reduce( - ( - ret: ToTailwindInputDataType, - [name, token]: [name: string, token: any] - ) => { - ConsoleLogger.info("Building shadow design tokens..."); - - if (name && token.value) { - const item = { - id: name, - name, - ...token, - type: "shadow", - value: Array.isArray(token.value) - ? token.value.map((shadow: any) => ({ - isInner: shadow.shadowType === "shadowType", - color: token.value.color, - radius: shadow.radius, - offsetX: shadow.offsetX, - offsetY: shadow.offsetY, - blur: shadow.radius, - spread: shadow.spread - })) - : [ - { - isInner: token.value.shadowType === "shadowType", - color: token.value.color, - radius: token.value.radius, - offsetX: token.value.offsetX, - offsetY: token.value.offsetY, - blur: token.value.radius, - spread: token.value.spread - } - ] - }; - - ret.push(item); - verbose && - ConsoleLogger.info(JSON.stringify(item, null, 2)); - } - - return ret; - }, - [] - ) - : []) - /*...(dataArray["size"] - ? Object.entries(dataArray["size"]).reduce( - ( - ret: ToTailwindInputDataType, - [name, token]: [name: string, token: any] - ) => { - if (name && token.value) { - const item = { - id: name, - name, - ...token, - type: "size", - }; - - ret.push(item); - } - - return ret; - }, - [] - ) - : []),*/ - ], - { - formatName: "kebabCase", - formatConfig: { - objectName: "extend", - exportDefault: true, - module: "commonjs" - } - }, - { _: null } - )); - - verbose && ConsoleLogger.success(result); - - if (!existsSync(joinPathFragments(outputPath, "js"))) { - ConsoleLogger.info( - `Creating token directory: ${joinPathFragments(outputPath, "js")}` - ); - - mkdirSync(joinPathFragments(outputPath, "js"), { recursive: true }); - } - - ConsoleLogger.info( - `Creating token file: ${joinPathFragments(outputPath, "js", `theme.js`)}` - ); - writeFileSync( - joinPathFragments(outputPath, "js", `theme.js`), - result, - "utf8" - ); - - ConsoleLogger.success(`Design token theme.js (tailwind import) created.`); - - const fontsPath = existsSync(joinPathFragments(tokensDir, fontsDir)) - ? joinPathFragments(tokensDir, fontsDir) - : fontsDir; - if (existsSync(fontsPath) && dataArray["font"]) { - result = await toCssFontImportParser( - Object.entries(dataArray["font"]).reduce( - ( - ret: ToCssFontImportParserInputDataType, - [name, token]: [ - name: string, - token: ToCssFontImportParserInputDataType[0] - ] - ) => { - if (name && token.value?.fontFamily) { - ret.push({ - id: name, - type: "font", - name: `${token.value.fontFamily - .replaceAll(/[_]/g, "") - .replaceAll(/\s/g, "")}`, - ...token - }); - } - - return ret; - }, - [] - ), - { - fontFamilyTransform: "pascalCase", - formats: ["ttf"], - fontsPath, - fontDisplay: "fallback", - genericFamily: "sans-serif", - includeFontWeight: true - } - ); - - verbose && ConsoleLogger.success(result); - - if (!existsSync(joinPathFragments(outputPath, "css"))) { - mkdirSync(joinPathFragments(outputPath, "css"), { recursive: true }); - } - - writeFileSync( - joinPathFragments(outputPath, "css", `fonts.css`), - result, - "utf8" - ); - - ConsoleLogger.success(`Theme specific fonts (font.css) created.`); - } - - /*const imagesPath = existsSync(joinPathFragments(tokensDir, imagesDir)) - ? joinPathFragments(tokensDir, imagesDir) - : imagesDir; - ConsoleLogger.info(`Checking for SVG images in ${imagesPath}`); - if (existsSync(imagesPath)) { - ConsoleLogger.info(`Building SVG images from design system assets...`); - - const fileList = readdirSync(imagesPath); - if (fileList.length === 0) { - ConsoleLogger.info(`No SVG images could be found in ${imagesPath}.`); - } else { - ConsoleLogger.info( - `Building SVG images for the following: ${fileList.join(", ")}.` - ); - - result = await svgoParser( - fileList.map((file: string) => ({ - name: file, - url: joinPathFragments(imagesDir, file), - value: { - url: joinPathFragments(imagesDir, file), - type: "svg", - }, - type: "svg", - })), - { - svgo: { - js2svg: { - pretty: true, - }, - plugins: [ - { - removeDimensions: true, - }, - { - removeAttrs: { - attrs: "*:(fill|stroke)", - }, - }, - { - addAttributesToSVGElement: { - // The svg also has a focusable attribute set - // to false which prevents the icon itself - // from receiving focus in IE, because otherwise - // the button will have two Tab stops, which is - // not the expected or desired behavior. - attributes: [ - 'width="1em"', - 'height="1em"', - 'focusable="false"', - ], - }, - }, - ], - }, - }, - { SVGO } as any - ); - - if (!result) { - ConsoleLogger.error(`An error occurred generating SVGs`); - return { success: false }; - } - - verbose && ConsoleLogger.success(JSON.stringify(result, null, 2)); - - ConsoleLogger.success( - `Theme specific images (assets/images/*.svg) created.` - ); - } - }*/ - - ConsoleLogger.success("Design tokens sync succeeded."); - - return { success: true }; - } catch (e) { - ConsoleLogger.error( - `An error occurred syncing client API for ${context.projectName}` - ); - ConsoleLogger.error(e); - - return { success: false }; - } -} diff --git a/tools/executors/typescript/design-tokens-build/schema.d.ts b/tools/executors/typescript/design-tokens-build/schema.d.ts deleted file mode 100644 index 8850e235d..000000000 --- a/tools/executors/typescript/design-tokens-build/schema.d.ts +++ /dev/null @@ -1,8 +0,0 @@ -export interface DesignTokensBuildExecutorSchema { - tokensDir: string; - tokensFile: string; - fontsDir?: string; - imagesDir?: string; - clean?: boolean; - verbose?: boolean; -} diff --git a/tools/executors/typescript/design-tokens-build/schema.json b/tools/executors/typescript/design-tokens-build/schema.json deleted file mode 100644 index 221b3966f..000000000 --- a/tools/executors/typescript/design-tokens-build/schema.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "$schema": "http://json-schema.org/schema", - "cli": "nx", - "title": "Open System - Design Tokens Build", - "id": "design-tokens-build", - "description": "Build the latest design tokens code from the extracted figma JSON.", - "type": "object", - "properties": { - "tokensDir": { - "type": "string", - "description": "The theme-specific directory containing the extracted design tokens.' json/asset data." - }, - "tokensFile": { - "type": "string", - "description": "The name of the JSON file containing the extracted design tokens.", - "default": "design-tokens.json" - }, - "fontsDir": { - "type": "string", - "description": "The directory containing the theme-specific font files (the provided path can either be relative to `tokensDir` or the repository root)." - }, - "imagesDir": { - "type": "string", - "description": "The directory containing the theme-specific image files (the provided path can either be relative to `tokensDir` or the repository root)." - }, - "clean": { - "type": "boolean", - "description": "Should `style-dictionary clean` be executed prior to the build.", - "default": false - }, - "verbose": { - "type": "boolean", - "description": "An indicator specifying the if the level of logging should be high (when `true`) or normal (when `false`).", - "default": false - } - }, - "required": ["tokensDir", "tokensFile"] -} diff --git a/tools/executors/typescript/event-library/impl.ts b/tools/executors/typescript/event-library/impl.ts index 2f3f45d8a..62b5b730e 100644 --- a/tools/executors/typescript/event-library/impl.ts +++ b/tools/executors/typescript/event-library/impl.ts @@ -1,7 +1,7 @@ import Generator from "@asyncapi/generator"; import { ExecutorContext } from "@nx/devkit"; import { executeAsync } from "@open-system/core-server-utilities"; -import { ConsoleLogger } from "@open-system/core-shared-utilities"; +import { ConsoleLogger } from "@open-system/core-shared-logging/console"; import { existsSync, removeSync } from "fs-extra"; import glob from "glob"; import Path from "path"; diff --git a/tools/executors/typescript/executors.json b/tools/executors/typescript/executors.json index 90f88c191..c85b36c97 100644 --- a/tools/executors/typescript/executors.json +++ b/tools/executors/typescript/executors.json @@ -35,11 +35,6 @@ "schema": "../../../dist/tools/executors/typescript/client-api-joi-sync/schema.json", "description": "Sync up TypeScript client-side Joi validator project code and types based on an OpenApi spec." }, - "design-tokens-build": { - "implementation": "../../../dist/tools/executors/typescript/design-tokens-build/impl", - "schema": "../../../dist/tools/executors/typescript/design-tokens-build/schema.json", - "description": "Build the latest design tokens code from the extracted figma JSON." - }, "storm-generate": { "implementation": "../../../dist/tools/executors/typescript/storm-generate/impl", "schema": "../../../dist/tools/executors/typescript/storm-generate/schema.json", diff --git a/tools/executors/typescript/project.json b/tools/executors/typescript/project.json index d38664c1d..22d90065b 100644 --- a/tools/executors/typescript/project.json +++ b/tools/executors/typescript/project.json @@ -16,7 +16,6 @@ "tools/executors/typescript/cloudflare-worker-build/impl.ts", "tools/executors/typescript/cloudflare-worker-deploy/impl.ts", "tools/executors/typescript/cloudflare-worker-serve/impl.ts", - "tools/executors/typescript/design-tokens-build/impl.ts", "tools/executors/typescript/design-components-clean/impl.ts", "tools/executors/typescript/client-api-sync/impl.ts", "tools/executors/typescript/client-gql-sync/impl.ts", @@ -108,6 +107,7 @@ "tags": ["scope:tools", "platform:admin"], "implicitDependencies": [ "core-shared-utilities", + "core-shared-logging", "core-server-utilities", "core-server-cloudflare", "tools-async-api-kafka", diff --git a/tools/executors/typescript/storm-generate/impl.ts b/tools/executors/typescript/storm-generate/impl.ts index de69ebe4b..7cdd5ea60 100644 --- a/tools/executors/typescript/storm-generate/impl.ts +++ b/tools/executors/typescript/storm-generate/impl.ts @@ -1,5 +1,5 @@ import { ExecutorContext, workspaceRoot } from "@nx/devkit"; -import { ConsoleLogger } from "@open-system/core-shared-utilities"; +import { ConsoleLogger } from "@open-system/core-shared-logging/console"; import { generateAction } from "@open-system/tools-storm-schema"; import { existsSync } from "fs"; import { removeSync } from "fs-extra"; diff --git a/tools/executors/typescript/utilities/design-token-parsers/index.ts b/tools/executors/typescript/utilities/design-token-parsers/index.ts deleted file mode 100644 index c75bcc91f..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from "./parsers"; diff --git a/tools/executors/typescript/utilities/design-token-parsers/libs/list-paths-by-pattern.ts b/tools/executors/typescript/utilities/design-token-parsers/libs/list-paths-by-pattern.ts deleted file mode 100644 index c32008ed0..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/libs/list-paths-by-pattern.ts +++ /dev/null @@ -1,42 +0,0 @@ -import { has, get } from "lodash"; - -export default function listPathsByPattern( - base: T | Array, - pattern: string -): Array { - try { - if (!pattern.includes("[*]")) return has(base, pattern) ? [pattern] : []; - return pattern - .split(/(?=\[\*])|(?<=\[\*])/g) // split without remove the delimiter - .reduce>( - (paths, item) => { - if (item === "[*]") { - return paths - .map(basePath => { - const iteration = basePath ? get(base, basePath) : base; - if (!Array.isArray(iteration)) return []; - return Array(iteration.length) - .fill(0) - .reduce( - (acc, _, index) => - has(base, `${basePath}[${index}]`) - ? [...acc, `${basePath}[${index}]`] - : acc, - [] - ); - }) - .flat(2); - } else { - return paths.reduce>( - (acc, elm) => - has(base, `${elm}${item}`) ? [...acc, `${elm}${item}`] : acc, - [] - ); - } - }, - [""] - ); - } catch (err) { - throw err; - } -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/libs/size-manipulation.ts b/tools/executors/typescript/utilities/design-token-parsers/libs/size-manipulation.ts deleted file mode 100644 index 19a85be57..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/libs/size-manipulation.ts +++ /dev/null @@ -1,42 +0,0 @@ -import { MeasurementValue } from "../types"; - -function convertMeasurement( - from: MeasurementValue, - toUnit: "px" | "rem", - basePixelValue?: number | undefined -): MeasurementValue; -function convertMeasurement( - from: string, - toUnit: "px" | "rem", - basePixelValue?: number | undefined -): string; -function convertMeasurement( - from: string | MeasurementValue, - toUnit: "px" | "rem", - basePixelValue = 16 -): MeasurementValue | string { - if (!["px", "rem"].includes(toUnit)) throw new Error("Unknown size unit"); - let fromValue = - typeof from === "object" && "measure" in from - ? from.measure - : parseFloat(from); - const fromUnit = - typeof from === "string" - ? from.match(/[\d.\-\+]*\s*(.*)/)![1] || "" - : from.unit; - let pxValue; - if (fromUnit === "px") { - pxValue = fromValue; - } else if (fromUnit === "rem") { - pxValue = fromValue * basePixelValue; - } - if (!pxValue) throw new Error("Unknown size unit"); - - const result = { - unit: toUnit === "px" ? "px" : "rem", - measure: toUnit === "px" ? pxValue : pxValue / basePixelValue, - }; - return typeof from === "string" ? `${result.measure}${result.unit}` : result; -} - -export default convertMeasurement; diff --git a/tools/executors/typescript/utilities/design-token-parsers/libs/template.ts b/tools/executors/typescript/utilities/design-token-parsers/libs/template.ts deleted file mode 100644 index 912b2e89d..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/libs/template.ts +++ /dev/null @@ -1,52 +0,0 @@ -import _ from "lodash"; -import Mustache from "mustache"; -import { MustacheWriter, TemplateSpans } from "../types/libs/mustache"; - -export default class Template { - keys: Array = []; - pattern: string; - mustache: MustacheWriter = new Mustache.Writer(); - constructor(pattern: string) { - this.mustache.escapedValue = (token, context) => { - return context.lookup(token[1]); - }; - this.pattern = pattern; - this.keys = this.mustache - .parse(pattern) - .reduce( - (acc: TemplateSpans, variable: TemplateSpans[0]) => - this.flattenVariablesFromParseTree(acc, variable), - [] - ) - .map((v: TemplateSpans) => (v && v[1] ? v[1] : null)); - } - - private flattenVariablesFromParseTree( - acc: TemplateSpans, - variable: TemplateSpans[0] - ) { - if (variable[0] === "name" || variable[0] === "&") { - // Evaluation of a variable. Simply add the variable to be evaluated - acc.push(variable); - } else if (variable[0] === "#" || variable[0] === "^") { - // Condition in the template. Add the variable to check + check if there is any nested conditions - acc.push(variable); - const childs = (variable[4] as TemplateSpans).reduce( - (acc, variable) => { - return this.flattenVariablesFromParseTree(acc, variable); - }, - acc - )[0]; - if (childs) acc.push(childs); - } - return acc; - } - - render(item: any) { - const views = this.keys.reduce string>>((acc, key) => { - _.set(acc, key, _.get(item, key, _.get(item, `value[${key}]`, ""))); - return acc; - }, {}); - return this.mustache.render(this.pattern, views); - } -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/camelcasify/README.md b/tools/executors/typescript/utilities/design-token-parsers/parsers/camelcasify/README.md deleted file mode 100644 index ec87da264..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/camelcasify/README.md +++ /dev/null @@ -1,94 +0,0 @@ -# Camelcasify - -## Description - -This parser helps you apply camelcase function on specific keys from a design token. - -Learn more about how to configure Specify in the API documentation: [https://specifyapp.com/developers](https://specifyapp.com/developers). - -## Interface - -```ts -interface parser { - name: "camelcasify"; - options?: { - keys: Array; - }; -} -``` - -### Options - -| Parameter | Required | Type | Default | Description | -| --------- | -------- | ------- | ---------- | --------------------------------------------------- | -| `keys` | optional | `Array` | `["name"]` | The list of keys where the function will be applied | - -## Types - -โ„น๏ธ **Please be aware that, depending on the order you use parsers, their input and output types have to match.** - -### Input - -Array of object with the keys to apply `camelcase` function - -```ts -type input = Array<{ [key: string]: any }>; -``` - -### Output - -```ts -type output = Array<{ [key: string]: any }>; -``` - -## Usage - -### Config - -```jsonc -"parsers": [ - { - "name": "camelcasify", - "options": { - "keys": ["name"] - } - } - // ... -] -``` - -### Before/After - -#### Input - -```jsonc -[ - { - "type": "color", - "value": { - "a": 0.96, - "b": 20, - "g": 227, - "r": 122 - }, - "name": "Brand / Primary Color" - } -] -``` - -#### Output - -```jsonc -[ - { - "type": "color", - "value": { - "a": 0.96, - "b": 20, - "g": 227, - "r": 122 - }, - "name": "brandPrimaryColor" - } -] -``` diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/camelcasify/camelcasify.parser.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/camelcasify/camelcasify.parser.ts deleted file mode 100644 index 097b5170f..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/camelcasify/camelcasify.parser.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { LibsType } from "../global-libs"; - -export type InputDataType = Array>; -export type OutputDataType = InputDataType; -export type OptionsType = - | undefined - | { - keys: Array; - }; -export default async function ( - tokens: InputDataType, - options: OptionsType = { keys: ["name"] }, - { _ }: Pick -): Promise { - try { - return tokens.map(token => { - options.keys.forEach(key => { - if (_.has(token, key)) { - _.set(token, key, _.camelCase(_.get(token, key))); - } - }); - return token; - }); - } catch (err) { - throw err; - } -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/camelcasify/camelcasify.spec.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/camelcasify/camelcasify.spec.ts deleted file mode 100644 index 58f95a891..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/camelcasify/camelcasify.spec.ts +++ /dev/null @@ -1,61 +0,0 @@ -import camelcasify from "./camelcasify.parser"; -import { Token } from "../../types"; -import libs from "../global-libs"; -import seeds from "../../tests/seeds"; - -describe("Camelcasify", () => { - it("Get tokens - apply parsers", async () => { - const result = await camelcasify( - seeds().tokens as Array, - { keys: ["name"] }, - libs - ); - if (result instanceof Error) return fail(result); - result.forEach(token => { - expect(token.name?.includes(" ")).toEqual(false); - }); - return; - }); - it("Get tokens - apply parsers - default", async () => { - const result = await camelcasify( - seeds().tokens as Array, - undefined, - libs - ); - if (result instanceof Error) return fail(result); - result.forEach(token => { - expect(token.name?.includes(" ")).toEqual(false); - }); - return; - }); - it("Get tokens - apply parsers - without tokens", async () => { - const result = await camelcasify([], undefined, libs); - if (result instanceof Error) return fail(result); - expect(Array.isArray(result)).toBeTruthy(); - expect(result.length).toEqual(0); - return; - }); - it("Get tokens - apply parsers - unknown target key", async () => { - const input = seeds().tokens; - const result = await camelcasify( - input, - { keys: ["name", "not exist"] }, - libs - ); - expect(Array.isArray(result)).toBeTruthy(); - expect(result.length).toEqual(input.length); - return; - }); - it("Get tokens - apply parsers - error", async () => { - try { - await camelcasify( - // @ts-ignore - "wrong type", - { keys: ["name", "not exist"] }, - libs - ); - } catch (err) { - return; - } - }); -}); diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/convert-font/README.md b/tools/executors/typescript/utilities/design-token-parsers/parsers/convert-font/README.md deleted file mode 100644 index b190aed75..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/convert-font/README.md +++ /dev/null @@ -1,145 +0,0 @@ -# Convert Font - -## Description - -This parser helps you convert font in several formats. - -Learn more about how to configure Specify in the API documentation: [https://specifyapp.com/developers](https://specifyapp.com/developers). - -## Interface - -```ts -interface parser { - name: "convert-font"; - options?: { - formats?: Array<"woff2" | "woff" | "otf" | "ttf" | "eot">; - fileNameKey?: "name" | "fontFamily" | "fontPostScriptName" | Array; - fileNameFormat?: "camelCase" | "kebabCase" | "snakeCase" | "pascalCase"; - }; -} -``` - -### Options - -| Parameter | Required | Type | Default | Description | -| ---------------- | -------- | ----------------------------------------------------------- | ------------------- | ----------------------------------------------------------------------------------------------------------------------------------- | -| `formats` | optional | `Array` | `["woff2", "woff"]` | The list of formats to convert | -| `fileNameKey` | optional | `name`, `fontFamily`, `fontPostScriptName`, `Array` | `name` | The design token's keys that will be used to create the file name. These keys will be separated by a space to create the file name. | -| `fileNameFormat` | optional | `camelCase` `kebabCase` `snakeCase` `pascalCase` | | The function to normalize the file name | - -## Output - -Please keep in mind that this parser generates files. This is why you should always set a folder as the final `path` in your parent rule. - -
-See Do & Don't config examples - -โœ… Do - -``` -// ... -"rules": [ - { - "name": "Design Tokens / Fonts", - "path": "fonts", // <-- path set as a folder - "parsers": [ - { - "name": "convert-font" - } - ] - } -] -``` - -๐Ÿšซ Don't - -``` -// ... -"rules": [ - { - "name": "Design Tokens / Fonts", - "path": "fonts/fonts.json", // <-- path set as a file - "parsers": [ - { - "name": "convert-font" - } - ] - } -] -``` - -
- -## Types - -โ„น๏ธ **Please be aware that, depending on the order you use parsers, their input and output types have to match.** - -### Input - -Array of object with at least the key `name` - -```ts -type input = Array<{ - name: string; - value: { fontPostScriptName: string; [Key: string]: any }; - [Key: string]: any; -}>; -``` - -### Output - -```ts -type output = Array<{ - value: { fontPostScriptName: string; url: string; [Key: string]: any }; - [Key: string]: any; -}>; -``` - -## Usage - -### Config - -```jsonc -"parsers": [ - { - "name": "convert-font", - "options": { - "formats": ["woff2", "woff"], - "fileNameKey": ["fontFamily", "fontWeight"], - "fileNameFormat": "kebabCase" - } - } - // ... -] -``` - -### Result - -```jsonc -[ - { - "name": "allan-700.woff2", - "value": { - "url": "https://beta.api.specifyapp.com/...", - "fontFamily": "Allan", - "fontWeight": 700, - "fontPostScriptName": "Allan-Bold" - } - }, - { - "name": "allan-700.woff", - "value": { - "url": "https://beta.api.specifyapp.com/...", - "fontFamily": "Allan", - "fontWeight": 700, - "fontPostScriptName": "Allan-Bold" - } - } -] -``` - -## โ„น๏ธ Good to know - -We decided to exclude the `eot`, `otf` and `ttf` file formats in the [`formats`](#Options) parameter. If you are mostly targeting users with modern browsers, [you can get away with a progressive method](https://css-tricks.com/understanding-web-fonts-getting/#font-formats) of using `@font-face` that only serves WOFF and WOFF2 formats. - -However, you can still add `eot`, `otf` and `ttf` file formats in the [`formats`](#Interface) parameter if you need to support older browsers. diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/convert-font/convert-font.parser.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/convert-font/convert-font.parser.ts deleted file mode 100644 index 70eac3d09..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/convert-font/convert-font.parser.ts +++ /dev/null @@ -1,94 +0,0 @@ -import { ConsoleLogger } from "@open-system/core-shared-utilities"; -import { AllowedFormat, PartialRecord } from "../../types"; -import type { LibsType } from "../global-libs"; - -export type InputDataType = Array<{ - value: { - fontPostScriptName: string; - fontFamily?: string; - fontWeight?: string | number; - [Key: string]: any; - }; - [Key: string]: any; -}>; -export type OutputDataType = - | Array< - InputDataType[0] & { value: InputDataType[0]["value"] & { url: string } } - > - | Error; -export type OptionsType = { - formats?: Array<"woff2" | "woff" | "otf" | "ttf" | "eot">; - fileNameKey?: "name" | "fontFamily" | Array; - fileNameFormat?: "camelCase" | "kebabCase" | "snakeCase" | "pascalCase"; -}; - -export default async function ( - designTokens: InputDataType, - options: OptionsType | undefined, - { _, SpServices }: LibsType -): Promise { - try { - const formats = options?.formats || ["woff2", "woff"]; - - const getFileName = (designToken: InputDataType[0]) => { - let fileName: string; - if (!options?.fileNameKey || typeof options.fileNameKey === "string") { - fileName = designToken[(options?.fileNameKey || "name") as string]; - } else { - fileName = options.fileNameKey - .reduce>((acc, key) => { - if ( - _.has(designToken, key) || - _.has(designToken, `value[${key}]`) - ) { - acc.push( - _.get(designToken, key) || _.get(designToken, `value[${key}]`) - ); - } - return acc; - }, []) - .join(" "); - } - return options?.fileNameFormat - ? _[options.fileNameFormat](fileName) - : fileName; - }; - - return ( - await Promise.all( - designTokens.flatMap(async designToken => { - const signedUrlsByFormat = await new Promise< - PartialRecord - >(resolve => - SpServices.font - .convert({ - postscriptName: designToken.value.fontPostScriptName, - formats, - }) - .then(resolve) - .catch(() => resolve({})) - ); - - return ( - Object.entries(signedUrlsByFormat) as Array<[AllowedFormat, string]> - ).map(([format, url]) => { - return { - ...designToken, - value: { - ...designToken.value, - url, - format: format, - fileName: - designToken?.value?.fileName || - `${getFileName(designToken)}.${format}`, - }, - }; - }); - }) - ) - ).flat(2); - } catch (err) { - ConsoleLogger.error(err); - throw err; - } -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/convert-font/convert-font.spec.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/convert-font/convert-font.spec.ts deleted file mode 100644 index 444d57756..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/convert-font/convert-font.spec.ts +++ /dev/null @@ -1,64 +0,0 @@ -import Path from "path"; -import seeds from "../../tests/seeds"; -import convertFont, { OptionsType } from "./convert-font.parser"; -import { AllowedFormat, FontToken } from "../../types"; -import { LibsType } from "../global-libs"; -import libs from "../global-libs"; - -describe("convert-font", () => { - it("Default options", async () => { - const fonts = seeds().tokens.filter( - ({ type }) => type === "font" - ) as Array; - const result = await convertFont(fonts, undefined, libs as LibsType); - if (result instanceof Error) return fail(result); - expect(Array.isArray(result)).toEqual(true); - expect(result.length).toEqual( - fonts.filter(({ value }) => !value.fontFileMissing).length * 2 - ); - result.forEach(item => { - expect(typeof item.value.url).toMatch("string"); - expect( - ["woff2", "woff"].includes(Path.extname(item.value.format).substring(1)) - ); - }); - const fontsWithoutMissing = fonts.filter( - ({ value }) => !value.fontFileMissing - ); - expect(result.map(({ value }) => value.fileName)).toEqual( - fontsWithoutMissing - .map(font => ["woff2", "woff"].map(format => `${font.name}.${format}`)) - .flat(2) - ); - return; - }); - it("Several options", async () => { - const fonts = seeds().tokens.filter( - ({ type }) => type === "font" - ) as Array; - const options: OptionsType = { - formats: ["woff"], - fileNameKey: ["fontFamily", "value.fontWeight", "name"], - fileNameFormat: "kebabCase", - }; - const result = await convertFont(fonts, options, libs as LibsType); - if (result instanceof Error) return fail(result); - expect(Array.isArray(result)).toEqual(true); - expect(result.length).toEqual( - fonts.filter(({ value }) => !value.fontFileMissing).length - ); - result.forEach((item, index) => { - expect(typeof item.value.url).toMatch("string"); - expect( - options.formats!.includes( - Path.extname(item.value.format).substring(1) as AllowedFormat - ) - ); - const expectedName = libs._.kebabCase( - `${fonts[index].value.fontFamily}-${fonts[index].value.fontWeight}-${fonts[index].name}` - ); - expect(item.value.fileName).toEqual(`${expectedName}.woff`); - }); - return; - }); -}); diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/convert-font/index.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/convert-font/index.ts deleted file mode 100644 index cd0c29c2a..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/convert-font/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -import { default as convertFontParser } from "./convert-font.parser"; - -export * from "./convert-font.parser"; -export default convertFontParser; diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/filter/README.md b/tools/executors/typescript/utilities/design-token-parsers/parsers/filter/README.md deleted file mode 100644 index 8a222edae..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/filter/README.md +++ /dev/null @@ -1,131 +0,0 @@ -# Filter - -## Description - -This parser helps you filter tokens and assets by their name using a regular expression. - -Learn more about how to configure Specify in the API documentation: [https://specifyapp.com/developers](https://specifyapp.com/developers). - -## Interface - -```ts -interface parser { - name: "filter"; - options: { - key: string; - regex: - | { - pattern: string; - flags?: string; - } - | string; - }; -} -``` - -### Options - -| Parameter | Required | Type | Default | Description | -| --------------- | -------- | ----------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -| `key` | required | `string` | | Key path to apply the filter function. | -| `regex` | required | `object` `string` | | If you need to define flags inside the [constructor of the regex](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp#literal_notation_and_constructor), use the `object` notation. Otherwise use the `string` notation. | -| `regex.pattern` | required | `string` | | The pattern of the regex used as first argument of the [constructor of the regex](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp#literal_notation_and_constructor). | -| `regex.flags` | optional | `string` | | The flags to use for regex. In the regex constructor it's the second argument [constructor of the regex](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp#literal_notation_and_constructor). | - -### Good to know - -Under the hood the regex is built as: - -`let re = new RegExp('ab+c', 'i') // constructor with string pattern as first argument` - -Where `ab+c` is the regex option in `string` or the `regex.pattern` in object. The second argument is the flags in options. - -## Types - -โ„น๏ธ **Please be aware that, depending on the order you use parsers, their input and output types have to match.** - -### Input - -```ts -type input = Array>; -``` - -### Output - -```ts -type output = Array>; -``` - -## Basic Usage - -### Config - -The following config filters the elements containing the word "Background". - -```jsonc -"parsers": [ - { - "name": "filter", - "options": { - "key": "name", - "regex": { - "pattern": "Background", - "flags": "g" - } - } - } - // ... -] -``` - -### Before/After - -#### Input - -```jsonc -[ - { - // โ€ฆ - "name": "BackgroundColor", - "value": { - "a": 1, - "b": 128, - "g": 255, - "r": 255 - }, - "type": "color" - // โ€ฆ - }, - { - // โ€ฆ - "name": "Colors/Accent", - "value": { - "a": 1, - "b": 255, - "g": 189, - "r": 198 - }, - "type": "color" - // โ€ฆ - } -] -``` - -#### Output - -```jsonc -[ - { - // โ€ฆ - "name": "BackgroundColor", - "value": { - "a": 1, - "b": 128, - "g": 255, - "r": 255 - }, - "type": "color" - // โ€ฆ - } -] -``` diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/filter/filter.parser.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/filter/filter.parser.ts deleted file mode 100644 index 36212be02..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/filter/filter.parser.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { LibsType } from "../global-libs"; - -export type InputDataType = Array>; -export type OutputDataType = InputDataType; -export type OptionsType = { - key: string; - regex: - | { - pattern: string; - flags?: string; // d g i m s u y - } - | string; -}; -export default async function ( - tokens: InputDataType, - options: OptionsType, - { _ }: Pick -): Promise { - try { - const reg = - typeof options.regex === "object" - ? new RegExp(options.regex.pattern, options.regex.flags || "") - : new RegExp(options.regex); - const result: InputDataType = []; - tokens.forEach(token => { - const valueToCheck = _.get(token, options.key); - if (!!valueToCheck && String(valueToCheck).match(reg)) { - result.push(token); - } - }); - return result; - } catch (error) { - throw error; - } -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/filter/filter.spec.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/filter/filter.spec.ts deleted file mode 100644 index 2caae6228..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/filter/filter.spec.ts +++ /dev/null @@ -1,100 +0,0 @@ -import filter from "./filter.parser"; -import { Token } from "../../types"; -import libs from "../global-libs"; -import seeds from "../../tests/seeds"; - -describe("Filter", () => { - it("Should return the elements matching the RegEx", async () => { - const result = await filter( - seeds().tokens as Array, - { key: "name", regex: { pattern: "Background", flags: "g" } }, - libs - ); - if (result instanceof Error) return fail(result); - expect(Array.isArray(result)).toEqual(true); - result.forEach(element => { - expect(typeof element).toBe(typeof {}); - }); - return; - }); - - it("Should return only the element matching the RegEx while ignoring the case", async () => { - const tokens = seeds().tokens as Array; - const result = await filter( - tokens, - { key: "type", regex: { pattern: "VeCtOr", flags: "i" } }, - libs - ); - if (result instanceof Error) return fail(result); - expect(Array.isArray(result)).toEqual(true); - expect(result.length).toEqual( - tokens.filter(token => token.type === "vector").length - ); - return; - }); - - it("Should return all the elements when regex is empty", async () => { - const result = await filter( - seeds().tokens as Array, - { key: "name", regex: { pattern: "", flags: "g" } }, - libs - ); - if (result instanceof Error) return fail(result); - expect(result).toBeDefined(); - expect(Array.isArray(result)).toEqual(true); - expect(result.length).toEqual(seeds().tokens.length); - return; - }); - - it("Should return one element when RegEx is without flag", async () => { - const result = await filter( - seeds().tokens as Array, - { key: "name", regex: { pattern: "Background" } }, - libs - ); - if (result instanceof Error) return fail(result); - expect(result).toBeDefined(); - expect(Array.isArray(result)).toEqual(true); - expect(result.length).toEqual(1); - return; - }); - - it("Should return one element when RegEx is with empty flag", async () => { - const result = await filter( - seeds().tokens as Array, - { key: "name", regex: { pattern: "Background", flags: "" } }, - libs - ); - if (result instanceof Error) return fail(result); - expect(result).toBeDefined(); - expect(Array.isArray(result)).toEqual(true); - expect(result.length).toEqual(1); - return; - }); - - it("Should return one element when RegEx is not an object", async () => { - const result = await filter( - seeds().tokens as Array, - { key: "name", regex: "Background" }, - libs - ); - if (result instanceof Error) return fail(result); - expect(result).toBeDefined(); - expect(Array.isArray(result)).toEqual(true); - expect(result.length).toEqual(1); - return; - }); - - it("Should work on non-string values", async () => { - const result = await filter( - seeds().tokens, - { key: "meta.dimension", regex: "2" }, - libs - ); - if (result instanceof Error) return fail(result); - expect(result).toBeDefined(); - expect(Array.isArray(result)).toEqual(true); - expect(result.length).toEqual(1); - return; - }); -}); diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/global-libs.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/global-libs.ts deleted file mode 100644 index b1d62c021..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/global-libs.ts +++ /dev/null @@ -1,43 +0,0 @@ -import _ from "lodash"; -import Mustache from "mustache"; -import SVGO from "svgo"; -import tinycolor from "tinycolor2"; -import { AllowedFormat, PartialRecord } from "../types"; -import { MustacheStatic } from "../types/libs/mustache"; - -/*declare module "lodash" { - export interface LoDashStatic { - pascalCase(string?: string): string; - none(string?: string): string; - } -}*/ - -_.mixin({ pascalCase: _.flow(_.camelCase, _.upperFirst) }); -_.mixin({ none: (i: string) => i }); - -const Libs = { - _, - SVGO, - tinycolor, - Mustache: Mustache as MustacheStatic, - // SpServices is appended to libs during the runtime -}; - -export default Libs; - -export type SpServicesType = { - font: { - convert: (payload: { - postscriptName: string; - formats: Array; - }) => Promise>; - }; - assets: { - getSource: ( - payload: string, - responseType: "text" | "buffer" | "json" - ) => Promise; - }; -}; - -export type LibsType = typeof Libs & { SpServices: SpServicesType }; diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/index.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/index.ts deleted file mode 100644 index c1466228d..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/index.ts +++ /dev/null @@ -1,5 +0,0 @@ -export { default as convertFontParser } from "./convert-font"; -export { default as kebabcasifyParser } from "./kebabcasify"; -export { default as svgoParser } from "./svgo"; -export { default as toCssFontImportParser } from "./to-css-font-import"; -export { default as toTailwindParser } from "./to-tailwind"; diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/kebabcasify/README.md b/tools/executors/typescript/utilities/design-token-parsers/parsers/kebabcasify/README.md deleted file mode 100644 index 848853e53..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/kebabcasify/README.md +++ /dev/null @@ -1,94 +0,0 @@ -# Kebabcasify - -## Description - -This parser helps you apply kebabcase function on specific keys from a design token. - -Learn more about how to configure Specify in the API documentation: [https://specifyapp.com/developers](https://specifyapp.com/developers). - -## Interface - -```ts -interface parser { - name: "kebabcasify"; - options?: { - keys: Array; - }; -} -``` - -### Options - -| Parameter | Required | Type | Default | Description | -| --------- | -------- | ------- | ---------- | --------------------------------------------------- | -| `keys` | optional | `Array` | `["name"]` | The list of keys where the function will be applied | - -## Types - -โ„น๏ธ **Please be aware that, depending on the order you use parsers, their input and output types have to match.** - -### Input - -Array of object with the keys to apply `kebabcase` function - -```ts -type input = Array<{ [key: string]: any }>; -``` - -### Output - -```ts -type output = Array<{ [key: string]: any }>; -``` - -## Usage - -### Config - -```jsonc -"parsers": [ - { - "name": "kebabcasify", - "options": { - "keys": ["name"] - } - } - // ... -] -``` - -### Before/After - -#### Input - -```jsonc -[ - { - "type": "color", - "value": { - "a": 0.96, - "b": 20, - "g": 227, - "r": 122 - }, - "name": "Brand / Primary Color" - } -] -``` - -#### Output - -```jsonc -[ - { - "type": "color", - "value": { - "a": 0.96, - "b": 20, - "g": 227, - "r": 122 - }, - "name": "brand-primary-color" - } -] -``` diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/kebabcasify/index.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/kebabcasify/index.ts deleted file mode 100644 index 1a0c645b0..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/kebabcasify/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -import { default as kebabcasifyParser } from "./kebabcasify.parser"; - -export * from "./kebabcasify.parser"; -export default kebabcasifyParser; diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/kebabcasify/kebabcasify.parser.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/kebabcasify/kebabcasify.parser.ts deleted file mode 100644 index df913c463..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/kebabcasify/kebabcasify.parser.ts +++ /dev/null @@ -1,25 +0,0 @@ -/* eslint-disable @typescript-eslint/no-explicit-any */ -import { LibsType } from "../global-libs"; - -export type InputDataType = Array>; -export type OutputDataType = InputDataType; -export type OptionsType = - | undefined - | { - keys: Array; - }; - -export default async function ( - tokens: InputDataType, - options: OptionsType = { keys: ["name"] }, - { _ }: Pick -): Promise { - return tokens.map((token: any) => { - options.keys.forEach((key: string) => { - if (_.has(token, key)) { - return _.set(token, key, _.kebabCase(_.get(token, key))); - } - }); - return token; - }); -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/kebabcasify/kebabcasify.spec.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/kebabcasify/kebabcasify.spec.ts deleted file mode 100644 index 331c04aa9..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/kebabcasify/kebabcasify.spec.ts +++ /dev/null @@ -1,59 +0,0 @@ -import kebabcasify from "./kebabcasify.parser"; -import { Token } from "../../types"; -import libs from "../global-libs"; -import seeds from "../../tests/seeds"; - -describe("Kebabcasify", () => { - it("Get tokens - apply parsers", async () => { - const result = await kebabcasify( - seeds().tokens as Array, - { keys: ["name"] }, - libs - ); - if (result instanceof Error) return fail(result); - result.forEach(token => expect(token.name?.includes(" ")).toEqual(false)); - return; - }); - it("Get tokens - apply parsers - default", async () => { - const result = await kebabcasify( - seeds().tokens as Array, - undefined, - libs - ); - if (result instanceof Error) return fail(result); - result.forEach(token => { - expect(token.name?.includes(" ")).toEqual(false); - }); - return; - }); - it("Get tokens - apply parsers - without tokens", async () => { - const result = await kebabcasify([], undefined, libs); - if (result instanceof Error) return fail(result); - expect(Array.isArray(result)).toBeTruthy(); - expect(result.length).toEqual(0); - return; - }); - it("Get tokens - apply parsers - unknown target key", async () => { - const input = seeds().tokens; - const result = await kebabcasify( - input, - { keys: ["name", "not exist"] }, - libs - ); - expect(Array.isArray(result)).toBeTruthy(); - expect(result.length).toEqual(input.length); - return; - }); - it("Get tokens - apply parsers - error", async () => { - try { - await kebabcasify( - // @ts-ignore - "wrong type", - { keys: ["name", "not exist"] }, - libs - ); - } catch (err) { - return; - } - }); -}); diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/name-assets-files-by-pattern/README.md b/tools/executors/typescript/utilities/design-token-parsers/parsers/name-assets-files-by-pattern/README.md deleted file mode 100644 index 676685aaf..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/name-assets-files-by-pattern/README.md +++ /dev/null @@ -1,202 +0,0 @@ -# Name asset files by pattern - -## Description - -This parser helps you set a structured filename on your assets. It won't rename your asset but only add a new `filename` property on the asset object. The filename structure uses [mustache](https://github.com/janl/mustache.js#templates) as a template engine. - -Learn more about how to configure Specify in the API documentation: [https://specifyapp.com/developers](https://specifyapp.com/developers). - -## Interface - -```ts -interface parser { - name: "name-assets-files-by-pattern"; - options: { - pattern: string; - }; -} -``` - -### Options - -| Parameter | Required | Type | Default | Description | -| --------- | -------- | -------- | ------- | ---------------------------------------------------------------------------------------------------------------------------------- | -| `pattern` | required | `string` | | The pattern used to generate files names. It must match [mustache](https://github.com/janl/mustache.js#templates) template syntax. | - -## Output - -Please keep in mind that this parser generates files. This is why you should always set a folder as the final `path` in your parent rule. - -
-See Do & Don't config examples - -โœ… Do - -``` -// ... -"rules": [ - { - "name": "Assets", - "path": "assets", // <-- path set as a folder - "parsers": [ - { - "name": "name-assets-files-by-pattern" - } - ] - } -] -``` - -๐Ÿšซ Don't - -``` -// ... -"rules": [ - { - "name": "Assets", - "path": "assets/assets.json", // <-- path set as a file - "parsers": [ - { - "name": "name-assets-files-by-pattern" - } - ] - } -] -``` - -
- -## Types - -โ„น๏ธ **Please be aware that, depending on the order you use parsers, their input and output types have to match.** - -### Input - -Array of object containing at least the keys described in the pattern option. - -```ts -type input = Array<{ [key: string]: any }>; -``` - -### Output - -```ts -type output = Array<{ [key: string]: any }>; -``` - -## Basic usage - -### Config - -```jsonc -"parsers": [ - { - "name": "name-assets-files-by-pattern", - "options": { - "pattern": "{{name}}-{{type}}.{{format}}" - } - } - // โ€ฆ -] -``` - -### Before/After - -#### Input - -```jsonc -[ - { - "type": "vector", - "value": { - "url": "https://...", - "format": "svg" - }, - "name": "Warning" - } -] -``` - -#### Output - -```jsonc -[ - { - "type": "vector", - "value": { - "url": "https://...", - "format": "svg", - "fileName": "Warning-vector.svg" - }, - "name": "Warning" - } -] -``` - -## Complex usage - with condition in template - -### Config - -```jsonc -"parsers": [ - { - "name": "name-assets-files-by-pattern", - "options": { - "pattern": "{{name}}{{#dimension}}@{{dimension}}{{/dimension}}.{{format}}" - } - } - // โ€ฆ -] -``` - -### Before/After - -#### Input - -```jsonc -[ - { - "type": "bitmap", - "value": { - "url": "https://...", - "format": "png", - "dimension": "2x" - }, - "name": "bitmapExampleWithDimension" - }, - { - "type": "bitmap", - "value": { - "url": "https://...", - "format": "webp" - }, - "name": "bitmapExampleWithoutDimension" - } -] -``` - -#### Output - -```jsonc -[ - { - "type": "bitmap", - "value": { - "url": "https://...", - "format": "png", - "dimension": "2x", - "fileName": "bitmapExampleWithDimension@2x.png" // <--- - }, - "name": "bitmapExampleWithDimension" - }, - { - "type": "bitmap", - "value": { - "url": "https://...", - "format": "webp", - "fileName": "bitmapExampleWithoutDimension.webp" // <--- - }, - "name": "bitmapExampleWithoutDimension" - } -] -``` diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/name-assets-files-by-pattern/name-assets-files-by-pattern.parser.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/name-assets-files-by-pattern/name-assets-files-by-pattern.parser.ts deleted file mode 100644 index a24e7115f..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/name-assets-files-by-pattern/name-assets-files-by-pattern.parser.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { LibsType } from "../global-libs"; -import Template from "../../libs/template"; - -export type InputDataType = Array>; -export type OutputDataType = InputDataType; -export type OptionsType = { - pattern: string; -}; - -export default async function ( - assets: InputDataType, - options: OptionsType, - libs: Pick -): Promise { - const template = new Template(options.pattern); - return assets.map(asset => - libs._.set(asset, "value.fileName", template.render(asset)) - ); -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/name-assets-files-by-pattern/name-assets-files-by-pattern.spec.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/name-assets-files-by-pattern/name-assets-files-by-pattern.spec.ts deleted file mode 100644 index e855b7af4..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/name-assets-files-by-pattern/name-assets-files-by-pattern.spec.ts +++ /dev/null @@ -1,46 +0,0 @@ -import nameAssetsFilesByPattern from "./name-assets-files-by-pattern.parser"; -import { VectorToken, BitmapToken } from "../../types"; -import libs from "../global-libs"; -import seeds from "../../tests/seeds"; - -describe("Name assets files by pattern", () => { - it("Get tokens - apply parser", async () => { - const vectors = seeds().tokens.filter( - ({ type }) => type === "vector" - ) as Array; - const result = await nameAssetsFilesByPattern( - vectors, - { pattern: "{{name}}-{{type}}.{{format}}" }, - libs - ); - if (result instanceof Error) return fail(result); - vectors.forEach(vector => { - expect(vector.value.fileName).toEqual( - `${vector.name}-vector.${vector.value.format}` - ); - }); - return; - }); - it("Get tokens - apply parser - bitmap", async () => { - const bitmaps = seeds().tokens.filter( - ({ type }) => type === "bitmap" - ) as Array; - const result = await nameAssetsFilesByPattern( - bitmaps, - { - pattern: - "{{name}}{{#dimension}}@{{dimension}}{{/dimension}}.{{format}}", - }, - libs - ); - if (result instanceof Error) return fail(result); - bitmaps.forEach(bitmap => { - expect(bitmap.value.fileName).toEqual( - `${bitmap.name}${ - bitmap.value.dimension ? `@${bitmap.value.dimension}` : "" - }.${bitmap.value.format}` - ); - }); - return; - }); -}); diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/omit/README.md b/tools/executors/typescript/utilities/design-token-parsers/parsers/omit/README.md deleted file mode 100644 index f8d2ace46..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/omit/README.md +++ /dev/null @@ -1,165 +0,0 @@ -# Omit - -## Description - -This parser helps you omit keys from a design token not given in parameters. - -Learn more about how to configure Specify in the API documentation: [https://specifyapp.com/developers](https://specifyapp.com/developers). - -## Interface - -```ts -interface parser { - name: "omit"; - options?: { - keys: Array; - filter?: { - types: Array; - }; - flatten?: boolean; - }; -} -``` - -### Options - -| Parameter | Required | Type | Default | Description | -| -------------- | -------- | --------- | ------- | ----------------------------------------------------------- | -| `keys` | optional | `Array` | `[]` | The list of keys where the function will be applied. | -| `filter.types` | optional | `Array` | `[]` | The list of token types where the function will be applied. | -| `flatten` | optional | `boolean` | `false` | Allow flattening each object after omiting their values. | - -## Types - -โ„น๏ธ **Please be aware that, depending on the order you use parsers, their input and output types have to match.** - -### Input - -Array of object with at least a name's key - -```ts -type input = Array<{ [key: string]: any }>; -``` - -### Output - -Array of object without the given keys - -```ts -type output = Array<{ [key: string]: any }>; -``` - -## Simple Usage - -### Config - -```jsonc -"parsers": [ - { - "name": "omit", - "options": { - "keys": ["value.a"] - } - } - // โ€ฆ -] -``` - -### Before/After - -#### Input - -```jsonc -[ - { - "type": "color", - "value": { - "a": 0.96, - "b": 20, - "g": 227, - "r": 122 - }, - "name": "Brand / Primary Color" - } -] -``` - -#### Output - -```jsonc -[ - { - "name": "Brand / Primary Color", - "value": { - "b": 20, - "g": 227, - "r": 122 - }, - "type": "color" - } -] -``` - -## Complexe Usage - -### Config - -```jsonc -{ - "name": "omit", - "options": { - "keys": ["value"], - "flatten": true - } -} -// โ€ฆ -``` - -### Before/After - -#### Input - -```jsonc -[ - { - "name": "Border / Main", - "type": "color", - "value": { - "type": "solid", - "color": { - "value": { - "a": 0.5, - "b": 239, - "g": 80, - "r": 102 - } - }, - "width": { - "value": { - "unit": "px", - "measure": 2 - } - } - }, - "meta": { - "source": "frames", - "sourceFile": "https://www.figma.com/file/9KvLO7F8VPrJ7GxGBWwCr9", - "originFrameName": "Border ยท Frame Example" - } - } -] -``` - -#### Output - -```jsonc -[ - { - "name": "Border / Main", - "type": "color", - "source": "frames", - "sourceFile": "https://www.figma.com/file/9KvLO7F8VPrJ7GxGBWwCr9", - "originFrameName": "Border ยท Frame Example" - } -] -``` diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/omit/omit.parser.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/omit/omit.parser.ts deleted file mode 100644 index 763046571..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/omit/omit.parser.ts +++ /dev/null @@ -1,46 +0,0 @@ -import { LibsType } from "../global-libs"; -import { TokensType } from "../../types"; - -export type InputDataType = Array>; -export type OutputDataType = InputDataType; -export type OptionsType = - | undefined - | { - keys: Array; - filter?: { - types: Array; - }; - flatten?: boolean; - }; - -const flattenObject = (obj: Record) => { - const flattened: Record = {}; - Object.keys(obj).forEach(key => { - if (typeof obj[key] === "object" && obj[key] !== null) { - Object.assign(flattened, flattenObject(obj[key])); - } else { - flattened[key] = obj[key]; - } - }); - - return flattened; -}; - -export default async function ( - tokens: InputDataType, - options: OptionsType = { keys: [] }, - { _ }: Pick -): Promise { - return tokens.map(token => { - if ( - !options?.filter || - (options?.filter?.types && - options.filter.types.length && - options.filter!.types.includes(token.type)) - ) { - const obj = _.omit(token, options.keys); - return options.flatten ? flattenObject(obj) : obj; - } - return token; - }); -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/omit/omit.spec.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/omit/omit.spec.ts deleted file mode 100644 index c854f895c..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/omit/omit.spec.ts +++ /dev/null @@ -1,63 +0,0 @@ -import seeds from "../../tests/seeds"; -import omit from "./omit.parser"; -import libs from "../global-libs"; -import { has } from "lodash"; - -describe("Omit", () => { - it("Execute parser", async () => { - const tokens = seeds().tokens; - const result = await omit( - tokens, - { - keys: ["value.color"], - }, - libs - ); - if (result instanceof Error) return fail(result); - expect(tokens.length).toEqual(result.length); - result.forEach(token => expect(has(token, "value.color")).toEqual(false)); - return; - }); - it("Execute parser with filter", async () => { - const tokens = seeds().tokens; - const result = await omit( - tokens, - { - keys: ["value.color"], - filter: { - types: ["textStyle"], - }, - }, - libs - ); - if (result instanceof Error) return fail(result); - expect(tokens.length).toEqual(result.length); - result.forEach(token => { - if (token.type === "textStyle") - expect(has(token, "value.color")).toEqual(false); - if (token.type === "border") - expect(has(token, "value.color")).toEqual(true); - }); - return; - }); - it("Execute parser with flatten option", async () => { - const tokens = seeds().tokens; - const result = await omit( - tokens, - { - keys: ["value"], - flatten: true, - }, - libs - ); - expect(tokens.length).toEqual(result.length); - if (result instanceof Error) return fail(result); - result.forEach(token => { - Object.keys(token).forEach(key => { - expect(token["value"]).toBeFalsy(); - expect(typeof token[key] !== "object").toBeTruthy(); - }); - }); - return; - }); -}); diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/pascalcasify/README.md b/tools/executors/typescript/utilities/design-token-parsers/parsers/pascalcasify/README.md deleted file mode 100644 index 6aa9fdc37..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/pascalcasify/README.md +++ /dev/null @@ -1,88 +0,0 @@ -# Pascalcasify - -## Description - -This parser helps you apply pascalcase function on specific keys from a design token. - -Learn more about how to configure Specify in the API documentation: [https://specifyapp.com/developers](https://specifyapp.com/developers). - -## Interface - -```ts -interface parser { - name: "pascalcasify"; - options?: { - keys: Array; - }; -} -``` - -### Options - -| Parameter | Required | Type | Default | Description | -| --------- | -------- | ------- | ---------- | --------------------------------------------------- | -| `keys` | optional | `Array` | `["name"]` | The list of keys where the function will be applied | - -## Types - -โ„น๏ธ **Please be aware that, depending on the order you use parsers, their input and output types have to match.** - -### Input - -Array of object with the keys to apply `pascalcase` function - -```ts -type input = Array<{ [key: string]: any }>; -``` - -### Output - -```ts -type output = Array<{ [key: string]: any }>; -``` - -## Usage - -### Config - -```jsonc -"parsers": [ - { - "name": "pascalcasify", - "options": { - "keys": ["name"] - } - } - // โ€ฆ -] -``` - -### Before/After - -#### Input - -```jsonc -[ - { - "type": "color", - "value": { - "a": 0.96, - "b": 20, - "g": 227, - "r": 122 - }, - "name": "Brand / Primary Color" - } -] -``` - -#### Output - -```jsonc -[ - { - "type": "color", - "name": "BrandPrimaryColor" - } -] -``` diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/pascalcasify/pascalcasify.parser.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/pascalcasify/pascalcasify.parser.ts deleted file mode 100644 index 2a1c34f9d..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/pascalcasify/pascalcasify.parser.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { LibsType } from "../global-libs"; - -export type InputDataType = Array>; -export type OutputDataType = InputDataType; -export type OptionsType = - | undefined - | { - keys: Array; - }; - -export default async function ( - tokens: InputDataType, - options: OptionsType = { keys: ["name"] }, - { _ }: Pick -): Promise { - try { - return tokens.map(token => { - options.keys.forEach(key => { - if (_.has(token, key)) { - _.set(token, key, _.pascalCase(_.get(token, key))); - } - }); - return token; - }); - } catch (err) { - throw err; - } -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/pascalcasify/pascalcasify.spec.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/pascalcasify/pascalcasify.spec.ts deleted file mode 100644 index d39fac3f3..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/pascalcasify/pascalcasify.spec.ts +++ /dev/null @@ -1,61 +0,0 @@ -import pascalcasify from "./pascalcasify.parser"; -import { Token } from "../../types"; -import libs from "../global-libs"; -import seeds from "../../tests/seeds"; - -describe("Pascalcasify", () => { - it("Get tokens - apply parsers", async () => { - const result = await pascalcasify( - seeds().tokens as Array, - { keys: ["name"] }, - libs - ); - if (result instanceof Error) return fail(result); - result.forEach(token => { - expect(token.name?.includes(" ")).toEqual(false); - }); - return; - }); - it("Get tokens - apply parsers - default", async () => { - const result = await pascalcasify( - seeds().tokens as Array, - undefined, - libs - ); - if (result instanceof Error) return fail(result); - result.forEach(token => { - expect(token.name?.includes(" ")).toEqual(false); - }); - return; - }); - it("Get tokens - apply parsers - without tokens", async () => { - const result = await pascalcasify([], undefined, libs); - if (result instanceof Error) return fail(result); - expect(Array.isArray(result)).toBeTruthy(); - expect(result.length).toEqual(0); - return; - }); - it("Get tokens - apply parsers - unknown target key", async () => { - const input = seeds().tokens; - const result = await pascalcasify( - input, - { keys: ["name", "not exist"] }, - libs - ); - expect(Array.isArray(result)).toBeTruthy(); - expect(result.length).toEqual(input.length); - return; - }); - it("Get tokens - apply parsers - error", async () => { - try { - await pascalcasify( - // @ts-ignore - "wrong type", - { keys: ["name", "not exist"] }, - libs - ); - } catch (err) { - return; - } - }); -}); diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/pick/README.md b/tools/executors/typescript/utilities/design-token-parsers/parsers/pick/README.md deleted file mode 100644 index bf3f0c91f..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/pick/README.md +++ /dev/null @@ -1,158 +0,0 @@ -# Pick - -## Description - -This parser helps you get only specific keys from a design token given in params. - -Learn more about how to configure Specify in the API documentation: [https://specifyapp.com/developers](https://specifyapp.com/developers). - -## Interface - -```ts -interface parser { - name: "pick"; - options?: { - keys: Array; - filter?: { - types: Array; - }; - flatten?: boolean; - }; -} -``` - -### Options - -| Parameter | Required | Type | Default | Description | -| -------------- | -------- | --------- | ---------- | ----------------------------------------------------------- | -| `keys` | optional | `Array` | `["name"]` | The list of keys where the function will be applied. | -| `filter.types` | optional | `Array` | `[]` | The list of token types where the function will be applied. | -| `flatten` | optional | `boolean` | `false` | Allow flattening each object after picking their values. | - -## Types - -โ„น๏ธ **Please be aware that, depending on the order you use parsers, their input and output types have to match.** - -### Input - -Array of object with at least a name's key - -```ts -type input = Array<{ [key: string]: any }>; -``` - -### Output - -Array of object with the keys given in options - -```ts -type output = Array<{ [key: string]: any }>; -``` - -## Simple Usage - -### Config - -```jsonc -"parsers": [ - { - "name": "pick", - "options": { - "keys": ["name", "type"] - } - } - // โ€ฆ -] -``` - -### Before/After - -#### Input - -```js -[ - { - type: "color", - value: { - a: 0.96, - b: 20, - g: 227, - r: 122, - }, - name: "Brand / Primary Color", - }, -]; -``` - -#### Output - -```jsonc -[ - { - "name": "Brand / Primary Color", - "type": "color" - } -] -``` - -## Complexe Usage - -### Config - -```jsonc -"parsers": [ - { - "name": "pick", - "options": { - "keys": ["name", "meta.originFrameName"], - "flatten": true - } - } - // โ€ฆ -] -``` - -### Before/After - -#### Input - -```jsonc -[ - { - "name": "Border / Main", - "value": { - "type": "solid", - "color": { - "value": { - "a": 0.5, - "b": 239, - "g": 80, - "r": 102 - } - }, - "width": { - "value": { - "unit": "px", - "measure": 2 - } - } - }, - "meta": { - "source": "frames", - "sourceFile": "https://www.figma.com/file/9KvLO7F8VPrJ7GxGBWwCr9", - "originFrameName": "Border ยท Frame Example" - } - } -] -``` - -#### Output - -```jsonc -[ - { - "name": "Border / Main", - "originFrameName": "Border ยท Frame Example" - } -] -``` diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/pick/pick.parser.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/pick/pick.parser.ts deleted file mode 100644 index dd544f484..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/pick/pick.parser.ts +++ /dev/null @@ -1,47 +0,0 @@ -import { LibsType } from "../global-libs"; -import { TokensType } from "../../types"; - -export type InputDataType = Array>; -export type OutputDataType = InputDataType; -export type OptionsType = - | undefined - | { - keys: Array; - filter?: { - types: Array; - }; - flatten?: boolean; - }; - -const flattenObject = (obj: Record) => { - const flattened: Record = {}; - - Object.keys(obj).forEach(key => { - if (typeof obj[key] === "object" && obj[key] !== null) { - Object.assign(flattened, flattenObject(obj[key])); - } else { - flattened[key] = obj[key]; - } - }); - - return flattened; -}; - -export default async function ( - tokens: InputDataType, - options: OptionsType = { keys: ["name"] }, - { _ }: Pick -): Promise { - return tokens.map(token => { - if ( - !options?.filter || - (options?.filter?.types && - options.filter.types.length && - options.filter!.types.includes(token.type)) - ) { - const obj = _.pick(token, options.keys); - return options.flatten ? flattenObject(obj) : obj; - } - return token; - }); -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/pick/pick.spec.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/pick/pick.spec.ts deleted file mode 100644 index a68141893..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/pick/pick.spec.ts +++ /dev/null @@ -1,71 +0,0 @@ -import seeds from "../../tests/seeds"; -import pick from "./pick.parser"; -import libs from "../global-libs"; -import { has } from "lodash"; - -describe("Pick", () => { - it("Execute parser", async () => { - const result = await pick( - seeds().tokens, - { - keys: ["name", "type"], - }, - libs - ); - if (result instanceof Error) return fail(result); - result.forEach(token => - expect(Object.keys(token)).toEqual(["name", "type"]) - ); - return; - }); - it("Execute parser without option", async () => { - const result = await pick(seeds().tokens, undefined, libs); - if (result instanceof Error) return fail(result); - result.forEach(token => expect(Object.keys(token)).toEqual(["name"])); - return; - }); - it("Execute parser with flatten option", async () => { - const tokens = seeds().tokens; - const result = await pick( - tokens, - { - keys: ["id", "name", "meta.originFrameName"], - flatten: true, - }, - libs - ); - - if (result instanceof Error) return fail(result); - - tokens.forEach(token => { - const expectation = ["id", "name"]; - if (token.meta?.originFrameName) expectation.push("originFrameName"); - expect(Object.keys(result.find(({ id }) => id === token.id)!)).toEqual( - expectation - ); - }); - return; - }); - it("Execute parser with filter", async () => { - const tokens = seeds().tokens; - const result = await pick( - tokens, - { - keys: ["value.font"], - filter: { - types: ["textStyle"], - }, - }, - libs - ); - if (result instanceof Error) return fail(result); - expect(tokens.length).toEqual(result.length); - result.forEach(token => { - if (token.type === "textStyle") - expect(has(token, "value.color")).toEqual(false); - if (token.type === "border") - expect(has(token, "value.color")).toEqual(true); - }); - return; - }); -}); diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/px-to-rem/README.md b/tools/executors/typescript/utilities/design-token-parsers/parsers/px-to-rem/README.md deleted file mode 100644 index e7b066ce2..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/px-to-rem/README.md +++ /dev/null @@ -1,95 +0,0 @@ -# PX to REM - -## Description - -This parser helps you convert the value of a measurement design token from pixel to rem. - -Learn more about how to configure Specify in the API documentation: [https://specifyapp.com/developers](https://specifyapp.com/developers). - -## Interface - -```ts -interface parser { - name: "px-to-rem"; - options: { - basePixelValue?: number; - keys: Array; - }; -} -``` - -### Options - -| Parameter | Required | Type | Default | Description | -| ---------------- | -------- | --------------- | ------- | ----------------------------------------- | -| `basePixelValue` | optional | `number` | 16 | Base font size of your HTML document | -| `keys` | required | `Array` | | List of key paths to apply the convertion | - -## Types - -โ„น๏ธ **Please be aware that, depending on the order you use parsers, their input and output types have to match.** - -Array of object with at least the keys describe in the keys option. -Values must match the type [MeasurementValue](https://github.com/Specifyapp/parsers/blob/master/types/tokens/Measurement.ts#L3) - -### Input - -```ts -type input = Array>; -``` - -### Output - -```ts -type output = Array>; -``` - -## Usage - -### Config - -```jsonc -"parsers": [ - { - "name": "px-to-rem", - "options": { - "keys": ["fontSize"] - } - } - // โ€ฆ -] -``` - -### Before/After - -#### Input - -```jsonc -{ - // โ€ฆ - "fontSize": { - "value": { - "unit": "px", - "measure": 14 - } - } - // โ€ฆ -} -``` - -#### Output - -```jsonc -[ - { - // โ€ฆ - "value": { - "fontSize": { - "measure": 0.875, - "unit": "rem" - } - } - // โ€ฆ - } -] -``` diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/px-to-rem/px-to-rem.parser.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/px-to-rem/px-to-rem.parser.ts deleted file mode 100644 index 8f2cc5b6f..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/px-to-rem/px-to-rem.parser.ts +++ /dev/null @@ -1,42 +0,0 @@ -import { LibsType } from "../global-libs"; -import convertMeasurement from "../../libs/size-manipulation"; -import { MeasurementValue } from "../../types"; -import _ from "lodash"; - -export type InputDataType = Array>; -export type OutputDataType = InputDataType; -export type OptionsType = { - basePixelValue?: number; - keys: Array; -}; - -const predicateKey = (input: InputDataType[0], key: string) => { - const ref = _.has(input, key) - ? key - : _.has(input, `value.${key}`) - ? `value.${key}` - : undefined; - return _.has(input, `${ref}.value`) ? `${ref}.value` : ref; -}; - -export default async function ( - inputData: InputDataType, - options: OptionsType, - { _ }: Pick -): Promise { - inputData.forEach(input => { - options.keys.forEach(key => { - const ref = predicateKey(input, key); - if (!ref) return; - let measurement = _.get(input, ref) as MeasurementValue; - if (measurement && "unit" in measurement && measurement.unit === "px") { - _.set( - input, - ref, - convertMeasurement(measurement, "rem", options.basePixelValue) - ); - } - }); - }); - return inputData; -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/px-to-rem/px-to-rem.spec.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/px-to-rem/px-to-rem.spec.ts deleted file mode 100644 index 901021571..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/px-to-rem/px-to-rem.spec.ts +++ /dev/null @@ -1,62 +0,0 @@ -import seeds from "../../tests/seeds"; -import { default as pxToRem, InputDataType } from "./px-to-rem.parser"; -import libs, { LibsType } from "../global-libs"; -import { TextStyleValue } from "../../types"; - -describe("px-to-rem", () => { - it("Get tokens - execute parser", async () => { - const inputData = seeds().tokens.filter( - ({ type }) => type === "textStyle" - ) as unknown as InputDataType; - const result = await pxToRem(inputData, { keys: ["value.fontSize"] }, libs); - if (result instanceof Error) return fail(result); - result.forEach((textStyle, index) => { - const unit = (textStyle.value as TextStyleValue).fontSize.value.unit; - const measure = (textStyle.value as TextStyleValue).fontSize.value - .measure; - expect(unit).toEqual("rem"); - expect(measure * 16).toEqual( - (inputData[index].value as TextStyleValue).fontSize.value.measure * 16 - ); - }); - return; - }); - it("Get tokens - execute parser - with predicate config", async () => { - const inputData = seeds().tokens.filter( - ({ type }) => type === "textStyle" - ) as unknown as InputDataType; - const result = await pxToRem(inputData, { keys: ["fontSize"] }, libs); - if (result instanceof Error) return fail(result); - result.forEach((textStyle, index) => { - const unit = (textStyle.value as TextStyleValue).fontSize.value.unit; - const measure = (textStyle.value as TextStyleValue).fontSize.value - .measure; - expect(unit).toEqual("rem"); - expect(measure * 16).toEqual( - (inputData[index].value as TextStyleValue).fontSize.value.measure * 16 - ); - }); - return; - }); - it("Get tokens - execute parser - with basePixelValue", async () => { - const inputData = seeds().tokens.filter( - ({ type }) => type === "textStyle" - ) as unknown as InputDataType; - const result = await pxToRem( - inputData, - { keys: ["fontSize.value"], basePixelValue: 20 }, - libs - ); - if (result instanceof Error) return fail(result); - result.forEach((textStyle, index) => { - const unit = (textStyle.value as TextStyleValue).fontSize.value.unit; - const measure = (textStyle.value as TextStyleValue).fontSize.value - .measure; - expect(unit).toEqual("rem"); - expect(measure * 20).toEqual( - (inputData[index].value as TextStyleValue).fontSize.value.measure * 20 - ); - }); - return; - }); -}); diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/replace-string/README.md b/tools/executors/typescript/utilities/design-token-parsers/parsers/replace-string/README.md deleted file mode 100644 index ff1893fb5..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/replace-string/README.md +++ /dev/null @@ -1,131 +0,0 @@ -# Replace string - -## Description - -This parser helps you replace any string matched by a regex by a new string. - -## Example use case - -Let's say you have some a color named "Red" in your Figma local styles in a "Colors" folder. The color name returned by Figma is "Colors / Red". - -This parser helps you rename your design tokens without characters before the last slash: - -- before: "Colors / Red" -- after: "Red" - -## Interface - -```ts -interface parser { - name: "replace-string"; - options: { - keys?: Array; - regex: - | { - pattern: string; - flags?: string; - } - | string; - replaceBy?: string; - trim?: boolean; - }; -} -``` - -### Options - -| Parameter | Required | Type | Default | Description | -| --------------- | -------- | ----------------- | ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -| `keys` | optional | `Array` | | List of key path to apply the replace function | -| `regex` | required | `object` `string` | | if string: the parameter used for the [constructor of the regex](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp#literal_notation_and_constructor). If your use case need to use flags prefer object notation. | -| `regex.pattern` | required | `string` | | the pattern of the regex used as first argument of the [constructor](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp#literal_notation_and_constructor) | -| `regex.flags` | optional | `string` | | the flags to use for regex. In the regex constructor it's the second argument [constructor of the regex](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp#literal_notation_and_constructor) | -| `replaceBy` | optional | `string` | `[empty string]` | The value will used as replacement. [This method](https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Global_Objects/String/replace) is used to apply the replacement. | -| `trim` | optional | `boolean` | `false` | Set true to remove spaces before and after the transformed values. [This method](https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Global_Objects/String/Trim) is used to trim | - -### Good to know - -Under the hood the regex is build like: - -`let re = new RegExp('ab+c', 'i') // constructor with string pattern as first argument` - -Where `ab+c` is the regex option in `string` or the `regex.pattern` in object. The second argument is the flags in options. - -## Types - -โ„น๏ธ **Please be aware that, depending on the order you use parsers, their input and output types have to match.** - -### Input - -```ts -type input = string | Array>; -``` - -### Output - -```ts -type output = Array>; -``` - -## Basic Usage - -### Config - -The following config changes a design token name property by keeping only characters present after the last slash character (`/`). - -```jsonc -"parsers": [ - { - "name": "replace-string", - "options": { - "keys": ["name"], - "regex": { - "pattern": "(.*?)\\/", - "flags": "g" - }, - "trim": true - } - } - // โ€ฆ -] -``` - -### Before/After - -#### Input - -```jsonc -[ - { - // โ€ฆ - "name": "Colors/Accent", - "value": { - "a": 1, - "b": 255, - "g": 189, - "r": 198 - }, - "type": "color" - // โ€ฆ - } -] -``` - -#### Output - -```jsonc -[ - { - // โ€ฆ - "name": "Accent", - "value": { - "a": 1, - "b": 255, - "g": 189, - "r": 198 - }, - "type": "color" - // โ€ฆ - } -] -``` diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/replace-string/replace-string.parser.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/replace-string/replace-string.parser.ts deleted file mode 100644 index 4226b17e4..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/replace-string/replace-string.parser.ts +++ /dev/null @@ -1,58 +0,0 @@ -import { LibsType } from "../global-libs"; -import listPathsByPattern from "../../libs/list-paths-by-pattern"; - -export type InputDataType = string | Array>; -export type OutputDataType = InputDataType; -export type OptionsType = { - keys?: Array; - regex: - | { - pattern: string; - flags?: string; // d g i m s u y - } - | string; - replaceBy?: string; - trim?: boolean; -}; - -async function replaceString( - input: string, - options: OptionsType, - { _ }: Pick -): Promise; -async function replaceString( - input: Array>, - options: OptionsType, - { _ }: Pick -): Promise>>; -async function replaceString( - input: InputDataType, - options: OptionsType, - { _ }: Pick -): Promise>> { - const reg = - typeof options.regex === "object" - ? new RegExp(options.regex.pattern, options.regex.flags || "") - : new RegExp(options.regex); - - if (typeof input === "string") { - const result = input.replace(reg, options.replaceBy || ""); - return options.trim ? result.trim() : result; - } else { - return input.map(token => { - options.keys!.forEach(pattern => { - const paths = listPathsByPattern(token, pattern); - paths.forEach(selector => { - const newValue = _.get(token, selector).replace( - reg, - options.replaceBy || "" - ); - _.set(token, selector, options.trim ? newValue.trim() : newValue); - }); - }); - return token; - }); - } -} - -export default replaceString; diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/replace-string/replace-string.spec.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/replace-string/replace-string.spec.ts deleted file mode 100644 index 7a16bd26f..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/replace-string/replace-string.spec.ts +++ /dev/null @@ -1,104 +0,0 @@ -import libs from "../global-libs"; -import seeds from "../../tests/seeds"; -import replaceString from "./replace-string.parser"; - -describe("Replace string", () => { - it("Should return string with characters after the last slash with flags", async () => { - const tokens = seeds().tokens; - const result = await replaceString( - tokens, - { - keys: ["name"], - regex: { pattern: "(.*?)\\/", flags: "g" }, - trim: true, - }, - libs - ); - if (result instanceof Error) return fail(result); - result.map(token => { - expect(token.name).not.toContain("/"); - expect(token.name.charAt(0)).not.toContain(" "); - expect(token.name.charAt(token.name.length - 1)).not.toContain(" "); - }); - }); - it("Should return string with characters after the first slash", async () => { - const tokens = seeds().tokens; - const result = await replaceString( - tokens, - { keys: ["name"], regex: { pattern: "(.*?)\\/" }, trim: true }, - libs - ); - if (result instanceof Error) return fail(result); - result.map(token => { - expect(token.name).not.toContain("/"); - expect(token.name.charAt(0)).not.toContain(" "); - expect(token.name.charAt(token.name.length - 1)).not.toContain(" "); - }); - }); - it("Should replace all space by dash", async () => { - const tokens = seeds().tokens; - const result = await replaceString( - tokens, - { keys: ["name"], regex: { pattern: " ", flags: "g" }, replaceBy: "-" }, - libs - ); - if (result instanceof Error) return fail(result); - tokens.map(token => { - expect(result.find(({ id }) => token.id === id)!.name).toEqual( - token.name.replace(/ /g, "-") - ); - }); - }); - it("Should replace space by size", async () => { - const tokens = seeds().tokens; - const result = await replaceString( - tokens, - { keys: ["name"], regex: "space", replaceBy: "size", trim: true }, - libs - ); - if (result instanceof Error) return fail(result); - result.map(token => { - expect(token.name).not.toContain("space"); - expect(token.name.charAt(0)).not.toContain(" "); - expect(token.name.charAt(token.name.length - 1)).not.toContain(" "); - }); - tokens.map(token => { - if (token.name.includes("space")) { - expect(result.find(({ id }) => token.id === id)).toContain("size"); - } - }); - }); - it("Should replace nothing", async () => { - const tokens = seeds().tokens; - const result = await replaceString( - tokens, - { keys: ["name"], regex: "", replaceBy: "nothing" }, - libs - ); - if (result instanceof Error) return fail(result); - tokens.map(token => { - expect(result.find(({ id }) => token.id === id)).toEqual(token); - }); - }); - it("Should selector match nothing", async () => { - const tokens = seeds().tokens; - const result = await replaceString( - tokens, - { keys: ["not-exist"], regex: "", replaceBy: "nothing" }, - libs - ); - if (result instanceof Error) return fail(result); - tokens.map(token => { - expect(result.find(({ id }) => token.id === id)).toEqual(token); - }); - }); - it("Should replace string input", async () => { - const input = ":root { color: red; }"; - const result = await replaceString( - input, - { regex: ":root ", replaceBy: "" }, - libs - ); - expect(result).toEqual(input.replace(":root ", "")); - }); -}); diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/round-number/README.md b/tools/executors/typescript/utilities/design-token-parsers/parsers/round-number/README.md deleted file mode 100644 index ba92f1580..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/round-number/README.md +++ /dev/null @@ -1,361 +0,0 @@ -# Round number - -## Description - -This parser helps you round any measurement design token with specific precision. - -Some measurement token values like a font size, a line height or a shadow blur may need to be rounded. By specifying a mode, you can control the round function more precisely. - -Learn more about how to configure Specify in the API documentation: [https://specifyapp.com/developers](https://specifyapp.com/developers). - -## Interface - -```ts -interface parser { - name: "round-number"; - options: { - keys: Array; - precision?: number; - mode?: "down" | "up" | "auto"; - }; -} -``` - -### Options - -| Parameter | Required | Type | Default | Description | -| ----------- | -------- | ---------------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `keys` | required | `Array` | | List of key path to apply the rounding | -| `precision` | optional | `number` | `0` | Number of decimal expected | -| `mode` | optional | `down, up, auto` | `auto` | up: rounds a number up to the next largest number with specific decimals

down: rounds a number down to the nearest less or equal number with specific decimals

auto: returns the value of a number rounded to the nearest number with specific decimals | - -## Types - -โ„น๏ธ **Please be aware that, depending on the order you use parsers, their input and output types have to match.** - -### Input - -```ts -type input = Array>; -``` - -### Output - -```ts -type output = Array>; -``` - -## Basic Usage - -### Config - -The following config rounds the measure of a measurement design token: - -```jsonc -"parsers": [ - { - "name": "round-number", - "options": { - "keys": ["value.measure"], - "precision": 1, - "mode": "auto" - } - } - // โ€ฆ -] -``` - -### Before/After - -#### Input - -```jsonc -[ - { - "type": "measurement", - "value": { - "unit": "rem", - "measure": 1.689 // <--- - }, - "name": "size-01" - }, - { - "type": "measurement", - "value": { - "unit": "rem", - "measure": 2.34 // <--- - }, - "name": "size-02" - } -] -``` - -#### Output - -```jsonc -[ - { - "type": "measurement", - "value": { - "unit": "rem", - "measure": 1.7 // <--- - }, - "name": "size-01" - }, - { - "type": "measurement", - "value": { - "unit": "rem", - "measure": 2.3 // <--- - }, - "name": "size-02" - } -] -``` - -## Complex Usage - Rounding text style font size and shadows blur - -### Config - -This config uses patterns. Here, the shadow has an array as a value. So we use `[*]` to round all the blur measures. - -```jsonc -"parsers": [ - { - "name": "round-number", - "options": { - "keys": [ - "value.fontSize.value.measure", - "value.lineHeight.value.measure", - "value[*].blur.value.measure" - ], - "mode": "down" - } - } - // โ€ฆ -] -``` - -### Before/After - -#### Input - -```jsonc -[ - { - "type": "textStyle", - "name": "app-code", - "value": { - "font": { - "name": "FiraCode-Medium", - "type": "font", - "value": { - "isItalic": false, - "fontFamily": "Fira Code", - "fontWeight": 500, - "fontPostScriptName": "FiraCode-Medium" - } - }, - "color": { - "value": { - "a": 1, - "b": 196, - "g": 196, - "r": 196 - } - }, - "fontSize": { - "value": { - "unit": "px", - "measure": 12.7 // <-- - } - }, - "textAlign": { - "vertical": "top", - "horizontal": "left" - }, - "lineHeight": { - "value": { - "unit": "px", - "measure": 14.0625 // <-- - } - } - } - }, - { - "type": "shadow", - "name": "Elevation-2", - "value": [ - { - "blur": { - "value": { - "unit": "px", - "measure": 28.33 // <-- - } - }, - "color": { - "value": { - "a": 0.1, - "b": 0, - "g": 0, - "r": 0 - } - }, - "isInner": false, - "offsetX": { - "value": { - "unit": "px", - "measure": 0 - } - }, - "offsetY": { - "value": { - "unit": "px", - "measure": 4 - } - } - }, - { - "blur": { - "value": { - "unit": "px", - "measure": 4.66 // <-- - } - }, - "color": { - "value": { - "a": 0.1, - "b": 0, - "g": 0, - "r": 0 - } - }, - "isInner": false, - "offsetX": { - "value": { - "unit": "px", - "measure": 0 - } - }, - "offsetY": { - "value": { - "unit": "px", - "measure": 4 - } - } - } - ] - } -] -``` - -#### Output - -```jsonc -[ - { - "type": "textStyle", - "name": "app-code", - "value": { - "font": { - "name": "FiraCode-Medium", - "type": "font", - "value": { - "isItalic": false, - "fontFamily": "Fira Code", - "fontWeight": 500, - "fontPostScriptName": "FiraCode-Medium" - } - }, - "color": { - "value": { - "a": 1, - "b": 196, - "g": 196, - "r": 196 - } - }, - "fontSize": { - "value": { - "unit": "px", - "measure": 12 // <-- - } - }, - "textAlign": { - "vertical": "top", - "horizontal": "left" - }, - "lineHeight": { - "value": { - "unit": "px", - "measure": 14 // <-- - } - } - } - }, - { - "type": "shadow", - "name": "Elevation-2", - "value": [ - { - "blur": { - "value": { - "unit": "px", - "measure": 28 // <-- - } - }, - "color": { - "value": { - "a": 0.1, - "b": 0, - "g": 0, - "r": 0 - } - }, - "isInner": false, - "offsetX": { - "value": { - "unit": "px", - "measure": 0 - } - }, - "offsetY": { - "value": { - "unit": "px", - "measure": 4 - } - } - }, - { - "blur": { - "value": { - "unit": "px", - "measure": 4 // <-- - } - }, - "color": { - "value": { - "a": 0.1, - "b": 0, - "g": 0, - "r": 0 - } - }, - "isInner": false, - "offsetX": { - "value": { - "unit": "px", - "measure": 0 - } - }, - "offsetY": { - "value": { - "unit": "px", - "measure": 4 - } - } - } - ] - } -] -``` diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/round-number/round-number.parser.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/round-number/round-number.parser.ts deleted file mode 100644 index c19372228..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/round-number/round-number.parser.ts +++ /dev/null @@ -1,46 +0,0 @@ -import { LibsType } from "../global-libs"; -import listPathsByPattern from "../../libs/list-paths-by-pattern"; - -export type InputDataType = Array>; -export type OutputDataType = InputDataType; -export type OptionsType = - | undefined - | { - keys: Array; // default [] - precision?: number; // default 0 - mode?: "down" | "up" | "auto"; // default auto - }; - -const defaultOptions = { keys: [], precision: 0, mode: "auto" }; - -export default async function ( - tokens: InputDataType, - options: OptionsType, - { _ }: Pick -): Promise { - const mergedOptions = { - ...defaultOptions, - ...options, - }; - - return tokens.map(token => { - mergedOptions.keys.forEach(pattern => { - const paths = listPathsByPattern(token, pattern); - paths.forEach(selector => { - const originalValue = _.get(token, selector); - - const roundFunction = - mergedOptions.mode === "auto" - ? Math.round - : mergedOptions.mode === "up" - ? Math.ceil - : Math.floor; - - const factor = Math.pow(10, mergedOptions.precision); - _.set(token, selector, roundFunction(originalValue * factor) / factor); - }); - }); - - return token; - }); -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/round-number/round-number.spec.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/round-number/round-number.spec.ts deleted file mode 100644 index c4cc7ecb7..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/round-number/round-number.spec.ts +++ /dev/null @@ -1,280 +0,0 @@ -import rounding from "./round-number.parser"; -import { - BorderToken, - MeasurementToken, - ShadowToken, - TextStyleToken, - Token, -} from "../../types"; -import libs from "../global-libs"; -import seeds from "../../tests/seeds"; - -const countDecimals = function (value: number) { - if (Math.floor(value) !== value) - return value.toString().split(".")[1].length || 0; - return 0; -}; - -describe("Rounding", () => { - it("Should round measurement tokens with 2 decimals (default options)", async () => { - const tokens = seeds().tokens; - const measurementTokens = tokens.filter( - token => token.type === "measurement" - ); - const result = await rounding( - measurementTokens, - { keys: ["value.measure"] }, - libs - ); - if (result instanceof Error) return fail(result); - expect(result.length).toEqual(measurementTokens.length); - - (result as Array).forEach(token => { - expect(countDecimals(token.value.measure)).toBeLessThanOrEqual(2); - }); - - return; - }); - - it("Should round measurement tokens with specific precision", async () => { - const tokens = seeds().tokens; - const measurementTokens = tokens.filter( - token => token.type === "measurement" - ); - const precision = 3; - const result = await rounding( - measurementTokens, - { keys: ["value.measure"], precision }, - libs - ); - if (result instanceof Error) return fail(result); - - expect(result.length).toEqual(measurementTokens.length); - - (result as Array).forEach((token, index) => { - expect(countDecimals(token.value.measure)).toBeLessThanOrEqual(precision); - }); - - return; - }); - - it("Should truncate measurement if precision is 0", async () => { - const tokens = seeds().tokens; - const measurementTokens = tokens.filter( - token => token.type === "measurement" - ); - const precision = 0; - const result = await rounding( - measurementTokens, - { keys: ["value.measure"], precision }, - libs - ); - if (result instanceof Error) return fail(result); - - expect(result.length).toEqual(measurementTokens.length); - - (result as Array).forEach(token => { - expect(countDecimals(token.value.measure)).toEqual(precision); - }); - - return; - }); - - it("Should round measurement tokens with mode (down)", async () => { - const tokens = seeds().tokens; - const measurementTokens = tokens.filter( - token => token.type === "measurement" - ); - const result = await rounding( - measurementTokens, - { keys: ["value.measure"], mode: "down" }, - libs - ); - if (result instanceof Error) return fail(result); - - expect(result.length).toEqual(measurementTokens.length); - - (result as Array).forEach(token => { - expect(countDecimals(token.value.measure)).toBeLessThanOrEqual(2); - - if (token.name === "feed reboot Investment Account") { - expect(token.value.measure).toEqual(13.23); - } - }); - - return; - }); - - it("Should round measurement tokens with mode (up)", async () => { - const tokens = seeds().tokens; - const measurementTokens = tokens.filter( - token => token.type === "measurement" - ); - const result = await rounding( - measurementTokens, - { keys: ["value.measure"], mode: "up" }, - libs - ); - if (result instanceof Error) return fail(result); - - expect(result.length).toEqual(measurementTokens.length); - - (result as Array).forEach(token => { - expect(countDecimals(token.value.measure)).toBeLessThanOrEqual(2); - - if (token.name === "feed reboot Investment Account") { - expect(token.value.measure).toEqual(13.24); - } - }); - - return; - }); - - it("Should not round if the pattern doesn't match", async () => { - const tokens = seeds().tokens; - const measurementTokens = tokens.filter( - token => token.type === "measurement" - ); - const result = await rounding( - measurementTokens, - { keys: ["value[*].measure"] }, - libs - ); - if (result instanceof Error) return fail(result); - - expect(result.length).toEqual(measurementTokens.length); - expect(result).toEqual(measurementTokens); - - return; - }); - - it("Should round measurement tokens in a more complex token (Text Style)", async () => { - const tokens = seeds().tokens; - const textStyleTokens = tokens.filter(token => token.type === "textStyle"); - const result = await rounding( - textStyleTokens, - { keys: ["value.fontSize.value.measure"] }, - libs - ); - if (result instanceof Error) return fail(result); - - expect(result.length).toEqual(textStyleTokens.length); - - (result as Array).forEach(token => { - expect( - countDecimals(token.value.fontSize.value.measure) - ).toBeLessThanOrEqual(2); - }); - - return; - }); - - it("Should round with multiple keys", async () => { - const tokens = seeds().tokens; - const textStyleTokens = tokens.filter(token => token.type === "textStyle"); - const result = await rounding( - textStyleTokens, - { - keys: [ - "value.fontSize.value.measure", - "value.lineHeight.value.measure", - ], - }, - libs - ); - if (result instanceof Error) return fail(result); - - expect(result.length).toEqual(textStyleTokens.length); - - (result as Array).forEach(token => { - expect( - countDecimals(token.value.fontSize.value.measure) - ).toBeLessThanOrEqual(2); - expect( - countDecimals(token.value.lineHeight!.value.measure) - ).toBeLessThanOrEqual(2); - }); - - return; - }); - - it("Should round with multiple keys and multiple types", async () => { - const tokens = seeds().tokens; - const textStyleAndBorderTokens = tokens.filter(token => - ["textStyle", "border"].includes(token.type) - ); - const result = await rounding( - textStyleAndBorderTokens, - { keys: ["value.fontSize.value.measure", "value.width.value.measure"] }, - libs - ); - if (result instanceof Error) return fail(result); - - expect(result.length).toEqual(textStyleAndBorderTokens.length); - - (result as Array).forEach(token => { - if (token.type === "textStyle") { - expect( - countDecimals((token as TextStyleToken).value.fontSize.value.measure) - ).toBeLessThanOrEqual(2); - } else { - expect( - countDecimals((token as BorderToken).value.width.value.measure) - ).toBeLessThanOrEqual(2); - } - }); - - return; - }); - - it("Should round within array (blur of shadows)", async () => { - const tokens = seeds().tokens; - const shadowTokens = tokens.filter(token => token.type === "shadow"); - const result = await rounding( - shadowTokens, - { keys: ["value[*].blur.value.measure"] }, - libs - ); - if (result instanceof Error) return fail(result); - - expect(result.length).toEqual(shadowTokens.length); - - (result as Array).forEach(token => { - token.value.forEach(shadow => { - expect(countDecimals(shadow.blur.value.measure)).toBeLessThanOrEqual(2); - }); - }); - - return; - }); - - it("Should round only when it founds the pattern", async () => { - const tokens = seeds().tokens; - const result = await rounding( - tokens, - { keys: ["value[*].blur.value.measure", "value.fontSize.value.measure"] }, - libs - ); - if (result instanceof Error) return fail(result); - - expect(result.length).toEqual(tokens.length); - - result.forEach(token => { - if (token.type === "shadow") { - (token as ShadowToken).value.forEach(shadow => { - expect(countDecimals(shadow.blur.value.measure)).toBeLessThanOrEqual( - 2 - ); - }); - } - - if (token.type === "textStyle") { - expect( - countDecimals((token as TextStyleToken).value.fontSize.value.measure) - ).toBeLessThanOrEqual(2); - } - }); - - return; - }); -}); diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/snakecasify/README.md b/tools/executors/typescript/utilities/design-token-parsers/parsers/snakecasify/README.md deleted file mode 100644 index 0047a182d..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/snakecasify/README.md +++ /dev/null @@ -1,94 +0,0 @@ -# Snakecasify - -## Description - -This parser helps you apply snakecase function on specific keys from a design token. - -Learn more about how to configure Specify in the API documentation: [https://specifyapp.com/developers](https://specifyapp.com/developers). - -## Interface - -```ts -interface parser { - name: "snakecasify"; - options?: { - keys: Array; - }; -} -``` - -### Options - -| Parameter | Required | Type | Default | Description | -| --------- | -------- | ------- | ---------- | --------------------------------------------------- | -| `keys` | optional | `Array` | `["name"]` | The list of keys where the function will be applied | - -## Types - -โ„น๏ธ **Please be aware that, depending on the order you use parsers, their input and output types have to match.** - -### Input - -Array of object with the keys to apply `snakecase` function - -```ts -type input = Array<{ [key: string]: any }>; -``` - -### Output - -```ts -type output = Array<{ [key: string]: any }>; -``` - -## Usage - -### Config - -```jsonc -"parsers": [ - { - "name": "snakecasify", - "options": { - "keys": ["name"] - } - } - // โ€ฆ -] -``` - -### Before/After - -#### Input - -```jsonc -[ - { - "type": "color", - "value": { - "a": 0.96, - "b": 20, - "g": 227, - "r": 122 - }, - "name": "Brand / Primary Color" - } -] -``` - -#### Output - -```jsonc -[ - { - "type": "color", - "value": { - "a": 0.96, - "b": 20, - "g": 227, - "r": 122 - }, - "name": "brand-primary-color" - } -] -``` diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/snakecasify/snakecasify.parser.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/snakecasify/snakecasify.parser.ts deleted file mode 100644 index 94056ce5e..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/snakecasify/snakecasify.parser.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { LibsType } from "../global-libs"; - -export type InputDataType = Array>; -export type OutputDataType = InputDataType; -export type OptionsType = - | undefined - | { - keys: Array; - }; - -export default async function ( - tokens: InputDataType, - options: OptionsType = { keys: ["name"] }, - { _ }: Pick -): Promise { - return tokens.map(token => { - options.keys.forEach(key => { - if (_.has(token, key)) { - _.set(token, key, _.snakeCase(_.get(token, key))); - } - }); - return token; - }); -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/snakecasify/snakecasify.spec.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/snakecasify/snakecasify.spec.ts deleted file mode 100644 index 927e49a9a..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/snakecasify/snakecasify.spec.ts +++ /dev/null @@ -1,59 +0,0 @@ -import snakecasify from "./snakecasify.parser"; -import { Token } from "../../types"; -import libs from "../global-libs"; -import seeds from "../../tests/seeds"; - -describe("Snakecasify", () => { - it("Get tokens - apply parsers", async () => { - const result = await snakecasify( - seeds().tokens as Array, - { keys: ["name"] }, - libs - ); - if (result instanceof Error) return fail(result); - result.forEach(token => expect(token.name?.includes(" ")).toEqual(false)); - return; - }); - it("Get tokens - apply parsers - default", async () => { - const result = await snakecasify( - seeds().tokens as Array, - undefined, - libs - ); - if (result instanceof Error) return fail(result); - result.forEach(token => { - expect(token.name?.includes(" ")).toEqual(false); - }); - return; - }); - it("Get tokens - apply parsers - without tokens", async () => { - const result = await snakecasify([], undefined, libs); - if (result instanceof Error) return fail(result); - expect(Array.isArray(result)).toBeTruthy(); - expect(result.length).toEqual(0); - return; - }); - it("Get tokens - apply parsers - unknown target key", async () => { - const input = seeds().tokens; - const result = await snakecasify( - input, - { keys: ["name", "not exist"] }, - libs - ); - expect(Array.isArray(result)).toBeTruthy(); - expect(result.length).toEqual(input.length); - return; - }); - it("Get tokens - apply parsers - error", async () => { - try { - await snakecasify( - // @ts-ignore - "wrong type", - { keys: ["name", "not exist"] }, - libs - ); - } catch (err) { - return; - } - }); -}); diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/sort-by/README.md b/tools/executors/typescript/utilities/design-token-parsers/parsers/sort-by/README.md deleted file mode 100644 index eef4219ec..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/sort-by/README.md +++ /dev/null @@ -1,134 +0,0 @@ -# Sort By - -## Description - -This parser helps loop on several design tokens and sort them according to their respective key values. - -Learn more about how to configure Specify in the API documentation: [https://specifyapp.com/developers](https://specifyapp.com/developers). - -## Interface - -```ts -interface parser { - name: "sort-by"; - options?: { - keys: Array; - }; -} -``` - -### Options - -| Parameter | Required | Type | Default | Description | -| --------- | -------- | ------- | ---------- | --------------------------------------------------- | -| `keys` | optional | `Array` | `["name"]` | The list of keys where the function will be applied | - -## Types - -โ„น๏ธ **Please be aware that, depending on the order you use parsers, their input and output types have to match.** - -### Input - -Array of object with the keys to apply `sort` function - -```ts -type input = Array<{ [key: string]: any }>; -``` - -### Output - -```ts -type output = Array<{ [key: string]: any }>; -``` - -## Usage - -### Config - -```jsonc -"parsers": [ - { - "name": "sort-by", - "options": { - "keys": ["name"] - } - } - // โ€ฆ -] -``` - -### Before/After - -#### Input - -```jsonc -[ - { - "type": "color", - "value": { - "a": 1, - "b": 17, - "g": 125, - "r": 249 - }, - "name": "Global / Blue Base" - }, - { - "type": "color", - "value": { - "a": 1, - "b": 245, - "g": 72, - "r": 63 - }, - "name": "Global / Red Base" - }, - { - "type": "color", - "value": { - "a": 1, - "b": 255, - "g": 142, - "r": 5 - }, - "name": "Global / Orange Base" - } -] -``` - -#### Output - -```jsonc -[ - { - "type": "color", - "value": { - "a": 1, - "b": 17, - "g": 125, - "r": 249 - }, - "name": "Global / Blue Base" // <--- - }, - { - "type": "color", - "value": { - "a": 1, - "b": 255, - "g": 142, - "r": 5 - }, - "name": "Global / Orange Base" // <--- - }, - { - "type": "color", - "value": { - "a": 1, - "b": 245, - "g": 72, - "r": 63 - }, - "name": "Global / Red Base" // <--- - } -] -``` diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/sort-by/sort-by.parser.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/sort-by/sort-by.parser.ts deleted file mode 100644 index fc0b72a34..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/sort-by/sort-by.parser.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { LibsType } from "../global-libs"; - -export type InputDataType = Record; -export type OutputDataType = InputDataType; -export type OptionsType = - | undefined - | { - keys: Array; - }; - -export default async function ( - tokens: InputDataType, - options: OptionsType = { keys: ["name"] }, - { _ }: Pick -): Promise { - return _.sortBy(tokens, options.keys); -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/sort-by/sort-by.spec.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/sort-by/sort-by.spec.ts deleted file mode 100644 index bcf6038d7..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/sort-by/sort-by.spec.ts +++ /dev/null @@ -1,27 +0,0 @@ -import seeds from "../../tests/seeds"; -import sortBy from "./sort-by.parser"; -import { Token } from "../../types"; -import libs from "../global-libs"; - -describe("sort-by", () => { - it("Get tokens - apply parsers", async () => { - const result = await sortBy( - seeds().tokens as Array, - { keys: ["name"] }, - libs - ); - if (result instanceof Error) return fail(result); - expect(JSON.stringify(libs._.sortBy(seeds().tokens, ["name"]))).toEqual( - JSON.stringify(result) - ); - return; - }); - it("Get tokens - apply parsers - wihtout options", async () => { - const result = await sortBy(seeds().tokens, undefined, libs); - if (result instanceof Error) return fail(result); - expect(JSON.stringify(libs._.sortBy(seeds().tokens, ["name"]))).toEqual( - JSON.stringify(result) - ); - return; - }); -}); diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/suffix-by/README.md b/tools/executors/typescript/utilities/design-token-parsers/parsers/suffix-by/README.md deleted file mode 100644 index 11aa81761..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/suffix-by/README.md +++ /dev/null @@ -1,163 +0,0 @@ -# Suffix By - -## Description - -This parser helps you concatenate two strings. - -Learn more about how to configure Specify in the API documentation: [https://specifyapp.com/developers](https://specifyapp.com/developers). - -## Interface - -```ts -interface parser { - name: "suffix-by"; - options?: { - key?: string; - suffix: string; - types?: Array; - }; -} -``` - -### Options - -| Parameter | Required | Type | Default | Description | -| --------- | -------- | --------------- | ------- | --------------------------------------------------------------------------------------------------------------------------------- | -| `key` | optional | `string` | "name" | The key of the value will be suffixed | -| `suffix` | required | `string` | | The pattern used generate suffix string. It must match [mustache](https://github.com/janl/mustache.js#templates) template syntax. | -| `types` | optional | `Array` | | The types where the function will be applied | - -## Types - -โ„น๏ธ **Please be aware that, depending on the order you use parsers, their input and output types have to match.** - -### Input - -Array of object with the keys to apply the suffix - -```ts -type input = Array<{ [key: string]: any }>; -``` - -### Output - -```ts -type output = Array<{ [key: string]: any }>; -``` - -## Basic usage - -### Config - -```jsonc -"parsers": [ - { - "name": "suffix-by", - "options": { - "types": ["vector"], - "suffix": ".svg", - "key": "name" - } - } - // โ€ฆ -] -``` - -### Before/After - -#### Input - -```jsonc -[ - { - "type": "vector", - "value": { - "url": "https://...", - "format": "svg" - }, - "name": "Warning" - } -] -``` - -#### Output - -```jsonc -[ - { - "type": "vector", - "value": { - "url": "https://...", - "format": "svg", - "fileName": "Warning-vector.svg" - }, - "name": "Warning.svg" - } -] -``` - -## Complex usage - with condition in template - -### Config - -```jsonc -{ - "name": "suffix-by", - "options": { - "types": ["bitmap"], - "suffix": "{{#value.dimension}}@{{value.dimension}}{{/value.dimension}}.{{value.format}}", - "key": "name" - } -} -// โ€ฆ -``` - -### Before/After - -#### Input - -```jsonc -[ - { - "type": "bitmap", - "value": { - "url": "https://...", - "format": "png", - "dimension": "2x" - }, - "name": "photo-example" - }, - { - "type": "bitmap", - "value": { - "url": "https://...", - "format": "webp" - }, - "name": "photo-example" - } -] -``` - -#### Output - -```jsonc -[ - { - "type": "bitmap", - "value": { - "url": "https://...", - "format": "png", - "dimension": "2x" - }, - "name": "photo-example@2x.png" - }, - { - "type": "bitmap", - "value": { - "url": "https://...", - "format": "webp" - }, - "name": "photo-example.webp" - } -] -``` diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/suffix-by/suffix-by.parser.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/suffix-by/suffix-by.parser.ts deleted file mode 100644 index 944a67e4c..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/suffix-by/suffix-by.parser.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { LibsType } from "../global-libs"; -import Template from "../../libs/template"; - -export type InputDataType = Array>; -export type OutputDataType = InputDataType; -export type OptionsType = { - key?: string; - suffix: string; // pattern - types?: Array; -}; - -export default async function ( - tokens: InputDataType, - options: OptionsType, - { _ }: Pick -): Promise { - const key = options.key || "name"; - const template = new Template(options.suffix); - return tokens.map(token => { - if (!options.types || (token.type && options.types.includes(token.type))) { - _.set(token, key, `${_.get(token, key)}${template.render(token)}`); - } - return token; - }); -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/suffix-by/suffix-by.spec.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/suffix-by/suffix-by.spec.ts deleted file mode 100644 index c56f4998c..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/suffix-by/suffix-by.spec.ts +++ /dev/null @@ -1,50 +0,0 @@ -import seeds from "../../tests/seeds"; -import suffixBy from "./suffix-by.parser"; -import { Token } from "../../types"; -import libs from "../global-libs"; - -describe("suffix-by", () => { - it("Execute parser", async () => { - const suffix = ".svg"; - const result = await suffixBy( - seeds().tokens, - { key: "name", suffix, types: ["vector"] }, - libs - ); - if (result instanceof Error) return fail(result); - expect( - result.every(token => - token.type === "vector" - ? token.name.endsWith(suffix) - : !token.name.endsWith(suffix) - ) - ).toEqual(true); - return; - }); - it("Execute parser with minimum option", async () => { - const result = await suffixBy( - seeds().tokens.filter(({ type }) => type === "vector") as Array, - { suffix: ".svg" }, - libs - ); - if (result instanceof Error) return fail(result); - expect(result.every(vector => vector.name?.endsWith(".svg"))).toEqual(true); - return; - }); - it("Execute with template", async () => { - const result = await suffixBy( - seeds().tokens.filter(({ type }) => type === "vector") as Array, - { suffix: ".{{type}}.{{value.format}}" }, - libs - ); - if (result instanceof Error) return fail(result); - expect( - result.every( - vector => - vector.name?.endsWith(".vector.svg") || - vector.name?.endsWith(".vector.pdf") - ) - ).toEqual(true); - return; - }); -}); diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/svg-to-jsx/README.md b/tools/executors/typescript/utilities/design-token-parsers/parsers/svg-to-jsx/README.md deleted file mode 100644 index 25c14cf25..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/svg-to-jsx/README.md +++ /dev/null @@ -1,257 +0,0 @@ -# SVG to JSX - -## Description - -This parser helps you wrap SVG files within a JSX component. - -## Interface - -```ts -interface parser { - name: "svg-to-jsx"; - options: { - prepend?: string; - formatConfig?: Partial<{ - exportDefault: boolean; - variableFormat?: "camelCase" | "kebabCase" | "snakeCase" | "pascalCase"; - endOfLine: "auto" | "lf" | "crlf" | "cr"; - tabWidth: number; - useTabs: boolean; - singleQuote: boolean; - isTsx: boolean; - }>; - wrapper?: { - tag?: string; - className?: string; - }; - }; -} -``` - -### Options - -| Parameter | Required | Type | Default | Description | -| ----------------------------- | -------- | ------------------------------------------------ | ----------- | --------------------------------------------------------------------------------------------------------- | -| `prepend` | optional | `string` | | A string to append at the top of the generated file | -| `formatConfig.endOfLine` | optional | `auto` `lf` `crlf` `cr` | `auto` | [Prettier documentation](https://prettier.io/docs/en/options.html#end-of-line) | -| `formatConfig.tabWidth` | optional | `number` | `2` | [Prettier documentation](https://prettier.io/docs/en/options.html#tab-width) | -| `formatConfig.useTabs` | optional | `boolean` | `true` | [Prettier documentation](https://prettier.io/docs/en/options.html#tabs) | -| `formatConfig.singleQuote` | optional | `boolean` | `false` | [Prettier documentation](https://prettier.io/docs/en/options.html#quotes) | -| `formatConfig.exportDefault` | optional | `boolean` | `true` | Defines if the export of the JSX component should be done using default or not. | -| `formatConfig.variableFormat` | optional | `camelCase` `kebabCase` `snakeCase` `pascalCase` | `kebabCase` | The case transformation you want to apply to the name of JavaScript variable that will be exported. | -| `formatConfig.isTsx` | optional | `boolean` | `false` | Append `.tsx` extension to the generated files. | -| `wrapper.tag` | optional | `string` | | An HTML parent tag will be used to wrap the SVG tag. | -| `wrapper.className` | optional | `string` | | A string or a pattern used to set a className attribute on the potential parent tag wrapping the SVG tag. | - -## Output - -Please keep in mind that this parser generates files. This is why you should always set a folder as the final `path` in your parent rule. - -
-See Do & Don't config examples - -โœ… Do - -``` -// ... -"rules": [ - { - "name": "Design Tokens / JSX Icons", - "path": "icons", // <-- path set as a folder - "parsers": [ - { - "name": "svg-to-jsx" - } - ] - } -] -``` - -๐Ÿšซ Don't - -``` -// ... -"rules": [ - { - "name": "Design Tokens / JSX Icons", - "path": "icons/icons.json", // <-- path set as a file - "parsers": [ - { - "name": "svg-to-jsx" - } - ] - } -] -``` - -
- -## Types - -โ„น๏ธ **Please be aware that, depending on the order you use parsers, their input and output types have to match.** - -### Input - -Array of object with at least the key `value.url` or `value.content`. - -```ts -type input = Array< - Record & { - type: string; - name: string; - value: ({ url?: string } | { content?: string }) & { [key: string]: any }; - } ->; -``` - -### Output - -Input type extended with `value.content` and `value.fileName` - -```ts -type output = Array< - Record & { - type: string; - value: { content: string; fileName: string; [key: string]: any }; - } ->; -``` - -### **โ„น๏ธ Good to know** - -The content generated by this parser is returned by the `{value.content}` property. -The output will differ according to the `path` you set in your rule: - -1. If the `path` targets a directory, the content will be written as a file. - By default, this file will be named according to the following pattern: `{assetName}.jsx` (assetName pascalCased). - If the asset object contains a `filename` property (e.g. by using the [name-assets-files-by-pattern](https://github.com/Specifyapp/parsers/tree/master/parsers/name-assets-files-by-pattern) parser), the file will be named after it. -2. If the `path` of your rule targets a file, the content will be written as a JSON object inside it. - -## Basic usage - -### Config - -```jsonc -"parsers": [ - { - "name": "svg-to-jsx" - } - // โ€ฆ -] -``` - -### Before/After - -#### Input - -```jsonc -{ - "type": "vector", - "name": "activity.svg", - "value": { - "url": "https://s3-us-west-2.amazonaws.com/figma-alpha-api/img/99b5/b311/257c650341b701d691be78f247b9cf5e" - //... - } - //... -} -``` - -#### Output - -``` -{ - "type": "vector", - "name": "activity", - "value": { - "fileName": "Activity.jsx", - "content": "export default () => ( - - - - );", - }, - // โ€ฆ -} -``` - -## Complex usage - -### Config - -```jsonc -"parsers": [ - { - "name": "svg-to-jsx", - "options": { - "prepend": "import React from 'react';", - "variableFormat": "camelCase", - "wrapper": { - "tag": "div", - "className": "icon-{{name}} icon" - } - } - } - // โ€ฆ -] -``` - -### Before/After - -#### Input - -```jsonc -{ - "type": "vector", - "name": "activity.svg", - "value": { - "url": "https://s3-us-west-2.amazonaws.com/figma-alpha-api/img/99b5/b311/257c650341b701d691be78f247b9cf5e" - //... - } - //... -} -``` - -#### Output - -```jsonc -{ - "type": "vector", - "name": "activity", - "value": { - "fileName": "Activity.jsx", - "content": "import React from "react"; - export const activity = () => ( -
- - - -
- );", - }, - // โ€ฆ -} -``` diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/svg-to-jsx/svg-to-jsx.parser.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/svg-to-jsx/svg-to-jsx.parser.ts deleted file mode 100644 index 2abdd3ccf..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/svg-to-jsx/svg-to-jsx.parser.ts +++ /dev/null @@ -1,194 +0,0 @@ -/* eslint-disable no-useless-catch */ -import * as _ from "lodash"; -import * as os from "os"; -import prettier from "prettier"; -import Template from "../../libs/template"; -import { IToken, TokensType } from "../../types"; -import { LibsType } from "../global-libs"; -//import { create } from 'xmlbuilder2'; -//import { parseStringPromise } from 'xml2js'; -import { xml2jsElementType } from "./svg-to-jsx.type"; -//import { ExpandObject } from 'xmlbuilder2/lib/interfaces'; - -export type InputDataType = Array< - IToken & { - name: string; - type: TokensType; - value: ({ url?: string } | { content?: string }) & { [key: string]: any }; - } ->; - -export type OutputDataType = Array< - InputDataType[0] & { - value: { content: string; fileName: string; [key: string]: any }; - } ->; - -export type OptionsType = - | undefined - | { - prepend?: string; // import React from 'react'; - variableFormat?: "camelCase" | "kebabCase" | "snakeCase" | "pascalCase"; // default: pascalCase - formatConfig?: Partial<{ - exportDefault: boolean; - endOfLine: "auto" | "lf" | "crlf" | "cr"; - tabWidth: number; - useTabs: boolean; - singleQuote: boolean; - isTsx: boolean; - }>; - wrapper?: { - tag: string; - className?: string; - }; - }; - -function formatObject4XMLBuilder( - xpath: string, - _: never, - element: xml2jsElementType -) { - const tag = element["#name"]; - let value = element._; - if (!value && element.$$) { - value = { "#": element.$$ }; - } - if (element.$) { - value = { ...value, ...element.$ }; - } - return { - [tag]: value, - }; -} - -function convertObjectToXMLString(xmlObject: any) { - // return create(xmlObject).end({ headless: true, prettyPrint: false, indent: '\t', newline: '\n' }); -} - -function camelCaseAttribute(attrName: string) { - const specificAttributeToConvert: Record = { - viewbox: "viewBox", - maskunits: "maskUnits", - gradientunits: "gradientUnits", - gradienttransform: "gradientTransform", - }; - attrName = attrName.toLowerCase(); - - // attribute for xmlBuilder must start with '@' - if (specificAttributeToConvert[attrName]) { - return `@${specificAttributeToConvert[attrName]}`; - } - - return attrName.startsWith("data-") || attrName.startsWith("aria-") - ? `@${attrName}` - : "@" + _.camelCase(attrName); -} - -function convertStyleAttrAsJsxObject(content: string) { - return content.replace( - /style="([^"\\]*)"/, - function (styleAttr: string, styleContent: string) { - const style = styleContent - .split(/\s*;\s*/g) - .filter(Boolean) - .reduce(function (hash: Record, rule: string) { - const keyValue: string[] = rule.split(/\s*:\s*(.*)/); - hash[_.camelCase(keyValue[0])] = keyValue[1]; - return hash; - }, {}); - //JSX style must be in json object format surrounded by curly braces - return `style={${JSON.stringify(style)}}`; - } - ); -} - -const templateExportDefaultModel = `export {{#options.formatConfig.exportDefault}}default{{/options.formatConfig.exportDefault}}{{^options.formatConfig.exportDefault}}const {{variableName}} ={{/options.formatConfig.exportDefault}} () => ( - {{#options.wrapper.tag}}<{{options.wrapper.tag}} {{#className}}className="{{className}}"{{/className}} >{{/options.wrapper.tag}} - {{token.value.content}} - {{#options.wrapper.tag}}{{/options.wrapper.tag}} -)`; - -export default async function ( - tokens: InputDataType, - options: OptionsType, - { SpServices }: Pick -): Promise { - try { - const template = new Template(templateExportDefaultModel); - const classNameTemplate = options?.wrapper?.className - ? new Template(options.wrapper.className) - : null; - - options = { - formatConfig: { - exportDefault: !options?.variableFormat, - ...(options?.formatConfig || {}), - }, - ...(options || {}), - }; - - return await Promise.all( - tokens - // This parser only works on svg, not pdf - .filter( - ({ value, type }) => type === "vector" && value.format === "svg" - ) - .map(async (token): Promise => { - if (token.value.url && !token.value.content) { - token.value.content = await SpServices.assets.getSource( - token.value.url!, - "text" - ); - } - const className = classNameTemplate?.render(token); - const variableName = _[options?.variableFormat || "pascalCase"]( - token.name - ); - - /*const xmlObject = await parseStringPromise(token.value.content, { - explicitArray: true, - explicitChildren: true, - explicitRoot: false, - mergeAttrs: false, - normalize: true, - normalizeTags: false, - preserveChildrenOrder: true, - attrNameProcessors: [camelCaseAttribute], - validator: formatObject4XMLBuilder, - }); - - token.value.content = convertObjectToXMLString(xmlObject);*/ - token.value.content = convertStyleAttrAsJsxObject( - token.value.content - ); - - token.value.content = prettier.format( - (options?.prepend ? `${options?.prepend}${os.EOL}${os.EOL}` : "") + - template.render({ token, variableName, options, className }), - { - parser: "babel", - ...(options?.formatConfig - ? _.pick(options.formatConfig, [ - "endOfLine", - "tabWidth", - "useTabs", - "singleQuote", - ]) - : {}), - } - ); - token.value.fileName = token.value.fileName - ? token.value.fileName - : `${_.camelCase(token.name)}.${ - options?.formatConfig?.isTsx ? "tsx" : "jsx" - }`; - return { - ...token, - value: _.omit(token.value, ["url"]), - } as OutputDataType[0]; - }) - ); - } catch (err) { - throw err; - } -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/svg-to-jsx/svg-to-jsx.spec.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/svg-to-jsx/svg-to-jsx.spec.ts deleted file mode 100644 index e6b298ee8..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/svg-to-jsx/svg-to-jsx.spec.ts +++ /dev/null @@ -1,120 +0,0 @@ -import seeds from "../../tests/seeds"; -import libs, { LibsType } from "../global-libs"; -import { InputDataType } from "./svg-to-jsx.parser"; -import svgToJsx from "./svg-to-jsx.parser"; - -describe("Svg to jsx", () => { - it("Get tokens - apply parsers", async () => { - const tokens = seeds().tokens.filter(({ type }) => type === "vector"); - const result = await svgToJsx( - tokens as InputDataType, - undefined, - libs as LibsType - ); - if (result instanceof Error) return fail(result); - expect(Array.isArray(result)).toEqual(true); - result.forEach(file => { - expect(typeof file.value.content).toEqual("string"); - expect(file.value.fileName.endsWith(".jsx")).toEqual(true); - const reg = new RegExp( - `export default \\(\\) => \\(\\n ([\\s\\S]*)<\\/svg>\\n\\);`, - "gm" - ); - expect(file.value.content).toMatch(reg); - }); - return; - }); - it("Get tokens - apply parsers without export default", async () => { - const tokens = seeds().tokens.filter(({ type }) => type === "vector"); - const result = await svgToJsx( - JSON.parse(JSON.stringify(tokens)) as InputDataType, - { formatConfig: { exportDefault: false } }, - libs as LibsType - ); - if (result instanceof Error) return fail(result); - expect(Array.isArray(result)).toEqual(true); - result.forEach(file => { - expect(typeof file.value.content).toEqual("string"); - expect(file.value.fileName.endsWith(".jsx")).toEqual(true); - const reg = new RegExp( - `export const ([a-zA-Z0-9])+ = \\(\\) => \\(\\n ([\\s\\S]*)<\\/svg>\\n\\);`, - "gm" - ); - expect(file.value.content).toMatch(reg); - }); - return; - }); - it("Get tokens - apply parsers with wrapper", async () => { - const tokens = seeds().tokens.filter(({ type }) => type === "vector"); - const result = await svgToJsx( - tokens as InputDataType, - { - prepend: "import React from 'react';", - variableFormat: "camelCase", - wrapper: { - tag: "div", - className: "icon-{{name}} icon", - }, - formatConfig: { - exportDefault: false, - }, - }, - libs as LibsType - ); - - if (result instanceof Error) return fail(result); - expect(Array.isArray(result)).toEqual(true); - result.forEach(file => { - expect(typeof file.value.content).toEqual("string"); - expect(file.value.url).toEqual(undefined); - expect(file.value.fileName.endsWith(".jsx")).toEqual(true); - const reg = new RegExp( - `import React from "react";([\\s\\S]*)export const ([a-zA-Z0-9])+ = \\(\\) => \\(\\n
([\\s\\S]*)([\\s\\S]*)<\\/svg>\\n <\\/div>\\n\\);`, - "gm" - ); - expect(file.value.content).toMatch(reg); - }); - return; - }); - it("Validate camelCase on attribute", async () => { - const tokens = seeds().tokens.filter(({ name }) => name === "activity"); - const result = await svgToJsx( - tokens as InputDataType, - undefined, - libs as LibsType - ); - if (result instanceof Error) return fail(result); - expect(result).toHaveLength(1); - expect(result[0].value.content).toContain("strokeWidth"); - expect(result[0].value.content).toContain("strokeLinecap"); - expect(result[0].value.content).toContain("strokeLinejoin"); - expect(result[0].value.content).toContain("viewBox"); - return; - }); - it("Validate camelCase on Style rules", async () => { - const tokens = seeds().tokens.filter(({ name }) => name === "user-mask"); - const result = await svgToJsx( - tokens as InputDataType, - undefined, - libs as LibsType - ); - if (result instanceof Error) return fail(result); - expect(result).toHaveLength(1); - expect(result[0].value.content).toContain('style={{ maskType: "alpha" }}'); - expect(result[0].value.content).toContain("maskUnits"); - return; - }); - it("Should return filename with tsx extension", async () => { - const tokens = seeds().tokens.filter(({ type }) => type === "vector"); - const result = await svgToJsx( - tokens as InputDataType, - { formatConfig: { isTsx: true } }, - libs as LibsType - ); - if (result instanceof Error) return fail(result); - result.forEach(file => { - expect(file.value.fileName.endsWith(".tsx")).toEqual(true); - }); - return; - }); -}); diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/svg-to-jsx/svg-to-jsx.type.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/svg-to-jsx/svg-to-jsx.type.ts deleted file mode 100644 index 692c20627..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/svg-to-jsx/svg-to-jsx.type.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { PartialRecord } from "../../types"; - -export type xml2jsElementType = { - "#name": string; //tagName - _?: object; //text - $$?: Array>; //children - $?: object; //attributes -}; diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/svgo/README.md b/tools/executors/typescript/utilities/design-token-parsers/parsers/svgo/README.md deleted file mode 100644 index 8f783b9e7..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/svgo/README.md +++ /dev/null @@ -1,161 +0,0 @@ -# SVGO - -## Description - -This parser helps you optimize vectors using [svgo](https://github.com/svg/svgo). - -Learn more about how to configure Specify in the API documentation: [https://specifyapp.com/developers](https://specifyapp.com/developers). - -## Interface - -```ts -interface parser { - name: "svgo"; - options?: { - // https://github.com/DefinitelyTyped/DefinitelyTyped/blob/3fb92644d8dc475a52147c6315704ece24335469/types/svgo/index.d.ts#L752 - svgo?: OptimizeOptions; - }; -} -``` - -### Options - -| Parameter | Required | Type | Default | Description | -| --------- | -------- | ----------------- | ---------------------------------------- | ------------------------------------------------- | -| `svgo` | optional | `OptimizeOptions` | `{ plugins: [{name: 'preset-default'}]}` | Inherits from [svgo](https://github.com/svg/svgo) | - -## Output - -Please keep in mind that this parser generates files. This is why you should always set a folder as the final `path` in your parent rule. - -
-See Do & Don't config examples - -โœ… Do - -``` -// ... -"rules": [ - { - "name": "Icons", - "path": "icons", // <-- path set as a folder - "parsers": [ - { - "name": "svgo" - } - ] - } -] -``` - -๐Ÿšซ Don't - -``` -// ... -"rules": [ - { - "name": "Icons", - "path": "icons/icons.json", // <-- path set as a file - "parsers": [ - { - "name": "svgo" - } - ] - } -] -``` - -
- -## Types - -โ„น๏ธ **Please be aware that, depending on the order you use parsers, their input and output types have to match.** - -### Input - -Array of object with at least the key `value.url` and `type` - -```ts -type input = Array< - Record & { - type: string; - value: { url: string } & { [key: string]: any }; - } ->; -``` - -### Output - -```ts -type output = Array< - Record & { - type: string; - value: { content: string } & { [key: string]: any }; - } ->; -``` - -## Usage - -### Config - -```jsonc -"parsers": [ - { - "name": "svgo", - "options": { - "svgo": { - "plugins": [ - { - "removeDimensions": true - }, - { - "removeAttrs": { - "attrs": "*:(fill|stroke)" - } - } - ] - } - } - } - // โ€ฆ -] -``` - -### Before/After - -#### Input - -```jsonc -{ - "type": "vector", - "name": "activity.svg", - "value": { - "url": "https://s3-us-west-2.amazonaws.com/figma-alpha-api/img/99b5/b311/257c650341b701d691be78f247b9cf5e" - } - // โ€ฆ -} -``` - -Under the hood, the SVG string returned by the `url` property is the one you want to optimize: - -```xml - - - -``` - -#### Output - -```jsonc -{ - "type": "vector", - "name": "activity.svg", - "value": { - "content": "" - } - // โ€ฆ -} -``` - -โ„น๏ธ Every SVGO option must be in its own object. diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/svgo/index.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/svgo/index.ts deleted file mode 100644 index ddfa4b9e4..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/svgo/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -import { default as svgoParser } from "./svgo.parser"; - -export * from "./svgo.parser"; -export default svgoParser; diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/svgo/svgo.parser.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/svgo/svgo.parser.ts deleted file mode 100644 index 7783b8fc1..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/svgo/svgo.parser.ts +++ /dev/null @@ -1,125 +0,0 @@ -/* eslint-disable @typescript-eslint/no-explicit-any */ -import { ConsoleLogger } from "@open-system/core-shared-utilities"; -import { readFileSync } from "fs"; -import type { Config, Output } from "svgo"; -import { DownloadableFile } from "../../types"; -import { LibsType } from "../global-libs"; -import { - DefaultPresetOverride, - DefaultPresetPluginsName, - DefaultPresetPluginsParams, - PluginV1, - PluginV2, - Plugins, - defaultPresetPlugins, -} from "./svgo.type"; - -export type InputDataType = Array< - Record & { - type: string; - value: { url: string } & { [key: string]: any }; - } ->; -export type OutputDataType = Array< - InputDataType[0] & { - value: DownloadableFile & { [key: string]: any }; - } ->; -export type OptionsType = - | undefined - | { - svgo?: Omit & - ({ plugins?: Array } | { plugins: Array }); - }; - -function getSyntaxPlugin(plugins: NonNullable): "v1" | "v2" { - return plugins.some(plugin => typeof plugin === "string" || "name" in plugin) - ? "v2" - : "v1"; -} - -function migrateSvgoPlugins(plugins?: Plugins): Array { - if (!plugins) { - return [{ name: "preset-default" }]; - } - - if (getSyntaxPlugin(plugins) === "v2") { - return plugins as Array; - } - - const { overrides, pluginsV2 } = (plugins as Array).reduce<{ - overrides: DefaultPresetOverride; - pluginsV2: Array; - }>( - (acc, plugin) => { - const pluginName = Object.keys(plugin)[0]; - if (defaultPresetPlugins.includes(pluginName)) { - acc.overrides[pluginName as DefaultPresetPluginsName] = plugin[ - pluginName as keyof PluginV1 - ] as DefaultPresetPluginsParams; - } else { - const params = plugin[pluginName as keyof PluginV1]; - if (params !== false) { - acc.pluginsV2.push({ - name: pluginName, - params: params, - } as any); - } - } - return acc; - }, - { overrides: {}, pluginsV2: [] } - ); - return [ - { - name: "preset-default", - params: { - overrides, - }, - }, - ...pluginsV2, - ]; -} - -export default async function ( - tokens: InputDataType, - options: OptionsType, - { SVGO, _ }: Pick -): Promise { - try { - ConsoleLogger.info("Running Svgo Parser"); - options = options || {}; - options.svgo = options?.svgo || {}; - options.svgo.plugins = migrateSvgoPlugins(options.svgo.plugins); - ConsoleLogger.info(JSON.stringify(tokens, null, 2)); - - return (await Promise.all( - tokens.map(async token => { - if (token.type === "vector" && token.value.format === "svg") { - ConsoleLogger.info(token.value.url); - - const baseString = readFileSync(token.value.url, "utf8"); - - try { - const result: Output = SVGO.optimize( - baseString, - options?.svgo as Config - ); - token.value.content = result.data!; - } catch (err) { - ConsoleLogger.error(err); - - token.value.content = baseString; - } - return { ...token, value: _.omit(token.value, ["url"]) }; - } - - return token; - }) - )) as OutputDataType; - } catch (err) { - ConsoleLogger.error(err); - - throw err; - } -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/svgo/svgo.spec.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/svgo/svgo.spec.ts deleted file mode 100644 index 564a8f34e..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/svgo/svgo.spec.ts +++ /dev/null @@ -1,310 +0,0 @@ -import seeds from "../../tests/seeds"; -import optimizeVector, { InputDataType } from "./svgo.parser"; -import libs, { LibsType } from "../global-libs"; -import SVGO from "svgo"; -import { VectorToken } from "../../types"; - -describe("Optimize vector", () => { - describe("SVGO v1", () => { - it("Get tokens - apply parsers", async () => { - const tokens = seeds().tokens; - const result = await optimizeVector( - tokens as InputDataType, - undefined, - libs as LibsType - ); - if (result instanceof Error) return fail(result); - expect( - result.find(({ name }) => name === "alert-circle")!.value.content - ).toEqual( - '' - ); - expect( - result.find(({ name }) => name === "airplay")!.value.content - ).toEqual( - '' - ); - expect(result.find(({ name }) => name === "airplay")!.value).toEqual( - expect.objectContaining({ - format: "svg", - content: expect.any(String), - }) - ); - return; - }); - it("Get tokens - apply parsers - with config", async () => { - const tokens = seeds().tokens; - const result = await optimizeVector( - tokens as InputDataType, - { - svgo: { - plugins: [ - { - cleanupAttrs: false, - }, - { - removeDoctype: false, - }, - { - removeXMLProcInst: false, - }, - { - removeComments: false, - }, - { - removeMetadata: false, - }, - { - removeTitle: false, - }, - { - removeDesc: false, - }, - { - removeUselessDefs: false, - }, - { - removeEditorsNSData: false, - }, - { - removeEmptyAttrs: false, - }, - { - removeHiddenElems: false, - }, - { - removeEmptyText: false, - }, - { - removeEmptyContainers: false, - }, - { - removeViewBox: false, - }, - { - cleanupEnableBackground: false, - }, - { - convertStyleToAttrs: false, - }, - { - convertColors: false, - }, - { - convertPathData: false, - }, - { - convertTransform: false, - }, - { - removeUnknownsAndDefaults: false, - }, - { - removeNonInheritableGroupAttrs: false, - }, - { - removeUselessStrokeAndFill: false, - }, - { - removeUnusedNS: false, - }, - { - cleanupIDs: false, - }, - { - cleanupNumericValues: false, - }, - { - moveElemsAttrsToGroup: false, - }, - { - moveGroupAttrsToElems: false, - }, - { - collapseGroups: false, - }, - { - removeRasterImages: false, - }, - { - mergePaths: false, - }, - { - convertShapeToPath: false, - }, - { - sortAttrs: false, - }, - { - removeDimensions: false, - }, - ], - }, - }, - libs as LibsType - ); - if (result instanceof Error) return fail(result); - expect( - result.find(({ name }) => name === "alert-circle")!.value.content - ).toEqual( - '' - ); - expect( - result.find(({ name }) => name === "airplay")!.value.content - ).toEqual( - '' - ); - return; - }); - - it("should send error", async () => { - try { - await optimizeVector( - // @ts-ignore - "Wrong data (should be catch by ts in real life)", - undefined, - libs as LibsType - ); - } catch (error) { - expect(error).toBeInstanceOf(TypeError); - } - - return; - }); - - it("should send an error after optimize", async () => { - const customSVGO: { - optimize: typeof SVGO.optimize; - } = { - optimize() { - throw new Error("Needed error"); - }, - }; - - const tokens = seeds().tokens; - const result = await optimizeVector( - tokens as InputDataType, - { - svgo: { - plugins: [ - { - removeDimensions: true, - }, - { - removeAttrs: { - attrs: "(fill|stroke)", - }, - }, - ], - }, - }, - { - ...libs, - SVGO: customSVGO, - } as LibsType - ); - if (result instanceof Error) return fail(result); - // Dimensions not removed - expect( - result.find(({ name }) => name === "airplay")!.value.content - ).toEqual( - ` - - - -` - ); - - return; - }); - - it("should remove dimensions", async () => { - const tokens = seeds().tokens; - const result = await optimizeVector( - tokens as InputDataType, - { - svgo: { - plugins: [ - { - removeDimensions: true, - }, - ], - }, - }, - libs as LibsType - ); - if (result instanceof Error) return fail(result); - expect( - result.find(({ name }) => name === "airplay")!.value.content - ).toEqual( - '' - ); - - return; - }); - }); - describe("SVGO v2", () => { - it("Get tokens - apply parsers", async () => { - const tokens = seeds().tokens.filter(token => token.type === "vector"); - const result = await optimizeVector( - tokens as InputDataType, - { - svgo: { - plugins: [ - { - name: "preset-default", - }, - { - name: "removeAttrs", - params: { - attrs: "fill", - }, - }, - ], - }, - }, - libs as LibsType - ); - if (result instanceof Error) return fail(result); - expect( - result.find(({ name }) => name === "alert-circle")!.value.content - ).toEqual( - '' - ); - expect( - result.find(({ name }) => name === "airplay")!.value.content - ).toEqual( - '' - ); - expect(result.find(({ name }) => name === "airplay")!.value).toEqual( - expect.objectContaining({ - format: "svg", - content: expect.any(String), - }) - ); - return; - }); - }); - describe("Handle no svg vector", () => { - it("PDF vector must output an url", async () => { - const tokens = seeds().tokens.filter( - token => token.type === "vector" - ) as Array; - const result = await optimizeVector( - tokens as InputDataType, - undefined, - libs as LibsType - ); - if (result instanceof Error) return fail(result); - result.forEach(vector => { - if (vector.value.format === "pdf") { - expect(vector.value.content).toBeFalsy(); - expect(typeof vector.value.url).toBe("string"); - } else { - expect(typeof vector.value.content).toBe("string"); - expect(vector.value.url).toBeFalsy(); - } - }); - }); - }); -}); diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/svgo/svgo.type.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/svgo/svgo.type.ts deleted file mode 100644 index f57bc9baa..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/svgo/svgo.type.ts +++ /dev/null @@ -1,51 +0,0 @@ -/* eslint-disable @typescript-eslint/no-explicit-any */ -import type { default as SVGOV1 } from "../../types/svgo.v1"; - -export type DefaultPresetPluginsName = any; - -export type DefaultPresetPluginsParams = any; - -export type DefaultPresetOverride = { - [P in DefaultPresetPluginsName]?: false | DefaultPresetPluginsParams; -}; - -export type PluginV2 = any; -export type PluginV1 = SVGOV1.PluginConfig; -export type Plugins = Array | Array; - -export const defaultPresetPlugins = [ - "removeDoctype", - "removeXMLProcInst", - "removeComments", - "removeMetadata", - "removeEditorsNSData", - "cleanupAttrs", - "mergeStyles", - "inlineStyles", - "minifyStyles", - "cleanupIDs", - "removeUselessDefs", - "cleanupNumericValues", - "convertColors", - "removeUnknownsAndDefaults", - "removeNonInheritableGroupAttrs", - "removeUselessStrokeAndFill", - "removeViewBox", - "cleanupEnableBackground", - "removeHiddenElems", - "removeEmptyText", - "convertShapeToPath", - "convertEllipseToCircle", - "moveElemsAttrsToGroup", - "moveGroupAttrsToElems", - "collapseGroups", - "convertPathData", - "convertTransform", - "removeEmptyAttrs", - "removeEmptyContainers", - "mergePaths", - "removeUnusedNS", - "sortDefsChildren", - "removeTitle", - "removeDesc", -]; diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-css-custom-properties/README.md b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-css-custom-properties/README.md deleted file mode 100644 index 41aec97a3..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-css-custom-properties/README.md +++ /dev/null @@ -1,210 +0,0 @@ -# To CSS Custom Properties - -## Description - -This parser helps you transform design tokens in CSS Custom Properties. - -Learn more about how to configure Specify in the API documentation: [https://specifyapp.com/developers](https://specifyapp.com/developers). - -## Interface - -```ts -interface parser { - name: "to-css-custom-properties"; - options?: Partial<{ - formatName: "camelCase" | "kebabCase" | "snakeCase" | "pascalCase"; - formatTokens: Partial<{ - color: - | "rgb" - | "prgb" - | "hex" - | "hex6" - | "hex3" - | "hex4" - | "hex8" - | "name" - | "hsl" - | "hsv"; - }>; - formatConfig: Partial<{ - selector: string; - endOfLine: "auto" | "lf" | "crlf" | "cr"; - tabWidth: number; - useTabs: boolean; - }>; - }>; -} -``` - -### Options - -| Parameter | Required | Type | Default | Description | -| ------------------------ | -------- | ----------------------------------------------------------------- | ------- | ----------------------------------------------------------------------------------------------------------------------------- | -| `formatName` | optional | `camelCase` `kebabCase` `snakeCase` `pascalCase` | | The case transformation you want to apply to your design token name. Learn more in [our dedicated section](#โ„น๏ธ-good-to-know). | -| `formatTokens.color` | optional | `rgb` `prgb` `hex` `hex6` `hex3` `hex4` `hex8` `name` `hsl` `hsv` | `rgb` | The color format you want to apply to your potential color design token | -| `formatConfig.selector` | optional | `string` | `:root` | The CSS selector containing your CSS custom properties | -| `formatConfig.endOfLine` | optional | `auto` `lf` `crlf` `cr` | `auto` | [Prettier documentation](https://prettier.io/docs/en/options.html#end-of-line) | -| `formatConfig.tabWidth` | optional | `number` | `2` | [Prettier documentation](https://prettier.io/docs/en/options.html#tab-width) | -| `formatConfig.useTabs` | optional | `boolean` | `false` | [Prettier documentation](https://prettier.io/docs/en/options.html#tabs) | - -## Types - -โ„น๏ธ **Please be aware that, depending on the order you use parsers, their input and output types have to match.** - -### Input - -Array of object with at least name, value and type - -```ts -type input = Array<{ name: string; value: any; type: string }>; -``` - -### Output - -String formated in css - -```ts -type output = string; -``` - -## Basic Usage - -### Config - -```jsonc -"parsers": [ - { - "name": "to-css-custom-properties" - } - // โ€ฆ -] -``` - -### Before/After - -#### Input - -```jsonc -[ - { - "type": "color", - "value": { - "a": 0.96, - "b": 20, - "g": 227, - "r": 122 - }, - "name": "Primary color" - } -] -``` - -#### Output - -```css -:root { - /* COLOR */ - --primary-color: rgba(122, 227, 20, 0.96); -} -``` - -## Complex Usage - Create CSS Custom Properties, change format color values and change CSS selector - -### Config - -```jsonc -{ - "name": "to-css-custom-properties", - "options": { - "formatTokens": { - "color": "hsl" - }, - "formatConfig": { - "selector": "body[data-theme=\"light\"]", - "tabWidth": 4 - } - } -} -``` - -### Before/After - -#### Input - -```jsonc -[ - { - "type": "color", - "value": { - "a": 0.96, - "b": 20, - "g": 227, - "r": 122 - }, - "name": "Primary color" - } -] -``` - -#### Output - -```css -body[data-theme="light"] { - /* COLOR */ - --primary-color: hsla(90, 84%, 48%, 0.96); -} -``` - -## โ„น๏ธ Good to know - -This parser will always generate valid CSS. Thus, if design tokens coming from Specify have a name incorrectly formatted, this parser will automatically "kebabcasify" your CSS Custom Properties. - -### Input example #1 - -Let's say a color design token coming from Specify has the following structure: - -```jsonc -{ - "type": "color", - "value": { - "a": 0.96, - "b": 20, - "g": 227, - "r": 122 - }, - "name": "Color / Red" <-- String contains invalid CSS characters like spaces and "/" ๐Ÿšซ -} -``` - -This parser will generate: `--color-red: rgba(122, 227, 20, 0.96);` - -### Input example #2 - -Let's say a color design token coming from Specify has the following structure: - -```jsonc -{ - "type": "color", - "value": { - "a": 0.96, - "b": 20, - "g": 227, - "r": 122 - }, - "name": "Red" <-- String is valid CSS โœ… -} -``` - -This parser will generate: `--Red: rgba(122, 227, 20, 0.96);`. - -Don't want uppercase in your CSS Custom Property? -Apply the following `formatName` options: - -```jsonc -{ - "name": "to-css-custom-properties", - "options": { - "formatName": "kebabCase" - } -} -``` diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-css-custom-properties/to-css-custom-properties.parser.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-css-custom-properties/to-css-custom-properties.parser.ts deleted file mode 100644 index 5f92b9a82..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-css-custom-properties/to-css-custom-properties.parser.ts +++ /dev/null @@ -1,82 +0,0 @@ -/* eslint-disable @typescript-eslint/no-explicit-any */ -import parserCss from "prettier/parser-postcss"; -import prettier from "prettier/standalone"; -import { IToken } from "../../types"; -import { LibsType } from "../global-libs"; -import * as TokensClass from "./tokens"; - -export type InputDataType = Array< - Pick & Record ->; -export type OutputDataType = string; -export type ColorsFormat = - | "rgb" - | "prgb" - | "hex" - | "hex6" - | "hex3" - | "hex4" - | "hex8" - | "name" - | "hsl" - | "hsv"; -export type OptionsType = - | Partial<{ - formatName: "camelCase" | "kebabCase" | "snakeCase" | "pascalCase"; - formatTokens: Partial<{ - color: ColorsFormat; - }>; - formatConfig: Partial<{ - selector: string; - endOfLine: "auto" | "lf" | "crlf" | "cr"; - tabWidth: number; - useTabs: boolean; - }>; - }> - | undefined; - -export default async function ( - tokens: InputDataType, - options: OptionsType, - { _ }: Pick -): Promise { - const transformNameFn = _[options?.formatName || "kebabCase"]; - const selector = options?.formatConfig?.selector || ":root"; - const tokensGroupByType = _.groupBy(tokens, "type"); - const styles = Object.keys(tokensGroupByType).reduce( - (result: any, type: any) => { - const formattedCss = tokensGroupByType[type] - .map((token: any) => { - if ( - !(TokensClass)[ - `${token.type.charAt(0).toUpperCase() + token.type.slice(1)}` - ] - ) { - return undefined; - } - const instance = new (TokensClass)[ - `${token.type.charAt(0).toUpperCase() + token.type.slice(1)}` - ](token); - - const name = - options?.formatName || - token.name.includes(" ") || - token.name.includes("\n") || - token.name.includes("/") - ? transformNameFn(token.name) - : token.name; - return `--${name}: ${instance.toCss(options)};`; - }) - .join(""); - if (formattedCss.length > 0) - result += `\n\n/* ${type.toUpperCase()} */\n${formattedCss}`; - return result; - }, - "" - ); - return prettier.format(`${selector} {${styles}}`, { - ...options?.formatConfig, - parser: "css", - plugins: [parserCss], - }); -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-css-custom-properties/to-css-custom-properties.spec.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-css-custom-properties/to-css-custom-properties.spec.ts deleted file mode 100644 index 48e34241b..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-css-custom-properties/to-css-custom-properties.spec.ts +++ /dev/null @@ -1,225 +0,0 @@ -import libs from "../global-libs"; -import seeds from "../../tests/seeds"; -import toCss, { OptionsType } from "./to-css-custom-properties.parser"; -import { - ColorToken, - ColorValue, - Shadow, - ShadowToken, - Token, - MeasurementToken, -} from "../../types"; - -describe("To css", () => { - it("Get tokens - apply parsers", async () => { - const result = await toCss(seeds().tokens, undefined, libs); - expect(typeof result).toEqual("string"); - const color = seeds().tokens.find( - token => token.type === "color" - ) as ColorToken; - const measurement = seeds().tokens.find( - token => token.type === "measurement" - ) as MeasurementToken; - const shadow = seeds().tokens.find( - token => token.type === "shadow" - ) as ShadowToken; - - const shadowValue = shadow.value.reduce((acc: string, value: Shadow) => { - const { color, offsetX, offsetY, blur, isInner } = value; - const x = offsetX.value; - const y = offsetY.value; - const bl = blur.value; - const { r, g, b, a } = color.value; - const innerText = isInner ? "inset " : ""; - if (acc === "") { - return `${innerText}${x.measure}${x.unit} ${y.measure}${y.unit} ${bl.measure}${bl.unit} rgba(${r}, ${g}, ${b}, ${a})`; - } - - return `${acc}, ${innerText}${x.measure}${x.unit} ${y.measure}${y.unit} ${bl.measure}${bl.unit} rgba(${r}, ${g}, ${b}, ${a})`; - }, ""); - - expect( - result.includes( - `${libs._.kebabCase(color.name)}: ${libs - .tinycolor(color.value as ColorValue) - .toString("rgb")}` - ) - ).toBe(true); - expect(result.includes(`${shadow.name}: ${shadowValue}`)).toBe(true); - expect( - result.includes( - `${libs._.kebabCase(measurement.name)}: ${measurement.value.measure}${ - measurement.value.unit - }` - ) - ).toBe(true); - }); - - it("Get tokens - apply parsers - with options", async () => { - const options: OptionsType = { - formatName: "snakeCase"!, - formatTokens: { color: "hsl" }, - }; - const result = await toCss(seeds().tokens, options, libs); - const color = seeds().tokens.find( - token => token.type === "color" - ) as ColorToken; - const measurement = seeds().tokens.find( - token => token.type === "measurement" - ) as MeasurementToken; - - const fnFormatColor = libs._[options.formatName!](color.name); - expect( - result.includes( - `${fnFormatColor}: ${libs - .tinycolor(color.value as ColorValue) - .toString(options.formatTokens?.color)}` - ) - ).toBe(true); - - const fnFormatMeasurement = libs._[options.formatName!](measurement.name); - expect( - result.includes( - `${fnFormatMeasurement}: ${measurement.value.measure}${measurement.value.unit}` - ) - ).toBe(true); - }); - - it("Get tokens - apply parsers - with custom selector", async () => { - const options: OptionsType = { - formatName: "snakeCase"!, - formatTokens: { color: "hsl" }, - formatConfig: { - selector: 'body[data-theme="light"]', - }, - }; - const result = await toCss(seeds().tokens, options, libs); - const color = seeds().tokens.find( - token => token.type === "color" - ) as ColorToken; - const measurement = seeds().tokens.find( - token => token.type === "measurement" - ) as MeasurementToken; - - const fnFormatColor = libs._[options.formatName!](color.name); - expect( - result.includes( - `${fnFormatColor}: ${libs - .tinycolor(color.value as ColorValue) - .toString(options.formatTokens?.color)}` - ) - ).toBe(true); - - const fnFormatMeasurement = libs._[options.formatName!](measurement.name); - expect( - result.includes( - `${fnFormatMeasurement}: ${measurement.value.measure}${measurement.value.unit}` - ) - ).toBe(true); - expect(result.includes(`${options.formatConfig!.selector}`)).toBe(true); - }); - - it("Get tokens - apply parsers - without custom selector", async () => { - const options: OptionsType = { - formatName: "snakeCase"!, - formatTokens: { color: "hsl" }, - }; - const result = await toCss(seeds().tokens, options, libs); - const color = seeds().tokens.find( - token => token.type === "color" - ) as ColorToken; - const measurement = seeds().tokens.find( - token => token.type === "measurement" - ) as MeasurementToken; - - const fnFormatColor = libs._[options.formatName!](color.name); - expect( - result.includes( - `${fnFormatColor}: ${libs - .tinycolor(color.value as ColorValue) - .toString(options.formatTokens?.color)}` - ) - ); - - const fnFormatMeasurement = libs._[options.formatName!](measurement.name); - expect( - result.includes( - `${fnFormatMeasurement}: ${measurement.value.measure}${measurement.value.unit}` - ) - ).toBe(true); - expect(result.includes(`:root {`)).toBe(true); - }); - - it("Get tokens - apply parsers - with camelCase", async () => { - const options: OptionsType = { - formatName: "camelCase"!, - formatTokens: { color: "hsl" }, - }; - const result = await toCss(seeds().tokens, options, libs); - const color = seeds().tokens.find( - token => token.type === "color" - ) as ColorToken; - const measurement = seeds().tokens.find( - token => token.type === "measurement" - ) as MeasurementToken; - - const fnFormatColor = libs._[options.formatName!](color.name); - expect( - result.includes( - `${fnFormatColor}: ${libs - .tinycolor(color.value as ColorValue) - .toString(options.formatTokens?.color)}` - ) - ).toBe(true); - - expect(result.includes("colorsAccent")).toBe(true); - expect(result.includes("colorsRed")).toBe(true); - - const fnFormatName = libs._.camelCase; - expect( - result.includes( - `${fnFormatName(measurement.name)}: ${measurement.value.measure}${ - measurement.value.unit - }` - ) - ).toBe(true); - expect(result.includes(`:root {`)).toBe(true); - }); - - it("Get tokens - apply parsers - all tokens", async () => { - const options: OptionsType = { - formatName: "kebabCase"!, - }; - const result = await toCss(seeds().tokens, options, libs); - expect(result.includes("--colors-accent: rgb(87, 124, 254);")).toBe(true); - expect( - result.includes( - '--acme-logo: "https://s3-us-west-2.amazonaws.com/figma-alpha-api/img/13d6/2eb6/a2626d914998754ac0b704e2cdb7a813";' - ) - ).toBe(true); - expect( - result.includes("--border-accent: 2px solid rgba(102, 80, 239, 1);") - ).toBe(true); - expect(result.includes("--very-long: 3s;")).toBe(true); - expect(result.includes("--base-space-01: 4px;")).toBe(true); - expect(result.includes("--visible: 0.95;")).toBe(true); - expect( - result.includes("--elevation-1: 0px 4px 8px rgba(0, 0, 0, 0.1);") - ).toBe(true); - expect( - result.includes( - '--activity: "https://s3-us-west-2.amazonaws.com/figma-alpha-api/img/96dc/8825/c166b559140a0a64b28441924700a0b2";' - ) - ).toBe(true); - expect(result.includes("--background: 1;")).toBe(true); - expect( - result.includes( - ` --gradients-colored: linear-gradient( - 90deg, - rgb(245, 72, 63) 0%, - rgb(255, 142, 5) 100% - );` - ) - ).toBe(true); - }); -}); diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-css-custom-properties/tokens/bitmap.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-css-custom-properties/tokens/bitmap.ts deleted file mode 100644 index 42afdfe2a..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-css-custom-properties/tokens/bitmap.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { BitmapToken } from "../../../types"; - -export class Bitmap extends BitmapToken { - constructor(token: Partial) { - super(token); - } - - toCss(): string { - return JSON.stringify(this.value.url); - } -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-css-custom-properties/tokens/border.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-css-custom-properties/tokens/border.ts deleted file mode 100644 index 8cdfade28..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-css-custom-properties/tokens/border.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { BorderToken } from "../../../types"; - -export class Border extends BorderToken { - constructor(token: Partial) { - super(token); - } - - toCss() { - const { color, type, width } = this.value; - const { measure, unit } = width.value; - const { r, g, b, a } = color.value; - return `${measure}${unit} ${type.toLowerCase()} rgba(${r}, ${g}, ${b}, ${a})`; - } -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-css-custom-properties/tokens/color.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-css-custom-properties/tokens/color.ts deleted file mode 100644 index cbf4467d1..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-css-custom-properties/tokens/color.ts +++ /dev/null @@ -1,14 +0,0 @@ -import tinycolor from "tinycolor2"; -import { OptionsType } from "../to-css-custom-properties.parser"; -import { ColorToken } from "../../../types"; - -export class Color extends ColorToken { - constructor(token: Partial) { - super(token); - } - toCss(options: OptionsType): string { - return tinycolor(this.value).toString( - options?.formatTokens?.color || "rgb" - ); - } -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-css-custom-properties/tokens/depth.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-css-custom-properties/tokens/depth.ts deleted file mode 100644 index f621f3d87..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-css-custom-properties/tokens/depth.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { DepthToken } from "../../../types"; - -export class Depth extends DepthToken { - constructor(token: Partial) { - super(token); - } - - toCss() { - return JSON.stringify(this.value.depth); - } -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-css-custom-properties/tokens/duration.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-css-custom-properties/tokens/duration.ts deleted file mode 100644 index 139d957c5..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-css-custom-properties/tokens/duration.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { DurationToken } from "../../../types"; - -export class Duration extends DurationToken { - constructor(token: Partial) { - super(token); - } - - toCss() { - const { duration, unit } = this.value; - return `${duration}${unit}`; - } -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-css-custom-properties/tokens/gradient.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-css-custom-properties/tokens/gradient.ts deleted file mode 100644 index 96789eefc..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-css-custom-properties/tokens/gradient.ts +++ /dev/null @@ -1,21 +0,0 @@ -import tinycolor from "tinycolor2"; -import { GradientToken } from "../../../types"; - -export class Gradient extends GradientToken { - constructor(token: Partial) { - super(token); - } - - toCss() { - return this.value.gradients - .map(gradient => { - return `linear-gradient(${gradient.angle}, ${gradient.colors - .map( - ({ color, position }) => - `${tinycolor(color.value).toString("rgb")} ${position}%` - ) - .join(", ")})`; - }) - .join(", "); - } -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-css-custom-properties/tokens/index.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-css-custom-properties/tokens/index.ts deleted file mode 100644 index a41731f86..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-css-custom-properties/tokens/index.ts +++ /dev/null @@ -1,10 +0,0 @@ -export * from "./bitmap"; -export * from "./color"; -export * from "./gradient"; -export * from "./shadow"; -export * from "./vector"; -export * from "./opacity"; -export * from "./depth"; -export * from "./duration"; -export * from "./border"; -export * from "./measurement"; diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-css-custom-properties/tokens/measurement.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-css-custom-properties/tokens/measurement.ts deleted file mode 100644 index 50fb07d65..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-css-custom-properties/tokens/measurement.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { MeasurementToken } from "../../../types"; - -export class Measurement extends MeasurementToken { - constructor(token: Partial) { - super(token); - } - toCss(): string { - return `${this.value.measure}${this.value.unit}`; - } -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-css-custom-properties/tokens/opacity.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-css-custom-properties/tokens/opacity.ts deleted file mode 100644 index 432f25165..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-css-custom-properties/tokens/opacity.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { OpacityToken } from "../../../types"; - -export class Opacity extends OpacityToken { - constructor(token: Partial) { - super(token); - } - toCss() { - return this.value.opacity / 100; - } -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-css-custom-properties/tokens/shadow.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-css-custom-properties/tokens/shadow.ts deleted file mode 100644 index 60005d576..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-css-custom-properties/tokens/shadow.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { ShadowToken } from "../../../types"; - -export class Shadow extends ShadowToken { - constructor(token: Partial) { - super(token); - } - - toCss() { - return this.value.reduce((acc, shadow) => { - const { color, offsetX, offsetY, blur, isInner, spread } = shadow; - const xString = `${offsetX.value.measure}${offsetX.value.unit}`; - const yString = `${offsetY.value.measure}${offsetY.value.unit}`; - const blurString = `${blur.value.measure}${blur.value.unit}`; - // Intial space in the string to avoid having double space - const spreadString = spread - ? ` ${spread.value.measure}${spread.value.unit}` - : ""; - const { r, g, b, a } = color.value; - const innerText = isInner ? "inset " : ""; - if (acc === "") { - return `${innerText}${xString} ${yString} ${blurString}${spreadString} rgba(${r},${g},${b},${a})`; - } - - return `${acc}, ${innerText}${xString} ${yString} ${blurString}${spreadString} rgba(${r},${g},${b},${a})`; - }, ""); - } -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-css-custom-properties/tokens/vector.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-css-custom-properties/tokens/vector.ts deleted file mode 100644 index 7ceaf931a..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-css-custom-properties/tokens/vector.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { VectorToken } from "../../../types"; - -export class Vector extends VectorToken { - constructor(token: Partial) { - super(token); - } - - toCss() { - return JSON.stringify(this.value.url); - } -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-css-font-import/README.md b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-css-font-import/README.md deleted file mode 100644 index 85402220f..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-css-font-import/README.md +++ /dev/null @@ -1,117 +0,0 @@ -# To CSS Font Import - -## Description - -This parser helps you create CSS `@font-face` rules to import your font files. - -Learn more about how to configure Specify in the API documentation: [https://specifyapp.com/developers](https://specifyapp.com/developers). - -## Interface - -```ts -interface parser { - name: "to-css-font-import"; - options?: { - formats?: Array<"woff2" | "woff" | "otf" | "ttf" | "eot">; - fontsPath?: string; - fontFamilyTransform?: - | "camelCase" - | "kebabCase" - | "snakeCase" - | "pascalCase"; - includeFontWeight?: boolean; - genericFamily?: - | "serif" - | "sans-serif" - | "cursive" - | "fantasy" - | "monospace"; - }; -} -``` - -### Options - -| Parameter | Required | Type | Default | Description | -| --------------------- | -------- | --------------- | ------------------- | ------------------------------------------------------------------ | -| `formats` | optional | `Array` | `["woff2", "woff"]` | The list of formats to import. | -| `fontsPath` | optional | `string` | | The path of font's directory | -| `fontFamilyTransform` | optional | `string` | | The function to normalize the font-family property | -| `includeFontWeight` | optional | `boolean` | true | Allow to include the font-weight property in the result | -| `genericFamily` | optional | `string` | | The generic font family will be applied after the main font family | - -## Types - -โ„น๏ธ **Please be aware that, depending on the order you use parsers, their input and output types have to match.** - -### Input - -Array of object with at least the key `name` - -```ts -Array<{ name: string; [Key: string]: any }>; -``` - -### Output - -```ts -type output = string; -``` - -## Usage - -### Config - -```jsonc -"parsers": [ - { - "name": "to-css-font-import", - "options": { - "formats": ["woff2", "woff"] - } - } - // โ€ฆ -] -``` - -### Before/After - -#### Input - -```jsonc -[ - { - "type": "font", - "name": "Inter-Medium", - "value": { - "isItalic": false, - "provider": "Google Fonts", - "fontFamily": "Inter", - "fontWeight": 500, - "fontFileMissing": false, - "fontPostScriptName": "Inter-Medium", - "url": "https://www.yourfonturl.com/Inter-Medium/Inter-Medium.ttf" - }, - "meta": { - "source": "localStyles" - } - } -] -``` - -#### Output - -```css -@font-face { - font-family: "Inter-Medium"; - src: url("Inter-Medium.woff2") format("woff2"), url("Inter-Medium.woff") - format("woff"); - font-weight: 700; -} -``` - -## โ„น๏ธ Good to know - -We decided to exclude the `eot`, `otf` and `ttf` file formats in the [`formats`](#Options) parameter. If you are mostly targeting users with modern browsers, [you can get away with a progressive method](https://css-tricks.com/understanding-web-fonts-getting/#font-formats) of using `@font-face` that only serves WOFF and WOFF2 formats. - -However, you can still add `eot`, `otf` and `ttf` file formats in the [`formats`](#Interface) parameter if you need to support older browsers. diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-css-font-import/index.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-css-font-import/index.ts deleted file mode 100644 index 8a43906ea..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-css-font-import/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -import { default as toCssFontImportParser } from "./to-css-font-import.parser"; - -export * from "./to-css-font-import.parser"; -export default toCssFontImportParser; diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-css-font-import/to-css-font-import.parser.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-css-font-import/to-css-font-import.parser.ts deleted file mode 100644 index 3c641aacb..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-css-font-import/to-css-font-import.parser.ts +++ /dev/null @@ -1,155 +0,0 @@ -import { ConsoleLogger } from "@open-system/core-shared-utilities"; -import * as _ from "lodash"; -import os from "os"; -import path from "path"; -import parserCss from "prettier/parser-postcss"; -import prettier from "prettier/standalone"; -export type InputDataType = Array<{ name: string; [Key: string]: any }>; -export type OutputDataType = string; -export type OptionsType = { - formats?: Array<"woff2" | "woff" | "otf" | "ttf" | "eot">; - fontsPath?: string; - fontFamilyTransform?: "camelCase" | "kebabCase" | "snakeCase" | "pascalCase"; - includeFontWeight?: boolean; - fontDisplay?: "auto" | "block" | "swap" | "fallback" | "optional"; - genericFamily?: "serif" | "sans-serif" | "cursive" | "fantasy" | "monospace"; -}; - -const formatDictionary = { - woff2: "woff2", - woff: "woff", - otf: "truetype", - ttf: "truetype", - eot: null, -}; - -class ToCssFont { - tokens: InputDataType; - formats: NonNullable; - fontsPath: NonNullable; - // eslint-disable-next-line @typescript-eslint/ban-types - fontFamilyTransformFn: Function | undefined; - includeFontWeight: OptionsType["includeFontWeight"]; - fontDisplay: NonNullable; - genericFamily: OptionsType["genericFamily"]; - - constructor(tokens: InputDataType, options: OptionsType | undefined) { - this.tokens = tokens; - this.formats = options?.formats || ["woff2", "woff"]; - this.fontsPath = options?.fontsPath || ""; - this.fontDisplay = options?.fontDisplay || "swap"; - this.genericFamily = options?.genericFamily; - this.includeFontWeight = - typeof options?.includeFontWeight !== "boolean" - ? true - : options.includeFontWeight; - if (options?.fontFamilyTransform) - this.fontFamilyTransformFn = _[options?.fontFamilyTransform]; - } - - run() { - return this.tokens - .map(tokenFont => { - let entry = this.appendFontFamily(tokenFont); - entry = this.appendFormats(entry, tokenFont); - if (this.formats?.includes("eot")) - entry = this.appendEotFormat(entry, tokenFont); - if (this.includeFontWeight) - entry = this.appendFontWeight(entry, tokenFont); - entry = this.setFontDisplay(entry, this.fontDisplay); - return this.wrapInFontFace(entry); - }) - .join(os.EOL + os.EOL); - } - - formatFontUrl(fontName: string, fileType = "ttf", fontWeight?: number) { - let fontWeightDesc = "Regular"; - if (fontWeight < 300) { - fontWeightDesc = "Light"; - } else if (fontWeight < 600) { - fontWeightDesc = "Regular"; - } else if (fontWeight < 700) { - fontWeightDesc = "SemiBold"; - } else if (fontWeight < 800) { - fontWeightDesc = "Bold"; - } else if (fontWeight < 900) { - fontWeightDesc = "ExtraBold"; - } else { - fontWeightDesc = "Black"; - } - - return path.join( - this.fontsPath, - fontName, - `${fontName}-${fontWeightDesc}.${fileType}` - ); - } - - appendFontFamily(token: InputDataType[0]) { - let result = this.fontFamilyTransformFn - ? this.fontFamilyTransformFn(token.name) - : JSON.stringify(token.name); - if (this.genericFamily) result += `, ${this.genericFamily}`; - return `font-family: ${result};`; - } - - appendEotFormat(entry: string, token: InputDataType[0]) { - return ( - entry + - `src: url("${this.formatFontUrl( - token.name, - "eot", - token.value?.fontWeight - )}");` - ); - } - - appendFormats(entry: string, token: InputDataType[0]) { - const formats = this.formats - .reduce>((result, format) => { - if (format === "eot") return result; - - result.push( - `url("${this.formatFontUrl( - token.name, - format, - token.value?.fontWeight - )}") format("${formatDictionary[format]}")` - ); - - return result; - }, []) - .join(","); - return entry + `src: ${formats};`; - } - - appendFontWeight(entry: string, token: InputDataType[0]) { - return token.value?.fontWeight - ? `${entry}font-weight: ${token.value.fontWeight};` - : entry; - } - - setFontDisplay(entry: string, fontDisplay: OptionsType["fontDisplay"]) { - return `${entry}font-display: ${fontDisplay};`; - } - - wrapInFontFace(entry: string) { - return `@font-face {${entry}}`; - } -} - -export default async function ( - tokens: InputDataType, - options?: OptionsType -): Promise { - try { - const toCssFont = new ToCssFont(tokens, options); - return prettier.format(toCssFont.run(), { - parser: "css", - plugins: [parserCss], - }); - } catch (err) { - ConsoleLogger.error(err); - throw err; - } -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-css-font-import/to-css-font-import.spec.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-css-font-import/to-css-font-import.spec.ts deleted file mode 100644 index 6ff3a5970..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-css-font-import/to-css-font-import.spec.ts +++ /dev/null @@ -1,49 +0,0 @@ -import seeds from "../../tests/seeds"; -import toCssFont from "./to-css-font-import.parser"; -import { Token } from "../../types"; - -describe("to-css-font-import", () => { - it("Get tokens - apply parsers", async () => { - const result = await toCssFont( - seeds().tokens.filter(({ type }) => type === "font") as Array - ); - if (result instanceof Error) return fail(result); - expect( - result.includes( - "@font-face {\n" + - ' font-family: "FiraCode-Medium";\n' + - ' src: url("FiraCode-Medium.woff2") format("woff2"),\n' + - ' url("FiraCode-Medium.woff") format("woff");\n' + - " font-weight: 500;\n" + - " font-display: swap;\n" + - "}" - ) - ).toBeTruthy(); - return; - }); - it("Get tokens - apply parsers - with options", async () => { - const result = await toCssFont( - seeds().tokens.filter(({ type }) => type === "font") as Array, - { - fontsPath: "../../assets/", - formats: ["woff2", "woff", "eot"], - fontFamilyTransform: "kebabCase", - includeFontWeight: false, - genericFamily: "sans-serif", - } - ); - if (result instanceof Error) return fail(result); - expect( - result.includes( - "@font-face {\n" + - " font-family: inter-semi-bold, sans-serif;\n" + - ' src: url("../../assets/Inter-SemiBold.woff2") format("woff2"),\n' + - ' url("../../assets/Inter-SemiBold.woff") format("woff");\n' + - ' src: url("../../assets/Inter-SemiBold.eot");\n' + - " font-display: swap;\n" + - "}" - ) - ).toBeTruthy(); - return; - }); -}); diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-css-text-style/README.md b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-css-text-style/README.md deleted file mode 100644 index f5acc733b..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-css-text-style/README.md +++ /dev/null @@ -1,210 +0,0 @@ -# TO CSS TEXTSTYLE - -## Description - -This parser helps you create text styles as CSS classes. - -Learn more about how to configure Specify in the API documentation: [https://specifyapp.com/developers](https://specifyapp.com/developers). - -## Interface - -```ts -interface parser { - name: "to-css-text-style"; - options?: { - include?: Array< - | "color" - | "font-family" - | "font-size" - | "font-weight" - | "line-height" - | "letter-spacing" - | "text-align" - | "vertical-align" - | "text-transform" - | "font-variant" - | "text-decoration" - | "text-indent" - | "font" - | "fontSize" - | "lineHeight" - | "letterSpacing" - | "textAlign" - | "textTransform" - | "fontVariant" - | "textDecoration" - | "textIndent" - >; - exclude?: Array< - | "color" - | "font-family" - | "font-size" - | "font-weight" - | "line-height" - | "letter-spacing" - | "text-align" - | "vertical-align" - | "text-transform" - | "font-variant" - | "text-decoration" - | "text-indent" - | "font" - | "fontSize" - | "lineHeight" - | "letterSpacing" - | "textAlign" - | "textTransform" - | "fontVariant" - | "textDecoration" - | "textIndent" - >; - prefix?: string; - suffix?: string; - colorFormat?: - | "rgb" - | "prgb" - | "hex" - | "hex6" - | "hex3" - | "hex4" - | "hex8" - | "name" - | "hsl" - | "hsv"; - cssClassFormat?: "camelCase" | "kebabCase" | "snakeCase" | "pascalCase"; - fontFamilyFormat?: "camelCase" | "kebabCase" | "snakeCase" | "pascalCase"; - genericFamily?: - | "serif" - | "sans-serif" - | "cursive" - | "fantasy" - | "monospace"; - relativeLineHeight?: boolean; - prettierConfig?: Partial<{ - endOfLine: "auto" | "lf" | "crlf" | "cr"; - tabWidth: number; - useTabs: boolean; - }>; - }; -} -``` - -### Options - -| Parameter | Required | Type | Default | Description | -| -------------------------- | -------- | ----------------------------------------------------------------- | ----------- | ------------------------------------------------------------------------------ | -| `include` | optional | `Array` | | List of properties to include in css classes | -| `exclude` | optional | `Array` | | List of properties to exclude in css classes | -| `prefix` | optional | `string` | | A string will be append before the css class name | -| `suffix` | optional | `string` | | A string will be append after the css class name | -| `colorFormat` | optional | `rgb` `prgb` `hex` `hex6` `hex3` `hex4` `hex8` `name` `hsl` `hsv` | `rgb` | A color format applied when a text style include a color | -| `cssClassFormat` | optional | `camelCase` `kebabCase` `snakeCase` `pascalCase` | `kebabCase` | The lodash function used to normalize the css class name | -| `fontFamilyFormat` | optional | `camelCase` `kebabCase` `snakeCase` `pascalCase` | | The lodash function used to normalize the font family value | -| `genericFamily` | optional | `string` | | The generic font family will be applied after the main font family | -| `relativeLineHeight` | optional | `boolean` | | Convert line height to relative value | -| `prettierConfig.endOfLine` | optional | `auto, lf, crlf, cr` | `auto` | [Prettier documentation](https://prettier.io/docs/en/options.html#end-of-line) | -| `prettierConfig.tabWidth` | optional | `number` | `2` | [Prettier documentation](https://prettier.io/docs/en/options.html#tab-width) | -| `prettierConfig.useTabs` | optional | `boolean` | `false` | [Prettier documentation](https://prettier.io/docs/en/options.html#tabs) | - -## Types - -โ„น๏ธ **Please be aware that, depending on the order you use parsers, their input and output types have to match.** - -Array of object with at least the key `name` and the value that match the [TextStyle type](https://github.com/Specifyapp/parsers/blob/master/types/tokens/TextStyle.ts#L70) - -### Input - -```ts -Array<{ name: string; value: TextStyleValue } & Record>; -``` - -### Output - -```ts -type output = string; -``` - -## Usage - -### Config - -```jsonc -"parsers": [ - { - "name": "to-css-text-style", - "options": { - "exclude": ["color", "text-indent", "vertical-align", "text-align"], - "prefix": "sp-", - "suffix": "-text-style", - "relativeLineHeight": true, - "genericFamily": "serif" - } - } - // โ€ฆ -] -``` - -### Before/After - -#### Input - -```jsonc -[ - { - "name": "Body", - "value": { - "font": { - "meta": { - "source": "localStyles" - }, - "name": "Inter-Medium", - "type": "font", - "value": { - "isItalic": false, - "fontFamily": "Inter", - "fontWeight": 500, - "fontPostScriptName": "Inter-Medium" - }, - "originId": "Inter-Medium" - }, - "color": { - "value": { - "a": 1, - "b": 196, - "g": 196, - "r": 196 - } - }, - "fontSize": { - "value": { - "unit": "px", - "measure": 14 - } - }, - "textAlign": { - "vertical": "top", - "horizontal": "left" - }, - "lineHeight": { - "value": { - "unit": "px", - "measure": 20 - } - } - }, - "type": "textStyle" - // โ€ฆ - } -] -``` - -#### Output - -```css -.sp-body-text-style { - font-family: allan, serif; - font-weight: 500; - font-size: 14px; - line-height: 1; -} -``` diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-css-text-style/to-css-text-style.parser.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-css-text-style/to-css-text-style.parser.ts deleted file mode 100644 index 2f501432e..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-css-text-style/to-css-text-style.parser.ts +++ /dev/null @@ -1,346 +0,0 @@ -import { LibsType } from "../global-libs"; -import { - ColorValue, - FontToken, - FontValue, - FontVariantValue, - MeasurementValue, - TextDecorationValue, - TextStyleValue, - TextTransformValue, -} from "../../types"; -import * as os from "os"; -import tinycolor from "tinycolor2"; -import prettier from "prettier/standalone"; -import parserCss from "prettier/parser-postcss"; -import _ from "lodash"; -import convertMeasurement from "../../libs/size-manipulation"; -const propertiesBase: Array = [ - "color", - "font", - "fontSize", - "lineHeight", - "letterSpacing", - "textAlign", - "textTransform", - "fontVariant", - "textDecoration", - "textIndent", -]; - -const propertiesBaseInCss = [ - "color", - "font-family", - "font-weight", - "font-size", - "line-height", - "letter-spacing", - "text-align", - "vertical-align", - "text-transform", - "font-variant", - "text-decoration", - "text-indent", -] as const; - -export type InputDataType = Array< - { name: string; value: TextStyleValue } & Record ->; -export type OutputDataType = string; -type FilterListFromTextStyle = keyof TextStyleValue; -type FilterListFromCssProperties = (typeof propertiesBaseInCss)[number]; -type FilterList = FilterListFromTextStyle | FilterListFromCssProperties; -type Properties = - | { include: Array } - | { exclude: Array }; -type ColorsFormat = - | "rgb" - | "prgb" - | "hex" - | "hex6" - | "hex3" - | "hex4" - | "hex8" - | "name" - | "hsl" - | "hsv"; -type transformFn = "camelCase" | "kebabCase" | "snakeCase" | "pascalCase"; -export type OptionsType = Partial< - { - prefix?: string; - suffix?: string; - colorFormat?: ColorsFormat; - cssClassFormat?: transformFn; - fontFamilyFormat?: transformFn; - genericFamily?: - | "serif" - | "sans-serif" - | "cursive" - | "fantasy" - | "monospace"; - relativeLineHeight?: boolean; - prettierConfig?: Partial<{ - endOfLine: "auto" | "lf" | "crlf" | "cr"; - tabWidth: number; - useTabs: boolean; - }>; - } & Properties ->; - -class ToCssTextStyle { - font: FontValue; - fontName: string; - color?: ColorValue; - fontSize?: MeasurementValue; - lineHeight?: MeasurementValue; - letterSpacing?: MeasurementValue; - textIndent?: MeasurementValue; - textAlign?: TextStyleValue["textAlign"]; - textTransform?: TextTransformValue; - fontVariant?: Array; - textDecoration?: Array; - cssContent: Array = []; - name: string; - cssProperties: Array; - options?: OptionsType; - constructor( - textStyle: TextStyleValue, - name: string, - cssProperties: Array, - options: OptionsType | undefined - ) { - this.font = textStyle.font.value; - this.fontName = - (textStyle.font as FontToken).name ?? this.font.fontPostScriptName; - this.color = textStyle.color?.value; - this.fontSize = textStyle.fontSize?.value; - this.textAlign = textStyle.textAlign; - this.lineHeight = textStyle.lineHeight?.value; - this.letterSpacing = textStyle.letterSpacing?.value; - this.textIndent = textStyle.textIndent?.value; - this.textTransform = textStyle.textTransform; - this.fontVariant = textStyle.fontVariant; - this.textDecoration = textStyle.textDecoration; - this.name = name; - this.cssProperties = cssProperties; - this.options = options; - } - - isIncluded(property: FilterListFromCssProperties) { - return this.cssProperties.includes(property); - } - - trigger = { - font: () => { - if (this.isIncluded("font-family")) { - let fontFamily = applyTransformStr( - this.fontName, - this.options?.fontFamilyFormat - ); - if (this.options?.genericFamily) - fontFamily += `, ${this.options.genericFamily}`; - this.cssContent.push(`font-family: ${fontFamily}`); - } - if (this.isIncluded("font-weight")) { - this.cssContent.push(`font-weight: ${this.font?.fontWeight}`); - } - }, - - fontSize: () => { - if (this.isIncluded("font-size")) { - this.cssContent.push( - `font-size: ${this.fontSize?.measure}${this.fontSize?.unit}` - ); - } - }, - - color: () => { - if (this.isIncluded("color")) { - this.cssContent.push( - `color: ${tinycolor(this.color).toString( - this.options?.colorFormat || "rgb" - )}` - ); - } - }, - lineHeight: () => { - if (this.isIncluded("line-height") && this.lineHeight) { - let lineHeight; - if (this.options?.relativeLineHeight) { - lineHeight = - Math.round( - (convertMeasurement(this.lineHeight, "px").measure / - convertMeasurement(this.fontSize!, "px").measure) * - 100 - ) / 100; - } else { - lineHeight = `${this.lineHeight?.measure}${ - this.lineHeight?.unit || "" - }`; - } - this.cssContent.push(`line-height: ${lineHeight}`); - } - }, - - letterSpacing: () => { - if (this.isIncluded("letter-spacing")) { - this.cssContent.push( - `letter-spacing: ${this.letterSpacing?.measure}${ - this.letterSpacing?.unit || "" - }` - ); - } - }, - textAlign: () => { - if (this.isIncluded("text-align")) { - if (this.textAlign?.horizontal) { - this.cssContent.push(`text-align: ${this.textAlign.horizontal}`); - } - } - if (this.isIncluded("vertical-align")) { - if (this.textAlign?.vertical) { - this.cssContent.push(`vertical-align: ${this.textAlign.vertical}`); - } - } - }, - textTransform: () => { - if (this.isIncluded("text-transform")) { - this.cssContent.push(`text-transform: ${this.textTransform}`); - } - }, - textDecoration: () => { - if (this.isIncluded("text-decoration") && this.textDecoration) { - this.cssContent.push( - `text-decoration: ${this.textDecoration.join(" ")}` - ); - } - }, - textIndent: () => { - if (this.isIncluded("text-indent")) { - this.cssContent.push( - `text-indent: ${this.textIndent?.measure}${this.textIndent?.unit}` - ); - } - }, - fontVariant: () => { - if (this.isIncluded("font-variant")) { - this.cssContent.push(`font-variant: ${this.fontVariant?.join(" ")}`); - } - }, - }; -} - -const getTextStyleProperties = function (options?: OptionsType) { - let textStyleProperties = propertiesBase; - if ( - options && - "include" in options && - options.include && - options.include.some(property => propertiesBase.includes(property)) - ) { - textStyleProperties = options.include.filter(property => { - return propertiesBase.includes(property); - }); - } else if ( - options && - "exclude" in options && - options.exclude && - options.exclude.some(property => propertiesBase.includes(property)) - ) { - textStyleProperties = textStyleProperties.filter(property => { - return ( - propertiesBase.includes(property) && - !options.exclude!.includes(property) - ); - }); - } - return textStyleProperties; -}; - -const getCssProperties = function (options?: OptionsType) { - let cssProperties: FilterListFromCssProperties[] = [...propertiesBaseInCss]; - if ( - options && - "include" in options && - options.include && - options.include.some(property => - propertiesBaseInCss.includes(property as FilterListFromCssProperties) - ) - ) { - cssProperties = options.include.filter(property => { - return propertiesBaseInCss.includes( - property as FilterListFromCssProperties - ); - }) as Array; - } else if ( - options && - "exclude" in options && - options.exclude && - options.exclude.some(property => - propertiesBaseInCss.includes(property as FilterListFromCssProperties) - ) - ) { - cssProperties = cssProperties.filter(property => { - return ( - propertiesBaseInCss.includes(property as FilterListFromCssProperties) && - !options.exclude!.includes(property) - ); - }); - } - return cssProperties; -}; - -const applyTransformStr = (str: string, fn?: transformFn) => { - if (fn) return _[fn](str); - return str.includes(" ") || str.includes("\n") || str.includes("/") - ? JSON.stringify(str) - : str; -}; - -export default async function ( - inputData: InputDataType, - options: OptionsType | undefined, - { _ }: Pick -): Promise { - try { - const textStylesProperties = getTextStyleProperties(options); - const cssProperties = getCssProperties(options); - const result = inputData - .map(token => { - const toCssTextStyle = new ToCssTextStyle( - token.value, - token.name, - cssProperties, - options - ); - - textStylesProperties.forEach(property => { - if ( - property in toCssTextStyle && - !!toCssTextStyle[property as keyof TextStyleValue] - ) { - toCssTextStyle.trigger[ - property as keyof ToCssTextStyle["trigger"] - ](); - } - }); - - if (options?.prefix) token.name = `${options.prefix}${token.name}`; - if (options?.suffix) token.name = `${token.name}${options.suffix}`; - let name = applyTransformStr( - token.name, - options?.cssClassFormat || "kebabCase" - ); - return `.${name} {${toCssTextStyle.cssContent.join(";" + os.EOL)}}`; - }) - .join(os.EOL + os.EOL); - - return prettier.format(result, { - ...options?.prettierConfig, - parser: "css", - plugins: [parserCss], - }); - } catch (err) { - throw err; - } -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-css-text-style/to-css-text-style.spec.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-css-text-style/to-css-text-style.spec.ts deleted file mode 100644 index 7ef8ce8e3..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-css-text-style/to-css-text-style.spec.ts +++ /dev/null @@ -1,217 +0,0 @@ -import seeds from "../../tests/seeds"; -import { - default as toCssTextStyle, - InputDataType, -} from "./to-css-text-style.parser"; -import libs from "../global-libs"; -import { TextStyleToken } from "../../types"; - -describe("to-css-text-style", () => { - it("Get tokens - execute parser", async () => { - const result = await toCssTextStyle( - seeds().tokens.filter( - ({ type }) => type === "textStyle" - ) as InputDataType, - undefined, - libs - ); - if (result instanceof Error) return fail(result); - expect(typeof result).toEqual("string"); - expect( - result.includes( - ".title {\n" + - " color: rgb(30, 33, 43);\n" + - " font-family: Inter-SemiBold;\n" + - " font-weight: 600;\n" + - " font-size: 32px;\n" + - " line-height: 40px;\n" + - " text-align: left;\n" + - " vertical-align: top;\n" + - " text-transform: uppercase;\n" + - " text-decoration: underline;\n" + - " text-indent: 5px;\n" + - "}" - ) - ).toBeTruthy(); - return; - }); - it("Get tokens - execute parser - with options include css properties", async () => { - const input = seeds().tokens.filter( - ({ type }) => type === "textStyle" - ) as Array; - const result = await toCssTextStyle( - input, - { - include: ["font-family"], - }, - libs - ); - if (result instanceof Error) return fail(result); - expect(result.match(/{\n font-family: (.*?);\n}/g)?.length).toEqual( - input.length - ); - return; - }); - it("Get tokens - execute parser - with options include textStyle properties", async () => { - const input = seeds().tokens.filter( - ({ type }) => type === "textStyle" - ) as Array; - const result = await toCssTextStyle( - input, - { - include: ["font"], - }, - libs - ); - if (result instanceof Error) return fail(result); - expect( - result.match(/{\n font-family: (.*?);\n font-weight: (.*?);\n}/g) - ?.length - ).toEqual(input.length); - return; - }); - it("Get tokens - execute parser - with options exclude textStyle properties", async () => { - const input = seeds().tokens.filter( - ({ type }) => type === "textStyle" - ) as Array; - const result = await toCssTextStyle( - input, - { - exclude: ["color"], - }, - libs - ); - if (result instanceof Error) return fail(result); - expect(result.includes("color")).toBeFalsy(); - return; - }); - - it("Get tokens - execute parser - with several options", async () => { - const input = seeds().tokens.filter( - ({ type }) => type === "textStyle" - ) as Array; - const result = await toCssTextStyle( - input, - { - prefix: "utils-", - suffix: "-text-style", - colorFormat: "hex", - cssClassFormat: "camelCase", - fontFamilyFormat: "kebabCase", - genericFamily: "serif", - relativeLineHeight: true, - }, - libs - ); - if (result instanceof Error) return fail(result); - expect( - result.includes( - ".utilsBodyTextStyle {\n" + - " color: #1e212b;\n" + - " font-family: inter-medium, serif;\n" + - " font-weight: 500;\n" + - " font-size: 14px;\n" + - " line-height: 1.43;\n" + - " letter-spacing: 10px;\n" + - " text-align: left;\n" + - " vertical-align: top;\n" + - "}" - ) - ).toBeTruthy(); - expect( - result.includes( - ".utilsCodeTextStyle {\n" + - " color: #ff8e05;\n" + - " font-family: fira-code-medium, serif;\n" + - " font-weight: 500;\n" + - " font-size: 13px;\n" + - " line-height: 1.54;\n" + - " text-align: left;\n" + - " vertical-align: top;\n" + - "}" - ) - ).toBeTruthy(); - expect( - result.includes( - ".utilsTitleTextStyle {\n" + - " color: #1e212b;\n" + - " font-family: inter-semi-bold, serif;\n" + - " font-weight: 600;\n" + - " font-size: 32px;\n" + - " line-height: 1.25;\n" + - " text-align: left;\n" + - " vertical-align: top;\n" + - " text-transform: uppercase;\n" + - " text-decoration: underline;\n" + - " text-indent: 5px;\n" + - "}" - ) - ).toBeTruthy(); - return; - }); - - it("Get tokens - execute parser - with options exclude font-weight property", async () => { - const input = seeds().tokens.filter( - ({ type }) => type === "textStyle" - ) as Array; - const result = await toCssTextStyle( - input, - { - exclude: ["font-weight"], - }, - libs - ); - if (result instanceof Error) return fail(result); - expect(result.includes("font-weight")).toBeFalsy(); - return; - }); - it("Get tokens - execute parser - with options include font-weight property", async () => { - const input = seeds().tokens.filter( - ({ type }) => type === "textStyle" - ) as Array; - const result = await toCssTextStyle( - input, - { - include: ["font-weight"], - }, - libs - ); - if (result instanceof Error) return fail(result); - expect(result.match(/{\n font-weight: (.*?);\n}/g)?.length).toEqual( - input.length - ); - return; - }); - it("Get tokens - execute parser - with options include font-weight property and exclude font-family", async () => { - const input = seeds().tokens.filter( - ({ type }) => type === "textStyle" - ) as Array; - const result = await toCssTextStyle( - input, - { - include: ["font-weight"], - exclude: ["font-family"], - }, - libs - ); - if (result instanceof Error) return fail(result); - expect(result.match(/{\n font-weight: (.*?);\n}/g)?.length).toEqual( - input.length - ); - return; - }); - it("Should Throw error when typing is incorrect", async () => { - const input = seeds().tokens.filter( - ({ type }) => type === "textStyle" - ) as Array; - await expect( - toCssTextStyle( - // @ts-ignore - "should break", - undefined, - libs - ) - ).rejects.toThrowError(Error); - return; - }); -}); diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-dsp/README.md b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-dsp/README.md deleted file mode 100644 index 48a1a365e..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-dsp/README.md +++ /dev/null @@ -1,252 +0,0 @@ -# TO DSP - -## Description - -This parser helps you create a [Design System Package (DSP)](https://github.com/AdobeXD/design-system-package-dsp). - -Learn more about how to configure Specify in the API documentation: [https://specifyapp.com/developers](https://specifyapp.com/developers). - -## Interface - -```ts -interface x { - name: "to-dsp"; - options?: Partial<{ - settings: Partial<{ - name?: string; - buildStatusLabel?: string; - packageVersion?: string; - snippetTriggerPrefix?: string; - }>; - createAssets: boolean; - }>; -} -``` - -### Options - -| Parameter | Required | Type | Default | Description | -| ------------------------------- | -------- | -------- | ---------------------- | ------------------------------------------------------------- | -| `settings.name` | optional | `string` | 'Generated by Specify' | The name of the DSP | -| `settings.buildStatusLabel` | optional | `string` | | Build status label (examples: 'dev' or 'released') | -| `settings.packageVersion` | optional | `string` | | Version of the DSP package, not the DSP spec | -| `settings.snippetTriggerPrefix` | optional | `string` | | Trigger for snippets on components (examples: 'sp-' or 'ex-") | -| `createAssets` | true | `true` | `true` | Defines if you want the assets to be created or not | - -## Output - -Please keep in mind that this parser generates files. This is why you should always set a folder as the final `path` in your parent rule. - -
-See Do & Don't config examples - -โœ… Do - -``` -// ... -"rules": [ - { - "name": "DSP", - "path": "dsp", // <-- path set as a folder - "parsers": [ - { - "name": "to-dsp" - } - ] - } -] -``` - -๐Ÿšซ Don't - -``` -// ... -"rules": [ - { - "name": "DSP", - "path": "dsp/dsp.json", // <-- path set as a file - "parsers": [ - { - "name": "to-dsp" - } - ] - } -] -``` - -
- -## Types - -โ„น๏ธ **Please be aware that, depending on the order you use parsers, their input and output types have to match.** - -### Input - -Array of object with at least name, value and type and id - -```ts -Array<{ - id: string; - name: string; - value: any; - type: string; -}>; -``` - -### Output - -An array of object containing a name and a value. The value is an object containing either an url or a content. This object is considered as a DownloadableFile - -```ts -type output = Array<{ - name: string; - value: { - content?: string; - url?: string; - }; -}>; -``` - -## Usage - -### Config - -```jsonc -"parsers": [ - { - "name": "to-dsp", - "options": { - "settings": { - "name": "My awesome DSP", - "buildStatusLabel": "test", - "packageVersion": "0.0.1", - "snippetTriggerPrefix": "ex-" - }, - "createAssets": false - } - } - // โ€ฆ -] -``` - -### Before/After - -#### Input - -```jsonc -[ - { - "type": "color", - "value": { - "a": 0.96, - "b": 20, - "g": 227, - "r": 122 - }, - "name": "Primary color" - } -] -``` - -#### Output - -```jsonc -[ - { - "name": "data/tokens.json", - "value": { - "content": - "{\n" + - " \"dsp_spec_version\": \"0.5.0\",\n" + - " \"last_updated_by\": \"Specify\",\n" + - " \"last_updated\": \"Wed, 07 Oct 2020 07:58:07 GMT\",\n" + - " \"entities\": [\n" + - " {\n" + - " \"class\": \"token\",\n" + - " \"type\": \"color\",\n" + - " \"name\": \"Primary color\",\n" + - " \"value\": \n" + - "{\n" + - " \"a\": \"0.96\",\n" + - " \"b\": \"20\",\n" + - " \"g\": \"227\",\n" + - " \"r\": \"122\",\n" + - "}," + - " \"tags\": [\n" + - " \"specify\",\n" + - " \"color\"\n" + - " ]\n" + - " },\n" + - " }\n" + - "}" - } - }, - { - "name": "data/components.json", - "value": { - "content": - "{\n" + - " \"dsp_spec_version\": \"0.5.0\",\n" + - " \"last_updated_by\": \"Specify\",\n" + - " \"last_updated\": \"Wed, 07 Oct 2020 08:04:22 GMT\",\n" + - " \"entities\": []\n" + - "}" - } - }, - { - "name": "data/fonts.json", - "value": { - "content": - "{\n" + - " \"dsp_spec_version\": \"0.5.0\",\n" + - " \"last_updated_by\": \"Specify\",\n" + - " \"last_updated\": \"Wed, 07 Oct 2020 08:04:22 GMT\",\n" + - " \"entities\": []\n" + - "}" - } - }, - { - "name": "data/docs.json", - "value": { - "content": - "{\n" + - " \"dsp_spec_version\": \"0.5.0\",\n" + - " \"last_updated_by\": \"Specify\",\n" + - " \"last_updated\": \"Wed, 07 Oct 2020 08:04:22 GMT\",\n" + - " \"entities\": []\n" + - "}" - } - }, - { - "name": "dsp.json", - "value": { - "content": - "{\n" + - " \"dsp_spec_version\": \"0.5.0\",\n" + - " \"last_updated_by\": \"Specify\",\n" + - " \"last_updated\": \"Wed, 07 Oct 2020 08:02:10 GMT\",\n" + - " \"import\": [\n" + - " {\n" + - " \"src\": \"data/tokens.json.json\"\n" + - " },\n" + - " {\n" + - " \"src\": \"data/components.json.json\"\n" + - " },\n" + - " {\n" + - " \"src\": \"data/fonts.json.json\"\n" + - " },\n" + - " {\n" + - " \"src\": \"data/docs.json.json\"\n" + - " }\n" + - " ],\n" + - " \"settings\": {\n" + - " \"name\": \"My DSP\",\n" + - " \"build_status_label\": \"test\",\n" + - " \"package_version\": \"0.0.1\",\n" + - " \"snippet_trigger_prefix\": \"ex-\"\n" + - " }\n" + - "}" - } - } -] -``` diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-dsp/dsp.type.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-dsp/dsp.type.ts deleted file mode 100644 index 034d7bdd0..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-dsp/dsp.type.ts +++ /dev/null @@ -1,48 +0,0 @@ -export interface DspEntity { - class: "token" | "collection" | "doc" | "component"; - type: "color" | "size" | "custom" | "alias" | "font" | "page"; - id: string; - name: string; - value: string; - tags: Array; - related_entity_ids?: Array; - snippets?: { - trigger: string; - languages: { - html: string; - }; - }; -} - -export interface DspImport { - src: string; -} - -export interface DspParserSettings { - name?: string; - buildStatusLabel?: string; - packageVersion?: string; - snippetTriggerPrefix?: string; -} - -export interface DspSettings { - name: string; - build_status_label: string; - package_version: string; - snippet_trigger_prefix: string; -} - -export interface DspJson { - dsp_spec_version: string; - last_updated_by: string; - last_updated: string; - import?: Array; - settings?: Partial; -} - -export interface ImportsJson { - dsp_spec_version: string; - last_updated_by: string; - last_updated: string; - entities: Array; -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-dsp/to-dsp.parser.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-dsp/to-dsp.parser.ts deleted file mode 100644 index f11d7a539..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-dsp/to-dsp.parser.ts +++ /dev/null @@ -1,149 +0,0 @@ -import { DownloadableFile, Token } from "../../types"; -import * as TokensClass from "./tokens"; -import { LibsType } from "../global-libs"; -import { DspEntity, DspJson, DspParserSettings } from "./dsp.type"; - -export type InputDataType = Array< - Pick & Record ->; -export type OutputDataType = Array; - -export type OptionsType = - | Partial<{ - settings: Partial; - createAssets: boolean; - }> - | undefined; - -export async function createAssetsFiles( - tokens: InputDataType, - SpServices: LibsType["SpServices"] -): Promise { - const assetsTypes = ["vector", "bitmap"]; - - const filteredTokens = tokens.filter(token => - assetsTypes.includes(token.type) - ); - - if (!filteredTokens.length) { - return []; - } - - return await Promise.all( - filteredTokens.map(async (token): Promise => { - const instance = new (TokensClass)[ - `${token.type.charAt(0).toUpperCase() + token.type.slice(1)}` - ](token); - - return instance.toDspAssets(SpServices); - }) - ); -} - -export default async function ( - tokens: InputDataType, - options: OptionsType, - { SpServices }: Pick -): Promise { - const sharedHeaders = { - dsp_spec_version: "0.5.0", - last_updated_by: "Specify", - last_updated: new Date().toISOString(), - }; - - const defaultSettings = { - name: "Generated by Specify", - build_status_label: "released", - package_version: "1.0.0", - snippet_trigger_prefix: "sp-", - }; - - const filesToCreateForTokenTypes = { - tokens: [ - "bitmap", - "border", - "color", - "depth", - "duration", - "gradient", - "measurement", - "opacity", - "shadow", - "vector", - ], - components: [], - fonts: [], - docs: [], - }; - - const filesToCreate = await Object.entries(filesToCreateForTokenTypes).reduce( - async (accPromise, [fileName, types]) => { - const acc = await accPromise; - const entities = tokens - .filter(token => - types.length ? (types as Array).includes(token.type) : false - ) - .map((token): DspEntity => { - const instance = new (TokensClass)[ - `${token.type.charAt(0).toUpperCase() + token.type.slice(1)}` - ](token); - - return instance.toDsp(); - }); - - return [ - ...acc, - { - name: `data/${fileName}.json`, - value: { - content: JSON.stringify( - { - ...sharedHeaders, - entities, - }, - null, - 4 - ), - }, - }, - ]; - }, - Promise.resolve([] as Array) - ); - - const dspJson: DspJson = { - ...sharedHeaders, - import: filesToCreate.map(file => ({ src: file.name })), - settings: defaultSettings, - }; - - if (options && options.settings) { - dspJson.settings = { - name: options.settings.name || defaultSettings.name, - build_status_label: - options.settings.buildStatusLabel || defaultSettings.build_status_label, - package_version: - options.settings.packageVersion || defaultSettings.package_version, - snippet_trigger_prefix: - options.settings.snippetTriggerPrefix || - defaultSettings.snippet_trigger_prefix, - }; - } - - // Create assets needed for dsp - const assetsFiles = - options?.createAssets === undefined || options.createAssets - ? await createAssetsFiles(tokens, SpServices) - : []; - - return [ - ...filesToCreate, - { - name: "dsp.json", - value: { - content: JSON.stringify(dspJson, null, 4), - }, - }, - ...assetsFiles, - ]; -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-dsp/to-dsp.spec.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-dsp/to-dsp.spec.ts deleted file mode 100644 index 22733128a..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-dsp/to-dsp.spec.ts +++ /dev/null @@ -1,524 +0,0 @@ -import seeds from "../../tests/seeds"; -import toDsp, { OptionsType } from "./to-dsp.parser"; -import { Token } from "../../types"; -import { DspParserSettings } from "./dsp.type"; -import libs, { LibsType } from "../global-libs"; - -const entitiesAvailable = [ - "bitmap", - "border", - "color", - "depth", - "duration", - "gradient", - "measurement", - "opacity", - "shadow", - "vector", -]; -const entitiesLength = seeds().tokens.filter(({ type }) => - entitiesAvailable.includes(type) -).length; - -describe("To DSP", () => { - it("should take settings and be able to return the correct value", async () => { - const settings: DspParserSettings = { - name: "My DSP", - buildStatusLabel: "test", - packageVersion: "0.0.1", - snippetTriggerPrefix: "ex-", - }; - - const tokenSeeds = seeds().tokens; - const result = await toDsp( - tokenSeeds, - { settings } as OptionsType, - libs as LibsType - ); - expect(Array.isArray(result)).toBe(true); - expect(result.length).toBe( - tokenSeeds.filter(({ type }) => type === "vector" || type === "bitmap") - .length + 5 - ); - expect(result.some(entity => entity.name === "dsp.json")).toBe(true); - expect(result.some(entity => entity.name === "data/tokens.json")).toBe( - true - ); - expect(result.some(entity => entity.name === "data/components.json")).toBe( - true - ); - expect(result.some(entity => entity.name === "data/fonts.json")).toBe(true); - expect(result.some(entity => entity.name === "data/docs.json")).toBe(true); - - const tokens = result.find(entity => entity.name === "data/tokens.json"); - const tokensEntities = JSON.parse(tokens?.value.content!).entities; - - expect(Array.isArray(tokensEntities)).toBe(true); - expect(tokensEntities.length).toBe(entitiesLength); - - const components = result.find( - entity => entity.name === "data/components.json" - ); - const componentsEntities = JSON.parse(components?.value.content!).entities; - - expect(Array.isArray(componentsEntities)).toBe(true); - expect(componentsEntities.length).toBe(0); - - const dsp = result.find(entity => entity.name === "dsp.json"); - const dspContent = JSON.parse(dsp?.value.content!); - - expect(dspContent.settings.name).toEqual(settings.name); - expect(dspContent.settings.build_status_label).toEqual( - settings.buildStatusLabel - ); - expect(dspContent.settings.package_version).toEqual( - settings.packageVersion - ); - expect(dspContent.settings.snippet_trigger_prefix).toEqual( - settings.snippetTriggerPrefix - ); - - expect( - dspContent.import.some( - (imported: { src: string }) => imported.src === "data/tokens.json" - ) - ).toBe(true); - expect( - dspContent.import.some( - (imported: { src: string }) => imported.src === "data/components.json" - ) - ).toBe(true); - expect( - dspContent.import.some( - (imported: { src: string }) => imported.src === "data/fonts.json" - ) - ).toBe(true); - expect( - dspContent.import.some( - (imported: { src: string }) => imported.src === "data/docs.json" - ) - ).toBe(true); - }); - - it("should send all when no tokens", async () => { - const settings: DspParserSettings = { - name: "My DSP", - buildStatusLabel: "test", - packageVersion: "0.0.1", - snippetTriggerPrefix: "ex-", - }; - - const result = await toDsp( - [] as Array, - { settings } as OptionsType, - libs as LibsType - ); - expect(result.length).toBe(5); - - expect(result.some(entity => entity.name === "dsp.json")).toBe(true); - expect(result.some(entity => entity.name === "data/tokens.json")).toBe( - true - ); - expect(result.some(entity => entity.name === "data/components.json")).toBe( - true - ); - expect(result.some(entity => entity.name === "data/fonts.json")).toBe(true); - expect(result.some(entity => entity.name === "data/docs.json")).toBe(true); - - const tokens = result.find(entity => entity.name === "data/tokens.json"); - const tokensEntities = JSON.parse(tokens?.value.content!).entities; - - expect(Array.isArray(tokensEntities)).toBe(true); - expect(tokensEntities.length).toBe(0); - - const components = result.find( - entity => entity.name === "data/components.json" - ); - const componentsEntities = JSON.parse(components?.value.content!).entities; - - expect(Array.isArray(componentsEntities)).toBe(true); - expect(componentsEntities.length).toBe(0); - }); - - it("should work with no settings", async () => { - const result = await toDsp( - [] as Array, - {} as OptionsType, - libs as LibsType - ); - expect(result.length).toBe(5); - - expect(result.some(entity => entity.name === "dsp.json")).toBe(true); - expect(result.some(entity => entity.name === "data/tokens.json")).toBe( - true - ); - expect(result.some(entity => entity.name === "data/components.json")).toBe( - true - ); - expect(result.some(entity => entity.name === "data/fonts.json")).toBe(true); - expect(result.some(entity => entity.name === "data/docs.json")).toBe(true); - - const dsp = result.find(entity => entity.name === "dsp.json"); - const dspContent = JSON.parse(dsp?.value.content!); - - expect(dspContent.settings.name).toEqual("Generated by Specify"); - }); - - it("should work with undefined settings", async () => { - const result = await toDsp( - [] as Array, - undefined as OptionsType, - libs as LibsType - ); - expect(result.length).toBe(5); - - expect(result.some(entity => entity.name === "dsp.json")).toBe(true); - expect(result.some(entity => entity.name === "data/tokens.json")).toBe( - true - ); - expect(result.some(entity => entity.name === "data/components.json")).toBe( - true - ); - expect(result.some(entity => entity.name === "data/fonts.json")).toBe(true); - expect(result.some(entity => entity.name === "data/docs.json")).toBe(true); - - const dsp = result.find(entity => entity.name === "dsp.json"); - const dspContent = JSON.parse(dsp?.value.content!); - - expect(dspContent.settings.name).toEqual("Generated by Specify"); - }); - - it("should work with missing name settings", async () => { - const settings: DspParserSettings = { - buildStatusLabel: "test", - packageVersion: "0.0.1", - snippetTriggerPrefix: "ex-", - }; - - const tokenSeeds = seeds().tokens as Array; - const result = await toDsp( - tokenSeeds, - { settings } as OptionsType, - libs as LibsType - ); - expect(Array.isArray(result)).toBe(true); - expect(result.length).toBe( - tokenSeeds.filter(({ type }) => type === "vector" || type === "bitmap") - .length + 5 - ); - expect(result.some(entity => entity.name === "dsp.json")).toBe(true); - expect(result.some(entity => entity.name === "data/tokens.json")).toBe( - true - ); - expect(result.some(entity => entity.name === "data/components.json")).toBe( - true - ); - expect(result.some(entity => entity.name === "data/fonts.json")).toBe(true); - expect(result.some(entity => entity.name === "data/docs.json")).toBe(true); - - const tokens = result.find(entity => entity.name === "data/tokens.json"); - const tokensEntities = JSON.parse(tokens?.value.content!).entities; - - expect(Array.isArray(tokensEntities)).toBe(true); - expect(tokensEntities.length).toBe(entitiesLength); - - const components = result.find( - entity => entity.name === "data/components.json" - ); - const componentsEntities = JSON.parse(components?.value.content!).entities; - - expect(Array.isArray(componentsEntities)).toBe(true); - expect(componentsEntities.length).toBe(0); - - const dsp = result.find(entity => entity.name === "dsp.json"); - const dspContent = JSON.parse(dsp?.value.content!); - - expect(dspContent.settings.name).toEqual("Generated by Specify"); - expect(dspContent.settings.build_status_label).toEqual( - settings.buildStatusLabel - ); - expect(dspContent.settings.package_version).toEqual( - settings.packageVersion - ); - expect(dspContent.settings.snippet_trigger_prefix).toEqual( - settings.snippetTriggerPrefix - ); - }); - - it("should work with missing buildStatusLabel setting", async () => { - const settings: DspParserSettings = { - name: "My DSP", - packageVersion: "0.0.1", - snippetTriggerPrefix: "ex-", - }; - - const tokenSeeds = seeds().tokens as Array; - const result = await toDsp( - tokenSeeds, - { settings } as OptionsType, - libs as LibsType - ); - expect(Array.isArray(result)).toBe(true); - expect(result.length).toBe( - tokenSeeds.filter(({ type }) => type === "vector" || type === "bitmap") - .length + 5 - ); - expect(result.some(entity => entity.name === "dsp.json")).toBe(true); - expect(result.some(entity => entity.name === "data/tokens.json")).toBe( - true - ); - expect(result.some(entity => entity.name === "data/components.json")).toBe( - true - ); - expect(result.some(entity => entity.name === "data/fonts.json")).toBe(true); - expect(result.some(entity => entity.name === "data/docs.json")).toBe(true); - - const tokens = result.find(entity => entity.name === "data/tokens.json"); - const tokensEntities = JSON.parse(tokens?.value.content!).entities; - - expect(Array.isArray(tokensEntities)).toBe(true); - expect(tokensEntities.length).toBe(entitiesLength); - - const components = result.find( - entity => entity.name === "data/components.json" - ); - const componentsEntities = JSON.parse(components?.value.content!).entities; - - expect(Array.isArray(componentsEntities)).toBe(true); - expect(componentsEntities.length).toBe(0); - - const dsp = result.find(entity => entity.name === "dsp.json"); - const dspContent = JSON.parse(dsp?.value.content!); - - expect(dspContent.settings.name).toEqual(settings.name); - expect(dspContent.settings.build_status_label).toEqual("released"); - expect(dspContent.settings.package_version).toEqual( - settings.packageVersion - ); - expect(dspContent.settings.snippet_trigger_prefix).toEqual( - settings.snippetTriggerPrefix - ); - }); - - it("should work with missing packageVersion setting", async () => { - const settings: DspParserSettings = { - name: "My DSP", - buildStatusLabel: "test", - snippetTriggerPrefix: "ex-", - }; - - const tokenSeeds = seeds().tokens as Array; - const result = await toDsp( - tokenSeeds, - { settings } as OptionsType, - libs as LibsType - ); - expect(Array.isArray(result)).toBe(true); - expect(result.length).toBe( - tokenSeeds.filter(({ type }) => type === "vector" || type === "bitmap") - .length + 5 - ); - expect(result.some(entity => entity.name === "dsp.json")).toBe(true); - expect(result.some(entity => entity.name === "data/tokens.json")).toBe( - true - ); - expect(result.some(entity => entity.name === "data/components.json")).toBe( - true - ); - expect(result.some(entity => entity.name === "data/fonts.json")).toBe(true); - expect(result.some(entity => entity.name === "data/docs.json")).toBe(true); - - const tokens = result.find(entity => entity.name === "data/tokens.json"); - const tokensEntities = JSON.parse(tokens?.value.content!).entities; - - expect(Array.isArray(tokensEntities)).toBe(true); - expect(tokensEntities.length).toBe(entitiesLength); - - const components = result.find( - entity => entity.name === "data/components.json" - ); - const componentsEntities = JSON.parse(components?.value.content!).entities; - - expect(Array.isArray(componentsEntities)).toBe(true); - expect(componentsEntities.length).toBe(0); - - const dsp = result.find(entity => entity.name === "dsp.json"); - const dspContent = JSON.parse(dsp?.value.content!); - - expect(dspContent.settings.name).toEqual(settings.name); - expect(dspContent.settings.build_status_label).toEqual( - settings.buildStatusLabel - ); - expect(dspContent.settings.package_version).toEqual("1.0.0"); - expect(dspContent.settings.snippet_trigger_prefix).toEqual( - settings.snippetTriggerPrefix - ); - }); - - it("should work with missing snipperTriggerPrefix setting", async () => { - const settings: DspParserSettings = { - name: "My DSP", - buildStatusLabel: "test", - packageVersion: "0.0.1", - }; - - const tokenSeeds = seeds().tokens as Array; - const result = await toDsp( - tokenSeeds, - { settings } as OptionsType, - libs as LibsType - ); - expect(Array.isArray(result)).toBe(true); - expect(result.length).toBe( - tokenSeeds.filter(({ type }) => type === "vector" || type === "bitmap") - .length + 5 - ); - expect(result.some(entity => entity.name === "dsp.json")).toBe(true); - expect(result.some(entity => entity.name === "data/tokens.json")).toBe( - true - ); - expect(result.some(entity => entity.name === "data/components.json")).toBe( - true - ); - expect(result.some(entity => entity.name === "data/fonts.json")).toBe(true); - expect(result.some(entity => entity.name === "data/docs.json")).toBe(true); - - const tokens = result.find(entity => entity.name === "data/tokens.json"); - const tokensEntities = JSON.parse(tokens?.value.content!).entities; - - expect(Array.isArray(tokensEntities)).toBe(true); - expect(tokensEntities.length).toBe(entitiesLength); - - const components = result.find( - entity => entity.name === "data/components.json" - ); - const componentsEntities = JSON.parse(components?.value.content!).entities; - - expect(Array.isArray(componentsEntities)).toBe(true); - expect(componentsEntities.length).toBe(0); - - const dsp = result.find(entity => entity.name === "dsp.json"); - const dspContent = JSON.parse(dsp?.value.content!); - - expect(dspContent.settings.name).toEqual(settings.name); - expect(dspContent.settings.build_status_label).toEqual( - settings.buildStatusLabel - ); - expect(dspContent.settings.package_version).toEqual( - settings.packageVersion - ); - expect(dspContent.settings.snippet_trigger_prefix).toEqual("sp-"); - }); - - it("should not create assets if asked so", async () => { - const settings: DspParserSettings = { - name: "My DSP", - buildStatusLabel: "test", - packageVersion: "0.0.1", - snippetTriggerPrefix: "ex-", - }; - - const result = await toDsp( - seeds().tokens as Array, - { settings, createAssets: false } as OptionsType, - libs as LibsType - ); - expect(Array.isArray(result)).toBe(true); - expect(result.length).toBe(5); - expect(result.some(entity => entity.name === "dsp.json")).toBe(true); - expect(result.some(entity => entity.name === "data/tokens.json")).toBe( - true - ); - expect(result.some(entity => entity.name === "data/components.json")).toBe( - true - ); - expect(result.some(entity => entity.name === "data/fonts.json")).toBe(true); - expect(result.some(entity => entity.name === "data/docs.json")).toBe(true); - - const tokens = result.find(entity => entity.name === "data/tokens.json"); - const tokensEntities = JSON.parse(tokens?.value.content!).entities; - - expect(Array.isArray(tokensEntities)).toBe(true); - expect(tokensEntities.length).toBe(entitiesLength); - - const components = result.find( - entity => entity.name === "data/components.json" - ); - const componentsEntities = JSON.parse(components?.value.content!).entities; - - expect(Array.isArray(componentsEntities)).toBe(true); - expect(componentsEntities.length).toBe(0); - - const dsp = result.find(entity => entity.name === "dsp.json"); - const dspContent = JSON.parse(dsp?.value.content!); - - expect(dspContent.settings.name).toEqual(settings.name); - expect(dspContent.settings.build_status_label).toEqual( - settings.buildStatusLabel - ); - expect(dspContent.settings.package_version).toEqual( - settings.packageVersion - ); - expect(dspContent.settings.snippet_trigger_prefix).toEqual( - settings.snippetTriggerPrefix - ); - }); - - it("should create assets with true value", async () => { - const settings: DspParserSettings = { - name: "My DSP", - buildStatusLabel: "test", - packageVersion: "0.0.1", - snippetTriggerPrefix: "ex-", - }; - - const tokenSeeds = seeds().tokens as Array; - const result = await toDsp( - tokenSeeds, - { settings, createAssets: true } as OptionsType, - libs as LibsType - ); - expect(Array.isArray(result)).toBe(true); - expect(result.length).toBe( - tokenSeeds.filter(({ type }) => type === "vector" || type === "bitmap") - .length + 5 - ); - expect(result.some(entity => entity.name === "dsp.json")).toBe(true); - expect(result.some(entity => entity.name === "data/tokens.json")).toBe( - true - ); - expect(result.some(entity => entity.name === "data/components.json")).toBe( - true - ); - expect(result.some(entity => entity.name === "data/fonts.json")).toBe(true); - expect(result.some(entity => entity.name === "data/docs.json")).toBe(true); - - const tokens = result.find(entity => entity.name === "data/tokens.json"); - const tokensEntities = JSON.parse(tokens?.value.content!).entities; - - expect(Array.isArray(tokensEntities)).toBe(true); - expect(tokensEntities.length).toBe(entitiesLength); - - const components = result.find( - entity => entity.name === "data/components.json" - ); - const componentsEntities = JSON.parse(components?.value.content!).entities; - - expect(Array.isArray(componentsEntities)).toBe(true); - expect(componentsEntities.length).toBe(0); - - const dsp = result.find(entity => entity.name === "dsp.json"); - const dspContent = JSON.parse(dsp?.value.content!); - - expect(dspContent.settings.name).toEqual(settings.name); - expect(dspContent.settings.build_status_label).toEqual( - settings.buildStatusLabel - ); - expect(dspContent.settings.package_version).toEqual( - settings.packageVersion - ); - expect(dspContent.settings.snippet_trigger_prefix).toEqual( - settings.snippetTriggerPrefix - ); - }); -}); diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-dsp/tokens/bitmap.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-dsp/tokens/bitmap.ts deleted file mode 100644 index 064b4c26e..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-dsp/tokens/bitmap.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { BitmapToken, DownloadableFile } from "../../../types"; -import { DspEntity } from "../dsp.type"; - -export class Bitmap extends BitmapToken { - constructor(token: Partial) { - super(token); - } - - toDsp(): DspEntity { - return { - class: "token", - type: "custom", - id: this.id!, - name: this.name, - value: `assets/${this.name}`, - tags: ["specify", "bitmap"], - }; - } - - async toDspAssets(): Promise { - return { - name: `assets/${this.name}`, - value: { - url: this.value.url, - }, - }; - } -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-dsp/tokens/border.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-dsp/tokens/border.ts deleted file mode 100644 index a6f8e24d1..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-dsp/tokens/border.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { BorderToken } from "../../../types"; -import { DspEntity } from "../dsp.type"; - -export class Border extends BorderToken { - constructor(token: Partial) { - super(token); - } - - toDsp(): DspEntity { - const { color, type, width } = this.value; - const { measure, unit } = width.value; - const { r, g, b, a } = color.value; - - return { - class: "token", - type: "custom", - id: this.id!, - name: this.name, - value: `${measure}${unit} ${type} rgba(${r}, ${g}, ${b}, ${a})`, - tags: ["specify", "border"], - }; - } -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-dsp/tokens/color.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-dsp/tokens/color.ts deleted file mode 100644 index 68f81ba31..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-dsp/tokens/color.ts +++ /dev/null @@ -1,19 +0,0 @@ -import tinycolor from "tinycolor2"; -import { ColorToken } from "../../../types"; -import { DspEntity } from "../dsp.type"; - -export class Color extends ColorToken { - constructor(token: Partial) { - super(token); - } - toDsp(): DspEntity { - return { - class: "token", - type: "color", - id: this.id!, - name: this.name, - value: tinycolor(this.value).toString("hex8"), - tags: ["specify", "color"], - }; - } -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-dsp/tokens/depth.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-dsp/tokens/depth.ts deleted file mode 100644 index 0aa1c708e..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-dsp/tokens/depth.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { DepthToken } from "../../../types"; -import { DspEntity } from "../dsp.type"; - -export class Depth extends DepthToken { - constructor(token: Partial) { - super(token); - } - - toDsp(): DspEntity { - return { - class: "token", - type: "color", - id: this.id!, - name: this.name, - value: `${this.value.depth}`, - tags: ["specify", "depth"], - }; - } -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-dsp/tokens/duration.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-dsp/tokens/duration.ts deleted file mode 100644 index 1874e98f4..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-dsp/tokens/duration.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { DurationToken } from "../../../types"; -import { DspEntity } from "../dsp.type"; - -export class Duration extends DurationToken { - constructor(token: Partial) { - super(token); - } - - toDsp(): DspEntity { - const { duration, unit } = this.value; - - return { - class: "token", - type: "color", - id: this.id!, - name: this.name, - value: `${duration}${unit}`, - tags: ["specify", "duration"], - }; - } -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-dsp/tokens/gradient.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-dsp/tokens/gradient.ts deleted file mode 100644 index b810de742..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-dsp/tokens/gradient.ts +++ /dev/null @@ -1,31 +0,0 @@ -import tinycolor from "tinycolor2"; -import { GradientToken } from "../../../types"; -import { DspEntity } from "../dsp.type"; - -export class Gradient extends GradientToken { - constructor(token: Partial) { - super(token); - } - - toDsp(): DspEntity { - const value = this.value.gradients - .map(gradient => { - return `linear-gradient(${gradient.angle}, ${gradient.colors - .map( - ({ color, position }) => - `${tinycolor(color.value).toString("rgb")} ${position}%)` - ) - .join(", ")}`; - }) - .join(", "); - - return { - class: "token", - type: "custom", - id: this.id!, - name: this.name, - value, - tags: ["specify", "gradient"], - }; - } -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-dsp/tokens/index.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-dsp/tokens/index.ts deleted file mode 100644 index a41731f86..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-dsp/tokens/index.ts +++ /dev/null @@ -1,10 +0,0 @@ -export * from "./bitmap"; -export * from "./color"; -export * from "./gradient"; -export * from "./shadow"; -export * from "./vector"; -export * from "./opacity"; -export * from "./depth"; -export * from "./duration"; -export * from "./border"; -export * from "./measurement"; diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-dsp/tokens/measurement.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-dsp/tokens/measurement.ts deleted file mode 100644 index e42f35b3e..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-dsp/tokens/measurement.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { MeasurementToken } from "../../../types"; -import { DspEntity } from "../dsp.type"; - -export class Measurement extends MeasurementToken { - constructor(token: Partial) { - super(token); - } - toDsp(): DspEntity { - return { - class: "token", - type: "size", - id: this.id!, - name: this.name, - value: `${this.value.measure}${this.value.unit}`, - tags: ["specify", "measurement"], - }; - } -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-dsp/tokens/opacity.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-dsp/tokens/opacity.ts deleted file mode 100644 index 9c783d79c..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-dsp/tokens/opacity.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { OpacityToken } from "../../../types"; -import { DspEntity } from "../dsp.type"; - -export class Opacity extends OpacityToken { - constructor(token: Partial) { - super(token); - } - toDsp(): DspEntity { - return { - class: "token", - type: "custom", - id: this.id!, - name: this.name, - value: `${this.value.opacity / 100}`, - tags: ["specify", "opacity"], - }; - } -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-dsp/tokens/shadow.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-dsp/tokens/shadow.ts deleted file mode 100644 index ee9c001f3..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-dsp/tokens/shadow.ts +++ /dev/null @@ -1,36 +0,0 @@ -import { ShadowToken } from "../../../types"; -import { DspEntity } from "../dsp.type"; - -export class Shadow extends ShadowToken { - constructor(token: Partial) { - super(token); - } - - toDsp(): DspEntity { - const value = this.value.reduce((acc, shadow) => { - const { color, offsetX, offsetY, blur, isInner, spread } = shadow; - const xString = `${offsetX.value.measure}${offsetX.value.unit}`; - const yString = `${offsetY.value.measure}${offsetY.value.unit}`; - const blurString = `${blur.value.measure}${blur.value.unit}`; - const spreadString = spread - ? `${spread.value.measure}${spread.value.unit}` - : ""; - const { r, g, b, a } = color.value; - const innerText = isInner ? "inset" : ""; - if (acc === "") { - return `${innerText} ${xString} ${yString} ${blurString} ${spreadString} rgba(${r},${g},${b},${a})`; - } - - return `${acc}, ${innerText} ${xString} ${yString} ${blurString} ${spreadString} rgba(${r},${g},${b},${a})`; - }, ""); - - return { - class: "token", - type: "custom", - id: this.id!, - name: this.name, - value, - tags: ["specify", "shadow"], - }; - } -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-dsp/tokens/vector.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-dsp/tokens/vector.ts deleted file mode 100644 index 9a30159e0..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-dsp/tokens/vector.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { DownloadableFile, VectorToken } from "../../../types"; -import { DspEntity } from "../dsp.type"; -import { LibsType } from "../../global-libs"; - -export class Vector extends VectorToken { - constructor(token: Partial) { - super(token); - } - - toDsp(): DspEntity { - return { - class: "token", - type: "custom", - id: this.id!, - name: this.name, - value: `assets/${this.name}`, - tags: ["specify", "vector"], - }; - } - - async toDspAssets( - SpServices: LibsType["SpServices"] - ): Promise { - const response = - this.value.content || - (await SpServices.assets.getSource(this.value.url!, "text")); - - return { - name: `assets/${this.name}`, - value: { - content: response, - }, - }; - } -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-jss/README.md b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-jss/README.md deleted file mode 100644 index 69943f349..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-jss/README.md +++ /dev/null @@ -1,222 +0,0 @@ -# To JSS - -## Description - -This parser helps you transform design tokens in JSS. - -Learn more about how to configure Specify in the API documentation: [https://specifyapp.com/developers](https://specifyapp.com/developers). - -**Supported JSS syntax**: - -- [Basic syntax](https://cssinjs.org/jss-syntax?v=v10.4.0#basic-syntax) [_string_] (default) - -```js -primaryBorder: '1px solid #55ff55', -``` - -- [Alternative syntax for space and comma separated values](https://cssinjs.org/jss-syntax?v=v10.4.0#alternative-syntax-for-space-and-comma-separated-values) [_array_] - -```js -primaryBorder: [1, 'solid', '#55ff55'], -``` - -- [jss-plugin-expand syntax](https://cssinjs.org/jss-plugin-expand?v=v10.4.0#better-syntax-for-complex-properties) [_object_] - -```js -primaryBorder: { - width: 1, - type: 'solid', - color: '#55ff55' -}, -``` - -### Optionnal format for font - -By passing `"classObject"` to `textStyleFormat` the parser will generate a jss class object containing the `color` and `letter-spacing` properties (which aren't `font`'s sub-properties). - -## Interface - -```ts -interface parser { - name: "to-jss"; - options?: Partial<{ - formatName: "camelCase" | "kebabCase" | "snakeCase" | "pascalCase"; - formatTokens: Partial<{ - colorFormat: - | "rgb" - | "prgb" - | "hex" - | "hex6" - | "hex3" - | "hex4" - | "hex8" - | "name" - | "hsl" - | "hsv"; - borderFormat: "string" | "array" | "object"; - durationFormat: "string" | "number"; - opacityFormat: "string" | "number"; - depthFormat: "string" | "number"; - measurementFormat: "string" | "number"; - shadowFormat: "string" | "array" | "object"; - gradientFormat: "string" | "array"; - textStyleFormat: "string" | "array" | "object" | "classObject"; - fontSizeUnit: "px" | "pt"; - }>; - formatConfig: Partial<{ - jssObjectName: string; - exportDefault: boolean; - endOfLine: "auto" | "lf" | "crlf" | "cr"; - tabWidth: number; - useTabs: boolean; - singleQuote: boolean; - assetsFolderPath?: string | { vector?: string; bitmap?: string }; - assetsFilePattern?: string; - }>; - }>; -} -``` - -## Types - -โ„น๏ธ **Please be aware that, depending on the order you use parsers, their input and output types have to match.** - -### Input - -Array of object with at least name, value and type - -```ts -type input = Array<{ name: string; value: any; type: string }>; -``` - -### Output - -String formated in jss - -```ts -type output = string; -``` - -## Usage - -### Config - -```jsonc -"parsers": [ - { - "name": "to-jss", - "options": { - "formatName": "camelCase", - "formatTokens":{ - "colorFormat": "hex8", - "textStyleFormat": "classObject", - "fontSizeUnit": "px" - }, - "formatConfig": { - "jssObjectName": "lightTheme", - "exportDefault": false, - "tabWidth": 4, - "singleQuote": true - } - } - } - // โ€ฆ -] -``` - -### Before/After - -#### Input - -```js -[ - { - name: "activity.svg", - value: { - url: "https://s3-us-west-2.amazonaws.com/figma-alpha-api/img/a114/ce5c/947dcb83ea93c2da18ee2ea16f470a30", - }, - type: "vector", - }, - { - name: "Body", - value: { - font: { - meta: { - source: "localStyles", - }, - name: "Inter-Medium", - type: "font", - value: { - isItalic: false, - fontFamily: "Inter", - fontWeight: 500, - fontPostScriptName: "Inter-Medium", - }, - }, - color: { - value: { - a: 1, - b: 196, - g: 196, - r: 196, - }, - }, - fontSize: { - value: { - unit: "px", - measure: 14, - }, - }, - textAlign: { - vertical: "top", - horizontal: "left", - }, - lineHeight: { - value: { - unit: "px", - measure: 20, - }, - }, - }, - type: "textStyle", - }, - { - name: "Colors / Accent", - value: { - a: 1, - b: 239, - g: 80, - r: 102, - }, - type: "color", - }, -]; -``` - -#### Output - -```js -export const lightTheme = { - vector: { - activity: - "https://s3-us-west-2.amazonaws.com/figma-alpha-api/img/96dc/8825/c166b559140a0a64b28441924700a0b2", - }, - textStyle: { - body: { - color: "#1e212bff", - font: { - style: null, - variant: null, - weight: 500, - size: 14, - lineHeight: 20, - family: "Inter-Medium", - }, - letterSpacing: 10, - }, - }, - color: { - colorsAccent: "#577cfeff", - }, -}; -``` diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-jss/to-jss.parser.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-jss/to-jss.parser.ts deleted file mode 100644 index df935b1c7..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-jss/to-jss.parser.ts +++ /dev/null @@ -1,128 +0,0 @@ -import prettier from "prettier"; -import Template from "../../libs/template"; -import { IToken, Token } from "../../types"; -import { LibsType } from "../global-libs"; -import * as TokensClass from "./tokens"; - -export type InputDataType = Array< - Pick & Record ->; -export type OutputDataType = string; -export type ColorsFormat = - | "rgb" - | "prgb" - | "hex" - | "hex6" - | "hex3" - | "hex4" - | "hex8" - | "name" - | "hsl" - | "hsv"; -export type BorderFormat = "string" | "array" | "object"; -export type DurationFormat = "string" | "number"; -export type OpacityFormat = "string" | "number"; -export type DepthFormat = "string" | "number"; -export type MeasurementFormat = "string" | "number"; -export type ShadowFormat = "string" | "array" | "object"; -export type GradientFormat = "string" | "array"; -export type TextStyleFormat = "string" | "array" | "object" | "classObject"; -export type FontSizeUnit = "px" | "pt"; - -export type FormatTokenType = Partial<{ - colorFormat: ColorsFormat; - borderFormat: BorderFormat; - durationFormat: DurationFormat; - depthFormat: DepthFormat; - shadowFormat: ShadowFormat; - opacityFormat: OpacityFormat; - measurementFormat: MeasurementFormat; - gradientFormat: GradientFormat; - textStyleFormat: TextStyleFormat; - fontSizeUnit: FontSizeUnit; -}>; - -export type FormatConfigType = Partial<{ - module: "es6" | "commonjs"; - jssObjectName: string; - endOfLine: "auto" | "lf" | "crlf" | "cr"; - tabWidth: number; - useTabs: boolean; - singleQuote: boolean; - exportDefault: boolean; - assetsFolderPath?: string | { vector?: string; bitmap?: string }; - assetsFilePattern?: string; -}>; - -export type OptionsType = - | Partial<{ - formatName: "camelCase" | "kebabCase" | "snakeCase" | "pascalCase"; - formatTokens: FormatTokenType; - formatConfig: FormatConfigType; - }> - | undefined; - -export default async function ( - tokens: InputDataType, - options: OptionsType, - { _ }: Pick -): Promise { - const transformNameFn = _[options?.formatName || "camelCase"]; - const objectName = options?.formatConfig?.jssObjectName || "theme"; - const exportDefault = options?.formatConfig?.exportDefault ?? true; - const module = options?.formatConfig?.module ?? "es6"; - const pattern = - options?.formatConfig?.assetsFilePattern ?? - "{{name}}{{#dimension}}@{{dimension}}x{{/dimension}}{{#format}}.{{format}}{{/format}}"; - const tokensGroupByType = _.groupBy(tokens, "type"); - const template = new Template(pattern); - const styles = Object.keys(tokensGroupByType).reduce((result, type) => { - const content = tokensGroupByType[type] - .map((token: Pick) => { - const tokenClassName = `${ - token.type.charAt(0).toUpperCase() + token.type.slice(1) - }`; - - if (!(TokensClass)[tokenClassName]) return undefined; - const instance = new (TokensClass)[tokenClassName](token); - - token.name = - options?.formatName || - token.name.includes(" ") || - token.name.includes("\n") || - token.name.includes("/") - ? transformNameFn(token.name) - : token.name; - - const fileName = - token.type === "vector" || token.type === "bitmap" - ? template.render(token) - : null; - return `'${token.name}': ${instance.toJss( - { ...options?.formatTokens }, - { ...options?.formatConfig }, - fileName - )},`; - }) - .join(""); - result += `'${transformNameFn(type)}': {${content}},`; - return result; - }, ""); - - return prettier.format( - (() => { - if (module === "es6" && exportDefault) - return `const ${objectName} = {${styles}} ${`;\n\nexport default ${objectName};`}`; - else if (module === "es6" && !exportDefault) - return `export const ${objectName} = {${styles}};`; - else if (module === "commonjs" && exportDefault) - return `const ${objectName} = {${styles}}; ${`\n\nmodule.exports = ${objectName};`}`; - else - return `const ${objectName} = {${styles}}; ${`\n\nmodule.exports = {${objectName}};`}`; - })(), - { - ...options?.formatConfig, - parser: "babel", - } - ); -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-jss/to-jss.spec.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-jss/to-jss.spec.ts deleted file mode 100644 index e6334d6b3..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-jss/to-jss.spec.ts +++ /dev/null @@ -1,425 +0,0 @@ -import libs from "../global-libs"; -import seeds from "../../tests/seeds"; -import toJss, { OptionsType } from "./to-jss.parser"; -import { - ColorToken, - ColorValue, - Shadow, - ShadowToken, - Token, - MeasurementToken, - BorderToken, - DepthToken, - OpacityToken, - DurationToken, - BitmapToken, - VectorToken, -} from "../../types"; -import tinycolor from "tinycolor2"; -import path from "path"; - -describe("To jss", () => { - it("Get tokens - apply parsers", async () => { - const result = await toJss( - seeds().tokens as Array, - { formatName: "camelCase" }, - libs - ); - expect(typeof result).toEqual("string"); - const color = seeds().tokens.find(token => token.type === "color") as Token; - const measurement = seeds().tokens.find( - token => token.type === "measurement" - ) as MeasurementToken; - const shadow = seeds().tokens.find( - token => token.type === "shadow" - ) as ShadowToken; - - const shadowValue = shadow.value.reduce((acc: string, value: Shadow) => { - const { color, offsetX, offsetY, blur, isInner } = value; - const x = offsetX.value; - const y = offsetY.value; - const bl = blur.value; - const { r, g, b, a } = color.value; - const innerText = isInner ? "inset " : ""; - if (acc === "") { - return `${innerText}${x.measure}${x.unit} ${y.measure}${y.unit} ${bl.measure}${bl.unit} rgba(${r}, ${g}, ${b}, ${a})`; - } - - return `${acc}, ${innerText}${x.measure}${x.unit} ${y.measure}${y.unit} ${bl.measure}${bl.unit} rgba(${r}, ${g}, ${b}, ${a})`; - }, ""); - - expect( - result.includes( - `${libs._.camelCase(color.name)}: "${libs - .tinycolor(color.value as ColorValue) - .toString("rgb")}",` - ) - ).toBe(true); - expect( - result.includes(`${libs._.camelCase(shadow.name)}: "${shadowValue}",`) - ).toBe(true); - expect( - result.includes( - `${libs._.camelCase(measurement.name)}: "${measurement.value.measure}${ - measurement.value.unit - }",` - ) - ).toBe(true); - return; - }); - - it("Get tokens - apply parsers - with snakeCase formatName options", async () => { - const options: OptionsType = { - formatName: "snakeCase"!, - formatTokens: { colorFormat: "hsl" }, - }; - const result = await toJss(seeds().tokens as Array, options, libs); - const color = seeds().tokens.find( - token => token.type === "color" - ) as ColorToken; - const measurement = seeds().tokens.find( - token => token.type === "measurement" - ) as MeasurementToken; - - const fnFormatColor = libs._[options.formatName!](color.name); - expect( - result.includes( - `${fnFormatColor}: "${libs - .tinycolor(color.value as ColorValue) - .toString(options.formatTokens?.colorFormat)}",` - ) - ).toBe(true); - - const fnFormatMeasurement = libs._[options.formatName!](measurement.name); - expect( - result.includes( - `${fnFormatMeasurement}: "${measurement.value.measure}${measurement.value.unit}",` - ) - ).toBe(true); - return; - }); - - it("Get tokens - apply parsers - with custom jssObjectName", async () => { - const options: OptionsType = { - formatName: "snakeCase"!, - formatTokens: { colorFormat: "hsl" }, - formatConfig: { - jssObjectName: "lightTheme", - }, - }; - const result = await toJss(seeds().tokens as Array, options, libs); - const color = seeds().tokens.find( - token => token.type === "color" - ) as ColorToken; - const measurement = seeds().tokens.find( - token => token.type === "measurement" - ) as MeasurementToken; - - const fnFormatColor = libs._[options.formatName!](color.name); - expect( - result.includes( - `${fnFormatColor}: "${libs - .tinycolor(color.value as ColorValue) - .toString(options.formatTokens?.colorFormat)}",` - ) - ).toBe(true); - - const fnFormatMeasurement = libs._[options.formatName!](measurement.name); - expect( - result.includes( - `${fnFormatMeasurement}: "${measurement.value.measure}${measurement.value.unit}",` - ) - ).toBe(true); - expect(result.includes(`${options.formatConfig!.jssObjectName}`)).toBe( - true - ); - return; - }); - - it("Get tokens - apply parsers - without custom jssObjectName", async () => { - const options: OptionsType = { - formatName: "snakeCase"!, - formatTokens: { colorFormat: "hsl" }, - }; - const result = await toJss(seeds().tokens as Array, options, libs); - const color = seeds().tokens.find( - token => token.type === "color" - ) as ColorToken; - const measurement = seeds().tokens.find( - token => token.type === "measurement" - ) as MeasurementToken; - - const fnFormatColor = libs._[options.formatName!](color.name); - expect( - result.includes( - `${fnFormatColor}: ${libs - .tinycolor(color.value as ColorValue) - .toString(options.formatTokens?.colorFormat)}` - ) - ); - - const fnFormatMeasurement = libs._[options.formatName!](measurement.name); - expect( - result.includes( - `${fnFormatMeasurement}: "${measurement.value.measure}${measurement.value.unit}",` - ) - ).toBe(true); - expect(result.includes(`const theme = {`)).toBe(true); - return; - }); - - it("Get tokens - apply parsers - with camelCase", async () => { - const options: OptionsType = { - formatName: "camelCase"!, - formatTokens: { colorFormat: "hsl" }, - }; - const result = await toJss(seeds().tokens as Array, options, libs); - const color = seeds().tokens.find( - token => token.type === "color" - ) as ColorToken; - const measurement = seeds().tokens.find( - token => token.type === "measurement" - ) as MeasurementToken; - - const fnFormatColor = libs._[options.formatName!](color.name); - expect( - result.includes( - `${fnFormatColor}: "${libs - .tinycolor(color.value as ColorValue) - .toString(options.formatTokens?.colorFormat)}",` - ) - ).toBe(true); - - const fnFormatName = libs._.camelCase; - expect( - result.includes( - `${fnFormatName(measurement.name)}: "${measurement.value.measure}${ - measurement.value.unit - }",` - ) - ).toBe(true); - expect(result.includes(`const theme = {`)).toBe(true); - return; - }); - - it("Get tokens - apply parsers - with values format options", async () => { - const options: OptionsType = { - formatName: "camelCase", - formatTokens: { - borderFormat: "array", - }, - }; - const result = await toJss(seeds().tokens as Array, options, libs); - - const border = seeds().tokens.find( - token => token.type === "border" - ) as BorderToken; - const xBorderWidth = border.value.width.value.measure; - const xBorderType = border.value.type.toLowerCase(); - const xBorderColor = tinycolor(border.value.color.value).toString( - options.formatTokens?.colorFormat - ); - const xBorder = `${libs._.camelCase( - border.name - )}: [${xBorderWidth}, "${xBorderType}", "${xBorderColor}"],`; - expect(result.includes(xBorder)).toBe(true); - - return; - }); - - it("Module Format - es6 - export default", async () => { - const jssObjectName = "moduleTheme"; - - const options: OptionsType = { - formatConfig: { exportDefault: true, jssObjectName }, - }; - - const result = await toJss(seeds().tokens as Array, options, libs); - - expect(result.includes(`export default ${jssObjectName}`)).toBeTruthy(); - expect(result.includes(`export const ${jssObjectName}`)).toBeFalsy(); - expect(result.includes("module.exports")).toBeFalsy(); - }); - - it("Module Format - es6", async () => { - const jssObjectName = "moduleTheme"; - - const options: OptionsType = { - formatConfig: { exportDefault: false, jssObjectName }, - }; - - const result = await toJss(seeds().tokens as Array, options, libs); - - expect(result.includes(`export default ${jssObjectName}`)).toBeFalsy(); - expect(result.includes(`export const ${jssObjectName}`)).toBeTruthy(); - expect(result.includes("module.exports")).toBeFalsy(); - }); - - it("Module Format - commonjs - export default ", async () => { - const jssObjectName = "moduleTheme"; - - const options: OptionsType = { - formatConfig: { module: "commonjs", exportDefault: true, jssObjectName }, - }; - - const result = await toJss(seeds().tokens as Array, options, libs); - - expect(result.includes(`export default ${jssObjectName}`)).toBeFalsy(); - expect(result.includes(`export const ${jssObjectName}`)).toBeFalsy(); - expect(result.includes(`module.exports = ${jssObjectName}`)).toBeTruthy(); - }); - - it("Module Format - commonjs", async () => { - const jssObjectName = "moduleTheme"; - - const options: OptionsType = { - formatConfig: { module: "commonjs", exportDefault: false, jssObjectName }, - }; - - const result = await toJss(seeds().tokens as Array, options, libs); - expect(result.includes(`export default ${jssObjectName}`)).toBeFalsy(); - expect(result.includes(`export const ${jssObjectName}`)).toBeFalsy(); - expect( - result.includes(`module.exports = { ${jssObjectName} }`) - ).toBeTruthy(); - }); - - it("Relative path with default pattern", async () => { - const options: OptionsType = { - formatConfig: { - assetsFolderPath: "assets/vector", - }, - }; - - const result = await toJss( - seeds().tokens.filter( - ({ type }) => type === "vector" || type === "bitmap" - ) as Array, - options, - libs - ); - - expect(result.includes("http://")).toBeFalsy(); - expect(result.includes("@2x.jpg")).toBeTruthy(); - }); - - it("Relative path with custom pattern", async () => { - const options: OptionsType = { - formatConfig: { - assetsFolderPath: "assets/vector", - assetsFilePattern: "{{name}}.{{format}}", - }, - }; - - const result = await toJss( - seeds().tokens.filter( - ({ type }) => type === "vector" || type === "bitmap" - ) as Array, - options, - libs - ); - - expect(result.includes("http://")).toBeFalsy(); - expect(result.includes("@2x.webp")).toBeFalsy(); - }); - - it("No assets folder path - type by tokens", async () => { - const options: OptionsType = { - formatName: "camelCase", - formatTokens: { - durationFormat: "number", - opacityFormat: "number", - measurementFormat: "number", - depthFormat: "number", - gradientFormat: "array", - shadowFormat: "array", - }, - }; - const tokens = seeds().tokens; - - const result = await toJss(tokens, options, libs); - tokens.forEach(token => { - if (token.type === "depth") { - expect( - result.includes( - `${token.name}: ${(token.value as DepthToken["value"]).depth}` - ) - ).toBeTruthy(); - } else if (token.type === "measurement") { - expect( - result.includes( - `${token.name}: ${ - (token.value as MeasurementToken["value"]).measure - }` - ) - ).toBeTruthy(); - } else if (token.type === "opacity") { - expect( - result.includes( - `${token.name}: ${ - (token.value as OpacityToken["value"]).opacity / 100 - }` - ) - ).toBeTruthy(); - } else if (token.type === "duration") { - expect( - result.includes( - `${token.name}: ${(token.value as DurationToken["value"]).duration}` - ) - ).toBeTruthy(); - } else if (token.type === "gradient" || token.type === "shadow") { - const arrayReg = new RegExp(`${token.name}: \\[`); - expect(result).toEqual(expect.stringMatching(arrayReg)); - } - }); - }); - - it("Define assets folder path by type", async () => { - const assetsFolderPath = { bitmap: "bitmap/", vector: "vector/" }; - const options: OptionsType = { - formatName: "camelCase", - formatConfig: { - assetsFilePattern: "{{name}}.{{format}}", - assetsFolderPath, - }, - }; - const tokens = seeds().tokens.filter( - ({ type }) => type === "bitmap" || type === "vector" - ); - - const result = await toJss(tokens, options, libs); - tokens.forEach(token => { - if (token.type === "bitmap") { - const bitmap = token as BitmapToken; - expect( - result.includes( - `${libs._.camelCase(bitmap.name)}: "${path.join( - assetsFolderPath.bitmap, - `${libs._.camelCase(bitmap.name)}.${bitmap.value.format}"` - )}` - ) - ).toBeTruthy(); - } else { - const vector = token as VectorToken; - expect( - result.includes( - `${libs._.camelCase(vector.name)}: "${path.join( - assetsFolderPath.vector, - `${libs._.camelCase(vector.name)}.${vector.value.format}"` - )}` - ) - ).toBeTruthy(); - } - }); - }); - - it("Enclose text-style object key in quote to be valid with js syntax", async () => { - const options: OptionsType = { - formatName: "kebabCase", - }; - const tokens = seeds().tokens.filter(({ type }) => type === "textStyle"); - - const result = await toJss(tokens, options, libs); - expect(result).toContain('"text-style"'); - }); -}); diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-jss/tokens/bitmap.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-jss/tokens/bitmap.ts deleted file mode 100644 index 655fc7ba3..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-jss/tokens/bitmap.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { BitmapToken } from "../../../types"; -import path from "path"; -import { FormatConfigType, FormatTokenType } from "../to-jss.parser"; - -export class Bitmap extends BitmapToken { - constructor(token: Partial) { - super(token); - } - - toJss( - formatTokens: FormatTokenType, - formatConfig: FormatConfigType, - fileName: string - ): string { - if (!formatConfig?.assetsFolderPath) return `'${this.value.url}'`; - const relPath = - typeof formatConfig.assetsFolderPath === "string" - ? formatConfig.assetsFolderPath - : formatConfig.assetsFolderPath!.bitmap; - return `'${path.join(relPath || "", fileName)}'`; - } -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-jss/tokens/border.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-jss/tokens/border.ts deleted file mode 100644 index c2068d499..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-jss/tokens/border.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { BorderToken } from "../../../types"; -import { FormatTokenType } from "../to-jss.parser"; -import tinycolor from "tinycolor2"; - -export class Border extends BorderToken { - constructor(token: Partial) { - super(token); - } - - toJss({ borderFormat = "string", colorFormat = "rgb" }: FormatTokenType) { - const { color, type, width } = this.value; - const { measure, unit } = width.value; - if (borderFormat === "object") - return JSON.stringify({ - width: measure, - style: type.toLowerCase(), - color: tinycolor(color.value).toString(colorFormat), - }); - else if (borderFormat === "array") - return JSON.stringify([ - measure, - type.toLowerCase(), - tinycolor(color.value).toString(colorFormat), - ]); - else - return `'${measure}${unit} ${type.toLowerCase()} ${tinycolor( - color.value - ).toString(colorFormat)}'`; - } -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-jss/tokens/color.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-jss/tokens/color.ts deleted file mode 100644 index 0a8eb8e79..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-jss/tokens/color.ts +++ /dev/null @@ -1,12 +0,0 @@ -import tinycolor from "tinycolor2"; -import { FormatTokenType } from "../to-jss.parser"; -import { ColorToken } from "../../../types"; - -export class Color extends ColorToken { - constructor(token: Partial) { - super(token); - } - toJss({ colorFormat = "rgb" }: FormatTokenType): string { - return `'${tinycolor(this.value).toString(colorFormat)}'`; - } -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-jss/tokens/depth.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-jss/tokens/depth.ts deleted file mode 100644 index 3d56f4f45..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-jss/tokens/depth.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { DepthToken } from "../../../types"; -import { FormatTokenType } from "../to-jss.parser"; - -export class Depth extends DepthToken { - constructor(token: Partial) { - super(token); - } - - toJss({ depthFormat = "string" }: FormatTokenType) { - return depthFormat === "number" - ? this.value.depth - : `'${this.value.depth}'`; - } -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-jss/tokens/duration.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-jss/tokens/duration.ts deleted file mode 100644 index 919fec4a5..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-jss/tokens/duration.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { DurationToken } from "../../../types"; -import { FormatTokenType } from "../to-jss.parser"; - -export class Duration extends DurationToken { - constructor(token: Partial) { - super(token); - } - - toJss({ durationFormat = "string" }: FormatTokenType) { - const { duration, unit } = this.value; - return durationFormat === "number" ? duration : `'${duration}${unit}'`; - } -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-jss/tokens/font.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-jss/tokens/font.ts deleted file mode 100644 index f7448a335..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-jss/tokens/font.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { FontToken } from "../../../types"; - -export class Font extends FontToken { - constructor(token: Partial) { - super(token); - } - toJss() { - return `'${this.value.fontPostScriptName}'`; - } -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-jss/tokens/gradient.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-jss/tokens/gradient.ts deleted file mode 100644 index e396194ec..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-jss/tokens/gradient.ts +++ /dev/null @@ -1,22 +0,0 @@ -import tinycolor from "tinycolor2"; -import { GradientToken, StepForGradient } from "../../../types"; -import { FormatTokenType } from "../to-jss.parser"; - -export class Gradient extends GradientToken { - constructor(token: Partial) { - super(token); - } - - toJss({ gradientFormat = "string" }: FormatTokenType) { - const getColorStop = ({ color, position }: StepForGradient) => - `${tinycolor(color.value).toString("rgb")} ${position}%`; - - const value: string = this.value.gradients - .map(gradient => { - const colorStops = gradient.colors.map(getColorStop).join(", "); - return `linear-gradient(${gradient.angle}, ${colorStops})`; - }) - .join(gradientFormat === "string" ? ", " : "', '"); - return gradientFormat === "string" ? `'${value}'` : `['${value}']`; - } -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-jss/tokens/index.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-jss/tokens/index.ts deleted file mode 100644 index 27c50d76a..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-jss/tokens/index.ts +++ /dev/null @@ -1,12 +0,0 @@ -export * from "./bitmap"; -export * from "./color"; -export * from "./gradient"; -export * from "./shadow"; -export * from "./textStyle"; -export * from "./vector"; -export * from "./opacity"; -export * from "./depth"; -export * from "./duration"; -export * from "./border"; -export * from "./measurement"; -export * from "./font"; diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-jss/tokens/measurement.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-jss/tokens/measurement.ts deleted file mode 100644 index 702d8be82..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-jss/tokens/measurement.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { MeasurementToken } from "../../../types"; -import { FormatTokenType } from "../to-jss.parser"; - -export class Measurement extends MeasurementToken { - constructor(token: Partial) { - super(token); - } - toJss({ measurementFormat = "string" }: FormatTokenType) { - return measurementFormat === "number" - ? this.value.measure - : `'${this.value.measure}${this.value.unit}'`; - } -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-jss/tokens/opacity.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-jss/tokens/opacity.ts deleted file mode 100644 index acc0c7c8e..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-jss/tokens/opacity.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { OpacityToken } from "../../../types"; -import { FormatTokenType } from "../to-jss.parser"; - -export class Opacity extends OpacityToken { - constructor(token: Partial) { - super(token); - } - toJss({ opacityFormat = "string" }: FormatTokenType) { - const value = this.value.opacity / 100; - return opacityFormat === "number" ? value : `'${value}'`; - } -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-jss/tokens/shadow.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-jss/tokens/shadow.ts deleted file mode 100644 index d59c5d72d..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-jss/tokens/shadow.ts +++ /dev/null @@ -1,73 +0,0 @@ -import { ShadowToken } from "../../../types"; -import { FormatTokenType } from "../to-jss.parser"; -import tinycolor from "tinycolor2"; - -export class Shadow extends ShadowToken { - constructor(token: Partial) { - super(token); - } - - toJss({ shadowFormat = "string", colorFormat = "rgb" }: FormatTokenType) { - return this.value.reduce((acc, shadow, idx, arr) => { - const { color, offsetX, offsetY, blur, isInner, spread } = shadow; - const x = offsetX.value; - const y = offsetY.value; - const bl = blur.value; - const innerText = isInner - ? { - string: "inset ", - array: "'inset', ", - object: "inset", - }[shadowFormat] - : ""; - const prepend = idx - ? { - string: acc + ", ", - array: acc + "], [", - object: acc + ", ", - }[shadowFormat] - : ""; - const before = !idx - ? { - string: "'", - array: "[[", - object: "[", - }[shadowFormat] - : ""; - const after = !arr[idx + 1] - ? { - string: "'", - array: "]]", - object: "]", - }[shadowFormat] - : ""; - - if (shadowFormat === "object") - return ( - before + - prepend + - JSON.stringify({ - x: x.measure, - y: y.measure, - blur: bl.measure, - spread: spread?.value || 0, - color: tinycolor(color.value).toString(colorFormat), - inset: innerText, - }) + - after - ); - else if (shadowFormat === "array") - return `${before}${prepend}${innerText}${x.measure}, ${y.measure}, ${ - bl.measure - }${spread ? `, ${spread.value.measure}` : ""},'${tinycolor( - color.value - ).toString(colorFormat)}'${after}`; - else - return `${before}${prepend}${innerText}${x.measure}${x.unit} ${ - y.measure - }${y.unit} ${bl.measure}${bl.unit}${ - spread ? ` ${spread.value.measure}${spread.value.unit}` : "" - } ${tinycolor(color.value).toString(colorFormat)}${after}`; - }, ""); - } -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-jss/tokens/textStyle.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-jss/tokens/textStyle.ts deleted file mode 100644 index 1bffb54d4..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-jss/tokens/textStyle.ts +++ /dev/null @@ -1,53 +0,0 @@ -import { TextStyleToken } from "../../../types"; -import { FormatTokenType } from "../to-jss.parser"; -import tinycolor from "tinycolor2"; - -export class TextStyle extends TextStyleToken { - constructor(token: Partial) { - super(token); - } - - toJss({ - textStyleFormat = "classObject", - colorFormat = "hex", - }: FormatTokenType) { - const { - font, - color: c, - fontSize: fs, - lineHeight: lh, - letterSpacing: ls, - } = this.value; - const { fontPostScriptName, fontWeight } = font.value; - const color = c?.value; - const { measure: fontSize, unit: fsUnit } = fs.value; - const { measure: letterSpacing } = ls?.value - ? ls.value - : { measure: "normal" }; - const { measure: lineHeight, unit: lhUnit } = lh?.value - ? lh.value - : { measure: "normal", unit: "px" }; - const fontObject = { - style: null, // TODO add font-style value to api results - variant: null, // TODO add font-variant value to api results - weight: fontWeight, - size: fontSize, - lineHeight: lineHeight, - family: fontPostScriptName, - }; - return { - object: JSON.stringify(fontObject), - classObject: JSON.stringify({ - color: tinycolor(color).toString(colorFormat), - font: fontObject, - letterSpacing: letterSpacing, - }), - array: JSON.stringify([ - fontWeight, - `${fontSize + fsUnit}/${lineHeight + lhUnit}`, - fontPostScriptName, - ]), - string: `'${fontWeight} ${fontSize}${fsUnit}/${lineHeight}${lhUnit} ${fontPostScriptName}'`, - }[textStyleFormat]; - } -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-jss/tokens/vector.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-jss/tokens/vector.ts deleted file mode 100644 index 94cbf9062..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-jss/tokens/vector.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { VectorToken } from "../../../types"; -import path from "path"; -import { FormatConfigType, FormatTokenType } from "../to-jss.parser"; - -export class Vector extends VectorToken { - constructor(token: Partial) { - super(token); - } - - toJss( - formatTokens: FormatTokenType, - formatConfig: FormatConfigType, - fileName: string - ): string { - if (!formatConfig?.assetsFolderPath) return `'${this.value.url}'`; - const relPath = - typeof formatConfig.assetsFolderPath === "string" - ? formatConfig.assetsFolderPath - : formatConfig.assetsFolderPath!.vector; - return `'${path.join(relPath || "", fileName)}'`; - } -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-react-native/README.md b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-react-native/README.md deleted file mode 100644 index ea588375c..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-react-native/README.md +++ /dev/null @@ -1,338 +0,0 @@ -# To React Native - -## Description - -This parser helps you transform design tokens to a JavaScript `theme` object compatible with [React Native](https://reactnative.dev/). - -Learn more about how to configure Specify in the API documentation: [https://specifyapp.com/developers](https://specifyapp.com/developers). - -## Interface - -```ts -interface parser { - name: "to-react-native"; - options?: Partial<{ - colorFormat?: - | "rgb" - | "prgb" - | "hex" - | "hex6" - | "hex3" - | "hex4" - | "hex8" - | "name" - | "hsl" - | "hsv"; - objectName?: string; - assetsFolderPath?: string | { vector?: string; bitmap?: string }; - prettierConfig?: Partial<{ - endOfLine: "auto" | "lf" | "crlf" | "cr"; - tabWidth: number; - useTabs: boolean; - }>; - formatFileName?: - | "camelCase" - | "kebabCase" - | "snakeCase" - | "pascalCase" - | "none"; - formatKeys?: "camelCase" | "kebabCase" | "snakeCase" | "pascalCase"; - typescript?: { - castToConst?: boolean; - }; - }>; -} -``` - -## Usage - -### Options - -| Parameter | Required | Type | Default | Description | -| ---------------------------- | -------- | -------------------------------------------------------------------------- | ----------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `colorFormat` | optional | `rgb`, `prgb`, `hex`, `hex6`, `hex3`, `hex4`, `hex8`, `name`, `hsl`, `hsv` | `rgb` | The format of all colors (gradients, borders, textStyles etc.) | -| `objectName` | optional | `string` | `'theme'` | The name of the JS object containing the theme (it will be the default export of the file). | -| `assetsFolderPath` | optional | `string` | `undefined` | The relative location of the folder to import the assets from, if not provided, the assets will be referenced by URL. | -| `assetsFolderPath.vector` | optional | `string` | `undefined` | The relative location of the folder to import the **vector** assets from. | -| `assetsFolderPath.bitmap` | optional | `string` | `undefined` | The relative location of the folder to import the **bitmap** assets from. | -| `prettierConfig.endOfLine` | optional | `auto, lf, crlf, cr` | `auto` | [Prettier documentation](https://prettier.io/docs/en/options.html#end-of-line) | -| `prettierConfig.tabWidth` | optional | `number` | `2` | [Prettier documentation](https://prettier.io/docs/en/options.html#tab-width) | -| `prettierConfig.useTabs` | optional | `boolean` | `false` | [Prettier documentation](https://prettier.io/docs/en/options.html#tabs) | -| `prettierConfig.singleQuote` | optional | `boolean` | `false` | [Prettier documentation](https://prettier.io/docs/en/options.html#quotes) | -| `formatFileName` | optional | `camelCase` , `kebabCase` , `snakeCase` , `pascalCase` , `none` | `camelCase` | Apply formatting to the file name in the import statements of vectors and bitmaps. Use this if you used transformations on the file names of downloaded assets. | -| `formatKeys` | optional | `camelCase` , `kebabCase` , `snakeCase` , `pascalCase` | `camelCase` | Apply formatting to each keyof the imported assets. | -| `typescript.castToConst` | optional | `boolean` | `false` | Adds `as const` to the end of the resulting exported object. | - -## Types - -โ„น๏ธ **Please be aware that, depending on the order you use parsers, their input and output types have to match.** - -### Input - -Array of object with at least name, value and type - -```ts -type input = Array<{ name: string; value: any; type: string }>; -``` - -### Output - -```ts -type output = string; -``` - -## Usage - -### Config - -```jsonc -"parsers": [ - { - "name": "to-react-native", - "options": { - "colorFormat": "hex", - "assetsFolderPath": "src/common/assets", - "objectName": "myTheme", - "prettierConfig": { - "tabWidth": 4, - "singleQuote": true - }, - "formatFileName": "none", - "formatKeys": "camelCase", - } - } -] -// ... -``` - -### Before/After - -#### Input - -```js -[ - // โ€ฆ - { - name: "activity.svg", - value: { - url: "https://s3-us-west-2.amazonaws.com/figma-alpha-api/img/a114/ce5c/947dcb83ea93c2da18ee2ea16f470a30", - }, - type: "vector", - }, - { - name: "Body", - value: { - font: { - meta: { - source: "localStyles", - }, - name: "Inter-Medium", - type: "font", - value: { - isItalic: false, - fontFamily: "Inter", - fontWeight: 500, - fontPostScriptName: "Inter-Medium", - }, - }, - color: { - value: { - a: 1, - b: 196, - g: 196, - r: 196, - }, - }, - fontSize: { - value: { - unit: "px", - measure: 14, - }, - }, - textAlign: { - vertical: "top", - horizontal: "left", - }, - lineHeight: { - value: { - unit: "px", - measure: 20, - }, - }, - }, - type: "textStyle", - }, - { - name: "Colors / Accent", - value: { - a: 1, - b: 239, - g: 80, - r: 102, - }, - type: "color", - }, - // โ€ฆ -]; -``` - -#### Output - -```js -import vectorActivity from "../src/assets/activity.svg"; -import bitmapAcmeLogo from "../src/assets/acme-logo.png"; - -const theme = { - bitmap: { - acmeLogo: bitmapAcmeLogo, - }, - vector: { - activity: vectorActivity, - }, - depth: { - background: { - elevation: 1, - shadowOpacity: 0.1815, - shadowRadius: 0.54, - shadowOffset: { width: 0.6, height: 0.6 }, - }, - }, - duration: { - base: 300, - }, - measurement: { - baseSpace01: 4, - }, - textStyle: { - body: { - fontWeight: 500, - fontSize: 14, - lineHeight: 20, - fontFamily: "Inter-Medium", - color: "#1e212b", - letterSpacing: 10, - }, - }, - border: { - borderAccent: { - borderWidth: 2, - borderStyle: "solid", - borderColor: "rgb(102, 80, 239)", - borderRadius: 16, - }, - }, - color: { - colorsAccent: "rgb(87, 124, 254)", - }, - font: { - firaCodeMedium: "FiraCode-Medium", - }, - gradient: { - gradientsColored: [ - { - angle: 90, - colors: ["rgb(245, 72, 63)", "rgb(255, 142, 5)"], - locations: [0, 1], - }, - ], - }, - opacity: { subtle: 0.5, transparent: 0.1, visible: 0.95 }, -}; - -export default theme; -``` - -## Guides - -
-Downloading assets & fonts - -Downloading assets happens in a seperate rule in `.specifyrc.json`. - -```jsoncc -// .specifyrc.json -{ - // โ€ฆ - "rules": [ - { - "name": "Download Assets", - "path": "src/common/assets/images", - "filter": { - "types": ["vector", "bitmap"] - } - }, - { - "name": "Download Fonts", - "path": "src/common/assets/fonts", - "filter": { - "types": ["font"] - } - } - ] -} -``` - -Next, create a `react-native.config.js` and fill in the path where the fonts are imported: - -```ts -module.exports = { - project: { - ios: {}, - android: {}, - }, - assets: ["assets/fonts/"], -}; -``` - -Finally, run `react-native link` after `specify pull`. All fonts in `assets/fonts` will be ready to use! - -> Linking fonts like this only works for non-Expo apps. Feel free to contribute a section for Expo managed apps ๐Ÿ™. - -
-
-Rendering bitmaps -Simple as that: - -```tsx -import { Image } from "react-native"; - -const App = () => ; -``` - -
-
-Rendering vectors - -You will need to install and configure [`react-native-svg-transformer`](https://github.com/kristerkari/react-native-svg-transformer). If you are using Expo, this is pre-configured for you. The imported SVG's are React Elements, so it is recommended you create a simple `Vector` component: - -```tsx -const Vector = ({ source: SVGElement, ...props }: Props) => ( - -); - -const App = () => ; -``` - -
- -
- -Rendering gradients - -For rendering gradients we recommend to use [react-native-linear-gradient](https://github.com/react-native-linear-gradient/react-native-linear-gradient). -Gradients can be rendered as such: - -```tsx -import { LinearGradient } from "react-native-linear-gradient"; - -const App = () => ( - -); -``` - -
diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-react-native/__snapshots__/to-react-native.spec.ts.snap b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-react-native/__snapshots__/to-react-native.spec.ts.snap deleted file mode 100644 index bae6ee43a..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-react-native/__snapshots__/to-react-native.spec.ts.snap +++ /dev/null @@ -1,2654 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`To React Native Should generate the theme object 1`] = ` -"const theme = { - bitmap: { - acmeLogo: { - uri: \\"'https://s3-us-west-2.amazonaws.com/figma-alpha-api/img/13d6/2eb6/a2626d914998754ac0b704e2cdb7a813'\\", - }, - photoExample: { - uri: \\"'https://s3-us-west-2.amazonaws.com/figma-alpha-api/img/3302/0ec5/79870771c0861eaa8f1af4e4ed5a8790'\\", - }, - }, - vector: { - activity: { - uri: \\"'https://s3-us-west-2.amazonaws.com/figma-alpha-api/img/96dc/8825/c166b559140a0a64b28441924700a0b2'\\", - }, - airplay: { - uri: \\"'https://s3-us-west-2.amazonaws.com/figma-alpha-api/img/ba89/d0aa/da2310c63c85699af43c8d128619cfdc'\\", - }, - alertCircle: { - uri: \\"'https://s3-us-west-2.amazonaws.com/figma-alpha-api/img/e8be/d9ce/4595ffa4510b7427d42e113c33632ae9'\\", - }, - alertOctagon: { - uri: \\"'https://s3-us-west-2.amazonaws.com/figma-alpha-api/img/fda9/f3ef/d31ed18fd324eb97190f34e0497214df'\\", - }, - alertTriangle: { - uri: \\"'https://s3-us-west-2.amazonaws.com/figma-alpha-api/img/877f/7e96/57aa1df766cf179f3610bf3b84cc268a'\\", - }, - alertTriangle: { - uri: \\"'https://s3-us-west-2.amazonaws.com/figma-alpha-api/img/880e/672c/155447c7e27185832ded7310ac9a02e7'\\", - }, - alignCenter: { - uri: \\"'https://s3-us-west-2.amazonaws.com/figma-alpha-api/img/44e1/3537/07081649495a48e2f2de80b83e69a876'\\", - }, - alignCenter: { - uri: \\"'https://s3-us-west-2.amazonaws.com/figma-alpha-api/img/60d9/4a66/69c02a6b502dec9e745acdfb8418093d'\\", - }, - userMask: { - uri: \\"'https://s3-us-west-2.amazonaws.com/figma-alpha-api/img/5e90/27b6/3e136d25798fc5013fce51eea15ad48c'\\", - }, - userMask: { - uri: \\"'https://s3-us-west-2.amazonaws.com/figma-alpha-api/img/8005/3a2c/7ab7a74d1b3b57bd5151e9c48669b4f7'\\", - }, - }, - depth: { - background: { - elevation: 1, - shadowOpacity: 0.1815, - shadowRadius: 0.54, - shadowOffset: { width: 0.6, height: 0.6 }, - }, - foreground: { - elevation: 100, - shadowOpacity: 0.32999999999999996, - shadowRadius: 54, - shadowOffset: { width: 60, height: 60 }, - }, - middle: { - elevation: 50, - shadowOpacity: 0.255, - shadowRadius: 27, - shadowOffset: { width: 30, height: 30 }, - }, - }, - duration: { base: 300, long: 700, short: 100, veryLong: 3000 }, - measurement: { - baseSpace01: 4, - baseSpace02: 8, - baseSpace03: 12, - baseSpace04: 16, - baseSpace05: 32, - baseSpace06: 48, - baseSpace07: 64, - baseSpace08: 80, - baseSpace09: 96, - baseSpace10: 112, - }, - textStyle: { - body: { - fontWeight: \\"500\\", - fontSize: 14, - lineHeight: 20, - fontFamily: \\"Inter-Medium\\", - color: \\"rgb(30, 33, 43)\\", - letterSpacing: 10, - }, - bodyWithOpacity: { - fontWeight: \\"500\\", - fontSize: 14, - lineHeight: 20, - fontFamily: \\"Inter-Medium\\", - color: \\"rgba(30, 33, 43, 0.3)\\", - letterSpacing: 10, - }, - code: { - fontWeight: \\"500\\", - fontSize: 13, - lineHeight: 20, - fontFamily: \\"FiraCode-Medium\\", - color: \\"rgb(255, 142, 5)\\", - }, - list: { - fontWeight: \\"400\\", - fontSize: 14, - lineHeight: 20, - fontFamily: \\"Roboto-Regular\\", - }, - title: { - fontWeight: \\"600\\", - fontSize: 32, - lineHeight: 40, - fontFamily: \\"Inter-SemiBold\\", - color: \\"rgb(30, 33, 43)\\", - }, - }, - border: { - borderAccent: { - borderWidth: 2, - borderStyle: \\"solid\\", - borderColor: \\"rgb(102, 80, 239)\\", - borderRadius: 16, - }, - borderAccentWithOpacity: { - borderWidth: 2, - borderStyle: \\"solid\\", - borderColor: \\"rgba(102, 80, 239, 0.5)\\", - borderRadius: 16, - }, - borderAccentWithoutRadii: { - borderWidth: 2, - borderStyle: \\"solid\\", - borderColor: \\"rgba(102, 80, 239, 0.5)\\", - }, - borderDashed: { - borderWidth: 1, - borderStyle: \\"dashed\\", - borderColor: \\"rgb(30, 33, 43)\\", - borderRadius: 16, - }, - }, - color: { - colorsAccent: \\"rgb(87, 124, 254)\\", - colorsBlack: \\"rgb(30, 33, 43)\\", - colorsGreen: \\"rgb(88, 205, 82)\\", - colorsGrey: \\"rgb(204, 213, 225)\\", - colorsOrange: \\"rgb(255, 142, 5)\\", - colorsRed: \\"rgb(245, 72, 63)\\", - colorsWhite: \\"rgb(255, 255, 255)\\", - }, - font: { - firaCodeMedium: \\"FiraCode-Medium\\", - interMedium: \\"Inter-Medium\\", - interSemiBold: \\"Inter-SemiBold\\", - robotoRegular: \\"Roboto-Regular\\", - }, - gradient: { - gradientsColored: [ - { - angle: 90, - colors: [\\"rgb(245, 72, 63)\\", \\"rgb(255, 142, 5)\\"], - locations: [0, 1], - }, - ], - gradientsDark: [ - { - angle: 90, - colors: [\\"rgb(30, 33, 43)\\", \\"rgb(204, 213, 225)\\"], - locations: [0, 1], - }, - ], - gradientsNeutral: [ - { - angle: 90, - colors: [\\"rgb(204, 213, 225)\\", \\"rgb(255, 255, 255)\\"], - locations: [0, 1], - }, - ], - gradientsSafari: [ - { - angle: 90, - colors: [\\"rgb(255, 142, 5)\\", \\"rgb(255, 255, 255)\\"], - locations: [0, 1], - }, - ], - }, - opacity: { subtle: 0.5, transparent: 0.1, visible: 0.95 }, -}; -export default theme; -" -`; - -exports[`To React Native Should support different duration types 1`] = ` -"const theme = { - duration: { - \\"2Hours\\": 7200000, - \\"2Minutes\\": 120000, - \\"2Seconds\\": 2000, - \\"2Milliseconds\\": 2, - \\"2Nanoseconds\\": 0.002, - }, -}; -export default theme; -" -`; - -exports[`To React Native Should support different formatKey options 1`] = ` -"import bitmapAcmeLogo from \\"./path/acmeLogo.png\\"; -import bitmapPhotoExample from \\"./path/photoExample.png\\"; -import vectorActivity from \\"./path/activity.svg\\"; -import vectorAirplay from \\"./path/airplay.svg\\"; -import vectorAlertCircle from \\"./path/alertCircle.svg\\"; -import vectorAlertOctagon from \\"./path/alertOctagon.svg\\"; -import vectorAlertTriangle from \\"./path/alertTriangle.pdf\\"; -import vectorAlertTriangle from \\"./path/alertTriangle.svg\\"; -import vectorAlignCenter from \\"./path/alignCenter.svg\\"; -import vectorAlignCenter from \\"./path/alignCenter.pdf\\"; -import vectorUserMask from \\"./path/userMask.svg\\"; -import vectorUserMask from \\"./path/userMask.pdf\\"; - -const theme = { - bitmap: { acmeLogo: bitmapAcmeLogo, photoExample: bitmapPhotoExample }, - vector: { - activity: vectorActivity, - airplay: vectorAirplay, - alertCircle: vectorAlertCircle, - alertOctagon: vectorAlertOctagon, - alertTriangle: vectorAlertTriangle, - alertTriangle: vectorAlertTriangle, - alignCenter: vectorAlignCenter, - alignCenter: vectorAlignCenter, - userMask: vectorUserMask, - userMask: vectorUserMask, - }, - depth: { - background: { - elevation: 1, - shadowOpacity: 0.1815, - shadowRadius: 0.54, - shadowOffset: { width: 0.6, height: 0.6 }, - }, - foreground: { - elevation: 100, - shadowOpacity: 0.32999999999999996, - shadowRadius: 54, - shadowOffset: { width: 60, height: 60 }, - }, - middle: { - elevation: 50, - shadowOpacity: 0.255, - shadowRadius: 27, - shadowOffset: { width: 30, height: 30 }, - }, - }, - duration: { base: 300, long: 700, short: 100, veryLong: 3000 }, - measurement: { - baseSpace01: 4, - baseSpace02: 8, - baseSpace03: 12, - baseSpace04: 16, - baseSpace05: 32, - baseSpace06: 48, - baseSpace07: 64, - baseSpace08: 80, - baseSpace09: 96, - baseSpace10: 112, - }, - textStyle: { - body: { - fontWeight: \\"500\\", - fontSize: 14, - lineHeight: 20, - fontFamily: \\"Inter-Medium\\", - color: \\"rgb(30, 33, 43)\\", - letterSpacing: 10, - }, - bodyWithOpacity: { - fontWeight: \\"500\\", - fontSize: 14, - lineHeight: 20, - fontFamily: \\"Inter-Medium\\", - color: \\"rgba(30, 33, 43, 0.3)\\", - letterSpacing: 10, - }, - code: { - fontWeight: \\"500\\", - fontSize: 13, - lineHeight: 20, - fontFamily: \\"FiraCode-Medium\\", - color: \\"rgb(255, 142, 5)\\", - }, - list: { - fontWeight: \\"400\\", - fontSize: 14, - lineHeight: 20, - fontFamily: \\"Roboto-Regular\\", - }, - title: { - fontWeight: \\"600\\", - fontSize: 32, - lineHeight: 40, - fontFamily: \\"Inter-SemiBold\\", - color: \\"rgb(30, 33, 43)\\", - }, - }, - border: { - borderAccent: { - borderWidth: 2, - borderStyle: \\"solid\\", - borderColor: \\"rgb(102, 80, 239)\\", - borderRadius: 16, - }, - borderAccentWithOpacity: { - borderWidth: 2, - borderStyle: \\"solid\\", - borderColor: \\"rgba(102, 80, 239, 0.5)\\", - borderRadius: 16, - }, - borderAccentWithoutRadii: { - borderWidth: 2, - borderStyle: \\"solid\\", - borderColor: \\"rgba(102, 80, 239, 0.5)\\", - }, - borderDashed: { - borderWidth: 1, - borderStyle: \\"dashed\\", - borderColor: \\"rgb(30, 33, 43)\\", - borderRadius: 16, - }, - }, - color: { - colorsAccent: \\"rgb(87, 124, 254)\\", - colorsBlack: \\"rgb(30, 33, 43)\\", - colorsGreen: \\"rgb(88, 205, 82)\\", - colorsGrey: \\"rgb(204, 213, 225)\\", - colorsOrange: \\"rgb(255, 142, 5)\\", - colorsRed: \\"rgb(245, 72, 63)\\", - colorsWhite: \\"rgb(255, 255, 255)\\", - }, - font: { - firaCodeMedium: \\"FiraCode-Medium\\", - interMedium: \\"Inter-Medium\\", - interSemiBold: \\"Inter-SemiBold\\", - robotoRegular: \\"Roboto-Regular\\", - }, - gradient: { - gradientsColored: [ - { - angle: 90, - colors: [\\"rgb(245, 72, 63)\\", \\"rgb(255, 142, 5)\\"], - locations: [0, 1], - }, - ], - gradientsDark: [ - { - angle: 90, - colors: [\\"rgb(30, 33, 43)\\", \\"rgb(204, 213, 225)\\"], - locations: [0, 1], - }, - ], - gradientsNeutral: [ - { - angle: 90, - colors: [\\"rgb(204, 213, 225)\\", \\"rgb(255, 255, 255)\\"], - locations: [0, 1], - }, - ], - gradientsSafari: [ - { - angle: 90, - colors: [\\"rgb(255, 142, 5)\\", \\"rgb(255, 255, 255)\\"], - locations: [0, 1], - }, - ], - }, - opacity: { subtle: 0.5, transparent: 0.1, visible: 0.95 }, -}; -export default theme; -" -`; - -exports[`To React Native Should support different formatKey options 2`] = ` -"import bitmapAcmeLogo from \\"./path/acmeLogo.png\\"; -import bitmapPhotoExample from \\"./path/photoExample.png\\"; -import vectorActivity from \\"./path/activity.svg\\"; -import vectorAirplay from \\"./path/airplay.svg\\"; -import vectorAlertCircle from \\"./path/alertCircle.svg\\"; -import vectorAlertOctagon from \\"./path/alertOctagon.svg\\"; -import vectorAlertTriangle from \\"./path/alertTriangle.pdf\\"; -import vectorAlertTriangle from \\"./path/alertTriangle.svg\\"; -import vectorAlignCenter from \\"./path/alignCenter.svg\\"; -import vectorAlignCenter from \\"./path/alignCenter.pdf\\"; -import vectorUserMask from \\"./path/userMask.svg\\"; -import vectorUserMask from \\"./path/userMask.pdf\\"; - -const theme = { - bitmap: { \\"acme-logo\\": bitmapAcmeLogo, \\"photo-example\\": bitmapPhotoExample }, - vector: { - activity: vectorActivity, - airplay: vectorAirplay, - \\"alert-circle\\": vectorAlertCircle, - \\"alert-octagon\\": vectorAlertOctagon, - \\"alert-triangle\\": vectorAlertTriangle, - \\"alert-triangle\\": vectorAlertTriangle, - \\"align-center\\": vectorAlignCenter, - \\"align-center\\": vectorAlignCenter, - \\"user-mask\\": vectorUserMask, - \\"user-mask\\": vectorUserMask, - }, - depth: { - background: { - elevation: 1, - shadowOpacity: 0.1815, - shadowRadius: 0.54, - shadowOffset: { width: 0.6, height: 0.6 }, - }, - foreground: { - elevation: 100, - shadowOpacity: 0.32999999999999996, - shadowRadius: 54, - shadowOffset: { width: 60, height: 60 }, - }, - middle: { - elevation: 50, - shadowOpacity: 0.255, - shadowRadius: 27, - shadowOffset: { width: 30, height: 30 }, - }, - }, - duration: { base: 300, long: 700, short: 100, \\"very-long\\": 3000 }, - measurement: { - \\"base-space-01\\": 4, - \\"base-space-02\\": 8, - \\"base-space-03\\": 12, - \\"base-space-04\\": 16, - \\"base-space-05\\": 32, - \\"base-space-06\\": 48, - \\"base-space-07\\": 64, - \\"base-space-08\\": 80, - \\"base-space-09\\": 96, - \\"base-space-10\\": 112, - }, - textStyle: { - body: { - fontWeight: \\"500\\", - fontSize: 14, - lineHeight: 20, - fontFamily: \\"Inter-Medium\\", - color: \\"rgb(30, 33, 43)\\", - letterSpacing: 10, - }, - \\"body-with-opacity\\": { - fontWeight: \\"500\\", - fontSize: 14, - lineHeight: 20, - fontFamily: \\"Inter-Medium\\", - color: \\"rgba(30, 33, 43, 0.3)\\", - letterSpacing: 10, - }, - code: { - fontWeight: \\"500\\", - fontSize: 13, - lineHeight: 20, - fontFamily: \\"FiraCode-Medium\\", - color: \\"rgb(255, 142, 5)\\", - }, - list: { - fontWeight: \\"400\\", - fontSize: 14, - lineHeight: 20, - fontFamily: \\"Roboto-Regular\\", - }, - title: { - fontWeight: \\"600\\", - fontSize: 32, - lineHeight: 40, - fontFamily: \\"Inter-SemiBold\\", - color: \\"rgb(30, 33, 43)\\", - }, - }, - border: { - \\"border-accent\\": { - borderWidth: 2, - borderStyle: \\"solid\\", - borderColor: \\"rgb(102, 80, 239)\\", - borderRadius: 16, - }, - \\"border-accent-with-opacity\\": { - borderWidth: 2, - borderStyle: \\"solid\\", - borderColor: \\"rgba(102, 80, 239, 0.5)\\", - borderRadius: 16, - }, - \\"border-accent-without-radii\\": { - borderWidth: 2, - borderStyle: \\"solid\\", - borderColor: \\"rgba(102, 80, 239, 0.5)\\", - }, - \\"border-dashed\\": { - borderWidth: 1, - borderStyle: \\"dashed\\", - borderColor: \\"rgb(30, 33, 43)\\", - borderRadius: 16, - }, - }, - color: { - \\"colors-accent\\": \\"rgb(87, 124, 254)\\", - \\"colors-black\\": \\"rgb(30, 33, 43)\\", - \\"colors-green\\": \\"rgb(88, 205, 82)\\", - \\"colors-grey\\": \\"rgb(204, 213, 225)\\", - \\"colors-orange\\": \\"rgb(255, 142, 5)\\", - \\"colors-red\\": \\"rgb(245, 72, 63)\\", - \\"colors-white\\": \\"rgb(255, 255, 255)\\", - }, - font: { - \\"fira-code-medium\\": \\"FiraCode-Medium\\", - \\"inter-medium\\": \\"Inter-Medium\\", - \\"inter-semi-bold\\": \\"Inter-SemiBold\\", - \\"roboto-regular\\": \\"Roboto-Regular\\", - }, - gradient: { - \\"gradients-colored\\": [ - { - angle: 90, - colors: [\\"rgb(245, 72, 63)\\", \\"rgb(255, 142, 5)\\"], - locations: [0, 1], - }, - ], - \\"gradients-dark\\": [ - { - angle: 90, - colors: [\\"rgb(30, 33, 43)\\", \\"rgb(204, 213, 225)\\"], - locations: [0, 1], - }, - ], - \\"gradients-neutral\\": [ - { - angle: 90, - colors: [\\"rgb(204, 213, 225)\\", \\"rgb(255, 255, 255)\\"], - locations: [0, 1], - }, - ], - \\"gradients-safari\\": [ - { - angle: 90, - colors: [\\"rgb(255, 142, 5)\\", \\"rgb(255, 255, 255)\\"], - locations: [0, 1], - }, - ], - }, - opacity: { subtle: 0.5, transparent: 0.1, visible: 0.95 }, -}; -export default theme; -" -`; - -exports[`To React Native Should support different formatKey options 3`] = ` -"import bitmapAcmeLogo from \\"./path/acmeLogo.png\\"; -import bitmapPhotoExample from \\"./path/photoExample.png\\"; -import vectorActivity from \\"./path/activity.svg\\"; -import vectorAirplay from \\"./path/airplay.svg\\"; -import vectorAlertCircle from \\"./path/alertCircle.svg\\"; -import vectorAlertOctagon from \\"./path/alertOctagon.svg\\"; -import vectorAlertTriangle from \\"./path/alertTriangle.pdf\\"; -import vectorAlertTriangle from \\"./path/alertTriangle.svg\\"; -import vectorAlignCenter from \\"./path/alignCenter.svg\\"; -import vectorAlignCenter from \\"./path/alignCenter.pdf\\"; -import vectorUserMask from \\"./path/userMask.svg\\"; -import vectorUserMask from \\"./path/userMask.pdf\\"; - -const theme = { - bitmap: { acme_logo: bitmapAcmeLogo, photo_example: bitmapPhotoExample }, - vector: { - activity: vectorActivity, - airplay: vectorAirplay, - alert_circle: vectorAlertCircle, - alert_octagon: vectorAlertOctagon, - alert_triangle: vectorAlertTriangle, - alert_triangle: vectorAlertTriangle, - align_center: vectorAlignCenter, - align_center: vectorAlignCenter, - user_mask: vectorUserMask, - user_mask: vectorUserMask, - }, - depth: { - background: { - elevation: 1, - shadowOpacity: 0.1815, - shadowRadius: 0.54, - shadowOffset: { width: 0.6, height: 0.6 }, - }, - foreground: { - elevation: 100, - shadowOpacity: 0.32999999999999996, - shadowRadius: 54, - shadowOffset: { width: 60, height: 60 }, - }, - middle: { - elevation: 50, - shadowOpacity: 0.255, - shadowRadius: 27, - shadowOffset: { width: 30, height: 30 }, - }, - }, - duration: { base: 300, long: 700, short: 100, very_long: 3000 }, - measurement: { - base_space_01: 4, - base_space_02: 8, - base_space_03: 12, - base_space_04: 16, - base_space_05: 32, - base_space_06: 48, - base_space_07: 64, - base_space_08: 80, - base_space_09: 96, - base_space_10: 112, - }, - textStyle: { - body: { - fontWeight: \\"500\\", - fontSize: 14, - lineHeight: 20, - fontFamily: \\"Inter-Medium\\", - color: \\"rgb(30, 33, 43)\\", - letterSpacing: 10, - }, - body_with_opacity: { - fontWeight: \\"500\\", - fontSize: 14, - lineHeight: 20, - fontFamily: \\"Inter-Medium\\", - color: \\"rgba(30, 33, 43, 0.3)\\", - letterSpacing: 10, - }, - code: { - fontWeight: \\"500\\", - fontSize: 13, - lineHeight: 20, - fontFamily: \\"FiraCode-Medium\\", - color: \\"rgb(255, 142, 5)\\", - }, - list: { - fontWeight: \\"400\\", - fontSize: 14, - lineHeight: 20, - fontFamily: \\"Roboto-Regular\\", - }, - title: { - fontWeight: \\"600\\", - fontSize: 32, - lineHeight: 40, - fontFamily: \\"Inter-SemiBold\\", - color: \\"rgb(30, 33, 43)\\", - }, - }, - border: { - border_accent: { - borderWidth: 2, - borderStyle: \\"solid\\", - borderColor: \\"rgb(102, 80, 239)\\", - borderRadius: 16, - }, - border_accent_with_opacity: { - borderWidth: 2, - borderStyle: \\"solid\\", - borderColor: \\"rgba(102, 80, 239, 0.5)\\", - borderRadius: 16, - }, - border_accent_without_radii: { - borderWidth: 2, - borderStyle: \\"solid\\", - borderColor: \\"rgba(102, 80, 239, 0.5)\\", - }, - border_dashed: { - borderWidth: 1, - borderStyle: \\"dashed\\", - borderColor: \\"rgb(30, 33, 43)\\", - borderRadius: 16, - }, - }, - color: { - colors_accent: \\"rgb(87, 124, 254)\\", - colors_black: \\"rgb(30, 33, 43)\\", - colors_green: \\"rgb(88, 205, 82)\\", - colors_grey: \\"rgb(204, 213, 225)\\", - colors_orange: \\"rgb(255, 142, 5)\\", - colors_red: \\"rgb(245, 72, 63)\\", - colors_white: \\"rgb(255, 255, 255)\\", - }, - font: { - fira_code_medium: \\"FiraCode-Medium\\", - inter_medium: \\"Inter-Medium\\", - inter_semi_bold: \\"Inter-SemiBold\\", - roboto_regular: \\"Roboto-Regular\\", - }, - gradient: { - gradients_colored: [ - { - angle: 90, - colors: [\\"rgb(245, 72, 63)\\", \\"rgb(255, 142, 5)\\"], - locations: [0, 1], - }, - ], - gradients_dark: [ - { - angle: 90, - colors: [\\"rgb(30, 33, 43)\\", \\"rgb(204, 213, 225)\\"], - locations: [0, 1], - }, - ], - gradients_neutral: [ - { - angle: 90, - colors: [\\"rgb(204, 213, 225)\\", \\"rgb(255, 255, 255)\\"], - locations: [0, 1], - }, - ], - gradients_safari: [ - { - angle: 90, - colors: [\\"rgb(255, 142, 5)\\", \\"rgb(255, 255, 255)\\"], - locations: [0, 1], - }, - ], - }, - opacity: { subtle: 0.5, transparent: 0.1, visible: 0.95 }, -}; -export default theme; -" -`; - -exports[`To React Native Should support different formatKey options 4`] = ` -"import bitmapAcmeLogo from \\"./path/acmeLogo.png\\"; -import bitmapPhotoExample from \\"./path/photoExample.png\\"; -import vectorActivity from \\"./path/activity.svg\\"; -import vectorAirplay from \\"./path/airplay.svg\\"; -import vectorAlertCircle from \\"./path/alertCircle.svg\\"; -import vectorAlertOctagon from \\"./path/alertOctagon.svg\\"; -import vectorAlertTriangle from \\"./path/alertTriangle.pdf\\"; -import vectorAlertTriangle from \\"./path/alertTriangle.svg\\"; -import vectorAlignCenter from \\"./path/alignCenter.svg\\"; -import vectorAlignCenter from \\"./path/alignCenter.pdf\\"; -import vectorUserMask from \\"./path/userMask.svg\\"; -import vectorUserMask from \\"./path/userMask.pdf\\"; - -const theme = { - bitmap: { AcmeLogo: bitmapAcmeLogo, PhotoExample: bitmapPhotoExample }, - vector: { - Activity: vectorActivity, - Airplay: vectorAirplay, - AlertCircle: vectorAlertCircle, - AlertOctagon: vectorAlertOctagon, - AlertTriangle: vectorAlertTriangle, - AlertTriangle: vectorAlertTriangle, - AlignCenter: vectorAlignCenter, - AlignCenter: vectorAlignCenter, - UserMask: vectorUserMask, - UserMask: vectorUserMask, - }, - depth: { - Background: { - elevation: 1, - shadowOpacity: 0.1815, - shadowRadius: 0.54, - shadowOffset: { width: 0.6, height: 0.6 }, - }, - Foreground: { - elevation: 100, - shadowOpacity: 0.32999999999999996, - shadowRadius: 54, - shadowOffset: { width: 60, height: 60 }, - }, - Middle: { - elevation: 50, - shadowOpacity: 0.255, - shadowRadius: 27, - shadowOffset: { width: 30, height: 30 }, - }, - }, - duration: { Base: 300, Long: 700, Short: 100, VeryLong: 3000 }, - measurement: { - BaseSpace01: 4, - BaseSpace02: 8, - BaseSpace03: 12, - BaseSpace04: 16, - BaseSpace05: 32, - BaseSpace06: 48, - BaseSpace07: 64, - BaseSpace08: 80, - BaseSpace09: 96, - BaseSpace10: 112, - }, - textStyle: { - Body: { - fontWeight: \\"500\\", - fontSize: 14, - lineHeight: 20, - fontFamily: \\"Inter-Medium\\", - color: \\"rgb(30, 33, 43)\\", - letterSpacing: 10, - }, - BodyWithOpacity: { - fontWeight: \\"500\\", - fontSize: 14, - lineHeight: 20, - fontFamily: \\"Inter-Medium\\", - color: \\"rgba(30, 33, 43, 0.3)\\", - letterSpacing: 10, - }, - Code: { - fontWeight: \\"500\\", - fontSize: 13, - lineHeight: 20, - fontFamily: \\"FiraCode-Medium\\", - color: \\"rgb(255, 142, 5)\\", - }, - List: { - fontWeight: \\"400\\", - fontSize: 14, - lineHeight: 20, - fontFamily: \\"Roboto-Regular\\", - }, - Title: { - fontWeight: \\"600\\", - fontSize: 32, - lineHeight: 40, - fontFamily: \\"Inter-SemiBold\\", - color: \\"rgb(30, 33, 43)\\", - }, - }, - border: { - BorderAccent: { - borderWidth: 2, - borderStyle: \\"solid\\", - borderColor: \\"rgb(102, 80, 239)\\", - borderRadius: 16, - }, - BorderAccentWithOpacity: { - borderWidth: 2, - borderStyle: \\"solid\\", - borderColor: \\"rgba(102, 80, 239, 0.5)\\", - borderRadius: 16, - }, - BorderAccentWithoutRadii: { - borderWidth: 2, - borderStyle: \\"solid\\", - borderColor: \\"rgba(102, 80, 239, 0.5)\\", - }, - BorderDashed: { - borderWidth: 1, - borderStyle: \\"dashed\\", - borderColor: \\"rgb(30, 33, 43)\\", - borderRadius: 16, - }, - }, - color: { - ColorsAccent: \\"rgb(87, 124, 254)\\", - ColorsBlack: \\"rgb(30, 33, 43)\\", - ColorsGreen: \\"rgb(88, 205, 82)\\", - ColorsGrey: \\"rgb(204, 213, 225)\\", - ColorsOrange: \\"rgb(255, 142, 5)\\", - ColorsRed: \\"rgb(245, 72, 63)\\", - ColorsWhite: \\"rgb(255, 255, 255)\\", - }, - font: { - FiraCodeMedium: \\"FiraCode-Medium\\", - InterMedium: \\"Inter-Medium\\", - InterSemiBold: \\"Inter-SemiBold\\", - RobotoRegular: \\"Roboto-Regular\\", - }, - gradient: { - GradientsColored: [ - { - angle: 90, - colors: [\\"rgb(245, 72, 63)\\", \\"rgb(255, 142, 5)\\"], - locations: [0, 1], - }, - ], - GradientsDark: [ - { - angle: 90, - colors: [\\"rgb(30, 33, 43)\\", \\"rgb(204, 213, 225)\\"], - locations: [0, 1], - }, - ], - GradientsNeutral: [ - { - angle: 90, - colors: [\\"rgb(204, 213, 225)\\", \\"rgb(255, 255, 255)\\"], - locations: [0, 1], - }, - ], - GradientsSafari: [ - { - angle: 90, - colors: [\\"rgb(255, 142, 5)\\", \\"rgb(255, 255, 255)\\"], - locations: [0, 1], - }, - ], - }, - opacity: { Subtle: 0.5, Transparent: 0.1, Visible: 0.95 }, -}; -export default theme; -" -`; - -exports[`To React Native Should support different formatName options 1`] = ` -"import bitmapAcmeLogo from \\"./path/acmeLogo.png\\"; -import bitmapPhotoExample from \\"./path/photoExample.png\\"; -import vectorActivity from \\"./path/activity.svg\\"; -import vectorAirplay from \\"./path/airplay.svg\\"; -import vectorAlertCircle from \\"./path/alertCircle.svg\\"; -import vectorAlertOctagon from \\"./path/alertOctagon.svg\\"; -import vectorAlertTriangle from \\"./path/alertTriangle.pdf\\"; -import vectorAlertTriangle from \\"./path/alertTriangle.svg\\"; -import vectorAlignCenter from \\"./path/alignCenter.svg\\"; -import vectorAlignCenter from \\"./path/alignCenter.pdf\\"; -import vectorUserMask from \\"./path/userMask.svg\\"; -import vectorUserMask from \\"./path/userMask.pdf\\"; - -const theme = { - bitmap: { acmeLogo: bitmapAcmeLogo, photoExample: bitmapPhotoExample }, - vector: { - activity: vectorActivity, - airplay: vectorAirplay, - alertCircle: vectorAlertCircle, - alertOctagon: vectorAlertOctagon, - alertTriangle: vectorAlertTriangle, - alertTriangle: vectorAlertTriangle, - alignCenter: vectorAlignCenter, - alignCenter: vectorAlignCenter, - userMask: vectorUserMask, - userMask: vectorUserMask, - }, - depth: { - background: { - elevation: 1, - shadowOpacity: 0.1815, - shadowRadius: 0.54, - shadowOffset: { width: 0.6, height: 0.6 }, - }, - foreground: { - elevation: 100, - shadowOpacity: 0.32999999999999996, - shadowRadius: 54, - shadowOffset: { width: 60, height: 60 }, - }, - middle: { - elevation: 50, - shadowOpacity: 0.255, - shadowRadius: 27, - shadowOffset: { width: 30, height: 30 }, - }, - }, - duration: { base: 300, long: 700, short: 100, veryLong: 3000 }, - measurement: { - baseSpace01: 4, - baseSpace02: 8, - baseSpace03: 12, - baseSpace04: 16, - baseSpace05: 32, - baseSpace06: 48, - baseSpace07: 64, - baseSpace08: 80, - baseSpace09: 96, - baseSpace10: 112, - }, - textStyle: { - body: { - fontWeight: \\"500\\", - fontSize: 14, - lineHeight: 20, - fontFamily: \\"Inter-Medium\\", - color: \\"rgb(30, 33, 43)\\", - letterSpacing: 10, - }, - bodyWithOpacity: { - fontWeight: \\"500\\", - fontSize: 14, - lineHeight: 20, - fontFamily: \\"Inter-Medium\\", - color: \\"rgba(30, 33, 43, 0.3)\\", - letterSpacing: 10, - }, - code: { - fontWeight: \\"500\\", - fontSize: 13, - lineHeight: 20, - fontFamily: \\"FiraCode-Medium\\", - color: \\"rgb(255, 142, 5)\\", - }, - list: { - fontWeight: \\"400\\", - fontSize: 14, - lineHeight: 20, - fontFamily: \\"Roboto-Regular\\", - }, - title: { - fontWeight: \\"600\\", - fontSize: 32, - lineHeight: 40, - fontFamily: \\"Inter-SemiBold\\", - color: \\"rgb(30, 33, 43)\\", - }, - }, - border: { - borderAccent: { - borderWidth: 2, - borderStyle: \\"solid\\", - borderColor: \\"rgb(102, 80, 239)\\", - borderRadius: 16, - }, - borderAccentWithOpacity: { - borderWidth: 2, - borderStyle: \\"solid\\", - borderColor: \\"rgba(102, 80, 239, 0.5)\\", - borderRadius: 16, - }, - borderAccentWithoutRadii: { - borderWidth: 2, - borderStyle: \\"solid\\", - borderColor: \\"rgba(102, 80, 239, 0.5)\\", - }, - borderDashed: { - borderWidth: 1, - borderStyle: \\"dashed\\", - borderColor: \\"rgb(30, 33, 43)\\", - borderRadius: 16, - }, - }, - color: { - colorsAccent: \\"rgb(87, 124, 254)\\", - colorsBlack: \\"rgb(30, 33, 43)\\", - colorsGreen: \\"rgb(88, 205, 82)\\", - colorsGrey: \\"rgb(204, 213, 225)\\", - colorsOrange: \\"rgb(255, 142, 5)\\", - colorsRed: \\"rgb(245, 72, 63)\\", - colorsWhite: \\"rgb(255, 255, 255)\\", - }, - font: { - firaCodeMedium: \\"FiraCode-Medium\\", - interMedium: \\"Inter-Medium\\", - interSemiBold: \\"Inter-SemiBold\\", - robotoRegular: \\"Roboto-Regular\\", - }, - gradient: { - gradientsColored: [ - { - angle: 90, - colors: [\\"rgb(245, 72, 63)\\", \\"rgb(255, 142, 5)\\"], - locations: [0, 1], - }, - ], - gradientsDark: [ - { - angle: 90, - colors: [\\"rgb(30, 33, 43)\\", \\"rgb(204, 213, 225)\\"], - locations: [0, 1], - }, - ], - gradientsNeutral: [ - { - angle: 90, - colors: [\\"rgb(204, 213, 225)\\", \\"rgb(255, 255, 255)\\"], - locations: [0, 1], - }, - ], - gradientsSafari: [ - { - angle: 90, - colors: [\\"rgb(255, 142, 5)\\", \\"rgb(255, 255, 255)\\"], - locations: [0, 1], - }, - ], - }, - opacity: { subtle: 0.5, transparent: 0.1, visible: 0.95 }, -}; -export default theme; -" -`; - -exports[`To React Native Should support different formatName options 2`] = ` -"import bitmapAcmeLogo from \\"./path/acme-logo.png\\"; -import bitmapPhotoExample from \\"./path/photo-example.png\\"; -import vectorActivity from \\"./path/activity.svg\\"; -import vectorAirplay from \\"./path/airplay.svg\\"; -import vectorAlertCircle from \\"./path/alert-circle.svg\\"; -import vectorAlertOctagon from \\"./path/alert-octagon.svg\\"; -import vectorAlertTriangle from \\"./path/alert-triangle.pdf\\"; -import vectorAlertTriangle from \\"./path/alert-triangle.svg\\"; -import vectorAlignCenter from \\"./path/align-center.svg\\"; -import vectorAlignCenter from \\"./path/align-center.pdf\\"; -import vectorUserMask from \\"./path/user-mask.svg\\"; -import vectorUserMask from \\"./path/user-mask.pdf\\"; - -const theme = { - bitmap: { acmeLogo: bitmapAcmeLogo, photoExample: bitmapPhotoExample }, - vector: { - activity: vectorActivity, - airplay: vectorAirplay, - alertCircle: vectorAlertCircle, - alertOctagon: vectorAlertOctagon, - alertTriangle: vectorAlertTriangle, - alertTriangle: vectorAlertTriangle, - alignCenter: vectorAlignCenter, - alignCenter: vectorAlignCenter, - userMask: vectorUserMask, - userMask: vectorUserMask, - }, - depth: { - background: { - elevation: 1, - shadowOpacity: 0.1815, - shadowRadius: 0.54, - shadowOffset: { width: 0.6, height: 0.6 }, - }, - foreground: { - elevation: 100, - shadowOpacity: 0.32999999999999996, - shadowRadius: 54, - shadowOffset: { width: 60, height: 60 }, - }, - middle: { - elevation: 50, - shadowOpacity: 0.255, - shadowRadius: 27, - shadowOffset: { width: 30, height: 30 }, - }, - }, - duration: { base: 300, long: 700, short: 100, veryLong: 3000 }, - measurement: { - baseSpace01: 4, - baseSpace02: 8, - baseSpace03: 12, - baseSpace04: 16, - baseSpace05: 32, - baseSpace06: 48, - baseSpace07: 64, - baseSpace08: 80, - baseSpace09: 96, - baseSpace10: 112, - }, - textStyle: { - body: { - fontWeight: \\"500\\", - fontSize: 14, - lineHeight: 20, - fontFamily: \\"Inter-Medium\\", - color: \\"rgb(30, 33, 43)\\", - letterSpacing: 10, - }, - bodyWithOpacity: { - fontWeight: \\"500\\", - fontSize: 14, - lineHeight: 20, - fontFamily: \\"Inter-Medium\\", - color: \\"rgba(30, 33, 43, 0.3)\\", - letterSpacing: 10, - }, - code: { - fontWeight: \\"500\\", - fontSize: 13, - lineHeight: 20, - fontFamily: \\"FiraCode-Medium\\", - color: \\"rgb(255, 142, 5)\\", - }, - list: { - fontWeight: \\"400\\", - fontSize: 14, - lineHeight: 20, - fontFamily: \\"Roboto-Regular\\", - }, - title: { - fontWeight: \\"600\\", - fontSize: 32, - lineHeight: 40, - fontFamily: \\"Inter-SemiBold\\", - color: \\"rgb(30, 33, 43)\\", - }, - }, - border: { - borderAccent: { - borderWidth: 2, - borderStyle: \\"solid\\", - borderColor: \\"rgb(102, 80, 239)\\", - borderRadius: 16, - }, - borderAccentWithOpacity: { - borderWidth: 2, - borderStyle: \\"solid\\", - borderColor: \\"rgba(102, 80, 239, 0.5)\\", - borderRadius: 16, - }, - borderAccentWithoutRadii: { - borderWidth: 2, - borderStyle: \\"solid\\", - borderColor: \\"rgba(102, 80, 239, 0.5)\\", - }, - borderDashed: { - borderWidth: 1, - borderStyle: \\"dashed\\", - borderColor: \\"rgb(30, 33, 43)\\", - borderRadius: 16, - }, - }, - color: { - colorsAccent: \\"rgb(87, 124, 254)\\", - colorsBlack: \\"rgb(30, 33, 43)\\", - colorsGreen: \\"rgb(88, 205, 82)\\", - colorsGrey: \\"rgb(204, 213, 225)\\", - colorsOrange: \\"rgb(255, 142, 5)\\", - colorsRed: \\"rgb(245, 72, 63)\\", - colorsWhite: \\"rgb(255, 255, 255)\\", - }, - font: { - firaCodeMedium: \\"FiraCode-Medium\\", - interMedium: \\"Inter-Medium\\", - interSemiBold: \\"Inter-SemiBold\\", - robotoRegular: \\"Roboto-Regular\\", - }, - gradient: { - gradientsColored: [ - { - angle: 90, - colors: [\\"rgb(245, 72, 63)\\", \\"rgb(255, 142, 5)\\"], - locations: [0, 1], - }, - ], - gradientsDark: [ - { - angle: 90, - colors: [\\"rgb(30, 33, 43)\\", \\"rgb(204, 213, 225)\\"], - locations: [0, 1], - }, - ], - gradientsNeutral: [ - { - angle: 90, - colors: [\\"rgb(204, 213, 225)\\", \\"rgb(255, 255, 255)\\"], - locations: [0, 1], - }, - ], - gradientsSafari: [ - { - angle: 90, - colors: [\\"rgb(255, 142, 5)\\", \\"rgb(255, 255, 255)\\"], - locations: [0, 1], - }, - ], - }, - opacity: { subtle: 0.5, transparent: 0.1, visible: 0.95 }, -}; -export default theme; -" -`; - -exports[`To React Native Should support different formatName options 3`] = ` -"import bitmapAcmeLogo from \\"./path/acme_logo.png\\"; -import bitmapPhotoExample from \\"./path/photo_example.png\\"; -import vectorActivity from \\"./path/activity.svg\\"; -import vectorAirplay from \\"./path/airplay.svg\\"; -import vectorAlertCircle from \\"./path/alert_circle.svg\\"; -import vectorAlertOctagon from \\"./path/alert_octagon.svg\\"; -import vectorAlertTriangle from \\"./path/alert_triangle.pdf\\"; -import vectorAlertTriangle from \\"./path/alert_triangle.svg\\"; -import vectorAlignCenter from \\"./path/align_center.svg\\"; -import vectorAlignCenter from \\"./path/align_center.pdf\\"; -import vectorUserMask from \\"./path/user_mask.svg\\"; -import vectorUserMask from \\"./path/user_mask.pdf\\"; - -const theme = { - bitmap: { acmeLogo: bitmapAcmeLogo, photoExample: bitmapPhotoExample }, - vector: { - activity: vectorActivity, - airplay: vectorAirplay, - alertCircle: vectorAlertCircle, - alertOctagon: vectorAlertOctagon, - alertTriangle: vectorAlertTriangle, - alertTriangle: vectorAlertTriangle, - alignCenter: vectorAlignCenter, - alignCenter: vectorAlignCenter, - userMask: vectorUserMask, - userMask: vectorUserMask, - }, - depth: { - background: { - elevation: 1, - shadowOpacity: 0.1815, - shadowRadius: 0.54, - shadowOffset: { width: 0.6, height: 0.6 }, - }, - foreground: { - elevation: 100, - shadowOpacity: 0.32999999999999996, - shadowRadius: 54, - shadowOffset: { width: 60, height: 60 }, - }, - middle: { - elevation: 50, - shadowOpacity: 0.255, - shadowRadius: 27, - shadowOffset: { width: 30, height: 30 }, - }, - }, - duration: { base: 300, long: 700, short: 100, veryLong: 3000 }, - measurement: { - baseSpace01: 4, - baseSpace02: 8, - baseSpace03: 12, - baseSpace04: 16, - baseSpace05: 32, - baseSpace06: 48, - baseSpace07: 64, - baseSpace08: 80, - baseSpace09: 96, - baseSpace10: 112, - }, - textStyle: { - body: { - fontWeight: \\"500\\", - fontSize: 14, - lineHeight: 20, - fontFamily: \\"Inter-Medium\\", - color: \\"rgb(30, 33, 43)\\", - letterSpacing: 10, - }, - bodyWithOpacity: { - fontWeight: \\"500\\", - fontSize: 14, - lineHeight: 20, - fontFamily: \\"Inter-Medium\\", - color: \\"rgba(30, 33, 43, 0.3)\\", - letterSpacing: 10, - }, - code: { - fontWeight: \\"500\\", - fontSize: 13, - lineHeight: 20, - fontFamily: \\"FiraCode-Medium\\", - color: \\"rgb(255, 142, 5)\\", - }, - list: { - fontWeight: \\"400\\", - fontSize: 14, - lineHeight: 20, - fontFamily: \\"Roboto-Regular\\", - }, - title: { - fontWeight: \\"600\\", - fontSize: 32, - lineHeight: 40, - fontFamily: \\"Inter-SemiBold\\", - color: \\"rgb(30, 33, 43)\\", - }, - }, - border: { - borderAccent: { - borderWidth: 2, - borderStyle: \\"solid\\", - borderColor: \\"rgb(102, 80, 239)\\", - borderRadius: 16, - }, - borderAccentWithOpacity: { - borderWidth: 2, - borderStyle: \\"solid\\", - borderColor: \\"rgba(102, 80, 239, 0.5)\\", - borderRadius: 16, - }, - borderAccentWithoutRadii: { - borderWidth: 2, - borderStyle: \\"solid\\", - borderColor: \\"rgba(102, 80, 239, 0.5)\\", - }, - borderDashed: { - borderWidth: 1, - borderStyle: \\"dashed\\", - borderColor: \\"rgb(30, 33, 43)\\", - borderRadius: 16, - }, - }, - color: { - colorsAccent: \\"rgb(87, 124, 254)\\", - colorsBlack: \\"rgb(30, 33, 43)\\", - colorsGreen: \\"rgb(88, 205, 82)\\", - colorsGrey: \\"rgb(204, 213, 225)\\", - colorsOrange: \\"rgb(255, 142, 5)\\", - colorsRed: \\"rgb(245, 72, 63)\\", - colorsWhite: \\"rgb(255, 255, 255)\\", - }, - font: { - firaCodeMedium: \\"FiraCode-Medium\\", - interMedium: \\"Inter-Medium\\", - interSemiBold: \\"Inter-SemiBold\\", - robotoRegular: \\"Roboto-Regular\\", - }, - gradient: { - gradientsColored: [ - { - angle: 90, - colors: [\\"rgb(245, 72, 63)\\", \\"rgb(255, 142, 5)\\"], - locations: [0, 1], - }, - ], - gradientsDark: [ - { - angle: 90, - colors: [\\"rgb(30, 33, 43)\\", \\"rgb(204, 213, 225)\\"], - locations: [0, 1], - }, - ], - gradientsNeutral: [ - { - angle: 90, - colors: [\\"rgb(204, 213, 225)\\", \\"rgb(255, 255, 255)\\"], - locations: [0, 1], - }, - ], - gradientsSafari: [ - { - angle: 90, - colors: [\\"rgb(255, 142, 5)\\", \\"rgb(255, 255, 255)\\"], - locations: [0, 1], - }, - ], - }, - opacity: { subtle: 0.5, transparent: 0.1, visible: 0.95 }, -}; -export default theme; -" -`; - -exports[`To React Native Should support different formatName options 4`] = ` -"import bitmapAcmeLogo from \\"./path/AcmeLogo.png\\"; -import bitmapPhotoExample from \\"./path/PhotoExample.png\\"; -import vectorActivity from \\"./path/Activity.svg\\"; -import vectorAirplay from \\"./path/Airplay.svg\\"; -import vectorAlertCircle from \\"./path/AlertCircle.svg\\"; -import vectorAlertOctagon from \\"./path/AlertOctagon.svg\\"; -import vectorAlertTriangle from \\"./path/AlertTriangle.pdf\\"; -import vectorAlertTriangle from \\"./path/AlertTriangle.svg\\"; -import vectorAlignCenter from \\"./path/AlignCenter.svg\\"; -import vectorAlignCenter from \\"./path/AlignCenter.pdf\\"; -import vectorUserMask from \\"./path/UserMask.svg\\"; -import vectorUserMask from \\"./path/UserMask.pdf\\"; - -const theme = { - bitmap: { acmeLogo: bitmapAcmeLogo, photoExample: bitmapPhotoExample }, - vector: { - activity: vectorActivity, - airplay: vectorAirplay, - alertCircle: vectorAlertCircle, - alertOctagon: vectorAlertOctagon, - alertTriangle: vectorAlertTriangle, - alertTriangle: vectorAlertTriangle, - alignCenter: vectorAlignCenter, - alignCenter: vectorAlignCenter, - userMask: vectorUserMask, - userMask: vectorUserMask, - }, - depth: { - background: { - elevation: 1, - shadowOpacity: 0.1815, - shadowRadius: 0.54, - shadowOffset: { width: 0.6, height: 0.6 }, - }, - foreground: { - elevation: 100, - shadowOpacity: 0.32999999999999996, - shadowRadius: 54, - shadowOffset: { width: 60, height: 60 }, - }, - middle: { - elevation: 50, - shadowOpacity: 0.255, - shadowRadius: 27, - shadowOffset: { width: 30, height: 30 }, - }, - }, - duration: { base: 300, long: 700, short: 100, veryLong: 3000 }, - measurement: { - baseSpace01: 4, - baseSpace02: 8, - baseSpace03: 12, - baseSpace04: 16, - baseSpace05: 32, - baseSpace06: 48, - baseSpace07: 64, - baseSpace08: 80, - baseSpace09: 96, - baseSpace10: 112, - }, - textStyle: { - body: { - fontWeight: \\"500\\", - fontSize: 14, - lineHeight: 20, - fontFamily: \\"Inter-Medium\\", - color: \\"rgb(30, 33, 43)\\", - letterSpacing: 10, - }, - bodyWithOpacity: { - fontWeight: \\"500\\", - fontSize: 14, - lineHeight: 20, - fontFamily: \\"Inter-Medium\\", - color: \\"rgba(30, 33, 43, 0.3)\\", - letterSpacing: 10, - }, - code: { - fontWeight: \\"500\\", - fontSize: 13, - lineHeight: 20, - fontFamily: \\"FiraCode-Medium\\", - color: \\"rgb(255, 142, 5)\\", - }, - list: { - fontWeight: \\"400\\", - fontSize: 14, - lineHeight: 20, - fontFamily: \\"Roboto-Regular\\", - }, - title: { - fontWeight: \\"600\\", - fontSize: 32, - lineHeight: 40, - fontFamily: \\"Inter-SemiBold\\", - color: \\"rgb(30, 33, 43)\\", - }, - }, - border: { - borderAccent: { - borderWidth: 2, - borderStyle: \\"solid\\", - borderColor: \\"rgb(102, 80, 239)\\", - borderRadius: 16, - }, - borderAccentWithOpacity: { - borderWidth: 2, - borderStyle: \\"solid\\", - borderColor: \\"rgba(102, 80, 239, 0.5)\\", - borderRadius: 16, - }, - borderAccentWithoutRadii: { - borderWidth: 2, - borderStyle: \\"solid\\", - borderColor: \\"rgba(102, 80, 239, 0.5)\\", - }, - borderDashed: { - borderWidth: 1, - borderStyle: \\"dashed\\", - borderColor: \\"rgb(30, 33, 43)\\", - borderRadius: 16, - }, - }, - color: { - colorsAccent: \\"rgb(87, 124, 254)\\", - colorsBlack: \\"rgb(30, 33, 43)\\", - colorsGreen: \\"rgb(88, 205, 82)\\", - colorsGrey: \\"rgb(204, 213, 225)\\", - colorsOrange: \\"rgb(255, 142, 5)\\", - colorsRed: \\"rgb(245, 72, 63)\\", - colorsWhite: \\"rgb(255, 255, 255)\\", - }, - font: { - firaCodeMedium: \\"FiraCode-Medium\\", - interMedium: \\"Inter-Medium\\", - interSemiBold: \\"Inter-SemiBold\\", - robotoRegular: \\"Roboto-Regular\\", - }, - gradient: { - gradientsColored: [ - { - angle: 90, - colors: [\\"rgb(245, 72, 63)\\", \\"rgb(255, 142, 5)\\"], - locations: [0, 1], - }, - ], - gradientsDark: [ - { - angle: 90, - colors: [\\"rgb(30, 33, 43)\\", \\"rgb(204, 213, 225)\\"], - locations: [0, 1], - }, - ], - gradientsNeutral: [ - { - angle: 90, - colors: [\\"rgb(204, 213, 225)\\", \\"rgb(255, 255, 255)\\"], - locations: [0, 1], - }, - ], - gradientsSafari: [ - { - angle: 90, - colors: [\\"rgb(255, 142, 5)\\", \\"rgb(255, 255, 255)\\"], - locations: [0, 1], - }, - ], - }, - opacity: { subtle: 0.5, transparent: 0.1, visible: 0.95 }, -}; -export default theme; -" -`; - -exports[`To React Native Should support different formatName options 5`] = ` -"import bitmapAcmeLogo from \\"./path/acme-logo.png\\"; -import bitmapPhotoExample from \\"./path/photo-example.png\\"; -import vectorActivity from \\"./path/activity.svg\\"; -import vectorAirplay from \\"./path/airplay.svg\\"; -import vectorAlertCircle from \\"./path/alert-circle.svg\\"; -import vectorAlertOctagon from \\"./path/alert-octagon.svg\\"; -import vectorAlertTriangle from \\"./path/alert-triangle.pdf\\"; -import vectorAlertTriangle from \\"./path/alert-triangle.svg\\"; -import vectorAlignCenter from \\"./path/align-center.svg\\"; -import vectorAlignCenter from \\"./path/align-center.pdf\\"; -import vectorUserMask from \\"./path/user-mask.svg\\"; -import vectorUserMask from \\"./path/user-mask.pdf\\"; - -const theme = { - bitmap: { acmeLogo: bitmapAcmeLogo, photoExample: bitmapPhotoExample }, - vector: { - activity: vectorActivity, - airplay: vectorAirplay, - alertCircle: vectorAlertCircle, - alertOctagon: vectorAlertOctagon, - alertTriangle: vectorAlertTriangle, - alertTriangle: vectorAlertTriangle, - alignCenter: vectorAlignCenter, - alignCenter: vectorAlignCenter, - userMask: vectorUserMask, - userMask: vectorUserMask, - }, - depth: { - background: { - elevation: 1, - shadowOpacity: 0.1815, - shadowRadius: 0.54, - shadowOffset: { width: 0.6, height: 0.6 }, - }, - foreground: { - elevation: 100, - shadowOpacity: 0.32999999999999996, - shadowRadius: 54, - shadowOffset: { width: 60, height: 60 }, - }, - middle: { - elevation: 50, - shadowOpacity: 0.255, - shadowRadius: 27, - shadowOffset: { width: 30, height: 30 }, - }, - }, - duration: { base: 300, long: 700, short: 100, veryLong: 3000 }, - measurement: { - baseSpace01: 4, - baseSpace02: 8, - baseSpace03: 12, - baseSpace04: 16, - baseSpace05: 32, - baseSpace06: 48, - baseSpace07: 64, - baseSpace08: 80, - baseSpace09: 96, - baseSpace10: 112, - }, - textStyle: { - body: { - fontWeight: \\"500\\", - fontSize: 14, - lineHeight: 20, - fontFamily: \\"Inter-Medium\\", - color: \\"rgb(30, 33, 43)\\", - letterSpacing: 10, - }, - bodyWithOpacity: { - fontWeight: \\"500\\", - fontSize: 14, - lineHeight: 20, - fontFamily: \\"Inter-Medium\\", - color: \\"rgba(30, 33, 43, 0.3)\\", - letterSpacing: 10, - }, - code: { - fontWeight: \\"500\\", - fontSize: 13, - lineHeight: 20, - fontFamily: \\"FiraCode-Medium\\", - color: \\"rgb(255, 142, 5)\\", - }, - list: { - fontWeight: \\"400\\", - fontSize: 14, - lineHeight: 20, - fontFamily: \\"Roboto-Regular\\", - }, - title: { - fontWeight: \\"600\\", - fontSize: 32, - lineHeight: 40, - fontFamily: \\"Inter-SemiBold\\", - color: \\"rgb(30, 33, 43)\\", - }, - }, - border: { - borderAccent: { - borderWidth: 2, - borderStyle: \\"solid\\", - borderColor: \\"rgb(102, 80, 239)\\", - borderRadius: 16, - }, - borderAccentWithOpacity: { - borderWidth: 2, - borderStyle: \\"solid\\", - borderColor: \\"rgba(102, 80, 239, 0.5)\\", - borderRadius: 16, - }, - borderAccentWithoutRadii: { - borderWidth: 2, - borderStyle: \\"solid\\", - borderColor: \\"rgba(102, 80, 239, 0.5)\\", - }, - borderDashed: { - borderWidth: 1, - borderStyle: \\"dashed\\", - borderColor: \\"rgb(30, 33, 43)\\", - borderRadius: 16, - }, - }, - color: { - colorsAccent: \\"rgb(87, 124, 254)\\", - colorsBlack: \\"rgb(30, 33, 43)\\", - colorsGreen: \\"rgb(88, 205, 82)\\", - colorsGrey: \\"rgb(204, 213, 225)\\", - colorsOrange: \\"rgb(255, 142, 5)\\", - colorsRed: \\"rgb(245, 72, 63)\\", - colorsWhite: \\"rgb(255, 255, 255)\\", - }, - font: { - firaCodeMedium: \\"FiraCode-Medium\\", - interMedium: \\"Inter-Medium\\", - interSemiBold: \\"Inter-SemiBold\\", - robotoRegular: \\"Roboto-Regular\\", - }, - gradient: { - gradientsColored: [ - { - angle: 90, - colors: [\\"rgb(245, 72, 63)\\", \\"rgb(255, 142, 5)\\"], - locations: [0, 1], - }, - ], - gradientsDark: [ - { - angle: 90, - colors: [\\"rgb(30, 33, 43)\\", \\"rgb(204, 213, 225)\\"], - locations: [0, 1], - }, - ], - gradientsNeutral: [ - { - angle: 90, - colors: [\\"rgb(204, 213, 225)\\", \\"rgb(255, 255, 255)\\"], - locations: [0, 1], - }, - ], - gradientsSafari: [ - { - angle: 90, - colors: [\\"rgb(255, 142, 5)\\", \\"rgb(255, 255, 255)\\"], - locations: [0, 1], - }, - ], - }, - opacity: { subtle: 0.5, transparent: 0.1, visible: 0.95 }, -}; -export default theme; -" -`; - -exports[`To React Native Should support the typescript.castToConst option 1`] = ` -"import bitmapAcmeLogo from \\"./path/acmeLogo.png\\"; -import bitmapPhotoExample from \\"./path/photoExample.png\\"; -import vectorActivity from \\"./path/activity.svg\\"; -import vectorAirplay from \\"./path/airplay.svg\\"; -import vectorAlertCircle from \\"./path/alertCircle.svg\\"; -import vectorAlertOctagon from \\"./path/alertOctagon.svg\\"; -import vectorAlertTriangle from \\"./path/alertTriangle.pdf\\"; -import vectorAlertTriangle from \\"./path/alertTriangle.svg\\"; -import vectorAlignCenter from \\"./path/alignCenter.svg\\"; -import vectorAlignCenter from \\"./path/alignCenter.pdf\\"; -import vectorUserMask from \\"./path/userMask.svg\\"; -import vectorUserMask from \\"./path/userMask.pdf\\"; - -const theme = { - bitmap: { acmeLogo: bitmapAcmeLogo, photoExample: bitmapPhotoExample }, - vector: { - activity: vectorActivity, - airplay: vectorAirplay, - alertCircle: vectorAlertCircle, - alertOctagon: vectorAlertOctagon, - alertTriangle: vectorAlertTriangle, - alertTriangle: vectorAlertTriangle, - alignCenter: vectorAlignCenter, - alignCenter: vectorAlignCenter, - userMask: vectorUserMask, - userMask: vectorUserMask, - }, - depth: { - background: { - elevation: 1, - shadowOpacity: 0.1815, - shadowRadius: 0.54, - shadowOffset: { width: 0.6, height: 0.6 }, - }, - foreground: { - elevation: 100, - shadowOpacity: 0.32999999999999996, - shadowRadius: 54, - shadowOffset: { width: 60, height: 60 }, - }, - middle: { - elevation: 50, - shadowOpacity: 0.255, - shadowRadius: 27, - shadowOffset: { width: 30, height: 30 }, - }, - }, - duration: { base: 300, long: 700, short: 100, veryLong: 3000 }, - measurement: { - baseSpace01: 4, - baseSpace02: 8, - baseSpace03: 12, - baseSpace04: 16, - baseSpace05: 32, - baseSpace06: 48, - baseSpace07: 64, - baseSpace08: 80, - baseSpace09: 96, - baseSpace10: 112, - }, - textStyle: { - body: { - fontWeight: \\"500\\", - fontSize: 14, - lineHeight: 20, - fontFamily: \\"Inter-Medium\\", - color: \\"rgb(30, 33, 43)\\", - letterSpacing: 10, - }, - bodyWithOpacity: { - fontWeight: \\"500\\", - fontSize: 14, - lineHeight: 20, - fontFamily: \\"Inter-Medium\\", - color: \\"rgba(30, 33, 43, 0.3)\\", - letterSpacing: 10, - }, - code: { - fontWeight: \\"500\\", - fontSize: 13, - lineHeight: 20, - fontFamily: \\"FiraCode-Medium\\", - color: \\"rgb(255, 142, 5)\\", - }, - list: { - fontWeight: \\"400\\", - fontSize: 14, - lineHeight: 20, - fontFamily: \\"Roboto-Regular\\", - }, - title: { - fontWeight: \\"600\\", - fontSize: 32, - lineHeight: 40, - fontFamily: \\"Inter-SemiBold\\", - color: \\"rgb(30, 33, 43)\\", - }, - }, - border: { - borderAccent: { - borderWidth: 2, - borderStyle: \\"solid\\", - borderColor: \\"rgb(102, 80, 239)\\", - borderRadius: 16, - }, - borderAccentWithOpacity: { - borderWidth: 2, - borderStyle: \\"solid\\", - borderColor: \\"rgba(102, 80, 239, 0.5)\\", - borderRadius: 16, - }, - borderAccentWithoutRadii: { - borderWidth: 2, - borderStyle: \\"solid\\", - borderColor: \\"rgba(102, 80, 239, 0.5)\\", - }, - borderDashed: { - borderWidth: 1, - borderStyle: \\"dashed\\", - borderColor: \\"rgb(30, 33, 43)\\", - borderRadius: 16, - }, - }, - color: { - colorsAccent: \\"rgb(87, 124, 254)\\", - colorsBlack: \\"rgb(30, 33, 43)\\", - colorsGreen: \\"rgb(88, 205, 82)\\", - colorsGrey: \\"rgb(204, 213, 225)\\", - colorsOrange: \\"rgb(255, 142, 5)\\", - colorsRed: \\"rgb(245, 72, 63)\\", - colorsWhite: \\"rgb(255, 255, 255)\\", - }, - font: { - firaCodeMedium: \\"FiraCode-Medium\\", - interMedium: \\"Inter-Medium\\", - interSemiBold: \\"Inter-SemiBold\\", - robotoRegular: \\"Roboto-Regular\\", - }, - gradient: { - gradientsColored: [ - { - angle: 90, - colors: [\\"rgb(245, 72, 63)\\", \\"rgb(255, 142, 5)\\"], - locations: [0, 1], - }, - ], - gradientsDark: [ - { - angle: 90, - colors: [\\"rgb(30, 33, 43)\\", \\"rgb(204, 213, 225)\\"], - locations: [0, 1], - }, - ], - gradientsNeutral: [ - { - angle: 90, - colors: [\\"rgb(204, 213, 225)\\", \\"rgb(255, 255, 255)\\"], - locations: [0, 1], - }, - ], - gradientsSafari: [ - { - angle: 90, - colors: [\\"rgb(255, 142, 5)\\", \\"rgb(255, 255, 255)\\"], - locations: [0, 1], - }, - ], - }, - opacity: { subtle: 0.5, transparent: 0.1, visible: 0.95 }, -} as const; -export default theme; -" -`; - -exports[`To React Native Should use assetsFolderPath 1`] = ` -"import bitmapAcmeLogo from \\"./path/acmeLogo.png\\"; -import bitmapPhotoExample from \\"./path/photoExample.png\\"; -import vectorActivity from \\"./path/activity.svg\\"; -import vectorAirplay from \\"./path/airplay.svg\\"; -import vectorAlertCircle from \\"./path/alertCircle.svg\\"; -import vectorAlertOctagon from \\"./path/alertOctagon.svg\\"; -import vectorAlertTriangle from \\"./path/alertTriangle.pdf\\"; -import vectorAlertTriangle from \\"./path/alertTriangle.svg\\"; -import vectorAlignCenter from \\"./path/alignCenter.svg\\"; -import vectorAlignCenter from \\"./path/alignCenter.pdf\\"; -import vectorUserMask from \\"./path/userMask.svg\\"; -import vectorUserMask from \\"./path/userMask.pdf\\"; - -const theme = { - bitmap: { acmeLogo: bitmapAcmeLogo, photoExample: bitmapPhotoExample }, - vector: { - activity: vectorActivity, - airplay: vectorAirplay, - alertCircle: vectorAlertCircle, - alertOctagon: vectorAlertOctagon, - alertTriangle: vectorAlertTriangle, - alertTriangle: vectorAlertTriangle, - alignCenter: vectorAlignCenter, - alignCenter: vectorAlignCenter, - userMask: vectorUserMask, - userMask: vectorUserMask, - }, - depth: { - background: { - elevation: 1, - shadowOpacity: 0.1815, - shadowRadius: 0.54, - shadowOffset: { width: 0.6, height: 0.6 }, - }, - foreground: { - elevation: 100, - shadowOpacity: 0.32999999999999996, - shadowRadius: 54, - shadowOffset: { width: 60, height: 60 }, - }, - middle: { - elevation: 50, - shadowOpacity: 0.255, - shadowRadius: 27, - shadowOffset: { width: 30, height: 30 }, - }, - }, - duration: { base: 300, long: 700, short: 100, veryLong: 3000 }, - measurement: { - baseSpace01: 4, - baseSpace02: 8, - baseSpace03: 12, - baseSpace04: 16, - baseSpace05: 32, - baseSpace06: 48, - baseSpace07: 64, - baseSpace08: 80, - baseSpace09: 96, - baseSpace10: 112, - }, - textStyle: { - body: { - fontWeight: \\"500\\", - fontSize: 14, - lineHeight: 20, - fontFamily: \\"Inter-Medium\\", - color: \\"rgb(30, 33, 43)\\", - letterSpacing: 10, - }, - bodyWithOpacity: { - fontWeight: \\"500\\", - fontSize: 14, - lineHeight: 20, - fontFamily: \\"Inter-Medium\\", - color: \\"rgba(30, 33, 43, 0.3)\\", - letterSpacing: 10, - }, - code: { - fontWeight: \\"500\\", - fontSize: 13, - lineHeight: 20, - fontFamily: \\"FiraCode-Medium\\", - color: \\"rgb(255, 142, 5)\\", - }, - list: { - fontWeight: \\"400\\", - fontSize: 14, - lineHeight: 20, - fontFamily: \\"Roboto-Regular\\", - }, - title: { - fontWeight: \\"600\\", - fontSize: 32, - lineHeight: 40, - fontFamily: \\"Inter-SemiBold\\", - color: \\"rgb(30, 33, 43)\\", - }, - }, - border: { - borderAccent: { - borderWidth: 2, - borderStyle: \\"solid\\", - borderColor: \\"rgb(102, 80, 239)\\", - borderRadius: 16, - }, - borderAccentWithOpacity: { - borderWidth: 2, - borderStyle: \\"solid\\", - borderColor: \\"rgba(102, 80, 239, 0.5)\\", - borderRadius: 16, - }, - borderAccentWithoutRadii: { - borderWidth: 2, - borderStyle: \\"solid\\", - borderColor: \\"rgba(102, 80, 239, 0.5)\\", - }, - borderDashed: { - borderWidth: 1, - borderStyle: \\"dashed\\", - borderColor: \\"rgb(30, 33, 43)\\", - borderRadius: 16, - }, - }, - color: { - colorsAccent: \\"rgb(87, 124, 254)\\", - colorsBlack: \\"rgb(30, 33, 43)\\", - colorsGreen: \\"rgb(88, 205, 82)\\", - colorsGrey: \\"rgb(204, 213, 225)\\", - colorsOrange: \\"rgb(255, 142, 5)\\", - colorsRed: \\"rgb(245, 72, 63)\\", - colorsWhite: \\"rgb(255, 255, 255)\\", - }, - font: { - firaCodeMedium: \\"FiraCode-Medium\\", - interMedium: \\"Inter-Medium\\", - interSemiBold: \\"Inter-SemiBold\\", - robotoRegular: \\"Roboto-Regular\\", - }, - gradient: { - gradientsColored: [ - { - angle: 90, - colors: [\\"rgb(245, 72, 63)\\", \\"rgb(255, 142, 5)\\"], - locations: [0, 1], - }, - ], - gradientsDark: [ - { - angle: 90, - colors: [\\"rgb(30, 33, 43)\\", \\"rgb(204, 213, 225)\\"], - locations: [0, 1], - }, - ], - gradientsNeutral: [ - { - angle: 90, - colors: [\\"rgb(204, 213, 225)\\", \\"rgb(255, 255, 255)\\"], - locations: [0, 1], - }, - ], - gradientsSafari: [ - { - angle: 90, - colors: [\\"rgb(255, 142, 5)\\", \\"rgb(255, 255, 255)\\"], - locations: [0, 1], - }, - ], - }, - opacity: { subtle: 0.5, transparent: 0.1, visible: 0.95 }, -}; -export default theme; -" -`; - -exports[`To React Native Should use assetsFolderPath 2`] = ` -"import bitmapAcmeLogo from \\"./path/acmeLogo.png\\"; -import bitmapPhotoExample from \\"./path/photoExample.png\\"; -import vectorActivity from \\"./path/activity.svg\\"; -import vectorAirplay from \\"./path/airplay.svg\\"; -import vectorAlertCircle from \\"./path/alertCircle.svg\\"; -import vectorAlertOctagon from \\"./path/alertOctagon.svg\\"; -import vectorAlertTriangle from \\"./path/alertTriangle.pdf\\"; -import vectorAlertTriangle from \\"./path/alertTriangle.svg\\"; -import vectorAlignCenter from \\"./path/alignCenter.svg\\"; -import vectorAlignCenter from \\"./path/alignCenter.pdf\\"; -import vectorUserMask from \\"./path/userMask.svg\\"; -import vectorUserMask from \\"./path/userMask.pdf\\"; - -const theme = { - bitmap: { acmeLogo: bitmapAcmeLogo, photoExample: bitmapPhotoExample }, - vector: { - activity: vectorActivity, - airplay: vectorAirplay, - alertCircle: vectorAlertCircle, - alertOctagon: vectorAlertOctagon, - alertTriangle: vectorAlertTriangle, - alertTriangle: vectorAlertTriangle, - alignCenter: vectorAlignCenter, - alignCenter: vectorAlignCenter, - userMask: vectorUserMask, - userMask: vectorUserMask, - }, - depth: { - background: { - elevation: 1, - shadowOpacity: 0.1815, - shadowRadius: 0.54, - shadowOffset: { width: 0.6, height: 0.6 }, - }, - foreground: { - elevation: 100, - shadowOpacity: 0.32999999999999996, - shadowRadius: 54, - shadowOffset: { width: 60, height: 60 }, - }, - middle: { - elevation: 50, - shadowOpacity: 0.255, - shadowRadius: 27, - shadowOffset: { width: 30, height: 30 }, - }, - }, - duration: { base: 300, long: 700, short: 100, veryLong: 3000 }, - measurement: { - baseSpace01: 4, - baseSpace02: 8, - baseSpace03: 12, - baseSpace04: 16, - baseSpace05: 32, - baseSpace06: 48, - baseSpace07: 64, - baseSpace08: 80, - baseSpace09: 96, - baseSpace10: 112, - }, - textStyle: { - body: { - fontWeight: \\"500\\", - fontSize: 14, - lineHeight: 20, - fontFamily: \\"Inter-Medium\\", - color: \\"rgb(30, 33, 43)\\", - letterSpacing: 10, - }, - bodyWithOpacity: { - fontWeight: \\"500\\", - fontSize: 14, - lineHeight: 20, - fontFamily: \\"Inter-Medium\\", - color: \\"rgba(30, 33, 43, 0.3)\\", - letterSpacing: 10, - }, - code: { - fontWeight: \\"500\\", - fontSize: 13, - lineHeight: 20, - fontFamily: \\"FiraCode-Medium\\", - color: \\"rgb(255, 142, 5)\\", - }, - list: { - fontWeight: \\"400\\", - fontSize: 14, - lineHeight: 20, - fontFamily: \\"Roboto-Regular\\", - }, - title: { - fontWeight: \\"600\\", - fontSize: 32, - lineHeight: 40, - fontFamily: \\"Inter-SemiBold\\", - color: \\"rgb(30, 33, 43)\\", - }, - }, - border: { - borderAccent: { - borderWidth: 2, - borderStyle: \\"solid\\", - borderColor: \\"rgb(102, 80, 239)\\", - borderRadius: 16, - }, - borderAccentWithOpacity: { - borderWidth: 2, - borderStyle: \\"solid\\", - borderColor: \\"rgba(102, 80, 239, 0.5)\\", - borderRadius: 16, - }, - borderAccentWithoutRadii: { - borderWidth: 2, - borderStyle: \\"solid\\", - borderColor: \\"rgba(102, 80, 239, 0.5)\\", - }, - borderDashed: { - borderWidth: 1, - borderStyle: \\"dashed\\", - borderColor: \\"rgb(30, 33, 43)\\", - borderRadius: 16, - }, - }, - color: { - colorsAccent: \\"rgb(87, 124, 254)\\", - colorsBlack: \\"rgb(30, 33, 43)\\", - colorsGreen: \\"rgb(88, 205, 82)\\", - colorsGrey: \\"rgb(204, 213, 225)\\", - colorsOrange: \\"rgb(255, 142, 5)\\", - colorsRed: \\"rgb(245, 72, 63)\\", - colorsWhite: \\"rgb(255, 255, 255)\\", - }, - font: { - firaCodeMedium: \\"FiraCode-Medium\\", - interMedium: \\"Inter-Medium\\", - interSemiBold: \\"Inter-SemiBold\\", - robotoRegular: \\"Roboto-Regular\\", - }, - gradient: { - gradientsColored: [ - { - angle: 90, - colors: [\\"rgb(245, 72, 63)\\", \\"rgb(255, 142, 5)\\"], - locations: [0, 1], - }, - ], - gradientsDark: [ - { - angle: 90, - colors: [\\"rgb(30, 33, 43)\\", \\"rgb(204, 213, 225)\\"], - locations: [0, 1], - }, - ], - gradientsNeutral: [ - { - angle: 90, - colors: [\\"rgb(204, 213, 225)\\", \\"rgb(255, 255, 255)\\"], - locations: [0, 1], - }, - ], - gradientsSafari: [ - { - angle: 90, - colors: [\\"rgb(255, 142, 5)\\", \\"rgb(255, 255, 255)\\"], - locations: [0, 1], - }, - ], - }, - opacity: { subtle: 0.5, transparent: 0.1, visible: 0.95 }, -}; -export default theme; -" -`; - -exports[`To React Native Should use assetsFolderPath 3`] = ` -"import bitmapAcmeLogo from \\"../path/acmeLogo.png\\"; -import bitmapPhotoExample from \\"../path/photoExample.png\\"; -import vectorActivity from \\"../path/activity.svg\\"; -import vectorAirplay from \\"../path/airplay.svg\\"; -import vectorAlertCircle from \\"../path/alertCircle.svg\\"; -import vectorAlertOctagon from \\"../path/alertOctagon.svg\\"; -import vectorAlertTriangle from \\"../path/alertTriangle.pdf\\"; -import vectorAlertTriangle from \\"../path/alertTriangle.svg\\"; -import vectorAlignCenter from \\"../path/alignCenter.svg\\"; -import vectorAlignCenter from \\"../path/alignCenter.pdf\\"; -import vectorUserMask from \\"../path/userMask.svg\\"; -import vectorUserMask from \\"../path/userMask.pdf\\"; - -const theme = { - bitmap: { acmeLogo: bitmapAcmeLogo, photoExample: bitmapPhotoExample }, - vector: { - activity: vectorActivity, - airplay: vectorAirplay, - alertCircle: vectorAlertCircle, - alertOctagon: vectorAlertOctagon, - alertTriangle: vectorAlertTriangle, - alertTriangle: vectorAlertTriangle, - alignCenter: vectorAlignCenter, - alignCenter: vectorAlignCenter, - userMask: vectorUserMask, - userMask: vectorUserMask, - }, - depth: { - background: { - elevation: 1, - shadowOpacity: 0.1815, - shadowRadius: 0.54, - shadowOffset: { width: 0.6, height: 0.6 }, - }, - foreground: { - elevation: 100, - shadowOpacity: 0.32999999999999996, - shadowRadius: 54, - shadowOffset: { width: 60, height: 60 }, - }, - middle: { - elevation: 50, - shadowOpacity: 0.255, - shadowRadius: 27, - shadowOffset: { width: 30, height: 30 }, - }, - }, - duration: { base: 300, long: 700, short: 100, veryLong: 3000 }, - measurement: { - baseSpace01: 4, - baseSpace02: 8, - baseSpace03: 12, - baseSpace04: 16, - baseSpace05: 32, - baseSpace06: 48, - baseSpace07: 64, - baseSpace08: 80, - baseSpace09: 96, - baseSpace10: 112, - }, - textStyle: { - body: { - fontWeight: \\"500\\", - fontSize: 14, - lineHeight: 20, - fontFamily: \\"Inter-Medium\\", - color: \\"rgb(30, 33, 43)\\", - letterSpacing: 10, - }, - bodyWithOpacity: { - fontWeight: \\"500\\", - fontSize: 14, - lineHeight: 20, - fontFamily: \\"Inter-Medium\\", - color: \\"rgba(30, 33, 43, 0.3)\\", - letterSpacing: 10, - }, - code: { - fontWeight: \\"500\\", - fontSize: 13, - lineHeight: 20, - fontFamily: \\"FiraCode-Medium\\", - color: \\"rgb(255, 142, 5)\\", - }, - list: { - fontWeight: \\"400\\", - fontSize: 14, - lineHeight: 20, - fontFamily: \\"Roboto-Regular\\", - }, - title: { - fontWeight: \\"600\\", - fontSize: 32, - lineHeight: 40, - fontFamily: \\"Inter-SemiBold\\", - color: \\"rgb(30, 33, 43)\\", - }, - }, - border: { - borderAccent: { - borderWidth: 2, - borderStyle: \\"solid\\", - borderColor: \\"rgb(102, 80, 239)\\", - borderRadius: 16, - }, - borderAccentWithOpacity: { - borderWidth: 2, - borderStyle: \\"solid\\", - borderColor: \\"rgba(102, 80, 239, 0.5)\\", - borderRadius: 16, - }, - borderAccentWithoutRadii: { - borderWidth: 2, - borderStyle: \\"solid\\", - borderColor: \\"rgba(102, 80, 239, 0.5)\\", - }, - borderDashed: { - borderWidth: 1, - borderStyle: \\"dashed\\", - borderColor: \\"rgb(30, 33, 43)\\", - borderRadius: 16, - }, - }, - color: { - colorsAccent: \\"rgb(87, 124, 254)\\", - colorsBlack: \\"rgb(30, 33, 43)\\", - colorsGreen: \\"rgb(88, 205, 82)\\", - colorsGrey: \\"rgb(204, 213, 225)\\", - colorsOrange: \\"rgb(255, 142, 5)\\", - colorsRed: \\"rgb(245, 72, 63)\\", - colorsWhite: \\"rgb(255, 255, 255)\\", - }, - font: { - firaCodeMedium: \\"FiraCode-Medium\\", - interMedium: \\"Inter-Medium\\", - interSemiBold: \\"Inter-SemiBold\\", - robotoRegular: \\"Roboto-Regular\\", - }, - gradient: { - gradientsColored: [ - { - angle: 90, - colors: [\\"rgb(245, 72, 63)\\", \\"rgb(255, 142, 5)\\"], - locations: [0, 1], - }, - ], - gradientsDark: [ - { - angle: 90, - colors: [\\"rgb(30, 33, 43)\\", \\"rgb(204, 213, 225)\\"], - locations: [0, 1], - }, - ], - gradientsNeutral: [ - { - angle: 90, - colors: [\\"rgb(204, 213, 225)\\", \\"rgb(255, 255, 255)\\"], - locations: [0, 1], - }, - ], - gradientsSafari: [ - { - angle: 90, - colors: [\\"rgb(255, 142, 5)\\", \\"rgb(255, 255, 255)\\"], - locations: [0, 1], - }, - ], - }, - opacity: { subtle: 0.5, transparent: 0.1, visible: 0.95 }, -}; -export default theme; -" -`; - -exports[`To React Native Should use assetsFolderPath 4`] = ` -"import bitmapAcmeLogo from \\"../path/acmeLogo.png\\"; -import bitmapPhotoExample from \\"../path/photoExample.png\\"; -import vectorActivity from \\"../path/activity.svg\\"; -import vectorAirplay from \\"../path/airplay.svg\\"; -import vectorAlertCircle from \\"../path/alertCircle.svg\\"; -import vectorAlertOctagon from \\"../path/alertOctagon.svg\\"; -import vectorAlertTriangle from \\"../path/alertTriangle.pdf\\"; -import vectorAlertTriangle from \\"../path/alertTriangle.svg\\"; -import vectorAlignCenter from \\"../path/alignCenter.svg\\"; -import vectorAlignCenter from \\"../path/alignCenter.pdf\\"; -import vectorUserMask from \\"../path/userMask.svg\\"; -import vectorUserMask from \\"../path/userMask.pdf\\"; - -const theme = { - bitmap: { acmeLogo: bitmapAcmeLogo, photoExample: bitmapPhotoExample }, - vector: { - activity: vectorActivity, - airplay: vectorAirplay, - alertCircle: vectorAlertCircle, - alertOctagon: vectorAlertOctagon, - alertTriangle: vectorAlertTriangle, - alertTriangle: vectorAlertTriangle, - alignCenter: vectorAlignCenter, - alignCenter: vectorAlignCenter, - userMask: vectorUserMask, - userMask: vectorUserMask, - }, - depth: { - background: { - elevation: 1, - shadowOpacity: 0.1815, - shadowRadius: 0.54, - shadowOffset: { width: 0.6, height: 0.6 }, - }, - foreground: { - elevation: 100, - shadowOpacity: 0.32999999999999996, - shadowRadius: 54, - shadowOffset: { width: 60, height: 60 }, - }, - middle: { - elevation: 50, - shadowOpacity: 0.255, - shadowRadius: 27, - shadowOffset: { width: 30, height: 30 }, - }, - }, - duration: { base: 300, long: 700, short: 100, veryLong: 3000 }, - measurement: { - baseSpace01: 4, - baseSpace02: 8, - baseSpace03: 12, - baseSpace04: 16, - baseSpace05: 32, - baseSpace06: 48, - baseSpace07: 64, - baseSpace08: 80, - baseSpace09: 96, - baseSpace10: 112, - }, - textStyle: { - body: { - fontWeight: \\"500\\", - fontSize: 14, - lineHeight: 20, - fontFamily: \\"Inter-Medium\\", - color: \\"rgb(30, 33, 43)\\", - letterSpacing: 10, - }, - bodyWithOpacity: { - fontWeight: \\"500\\", - fontSize: 14, - lineHeight: 20, - fontFamily: \\"Inter-Medium\\", - color: \\"rgba(30, 33, 43, 0.3)\\", - letterSpacing: 10, - }, - code: { - fontWeight: \\"500\\", - fontSize: 13, - lineHeight: 20, - fontFamily: \\"FiraCode-Medium\\", - color: \\"rgb(255, 142, 5)\\", - }, - list: { - fontWeight: \\"400\\", - fontSize: 14, - lineHeight: 20, - fontFamily: \\"Roboto-Regular\\", - }, - title: { - fontWeight: \\"600\\", - fontSize: 32, - lineHeight: 40, - fontFamily: \\"Inter-SemiBold\\", - color: \\"rgb(30, 33, 43)\\", - }, - }, - border: { - borderAccent: { - borderWidth: 2, - borderStyle: \\"solid\\", - borderColor: \\"rgb(102, 80, 239)\\", - borderRadius: 16, - }, - borderAccentWithOpacity: { - borderWidth: 2, - borderStyle: \\"solid\\", - borderColor: \\"rgba(102, 80, 239, 0.5)\\", - borderRadius: 16, - }, - borderAccentWithoutRadii: { - borderWidth: 2, - borderStyle: \\"solid\\", - borderColor: \\"rgba(102, 80, 239, 0.5)\\", - }, - borderDashed: { - borderWidth: 1, - borderStyle: \\"dashed\\", - borderColor: \\"rgb(30, 33, 43)\\", - borderRadius: 16, - }, - }, - color: { - colorsAccent: \\"rgb(87, 124, 254)\\", - colorsBlack: \\"rgb(30, 33, 43)\\", - colorsGreen: \\"rgb(88, 205, 82)\\", - colorsGrey: \\"rgb(204, 213, 225)\\", - colorsOrange: \\"rgb(255, 142, 5)\\", - colorsRed: \\"rgb(245, 72, 63)\\", - colorsWhite: \\"rgb(255, 255, 255)\\", - }, - font: { - firaCodeMedium: \\"FiraCode-Medium\\", - interMedium: \\"Inter-Medium\\", - interSemiBold: \\"Inter-SemiBold\\", - robotoRegular: \\"Roboto-Regular\\", - }, - gradient: { - gradientsColored: [ - { - angle: 90, - colors: [\\"rgb(245, 72, 63)\\", \\"rgb(255, 142, 5)\\"], - locations: [0, 1], - }, - ], - gradientsDark: [ - { - angle: 90, - colors: [\\"rgb(30, 33, 43)\\", \\"rgb(204, 213, 225)\\"], - locations: [0, 1], - }, - ], - gradientsNeutral: [ - { - angle: 90, - colors: [\\"rgb(204, 213, 225)\\", \\"rgb(255, 255, 255)\\"], - locations: [0, 1], - }, - ], - gradientsSafari: [ - { - angle: 90, - colors: [\\"rgb(255, 142, 5)\\", \\"rgb(255, 255, 255)\\"], - locations: [0, 1], - }, - ], - }, - opacity: { subtle: 0.5, transparent: 0.1, visible: 0.95 }, -}; -export default theme; -" -`; diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-react-native/to-react-native.parser.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-react-native/to-react-native.parser.ts deleted file mode 100644 index 47ae66aed..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-react-native/to-react-native.parser.ts +++ /dev/null @@ -1,115 +0,0 @@ -/* eslint-disable @typescript-eslint/ban-types */ -import prettier from "prettier"; -import Template from "../../libs/template"; -import { BitmapToken, IToken, Token, VectorToken } from "../../types"; -import { LibsType } from "../global-libs"; -import * as TokensClass from "./tokens"; - -export type InputDataType = Array< - Pick & Record ->; -export type OutputDataType = string; -export type ColorsFormat = - | "rgb" - | "prgb" - | "hex" - | "hex6" - | "hex3" - | "hex4" - | "hex8" - | "name" - | "hsl" - | "hsv"; - -export type FormatTokenType = Partial<{}>; - -export type OptionsType = - | Partial<{ - assetsFolderPath: string | { vector?: string; bitmap?: string }; - colorFormat: ColorsFormat; - header: string; - objectName: string; - prettierConfig: prettier.Options; - formatFileName: - | "camelCase" - | "kebabCase" - | "snakeCase" - | "pascalCase" - | "none"; - formatKeys: "camelCase" | "kebabCase" | "snakeCase" | "pascalCase"; - typescript: { castToConst?: boolean }; - }> - | undefined; - -export default async function ( - tokens: InputDataType, - options: OptionsType, - { _ }: Pick -): Promise { - const objectName = options?.objectName || "theme"; - const pattern = - "{{name}}{{#dimension}}@{{dimension}}x{{/dimension}}{{#format}}.{{format}}{{/format}}"; - const tokensGroupByType = _.groupBy(tokens, "type"); - const template = new Template(pattern); - let imports = ""; - const styles = Object.keys(tokensGroupByType).reduce((result, type) => { - const content = tokensGroupByType[type] - .map((token: Pick) => { - const tokenClassName = `${ - token.type.charAt(0).toUpperCase() + token.type.slice(1) - }`; - - if (!(TokensClass)[tokenClassName]) return undefined; - - const formattedTokenName = _[options?.formatKeys ?? "camelCase"]( - token.name - ); - - token.name = - options?.formatFileName !== "none" - ? _[options?.formatFileName ?? "camelCase"](token.name) - : token.name; - - const instance = new (TokensClass)[tokenClassName](token); - - if (token.type === "vector" || token.type === "bitmap") { - if ((token as VectorToken | BitmapToken).meta.dimension !== 1) { - return undefined; // Do nothing with @2, @3 etc. - } - const fileName = template.render(token); - const { theme, imports: tokenImports } = instance.toReactNative( - options, - fileName - ); - imports += tokenImports ?? ""; - - return `'${formattedTokenName}': ${theme},`; - } - - return `'${formattedTokenName}': ${instance.toReactNative(options)},`; - }) - .join(""); - - if (content) { - result += `${_.camelCase(type)}: {${content}},`; - } - return result; - }, ""); - - return prettier.format( - (() => { - return [ - options?.header || "", - imports, - `const ${objectName} = {${styles}}${ - options?.typescript?.castToConst ? " as const" : "" - };`, - `export default ${objectName};`, - ].join("\n"); - })(), - { - ...options?.prettierConfig, - parser: "babel-ts", - } - ); -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-react-native/to-react-native.spec.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-react-native/to-react-native.spec.ts deleted file mode 100644 index 0fcf41434..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-react-native/to-react-native.spec.ts +++ /dev/null @@ -1,103 +0,0 @@ -import libs from "../global-libs"; -import seeds from "../../tests/seeds"; -import toReactNative, { InputDataType } from "./to-react-native.parser"; - -describe("To React Native", () => { - it("Should generate the theme object", async () => { - const tokens = seeds().tokens; - const result = await toReactNative(tokens, undefined, libs); - expect(result).toMatchSnapshot(); - expect(result).toContain("};\nexport default theme;"); - }); - it("Should use assetsFolderPath", async () => { - const tokens = seeds().tokens; - expect( - await toReactNative(tokens, { assetsFolderPath: "path" }, libs) - ).toMatchSnapshot(); - expect( - await toReactNative(tokens, { assetsFolderPath: "./path" }, libs) - ).toMatchSnapshot(); - expect( - await toReactNative(tokens, { assetsFolderPath: "../path" }, libs) - ).toMatchSnapshot(); - expect( - await toReactNative(tokens, { assetsFolderPath: "../path/" }, libs) - ).toMatchSnapshot(); - }); - it("Should support the typescript.castToConst option", async () => { - const tokens = seeds().tokens; - const result = await toReactNative( - tokens, - { assetsFolderPath: "path", typescript: { castToConst: true } }, - libs - ); - expect(result).toContain("} as const;\nexport default theme;"); - expect(result).toMatchSnapshot(); - }); - it("Should support different formatName options", async () => { - ( - ["camelCase", "kebabCase", "snakeCase", "pascalCase", "none"] as const - ).map(async formatName => { - const tokens = seeds().tokens; - const result = await toReactNative( - tokens, - { assetsFolderPath: "path", formatFileName: formatName }, - libs - ); - expect(result).toMatchSnapshot(); - }); - }); - it("Should support different formatKey options", async () => { - (["camelCase", "kebabCase", "snakeCase", "pascalCase"] as const).map( - async formatKeys => { - const tokens = seeds().tokens; - const result = await toReactNative( - tokens, - { assetsFolderPath: "path", formatKeys }, - libs - ); - expect(result).toMatchSnapshot(); - } - ); - }); - it("Should support different duration types", async () => { - const tokens: InputDataType = [ - { - id: "1", - name: "2 hours", - value: { unit: "h", duration: 2 }, - type: "duration", - }, - { - id: "2", - name: "2 minutes", - value: { unit: "m", duration: 2 }, - type: "duration", - }, - { - id: "3", - name: "2 seconds", - value: { unit: "s", duration: 2 }, - type: "duration", - }, - { - id: "4", - name: "2 milliseconds", - value: { unit: "ms", duration: 2 }, - type: "duration", - }, - { - id: "5", - name: "2 nanoseconds", - value: { unit: "ns", duration: 2 }, - type: "duration", - }, - ]; - const result = await toReactNative( - tokens, - { assetsFolderPath: "path" }, - libs - ); - expect(result).toMatchSnapshot(); - }); -}); diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-react-native/tokens/bitmap.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-react-native/tokens/bitmap.ts deleted file mode 100644 index f184d2597..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-react-native/tokens/bitmap.ts +++ /dev/null @@ -1,36 +0,0 @@ -import { BitmapToken } from "../../../types"; -import { OptionsType } from "../to-react-native.parser"; -import { pascalCase } from "lodash"; -import { join } from "../util/path"; - -export class Bitmap extends BitmapToken { - constructor(token: Partial) { - super(token); - } - - toReactNative( - options: OptionsType, - fileName: string - ): { theme: string; imports: string } { - if (!options?.assetsFolderPath) { - return { - theme: JSON.stringify({ - uri: `'${this.value.url}'`, - }), - imports: "", - }; - } - - const relPath = - typeof options.assetsFolderPath === "string" - ? options.assetsFolderPath - : options.assetsFolderPath!.bitmap; - - const symbol = `bitmap${pascalCase(this.name)}`; - const fullPath = join(relPath || "", fileName); - return { - theme: symbol, - imports: `import ${symbol} from '${fullPath}';\n`, - }; - } -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-react-native/tokens/border.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-react-native/tokens/border.ts deleted file mode 100644 index 80f621673..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-react-native/tokens/border.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { BorderToken } from "../../../types"; -import { OptionsType } from "../to-react-native.parser"; -import tinycolor from "tinycolor2"; - -export class Border extends BorderToken { - constructor(token: Partial) { - super(token); - } - - toReactNative({ colorFormat = "rgb" }: OptionsType = {}) { - const { color, type, width, radii } = this.value; - const { measure } = width.value; - return JSON.stringify({ - borderWidth: measure, - borderStyle: type.toLowerCase(), - borderColor: tinycolor(color.value).toString(colorFormat), - borderRadius: radii?.value.measure, - }); - } -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-react-native/tokens/color.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-react-native/tokens/color.ts deleted file mode 100644 index 9ef44ebc3..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-react-native/tokens/color.ts +++ /dev/null @@ -1,12 +0,0 @@ -import tinycolor from "tinycolor2"; -import { OptionsType } from "../to-react-native.parser"; -import { ColorToken } from "../../../types"; - -export class Color extends ColorToken { - constructor(token: Partial) { - super(token); - } - toReactNative({ colorFormat = "rgb" }: OptionsType = {}): string { - return `'${tinycolor(this.value).toString(colorFormat)}'`; - } -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-react-native/tokens/depth.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-react-native/tokens/depth.ts deleted file mode 100644 index 40d4bf863..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-react-native/tokens/depth.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { DepthToken } from "../../../types"; - -export class Depth extends DepthToken { - constructor(token: Partial) { - super(token); - } - - private shadowHelper(elevation: number) { - return { - elevation, - shadowOpacity: 0.0015 * elevation + 0.18, - shadowRadius: 0.54 * elevation, - shadowOffset: { - width: 0.6 * elevation, - height: 0.6 * elevation, - }, - }; - } - - toReactNative() { - return JSON.stringify(this.shadowHelper(this.value.depth)); - } -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-react-native/tokens/duration.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-react-native/tokens/duration.ts deleted file mode 100644 index 61e20c3ff..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-react-native/tokens/duration.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { DurationToken } from "../../../types"; - -export class Duration extends DurationToken { - constructor(token: Partial) { - super(token); - } - - toReactNative() { - const { duration, unit } = this.value; - switch (unit) { - case "h": - return duration * 60 * 60 * 1000; - case "m": - return duration * 60 * 1000; - case "s": - return duration * 1000; - case "ms": - default: - return duration; - case "ns": - return duration / 1000; - } - } -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-react-native/tokens/font.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-react-native/tokens/font.ts deleted file mode 100644 index bc4c77f4a..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-react-native/tokens/font.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { FontToken } from "../../../types"; - -export class Font extends FontToken { - constructor(token: Partial) { - super(token); - } - toReactNative() { - return `'${this.value.fontPostScriptName}'`; - } -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-react-native/tokens/gradient.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-react-native/tokens/gradient.ts deleted file mode 100644 index 88585bb09..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-react-native/tokens/gradient.ts +++ /dev/null @@ -1,26 +0,0 @@ -import tinycolor from "tinycolor2"; -import { GradientToken } from "../../../types"; -import { OptionsType } from "../to-react-native.parser"; - -export class Gradient extends GradientToken { - constructor(token: Partial) { - super(token); - } - - toReactNative({ colorFormat = "rgb" }: OptionsType = {}) { - const value = this.value.gradients.map(gradient => { - const colors = gradient.colors.map(({ color }) => - tinycolor(color.value).toString(colorFormat) - ); - const locations = gradient.colors.map(({ position }) => position / 100); - const angle = parseFloat(gradient.angle.replace("deg", "")) || 0; - - return { - angle, - colors, - locations, - }; - }); - return JSON.stringify(value); - } -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-react-native/tokens/index.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-react-native/tokens/index.ts deleted file mode 100644 index ce9ad2296..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-react-native/tokens/index.ts +++ /dev/null @@ -1,11 +0,0 @@ -export * from "./bitmap"; -export * from "./color"; -export * from "./gradient"; -export * from "./textStyle"; -export * from "./vector"; -export * from "./opacity"; -export * from "./depth"; -export * from "./duration"; -export * from "./border"; -export * from "./measurement"; -export * from "./font"; diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-react-native/tokens/measurement.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-react-native/tokens/measurement.ts deleted file mode 100644 index 54282aaf3..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-react-native/tokens/measurement.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { MeasurementToken } from "../../../types"; - -export class Measurement extends MeasurementToken { - constructor(token: Partial) { - super(token); - } - toReactNative() { - return this.value.measure; - } -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-react-native/tokens/opacity.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-react-native/tokens/opacity.ts deleted file mode 100644 index 050e062e2..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-react-native/tokens/opacity.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { OpacityToken } from "../../../types"; - -export class Opacity extends OpacityToken { - constructor(token: Partial) { - super(token); - } - toReactNative() { - const value = this.value.opacity / 100; - return value; - } -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-react-native/tokens/textStyle.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-react-native/tokens/textStyle.ts deleted file mode 100644 index 24dcc9d79..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-react-native/tokens/textStyle.ts +++ /dev/null @@ -1,34 +0,0 @@ -import { TextStyleToken } from "../../../types"; -import { OptionsType } from "../to-react-native.parser"; -import tinycolor from "tinycolor2"; - -export class TextStyle extends TextStyleToken { - constructor(token: Partial) { - super(token); - } - - toReactNative({ colorFormat = "rgb" }: OptionsType = {}) { - const { - font, - color: c, - fontSize: fs, - lineHeight: lh, - letterSpacing: ls, - } = this.value; - const { fontPostScriptName, fontWeight } = font.value; - const color = c?.value; - const fontSize = fs.value.measure; - const letterSpacing = ls?.value?.measure; - const lineHeight = lh?.value?.measure; - - const fontObject = { - fontWeight: `${fontWeight || "normal"}`, - fontSize, - lineHeight, - fontFamily: fontPostScriptName, - color: color ? tinycolor(color).toString(colorFormat) : undefined, - letterSpacing, - }; - return JSON.stringify(fontObject); - } -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-react-native/tokens/vector.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-react-native/tokens/vector.ts deleted file mode 100644 index 53409204d..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-react-native/tokens/vector.ts +++ /dev/null @@ -1,36 +0,0 @@ -import { VectorToken } from "../../../types"; -import { OptionsType } from "../to-react-native.parser"; -import { pascalCase } from "lodash"; -import { join } from "../util/path"; - -export class Vector extends VectorToken { - constructor(token: Partial) { - super(token); - } - - toReactNative( - options: OptionsType, - fileName: string - ): { theme: string; imports: string } { - if (!options?.assetsFolderPath) { - return { - theme: JSON.stringify({ - uri: `'${this.value.url}'`, - }), - imports: "", - }; - } - - const relPath = - typeof options.assetsFolderPath === "string" - ? options.assetsFolderPath - : options.assetsFolderPath!.vector; - - const symbol = `vector${pascalCase(this.name)}`; - const fullPath = join(relPath || "", fileName); - return { - theme: symbol, - imports: `import ${symbol} from '${fullPath}';\n`, - }; - } -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-react-native/util/path.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-react-native/util/path.ts deleted file mode 100644 index a7f6e9eef..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-react-native/util/path.ts +++ /dev/null @@ -1,11 +0,0 @@ -export const join = (dir: string, fileName: string) => { - let path = ""; - if (!dir.startsWith(".")) { - path += "./"; - } - path += dir; - if (!path.endsWith("/")) { - path += "/"; - } - return path + fileName; -}; diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-style-dictionary/README.md b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-style-dictionary/README.md deleted file mode 100644 index 74ef57563..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-style-dictionary/README.md +++ /dev/null @@ -1,506 +0,0 @@ -# To Style Dictionary - -## Description - -This parser helps you generate [Style Dictionary](https://amzn.github.io/style-dictionary/#/) configuration files for all your design tokens coming from Specify. - -Learn more about how to configure Specify in the API documentation: [https://specifyapp.com/developers](https://specifyapp.com/developers). - -## Interface - -```ts -interface parser { - name: "to-style-dictionary"; - options: Partial<{ - formatName: "camelCase" | "kebabCase" | "snakeCase" | "pascalCase"; - formatTokens: Partial<{ - colorFormat: { - format: ColorsFormat; - }; - fontSizeFormat: { - unit: "px" | "rem" | "none"; - }; - fontFormat: Array<"woff2" | "woff" | "otf" | "ttf" | "eot">; - }>; - splitBy?: string; - assetsBaseDirectory?: Partial<{ - fonts?: string; - images?: string; - icons?: string; - }>; - formatConfig?: Partial<{ - endOfLine: "auto" | "lf" | "crlf" | "cr"; - tabWidth: number; - useTabs: boolean; - }>; - }>; -} -``` - -### Options - -| Parameter | Required | Type | Default | Description | -| ---------------------------------- | -------- | ----------------------------------------------------------------- | ----------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `formatName` | optional | `camelCase` `kebabCase` `snakeCase` `pascalCase` | `camelCase` | The case transformation you want to apply to your design tokens' name. | -| `formatTokens.colorFormat.format` | optional | `rgb` `prgb` `hex` `hex6` `hex3` `hex4` `hex8` `name` `hsl` `hsv` | `hex` | The color format you want to apply to your color design tokens. | -| `formatTokens.fontSizeFormat.unit` | optional | `px` `rem` | `none` | | -| `formatTokens.fontFormat` | optional | `woff2` `woff` `otf` `ttf` `eot` | `ttf` | The formats of your font files. | -| `splitBy` | optional | `string` | | The character used to define the nesting of the values in the object (e.g. The name of the color in [this example](https://github.com/Specifyapp/parsers/tree/master/parsers/to-style-dictionary#input-2)) | -| `assetsBaseDirectory.fonts` | optional | `string` | `none` | The base directory containing your font files. | -| `assetsBaseDirectory.images` | optional | `string` | `none` | The base directory containing your images. | -| `assetsBaseDirectory.icons` | optional | `string` | `none` | The base directory containing your icons. | -| `formatConfig.endOfLine` | optional | `auto` `lf` `crlf` `cr` | `auto` | [Prettier documentation](https://prettier.io/docs/en/options.html#end-of-line) | -| `formatConfig.tabWidth` | optional | `number` | `2` | [Prettier documentation](https://prettier.io/docs/en/options.html#tab-width) | -| `formatConfig.useTabs` | optional | `boolean` | `true` | [Prettier documentation](https://prettier.io/docs/en/options.html#tabs) | - -## Output - -Please keep in mind that this parser generates files. This is why you should always set a folder as the final `path` in your parent rule. - -
-See Do & Don't config examples - -โœ… Do - -``` -// ... -"rules": [ - { - "name": "Design Tokens / Colors", - "path": "tokens", // <-- path set as a folder - "parsers": [ - { - "name": "to-style-dictionary" - } - ] - } -] -``` - -๐Ÿšซ Don't - -``` -// ... -"rules": [ - { - "name": "Design Tokens / Colors", - "path": "tokens/colors.json", // <-- path set as a file - "parsers": [ - { - "name": "to-style-dictionary" - } - ] - } -] -``` - -
- -## Types - -โ„น๏ธ **Please be aware that, depending on the order you use parsers, their input and output types have to match.** - -### Input - -Array of objects with at least `name`, `value` and `type`: - -```ts -type input = Array<{ name: string; value: any; type: string }>; -``` - -### Output - -An array of objects containing a `name` and a `value`. The value is an object containing either an `url` or a `content`. This object is considered as a `DownloadableFile`. - -```ts -type output = Array<{ - name: string; - value: { - content?: string; - url?: string; - }; -}>; -``` - -## Basic Usage - -### Config - -```jsonc -"parsers": [ - { - "name": "to-style-dictionary" - } - // โ€ฆ -] -``` - -### Before/After - -#### Input - -```jsonc -[ - { - "name": "primary", - "value": { - "a": 1, - "b": 255, - "g": 189, - "r": 198 - }, - "type": "color" - }, - { - "name": "base-space-01", - "value": { - "unit": "px", - "measure": 4 - }, - "type": "measurement" - }, - { - "name": "body", - "value": { - "font": { - "id": "69d2d62e-4d62-45d7-b85f-5da2f9f0c0d4", - "name": "Roboto-Regular", - "value": { - "fontFamily": "Roboto", - "fontWeight": 400, - "fontPostScriptName": "Roboto-Regular" - }, - "type": "font" - }, - "fontSize": { - "value": { - "unit": "px", - "measure": 16 - } - }, - "textAlign": { - "vertical": "top", - "horizontal": "left" - }, - "lineHeight": { - "value": { - "unit": "px", - "measure": 20 - } - }, - "fontVariant": ["small-caps"] - }, - "type": "textStyle" - }, - { - "name": "Roboto-Regular", - "value": { - "fontFamily": "Roboto", - "fontWeight": 400, - "fontPostScriptName": "Roboto-Regular" - }, - "type": "font" - } -] -``` - -#### Output - -This will create multiple files inside a folder with the following structure: - -``` -๐Ÿ—‚ folder-defined-in-the-rule -โ””โ”€โ”€ ๐Ÿ—‚ color -โ”‚ โ””โ”€โ”€ base.json -โ”œโ”€โ”€ ๐Ÿ—‚ size -โ”‚ โ””โ”€โ”€ base.json -โ”‚ โ””โ”€โ”€ font.json -โ”‚ โ””โ”€โ”€ lineHeight.json -โ””โ”€โ”€ ๐Ÿ—‚ asset - โ””โ”€โ”€ font.json -``` - -In each of these files are the tokens usable in Style Dictionary - -```jsonc -/* color/base.json */ -{ - "color": { - "base": { - "primary": { - "value": "#c6bdff" - } - } - } -} -``` - -```jsonc -/* size/base.json */ -{ - "size": { - "base": { - "baseSpace01": { - "value": "4px" - } - } - } -} -``` - -```jsonc -/* size/font.json */ -{ - "size": { - "base": { - "body": { - "value": "16px" - } - } - } -} -``` - -```jsonc -/* size/lineHeight.json */ -{ - "size": { - "base": { - "body": { - "value": "20px" - } - } - } -} -``` - -```jsonc -/* asset/font.json */ -{ - "asset": { - "font": { - "robotoRegular": { - "ttf": { - "value": "Roboto-Regular.ttf" - } - } - } - } -} -``` - -## Complex usage - with specific config - -### Config - -```jsonc -"parsers": [ - { - "name": "to-style-dictionary", - "options": { - "splitBy": "/", - "assetsBaseDirectory": { - "fonts": "assets/my-fonts/" - } - } - } - // โ€ฆ -] -``` - -### Before/After - -#### Input - -```jsonc -[ - { - "name": "primary/main", - "value": { - "a": 1, - "b": 255, - "g": 189, - "r": 198 - }, - "type": "color" - }, - { - "name": "primary/hover", - "value": { - "a": 1, - "b": 255, - "g": 159, - "r": 168 - }, - "type": "color" - }, - { - "name": "secondary/main", - "value": { - "a": 1, - "b": 31, - "g": 174, - "r": 222 - }, - "type": "color" - }, - { - "name": "base-space-01", - "value": { - "unit": "px", - "measure": 4 - }, - "type": "measurement" - }, - { - "name": "component/small-padding", - "value": { - "unit": "px", - "measure": 2 - }, - "type": "measurement" - }, - { - "name": "body", - "value": { - "font": { - "id": "69d2d62e-4d62-45d7-b85f-5da2f9f0c0d4", - "name": "Roboto-Regular", - "value": { - "fontFamily": "Roboto", - "fontWeight": 400, - "fontPostScriptName": "Roboto-Regular" - }, - "type": "font" - }, - "fontSize": { - "value": { - "unit": "px", - "measure": 16 - } - }, - "textAlign": { - "vertical": "top", - "horizontal": "left" - }, - "lineHeight": { - "value": { - "unit": "px", - "measure": 20 - } - }, - "fontVariant": ["small-caps"] - }, - "type": "textStyle" - }, - { - "name": "Roboto-Regular", - "value": { - "fontFamily": "Roboto", - "fontWeight": 400, - "fontPostScriptName": "Roboto-Regular" - }, - "type": "font" - } -] -``` - -#### Output - -This will create multiple files inside a folder with the following structure: - -``` -๐Ÿ—‚ folder-defined-in-the-rule -โ””โ”€โ”€ ๐Ÿ—‚ color -โ”‚ โ””โ”€โ”€ base.json -โ”œโ”€โ”€ ๐Ÿ—‚ size -โ”‚ โ””โ”€โ”€ base.json -โ”‚ โ””โ”€โ”€ font.json -โ”‚ โ””โ”€โ”€ lineHeight.json -โ””โ”€โ”€ ๐Ÿ—‚ asset - โ””โ”€โ”€ font.json -``` - -In each of these files are the tokens usable in Style Dictionary - -```jsonc -/* color/base.json */ -{ - "color": { - "base": { - "primary": { - "main": { - "value": "#c6bdff" - }, - "hover": { - "value": "#a99fff" - } - }, - "secondary": { - "main": { - "value": "#deae1f" - } - } - } - } -} -``` - -```jsonc -/* size/base.json */ -{ - "size": { - "base": { - "baseSpace01": { - "value": "4px" - }, - "component": { - "smallPadding": { - "value": "2px" - } - } - } - } -} -``` - -```jsonc -/* size/font.json */ -{ - "size": { - "base": { - "body": { - "value": "16px" - } - } - } -} -``` - -```jsonc -/* size/lineHeight.json */ -{ - "size": { - "base": { - "body": { - "value": "20px" - } - } - } -} -``` - -```jsonc -/* asset/font.json */ -{ - "asset": { - "font": { - "robotoRegular": { - "ttf": { - "value": "assets/my-fonts/Roboto-Regular.ttf" - } - } - } - } -} -``` diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-style-dictionary/to-style-dictionary.parser.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-style-dictionary/to-style-dictionary.parser.ts deleted file mode 100644 index c384916fe..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-style-dictionary/to-style-dictionary.parser.ts +++ /dev/null @@ -1,115 +0,0 @@ -import { deepMerge } from "@open-system/core-shared-utilities/common/deep-merge"; -import prettier from "prettier"; -import { - ColorsFormat, - DownloadableFile, - IToken, - TokensType, -} from "../../types"; -import "../../types/utils/utils"; -import { LibsType } from "../global-libs"; -import { - BaseStyleDictionaryTokensFormat, - StyleDictionaryTokenClass, -} from "./to-style-dictionary.type"; -import * as TokensClass from "./tokens"; - -export type OutputDataType = Array; -export type InputDataType = Array< - Pick & Record ->; -export type FormatTokenType = Partial<{ - colorFormat: { - format: ColorsFormat; - }; - fontSizeFormat: { - unit: "px" | "rem" | "none"; - }; - fontFormat: Array<"woff2" | "woff" | "otf" | "ttf" | "eot">; -}>; -export type OptionsType = - | Partial<{ - formatName: "camelCase" | "kebabCase" | "snakeCase" | "pascalCase"; - formatTokens: FormatTokenType; - splitBy?: string; - assetsBaseDirectory?: Partial<{ - fonts?: string; - images?: string; - icons?: string; - }>; - formatConfig?: Partial<{ - endOfLine: "auto" | "lf" | "crlf" | "cr"; - tabWidth: number; - useTabs: boolean; - }>; - }> - | undefined; - -function getClassByType(type: string): StyleDictionaryTokenClass | undefined { - const tokenClassName = `${type.charAt(0).toUpperCase() + type.slice(1)}`; - return (TokensClass)[tokenClassName]; -} - -export default async function ( - tokens: InputDataType, - options: OptionsType = {}, - { _ }: Pick -): Promise { - const transformNameFn = _[options?.formatName ?? "camelCase"]; - const tokensGroupByType = _.groupBy(tokens, "type"); - // loop over specify types - const data = Object.keys( - tokensGroupByType - ).reduce((result, type) => { - // loop over design tokens of one specify type - const styleDictionaryTokens = Object.values(tokensGroupByType[type]).reduce( - (ret, designDecision: any) => { - const tokenHandler = getClassByType(type as TokensType); - if (!tokenHandler) return {}; - const keys = options?.splitBy - ? designDecision.name!.split(options.splitBy) - : [designDecision.name]; - const instance = new tokenHandler( - designDecision, - keys.map(k => transformNameFn(k)) - ); - return deepMerge(instance.generate(options), ret); - }, - {} - ); - return deepMerge(result, styleDictionaryTokens); - }, {}); - - return Object.entries(data).reduce>( - (acc, [type, value]) => { - if (type === "measurement") type = "size"; - return acc.concat( - ...Object.entries(value!).reduce>( - (files, [fileName, content]) => { - return [ - ...files, - { - name: `${type}/${fileName === type ? "base" : fileName}.json`, - value: { - content: prettier.format( - JSON.stringify({ - [type]: { - [fileName]: content, - }, - }), - { - parser: "json", - ...options.formatConfig, - } - ), - }, - }, - ]; - }, - [] - ) - ); - }, - [] - ); -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-style-dictionary/to-style-dictionary.spec.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-style-dictionary/to-style-dictionary.spec.ts deleted file mode 100644 index 7efd4f0b7..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-style-dictionary/to-style-dictionary.spec.ts +++ /dev/null @@ -1,772 +0,0 @@ -import toStyleDictionary from "./to-style-dictionary.parser"; -import seeds from "../../tests/seeds"; -import libs from "../global-libs"; -import { AllowedFormat, FontFormatList, Token } from "../../types"; -import * as TokensClass from "./tokens"; -import { - BaseStyleDictionaryTokensFormat, - StyleDictionaryTokenClass, -} from "./to-style-dictionary.type"; - -describe("To Style Dictionary", () => { - it("Should be able to extract tokens in multiple files", async () => { - const result = await toStyleDictionary( - seeds().tokens.filter(({ type }) => - ["color", "textStyle", "shadow", "border"].includes(type) - ) as Array, - { splitBy: "/" }, - libs - ); - - const expectedNames = [ - "color/base.json", - "color/font.json", - "color/shadow.json", - "color/border.json", - ]; - - expect(Array.isArray(result)).toEqual(true); - - // Only test on extracted colors - const resultWithOnlyColors = result.filter(file => - file.name.includes("color/") - ); - expect(resultWithOnlyColors.length).toEqual(4); // Should have all the files - const actualNames = resultWithOnlyColors.map(file => file.name); - expect(actualNames).toEqual(expect.arrayContaining(expectedNames)); - }); - - it("Should be able to extract Color token type", async () => { - const result = await toStyleDictionary( - seeds().tokens.filter(({ type }) => type === "color") as Array, - { splitBy: "/" }, - libs - ); - - expect(Array.isArray(result)).toEqual(true); - expect(result.length).toEqual(1); // Color token only creates base - const file = result[0]; - expect(typeof file.name).toEqual("string"); - expect(file.name).toEqual("color/base.json"); - expect(typeof file.value.content).toEqual("string"); - const content = JSON.parse(file.value.content!) as Record; - expect(Object.keys(content)[0]).toEqual("color"); - expect(Object.keys(content.color)[0]).toEqual("base"); - expect(Object.keys(content.color.base)[0]).toEqual("colors"); - expect(content.color.base.colors.accent).toEqual({ - value: expect.any(String), - }); - expect(content.color.base.colors.black).toEqual({ - value: expect.any(String), - }); - expect(content.color.base.colors.green).toEqual({ - value: expect.any(String), - }); - expect(content.color.base.colors.grey).toEqual({ - value: expect.any(String), - }); - expect(content.color.base.colors.orange).toEqual({ - value: expect.any(String), - }); - }); - - it("Should be able to extract Border token type", async () => { - const result = await toStyleDictionary( - seeds().tokens.filter(({ type }) => type === "border") as Array, - { splitBy: "/" }, - libs - ); - - const expectedNames = [ - "color/border.json", - "size/border.json", - "size/radius.json", - ]; - const expectedTypes = ["color", "size", "size"]; - - expect(Array.isArray(result)).toEqual(true); - expect(result.length).toEqual(expectedNames.length); // Border token creates a size and a color - - result.forEach(file => { - const index = expectedNames.findIndex(name => name === file.name); - - expect(typeof file.name).toEqual("string"); - expect(index).toBeGreaterThan(-1); - expect(typeof file.value.content).toEqual("string"); - const type = expectedTypes[index]; - const content = JSON.parse(file.value.content!) as Record; - expect(typeof content[type]).toEqual("object"); - Object.values(content).forEach(property => { - expect(Object.values(property).length).toBeGreaterThan(0); - }); - }); - }); - - it("Should be able to extract Depth token type", async () => { - const result = await toStyleDictionary( - seeds().tokens.filter(({ type }) => type === "depth") as Array, - { splitBy: "/" }, - libs - ); - expect(Array.isArray(result)).toEqual(true); - expect(result.length).toEqual(1); // Depth token only creates base - const file = result[0]; - expect(typeof file.name).toEqual("string"); - expect(file.name).toEqual("depth/base.json"); - expect(typeof file.value.content).toEqual("string"); - const content = JSON.parse(file.value.content!) as Record; - expect(Object.keys(content)[0]).toEqual("depth"); - expect(Object.keys(content.depth)[0]).toEqual("base"); - expect(content.depth.base.background).toEqual({ - value: expect.any(String), - }); - expect(content.depth.base.middle).toEqual({ value: expect.any(String) }); - expect(content.depth.base.foreground).toEqual({ - value: expect.any(String), - }); - }); - - it("Should be able to extract Duration token type", async () => { - const result = await toStyleDictionary( - seeds().tokens.filter(({ type }) => type === "duration") as Array, - { splitBy: "/" }, - libs - ); - expect(Array.isArray(result)).toEqual(true); - expect(result.length).toEqual(1); // Time token only creates base - const file = result[0]; - expect(typeof file.name).toEqual("string"); - expect(file.name).toEqual("time/base.json"); - expect(typeof file.value.content).toEqual("string"); - const content = JSON.parse(file.value.content!) as Record; - expect(Object.keys(content)[0]).toEqual("time"); - expect(Object.keys(content.time)[0]).toEqual("base"); - expect(content.time.base.base).toEqual({ value: expect.any(String) }); - expect(content.time.base.long).toEqual({ value: expect.any(String) }); - expect(content.time.base.short).toEqual({ value: expect.any(String) }); - expect(content.time.base.veryLong).toEqual({ value: expect.any(String) }); - }); - - it("Should be able to extract Measurement token type", async () => { - const result = await toStyleDictionary( - seeds().tokens.filter( - ({ type }) => type === "measurement" - ) as Array, - { splitBy: "/" }, - libs - ); - expect(Array.isArray(result)).toEqual(true); - expect(result.length).toEqual(1); // Measurement token only creates base - const file = result[0]; - expect(typeof file.name).toEqual("string"); - expect(file.name).toEqual("size/base.json"); - expect(typeof file.value.content).toEqual("string"); - const content = JSON.parse(file.value.content!) as Record; - expect(Object.keys(content)[0]).toEqual("size"); - expect(Object.keys(content.size)[0]).toEqual("base"); - Object.values(content.size).forEach(property => { - Object.values(property as Record).forEach( - value => { - expect(value.value).toEqual(expect.any(String)); - } - ); - }); - }); - - it("Should be able to extract Opacity token type", async () => { - const result = await toStyleDictionary( - seeds().tokens.filter(({ type }) => type === "opacity") as Array, - { splitBy: "/" }, - libs - ); - expect(Array.isArray(result)).toEqual(true); - expect(result.length).toEqual(1); // Opacity token only creates base - const file = result[0]; - expect(typeof file.name).toEqual("string"); - expect(file.name).toEqual("opacity/base.json"); - expect(typeof file.value.content).toEqual("string"); - const content = JSON.parse(file.value.content!) as Record; - expect(Object.keys(content)[0]).toEqual("opacity"); - expect(Object.keys(content.opacity)[0]).toEqual("base"); - expect(content.opacity.base.transparent).toEqual({ - value: expect.any(String), - }); - expect(content.opacity.base.subtle).toEqual({ value: expect.any(String) }); - expect(content.opacity.base.visible).toEqual({ value: expect.any(String) }); - }); - - it("Should be able to extract Shadow token type", async () => { - const result = await toStyleDictionary( - seeds().tokens.filter(({ type }) => type === "shadow") as Array, - { splitBy: "/" }, - libs - ); - - const expectedNames = ["color/shadow.json", "size/shadow.json"]; - - expect(Array.isArray(result)).toEqual(true); - expect(result.length).toEqual(expectedNames.length); // Shadow token creates a size and a color - - result.forEach(file => { - const index = expectedNames.findIndex(name => name === file.name); - - expect(typeof file.name).toEqual("string"); - expect(index).toBeGreaterThan(-1); - expect(typeof file.value.content).toEqual("string"); - const content = JSON.parse(file.value.content!) as Record; - - // get in color or size - Object.values(content).forEach(value => { - expect(typeof value).toEqual("object"); - // get in shadow - Object.values( - value as NonNullable< - BaseStyleDictionaryTokensFormat["size" | "color"] - > - ).forEach(nestedValue => { - expect(typeof nestedValue).toEqual("object"); - expect(Object.keys(nestedValue).length).toBeGreaterThan(0); - }); - }); - }); - }); - - it("Should be able to extract TextStyle token type", async () => { - const result = await toStyleDictionary( - seeds().tokens.filter(({ type }) => type === "textStyle") as Array, - { splitBy: "/" }, - libs - ); - - const expectedNames = [ - "color/font.json", - "size/font.json", - "size/lineHeight.json", - "size/letterSpacing.json", - "size/textIndent.json", - ]; - - expect(Array.isArray(result)).toEqual(true); - expect(result.length).toEqual(expectedNames.length); // Shadow token creates 4 size and a color - result.forEach(file => { - const index = expectedNames.findIndex(name => name === file.name); - - expect(typeof file.name).toEqual("string"); - expect(index).toBeGreaterThan(-1); - expect(typeof file.value.content).toEqual("string"); - const content = JSON.parse(file.value.content!) as Record; - Object.values(content).forEach(property => { - Object.values(property).forEach(nestedProperty => { - Object.values( - nestedProperty as Record - ).forEach(value => { - expect(value.value).toEqual(expect.any(String)); - }); - }); - }); - }); - }); - - it("Should be able to extract Font token type", async () => { - const result = await toStyleDictionary( - seeds().tokens.filter(({ type }) => type === "font") as Array, - { splitBy: "/" }, - libs - ); - - expect(Array.isArray(result)).toEqual(true); - expect(result.length).toEqual(1); // Time token only creates base - const file = result[0]; - expect(typeof file.name).toEqual("string"); - expect(file.name).toEqual("asset/font.json"); - expect(typeof file.value.content).toEqual("string"); - const content = JSON.parse(file.value.content!) as Record; - expect(Object.keys(content)[0]).toEqual("asset"); - expect(Object.keys(content.asset)[0]).toEqual("font"); - Object.values(content).forEach(property => { - Object.values(property).forEach(nestedProperty => { - Object.values( - nestedProperty as Record> - ).forEach(format => { - Object.values(format).forEach(value => { - expect(value.value).toEqual(expect.any(String)); - }); - }); - }); - }); - }); - - it("Should be able to extract Font token type with assetsBaseDirectory", async () => { - const result = await toStyleDictionary( - seeds().tokens.filter(({ type }) => type === "font") as Array, - { splitBy: "/", assetsBaseDirectory: { fonts: "fonts/" } }, - libs - ); - - expect(Array.isArray(result)).toEqual(true); - expect(result.length).toEqual(1); // Time token only creates base - const file = result[0]; - expect(typeof file.name).toEqual("string"); - expect(file.name).toEqual("asset/font.json"); - expect(typeof file.value.content).toEqual("string"); - const content = JSON.parse(file.value.content!) as Record; - expect(Object.keys(content)[0]).toEqual("asset"); - expect(Object.keys(content.asset)[0]).toEqual("font"); - Object.values(content).forEach(property => { - Object.values(property).forEach(nestedProperty => { - Object.values( - nestedProperty as Record> - ).forEach(format => { - Object.entries(format).forEach(([format, value]) => { - if (format === "name") { - expect(value.value).toEqual(expect.any(String)); - } else { - expect(value.value).toContain("fonts/"); - } - }); - }); - }); - }); - }); - - it("Should be able to extract Font token type with assetsBaseDirectory without trailing slash", async () => { - const result = await toStyleDictionary( - seeds().tokens.filter(({ type }) => type === "font") as Array, - { splitBy: "/", assetsBaseDirectory: { fonts: "fonts" } }, - libs - ); - - expect(Array.isArray(result)).toEqual(true); - expect(result.length).toEqual(1); // Time token only creates base - const file = result[0]; - expect(typeof file.name).toEqual("string"); - expect(file.name).toEqual("asset/font.json"); - expect(typeof file.value.content).toEqual("string"); - const content = JSON.parse(file.value.content!) as Record; - expect(Object.keys(content)[0]).toEqual("asset"); - expect(Object.keys(content.asset)[0]).toEqual("font"); - Object.values(content).forEach(property => { - Object.values(property).forEach(nestedProperty => { - Object.values( - nestedProperty as Record> - ).forEach(format => { - Object.entries(format).forEach(([format, value]) => { - if (format === "name") { - expect(value.value).toEqual(expect.any(String)); - } else { - expect(value.value).toContain("fonts/"); - } - }); - }); - }); - }); - }); - - it("Should be able to extract Bitmap token type", async () => { - const result = await toStyleDictionary( - seeds().tokens.filter(({ type }) => type === "bitmap") as Array, - { splitBy: "/" }, - libs - ); - expect(Array.isArray(result)).toEqual(true); - expect(result.length).toEqual(1); // Time token only creates base - const file = result[0]; - expect(typeof file.name).toEqual("string"); - expect(file.name).toEqual("asset/image.json"); - expect(typeof file.value.content).toEqual("string"); - const content = JSON.parse(file.value.content!) as Record; - expect(Object.keys(content)[0]).toEqual("asset"); - expect(Object.keys(content.asset)[0]).toEqual("image"); - Object.values(content.asset).forEach(property => { - Object.values(property as Record).forEach( - nestedProperty => { - expect(nestedProperty.value).toEqual(expect.any(String)); - } - ); - }); - }); - - it("Should be able to extract Bitmap token type with assetsBaseDirectory", async () => { - const result = await toStyleDictionary( - seeds().tokens.filter(({ type }) => type === "bitmap") as Array, - { splitBy: "/", assetsBaseDirectory: { images: "images/" } }, - libs - ); - expect(Array.isArray(result)).toEqual(true); - expect(result.length).toEqual(1); // Time token only creates base - const file = result[0]; - expect(typeof file.name).toEqual("string"); - expect(file.name).toEqual("asset/image.json"); - expect(typeof file.value.content).toEqual("string"); - const content = JSON.parse(file.value.content!) as Record; - expect(Object.keys(content)[0]).toEqual("asset"); - expect(Object.keys(content.asset)[0]).toEqual("image"); - Object.values(content.asset).forEach(property => { - Object.values(property as Record).forEach( - nestedProperty => { - expect(nestedProperty.value.includes("images/")).toBeTruthy(); - expect(nestedProperty.value).toEqual(expect.any(String)); - } - ); - }); - }); - - it("Should be able to extract Bitmap token type with assetsBaseDirectory without trailing slash", async () => { - const result = await toStyleDictionary( - seeds().tokens.filter(({ type }) => type === "bitmap") as Array, - { splitBy: "/", assetsBaseDirectory: { images: "images" } }, - libs - ); - expect(Array.isArray(result)).toEqual(true); - expect(result.length).toEqual(1); // Time token only creates base - const file = result[0]; - expect(typeof file.name).toEqual("string"); - expect(file.name).toEqual("asset/image.json"); - expect(typeof file.value.content).toEqual("string"); - const content = JSON.parse(file.value.content!) as Record; - expect(Object.keys(content)[0]).toEqual("asset"); - expect(Object.keys(content.asset)[0]).toEqual("image"); - Object.values(content.asset).forEach(property => { - Object.values(property as Record).forEach( - nestedProperty => { - expect(nestedProperty.value.includes("images/")).toBeTruthy(); - expect(nestedProperty.value).toEqual(expect.any(String)); - } - ); - }); - }); - - it("Should be able to extract Vector token type", async () => { - const result = await toStyleDictionary( - seeds().tokens.filter(({ type }) => type === "vector") as Array, - { splitBy: "/" }, - libs - ); - expect(Array.isArray(result)).toEqual(true); - expect(result.length).toEqual(1); // Time token only creates base - const file = result[0]; - expect(typeof file.name).toEqual("string"); - expect(file.name).toEqual("asset/icon.json"); - expect(typeof file.value.content).toEqual("string"); - const content = JSON.parse(file.value.content!) as Record; - expect(Object.keys(content)[0]).toEqual("asset"); - expect(Object.keys(content.asset)[0]).toEqual("icon"); - Object.values(content.asset).forEach(property => { - Object.values(property as Record).forEach( - nestedProperty => { - expect(nestedProperty.value).toEqual(expect.any(String)); - } - ); - }); - }); - - it("Should be able to extract Vector token type with assetsBaseDirectory", async () => { - const result = await toStyleDictionary( - seeds().tokens.filter(({ type }) => type === "vector") as Array, - { splitBy: "/", assetsBaseDirectory: { icons: "icons/" } }, - libs - ); - expect(Array.isArray(result)).toEqual(true); - expect(result.length).toEqual(1); // Time token only creates base - const file = result[0]; - expect(typeof file.name).toEqual("string"); - expect(file.name).toEqual("asset/icon.json"); - expect(typeof file.value.content).toEqual("string"); - const content = JSON.parse(file.value.content!) as Record; - expect(Object.keys(content)[0]).toEqual("asset"); - expect(Object.keys(content.asset)[0]).toEqual("icon"); - Object.values(content.asset).forEach(property => { - Object.values(property as Record).forEach( - nestedProperty => { - expect(nestedProperty.value.includes("icons/")).toBeTruthy(); - expect(nestedProperty.value).toEqual(expect.any(String)); - } - ); - }); - }); - - it("Should be able to extract Vector token type with assetsBaseDirectory without trailing slash", async () => { - const result = await toStyleDictionary( - seeds().tokens.filter(({ type }) => type === "vector") as Array, - { splitBy: "/", assetsBaseDirectory: { icons: "icons" } }, - libs - ); - expect(Array.isArray(result)).toEqual(true); - expect(result.length).toEqual(1); // Time token only creates base - const file = result[0]; - expect(typeof file.name).toEqual("string"); - expect(file.name).toEqual("asset/icon.json"); - expect(typeof file.value.content).toEqual("string"); - const content = JSON.parse(file.value.content!) as Record; - expect(Object.keys(content)[0]).toEqual("asset"); - expect(Object.keys(content.asset)[0]).toEqual("icon"); - Object.values(content.asset).forEach(property => { - Object.values(property as Record).forEach( - nestedProperty => { - expect(nestedProperty.value.includes("icons/")).toBeTruthy(); - expect(nestedProperty.value).toEqual(expect.any(String)); - } - ); - }); - }); - - it("Should be able to extract without splitBy", async () => { - const result = await toStyleDictionary( - seeds().tokens.filter(({ type }) => type === "color") as Array, - {}, - libs - ); - - expect(Array.isArray(result)).toEqual(true); - expect(result.length).toEqual(1); // Color token only creates base - const file = result[0]; - expect(typeof file.name).toEqual("string"); - expect(file.name).toEqual("color/base.json"); - expect(typeof file.value.content).toEqual("string"); - const content = JSON.parse(file.value.content!) as Record; - expect(Object.keys(content)[0]).toEqual("color"); - expect(Object.keys(content.color)[0]).toEqual("base"); - expect(content.color.base["colorsAccent"]).toEqual({ - value: expect.any(String), - }); - expect(content.color.base["colorsBlack"]).toEqual({ - value: expect.any(String), - }); - expect(content.color.base["colorsGreen"]).toEqual({ - value: expect.any(String), - }); - expect(content.color.base["colorsGrey"]).toEqual({ - value: expect.any(String), - }); - expect(content.color.base["colorsOrange"]).toEqual({ - value: expect.any(String), - }); - }); - - describe("Should generate simple token per type", () => { - it("Color", () => { - seeds() - .tokens.filter(({ type }) => type === "color") - .map(color => { - const tokenClass: StyleDictionaryTokenClass = (TokensClass)[ - "Color" - ]; - const instance = new tokenClass(color, color.name.split("/")); - const result = instance.generate({ - formatTokens: { colorFormat: { format: "rgb" } }, - }); - expect(result).toEqual({ - color: { - base: { - Colors: { - [color.name.split("/").pop() as string]: { - value: expect.any(String), - }, - }, - }, - }, - }); - }); - }); - it("Border", () => { - seeds() - .tokens.filter(({ type }) => type === "border") - .map(border => { - const tokenClass: StyleDictionaryTokenClass = (TokensClass)[ - "Border" - ]; - const instance = new tokenClass(border, border.name.split("-")); - const result = instance.generate({ - formatTokens: { colorFormat: { format: "rgb" } }, - }); - const expectation: Record = { - size: { - border: { border: expect.any(Object) }, - }, - color: { - border: { border: expect.any(Object) }, - }, - }; - if ("radii" in border.value) { - expectation.size.radius = { border: expect.any(Object) }; - } - expect(result).toEqual(expectation); - }); - }); - it("Depth", () => { - seeds() - .tokens.filter(({ type }) => type === "depth") - .map(depth => { - const tokenClass: StyleDictionaryTokenClass = (TokensClass)[ - "Depth" - ]; - const instance = new tokenClass(depth, depth.name.split("-")); - const result = instance.generate({}); - expect(result).toEqual({ - depth: { base: { [depth.name]: { value: expect.any(String) } } }, - }); - }); - }); - it("Duration", () => { - seeds() - .tokens.filter(({ type }) => type === "duration") - .map(duration => { - const tokenClass: StyleDictionaryTokenClass = (TokensClass)[ - "Duration" - ]; - const instance = new tokenClass(duration, duration.name.split("-")); - const result = instance.generate({}); - expect(result).toEqual({ - time: { base: { [duration.name]: { value: expect.any(String) } } }, - }); - }); - }); - it("Measurement", () => { - seeds() - .tokens.filter(({ type }) => type === "measurement") - .map(measurement => { - const tokenClass: StyleDictionaryTokenClass = (TokensClass)[ - "Measurement" - ]; - const instance = new tokenClass( - measurement, - measurement.name.split("-") - ); - const result = instance.generate({}); - expect(result).toEqual({ - size: { - base: { - base: { - space: { - [measurement.name.split("-").pop() as string]: { - value: expect.any(String), - }, - }, - }, - }, - }, - }); - }); - }); - it("Opacity", () => { - seeds() - .tokens.filter(({ type }) => type === "opacity") - .map(opacity => { - const tokenClass: StyleDictionaryTokenClass = (TokensClass)[ - "Opacity" - ]; - const instance = new tokenClass(opacity, opacity.name.split("-")); - const result = instance.generate({}); - expect(result).toEqual({ - opacity: { - base: { - [opacity.name.split("-").pop() as string]: { - value: expect.any(String), - }, - }, - }, - }); - }); - }); - it("Shadow", () => { - seeds() - .tokens.filter(({ type }) => type === "shadow") - .map(shadow => { - const tokenClass: StyleDictionaryTokenClass = (TokensClass)[ - "Shadow" - ]; - const instance = new tokenClass(shadow, shadow.name.split("-")); - const result = instance.generate({}); - expect(result).toEqual({ - color: { - shadow: { - Elevation: expect.any(Object), - }, - }, - size: { - shadow: { - Elevation: expect.any(Object), - }, - }, - }); - }); - }); - it("TextStyle", () => { - seeds() - .tokens.filter(({ type }) => type === "textStyle") - .map(textStyle => { - const tokenClass: StyleDictionaryTokenClass = (TokensClass)[ - "TextStyle" - ]; - const instance = new tokenClass(textStyle, textStyle.name.split("-")); - const result = instance.generate({}); - const firstLevelSplitedTokenName = textStyle.name - .split("-") - .shift() as string; - const expectation: Record = { - size: { - font: { [firstLevelSplitedTokenName]: expect.any(Object) }, - lineHeight: { [firstLevelSplitedTokenName]: expect.any(Object) }, - }, - }; - if ("color" in textStyle.value) { - expectation.color = { - font: { [firstLevelSplitedTokenName]: expect.any(Object) }, - }; - } - if ("letterSpacing" in textStyle.value) { - expectation.size.letterSpacing = { - [firstLevelSplitedTokenName]: expect.any(Object), - }; - } - if ("textIndent" in textStyle.value) { - expectation.size.textIndent = { - [firstLevelSplitedTokenName]: expect.any(Object), - }; - } - expect(result).toEqual(expectation); - }); - }); - it("Font", () => { - seeds() - .tokens.filter(({ type }) => type === "font") - .map(font => { - const tokenClass: StyleDictionaryTokenClass = (TokensClass)[ - "Font" - ]; - const [familyName, subFamilyName] = font.name.split("-"); - const instance = new tokenClass(font, [familyName, subFamilyName]); - const expectedFormats: Array = ["woff", "woff2"]; - const result = instance.generate({ - formatTokens: { - fontFormat: expectedFormats, - }, - }); - - expect(result).toEqual({ - asset: { - font: { - [familyName]: { - [subFamilyName]: expectedFormats.reduce< - Record - >( - (acc, format) => { - acc[format] = { - value: `${font.name}.${format}`, - }; - return acc; - }, - { - name: { - value: font.name, - }, - } - ), - }, - }, - }, - }); - }); - }); - }); -}); diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-style-dictionary/to-style-dictionary.type.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-style-dictionary/to-style-dictionary.type.ts deleted file mode 100644 index 547ccc62b..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-style-dictionary/to-style-dictionary.type.ts +++ /dev/null @@ -1,68 +0,0 @@ -import Token from "../../types/tokens/Token"; -import { OptionsType } from "./to-style-dictionary.parser"; - -type BasicObject = Record; -type RecursiveBasicObject = Record; -export type BaseStyleDictionaryTokensFormat = Partial<{ - color: Partial<{ - base: RecursiveBasicObject; // from colors in Specify - font: RecursiveBasicObject; // from textStyles in Specify - // gradient: RecursiveBasicObject; Useless until we can add property like direction or position in style dictionary. - shadow: Record< - string, - Partial<{ - blur: RecursiveBasicObject; // from shadows in Specify - offsetX: RecursiveBasicObject; // from shadows in Specify - offsetY: RecursiveBasicObject; // from shadows in Specify - spread: RecursiveBasicObject; // from shadows in Specify - }> - >; // from shadows in Specify - border: RecursiveBasicObject; // from borders in Specify - }>; - size: Partial<{ - base: RecursiveBasicObject; // from measurement in Specify - font: RecursiveBasicObject; // from textStyles in Specify - border: RecursiveBasicObject; // from borders in Specify - radius: RecursiveBasicObject; // from borders in Specify - lineHeight: RecursiveBasicObject; // from textStyles in Specify - letterSpacing: RecursiveBasicObject; // from textStyles in Specify - textIndent: RecursiveBasicObject; // from textStyles in Specify - shadow: Record< - string, - Partial<{ - blur: RecursiveBasicObject; // from shadows in Specify - offsetX: RecursiveBasicObject; // from shadows in Specify - offsetY: RecursiveBasicObject; // from shadows in Specify - spread: RecursiveBasicObject; // from shadows in Specify - }> - >; - }>; - time: Partial<{ - base: RecursiveBasicObject; // from duration in Specify - }>; - asset: Partial<{ - font: RecursiveBasicObject; - icon: RecursiveBasicObject; - image: RecursiveBasicObject; - }>; - opacity: Partial<{ - base: RecursiveBasicObject; - }>; - depth: Partial<{ - base: RecursiveBasicObject; // from depth in Specify - }>; -}>; - -export interface StyleDictionaryTokenClass { - new ( - tokens: Partial, - options: Array - ): StyleDictionaryTokenClassInstance; - // afterStringGenerate?(tailwindTokens: TailwindOutputType, result: string): string; - // afterGenerate(TailwindTokens: TailwindMappingTypes): TailwindOutputType; -} - -export interface StyleDictionaryTokenClassInstance { - transformedName: string; - generate(options: OptionsType): Partial; -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-style-dictionary/tokens/bitmap.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-style-dictionary/tokens/bitmap.ts deleted file mode 100644 index 3e3bfb0f5..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-style-dictionary/tokens/bitmap.ts +++ /dev/null @@ -1,28 +0,0 @@ -import Path from "path"; -import * as _ from "lodash"; -import { BitmapToken } from "../../../types"; -import { OptionsType } from "../to-style-dictionary.parser"; -import { BaseStyleDictionaryTokensFormat } from "../to-style-dictionary.type"; - -export class Bitmap extends BitmapToken { - keys: Array; - constructor(token: Partial, keys: Array) { - super(token); - this.keys = ["asset", "image", ...keys]; - } - generate( - options: OptionsType - ): Pick { - return _.setWith( - {}, - this.keys, - { - value: Path.join( - options?.assetsBaseDirectory?.images ?? "", - `${this.name}@${this.value.dimension ?? 1}.${this.value.format}` - ), - }, - Object - ); - } -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-style-dictionary/tokens/border.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-style-dictionary/tokens/border.ts deleted file mode 100644 index b7841afdd..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-style-dictionary/tokens/border.ts +++ /dev/null @@ -1,52 +0,0 @@ -import { BorderToken } from "../../../types"; -import tinycolor from "tinycolor2"; -import { BaseStyleDictionaryTokensFormat } from "../to-style-dictionary.type"; -import { OptionsType } from "../to-style-dictionary.parser"; -import * as _ from "lodash"; - -export class Border extends BorderToken { - keys: Array; - constructor(token: Partial, keys: Array) { - super(token); - this.keys = keys; - } - - generate( - options: OptionsType - ): Pick { - const { width, radii, color } = this.value; - - let result = _.setWith< - Pick - >( - {}, - ["size", "border", ...this.keys], - { value: `${width.value.measure}${width.value.unit}` }, - Object - ); - if (radii && radii.value) { - result = _.setWith( - result, - ["size", "radius", ...this.keys], - { value: `${radii?.value.measure}${radii?.value.unit}` }, - Object - ); - } - - if (color && color.value) { - if (!result.color) result.color = {}; - result = _.setWith( - result, - ["color", "border", ...this.keys], - { - value: tinycolor(color.value).toString( - options?.formatTokens?.colorFormat?.format || "rgb" - ), - }, - Object - ); - } - - return result; - } -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-style-dictionary/tokens/color.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-style-dictionary/tokens/color.ts deleted file mode 100644 index 05b6d6245..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-style-dictionary/tokens/color.ts +++ /dev/null @@ -1,27 +0,0 @@ -import tinycolor from "tinycolor2"; -import { ColorToken } from "../../../types"; -import { OptionsType } from "../to-style-dictionary.parser"; -import { BaseStyleDictionaryTokensFormat } from "../to-style-dictionary.type"; -import * as _ from "lodash"; - -export class Color extends ColorToken { - keys: Array; - constructor(token: Partial, keys: Array) { - super(token); - this.keys = ["color", "base", ...keys]; - } - generate( - options: OptionsType - ): Pick { - return _.setWith( - {}, - this.keys, - { - value: tinycolor(this.value).toString( - options?.formatTokens?.colorFormat?.format || "rgb" - ), - }, - Object - ); - } -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-style-dictionary/tokens/depth.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-style-dictionary/tokens/depth.ts deleted file mode 100644 index ed527db25..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-style-dictionary/tokens/depth.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { DepthToken } from "../../../types"; -import { BaseStyleDictionaryTokensFormat } from "../to-style-dictionary.type"; -import * as _ from "lodash"; - -export class Depth extends DepthToken { - keys: Array; - - constructor(token: Partial, keys: Array) { - super(token); - this.keys = ["depth", "base", ...keys]; - } - - generate(): Pick { - return _.setWith({}, this.keys, { value: `${this.value.depth}` }, Object); - } -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-style-dictionary/tokens/duration.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-style-dictionary/tokens/duration.ts deleted file mode 100644 index 3116de9c3..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-style-dictionary/tokens/duration.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { DurationToken } from "../../../types"; -import { BaseStyleDictionaryTokensFormat } from "../to-style-dictionary.type"; -import * as _ from "lodash"; - -export class Duration extends DurationToken { - keys: Array; - - constructor(token: Partial, keys: Array) { - super(token); - this.keys = ["time", "base", ...keys]; - } - - generate(): Pick { - return _.setWith( - {}, - this.keys, - { - value: `${this.value.duration}${this.value.unit}`, - }, - Object - ); - } -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-style-dictionary/tokens/font.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-style-dictionary/tokens/font.ts deleted file mode 100644 index 6d0880aee..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-style-dictionary/tokens/font.ts +++ /dev/null @@ -1,39 +0,0 @@ -import Path from "path"; -import * as _ from "lodash"; -import { FontToken } from "../../../types"; -import { OptionsType } from "../to-style-dictionary.parser"; -import { BaseStyleDictionaryTokensFormat } from "../to-style-dictionary.type"; - -export class Font extends FontToken { - keys: Array; - constructor(token: Partial, keys: Array) { - super(token); - this.keys = keys; - } - generate( - options: OptionsType - ): Pick { - return { - asset: { - font: (options?.formatTokens?.fontFormat ?? ["ttf"]).reduce( - (acc, format) => { - const path = [...this.keys, format]; - _.setWith( - acc, - path, - { - value: Path.join( - options?.assetsBaseDirectory?.fonts ?? "", - `${this.name}.${format}` - ), - }, - Object - ); - return acc; - }, - _.set({}, [...this.keys, "name"], { value: this.name }) - ), - }, - }; - } -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-style-dictionary/tokens/index.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-style-dictionary/tokens/index.ts deleted file mode 100644 index ecdf4d6c5..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-style-dictionary/tokens/index.ts +++ /dev/null @@ -1,11 +0,0 @@ -export * from "./color"; -export * from "./shadow"; -export * from "./textStyle"; -export * from "./opacity"; -export * from "./depth"; -export * from "./duration"; -export * from "./border"; -export * from "./measurement"; -export * from "./bitmap"; -export * from "./font"; -export * from "./vector"; diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-style-dictionary/tokens/measurement.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-style-dictionary/tokens/measurement.ts deleted file mode 100644 index 5b0b83af1..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-style-dictionary/tokens/measurement.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { MeasurementToken } from "../../../types"; -import { BaseStyleDictionaryTokensFormat } from "../to-style-dictionary.type"; -import * as _ from "lodash"; - -export class Measurement extends MeasurementToken { - keys: Array; - - constructor(token: Partial, keys: Array) { - super(token); - this.keys = ["size", "base", ...keys]; - } - - generate(): Pick { - return _.setWith( - {}, - this.keys, - { - value: `${this.value.measure}${this.value.unit}`, - }, - Object - ); - } -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-style-dictionary/tokens/opacity.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-style-dictionary/tokens/opacity.ts deleted file mode 100644 index dbd94d4a4..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-style-dictionary/tokens/opacity.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { OpacityToken } from "../../../types"; -import { BaseStyleDictionaryTokensFormat } from "../to-style-dictionary.type"; -import * as _ from "lodash"; - -export class Opacity extends OpacityToken { - keys: Array; - - constructor(token: Partial, keys: Array) { - super(token); - this.keys = ["opacity", "base", ...keys]; - } - - generate(): Pick { - return _.setWith( - {}, - this.keys, - { - value: `${this.value.opacity / 100}`, - }, - Object - ); - } -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-style-dictionary/tokens/shadow.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-style-dictionary/tokens/shadow.ts deleted file mode 100644 index c3299913e..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-style-dictionary/tokens/shadow.ts +++ /dev/null @@ -1,88 +0,0 @@ -import { ShadowToken } from "../../../types"; -import tinycolor from "tinycolor2"; -import { BaseStyleDictionaryTokensFormat } from "../to-style-dictionary.type"; -import { OptionsType } from "../to-style-dictionary.parser"; -import * as _ from "lodash"; - -export class Shadow extends ShadowToken { - keys: Array; - constructor(token: Partial, keys: Array) { - super(token); - this.keys = keys; - } - generate( - options: OptionsType - ): Pick { - const colorFormat = options?.formatTokens?.colorFormat?.format ?? "rgb"; - - return { - color: { - shadow: this.value.reduce< - NonNullable - >((acc, shadow, index) => { - const keys = [...this.keys, `${index}`]; - _.setWith( - acc, - keys, - { - value: tinycolor(shadow.color.value).toString(colorFormat), - }, - Object - ); - return acc; - }, {}), - }, - size: { - shadow: this.value.reduce< - NonNullable - >((acc, shadow, index) => { - const keys = [...this.keys, `${index}`]; - - if (shadow.offsetX.value.measure !== 0) { - _.setWith( - acc, - [...keys, "offsetX"], - { - value: `${shadow.offsetX.value.measure}${shadow.offsetX.value.unit}`, - }, - Object - ); - } - if (shadow.offsetY.value.measure !== 0) { - _.setWith( - acc, - [...keys, "offsetY"], - { - value: `${shadow.offsetY.value.measure}${shadow.offsetY.value.unit}`, - }, - Object - ); - } - if (shadow.blur.value.measure !== 0) { - _.setWith( - acc, - [...keys, "blur"], - { - value: `${shadow.blur.value.measure}${shadow.blur.value.unit}`, - }, - Object - ); - } - - if (shadow.spread) { - _.setWith( - acc, - [...keys, "spread"], - { - value: `${shadow.spread.value.measure}${shadow.spread.value.unit}`, - }, - Object - ); - } - - return acc; - }, {}), - }, - }; - } -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-style-dictionary/tokens/textStyle.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-style-dictionary/tokens/textStyle.ts deleted file mode 100644 index 123f44d45..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-style-dictionary/tokens/textStyle.ts +++ /dev/null @@ -1,118 +0,0 @@ -import * as _ from "lodash"; -import tinycolor from "tinycolor2"; -import convertMeasurement from "../../../libs/size-manipulation"; -import { TextStyleToken } from "../../../types"; -import { FormatTokenType, OptionsType } from "../to-style-dictionary.parser"; -import { BaseStyleDictionaryTokensFormat } from "../to-style-dictionary.type"; - -export class TextStyle extends TextStyleToken { - keys: Array; - constructor(token: Partial, keys: Array) { - super(token); - this.keys = keys; - } - - private getLetterSpacing() { - const ls = this.value.letterSpacing; - if (ls) return `${ls.value.measure}${ls.value.unit}`; - return undefined; - } - private getLineHeight() { - const lh = this.value.lineHeight; - return `${lh.value.measure}${lh.value.unit}`; - } - private getTextIndent() { - const ti = this.value.textIndent; - if (ti) return `${ti.value.measure}${ti.value.unit}`; - return undefined; - } - private getColor( - format: NonNullable["format"] - ) { - if (this.value.color?.value) { - return tinycolor(this.value.color?.value).toString(format); - } - return undefined; - } - - private getFontSize(fontFormat: FormatTokenType["fontSizeFormat"]) { - const fontSize = this.value.fontSize; - if ( - fontFormat?.unit && - this.value.fontSize.value.unit !== fontFormat?.unit - ) { - this.value.fontSize.value = - fontFormat?.unit === "none" || !fontFormat.unit - ? this.value.fontSize.value - : convertMeasurement(this.value.fontSize.value, fontFormat?.unit); - } - return `${fontSize.value.measure}${fontSize.value.unit}`; - } - - generate( - options: OptionsType - ): Pick { - let result: Pick = {}; - - result = _.setWith( - result, - ["size", "font", ...this.keys], - { - value: this.getFontSize(options?.formatTokens?.fontSizeFormat), - }, - Object - ); - - const letterSpacing = this.getLetterSpacing(); - if (letterSpacing) { - _.setWith( - result, - ["size", "letterSpacing", ...this.keys], - { - value: letterSpacing, - }, - Object - ); - } - - const lineHeight = this.getLineHeight(); - if (lineHeight) { - _.setWith( - result, - ["size", "lineHeight", ...this.keys], - { - value: lineHeight, - }, - Object - ); - } - - const textColor = this.getColor( - options?.formatTokens?.colorFormat?.format || "hex" - ); - if (textColor) { - _.setWith( - result, - ["color", "font", ...this.keys], - { - value: textColor, - }, - Object - ); - } - - const textIndent = this.getTextIndent(); - if (textIndent) { - _.setWith( - result, - ["size", "textIndent", ...this.keys], - { - value: textIndent, - }, - Object - ); - } - - return result; - } -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-style-dictionary/tokens/vector.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-style-dictionary/tokens/vector.ts deleted file mode 100644 index 4050dde55..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-style-dictionary/tokens/vector.ts +++ /dev/null @@ -1,28 +0,0 @@ -import Path from "path"; -import * as _ from "lodash"; -import { VectorToken } from "../../../types"; -import { OptionsType } from "../to-style-dictionary.parser"; -import { BaseStyleDictionaryTokensFormat } from "../to-style-dictionary.type"; - -export class Vector extends VectorToken { - keys: Array; - constructor(token: Partial, keys: Array) { - super(token); - this.keys = ["asset", "icon", ...keys]; - } - generate( - options: OptionsType - ): Pick { - return _.setWith( - {}, - this.keys, - { - value: Path.join( - options?.assetsBaseDirectory?.icons ?? "", - `${this.name}.${this.value.format}` - ), - }, - Object - ); - } -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-tailwind/README.md b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-tailwind/README.md deleted file mode 100644 index 8fa946239..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-tailwind/README.md +++ /dev/null @@ -1,435 +0,0 @@ -# To Tailwind - -## Description - -Format design tokens to create a theme compatible with the [TailwindCSS specification](https://tailwindcss.com/docs/theme). -The theme is also compatible with [WindiCSS](https://windicss.org/). - -This parser creates a file containing the whole theme. It can then be used in the `tailwind.config.js`. - -The theme created by this parser is compatible with the Tailwind versions >= `2.x`. - -Learn more about how to configure Specify in the API documentation: [https://specifyapp.com/developers](https://specifyapp.com/developers). - -## Interface - -```ts -interface parser { - name: "to-tailwind"; - options: Partial<{ - formatName: "camelCase" | "kebabCase" | "snakeCase" | "pascalCase"; - formatTokens: Partial<{ - colorFormat: { - format: ColorsFormat; - }; - fontSizeFormat: { - unit: "px" | "rem"; - }; - }>; - formatConfig: Partial<{ - module: "es6" | "commonjs"; - objectName: string; - endOfLine: "auto" | "lf" | "crlf" | "cr"; - tabWidth: number; - useTabs: boolean; - singleQuote: boolean; - exportDefault: boolean; - }>; - splitBy?: string; - renameKeys: PartialRecord; - }>; -} -``` - -### Options - -| Parameter | Required | Type | Default | Description | -| ---------------------------------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | ----------- | ------------------------------------------------------------------------------ | -| `formatName` | optional | `camelCase` `kebabCase` `snakeCase` `pascalCase` | `kebabCase` | The case transformation you want to apply to your design token name | -| `formatConfig.module` | optional | `es6` `commonjs` `json` | `es6` | Module loader used to export the result | -| `formatConfig.objectName` | optional | `string` | `theme` | Name of exported variable | -| `formatConfig.endOfLine` | optional | `auto` `lf` `crlf` `cr` | `auto` | [Prettier documentation](https://prettier.io/docs/en/options.html#end-of-line) | -| `formatConfig.tabWidth` | optional | `number` | `2` | [Prettier documentation](https://prettier.io/docs/en/options.html#tab-width) | -| `formatConfig.useTabs` | optional | `boolean` | `true` | [Prettier documentation](https://prettier.io/docs/en/options.html#tabs) | -| `formatConfig.singleQuote` | optional | `boolean` | `false` | [Prettier documentation](https://prettier.io/docs/en/options.html#quotes) | -| `formatConfig.exportDefault` | optional | `boolean` | `true` | | -| `formatTokens.colorFormat.format` | optional | `rgb` `prgb` `hex` `hex6` `hex3` `hex4` `hex8` `name` `hsl` `hsv` | `hex` | The color format you want to apply to your potential color design token | -| `formatTokens.fontSizeFormat.unit` | optional | `px` `rem` | `none` | | -| `renameKeys` | optional | `{ colors?: string, spacing?: string... }` [full list](https://github.com/Specifyapp/parsers/blob/master/parsers/to-tailwind/to-tailwind.type.ts#L16) | `none` | Used to rename the generated tokens based on their Tailwind theme keys | -| `splitBy` | optional | `string` | none | The character used to define the nesting of the values in the generated object | - -## Types - -โ„น๏ธ **Please be aware that, depending on the order you use parsers, their input and output types have to match.** - -### Input - -Array of object with at least name, value and type: - -```ts -type input = Array<{ name: string; value: any; type: string }>; -``` - -### Output - -String formated in js or json. - -```ts -type output = string; -``` - -## Basic Usage - -### Config - -```jsonc -"parsers": [ - { - "name": "to-tailwind" - } - // โ€ฆ -] -``` - -### Before/After - -#### Input - -```jsonc -[ - { - "name": "primary", - "value": { - "a": 1, - "b": 255, - "g": 189, - "r": 198 - }, - "type": "color" - }, - { - "name": "base-space-01", - "value": { - "unit": "px", - "measure": 4 - }, - "type": "measurement" - }, - { - "name": "body", - "value": { - "font": { - "id": "69d2d62e-4d62-45d7-b85f-5da2f9f0c0d4", - "name": "Roboto-Regular", - "value": { - "fontFamily": "Roboto", - "fontWeight": 400, - "fontPostScriptName": "Roboto-Regular" - }, - "type": "font" - }, - "fontSize": { - "value": { - "unit": "px", - "measure": 16 - } - }, - "textAlign": { - "vertical": "top", - "horizontal": "left" - }, - "lineHeight": { - "value": { - "unit": "px", - "measure": 20 - } - }, - "fontVariant": ["small-caps"] - }, - "type": "textStyle" - } -] -``` - -#### Output - -```js -const theme = { - colors: { - primary: "#c6bdff", - }, - fontSize: { body: "16px" }, - lineHeight: { body: "20px" }, - fontFamily: { - body: ["Roboto-Regular"], - }, - spacing: { - "base-space-01": "4px", - }, -}; - -export default theme; -``` - -## Complex usage - with specific config for `colorFormat` - -### Config - -```jsonc -"parsers": [ - { - "name": "to-tailwind", - "options": { - "formatTokens": { - "colorFormat": { - "format": "rgb" - } - }, - "formatConfig": { - "objectName": "extend", - "module": "commonjs" - } - } - } - // โ€ฆ -] -``` - -### Before/After - -#### Input - -```jsonc -[ - { - "name": "primary", - "value": { - "a": 1, - "b": 255, - "g": 189, - "r": 198 - }, - "type": "color" - }, - { - "name": "base-space-01", - "value": { - "unit": "px", - "measure": 4 - }, - "type": "measurement" - }, - { - "name": "body", - "value": { - "font": { - "id": "69d2d62e-4d62-45d7-b85f-5da2f9f0c0d4", - "name": "Roboto-Regular", - "value": { - "fontFamily": "Roboto", - "fontWeight": 400, - "fontPostScriptName": "Roboto-Regular" - }, - "type": "font" - }, - "fontSize": { - "value": { - "unit": "px", - "measure": 16 - } - }, - "textAlign": { - "vertical": "top", - "horizontal": "left" - }, - "lineHeight": { - "value": { - "unit": "px", - "measure": 20 - } - }, - "fontVariant": ["small-caps"] - }, - "type": "textStyle" - } -] -``` - -#### Output - -```js -const extend = { - colors: { - primary: "rgb(198, 189, 255)", - }, - fontSize: { body: "16px" }, - lineHeight: { body: "20px" }, - fontFamily: { - body: ["Roboto-Regular"], - }, - spacing: { - "base-space-01": "4px", - }, -}; - -module.exports = extend; -``` - -## Complex usage - with specific config for `renameKeys` - -### Config - -```jsonc -"parsers": [ - { - "name": "to-tailwind", - "options": { - "renameKeys": { - "colors": "custom-color-{{name}}", - "spacing": "custom-spacing-{{name}}" - }, - "formatName": "kebabCase", - "formatConfig": { - "objectName": "extend", - "module": "commonjs" - } - } - } - // โ€ฆ -] -``` - -### Before/After - -#### Input - -```jsonc -[ - { - "name": "primary", - "value": { - "a": 1, - "b": 255, - "g": 189, - "r": 198 - }, - "type": "color" - }, - { - "name": "base-space-01", - "value": { - "unit": "px", - "measure": 4 - }, - "type": "measurement" - } -] -``` - -#### Output - -```js -const extend = { - colors: { - "custom-color-primary": "#C6BDFF", - }, - spacing: { - "custom-spacing-base-space-01": "4px", - }, -}; - -module.exports = extend; -``` - -## Complex usage - with specific config for `splitBy` - -### Config - -```jsonc -"parsers": [ - { - "name": "to-tailwind", - "options": { - "splitBy": "/", - "formatConfig": { - "objectName": "extend", - "module": "commonjs" - } - } - } - // โ€ฆ -] -``` - -### Before/After - -#### Input - -```jsonc -[ - { - "name": "danger/100", - "value": { - "a": 1, - "b": 135, - "g": 33, - "r": 255 - }, - "type": "color" - }, - { - "name": "danger/200", - "value": { - "a": 1, - "b": 33, - "g": 33, - "r": 255 - }, - "type": "color" - } -] -``` - -#### Output - -```js -const extend = { - colors: { - danger: { - 100: "#ff2187", - 200: "#ff2121", - }, - }, -}; - -module.exports = extend; -``` - -## โ„น๏ธ Good to know - -In your `tailwind.config.js` file, you can easily use the theme in the extend object. - -Example: - -```js -const themeBySpecify = require('./theme-by-specify'); - -module.exports = { - // Whole config - theme: { - extend: { - // add the colors only from Specify - colors: themeBySpecify.colors, - spacing: { - // use the spacing from Specify and add a custom spacing - ...themeBySpecify.spacing - 'custom-spacing': '8px', - } - }, - }, - variants: { - extend: {}, - }, - plugins: [], -}; -``` diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-tailwind/index.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-tailwind/index.ts deleted file mode 100644 index 532af3134..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-tailwind/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -import { default as toTailwindParser } from "./to-tailwind.parser"; - -export * from "./to-tailwind.parser"; -export default toTailwindParser; diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-tailwind/to-tailwind.parser.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-tailwind/to-tailwind.parser.ts deleted file mode 100644 index c42a1136b..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-tailwind/to-tailwind.parser.ts +++ /dev/null @@ -1,127 +0,0 @@ -import { ConsoleLogger, deepMerge } from "@open-system/core-shared-utilities"; -import * as _ from "lodash"; -import os from "os"; -import { IToken, PartialRecord, TokensType } from "../../types"; -import { LibsType } from "../global-libs"; -import { - ColorsFormat, - FormatName, - TailwindTokenClass, - TailwindType, -} from "./to-tailwind.type"; -import * as TokensClass from "./tokens"; - -export type OutputDataType = string; -export type InputDataType = Array< - Pick & Record ->; -export type FormatTokenType = Partial<{ - colorFormat: { - format: ColorsFormat; - }; - fontSizeFormat: { - unit: "px" | "rem"; - }; -}>; -export type OptionsType = - | Partial<{ - formatName: FormatName; - formatTokens: FormatTokenType; - formatConfig: Partial<{ - module: "es6" | "commonjs"; - objectName: string; - endOfLine: "auto" | "lf" | "crlf" | "cr"; - tabWidth: number; - useTabs: boolean; - singleQuote: boolean; - exportDefault: boolean; - }>; - renameKeys: PartialRecord; - splitBy?: string; - }> - | undefined; - -function getClassByType(type: string): TailwindTokenClass | undefined { - const tokenClassName = `${type.charAt(0).toUpperCase() + type.slice(1)}`; - return (TokensClass)[tokenClassName]; -} - -class ToTailwind { - objectName; - exportDefault; - module; - tokensGroupedByType; - options; - tokens; - styles: Partial> = {}; - constructor(tokens: InputDataType, options: OptionsType) { - this.options = options; - this.objectName = options?.formatConfig?.objectName ?? "theme"; - this.exportDefault = options?.formatConfig?.exportDefault ?? true; - this.module = options?.formatConfig?.module ?? "es6"; - this.tokens = tokens; - this.tokensGroupedByType = _.groupBy(tokens, "type"); - this.styles = {}; - } - exec() { - const tokenTypes = Object.keys( - this.tokensGroupedByType - ) as Array; - this.styles = tokenTypes.reduce( - (acc, tokenType) => ({ ...acc, ...this.setGlobal(tokenType) }), - {} - ); - return this.finalize(JSON.stringify(this.styles)); - } - - setGlobal(tokenType: TokensType) { - const TokenHandler = getClassByType(tokenType); - if (!TokenHandler) return {}; - - const tokenByType = this.tokensGroupedByType[tokenType].reduce( - (acc, token) => { - const instance = new TokenHandler(token); - const tailwindTokens = instance.generate(this.options, this.tokens); - return deepMerge(acc, tailwindTokens); - }, - {} - ); - - return TokenHandler.afterGenerate - ? TokenHandler.afterGenerate(tokenByType) - : tokenByType; - } - - finalize(result: string) { - return (() => { - if (this.module === "es6" && this.exportDefault) - return `const ${this.objectName} = ${result} ${`;${ - os.EOL + os.EOL - }export default ${this.objectName};`}`; - else if (this.module === "es6" && !this.exportDefault) - return `export const ${this.objectName} = ${result};`; - else if (this.module === "commonjs" && this.exportDefault) - return `const ${this.objectName} = ${result}; ${`${ - os.EOL + os.EOL - }module.exports = ${this.objectName};`}`; - else - return `const ${this.objectName} = ${result}; ${`${ - os.EOL + os.EOL - }module.exports = {${this.objectName}};`}`; - })(); - } -} - -export default async function ( - tokens: InputDataType, - options: OptionsType, - { _ }: Pick -): Promise { - try { - const parserInstance = new ToTailwind(tokens, options); - return parserInstance.exec(); - } catch (err) { - ConsoleLogger.error(err); - throw err; - } -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-tailwind/to-tailwind.spec.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-tailwind/to-tailwind.spec.ts deleted file mode 100644 index 413f7c287..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-tailwind/to-tailwind.spec.ts +++ /dev/null @@ -1,948 +0,0 @@ -import * as _ from "lodash"; -import { camelCase } from "lodash"; -import tinycolor from "tinycolor2"; -import seeds from "../../tests/seeds"; -import { - BorderToken, - ColorToken, - DepthToken, - DurationToken, - FontToken, - GradientToken, - MeasurementToken, - OpacityToken, - ShadowToken, - TextStyleToken, -} from "../../types"; -import libs from "../global-libs"; -import toTailwind from "./to-tailwind.parser"; -import { getNameFormatterFunction } from "./utils/getNameFormatterFunction"; - -describe("To tailwind", () => { - it("Should generate the colors object", async () => { - const tokens = seeds().tokens.filter( - token => token.type === "color" - ) as Array; - const result = await toTailwind(tokens, undefined, libs); - - tokens.forEach(({ name, value }) => { - expect(result).toEqual(expect.stringMatching(_.camelCase(name))); - expect(result).toEqual( - expect.stringMatching(tinycolor(value).toString("hex")) - ); - }); - - return; - }); - - it("Should generate the border object", async () => { - const tokens = seeds().tokens.filter( - token => token.type === "border" - ) as Array; - const result = await toTailwind(tokens, undefined, libs); - - tokens.forEach(({ name, value }) => { - expect(result).toEqual(expect.stringMatching("borderWidth")); - expect(result).toEqual( - expect.stringMatching( - `${_.camelCase(name)}: "${value.width.value.measure}${ - value.width.value.unit - }"` - ) - ); - expect(result).toEqual(expect.stringMatching("borderColor")); - expect(result).toEqual( - expect.stringMatching( - `${_.camelCase(name)}: "${tinycolor(value.color.value).toString( - "hex" - )}"` - ) - ); - if (value.radii) { - expect(result).toEqual(expect.stringMatching("borderRadius")); - expect(result).toEqual( - expect.stringMatching( - `${_.camelCase(name)}: "${value.radii?.value.measure}${ - value.radii?.value.unit - }"` - ) - ); - } - - if (value.color.value.a && value.color.value.a !== 1) { - expect(result).toEqual(expect.stringMatching("borderOpacity")); - expect(result).toEqual( - expect.stringMatching( - `${_.camelCase(name)}: "${value.color.value.a}"` - ) - ); - } - }); - - return; - }); - - it("Should generate the depth object", async () => { - const tokens = seeds().tokens.filter( - token => token.type === "depth" - ) as Array; - const result = await toTailwind(tokens, undefined, libs); - - tokens.forEach(({ name, value }) => { - expect(result).toEqual( - expect.stringMatching(`${_.camelCase(name)}: "${value.depth}"`) - ); - }); - - return; - }); - - it("Should generate the duration object", async () => { - const tokens = seeds().tokens.filter( - token => token.type === "duration" - ) as Array; - const result = await toTailwind(tokens, undefined, libs); - - tokens.forEach(({ name, value }) => { - expect(result).toEqual( - expect.stringMatching( - `${_.camelCase(name)}: "${value.duration}${value.unit}"` - ) - ); - }); - - return; - }); - - it("Should generate the gradient object", async () => { - const tokens = seeds().tokens.filter( - token => token.type === "gradient" - ) as Array; - const result = await toTailwind(tokens, undefined, libs); - tokens.forEach(({ name, value }) => { - const gradientValue = value.gradients - .map(gradient => { - return `linear-gradient(${gradient.angle}, ${gradient.colors - .map( - ({ color, position }) => - `${tinycolor(color.value).toString("hex")} ${position}%` - ) - .join(", ")})`; - }) - .join(", "); - expect(result).toEqual( - expect.stringMatching( - `${_.camelCase(name)}: "${gradientValue - .replace(/\(/, "\\(") - .replace(/\)/, "\\)")}"` - ) - ); - }); - - return; - }); - - it("Should generate the measurement object", async () => { - const tokens = seeds().tokens.filter( - token => token.type === "measurement" - ) as Array; - const result = await toTailwind(tokens, undefined, libs); - - tokens.forEach(({ name, value }) => { - expect(result).toEqual( - expect.stringMatching( - `${_.camelCase(name)}: "${value.measure}${value.unit}"` - ) - ); - }); - - return; - }); - - it("Should generate the opacity object", async () => { - const tokens = seeds().tokens.filter( - token => token.type === "opacity" - ) as Array; - const result = await toTailwind(tokens, undefined, libs); - - tokens.forEach(({ name, value }) => { - expect(result).toEqual( - expect.stringMatching(`${_.camelCase(name)}: "${value.opacity / 100}"`) - ); - }); - - return; - }); - - it("Should generate the shadow object", async () => { - const tokens = seeds().tokens.filter( - token => token.type === "shadow" - ) as Array; - const result = await toTailwind(tokens, undefined, libs); - - tokens.forEach(({ name, value }) => { - const shadowString = value - .reduce>((acc, shadow) => { - const { color, offsetX, offsetY, blur, isInner, spread } = shadow; - const x = `${offsetX.value.measure}${offsetX.value.unit}`; - const y = `${offsetY.value.measure}${offsetY.value.unit}`; - const blurString = `${blur.value.measure}${blur.value.unit}`; - const spreadString = spread - ? ` ${spread.value.measure}${spread.value.unit}` - : ""; - const innerText = isInner ? "inset " : ""; - const colorString = tinycolor(color.value).toString("hex"); - acc.push( - `${innerText}${x} ${y} ${blurString}${spreadString} ${colorString}` - ); - return acc; - }, []) - .join(", "); - - // Create RegExp to skip the problem of - const regexp = new RegExp( - `${_.camelCase(name)}:\\s*"${shadowString.replace(/\./g, "\\.")}"`, - "gm" - ); - expect(result).toEqual(expect.stringMatching(regexp)); - }); - - return; - }); - - it("Should generate the textStyle object", async () => { - const tokens = seeds().tokens.filter( - token => token.type === "textStyle" - ) as Array; - const result = await toTailwind(tokens, undefined, libs); - - tokens.forEach(({ name, value }) => { - // Match font size - expect(result).toEqual(expect.stringMatching("fontSize")); - expect(result).toEqual( - expect.stringMatching( - `${_.camelCase(name)}: "${value.fontSize.value.measure}${ - value.fontSize.value.unit - }"` - ) - ); - // Match line height - expect(result).toEqual(expect.stringMatching("lineHeight")); - expect(result).toEqual( - expect.stringMatching( - `${_.camelCase(name)}: "${value.lineHeight.value.measure}${ - value.lineHeight.value.unit - }"` - ) - ); - // Match fontFamily - expect(result).toEqual(expect.stringMatching("fontFamily")); - expect(result).toEqual( - expect.stringMatching( - `${_.camelCase(name)}: ["${(value.font as FontToken).name.replace( - "-", - "\\-" - )}"]` - ) - ); - // Match textOpacity - expect(result).toEqual(expect.stringMatching("textOpacity")); - if (value.color?.value.a && value.color?.value.a < 1) { - expect(result).toEqual( - expect.stringMatching( - `${_.camelCase(name)}: "${value.color?.value.a}"` - ) - ); - } - - // Match textColor - expect(result).toEqual(expect.stringMatching("textColor")); - if (value.color?.value) { - expect(result).toEqual( - expect.stringMatching( - `${_.camelCase(name)}: "${tinycolor(value.color.value).toString( - "hex" - )}"` - ) - ); - } - - // Match letterSpacing - expect(result).toEqual(expect.stringMatching("letterSpacing")); - if (value.letterSpacing?.value) { - expect(result).toEqual( - expect.stringMatching( - `${_.camelCase(name)}: "${value.letterSpacing.value.measure}${ - value.letterSpacing.value.unit - }"` - ) - ); - } - }); - - return; - }); - - it("Should generate with multiple types", async () => { - const tokens = seeds().tokens.filter(token => - ["color", "gradient"].includes(token.type) - ) as Array; - const result = await toTailwind(tokens, undefined, libs); - - tokens.forEach(token => { - if (token.type === "color") { - const color = token as ColorToken; - expect(result).toEqual(expect.stringMatching(_.camelCase(color.name))); - expect(result).toEqual( - expect.stringMatching(tinycolor(color.value).toString("hex")) - ); - } else { - const gradient = token as GradientToken; - - const gradientValue = gradient.value.gradients - .map(gradient => { - return `linear-gradient(${gradient.angle}, ${gradient.colors - .map( - ({ color, position }) => - `${tinycolor(color.value).toString("hex")} ${position}%` - ) - .join(", ")})`; - }) - .join(", "); - - expect(result).toEqual( - expect.stringMatching( - `.*${_.camelCase(gradient.name)}: "${gradientValue - .replace(/\(/, "\\(") - .replace(/\)/, "\\)")}".*` - ) - ); - } - }); - return; - }); - - it("Should generate with specific formatName", async () => { - const tokens = seeds().tokens.filter( - token => token.type === "color" - ) as Array; - const result = await toTailwind(tokens, { formatName: "kebabCase" }, libs); - - tokens.forEach(({ name, value }) => { - expect(result).toEqual(expect.stringMatching(_.kebabCase(name))); - expect(result).toEqual( - expect.stringMatching(tinycolor(value).toString("hex")) - ); - }); - - return; - }); - - it("Should generate with specific format on colors", async () => { - const tokens = seeds().tokens.filter( - token => token.type === "color" - ) as Array; - const result = await toTailwind( - tokens, - { - formatTokens: { - colorFormat: { - format: "hsl", - }, - }, - }, - libs - ); - - tokens.forEach(({ name, value }) => { - expect(result).toEqual( - expect.stringMatching( - `${_.camelCase(name)}: "${tinycolor(value) - .toString("hsl") - .replace(/\(/, "\\(") - .replace(/\)/, "\\)")}"` - ) - ); - }); - - return; - }); - - it("Should generate with specific format on textStyle", async () => { - const tokens = seeds().tokens.filter( - token => token.type === "textStyle" - ) as Array; - const result = await toTailwind( - tokens, - { - formatTokens: { - fontSizeFormat: { - unit: "rem", - }, - }, - }, - libs - ); - - tokens.forEach(({ name, value }) => { - // Match font size - expect(result).toEqual(expect.stringMatching("fontSize")); - expect(result).toEqual( - expect.stringMatching( - `${_.camelCase(name)}: "${value.fontSize.value.measure}rem"` - ) - ); - // Match line height - expect(result).toEqual(expect.stringMatching("lineHeight")); - expect(result).toEqual( - expect.stringMatching( - `${_.camelCase(name)}: "${value.lineHeight.value.measure}${ - value.lineHeight.value.unit - }"` - ) - ); - // Match fontFamily - expect(result).toEqual(expect.stringMatching("fontFamily")); - expect(result).toEqual( - expect.stringMatching( - `${_.camelCase(name)}: ["${(value.font as FontToken).name.replace( - "-", - "\\-" - )}"]` - ) - ); - // Match textOpacity - expect(result).toEqual(expect.stringMatching("textOpacity")); - if (value.color?.value.a && value.color?.value.a < 1) { - expect(result).toEqual( - expect.stringMatching( - `${_.camelCase(name)}: "${value.color?.value.a}"` - ) - ); - } - - // Match textColor - expect(result).toEqual(expect.stringMatching("textColor")); - if (value.color?.value) { - expect(result).toEqual( - expect.stringMatching( - `${_.camelCase(name)}: "${tinycolor(value.color.value).toString( - "hex" - )}"` - ) - ); - } - - // Match letterSpacing - expect(result).toEqual(expect.stringMatching("letterSpacing")); - if (value.letterSpacing?.value) { - expect(result).toEqual( - expect.stringMatching( - `${_.camelCase(name)}: "${value.letterSpacing.value.measure}${ - value.letterSpacing.value.unit - }"` - ) - ); - } - }); - - return; - }); - - it("Should generate with specific as es6 exportDefault", async () => { - const tokens = seeds().tokens.filter( - token => token.type === "color" - ) as Array; - const result = await toTailwind( - tokens, - { - formatConfig: { - module: "es6", - exportDefault: true, - }, - }, - libs - ); - - tokens.forEach(({ name, value }) => { - expect(result).toEqual(expect.stringMatching(_.camelCase(name))); - expect(result).toEqual( - expect.stringMatching(tinycolor(value).toString("hex")) - ); - }); - - expect(result).toEqual(expect.stringMatching("const theme")); - expect(result).toEqual(expect.stringMatching("export default theme")); - - return; - }); - - it("Should generate with specific as es6 not export default", async () => { - const tokens = seeds().tokens.filter( - token => token.type === "color" - ) as Array; - const result = await toTailwind( - tokens, - { - formatConfig: { - module: "es6", - exportDefault: false, - }, - }, - libs - ); - - tokens.forEach(({ name, value }) => { - expect(result).toEqual(expect.stringMatching(_.camelCase(name))); - expect(result).toEqual( - expect.stringMatching(tinycolor(value).toString("hex")) - ); - }); - - expect(result).toEqual(expect.stringMatching("export const theme")); - - return; - }); - - it("Should generate with specific as commonjs export default", async () => { - const tokens = seeds().tokens.filter( - token => token.type === "color" - ) as Array; - const result = await toTailwind( - tokens, - { - formatConfig: { - module: "commonjs", - exportDefault: true, - }, - }, - libs - ); - - tokens.forEach(({ name, value }) => { - expect(result).toEqual(expect.stringMatching(_.camelCase(name))); - expect(result).toEqual( - expect.stringMatching(tinycolor(value).toString("hex")) - ); - }); - - expect(result).toEqual(expect.stringMatching("const theme")); - expect(result).toEqual(expect.stringMatching("module.exports = theme")); - - return; - }); - - it("Should generate with specific as commonjs not export default", async () => { - const tokens = seeds().tokens.filter( - token => token.type === "color" - ) as Array; - const result = await toTailwind( - tokens, - { - formatConfig: { - module: "commonjs", - exportDefault: false, - }, - }, - libs - ); - - tokens.forEach(({ name, value }) => { - expect(result).toEqual(expect.stringMatching(_.camelCase(name))); - expect(result).toEqual( - expect.stringMatching(tinycolor(value).toString("hex")) - ); - }); - - expect(result).toEqual(expect.stringMatching("const theme")); - expect(result).toEqual(expect.stringMatching("module.exports = { theme }")); - - return; - }); - - it("Should generate with specific objectName", async () => { - const tokens = seeds().tokens.filter( - token => token.type === "color" - ) as Array; - const result = await toTailwind( - tokens, - { - formatConfig: { - module: "es6", - exportDefault: true, - objectName: "extend", - }, - }, - libs - ); - - tokens.forEach(({ name, value }) => { - expect(result).toEqual(expect.stringMatching(_.camelCase(name))); - expect(result).toEqual( - expect.stringMatching(tinycolor(value).toString("hex")) - ); - }); - - expect(result).toEqual(expect.stringMatching("const extend")); - expect(result).toEqual(expect.stringMatching("export default extend")); - - return; - }); - - it("Should allow renaming of `border` tokens", async () => { - const tokens = seeds().tokens.filter( - token => token.type === "border" - ) as Array; - const borderWidthPrefix = "border-width-"; - const borderRadiusPrefix = "border-radius-"; - const borderColorPrefix = "border-color-"; - const borderOpacityPrefix = "border-opacity-"; - - const formatName = "kebabCase"; - const result = await toTailwind( - tokens, - { - renameKeys: { - borderWidth: `${borderWidthPrefix}{{name}}`, - borderRadius: `${borderRadiusPrefix}{{name}}`, - borderColor: `${borderColorPrefix}{{name}}`, - borderOpacity: `${borderOpacityPrefix}{{name}}`, - }, - formatName, - formatConfig: { - module: "es6", - exportDefault: true, - objectName: "extend", - }, - }, - libs - ); - - tokens.forEach(({ name, value }) => { - const transformedName = getNameFormatterFunction(formatName)(name); - expect(result).toEqual( - expect.stringContaining(`${borderWidthPrefix}${transformedName}`) - ); - expect(result).toEqual( - expect.stringContaining(`${borderColorPrefix}${transformedName}`) - ); - - // only for tokens with radii values - if (value.radii) { - expect(result).toEqual( - expect.stringContaining(`${borderRadiusPrefix}${transformedName}`) - ); - } - - // only for border color using alpha - if (value.color.value.a < 1) { - expect(result).toEqual( - expect.stringContaining(`${borderOpacityPrefix}${transformedName}`) - ); - } - }); - }); - it("Should allow renaming of `color` tokens", async () => { - const tokens = seeds().tokens.filter( - token => token.type === "color" - ) as Array; - const prefix = "color-"; - - const formatName = "kebabCase"; - const result = await toTailwind( - tokens, - { - renameKeys: { - colors: `${prefix}{{name}}`, - }, - formatName, - formatConfig: { - module: "es6", - exportDefault: true, - objectName: "extend", - }, - }, - libs - ); - - tokens.forEach(({ name }) => { - const transformedName = getNameFormatterFunction(formatName)(name); - expect(result).toEqual( - expect.stringContaining(`${prefix}${transformedName}`) - ); - }); - }); - it("Should allow renaming of `depth` tokens", async () => { - const tokens = seeds().tokens.filter( - token => token.type === "depth" - ) as Array; - const prefix = "depth-"; - - const formatName = "kebabCase"; - const result = await toTailwind( - tokens, - { - renameKeys: { - zIndex: `${prefix}{{name}}`, - }, - formatName, - formatConfig: { - module: "es6", - exportDefault: true, - objectName: "extend", - }, - }, - libs - ); - - tokens.forEach(({ name }) => { - const transformedName = getNameFormatterFunction(formatName)(name); - expect(result).toEqual( - expect.stringContaining(`${prefix}${transformedName}`) - ); - }); - }); - it("Should allow renaming of `duration` tokens", async () => { - const tokens = seeds().tokens.filter( - token => token.type === "duration" - ) as Array; - const prefix = "duration-"; - - const formatName = "kebabCase"; - const result = await toTailwind( - tokens, - { - renameKeys: { - transitionDuration: `${prefix}{{name}}`, - }, - formatName, - formatConfig: { - module: "es6", - exportDefault: true, - objectName: "extend", - }, - }, - libs - ); - - tokens.forEach(({ name }) => { - const transformedName = getNameFormatterFunction(formatName)(name); - expect(result).toEqual( - expect.stringContaining(`${prefix}${transformedName}`) - ); - }); - }); - it("Should allow renaming of `gradient` tokens", async () => { - const tokens = seeds().tokens.filter( - token => token.type === "gradient" - ) as Array; - const prefix = "gradient-"; - - const formatName = "kebabCase"; - const result = await toTailwind( - tokens, - { - renameKeys: { - backgroundImage: `${prefix}{{name}}`, - }, - formatName, - formatConfig: { - module: "es6", - exportDefault: true, - objectName: "extend", - }, - }, - libs - ); - - tokens.forEach(({ name }) => { - const transformedName = getNameFormatterFunction(formatName)(name); - expect(result).toEqual( - expect.stringContaining(`${prefix}${transformedName}`) - ); - }); - }); - it("Should allow renaming of `measurement` tokens", async () => { - const tokens = seeds().tokens.filter( - token => token.type === "measurement" - ) as Array; - const prefix = "measurement-"; - - const formatName = "kebabCase"; - const result = await toTailwind( - tokens, - { - renameKeys: { - spacing: `${prefix}{{name}}`, - }, - formatName, - formatConfig: { - module: "es6", - exportDefault: true, - objectName: "extend", - }, - }, - libs - ); - - tokens.forEach(({ name }) => { - const transformedName = getNameFormatterFunction(formatName)(name); - expect(result).toEqual( - expect.stringContaining(`${prefix}${transformedName}`) - ); - }); - }); - it("Should allow renaming of `opacity` tokens", async () => { - const tokens = seeds().tokens.filter( - token => token.type === "opacity" - ) as Array; - const prefix = "opacity-"; - - const formatName = "kebabCase"; - const result = await toTailwind( - tokens, - { - renameKeys: { - opacity: `${prefix}{{name}}`, - }, - formatName, - formatConfig: { - module: "es6", - exportDefault: true, - objectName: "extend", - }, - }, - libs - ); - - tokens.forEach(({ name }) => { - const transformedName = getNameFormatterFunction(formatName)(name); - expect(result).toEqual( - expect.stringContaining(`${prefix}${transformedName}`) - ); - }); - }); - it("Should allow renaming of `shadow` tokens", async () => { - const tokens = seeds().tokens.filter( - token => token.type === "shadow" - ) as Array; - const prefix = "shadow-"; - - const formatName = "kebabCase"; - const result = await toTailwind( - tokens, - { - renameKeys: { - boxShadow: `${prefix}{{name}}`, - }, - formatName, - formatConfig: { - module: "es6", - exportDefault: true, - objectName: "extend", - }, - }, - libs - ); - - tokens.forEach(({ name }) => { - const transformedName = getNameFormatterFunction(formatName)(name); - expect(result).toEqual( - expect.stringContaining(`${prefix}${transformedName}`) - ); - }); - }); - - it("Should allow to format object with the splitBy options", async () => { - const tokens = seeds().tokens.filter( - token => !["font", "vector", "bitmap"].includes(token.type) - ); - const result = await toTailwind( - tokens, - { - splitBy: "/", - }, - libs - ); - tokens.forEach(token => { - if (token.name.includes("/")) { - expect(result).toEqual( - expect.stringContaining(`${camelCase(token.name.split("/")[0])}: {`) - ); - expect(result).toEqual( - expect.stringContaining(`${camelCase(token.name.split("/")[1])}: `) - ); - } else { - expect(result).toEqual(expect.stringContaining(camelCase(token.name))); - } - }); - }); - - it("Should allow renaming of `textStyle` tokens", async () => { - const tokens = seeds().tokens.filter( - token => token.type === "textStyle" - ) as Array; - const fontSizePrefix = "text-style-font-size-"; - const letterSpacingPrefix = "text-style-letter-spacing-"; - const lineHeightPrefix = "text-style-line-height-"; - const textColorPrefix = "text-style-text-color-"; - const textOpacityPrefix = "text-style-text-opacity-"; - const fontFamilyPrefix = "text-style-font-family-"; - const fontWeightPrefix = "text-style-font-weight-"; - - const formatName = "kebabCase"; - const result = await toTailwind( - tokens, - { - renameKeys: { - fontSize: `${fontSizePrefix}{{name}}`, - letterSpacing: `${letterSpacingPrefix}{{name}}`, - lineHeight: `${lineHeightPrefix}{{name}}`, - textColor: `${textColorPrefix}{{name}}`, - textOpacity: `${textOpacityPrefix}{{name}}`, - fontFamily: `${fontFamilyPrefix}{{name}}`, - fontWeight: `${fontWeightPrefix}{{name}}`, - }, - formatName, - formatConfig: { - module: "es6", - exportDefault: true, - objectName: "extend", - }, - }, - libs - ); - - tokens.forEach(({ name, value }) => { - const transformedName = getNameFormatterFunction(formatName)(name); - - expect(result).toEqual( - expect.stringContaining(`${fontSizePrefix}${transformedName}`) - ); - expect(result).toEqual( - expect.stringContaining(`${lineHeightPrefix}${transformedName}`) - ); - expect(result).toEqual( - expect.stringContaining(`${fontFamilyPrefix}${transformedName}`) - ); - expect(result).toEqual( - expect.stringContaining(`${fontWeightPrefix}${transformedName}`) - ); - if (value.letterSpacing) { - expect(result).toEqual( - expect.stringContaining(`${letterSpacingPrefix}${transformedName}`) - ); - } - if (value.color) { - expect(result).toEqual( - expect.stringContaining(`${textColorPrefix}${transformedName}`) - ); - } - if (value.color && value.color.value.a < 1) { - expect(result).toEqual( - expect.stringContaining(`${textOpacityPrefix}${transformedName}`) - ); - } - }); - }); -}); diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-tailwind/to-tailwind.type.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-tailwind/to-tailwind.type.ts deleted file mode 100644 index bd769ea4a..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-tailwind/to-tailwind.type.ts +++ /dev/null @@ -1,119 +0,0 @@ -import { RecursiveRecord } from "../../types"; -import Token from "../../types/tokens/Token"; -import { InputDataType, OptionsType } from "./to-tailwind.parser"; - -export type ColorsFormat = - | "rgb" - | "prgb" - | "hex" - | "hex6" - | "hex3" - | "hex4" - | "hex8" - | "name" - | "hsl" - | "hsv"; - -export type TailwindType = - | "colors" - | "spacing" - | "borderRadius" - | "borderWidth" - | "boxShadow" - | "opacity" - | "borderColor" - | "borderOpacity" - | "zIndex" - | "fontWeight" - | "letterSpacing" - | "lineHeight" - | "fontFamily" - | "fontSize" - | "textColor" - | "textOpacity" - | "width" - | "height" - | "transitionDuration" - | "backgroundImage"; - -export type DepthMapping = { - zIndex?: RecursiveRecord; -}; -export type MeasurementMapping = { - spacing?: RecursiveRecord; -}; -export type OpacityMapping = { - opacity?: RecursiveRecord; -}; -export type ShadowMapping = { - boxShadow?: RecursiveRecord; -}; -export type SizeMapping = { - height?: RecursiveRecord; - width?: RecursiveRecord; -}; - -export type TextStyleMapping = { - fontSize?: RecursiveRecord; - fontWeight?: RecursiveRecord; - letterSpacing?: RecursiveRecord; - lineHeight?: RecursiveRecord; - textColor?: RecursiveRecord; - textOpacity?: RecursiveRecord; - fontFamily?: RecursiveRecord>; -}; -export type BorderMapping = { - borderRadius?: RecursiveRecord; - borderColor?: RecursiveRecord; - borderOpacity?: RecursiveRecord; - borderWidth?: RecursiveRecord; -}; -export type DurationMapping = { - transitionDuration?: RecursiveRecord; -}; -export type ColorMapping = { - colors?: RecursiveRecord; -}; -export type GradientMappingBeforeWrapper = { - backgroundImage?: RecursiveRecord; -}; -export type GradientMapping = { - backgroundImage?: (theme: string) => RecursiveRecord; -}; - -export type TailwindMappingTypes = DepthMapping & - SizeMapping & - MeasurementMapping & - OpacityMapping & - ShadowMapping & - TextStyleMapping & - BorderMapping & - DurationMapping & - ColorMapping & - GradientMappingBeforeWrapper; - -export type TailwindOutputType = DepthMapping & - MeasurementMapping & - OpacityMapping & - ShadowMapping & - TextStyleMapping & - BorderMapping & - DurationMapping & - ColorMapping & - GradientMapping; - -export interface TailwindTokenClass { - new (tokens: Partial): TailwindTokenClassInstance; - tailwindKeys?: Array; - afterGenerate(TailwindTokens: TailwindMappingTypes): TailwindOutputType; -} - -export interface TailwindTokenClassInstance { - transformedName: string; - generate( - options: OptionsType, - spTokens: InputDataType - ): Partial>; -} - -export type FormatName = "camelCase" | "kebabCase" | "snakeCase" | "pascalCase"; diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-tailwind/tokens/border.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-tailwind/tokens/border.ts deleted file mode 100644 index 727d2fb68..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-tailwind/tokens/border.ts +++ /dev/null @@ -1,60 +0,0 @@ -import { BorderToken } from "../../../types"; -import { BorderMapping } from "../to-tailwind.type"; -import tinycolor from "tinycolor2"; -import { OptionsType } from "../to-tailwind.parser"; -import { Utils } from "./index"; - -export class Border extends BorderToken { - token: Partial; - constructor(token: Partial) { - super(token); - this.token = token; - } - - generate(options: OptionsType): BorderMapping { - const { width, radii, color } = this.value; - const result = {} as BorderMapping; - - if (width && width.value) { - result.borderWidth = Utils.go< - ConstructorParameters[0] - >( - this.token, - options, - "borderWidth", - `${width.value.measure}${width.value.unit}` - ); - } - - if (radii && radii.value) { - result.borderRadius = Utils.go< - ConstructorParameters[0] - >( - this.token, - options, - "borderRadius", - `${radii?.value.measure}${radii?.value.unit}` - ); - } - - if (color && color.value) { - result.borderColor = Utils.go< - ConstructorParameters[0] - >( - this.token, - options, - "borderColor", - tinycolor(color.value).toString( - options?.formatTokens?.colorFormat?.format || "hex" - ) - ); - if (color.value.a && color.value.a !== 1) { - result.borderOpacity = Utils.go< - ConstructorParameters[0] - >(this.token, options, "borderOpacity", `${color.value.a}`); - } - } - - return result; - } -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-tailwind/tokens/color.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-tailwind/tokens/color.ts deleted file mode 100644 index b41a715cc..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-tailwind/tokens/color.ts +++ /dev/null @@ -1,25 +0,0 @@ -import tinycolor from "tinycolor2"; -import { ColorToken } from "../../../types"; -import { ColorMapping } from "../to-tailwind.type"; -import { OptionsType } from "../to-tailwind.parser"; -import { Utils } from "./index"; - -export class Color extends ColorToken { - token: Partial; - constructor(token: Partial) { - super(token); - this.token = token; - } - generate(options: OptionsType): ColorMapping { - return { - colors: Utils.go[0]>( - this.token, - options, - "colors", - tinycolor(this.value).toString( - options?.formatTokens?.colorFormat?.format || "hex" - ) - ), - }; - } -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-tailwind/tokens/depth.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-tailwind/tokens/depth.ts deleted file mode 100644 index d5b6c62ef..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-tailwind/tokens/depth.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { DepthToken } from "../../../types"; -import { OptionsType } from "../to-tailwind.parser"; -import { DepthMapping, TailwindMappingTypes } from "../to-tailwind.type"; -import { Utils } from "./index"; - -export class Depth extends DepthToken { - token: Partial; - constructor(token: Partial) { - super(token); - this.token = token; - } - - generate(options: OptionsType): DepthMapping { - return { - zIndex: Utils.go[0]>( - this.token, - options, - "zIndex", - `${this.value.depth}` - ), - }; - } - - static afterGenerate(tokens: TailwindMappingTypes) { - if (tokens.zIndex) tokens.zIndex = Utils.sortObjectByValue(tokens.zIndex); - return tokens; - } -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-tailwind/tokens/duration.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-tailwind/tokens/duration.ts deleted file mode 100644 index 98ff0f221..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-tailwind/tokens/duration.ts +++ /dev/null @@ -1,32 +0,0 @@ -import { DurationToken } from "../../../types"; -import { Utils } from "./index"; -import { DurationMapping, TailwindMappingTypes } from "../to-tailwind.type"; -import { OptionsType } from "../to-tailwind.parser"; - -export class Duration extends DurationToken { - token: Partial; - constructor(token: Partial) { - super(token); - this.token = token; - } - generate(options: OptionsType): DurationMapping { - return { - transitionDuration: Utils.go< - ConstructorParameters[0] - >( - this.token, - options, - "transitionDuration", - `${this.value.duration}${this.value.unit}` - ), - }; - } - - static afterGenerate(tokens: TailwindMappingTypes) { - if (tokens.transitionDuration) - tokens.transitionDuration = Utils.sortObjectByValue( - tokens.transitionDuration - ); - return tokens; - } -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-tailwind/tokens/gradient.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-tailwind/tokens/gradient.ts deleted file mode 100644 index c2c8bb120..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-tailwind/tokens/gradient.ts +++ /dev/null @@ -1,37 +0,0 @@ -import tinycolor from "tinycolor2"; -import { GradientToken } from "../../../types"; -import { OptionsType } from "../to-tailwind.parser"; -import { GradientMappingBeforeWrapper } from "../to-tailwind.type"; -import { Utils } from "./index"; - -export class Gradient extends GradientToken { - token: Partial; - constructor(token: Partial) { - super(token); - this.token = token; - } - - generate(options: OptionsType): GradientMappingBeforeWrapper { - return { - backgroundImage: Utils.go[0]>( - this.token, - options, - "backgroundImage", - this.value.gradients - .map(gradient => { - return `linear-gradient(${ - gradient.angle ?? "to right" - }, ${gradient.colors - .map( - ({ color, position }) => - `${tinycolor(color.value).toString( - options?.formatTokens?.colorFormat?.format || "hex" - )} ${position * 100}%` - ) - .join(", ")})`; - }) - .join(", ") - ), - }; - } -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-tailwind/tokens/index.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-tailwind/tokens/index.ts deleted file mode 100644 index 882f5e970..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-tailwind/tokens/index.ts +++ /dev/null @@ -1,66 +0,0 @@ -import * as _ from "lodash"; -import Template from "../../../libs/template"; -import { Token } from "../../../types"; -import { OptionsType } from "../to-tailwind.parser"; -import { TailwindType } from "../to-tailwind.type"; -import { getNameFormatterFunction } from "../utils/getNameFormatterFunction"; - -export * from "./border"; -export * from "./color"; -export * from "./depth"; -export * from "./duration"; -export * from "./gradient"; -export * from "./measurement"; -export * from "./opacity"; -export * from "./shadow"; -export * from "./size"; -export * from "./textStyle"; - -export abstract class Utils { - static parseFloatIfString(value: string | number) { - return typeof value === "string" ? parseFloat(value) : value; - } - - static sortObjectByValue(obj: T) { - return Object.entries(obj) - .sort( - ([, a], [, b]) => - this.parseFloatIfString(a) - this.parseFloatIfString(b) - ) - .reduce((r, [k, v]) => ({ ...r, [k]: v }), {}); - } - - static getTemplatedTokenName( - token: Partial, - template: string | undefined - ) { - if (template) { - const templateInstance = new Template(template); - return templateInstance.render(token); - } - return token.name!; - } - - static go( - token: T, - options: OptionsType, - tailwindKey: TailwindType, - value: unknown - ) { - const keyName = this.getTemplatedTokenName( - token, - options?.renameKeys?.[tailwindKey] - ); - const keys = [ - ...(options?.splitBy - ? keyName.split(new RegExp(options.splitBy)) - : [keyName]), - ]; - return _.setWith( - {}, - keys.map(k => getNameFormatterFunction(options?.formatName)(k)).join("."), - value, - Object - ); - } -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-tailwind/tokens/measurement.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-tailwind/tokens/measurement.ts deleted file mode 100644 index ce54d42cc..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-tailwind/tokens/measurement.ts +++ /dev/null @@ -1,39 +0,0 @@ -import { MeasurementToken } from "../../../types"; -import { OptionsType } from "../to-tailwind.parser"; -import { MeasurementMapping, TailwindMappingTypes } from "../to-tailwind.type"; -import { Utils } from "./index"; - -export class Measurement extends MeasurementToken { - token: Partial; - constructor(token: Partial) { - super(token); - this.token = token; - } - generate(options: OptionsType): MeasurementMapping { - console.log(this.value); - return { - spacing: Utils.go[0]>( - this.token, - options, - "spacing", - `${ - (this.value as any).top - ? `${(this.value as any).top}px` - : (this.value as any).bottom - ? `${(this.value as any).bottom}px` - : (this.value as any).left - ? `${(this.value as any).left}px` - : (this.value as any).right - ? `${(this.value as any).right}px` - : "0px" - }` - ), - }; - } - - static afterGenerate(tokens: TailwindMappingTypes) { - if (tokens.spacing) - tokens.spacing = Utils.sortObjectByValue(tokens.spacing!); - return tokens; - } -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-tailwind/tokens/opacity.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-tailwind/tokens/opacity.ts deleted file mode 100644 index 4d28baa40..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-tailwind/tokens/opacity.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { OpacityToken } from "../../../types"; -import { Utils } from "./index"; -import { OpacityMapping } from "../to-tailwind.type"; -import { OptionsType } from "../to-tailwind.parser"; - -export class Opacity extends OpacityToken { - token: Partial; - constructor(token: Partial) { - super(token); - this.token = token; - } - - generate(options: OptionsType): OpacityMapping { - return { - opacity: Utils.go[0]>( - this.token, - options, - "opacity", - `${this.value.opacity / 100}` - ), - }; - } - - static afterGenerate(tokens: OpacityMapping) { - if (tokens.opacity) - tokens.opacity = Utils.sortObjectByValue(tokens.opacity); - return tokens; - } -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-tailwind/tokens/shadow.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-tailwind/tokens/shadow.ts deleted file mode 100644 index 3ae60b64b..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-tailwind/tokens/shadow.ts +++ /dev/null @@ -1,39 +0,0 @@ -import tinycolor from "tinycolor2"; -import { ShadowToken } from "../../../types"; -import { OptionsType } from "../to-tailwind.parser"; -import { ShadowMapping } from "../to-tailwind.type"; -import { Utils } from "./index"; - -export class Shadow extends ShadowToken { - token: Partial; - constructor(token: Partial) { - super(token); - this.token = token; - } - generate(options: OptionsType): ShadowMapping { - return { - boxShadow: Utils.go[0]>( - this.token, - options, - "boxShadow", - this.value - .reduce>((acc, shadow) => { - const { color, offsetX, offsetY, blur, isInner, spread } = shadow; - const x = `${offsetX}px`; - const y = `${offsetY}px`; - const blurString = `${blur}px`; - const spreadString = spread ? ` ${spread}px` : ""; - const innerText = isInner ? "inset " : ""; - const colorString = tinycolor(color).toString( - options?.formatTokens?.colorFormat?.format ?? "hex" - ); - acc.push( - `${innerText}${x} ${y} ${blurString}${spreadString} ${colorString}` - ); - return acc; - }, []) - .join(", ") - ), - }; - } -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-tailwind/tokens/size.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-tailwind/tokens/size.ts deleted file mode 100644 index 73eac506a..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-tailwind/tokens/size.ts +++ /dev/null @@ -1,36 +0,0 @@ -import { SizeToken } from "../../../types/tokens/Size"; -import { OptionsType } from "../to-tailwind.parser"; -import { SizeMapping, TailwindMappingTypes } from "../to-tailwind.type"; -import { Utils } from "./index"; - -export class Size extends SizeToken { - token: Partial; - - constructor(token: Partial) { - super(token); - this.token = token; - this.value = token.value!; - } - generate(options: OptionsType): SizeMapping { - return { - height: Utils.go[0]>( - this.token, - options, - "height", - `${this.value.measure ?? this.value}${this.value.unit ?? "px"}` - ), - width: Utils.go[0]>( - this.token, - options, - "width", - `${this.value.measure ?? this.value}${this.value.unit ?? "px"}` - ), - }; - } - - static afterGenerate(tokens: TailwindMappingTypes) { - if (tokens.height) tokens.height = Utils.sortObjectByValue(tokens.height!); - if (tokens.width) tokens.width = Utils.sortObjectByValue(tokens.width!); - return tokens; - } -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-tailwind/tokens/textStyle.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-tailwind/tokens/textStyle.ts deleted file mode 100644 index 480ee9aea..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-tailwind/tokens/textStyle.ts +++ /dev/null @@ -1,154 +0,0 @@ -/* eslint-disable @typescript-eslint/no-explicit-any */ -import tinycolor from "tinycolor2"; -import convertMeasurement from "../../../libs/size-manipulation"; -import { FontToken, TextStyleToken } from "../../../types"; -import { FormatTokenType, OptionsType } from "../to-tailwind.parser"; -import { - ColorsFormat, - TailwindMappingTypes, - TextStyleMapping, -} from "../to-tailwind.type"; -import { Utils } from "./index"; - -export class TextStyle extends TextStyleToken { - token: Partial; - constructor(token: Partial) { - super(token); - this.token = token; - } - - private getFontWeight() { - return this.value.font.value.fontWeight; - } - private getLetterSpacing() { - const ls = this.value.letterSpacing; - if (ls?.value || (this.value?.font?.value as any)?.ls) { - return `${ - ls?.value?.measure ?? (this.value?.font?.value as any)?.ls ?? 0 - }${ls?.value?.unit ?? "%"}`; - } - - return undefined; - } - private getLineHeight() { - const lh = this.value.lineHeight; - return `${ - lh?.value?.measure ?? (this.value?.font?.value as any)?.lineHeight ?? 0 - }${lh?.value?.unit ?? "px"}`; - } - private getColor(format: ColorsFormat) { - if (this.value.color?.value) { - return tinycolor(this.value.color?.value).toString(format); - } - } - private getOpacity() { - if (this.value.color?.value?.a && this.value.color?.value?.a < 1) { - return `${this.value.color.value.a}`; - } - return undefined; - } - - private getFontFamily() { - return ( - (this?.value?.font as FontToken)?.name ?? - this.value?.font?.value?.fontPostScriptName - ); - } - - private getFontSize(fontFormat: FormatTokenType["fontSizeFormat"]) { - const fontSize = this.value.fontSize; - if (fontFormat?.unit && fontSize?.value?.unit !== fontFormat?.unit) { - fontSize.value = convertMeasurement(fontSize.value, fontFormat?.unit); - } - return `${ - fontSize?.value?.measure ?? - (this.value?.font?.value as any)?.fontSize ?? - 0 - }${fontSize?.value?.unit ?? "px"}`; - } - - generate(options: OptionsType): TextStyleMapping { - const result: TextStyleMapping = {}; - - result.fontSize = Utils.go[0]>( - this.token, - options, - "fontSize", - this.getFontSize(options?.formatTokens?.fontSizeFormat) - ); - - const letterSpacing = this.getLetterSpacing(); - if (letterSpacing) { - result.letterSpacing = Utils.go< - ConstructorParameters[0] - >(this.token, options, "letterSpacing", letterSpacing); - } - - const lineHeight = this.getLineHeight(); - result.lineHeight = Utils.go< - ConstructorParameters[0] - >(this.token, options, "lineHeight", lineHeight); - - const textColor = this.getColor( - options?.formatTokens?.colorFormat?.format || "hex" - ); - if (textColor) { - result.textColor = Utils.go< - ConstructorParameters[0] - >(this.token, options, "textColor", textColor); - } - - const textOpacity = this.getOpacity(); - if (textOpacity) { - result.textOpacity = Utils.go< - ConstructorParameters[0] - >(this.token, options, "textOpacity", textOpacity); - } - - const fontFamily = this.getFontFamily(); - result.fontFamily = Utils.go< - ConstructorParameters[0] - >(this.token, options, "fontFamily", [fontFamily, "sans-serif"]); - - const fontWeight = this.getFontWeight(); - result.fontWeight = Utils.go< - ConstructorParameters[0] - >(this.token, options, "fontWeight", fontWeight); - - return result; - } - - static afterGenerate(TailwindTokens: TailwindMappingTypes) { - if (TailwindTokens.fontSize) - TailwindTokens.fontSize = Utils.sortObjectByValue( - TailwindTokens.fontSize - ); - - if (TailwindTokens.fontWeight) - TailwindTokens.fontWeight = Utils.sortObjectByValue( - TailwindTokens.fontWeight - ); - - if (TailwindTokens.lineHeight) - TailwindTokens.lineHeight = Utils.sortObjectByValue( - TailwindTokens.lineHeight - ); - - if (TailwindTokens.letterSpacing) - TailwindTokens.letterSpacing = Utils.sortObjectByValue( - TailwindTokens.letterSpacing - ); - - if (TailwindTokens.textColor) - TailwindTokens.textColor = Utils.sortObjectByValue( - TailwindTokens.textColor - ); - - if (TailwindTokens.textOpacity) - TailwindTokens.textOpacity = Utils.sortObjectByValue( - TailwindTokens.textOpacity - ); - - return TailwindTokens; - } -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-tailwind/utils/getNameFormatterFunction.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-tailwind/utils/getNameFormatterFunction.ts deleted file mode 100644 index 571179240..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-tailwind/utils/getNameFormatterFunction.ts +++ /dev/null @@ -1,7 +0,0 @@ -import * as _ from "lodash"; - -import { FormatName } from "../to-tailwind.type"; - -export function getNameFormatterFunction(format: FormatName = "camelCase") { - return _[format]; -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-theme-ui/README.md b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-theme-ui/README.md deleted file mode 100644 index b1cefe7b2..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-theme-ui/README.md +++ /dev/null @@ -1,420 +0,0 @@ -# To Theme Ui - -## Description - -Format design tokens to create a theme compatible with the [theme-ui specification](https://theme-ui.com/theme-spec). - -Learn more about how to configure Specify in the API documentation: [https://specifyapp.com/developers](https://specifyapp.com/developers). - -## Interface - -```ts -interface parser { - name: "to-theme-ui"; - options: Partial<{ - formatName: "camelCase" | "kebabCase" | "snakeCase" | "pascalCase" | "none"; - variants: boolean; - formatConfig: Partial<{ - module: "es6" | "commonjs" | "json"; - objectName: string; - endOfLine: "auto" | "lf" | "crlf" | "cr"; - tabWidth: number; - useTabs: boolean; - singleQuote: boolean; - exportDefault: boolean; - }>; - formatTokens?: { - colorFormat?: { - format: - | "rgb" - | "prgb" - | "hex" - | "hex6" - | "hex3" - | "hex4" - | "hex8" - | "name" - | "hsl" - | "hsv"; - }; - opacityFormat?: { - type?: "number" | "string"; - unit: "percent" | "none"; - }; - fontSizeFormat?: { - type: "number" | "string"; - unit?: "px" | "rem"; - }; - }; - presets?: { - fontWeights?: { - preset: "base" | Record; - freeze?: boolean; - }; - fontSizes?: { - preset: "base" | Array; - unit?: "px" | "rem"; - freeze?: boolean; - }; - }; - }>; -} -``` - -### Options - -| Parameter | Required | Type | Default | Description | -| ---------------------------------- | -------- | ----------------------------------------------------------------- | ----------- | --------------------------------------------------------------------------------------------------------------------------------- | -| `formatName` | optional | `camelCase` `kebabCase` `snakeCase` `pascalCase` `none` | `kebabCase` | The case transformation you want to apply to your design token name | -| `variants` | optional | `boolean` | `false` | Generate variants. Currently `texts` and `borders` are generated as variants. [source](https://theme-ui.com/theme-spec#variants). | -| `formatConfig.module` | optional | `es6` `commonjs` `json` | `es6` | Module loader used to export the result | -| `formatConfig.objectName` | optional | `string` | `theme` | Name of exported variable | -| `formatConfig.endOfLine` | optional | `auto` `lf` `crlf` `cr` | `auto` | [Prettier documentation](https://prettier.io/docs/en/options.html#end-of-line) | -| `formatConfig.tabWidth` | optional | `number` | `2` | [Prettier documentation](https://prettier.io/docs/en/options.html#tab-width) | -| `formatConfig.useTabs` | optional | `boolean` | `true` | [Prettier documentation](https://prettier.io/docs/en/options.html#tabs) | -| `formatConfig.singleQuote` | optional | `boolean` | `false` | [Prettier documentation](https://prettier.io/docs/en/options.html#quotes) | -| `formatConfig.exportDefault` | optional | `boolean` | `true` | | -| `formatTokens.colorFormat.format` | optional | `rgb` `prgb` `hex` `hex6` `hex3` `hex4` `hex8` `name` `hsl` `hsv` | `rgb` | The color format you want to apply to your potential color design token | -| `formatTokens.opacityFormat.type` | optional | `number` `string` | `number` | if unit is `percent` type will be `string` | -| `formatTokens.opacityFormat.unit` | optional | `percent` `none` | `none` | | -| `formatTokens.fontSizeFormat.type` | optional | `number` `string` | `number` | if unit is `percent` type will be `string` | -| `formatTokens.fontSizeFormat.unit` | optional | `px` `rem` | `none` | | -| `presets.fontWeights.preset` | optional | `base` Record | | | -| `presets.fontWeights.freeze` | optional | `boolean` | false | Prevent the edition of the preset | -| `presets.fontSizes.preset` | required | `base` Array | | | -| `presets.fontSizes.unit` | optional | `px` `rem` | `px` | | -| `presets.fontSizes.freeze` | optional | `boolean` | false | Prevent the edition of the preset | - -### Preset - -A preset is a list of elements that you can arbitrarily add to the final object. - -There are two presets you can use: - -- Font weight -- Font size - -All presets can be frozen to prevent their edition. - -#### Font Weight - -Using the base preset will return the following object: - -```jsonc -// base -{ - "thin": 100, - "extraLight": 200, - "light": 300, - "normal": 400, - "medium": 500, - "semiBold": 600, - "bold": 700, - "extraBold": 800, - "black": 900 -} -``` - -On the other hand you can use a custom preset that match the following type: - -```ts -Record; -``` - -#### Font Size - -The base preset depends of the unit. - -Choosing `px` returns: - -```jsonc -[ - "8.19px", - "10.24px", - "12.8px", - "16px", - "20px", - "25px", - "31.25px", - "39.06px", - "48.83px" -] -``` - -Choosing `rem` returns: - -```jsonc -[ - "0.512rem", - "0.64rem", - "0.8rem", - "1rem", - "1.25rem", - "1.563rem", - "1.953rem", - "2.441rem", - "3.052rem" -] -``` - -## Types - -โ„น๏ธ **Please be aware that, depending on the order you use parsers, their input and output types have to match.** - -### Input - -Array of object with at least name, value and type: - -```ts -type input = Array<{ name: string; value: any; type: string }>; -``` - -### Output - -String formated in js or json. - -```ts -type output = string; -``` - -## Basic Usage - -### Config - -```jsonc -"parsers": [ - { - "name": "to-theme-ui" - } - // โ€ฆ -] -``` - -### Before/After - -#### Input - -```jsonc -[ - { - "name": "primary", - "value": { - "a": 1, - "b": 255, - "g": 189, - "r": 198 - }, - "type": "color" - }, - { - "name": "base-space-01", - "value": { - "unit": "px", - "measure": 4 - }, - "type": "measurement" - }, - { - "name": "body", - "value": { - "font": { - "id": "69d2d62e-4d62-45d7-b85f-5da2f9f0c0d4", - "name": "Roboto-Regular", - "value": { - "fontFamily": "Roboto", - "fontWeight": 400, - "fontPostScriptName": "Roboto-Regular" - }, - "type": "font" - }, - "fontSize": { - "value": { - "unit": "px", - "measure": 16 - } - }, - "textAlign": { - "vertical": "top", - "horizontal": "left" - }, - "lineHeight": { - "value": { - "unit": "px", - "measure": 20 - } - }, - "fontVariant": ["small-caps"] - }, - "type": "textStyle" - } -] -``` - -#### Output - -```js -const theme = { - sizes: { - baseSpace01: "4px", - }, - colors: { - primary: "rgb(198, 189, 255)", - }, - fonts: { - robotoRegular: "Roboto-Regular", - }, - fontWeights: { - robotoRegular: 400, - }, - fontSizes: [16], - lineHeights: { - body: "20px", - }, -}; - -export default theme; -``` - -## Complex usage - with variant and preset - -### Config - -```jsonc -"parsers": [ - { - "name": "to-theme-ui", - "options": { - "variants": true, - "formatTokens": { - "colorFormat": { - "format": "hex" - }, - "fontSizeFormat": { - "type": "string", - "unit": "rem", - "freeze": true - } - }, - "presets": { - "fontWeights": { - "preset": "base", - "freeze": true - } - } - } - } - // โ€ฆ -] -``` - -### Before/After - -#### Input - -```jsonc -[ - { - "name": "primary", - "value": { - "a": 1, - "b": 255, - "g": 189, - "r": 198 - }, - "type": "color" - }, - { - "name": "base-space-01", - "value": { - "unit": "px", - "measure": 4 - }, - "type": "measurement" - }, - { - "name": "body", - "value": { - "font": { - "id": "69d2d62e-4d62-45d7-b85f-5da2f9f0c0d4", - "name": "Roboto-Regular", - "value": { - "fontFamily": "Roboto", - "fontWeight": 400, - "fontPostScriptName": "Roboto-Regular" - }, - "type": "font" - }, - "fontSize": { - "value": { - "unit": "px", - "measure": 16 - } - }, - "textAlign": { - "vertical": "top", - "horizontal": "left" - }, - "lineHeight": { - "value": { - "unit": "px", - "measure": 20 - } - }, - "fontVariant": ["small-caps"] - }, - "type": "textStyle" - } -] -``` - -#### Output - -```js -const theme = { - fontWeights: { - thin: 100, - extraLight: 200, - light: 300, - normal: 400, - medium: 500, - semiBold: 600, - bold: 700, - extraBold: 800, - black: 900, - }, - fontSizes: [ - "0.512rem", - "0.64rem", - "0.8rem", - "0.875rem", - "1rem", - "1.25rem", - "1.563rem", - "1.953rem", - "2.441rem", - "3.052rem", - ], - colors: { primary: "#c6bdff" }, - sizes: { baseSpace01: "4px" }, - lineHeights: { body: "20px" }, - text: { - body: { - fontFamily: "Roboto-Regular", - lineHeight: "20px", - fontSize: "0.875rem", - fontWeight: 400, - textAlign: "left", - verticalAlign: "top", - fontVariant: "small-caps", - }, - }, -}; - -export default theme; -``` - -## โ„น๏ธ Good to know - -Use the [link-design-tokens](https://github.com/Specifyapp/parsers/tree/master/parsers/link-design-tokens) parser before this parser to reference color and measurement design tokens in [variants](https://theme-ui.com/theme-spec/#variants). - -With this flow you will be able to link `fontSizes, colors` with variants like `texts` or `borders`. diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-theme-ui/to-theme-ui.parser.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-theme-ui/to-theme-ui.parser.ts deleted file mode 100644 index 734242b68..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-theme-ui/to-theme-ui.parser.ts +++ /dev/null @@ -1,292 +0,0 @@ -import * as _ from "lodash"; -import * as os from "os"; -import prettier from "prettier"; -import { IToken, TokensType } from "../../types"; -import { LibsType } from "../global-libs"; -import { - ColorsFormat, - ThemeUiIndexes, - ThemeUiTokenClass, - ThemeUiType, - ThemeUiTypes, -} from "./to-theme-ui.type"; -import * as TokensClass from "./tokens"; - -export type InputDataType = Array< - Pick & Record ->; -export type OutputDataType = string; -export type FormatTokenType = Partial<{ - colorFormat: { - format: ColorsFormat; - }; - opacityFormat: { - unit: "percent" | "none"; - type?: "number" | "string"; - }; - fontSizeFormat: { - type: "number" | "string"; - unit?: "px" | "rem"; - }; -}>; -type PresetableKey = "fontWeights" | "fontSizes"; -type PresetsType = Partial<{ - fontWeights: { - preset: "base" | Record; - freeze?: boolean; - }; - fontSizes: { - preset: "base" | Array; - unit?: "px" | "rem"; - freeze?: boolean; - }; -}>; -export type OptionsType = - | Partial<{ - formatName: - | "camelCase" - | "kebabCase" - | "snakeCase" - | "pascalCase" - | "none"; - formatTokens: FormatTokenType; - formatConfig: Partial<{ - module: "es6" | "commonjs" | "json"; - objectName: string; - endOfLine: "auto" | "lf" | "crlf" | "cr"; - tabWidth: number; - useTabs: boolean; - singleQuote: boolean; - exportDefault: boolean; - }>; - variants: boolean; - presets: PresetsType; - }> - | undefined; - -function getClassByType(type: string): ThemeUiTokenClass | undefined { - const tokenClassName = `${type.charAt(0).toUpperCase() + type.slice(1)}`; - return (TokensClass)[tokenClassName]; -} - -export class Indexes { - private static _instance: Indexes; - private _enable: boolean; - list: ThemeUiIndexes = {}; - presets: ToThemeUiParser["styles"] = {}; - - private constructor(enable: boolean) { - this._enable = enable; - } - - public static init(enable: boolean, presets: Indexes["presets"]) { - this._instance = new this(enable); - this._instance.presets = { ...presets }; - if (enable && Object.keys(presets).length > 0) { - Object.entries(presets).forEach(([property, values]) => { - if (!this._instance.list[property as keyof ThemeUiIndexes]) { - this._instance.list[property as keyof ThemeUiIndexes] = {}; - } - if (Array.isArray(values)) { - values.forEach( - (value, index) => - (this._instance.list[property as keyof ThemeUiIndexes]![value] = - index) - ); - } else { - Object.entries(values).forEach( - ([key, value]) => - (this._instance.list[property as keyof ThemeUiIndexes]![value] = - key) - ); - } - }); - } - } - - public static get Instance(): Indexes { - return this._instance; - } - - public add( - themeUiKey: ThemeUiType, - tokenKey: string, - tokenRef: string | number, - value: string | number = tokenRef - ) { - if (!this._enable) return; - if (!this.list[themeUiKey]) this.list[themeUiKey] = {}; - if (this.presets && themeUiKey in this.presets) { - const preset = this.presets[themeUiKey as PresetableKey]; - if (Array.isArray(preset)) { - const matchedPreset = preset.find(presetValue => presetValue === value); - if (matchedPreset) this.list[themeUiKey]![tokenKey] = matchedPreset; - } else { - const matchedPreset = Object.entries(preset as object).find( - ([_, presetValue]) => value === presetValue - ); - if (matchedPreset) this.list[themeUiKey]![tokenKey] = matchedPreset[0]; - } - } else { - this.list[themeUiKey]![tokenKey] = tokenRef; - } - } -} - -class ToThemeUiParser { - objectName; - transformNameFn; - exportDefault; - module; - tokensGroupByType; - options; - tokens; - styles: Partial> = {}; - constructor(tokens: InputDataType, options: OptionsType) { - this.options = options; - this.objectName = options?.formatConfig?.objectName ?? "theme"; - this.transformNameFn = _[options?.formatName ?? "camelCase"]; - this.exportDefault = options?.formatConfig?.exportDefault ?? true; - this.module = options?.formatConfig?.module ?? "es6"; - this.tokens = tokens; - this.tokensGroupByType = _.groupBy(tokens, "type"); - this.styles = {}; - if (options?.presets) this.initPreset(options.presets); - Indexes.init(!!options?.variants, this.styles); - } - - initPreset(presets: PresetsType) { - this.styles.fontWeights = - presets.fontWeights?.preset === "base" - ? { - thin: 100, - extraLight: 200, - light: 300, - normal: 400, - medium: 500, - semiBold: 600, - bold: 700, - extraBold: 800, - black: 900, - } // source: https://developer.mozilla.org/fr/docs/Web/CSS/font-weight - : presets.fontWeights?.preset ?? {}; - - if (presets.fontSizes?.preset === "base") { - this.styles.fontSizes = - presets.fontSizes?.unit && presets.fontSizes?.unit === "px" - ? [ - "8.19px", - "10.24px", - "12.8px", - "16px", - "20px", - "25px", - "31.25px", - "39.06px", - "48.83px", - ] - : [ - "0.512rem", - "0.64rem", - "0.8rem", - "1rem", - "1.25rem", - "1.563rem", - "1.953rem", - "2.441rem", - "3.052rem", - ]; // source: https://type-scale.com/; - } else if (presets.fontSizes?.preset) { - this.styles.fontSizes = presets.fontSizes?.preset; - } - } - - exec() { - const types = Object.keys(this.tokensGroupByType) as Array; - types.forEach(type => Object.assign(this.styles, this.setGlobal(type))); - if (this.options && this.options.variants) { - types.forEach(type => Object.assign(this.styles, this.setVariants(type))); - } - return this; - } - - setGlobal(type: TokensType) { - const tokenHandler = getClassByType(type); - if (!tokenHandler) return {}; - const tokenByType = this.tokensGroupByType[type].reduce((acc, token) => { - const instance = new tokenHandler(token, this.transformNameFn); - const themeUiTokens = instance.generate(this.options, this.tokens); - (Object.keys(themeUiTokens) as Array).forEach( - themeUiKey => { - if ( - this.styles[themeUiKey] && - this.options?.presets?.[themeUiKey as keyof PresetsType]?.freeze - ) - return; - if (Array.isArray(themeUiTokens[themeUiKey])) { - acc[themeUiKey] = (acc[themeUiKey] || []).concat( - themeUiTokens[themeUiKey] - ); - } else { - if (!acc[themeUiKey]) acc[themeUiKey] = {}; - Object.assign(acc[themeUiKey], themeUiTokens[themeUiKey]); - } - } - ); - return acc; - }, this.styles as Record); - return tokenHandler.afterGenerate - ? tokenHandler.afterGenerate(tokenByType) - : tokenByType; - } - - setVariants(type: TokensType) { - const tokenHandler = getClassByType(type); - if (!tokenHandler) return {}; - return tokenHandler?.generateVariants - ? tokenHandler.generateVariants( - this.styles, - this.tokensGroupByType[type], - this.options, - this.transformNameFn - ) - : this.styles; - } - - finalize() { - const styles = JSON.stringify(this.styles); - return prettier.format( - (() => { - if (this.module === "json") { - return styles; - } else if (this.module === "es6" && this.exportDefault) - return `const ${this.objectName} = ${styles} ${`;${ - os.EOL + os.EOL - }export default ${this.objectName};`}`; - else if (this.module === "es6" && !this.exportDefault) - return `export const ${this.objectName} = ${styles};`; - else if (this.module === "commonjs" && this.exportDefault) - return `const ${this.objectName} = ${styles}; ${`${ - os.EOL + os.EOL - }module.exports = ${this.objectName};`}`; - else - return `const ${this.objectName} = ${styles}; ${`${ - os.EOL + os.EOL - }module.exports = {${this.objectName}};`}`; - })(), - { - ...this.options?.formatConfig, - parser: this.module === "json" ? "json" : "babel", - } - ); - } -} - -export default async function ( - tokens: InputDataType, - options: OptionsType, - { _ }: Pick -): Promise { - const parserInstance = new ToThemeUiParser(tokens, options); - return parserInstance.exec().finalize(); -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-theme-ui/to-theme-ui.spec.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-theme-ui/to-theme-ui.spec.ts deleted file mode 100644 index 94eaf196f..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-theme-ui/to-theme-ui.spec.ts +++ /dev/null @@ -1,358 +0,0 @@ -import libs from "../global-libs"; -import seeds from "../../tests/seeds"; -import toThemeUi, { OptionsType } from "./to-theme-ui.parser"; -import * as _ from "lodash"; -import { ThemeUiConfig, ThemeUiType } from "./to-theme-ui.type"; - -type ObjectOfStringNumber = { [key: string]: number }; -type ObjectOfStringString = { [key: string]: string }; -describe("To theme ui", () => { - it("Get tokens - apply parsers", async () => { - const str = await toThemeUi(seeds().tokens, undefined, libs); - - seeds().tokens.forEach(({ type, name }) => { - if (!["vector", "bitmap", "opacity"].includes(type)) { - expect(str).toEqual(expect.stringMatching(_.camelCase(name))); - } - }); - return; - }); - it("Get tokens - apply parsers - json", async () => { - const str = await toThemeUi( - seeds().tokens, - { - formatConfig: { - module: "json", - }, - }, - libs - ); - const result = JSON.parse(str) as ThemeUiConfig; - - expect(Object.keys(result)).toEqual( - expect.arrayContaining([ - "zIndices", - "durations", - "sizes", - "fontSizes", - "lineHeights", - "borderWidths", - "borderStyles", - "colors", - "shadows", - "fonts", - "fontWeights", - "gradients", - "opacities", - ]) - ); - expect(Object.keys(result.fontWeights)).toEqual( - expect.arrayContaining(Object.keys(result.fonts)) - ); - result.fontSizes.reduce( - (lastValue: number, currentValue: string | number) => { - expect(lastValue < parseFloat(`${currentValue}`)).toEqual(true); - return parseFloat(`${currentValue}`); - }, - -1 - ); - expect(Object.keys(result.fontWeights)).toEqual( - expect.arrayContaining(Object.keys(result.fonts)) - ); - Object.values(result.zIndices as ObjectOfStringNumber).forEach( - (item: number) => expect(item).toEqual(expect.any(Number)) - ); - ( - [ - "durations", - "sizes", - "borderWidths", - "borderStyles", - "lineHeights", - "shadows", - "colors", - ] as Array - ).forEach(key => { - Object.values(result[key] as ObjectOfStringString).forEach( - (item: string) => expect(item).toEqual(expect.any(String)) - ); - }); - (["fontWeights", "zIndices"] as Array).forEach(key => { - Object.values(result[key] as ObjectOfStringNumber).forEach( - (item: number) => expect(item).toEqual(expect.any(Number)) - ); - }); - (["fontSizes", "opacities"] as Array).forEach(key => { - (result[key] as Array).forEach((item: number) => - expect(item).toEqual(expect.any(Number)) - ); - }); - return; - }); - it("Get tokens - apply parsers - with variant", async () => { - const str = await toThemeUi( - seeds().tokens, - { - formatConfig: { - module: "json", - }, - variants: true, - }, - libs - ); - const result = JSON.parse(str) as ThemeUiConfig; - - expect(Object.keys(result)).toEqual( - expect.arrayContaining([ - "zIndices", - "durations", - "sizes", - "fontSizes", - "lineHeights", - "borderWidths", - "borderStyles", - "colors", - "shadows", - "fonts", - "fontWeights", - "gradients", - "opacities", - "text", - "border", - ]) - ); - expect(Object.keys(result.fontWeights)).toEqual( - expect.arrayContaining(Object.keys(result.fonts)) - ); - result.fontSizes.reduce( - (lastValue: number, currentValue: string | number) => { - expect(lastValue < parseFloat(`${currentValue}`)).toEqual(true); - return parseFloat(`${currentValue}`); - }, - -1 - ); - - Object.values( - result.text as Record - ).forEach(value => { - expect(result.fonts[value.fontFamily]).toBeDefined(); - expect(result.fontWeights[value.fontFamily]).toBeDefined(); - }); - return; - }); - it("Should return variant that matched frozen presets", async () => { - const str = await toThemeUi( - seeds().tokens, - { - formatTokens: { - fontSizeFormat: { - unit: "rem", - type: "string", - }, - opacityFormat: { - unit: "percent", - }, - }, - formatConfig: { - module: "json", - }, - variants: true, - presets: { - fontWeights: { - freeze: true, - preset: "base", - }, - fontSizes: { - freeze: true, - preset: "base", - }, - }, - }, - libs - ); - const result = JSON.parse(str) as ThemeUiConfig; - expect(Object.keys(result.fontWeights).length).toEqual(9); - Object.values( - result.text as Record - ).forEach(value => { - expect(result.fonts[value.fontFamily]).toBeDefined(); - expect(result.fontWeights[value.fontWeight]).toBeDefined(); - }); - result.opacities.forEach((opacity: string) => { - expect(opacity).toMatch(/[0-9]+%/); - }); - return; - }); - it("Should return variant that matched non frozen presets", async () => { - const tokens = seeds().tokens; - const str = await toThemeUi( - tokens, - { - formatConfig: { - module: "json", - }, - variants: true, - presets: { - fontWeights: { - preset: "base", - }, - }, - }, - libs - ); - const result = JSON.parse(str) as ThemeUiConfig; - - expect(Object.keys(result.fontWeights).length).toBeGreaterThan( - tokens.filter(({ type }) => type === "textStyle").length - ); - Object.values( - result.text as Record - ).forEach(value => { - expect(result.fonts[value.fontFamily]).toBeDefined(); - expect(result.fontWeights[value.fontWeight]).toBeDefined(); - }); - return; - }); - it("Should return variant that matched custom presets", async () => { - const tokens = seeds().tokens; - const str = await toThemeUi( - tokens, - { - formatConfig: { - module: "json", - }, - variants: true, - presets: { - fontWeights: { - preset: { - thin: 100, - extraLight: 200, - light: 300, - normal: 400, - regular: 400, - medium: 500, - semiBold: 600, - bold: 700, - extraBold: 800, - black: 900, - }, - }, - fontSizes: { - preset: [4, 8, 12], - }, - }, - }, - libs - ); - const result = JSON.parse(str) as ThemeUiConfig; - - expect(Object.keys(result.fontWeights).length).toBeGreaterThan( - tokens.filter(({ type }) => type === "textStyle").length - ); - expect(Object.keys(result.fontSizes).length).toBeGreaterThan( - tokens.filter(({ type }) => type === "textStyle").length - ); - Object.values( - result.text as Record - ).forEach(value => { - expect(result.fonts[value.fontFamily]).toBeDefined(); - expect(result.fontWeights[value.fontWeight]).toBeDefined(); - }); - return; - }); - it("Should return variant that matched nothing", async () => { - const tokens = seeds().tokens.filter( - ({ type }) => type !== "measurement" && type !== "color" - ); - const str = await toThemeUi( - tokens, - { - formatConfig: { - module: "json", - }, - variants: true, - }, - libs - ); - const result = JSON.parse(str) as ThemeUiConfig; - expect(result.colors).toBeFalsy(); - expect(result.sizes).toBeFalsy(); - return; - }); - it("Should return tokens wihtout any transformation on name", async () => { - const tokens = seeds().tokens.filter( - ({ type }) => type !== "measurement" && type !== "color" - ); - const str = await toThemeUi( - tokens, - { - formatName: "none", - formatConfig: { - module: "json", - }, - }, - libs - ); - const result = JSON.parse(str) as ThemeUiConfig; - const themeUiTokensNameList = Object.values(result) - .map(values => (Array.isArray(values) ? [] : Object.keys(values))) - .flat(2); - expect(tokens.map(({ name }) => name)).toEqual( - expect.arrayContaining(themeUiTokensNameList) - ); - }); - - it("Module Format - es6 - export default", async () => { - const objectName = "moduleTheme"; - - const options: OptionsType = { - formatConfig: { exportDefault: true, objectName }, - }; - - const result = await toThemeUi(seeds().tokens, options, libs); - expect(result.includes(`export default ${objectName}`)).toBeTruthy(); - expect(result.includes(`export const ${objectName}`)).toBeFalsy(); - expect(result.includes("module.exports")).toBeFalsy(); - }); - - it("Module Format - es6", async () => { - const objectName = "moduleTheme"; - - const options: OptionsType = { - formatConfig: { exportDefault: false, objectName }, - }; - - const result = await toThemeUi(seeds().tokens, options, libs); - - expect(result.includes(`export default ${objectName}`)).toBeFalsy(); - expect(result.includes(`export const ${objectName}`)).toBeTruthy(); - expect(result.includes("module.exports")).toBeFalsy(); - }); - - it("Module Format - commonjs - export default ", async () => { - const objectName = "moduleTheme"; - - const options: OptionsType = { - formatConfig: { module: "commonjs", exportDefault: true, objectName }, - }; - - const result = await toThemeUi(seeds().tokens, options, libs); - - expect(result.includes(`export default ${objectName}`)).toBeFalsy(); - expect(result.includes(`export const ${objectName}`)).toBeFalsy(); - expect(result.includes(`module.exports = ${objectName}`)).toBeTruthy(); - }); - - it("Module Format - commonjs", async () => { - const objectName = "moduleTheme"; - - const options: OptionsType = { - formatConfig: { module: "commonjs", exportDefault: false, objectName }, - }; - - const result = await toThemeUi(seeds().tokens, options, libs); - expect(result.includes(`export default ${objectName}`)).toBeFalsy(); - expect(result.includes(`export const ${objectName}`)).toBeFalsy(); - expect(result.includes(`module.exports = { ${objectName} }`)).toBeTruthy(); - }); -}); diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-theme-ui/to-theme-ui.type.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-theme-ui/to-theme-ui.type.ts deleted file mode 100644 index 2fdcb61bf..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-theme-ui/to-theme-ui.type.ts +++ /dev/null @@ -1,91 +0,0 @@ -import { InputDataType, OptionsType } from "./to-theme-ui.parser"; -import Token from "../../types/tokens/Token"; - -export type ColorsFormat = - | "rgb" - | "prgb" - | "hex" - | "hex6" - | "hex3" - | "hex4" - | "hex8" - | "name" - | "hsl" - | "hsv"; - -export type ThemeUiType = - | "borderStyles" - | "borderWidths" - | "colors" - | "fonts" - | "fontSizes" - | "fontWeights" - | "letterSpacings" - | "lineHeights" - | "opacities" - | "durations" - | "radii" - | "shadows" - | "sizes" - | "space" - | "transitions" - | "zIndices" - | "gradients" - | "border" - | "text"; - -export type DepthMapping = "zIndices"; -export type MeasurementMapping = "sizes" | "space" | "radii"; -export type OpacityMapping = "opacities"; -export type ShadowMapping = "shadows"; -export type FontMapping = "fonts"; -export type TextStyleMapping = - | "fontSizes" - | "fontWeights" - | "letterSpacings" - | "lineHeights"; -export type BorderMapping = "borderStyles" | "borderWidths"; -export type DurationMapping = "durations"; -export type ColorMapping = "colors"; -export type GradientMapping = "gradients"; -export type VariantMapping = "text" | "border"; - -export type ThemeUiTypes = - | DepthMapping - | MeasurementMapping - | OpacityMapping - | ShadowMapping - | FontMapping - | TextStyleMapping - | BorderMapping - | ColorMapping - | GradientMapping - | VariantMapping; - -export type ThemeUiConfig = Partial>; -export type ThemeUiIndexes = Partial< - Record> ->; -export interface ThemeUiTokenClass { - new ( - tokens: Partial, - transformNameFn: Function - ): ThemeUiTokenClassInstance; - afterGenerate?( - themeUiTokens: Record - ): Record; - generateVariants?( - themeUiTokens: Partial>, - tokens: InputDataType, - options: OptionsType, - transformNameFn: Function - ): Record; -} - -export interface ThemeUiTokenClassInstance { - transformedName: string; - generate( - options: OptionsType, - spTokens: InputDataType - ): Partial>; -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-theme-ui/tokens/border.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-theme-ui/tokens/border.ts deleted file mode 100644 index 3dfcc0886..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-theme-ui/tokens/border.ts +++ /dev/null @@ -1,98 +0,0 @@ -import { BorderToken } from "../../../types"; -import { Indexes, OptionsType } from "../to-theme-ui.parser"; -import tinycolor from "tinycolor2"; -import { BorderMapping, ThemeUiTypes } from "../to-theme-ui.type"; - -interface ThemeUiBorder extends Partial> { - border?: Record; - borderStyles?: Record; - borderWidths?: Record; - radii?: Record; -} - -interface ThemeUiBorderVariant { - borderWidth?: string | number; - borderColor?: string; - borderRadius?: string | number; - borderStyle?: Border["value"]["type"]; -} - -export class Border extends BorderToken { - transformedName: string; - constructor(token: Partial, transformedNameFn: Function) { - super(token); - this.transformedName = transformedNameFn(token.name); - } - - generate(): ThemeUiBorder { - const { type, width, radii } = this.value; - const { measure, unit } = width.value; - const style = type.toLowerCase(); - const result: ThemeUiBorder = { - borderWidths: { - [this.transformedName]: `${measure}${unit}`, - }, - }; - - if (style && style !== "none") { - result.borderStyles = { - [this.transformedName]: style as BorderToken["value"]["type"], - }; - } - - if (radii && radii.value) { - result.radii = { - [this.transformedName]: radii?.value.measure, - }; - } - - return result; - } - - static generateVariants( - themeUiTokens: Partial>, - borders: Array, - options: OptionsType, - transformNameFn: Function - ) { - themeUiTokens.border = {}; - - borders.forEach(spToken => { - const variantValue: ThemeUiBorderVariant = {}; - if (spToken.value.color) { - variantValue.borderColor = - spToken.value.color && - "id" in spToken.value.color && - Indexes.Instance.list.colors?.[spToken.value.color.id] - ? (Indexes.Instance.list.colors[spToken.value.color.id] as string) - : tinycolor(spToken.value.color.value).toString( - options?.formatTokens?.colorFormat?.format || "rgb" - ); - } - - if (spToken.value.width) { - variantValue.borderWidth = - spToken.value.width && - "id" in spToken.value.width && - Indexes.Instance.list.sizes?.[spToken.value.width.id] - ? Indexes.Instance.list.sizes[spToken.value.width.id] - : `${spToken.value.width.value.measure}${spToken.value.width.value.unit}`; - } - - if (spToken.value.radii) { - variantValue.borderRadius = - spToken.value.radii && - "id" in spToken.value.radii && - Indexes.Instance.list.sizes?.[spToken.value.radii.id] - ? Indexes.Instance.list.sizes[spToken.value.radii.id] - : `${spToken.value.radii.value.measure}${spToken.value.radii.value.unit}`; - } - - if (spToken.value.type) { - variantValue.borderStyle = spToken.value.type; - } - - themeUiTokens.border[transformNameFn(spToken.name)] = variantValue; - }); - } -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-theme-ui/tokens/color.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-theme-ui/tokens/color.ts deleted file mode 100644 index 75c8740c8..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-theme-ui/tokens/color.ts +++ /dev/null @@ -1,27 +0,0 @@ -import tinycolor from "tinycolor2"; -import { Indexes, OptionsType } from "../to-theme-ui.parser"; -import { ColorToken } from "../../../types"; -import { ColorMapping } from "../to-theme-ui.type"; - -interface ThemeUiColor extends Partial> { - colors: Record; -} - -export class Color extends ColorToken { - transformedName: string; - constructor(token: Partial, transformNameFn: Function) { - super(token); - this.transformedName = transformNameFn(token.name); - } - generate(options: OptionsType): ThemeUiColor { - const result = { - colors: { - [this.transformedName]: tinycolor(this.value).toString( - options?.formatTokens?.colorFormat?.format || "rgb" - ), - }, - }; - Indexes.Instance.add("colors", this.id, this.transformedName); - return result; - } -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-theme-ui/tokens/depth.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-theme-ui/tokens/depth.ts deleted file mode 100644 index 20a09fbff..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-theme-ui/tokens/depth.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { DepthToken } from "../../../types"; -import { DepthMapping } from "../to-theme-ui.type"; -import { Utils } from "./index"; - -interface ThemeUiDepth extends Partial> { - zIndices: Record; -} - -export class Depth extends DepthToken { - transformedName: string; - constructor(token: Partial, transformNameFn: Function) { - super(token); - this.transformedName = transformNameFn(token.name); - } - - generate(): ThemeUiDepth { - return { - zIndices: { - [this.transformedName]: this.value.depth, - }, - }; - } - - static afterGenerate(tokens: ThemeUiDepth) { - tokens.zIndices = Utils.sortObject(tokens.zIndices); - return tokens; - } -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-theme-ui/tokens/duration.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-theme-ui/tokens/duration.ts deleted file mode 100644 index 8deab7a8b..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-theme-ui/tokens/duration.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { DurationToken } from "../../../types"; -import { Utils } from "./index"; -import { DurationMapping } from "../to-theme-ui.type"; - -interface ThemeUiDuration extends Partial> { - durations: Record; -} - -export class Duration extends DurationToken { - transformedName: string; - constructor(token: Partial, transformNameFn: Function) { - super(token); - this.transformedName = transformNameFn(token.name); - } - generate(): ThemeUiDuration { - return { - durations: { - [this.transformedName]: `${this.value.duration}${this.value.unit}`, - }, - }; - } - - static afterGenerate(tokens: ThemeUiDuration) { - tokens.durations = Utils.sortObject(tokens.durations); - return tokens; - } -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-theme-ui/tokens/font.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-theme-ui/tokens/font.ts deleted file mode 100644 index 725d0dfba..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-theme-ui/tokens/font.ts +++ /dev/null @@ -1,39 +0,0 @@ -import { FontToken } from "../../../types"; -import { Utils } from "./index"; -import { FontMapping } from "../to-theme-ui.type"; -import { Indexes } from "../to-theme-ui.parser"; - -interface ThemeUiFont extends Partial> { - fonts?: Record; - fontWeights?: Record; -} - -export class Font extends FontToken { - transformedName: string; - constructor(token: Partial, transformNameFn: Function) { - super(token); - this.transformedName = transformNameFn(token.name); - } - - static afterGenerate(tokens: ThemeUiFont) { - tokens.fonts = Utils.sortObject(tokens.fonts!); - return tokens; - } - - generate(): ThemeUiFont { - const result: ThemeUiFont = { - fonts: { - [this.transformedName]: this.name, - }, - }; - result.fontWeights = { [this.transformedName]: this.value.fontWeight }; - Indexes.Instance.add( - "fontWeights", - this.id, - this.transformedName, - this.value.fontWeight - ); - Indexes.Instance.add("fonts", this.id, this.transformedName); - return result; - } -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-theme-ui/tokens/gradient.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-theme-ui/tokens/gradient.ts deleted file mode 100644 index 7e610fe1d..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-theme-ui/tokens/gradient.ts +++ /dev/null @@ -1,32 +0,0 @@ -import tinycolor from "tinycolor2"; -import { GradientToken } from "../../../types"; -import { GradientMapping } from "../to-theme-ui.type"; - -interface ThemeUiGradient extends Partial> { - gradients?: Record; -} - -export class Gradient extends GradientToken { - transformedName: string; - constructor(token: Partial, transformNameFn: Function) { - super(token); - this.transformedName = transformNameFn(token.name); - } - - generate(): ThemeUiGradient { - return { - gradients: { - [this.transformedName]: this.value.gradients - .map(gradient => { - return `linear-gradient(${gradient.angle}, ${gradient.colors - .map( - ({ color, position }) => - `${tinycolor(color.value).toString("rgb")} ${position}%` - ) - .join(", ")})`; - }) - .join(", "), - }, - }; - } -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-theme-ui/tokens/index.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-theme-ui/tokens/index.ts deleted file mode 100644 index 9d0b7bff1..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-theme-ui/tokens/index.ts +++ /dev/null @@ -1,31 +0,0 @@ -export * from "./color"; -export * from "./gradient"; -export * from "./shadow"; -export * from "./textStyle"; -export * from "./opacity"; -export * from "./depth"; -export * from "./duration"; -export * from "./border"; -export * from "./measurement"; -export * from "./font"; - -export abstract class Utils { - static parseFloatIfString(value: string | number) { - return typeof value === "string" ? parseFloat(value) : value; - } - - static sortObject(obj: Record) { - return Object.entries(obj) - .sort( - ([, a], [, b]) => - this.parseFloatIfString(a) - this.parseFloatIfString(b) - ) - .reduce((r, [k, v]) => ({ ...r, [k]: v }), {}); - } - - static deduplicateAndSortList(list: Array) { - return [...new Set(list)].sort( - (a, b) => this.parseFloatIfString(a) - this.parseFloatIfString(b) - ); - } -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-theme-ui/tokens/measurement.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-theme-ui/tokens/measurement.ts deleted file mode 100644 index 1b2b2dd7e..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-theme-ui/tokens/measurement.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { MeasurementToken } from "../../../types"; -import { Indexes } from "../to-theme-ui.parser"; -import { Utils } from "./index"; -import { MeasurementMapping } from "../to-theme-ui.type"; - -interface ThemeUiSizes extends Partial> { - sizes?: Record; -} - -export class Measurement extends MeasurementToken { - transformedName: string; - constructor(token: Partial, transformNameFn: Function) { - super(token); - this.transformedName = transformNameFn(token.name); - } - generate(): ThemeUiSizes { - const result = { - sizes: { - [this.transformedName]: `${this.value.measure}${this.value.unit}`, - }, - }; - Indexes.Instance.add("sizes", this.id, this.transformedName); - return result; - } - - static afterGenerate(tokens: ThemeUiSizes) { - tokens.sizes = Utils.sortObject(tokens.sizes!); - return tokens; - } -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-theme-ui/tokens/opacity.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-theme-ui/tokens/opacity.ts deleted file mode 100644 index 7c8d172df..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-theme-ui/tokens/opacity.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { OpacityToken } from "../../../types"; -import { OptionsType } from "../to-theme-ui.parser"; -import { Utils } from "./index"; -import { OpacityMapping } from "../to-theme-ui.type"; - -interface ThemeUiOpacities extends Partial> { - opacities: Array; -} - -export class Opacity extends OpacityToken { - transformedName: string; - constructor(token: Partial, transformNameFn: Function) { - super(token); - this.transformedName = transformNameFn(token.name); - } - generate(options: OptionsType): ThemeUiOpacities { - let opacity: number | string = this.value.opacity; - const opacityType = options?.formatTokens?.opacityFormat?.type || "number"; - const opacityUnit = options?.formatTokens?.opacityFormat?.unit || "none"; - if (opacityUnit === "percent") { - opacity = `${opacity}%`; - } else if (opacityType === "string") { - opacity = `${opacity / 100}`; - } else { - opacity = opacity / 100; - } - return { opacities: [opacity] }; - } - - static afterGenerate(tokens: ThemeUiOpacities) { - if (tokens.opacities) - tokens.opacities = Utils.deduplicateAndSortList(tokens.opacities); - return tokens; - } -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-theme-ui/tokens/shadow.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-theme-ui/tokens/shadow.ts deleted file mode 100644 index 0059c8245..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-theme-ui/tokens/shadow.ts +++ /dev/null @@ -1,41 +0,0 @@ -import { ShadowToken } from "../../../types"; -import { OptionsType } from "../to-theme-ui.parser"; -import tinycolor from "tinycolor2"; -import { ShadowMapping } from "../to-theme-ui.type"; - -interface ThemeUiShadow extends Partial> { - shadows?: Record; -} - -export class Shadow extends ShadowToken { - transformedName: string; - constructor(token: Partial, transformNameFn: Function) { - super(token); - this.transformedName = transformNameFn(token.name); - } - generate(options: OptionsType): ThemeUiShadow { - const colorFormat = options?.formatTokens?.colorFormat?.format ?? "rgb"; - - return { - shadows: { - [this.transformedName]: this.value - .reduce((acc, shadow) => { - const { color, offsetX, offsetY, blur, isInner, spread } = shadow; - const x = `${offsetX.value.measure}${offsetX.value.unit}`; - const y = `${offsetY.value.measure}${offsetY.value.unit}`; - const blurString = `${blur.value.measure}${blur.value.unit}`; - const spreadString = spread - ? ` ${spread.value.measure}${spread.value.unit}` - : ""; - const innerText = isInner ? "inset " : ""; - const colorString = tinycolor(color.value).toString(colorFormat); - acc.push( - `${innerText}${x} ${y} ${blurString}${spreadString} ${colorString}` - ); - return acc; - }, [] as Array) - .join(", "), - }, - }; - } -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-theme-ui/tokens/textStyle.ts b/tools/executors/typescript/utilities/design-token-parsers/parsers/to-theme-ui/tokens/textStyle.ts deleted file mode 100644 index da264ef05..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/parsers/to-theme-ui/tokens/textStyle.ts +++ /dev/null @@ -1,286 +0,0 @@ -/* eslint-disable @typescript-eslint/no-non-null-assertion */ -/* eslint-disable no-unsafe-optional-chaining */ -/* eslint-disable @typescript-eslint/ban-types */ -import tinycolor from "tinycolor2"; -import convertMeasurement from "../../../libs/size-manipulation"; -import { IToken, MeasurementToken, TextStyleToken } from "../../../types"; -import { FormatTokenType, Indexes, OptionsType } from "../to-theme-ui.parser"; -import { ThemeUiTypes } from "../to-theme-ui.type"; -import { Utils } from "./index"; - -export interface ThemeUiTextStyle extends Partial> { - fontSizes?: Array; - letterSpacings?: Record; - lineHeights?: Record; -} - -type ComputeParamsFn = { - spToken: TextStyleToken; - themeUiTokens?: Partial>; - options?: OptionsType; -}; - -export class TextStyle extends TextStyleToken { - transformedName: string; - constructor(token: Partial, transformNameFn: Function) { - super(token); - this.transformedName = transformNameFn(token.name); - } - - private getLetterSpacings() { - const ls = this.value.letterSpacing; - if (ls) return `${ls.value.measure}${ls.value.unit}`; - return undefined; - } - private getLineHeights() { - const lh = this.value.lineHeight; - if (lh) return `${lh.value.measure}${lh.value.unit}`; - return undefined; - } - - private getFontSizes(fontFormat: FormatTokenType["fontSizeFormat"]) { - const fontSizeType = fontFormat?.type || "number"; - const fontSize = this.value.fontSize; - if ( - fontFormat?.unit && - this.value.fontSize.value.unit !== fontFormat?.unit - ) { - this.value.fontSize.value = convertMeasurement( - this.value.fontSize.value, - fontFormat?.unit - ); - } - return fontSizeType === "number" - ? [fontSize.value.measure] - : [`${fontSize.value.measure}${fontSize.value.unit}`]; - } - - generate(options: OptionsType, spTokens: Array): ThemeUiTextStyle { - const result: ThemeUiTextStyle = {}; - - result.fontSizes = this.getFontSizes(options?.formatTokens?.fontSizeFormat); - - const letterSpacing = this.getLetterSpacings(); - if (letterSpacing) - result.letterSpacings = { [this.transformedName]: letterSpacing }; - - const lineHeight = this.getLineHeights(); - if (lineHeight) result.lineHeights = { [this.transformedName]: lineHeight }; - - if (options?.variants) { - if (lineHeight) { - Indexes.Instance.add("lineHeights", lineHeight, this.transformedName); - } - if (letterSpacing) { - Indexes.Instance.add( - "letterSpacings", - letterSpacing, - this.transformedName - ); - } - - if (!("id" in this.value.fontSize)) { - const fontSizeToken = new MeasurementToken({ - id: `temp-fontSize-${this.id}`, - value: this.value.fontSize.value, - }); - spTokens.push(fontSizeToken); - this.value.fontSize = fontSizeToken; - Indexes.Instance.add( - "fontSizes", - fontSizeToken.id, - result.fontSizes[0] - ); - } - } - - return result; - } - - static afterGenerate(themeUiTokens: Record) { - if (themeUiTokens.fontSizes) - themeUiTokens.fontSizes = Utils.deduplicateAndSortList( - themeUiTokens.fontSizes - ); - - if (themeUiTokens.fontWeights) - themeUiTokens.fontWeights = Utils.sortObject(themeUiTokens.fontWeights); - - if (themeUiTokens.lineHeights) - themeUiTokens.lineHeights = Utils.sortObject(themeUiTokens.lineHeights); - - if (themeUiTokens.letterSpacings) - themeUiTokens.letterSpacings = Utils.sortObject( - themeUiTokens.letterSpacings - ); - - return themeUiTokens; - } - - static generateVariants( - themeUiTokens: Partial>, - textStyles: Array, - options: OptionsType, - transformNameFn: Function - ) { - themeUiTokens.text = {}; - - textStyles.forEach(spToken => { - const variantValue: Record = {}; - - if (spToken.value.font) { - variantValue.fontFamily = - "id" in spToken.value?.font && - Indexes.Instance.list.fonts?.[spToken.value.font.id] - ? Indexes.Instance.list.fonts[spToken.value.font.id] - : spToken.value.font.value.fontPostScriptName; - } - - if (spToken.value.textTransform) - variantValue.textTransform = spToken.value.textTransform; - - if (spToken.value.letterSpacing) { - variantValue.letterSpacing = TextStyle.computeLetterSpacing({ - spToken, - }); - } - - if (spToken.value.lineHeight) { - variantValue.lineHeight = TextStyle.computeLineHeight({ spToken }); - } - - if (spToken.value.textIndent) { - variantValue.textIndent = TextStyle.computeTextIndent({ spToken }); - } - - if (spToken.value.fontSize) { - variantValue.fontSize = TextStyle.computeFontSize({ - spToken, - themeUiTokens, - }); - } - - if (spToken.value.font?.value?.fontWeight) { - variantValue.fontWeight = TextStyle.computeFontWeight({ spToken }); - } - - if (spToken.value.color) { - variantValue.color = TextStyle.computeColor({ spToken, options }); - } - - if (spToken.value.textAlign?.horizontal) { - variantValue.textAlign = spToken.value.textAlign.horizontal; - } - if (spToken.value.textAlign?.vertical) { - variantValue.verticalAlign = spToken.value.textAlign.vertical; - } - if (spToken.value.textTransform) { - variantValue.textTransform = spToken.value.textTransform; - } - if (spToken.value.textDecoration) { - variantValue.textDecoration = spToken.value.textDecoration.join(" "); - } - if (spToken.value.fontVariant) { - variantValue.fontVariant = spToken.value.fontVariant.join(" "); - } - - themeUiTokens.text[transformNameFn(spToken.name)] = variantValue; - }); - return themeUiTokens; - } - - static computeLetterSpacing({ spToken }: ComputeParamsFn) { - const letterSpacing = `${spToken.value?.letterSpacing!.value.measure}${ - spToken.value?.letterSpacing!.value.unit - }`; - if (Indexes.Instance.list.letterSpacings?.[letterSpacing]) { - return Indexes.Instance.list.letterSpacings[letterSpacing]; - } else if ( - "id" in spToken.value.letterSpacing! && - Indexes.Instance.list.letterSpacings?.[spToken.value.letterSpacing.id] - ) { - return Indexes.Instance.list.letterSpacings[ - spToken.value.letterSpacing.id - ]; - } - return letterSpacing; - } - - static computeLineHeight({ spToken }: ComputeParamsFn) { - const lineHeight = `${spToken.value.lineHeight.value.measure}${spToken.value.lineHeight.value.unit}`; - - if (Indexes.Instance.list.lineHeights?.[lineHeight]) { - return Indexes.Instance.list.lineHeights[lineHeight]; - } else if ( - "id" in spToken.value.lineHeight! && - Indexes.Instance.list.lineHeights?.[spToken.value.lineHeight.id] - ) { - return Indexes.Instance.list.lineHeights[spToken.value.lineHeight.id]; - } - return lineHeight; - } - - static computeFontWeight({ spToken }: ComputeParamsFn) { - const fontWeight = spToken.value.font.value.fontWeight; - if (Indexes.Instance.list.fontWeights?.[fontWeight]) { - return Indexes.Instance.list.fontWeights[fontWeight]; - } else if ( - spToken.value.font.value.fontWeight && - "id" in spToken.value.font && - Indexes.Instance.list.fontWeights?.[spToken.value.font.id] - ) { - return Indexes.Instance.list.fontWeights[spToken.value.font.id]; - } - return fontWeight; - } - - static computeColor({ spToken, options }: ComputeParamsFn) { - const color = spToken.value.color!; - if ( - spToken.value.color && - "id" in spToken.value.color && - Indexes.Instance.list.colors?.[spToken.value.color.id] - ) { - return Indexes.Instance.list.colors[spToken.value.color.id]; - } - return tinycolor(color.value).toString( - options?.formatTokens?.colorFormat?.format || "rgb" - ); - } - - static computeFontSize({ spToken, themeUiTokens }: ComputeParamsFn) { - const fontSize = `${spToken.value.fontSize.value.measure}${spToken.value.fontSize.value.unit}`; - if (Indexes.Instance.list.fontSizes?.[fontSize]) { - return Indexes.Instance.list.fontSizes[fontSize]; - } else if ( - spToken.value.fontSize && - "id" in spToken.value.fontSize && - Indexes.Instance.list.fontSizes?.[spToken.value.fontSize.id] - ) { - return ( - themeUiTokens!.fontSizes as NonNullable - ).findIndex( - fontSize => - fontSize === - Indexes.Instance.list.fontSizes![ - (spToken.value.fontSize as MeasurementToken).id - ] - ); - } - return fontSize; - } - - static computeTextIndent({ spToken }: ComputeParamsFn) { - const textIndent = `${spToken.value.textIndent!.value.measure}${ - spToken.value.textIndent!.value.unit - }`; - - if ( - "id" in spToken.value.textIndent! && - Indexes.Instance.list.sizes?.[spToken.value.textIndent.id] - ) { - return Indexes.Instance.list.sizes[spToken.value.textIndent.id]; - } - return textIndent; - } -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/types/Providers/Apps.ts b/tools/executors/typescript/utilities/design-token-parsers/types/Providers/Apps.ts deleted file mode 100644 index 8ad4d1d5d..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/types/Providers/Apps.ts +++ /dev/null @@ -1,6 +0,0 @@ -export interface AppFormat { - id: string; - name: string; - provider: string; - properties: Record; -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/types/Providers/Sources.ts b/tools/executors/typescript/utilities/design-token-parsers/types/Providers/Sources.ts deleted file mode 100644 index 330abb920..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/types/Providers/Sources.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { AppFormat } from "./Apps"; - -export interface FigmaSourceSettings { - sourceType: "frames" | "localStyles"; - fileId: string; - fileUrl: string; - pageId?: string; - framesIds?: Array; - teamId?: string; -} - -export interface UrlSourceSettings { - [key: string]: any; -} - -export type SourceSettings = UrlSourceSettings | FigmaSourceSettings; - -export type SourceStatusValue = "on" | "off" | "error"; - -export interface Source { - id: string; - type: string; - settings: SourceSettings; - app: AppFormat; - name: string; - lastSyncedAt: Date; - status: SourceStatusValue; -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/types/Providers/index.ts b/tools/executors/typescript/utilities/design-token-parsers/types/Providers/index.ts deleted file mode 100644 index d5e2394ae..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/types/Providers/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from "./Apps"; -export * from "./Sources"; diff --git a/tools/executors/typescript/utilities/design-token-parsers/types/index.ts b/tools/executors/typescript/utilities/design-token-parsers/types/index.ts deleted file mode 100644 index 0722ac087..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/types/index.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { SpServicesType } from "../parsers/global-libs"; - -export * from "./tokens"; -export * from "./Providers"; -export * from "./utils/utils"; - -declare global { - namespace NodeJS { - interface Global { - SpServices: SpServicesType; - } - } -} - -export type ColorsFormat = - | "rgb" - | "prgb" - | "hex" - | "hex6" - | "hex3" - | "hex4" - | "hex8" - | "name" - | "hsl" - | "hsv"; diff --git a/tools/executors/typescript/utilities/design-token-parsers/types/libs/mustache.d.ts b/tools/executors/typescript/utilities/design-token-parsers/types/libs/mustache.d.ts deleted file mode 100644 index ba18d5f7e..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/types/libs/mustache.d.ts +++ /dev/null @@ -1,442 +0,0 @@ -// Type definitions for Mustache 4.1.0 -// Project: https://github.com/janl/mustache.js -// Definitions by: Mark Ashley Bell , -// Manuel Thalmann , -// Phillip Johnsen -// Steve Dignam -// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// Minimum TypeScript Version: 3.7 - -/** - * Provides the functionality to render templates with `{{mustaches}}`. - */ -export interface MustacheStatic { - /** - * The name of the module. - */ - readonly name: string; - - /** - * The version of the module. - */ - readonly version: string; - - /** - * The default opening and closing tags used while parsing the templates. - * - * Different default tags can be overridden by setting this field. They will have effect on all subsequent - * calls to `.render()` or `.parse()`, unless custom tags are given as arguments to those functions. - * - * Default value is `[ "{{", "}}" ]`. - */ - tags: OpeningAndClosingTags; - - /** - * A simple string scanner that is used by the template parser to find tokens in template strings. - */ - Scanner: typeof MustacheScanner; - - /** - * Represents a rendering context by wrapping a view object and maintaining a reference to the parent context. - */ - Context: typeof MustacheContext; - - /** - * A Writer knows how to take a stream of tokens and render them to a `string`, given a context. - * - * It also maintains a cache of templates to avoid the need to parse the same template twice. - */ - Writer: typeof MustacheWriter; - - /** - * HTML escaping by default, can be overriden by setting Mustache.escape explicitly or providing the `options` - * argument with an `escape` function when invoking Mustache.render(). - * - * Escaping can be avoided when needed by using `{{{ value }}}` or `{{& value }}` in templates. - * - * @param value - * The value to escape into a string. - */ - escape: EscapeFunction; - - /** - * Clears all cached templates in this writer. - */ - clearCache(): void; - - /** - * Customise the template caching behaviour by either: - * - * disable it completely by setting it to `undefined` - * - * -- or -- - * - * provide a custom cache strategy that satisfies the `TemplateCache` interface - */ - templateCache: TemplateCache | undefined; - - /** - * Parses and caches the given template in the default writer and returns the array of tokens it contains. - * - * Doing this ahead of time avoids the need to parse templates on the fly as they are rendered. - * - * @param template - * The template to parse. - * - * @param tags - * The tags to use. - */ - parse(template: string, tags?: OpeningAndClosingTags): TemplateSpans; - - /** - * Renders the `template` with the given `view` and `partials` using the default writer. - * - * @param template - * The template to render. - * - * @param view - * The view to render the template with. - * - * @param partials - * Either an object that contains the names and templates of partials that are used in a template - * - * -- or -- - * - * A function that is used to load partial template on the fly that takes a single argument: the name of the partial. - * - * @param tagsOrOptions - * The delimeter tags to use or options overriding global defaults. - */ - render( - template: string, - view: any | MustacheContext, - partials?: PartialsOrLookupFn, - tagsOrOptions?: OpeningAndClosingTags | RenderOptions - ): string; -} - -/** - * A simple string scanner that is used by the template parser to find tokens in template strings. - */ -declare class MustacheScanner { - string: string; - tail: string; - pos: number; - - /** - * Initializes a new instance of the `MustacheScanner` class. - */ - constructor(string: string); - - /** - * Returns `true` if the tail is empty (end of string). - */ - eos(): boolean; - - /** - * Tries to match the given regular expression at the current position. - * - * @param re - * The regex-pattern to match. - * - * @returns - * The matched text if it can match, the empty string otherwise. - */ - scan(re: RegExp): string; - - /** - * Skips all text until the given regular expression can be matched. - * - * @param re - * The regex-pattern to match. - * - * @returns - * Returns the skipped string, which is the entire tail if no match can be made. - */ - scanUntil(re: RegExp): string; -} - -/** - * Represents a rendering context by wrapping a view object and maintaining a reference to the parent context. - */ -export class MustacheContext { - view: any; - parent: MustacheContext | undefined; - - /** - * Initializes a new instance of the `MustacheContext` class. - */ - constructor(view: any, parentContext?: MustacheContext); - - /** - * Creates a new context using the given view with this context as the parent. - * - * @param view - * The view to create the new context with. - */ - push(view: any): MustacheContext; - - /** - * Returns the value of the given name in this context, traversing up the context hierarchy if the value is absent in this context's view. - * - * @param name - * The name to look up. - */ - lookup(name: string): any; -} - -/** - * A Writer knows how to take a stream of tokens and render them to a `string`, given a context. - * - * It also maintains a cache of templates to avoid the need to parse the same template twice. - */ -export class MustacheWriter { - /** - * Initializes a new instance of the `MustacheWriter` class. - */ - constructor(); - - /** - * Clears all cached templates in this writer. - */ - clearCache(): void; - - /** - * Parses and caches the given `template` and returns the array of tokens that is generated from the parse. - * - * @param template - * The template to parse. - * - * @param tags - * The tags to use. - */ - parse(template: string, tags?: OpeningAndClosingTags): any; - - /** - * High-level method that is used to render the given `template` with the given `view`. - * - * @param template - * The template to render. - * - * @param view - * The view to render the template with. - * - * @param partials - * Either an object that contains the names and templates of partials that are used in a template - * - * -- or -- - * - * A function that is used to load partial template on the fly that takes a single argument: the name of the partial. - * - * @param tags - * The tags to use. - */ - render( - template: string, - view: any | MustacheContext, - partials?: PartialsOrLookupFn, - config?: OpeningAndClosingTags | RenderOptions - ): string; - - /** - * Low-level method that renders the given array of `tokens` using the given `context` and `partials`. - * - * @param tokens - * The tokens to render. - * - * @param context - * The context to use for rendering the tokens. - * - * @param partials - * The partials to use for rendering the tokens. - * - * @param originalTemplate - * An object used to extract the portion of the original template that was contained in a higher-order section. - * - * If the template doesn't use higher-order sections, this argument may be omitted. - */ - renderTokens( - tokens: string[][], - context: MustacheContext, - partials?: PartialsOrLookupFn, - originalTemplate?: string, - config?: RenderOptions - ): string; - - /** - * Renders a section block. - * - * @param token - * The token to render. - * - * @param context - * The context to use for rendering the token. - * - * @param partials - * The partials to use for rendering the token. - * - * @param originalTemplate - * An object used to extract the portion of the original template that was contained in a higher-order section. - */ - renderSection( - token: string[], - context: MustacheContext, - partials?: PartialsOrLookupFn, - originalTemplate?: string, - config?: RenderOptions - ): string; - - /** - * Renders an inverted section block. - * - * @param token - * The token to render. - * - * @param context - * The context to use for rendering the token. - * - * @param partials - * The partials to use for rendering the token. - * - * @param originalTemplate - * An object used to extract the portion of the original template that was contained in a higher-order section. - */ - renderInverted( - token: string[], - context: MustacheContext, - partials?: PartialsOrLookupFn, - originalTemplate?: string, - config?: RenderOptions - ): string; - - /** - * Adds indentation to each line of the given partial. - * - * @param partial - * The partial to indent. - * - * @param indentation - * String containing a combination of spaces and tabs to use as indentation. - * - * @param lineHasNonSpace - * Whether to indent lines that are empty. - */ - indentPartial( - partial: string, - indentation: string, - lineHasNonSpace: boolean - ): string; - - /** - * Renders a partial. - * - * @param token - * The token to render. - * - * @param context - * The context to use for rendering the token. - * - * @param partials - * The partials to use for rendering the token. - * - * @param tags - * The tags to use. - */ - renderPartial( - token: string[], - context: MustacheContext, - partials?: PartialsOrLookupFn, - config?: OpeningAndClosingTags | RenderOptions - ): string; - - /** - * Renders an unescaped value. - * - * @param token - * The token to render. - * - * @param context - * The context to use for rendering the token. - */ - unescapedValue(token: string[], context: MustacheContext): string; - - /** - * Renders an escaped value. - * - * @param token - * The token to render. - * - * @param context - * The context to use for rendering the token. - */ - escapedValue( - token: string[], - context: MustacheContext, - config?: RenderOptions - ): string; - - /** - * Renders a raw token. - * - * @param token - * The token to render. - */ - rawValue(token: string[]): string; -} - -type RAW_VALUE = "text"; -type ESCAPED_VALUE = "name"; -type UNESCAPED_VALUE = "&"; -type SECTION = "#"; -type INVERTED = "^"; -type COMMENT = "!"; -type PARTIAL = ">"; -type EQUAL = "="; - -export type TemplateSpanType = - | RAW_VALUE - | ESCAPED_VALUE - | SECTION - | UNESCAPED_VALUE - | INVERTED - | COMMENT - | PARTIAL - | EQUAL; - -export type TemplateSpans = Array< - | [TemplateSpanType, string, number, number] - | [TemplateSpanType, string, number, number, TemplateSpans, number] - | [TemplateSpanType, string, number, number, string, number, boolean] ->; - -/** - * Function responsible for escaping values from the view into the rendered output when templates - * has `{{ value }}` in them. - */ -type EscapeFunction = (value: any) => string; - -/** - * An array of two strings, representing the opening and closing tags respectively, to be used in the templates being rendered. - */ -type OpeningAndClosingTags = [string, string]; - -/** - * Whenever partials are provided, it can either be an object that contains the names and templates of partials that are used in tempaltes - * - * -- or -- - * - * A function that is used to load partial template on the fly that takes a single argument: the name of the partial. - */ -type PartialsOrLookupFn = Record | PartialLookupFn; -type PartialLookupFn = (partialName: string) => string | undefined; - -interface RenderOptions { - escape?: EscapeFunction; - tags?: OpeningAndClosingTags; -} - -interface TemplateCache { - set(cacheKey: string, value: string): void; - get(cacheKey: string): string | undefined; - clear(): void; -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/types/svgo.v1.ts b/tools/executors/typescript/utilities/design-token-parsers/types/svgo.v1.ts deleted file mode 100644 index 06e5c004a..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/types/svgo.v1.ts +++ /dev/null @@ -1,376 +0,0 @@ -/* eslint-disable @typescript-eslint/no-namespace */ -// Type definitions for svgo 1.3 -// Project: https://github.com/svg/svgo -// Definitions by: Bradley Ayers -// Gilad Gray -// Aankhen -// Jan Karres -// Gavin Gregory -// Piotr Bล‚aลผejewicz -// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.2 - -interface PluginCleanupAttrs { - cleanupAttrs: boolean | object; -} - -interface PluginInlineStyles { - inlineStyles: boolean | object; -} - -interface PluginRemoveDoctype { - removeDoctype: boolean | object; -} - -interface PluginRemoveXMLProcInst { - removeXMLProcInst: boolean | object; -} - -interface PluginRemoveComments { - removeComments: boolean | object; -} - -interface PluginRemoveMetadata { - removeMetadata: boolean | object; -} - -interface PluginRemoveTitle { - removeTitle: boolean | object; -} - -interface PluginRemoveDesc { - removeDesc: boolean | object; -} - -interface PluginRemoveUselessDefs { - removeUselessDefs: boolean | object; -} - -interface PluginRemoveXMLNS { - removeXMLNS: boolean | object; -} - -interface PluginRemoveEditorsNSData { - removeEditorsNSData: boolean | object; -} - -interface PluginRemoveEmptyAttrs { - removeEmptyAttrs: boolean | object; -} - -interface PluginRemoveHiddenElems { - removeHiddenElems: boolean | object; -} - -interface PluginRemoveEmptyText { - removeEmptyText: boolean | object; -} - -interface PluginRemoveEmptyContainers { - removeEmptyContainers: boolean | object; -} - -interface PluginRemoveViewBox { - removeViewBox: boolean | object; -} - -interface PluginCleanupEnableBackground { - cleanupEnableBackground: boolean | object; -} - -interface PluginMinifyStyles { - minifyStyles: boolean | object; -} - -interface PluginConvertStyleToAttrs { - convertStyleToAttrs: boolean | object; -} - -interface PluginConvertColors { - convertColors: boolean | object; -} - -interface PluginConvertEllipseToCircle { - /** convert ellipse with equal radius measures to circle */ - convertEllipseToCircle: boolean | object; -} - -interface PluginConvertPathData { - convertPathData: boolean | object; -} - -interface PluginConvertTransform { - convertTransform: boolean | object; -} - -interface PluginRemoveUnknownsAndDefaults { - removeUnknownsAndDefaults: boolean | object; -} - -interface PluginRemoveNonInheritableGroupAttrs { - removeNonInheritableGroupAttrs: boolean | object; -} - -interface PluginRemoveUselessStrokeAndFill { - removeUselessStrokeAndFill: boolean | object; -} - -interface PluginRemoveUnusedNS { - removeUnusedNS: boolean | object; -} - -interface PluginPrefixIds { - /** prefix IDs and classes with the SVG filename or an arbitrary string */ - prefixIds: boolean | object; -} - -interface PluginCleanupIDs { - cleanupIDs: boolean | object; -} - -interface PluginCleanupNumericValues { - cleanupNumericValues: boolean | object; -} - -interface PluginCleanupListOfValues { - cleanupListOfValues: boolean | object; -} - -interface PluginMoveElemsAttrsToGroup { - moveElemsAttrsToGroup: boolean | object; -} - -interface PluginMoveGroupAttrsToElems { - moveGroupAttrsToElems: boolean | object; -} - -interface PluginCollapseGroups { - collapseGroups: boolean | object; -} - -interface PluginRemoveRasterImages { - removeRasterImages: boolean | object; -} - -interface PluginMergePaths { - mergePaths: boolean | object; -} - -interface PluginConvertShapeToPath { - convertShapeToPath: boolean | object; -} - -interface PluginSortAttrs { - sortAttrs: boolean | object; -} - -interface PluginSortDefsChildren { - /** sort children of in order to improve compression */ - sortDefsChildren: boolean | object; -} - -interface PluginRemoveDimensions { - removeDimensions: boolean | object; -} - -interface PluginRemoveAttrs { - removeAttrs: boolean | object; -} - -interface PluginRemoveAttributesBySelector { - removeAttributesBySelector: boolean | object; -} - -interface PluginRemoveElementsByAttr { - removeElementsByAttr: boolean | object; -} - -interface PluginAddClassesToSVGElement { - addClassesToSVGElement: boolean | object; -} - -interface PluginAddAttributesToSVGElement { - addAttributesToSVGElement: boolean | object; -} - -interface PluginRemoveOffCanvasPaths { - removeOffCanvasPaths: boolean | object; -} - -interface PluginRemoveStyleElement { - removeStyleElement: boolean | object; -} - -interface PluginRemoveScriptElement { - removeScriptElement: boolean | object; -} - -interface PluginReusePaths { - reusePaths: boolean | object; -} - -interface SvgInfo { - path?: string | undefined; -} - -interface OptimizedSvg { - data: string; - info: { - width: string; - height: string; - }; - path?: string | undefined; -} - -declare class SVGO { - static Config(config?: SVGO.Options): SVGO.Options; - constructor(config?: SVGO.Options); - optimize(svgString: string, info?: SvgInfo): Promise; -} - -declare namespace SVGO { - type PluginConfig = - | PluginCleanupAttrs - | PluginInlineStyles - | PluginRemoveDoctype - | PluginRemoveXMLProcInst - | PluginRemoveComments - | PluginRemoveMetadata - | PluginRemoveTitle - | PluginRemoveDesc - | PluginRemoveUselessDefs - | PluginRemoveXMLNS - | PluginRemoveEditorsNSData - | PluginRemoveEmptyAttrs - | PluginRemoveHiddenElems - | PluginRemoveEmptyText - | PluginRemoveEmptyContainers - | PluginRemoveViewBox - | PluginCleanupEnableBackground - | PluginMinifyStyles - | PluginConvertStyleToAttrs - | PluginConvertColors - | PluginConvertEllipseToCircle - | PluginConvertPathData - | PluginConvertTransform - | PluginRemoveUnknownsAndDefaults - | PluginRemoveNonInheritableGroupAttrs - | PluginRemoveUselessStrokeAndFill - | PluginRemoveUnusedNS - | PluginPrefixIds - | PluginCleanupIDs - | PluginCleanupNumericValues - | PluginCleanupListOfValues - | PluginMoveElemsAttrsToGroup - | PluginMoveGroupAttrsToElems - | PluginCollapseGroups - | PluginRemoveRasterImages - | PluginMergePaths - | PluginConvertShapeToPath - | PluginSortAttrs - | PluginSortDefsChildren - | PluginRemoveDimensions - | PluginRemoveAttrs - | PluginRemoveAttributesBySelector - | PluginRemoveElementsByAttr - | PluginAddClassesToSVGElement - | PluginAddAttributesToSVGElement - | PluginRemoveOffCanvasPaths - | PluginRemoveStyleElement - | PluginRemoveScriptElement - | PluginReusePaths; - - interface Js2SvgOptions { - /** @default '' */ - doctypeEnd?: string | undefined; - /** @default '' */ - procInstEnd?: string | undefined; - /** @default '<' */ - tagOpenStart?: string | undefined; - /** @default '>' */ - tagOpenEnd?: string | undefined; - /** @default '' */ - tagCloseEnd?: string | undefined; - /** @default '<' */ - tagShortStart?: string | undefined; - /** @default '/>' */ - tagShortEnd?: string | undefined; - /** @default '="' */ - attrStart?: string | undefined; - /** @default '"' */ - attrEnd?: string | undefined; - /** @default '' */ - commentEnd?: string | undefined; - /** @default '' */ - cdataEnd?: string | undefined; - /** @default '' */ - textStart?: string | undefined; - /** @default '' */ - textEnd?: string | undefined; - /** @default 4 */ - indent?: number | undefined; - /** @default /[&'"<>]/g */ - regEntities?: RegExp | undefined; - /** @default /[&"<>]/g */ - regValEntities?: RegExp | undefined; - /** @default encodeEntity */ - encodeEntity?: ((char?: string) => string) | undefined; - /** @default false */ - pretty?: boolean | undefined; - /** @default true */ - useShortTags?: boolean | undefined; - } - - interface Svg2JsOptions { - /** @default true */ - strict?: boolean | undefined; - /** @default false */ - trim?: boolean | undefined; - /** @default true */ - normalize?: boolean | undefined; - /** @default true */ - lowercase?: boolean | undefined; - /** @default true */ - xmlns?: boolean | undefined; - /** @default true */ - position?: boolean | undefined; - } - - interface Options { - /** Output as Data URI string. */ - datauri?: "base64" | "enc" | "unenc" | undefined; - - /** Precision of floating point numbers. Will be passed to each plugin that suppors this param. */ - floatPrecision?: number | undefined; - - /** Use full set of plugins. */ - full?: boolean | undefined; - - /** Pass over SVGs multiple times to ensure all optimizations are applied */ - multipass?: boolean | undefined; - - /** Options for rendering optimized SVG from AST. */ - js2svg?: Js2SvgOptions | undefined; - - /** - * Individual plugin configurations. - * For specific options, see plugin source in https://github.com/svg/svgo/tree/master/plugins. - */ - plugins?: PluginConfig[] | undefined; - - /** Options for parsing original SVG into AST. */ - svg2js?: Svg2JsOptions | undefined; - } -} - -export default SVGO; diff --git a/tools/executors/typescript/utilities/design-token-parsers/types/tokens/Bitmap.ts b/tools/executors/typescript/utilities/design-token-parsers/types/tokens/Bitmap.ts deleted file mode 100644 index e6b20aa3b..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/types/tokens/Bitmap.ts +++ /dev/null @@ -1,19 +0,0 @@ -import Token, { TokenInterface } from "./Token"; -import { TokensType } from "./index"; - -export interface BitmapValue { - url: string; - format?: string; - dimension?: number; - fileName?: string; -} - -export class BitmapToken extends Token implements TokenInterface { - type: TokensType = "bitmap"; - declare value: BitmapValue; - - constructor(element: Partial) { - super(element); - this.value = element.value!; - } -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/types/tokens/Border.ts b/tools/executors/typescript/utilities/design-token-parsers/types/tokens/Border.ts deleted file mode 100644 index 2c644de65..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/types/tokens/Border.ts +++ /dev/null @@ -1,56 +0,0 @@ -import { ColorToken, ColorValue } from "./Color"; -import { MeasurementToken, MeasurementValue } from "./Measurement"; -import Token, { TokenInterface } from "./Token"; -import { TokensType } from "./index"; - -export interface BorderValue { - color: - | ColorToken - | { - value: ColorValue; - }; - type: - | "none" - | "hidden" - | "dotted" - | "dashed" - | "solid" - | "double" - | "groove" - | "ridge" - | "inset" - | "outset"; - width: - | MeasurementToken - | { - value: MeasurementValue; - }; - align?: string; - radii?: - | MeasurementToken - | { - value: MeasurementValue; - }; - rectangleCornerRadii?: Array< - | MeasurementToken - | { - value: MeasurementValue; - } - >; - dashes?: Array< - | MeasurementToken - | { - value: MeasurementValue; - } - >; -} - -export class BorderToken extends Token implements TokenInterface { - type: TokensType = "border"; - declare value: BorderValue; - - constructor(element: Partial) { - super(element); - this.value = element.value!; - } -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/types/tokens/Color.ts b/tools/executors/typescript/utilities/design-token-parsers/types/tokens/Color.ts deleted file mode 100644 index 102d1b131..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/types/tokens/Color.ts +++ /dev/null @@ -1,19 +0,0 @@ -import Token, { TokenInterface } from "./Token"; -import { TokensType } from "./index"; - -export interface ColorValue { - r: number; - g: number; - b: number; - a: number; -} - -export class ColorToken extends Token implements TokenInterface { - type: TokensType = "color"; - declare value: ColorValue; - - constructor(element: Partial) { - super(element); - this.value = element.value!; - } -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/types/tokens/Depth.ts b/tools/executors/typescript/utilities/design-token-parsers/types/tokens/Depth.ts deleted file mode 100644 index 82719c41b..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/types/tokens/Depth.ts +++ /dev/null @@ -1,16 +0,0 @@ -import Token, { TokenInterface } from "./Token"; -import { TokensType } from "./index"; - -export interface DepthValue { - depth: number; -} - -export class DepthToken extends Token implements TokenInterface { - type: TokensType = "depth"; - declare value: DepthValue; - - constructor(element: Partial) { - super(element); - this.value = element.value!; - } -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/types/tokens/Duration.ts b/tools/executors/typescript/utilities/design-token-parsers/types/tokens/Duration.ts deleted file mode 100644 index 47cf7f1cc..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/types/tokens/Duration.ts +++ /dev/null @@ -1,17 +0,0 @@ -import Token, { TokenInterface } from "./Token"; -import { TokensType } from "./index"; - -export interface DurationValue { - duration: number; - unit: string; -} - -export class DurationToken extends Token implements TokenInterface { - type: TokensType = "duration"; - declare value: DurationValue; - - constructor(element: Partial) { - super(element); - this.value = element.value!; - } -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/types/tokens/Font.ts b/tools/executors/typescript/utilities/design-token-parsers/types/tokens/Font.ts deleted file mode 100644 index 77d545210..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/types/tokens/Font.ts +++ /dev/null @@ -1,26 +0,0 @@ -import Token, { TokenInterface } from "./Token"; -import { TokensType } from "./index"; - -export const FontFormatList = ["woff2", "woff", "otf", "ttf", "eot"] as const; -export type AllowedFormat = (typeof FontFormatList)[number]; - -export interface FontValue { - fontFamily: string; - fontPostScriptName: string; - fontWeight: number; - fontFileMissing?: boolean; - isItalic?: boolean; - provider?: "Custom font" | "Google Fonts"; - url?: string; - format?: string; -} - -export class FontToken extends Token implements TokenInterface { - type: TokensType = "font"; - declare value: FontValue; - - constructor(element: Partial) { - super(element); - this.value = element.value!; - } -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/types/tokens/Gradient.ts b/tools/executors/typescript/utilities/design-token-parsers/types/tokens/Gradient.ts deleted file mode 100644 index 568f5cf78..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/types/tokens/Gradient.ts +++ /dev/null @@ -1,32 +0,0 @@ -import { ColorToken, ColorValue } from "./Color"; -import Token, { TokenInterface } from "./Token"; -import { TokensType } from "./index"; - -export interface StepForGradient { - type: string; - color: - | ColorToken - | { - value: ColorValue; - }; - position: number; -} - -interface Gradient { - angle: string; - colors: Array; -} - -export interface GradientValue { - gradients: Array; -} - -export class GradientToken extends Token implements TokenInterface { - type: TokensType = "gradient"; - declare value: GradientValue; - - constructor(element: Partial) { - super(element); - this.value = element.value!; - } -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/types/tokens/Measurement.ts b/tools/executors/typescript/utilities/design-token-parsers/types/tokens/Measurement.ts deleted file mode 100644 index 96f17efbe..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/types/tokens/Measurement.ts +++ /dev/null @@ -1,17 +0,0 @@ -import Token, { TokenInterface } from "./Token"; -import { TokensType } from "./index"; - -export interface MeasurementValue { - measure: number; - unit: string; -} - -export class MeasurementToken extends Token implements TokenInterface { - type: TokensType = "measurement"; - declare value: MeasurementValue; - - constructor(element: Partial) { - super(element); - this.value = element.value!; - } -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/types/tokens/Opacity.ts b/tools/executors/typescript/utilities/design-token-parsers/types/tokens/Opacity.ts deleted file mode 100644 index 3d2cba202..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/types/tokens/Opacity.ts +++ /dev/null @@ -1,16 +0,0 @@ -import Token, { TokenInterface } from "./Token"; -import { TokensType } from "./index"; - -export interface OpacityValue { - opacity: number; -} - -export class OpacityToken extends Token implements TokenInterface { - type: TokensType = "opacity"; - declare value: OpacityValue; - - constructor(element: Partial) { - super(element); - this.value = element.value!; - } -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/types/tokens/Shadow.ts b/tools/executors/typescript/utilities/design-token-parsers/types/tokens/Shadow.ts deleted file mode 100644 index 88a01ec79..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/types/tokens/Shadow.ts +++ /dev/null @@ -1,46 +0,0 @@ -import { ColorToken, ColorValue } from "./Color"; -import { MeasurementToken, MeasurementValue } from "./Measurement"; -import Token, { TokenInterface } from "./Token"; -import { TokensType } from "./index"; - -export interface Shadow { - color: - | { - value: ColorValue; - } - | ColorToken; - offsetX: - | { - value: MeasurementValue; - } - | MeasurementToken; - offsetY: - | { - value: MeasurementValue; - } - | MeasurementToken; - blur: - | { - value: MeasurementValue; - } - | MeasurementToken; - spread?: - | { - value: MeasurementValue; - } - | MeasurementToken; - - isInner: boolean; -} - -export type ShadowValue = Array; - -export class ShadowToken extends Token implements TokenInterface { - type: TokensType = "shadow"; - declare value: ShadowValue; - - constructor(element: Partial) { - super(element); - this.value = element.value!; - } -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/types/tokens/Size.ts b/tools/executors/typescript/utilities/design-token-parsers/types/tokens/Size.ts deleted file mode 100644 index 11b11cce8..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/types/tokens/Size.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { TokensType } from "./index"; -import Token, { TokenInterface } from "./Token"; - -export interface SizeValue { - measure: number; - unit: string; -} - -export class SizeToken extends Token implements TokenInterface { - type: TokensType = "size"; - declare value: SizeValue; - - constructor(element: Partial) { - super(element); - - this.value = element.value!; - } -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/types/tokens/TextStyle.ts b/tools/executors/typescript/utilities/design-token-parsers/types/tokens/TextStyle.ts deleted file mode 100644 index 28ee8edf5..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/types/tokens/TextStyle.ts +++ /dev/null @@ -1,120 +0,0 @@ -import { ColorToken, ColorValue } from "./Color"; -import { FontToken, FontValue } from "./Font"; -import { MeasurementToken, MeasurementValue } from "./Measurement"; -import Token, { TokenInterface } from "./Token"; -import { TokensType } from "./index"; - -export type TextTransformValue = - | "none" - | "capitalize" - | "uppercase" - | "lowercase" - | "full-width" - | "full-size-kana"; - -export type FontVariantValue = - | "normal" - | "none" - | "small-caps" - | "all-small-caps" - | "petite-caps" - | "all-petite-caps" - | "unicase" - | "titling-caps" - | "common-ligatures" - | "no-common-ligatures" - | "discretionary-ligatures" - | "no-discretionary-ligatures" - | "historical-ligatures" - | "no-historical-ligatures" - | "contextual" - | "no-contextual" - | "ordinal" - | "slashed-zero" - | "lining-nums" - | "proportional-nums" - | "tabular-nums" - | "diagonal-fractions" - | "stacked-fractions" - | "oldstyle-nums"; - -export type TextDecorationValue = - | "none" - | "underline" - | "overline" - | "line-through" - | "dashed" - | "wavy"; - -export type TextAlignValue = - | "initial" - | "left" - | "right" - | "center" - | "justify" - | "start" - | "end" - | "justify-all" - | "match-parent"; - -export type VerticalAlignValue = - | "initial" - | "baseline" - | "sub" - | "super" - | "text-top" - | "text-bottom" - | "middle" - | "top" - | "bottom" - | "center"; - -export interface TextStyleValue { - color?: - | ColorToken - | { - value: ColorValue; - }; - font: - | FontToken - | { - value: FontValue; - }; - fontSize: - | MeasurementToken - | { - value: MeasurementValue; - }; - lineHeight: - | MeasurementToken - | { - value: MeasurementValue; - }; - letterSpacing?: - | MeasurementToken - | { - value: MeasurementValue; - }; - textAlign?: { - horizontal?: TextAlignValue; - vertical?: VerticalAlignValue; - }; - textTransform?: TextTransformValue; - fontVariant?: Array; - textDecoration?: Array; - textIndent?: - | MeasurementToken - | { - value: MeasurementValue; - }; -} - -export class TextStyleToken extends Token implements TokenInterface { - type: TokensType = "textStyle"; - declare value: TextStyleValue; - - constructor(element: Partial) { - super(element); - this.value = element.value!; - } -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/types/tokens/Token.ts b/tools/executors/typescript/utilities/design-token-parsers/types/tokens/Token.ts deleted file mode 100644 index 720169282..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/types/tokens/Token.ts +++ /dev/null @@ -1,73 +0,0 @@ -import { Source } from "../Providers"; -import { TokensType, TokensValues } from "./index"; -import crypto from "crypto"; -import { LinkableTokensSignaturesValue } from "../utils/utils"; - -export interface TokenInterface { - originId: string; - name: string; - type: TokensType; - value: TokensValues; - meta?: any; - createdAt?: string; - updatedAt?: string; - source?: Source; -} - -export interface IToken { - originId?: string; - id: string; - type: TokensType; - value: TokensValues; - name: string; - meta?: any; - createdAt?: string; - updatedAt?: string; - source?: Source; - sourceId?: string; - repositoryId?: string; -} - -export abstract class Token implements IToken { - originId: string; - id: string; - type: TokensType; - value!: TokensValues; - meta?: any; - name: string; - createdAt?: string; - updatedAt?: string; - source?: Source; - sourceId?: string; - repositoryId?: string; - - constructor(element: Partial) { - this.originId = element?.originId || ""; - this.type = element.type!; - this.meta = element?.meta || {}; - this.name = element?.name || "No name"; - this.createdAt = element?.createdAt || undefined; - this.updatedAt = element?.updatedAt || undefined; - this.source = element?.source || undefined; - this.sourceId = element?.sourceId || element?.source?.id || undefined; - this.id = element.id!; - // if (element?.id) this.id = element.id; - } - - computeSignature(value: string) { - return crypto.createHash("md5").update(value).digest("hex"); - } - - match( - value: U, - indexes: LinkableTokensSignaturesValue, - tokens: Array - ): T | { value: U } { - const signature = this.computeSignature(JSON.stringify(value)); - return indexes[signature] - ? tokens.find(({ id }) => id === indexes[signature]) || { value } - : { value }; - } -} - -export default Token; diff --git a/tools/executors/typescript/utilities/design-token-parsers/types/tokens/Vector.ts b/tools/executors/typescript/utilities/design-token-parsers/types/tokens/Vector.ts deleted file mode 100644 index 45f8d5fcd..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/types/tokens/Vector.ts +++ /dev/null @@ -1,19 +0,0 @@ -import Token, { TokenInterface } from "./Token"; -import { TokensType } from "./index"; - -export interface VectorValue { - url?: string; - content?: string; - format?: string; - fileName?: string; -} - -export class VectorToken extends Token implements TokenInterface { - type: TokensType = "vector"; - declare value: VectorValue; - - constructor(element: Partial) { - super(element); - this.value = element.value!; - } -} diff --git a/tools/executors/typescript/utilities/design-token-parsers/types/tokens/index.ts b/tools/executors/typescript/utilities/design-token-parsers/types/tokens/index.ts deleted file mode 100644 index 90671d99d..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/types/tokens/index.ts +++ /dev/null @@ -1,70 +0,0 @@ -import { BitmapToken, BitmapValue } from "./Bitmap"; -import { BorderToken, BorderValue } from "./Border"; -import { ColorToken, ColorValue } from "./Color"; -import { DepthToken, DepthValue } from "./Depth"; -import { DurationToken, DurationValue } from "./Duration"; -import { FontToken, FontValue } from "./Font"; -import { GradientToken, GradientValue } from "./Gradient"; -import { MeasurementToken, MeasurementValue } from "./Measurement"; -import { OpacityToken, OpacityValue } from "./Opacity"; -import { ShadowToken, ShadowValue } from "./Shadow"; -import { TextStyleToken, TextStyleValue } from "./TextStyle"; -import { VectorToken, VectorValue } from "./Vector"; - -export type Token = - | BorderToken - | ColorToken - | DurationToken - | FontToken - | GradientToken - | MeasurementToken - | OpacityToken - | ShadowToken - | TextStyleToken - | VectorToken - | DepthToken - | BitmapToken; - -export * from "./Bitmap"; -export * from "./Border"; -export * from "./Color"; -export * from "./Depth"; -export * from "./Duration"; -export * from "./Font"; -export * from "./Gradient"; -export * from "./Measurement"; -export * from "./Opacity"; -export * from "./Shadow"; -export * from "./TextStyle"; -export * from "./Token"; -export * from "./Vector"; - -export type DesignTokensType = - | "border" - | "color" - | "gradient" - | "duration" - | "measurement" - | "opacity" - | "shadow" - | "size" - | "textStyle" - | "depth"; - -export type AssetsType = "font" | "bitmap" | "vector"; - -export type TokensType = AssetsType | DesignTokensType; - -export type TokensValues = - | BitmapValue - | BorderValue - | ColorValue - | DurationValue - | FontValue - | GradientValue - | MeasurementValue - | OpacityValue - | ShadowValue - | TextStyleValue - | VectorValue - | DepthValue; diff --git a/tools/executors/typescript/utilities/design-token-parsers/types/utils/utils.ts b/tools/executors/typescript/utilities/design-token-parsers/types/utils/utils.ts deleted file mode 100644 index ca96c172e..000000000 --- a/tools/executors/typescript/utilities/design-token-parsers/types/utils/utils.ts +++ /dev/null @@ -1,37 +0,0 @@ -export type AllowedFieldsWithType = { - [K in keyof Obj]: Obj[K] extends Type ? K : never; -}[keyof Obj]; - -export interface DownloadableFile { - name: string; - value: { - fileName?: string; - content?: string; // File content in string - url?: string; // File we will download - }; -} - -export type LinkableTokensSignaturesValue = Record; -export interface LinkableTokensSignatures { - color: LinkableTokensSignaturesValue; - measurement: LinkableTokensSignaturesValue; -} - -export type PartialRecord = { - [P in K]?: T; -}; -export type Assign = Omit & B; -export type Await = T extends PromiseLike ? U : T; - -export type RecursiveRecord = Record< - PropertyKey, - T | Record ->; - -export type ObjectKeys = T extends object - ? (keyof T)[] - : T extends number - ? [] - : T extends Array | string - ? string[] - : never; diff --git a/tools/executors/typescript/utilities/index.ts b/tools/executors/typescript/utilities/index.ts deleted file mode 100644 index 749b19c49..000000000 --- a/tools/executors/typescript/utilities/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from "./design-token-parsers"; diff --git a/tools/generators/typescript/client-api/impl.ts b/tools/generators/typescript/client-api/impl.ts index 53baeda69..aa4b88dfa 100644 --- a/tools/generators/typescript/client-api/impl.ts +++ b/tools/generators/typescript/client-api/impl.ts @@ -1,6 +1,6 @@ import { Tree } from "@nx/devkit"; import { executeAsync } from "@open-system/core-server-utilities"; -import { ConsoleLogger } from "@open-system/core-shared-utilities"; +import { ConsoleLogger } from "@open-system/core-shared-logging/console"; // import { ExecOptions, exec } from "child_process"; import { existsSync } from "fs"; import Path from "path"; diff --git a/tools/generators/typescript/cloudflare-worker/impl.ts b/tools/generators/typescript/cloudflare-worker/impl.ts index 775f102a1..495212be1 100644 --- a/tools/generators/typescript/cloudflare-worker/impl.ts +++ b/tools/generators/typescript/cloudflare-worker/impl.ts @@ -8,7 +8,7 @@ import { readProjectConfiguration } from "@nx/devkit"; import { applicationGenerator } from "@nx/node"; -import { ConsoleLogger } from "@open-system/core-shared-utilities"; +import { ConsoleLogger } from "@open-system/core-shared-logging/console"; import { CloudflareWorkerGeneratorSchema } from "./schema"; export default async function ( diff --git a/tools/generators/typescript/project.json b/tools/generators/typescript/project.json index d3d5c6a22..824dc6466 100644 --- a/tools/generators/typescript/project.json +++ b/tools/generators/typescript/project.json @@ -93,6 +93,7 @@ "tags": ["scope:tools", "platform:admin"], "implicitDependencies": [ "core-shared-utilities", + "core-shared-logging", "core-server-utilities", "core-server-cloudflare" ] diff --git a/tools/generators/typescript/repo-readme-format/impl.ts b/tools/generators/typescript/repo-readme-format/impl.ts index 26309ee34..b5fe9e6db 100644 --- a/tools/generators/typescript/repo-readme-format/impl.ts +++ b/tools/generators/typescript/repo-readme-format/impl.ts @@ -2,14 +2,14 @@ import { ProjectConfiguration, Tree, getProjects, - joinPathFragments, + joinPathFragments } from "@nx/devkit"; import { execute, findFileName, - findFilePath, + findFilePath } from "@open-system/core-server-utilities"; -import { ConsoleLogger } from "@open-system/core-shared-utilities"; +import { ConsoleLogger } from "@open-system/core-shared-logging/console"; import { existsSync, readdirSync } from "fs"; import { ReadMeFormatGeneratorSchema } from "./schema"; diff --git a/tools/storm/plugins/graphql/src/generator.ts b/tools/storm/plugins/graphql/src/generator.ts index facbea4fb..fd55576b6 100644 --- a/tools/storm/plugins/graphql/src/generator.ts +++ b/tools/storm/plugins/graphql/src/generator.ts @@ -3,13 +3,13 @@ import * as typescriptPlugin from "@graphql-codegen/typescript"; import * as typescriptResolversPlugin from "@graphql-codegen/typescript-resolvers"; import { GraphQLFileLoader } from "@graphql-tools/graphql-file-loader"; import { loadSchema } from "@graphql-tools/load"; +import { ConsoleLogger } from "@open-system/core-shared-logging"; import { constantCase, kebabCase, lowerCaseFirst, upperCaseFirst } from "@open-system/core-shared-utilities/common/string-fns"; -import { ConsoleLogger } from "@open-system/core-shared-utilities/logging"; import { ApiModel, DataModel, diff --git a/tools/storm/schema/src/cli/cli-util.ts b/tools/storm/schema/src/cli/cli-util.ts index 688d8e771..132f3b78a 100644 --- a/tools/storm/schema/src/cli/cli-util.ts +++ b/tools/storm/schema/src/cli/cli-util.ts @@ -1,4 +1,4 @@ -import { ConsoleLogger } from "@open-system/core-shared-utilities/logging/console-logger"; +import { ConsoleLogger } from "@open-system/core-shared-logging/console"; import { isDataSource, isPlugin, diff --git a/tools/storm/schema/src/cli/plugin-runner.ts b/tools/storm/schema/src/cli/plugin-runner.ts index 214af2d1b..985076fec 100644 --- a/tools/storm/schema/src/cli/plugin-runner.ts +++ b/tools/storm/schema/src/cli/plugin-runner.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ /* eslint-disable @typescript-eslint/no-var-requires */ -import { ConsoleLogger } from "@open-system/core-shared-utilities/logging/console-logger"; +import { ConsoleLogger } from "@open-system/core-shared-logging/console"; import { isPlugin, Plugin } from "@open-system/tools-storm-language/ast"; import type { DMMF } from "@prisma/generator-helper"; import chalk from "chalk"; diff --git a/tools/storm/schema/src/plugins/plugin-utils.ts b/tools/storm/schema/src/plugins/plugin-utils.ts index 223e657b6..fbbf8210b 100644 --- a/tools/storm/schema/src/plugins/plugin-utils.ts +++ b/tools/storm/schema/src/plugins/plugin-utils.ts @@ -1,4 +1,4 @@ -import { ConsoleLogger } from "@open-system/core-shared-utilities/logging/console-logger"; +import { ConsoleLogger } from "@open-system/core-shared-logging/console"; import type { PolicyOperationKind } from "@open-system/tools-storm-runtime"; import fs from "fs"; import path from "path"; diff --git a/tools/storm/schema/src/plugins/prisma/schema-generator.ts b/tools/storm/schema/src/plugins/prisma/schema-generator.ts index da190779e..c4756c95d 100644 --- a/tools/storm/schema/src/plugins/prisma/schema-generator.ts +++ b/tools/storm/schema/src/plugins/prisma/schema-generator.ts @@ -4,7 +4,7 @@ import { } from "@open-system/core-server-utilities/execute"; import { exists } from "@open-system/core-server-utilities/exists"; import { findFilePath } from "@open-system/core-server-utilities/file-path-fns"; -import { ConsoleLogger } from "@open-system/core-shared-utilities/logging"; +import { ConsoleLogger } from "@open-system/core-shared-logging"; import { ArrayExpr, AstNode, diff --git a/tools/storm/schema/src/sdk/code-gen.ts b/tools/storm/schema/src/sdk/code-gen.ts index 328f960fe..60eeca3c9 100644 --- a/tools/storm/schema/src/sdk/code-gen.ts +++ b/tools/storm/schema/src/sdk/code-gen.ts @@ -1,4 +1,4 @@ -import { ConsoleLogger } from "@open-system/core-shared-utilities/logging"; +import { ConsoleLogger } from "@open-system/core-shared-logging"; import prettier, { Options } from "prettier"; import { CompilerOptions, diff --git a/tools/storm/schema/src/sdk/prisma.ts b/tools/storm/schema/src/sdk/prisma.ts index af7ae6171..5912dda20 100644 --- a/tools/storm/schema/src/sdk/prisma.ts +++ b/tools/storm/schema/src/sdk/prisma.ts @@ -1,4 +1,4 @@ -import { ConsoleLogger } from "@open-system/core-shared-utilities/logging"; +import { ConsoleLogger } from "@open-system/core-shared-logging"; import { GeneratorDecl, Model, diff --git a/tsconfig.base.json b/tsconfig.base.json index bf318a5f5..7a84c56cf 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -197,6 +197,12 @@ "@open-system/core-shared-injection/*": [ "libs/core/typescript/shared/injection/src/*" ], + "@open-system/core-shared-logging": [ + "libs/core/typescript/shared/logging/src/index.ts" + ], + "@open-system/core-shared-logging/*": [ + "libs/core/typescript/shared/logging/src/*" + ], "@open-system/core-shared-serialization": [ "libs/core/typescript/shared/serialization/src/index.ts" ],