From 7723fa70a4699f35d111ef14e61fb03c03fc22bd Mon Sep 17 00:00:00 2001 From: martmull Date: Mon, 20 Oct 2025 15:41:53 +0200 Subject: [PATCH] Move schemas to constant folder (#15207) - move schemas to constants - increase npm package version --- packages/twenty-cli/package.json | 2 +- packages/twenty-cli/project.json | 3 ++- packages/twenty-cli/src/commands/app-add.command.ts | 5 ++--- .../src/constants/base-application-project-path.ts | 6 ------ packages/twenty-cli/src/constants/constants-path.ts | 10 ++++++++++ packages/twenty-cli/src/constants/schemas.ts | 2 +- .../{ => src/constants}/schemas/agent.schema.json | 2 +- .../constants}/schemas/appManifest.schema.json | 6 +++--- .../{ => src/constants}/schemas/object.schema.json | 2 +- .../constants}/schemas/serverlessFunction.schema.json | 4 ++-- .../{ => src/constants}/schemas/trigger.schema.json | 2 +- packages/twenty-cli/src/utils/app-template.ts | 2 +- packages/twenty-cli/src/utils/schema-validator.ts | 4 ++-- 13 files changed, 27 insertions(+), 23 deletions(-) delete mode 100644 packages/twenty-cli/src/constants/base-application-project-path.ts create mode 100644 packages/twenty-cli/src/constants/constants-path.ts rename packages/twenty-cli/{ => src/constants}/schemas/agent.schema.json (98%) rename packages/twenty-cli/{ => src/constants}/schemas/appManifest.schema.json (95%) rename packages/twenty-cli/{ => src/constants}/schemas/object.schema.json (97%) rename packages/twenty-cli/{ => src/constants}/schemas/serverlessFunction.schema.json (95%) rename packages/twenty-cli/{ => src/constants}/schemas/trigger.schema.json (94%) diff --git a/packages/twenty-cli/package.json b/packages/twenty-cli/package.json index 1eb6494b47..3a49f65959 100644 --- a/packages/twenty-cli/package.json +++ b/packages/twenty-cli/package.json @@ -1,6 +1,6 @@ { "name": "twenty-cli", - "version": "0.1.2-beta", + "version": "0.1.2-gamma", "description": "Command-line interface for Twenty application development", "main": "dist/cli.js", "bin": { diff --git a/packages/twenty-cli/project.json b/packages/twenty-cli/project.json index d8fce929b9..26aed8e04a 100644 --- a/packages/twenty-cli/project.json +++ b/packages/twenty-cli/project.json @@ -19,7 +19,8 @@ "options": { "cwd": "packages/twenty-cli", "commands": [ - "cp -R src/constants/base-application-project dist/constants" + "cp -R src/constants/base-application-project dist/constants", + "cp -R src/constants/schemas dist/constants" ] }, "dependsOn": ["after-build"] diff --git a/packages/twenty-cli/src/commands/app-add.command.ts b/packages/twenty-cli/src/commands/app-add.command.ts index 0fde5bcbb8..db88709e85 100644 --- a/packages/twenty-cli/src/commands/app-add.command.ts +++ b/packages/twenty-cli/src/commands/app-add.command.ts @@ -7,6 +7,7 @@ import { CURRENT_EXECUTION_DIRECTORY } from '../constants/current-execution-dire import { HTTPMethod } from '../types/config.types'; import { parseJsoncFile, writeJsoncFile } from '../utils/jsonc-parser'; import { getSchemaUrls } from '../utils/schema-validator'; +import { BASE_SCHEMAS_PATH } from '../constants/constants-path'; export enum SyncableEntity { AGENT = 'agent', @@ -156,9 +157,7 @@ export class AppAddCommand { entityToCreateData.standardId = uuid; } - const schemasDir = path.join(__dirname, '../../schemas'); - - const schemaPath = path.join(schemasDir, `${entity}.schema.json`); + const schemaPath = path.join(BASE_SCHEMAS_PATH, `${entity}.schema.json`); const schema = await fs.readJson(schemaPath); diff --git a/packages/twenty-cli/src/constants/base-application-project-path.ts b/packages/twenty-cli/src/constants/base-application-project-path.ts deleted file mode 100644 index fa694131a9..0000000000 --- a/packages/twenty-cli/src/constants/base-application-project-path.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { join } from 'path'; - -export const BASE_APPLICATION_PROJECT_PATH = join( - __dirname, - '../constants/base-application-project', -); diff --git a/packages/twenty-cli/src/constants/constants-path.ts b/packages/twenty-cli/src/constants/constants-path.ts new file mode 100644 index 0000000000..82d7a5a6ac --- /dev/null +++ b/packages/twenty-cli/src/constants/constants-path.ts @@ -0,0 +1,10 @@ +import { join } from 'path'; + +const BASE_PATH = join(__dirname, '../constants'); + +export const BASE_APPLICATION_PROJECT_PATH = join( + BASE_PATH, + 'base-application-project', +); + +export const BASE_SCHEMAS_PATH = join(BASE_PATH, 'schemas'); diff --git a/packages/twenty-cli/src/constants/schemas.ts b/packages/twenty-cli/src/constants/schemas.ts index 39dbbdebbf..988bbcae5e 100644 --- a/packages/twenty-cli/src/constants/schemas.ts +++ b/packages/twenty-cli/src/constants/schemas.ts @@ -1,5 +1,5 @@ const SCHEMA_BASE_URL = - 'https://raw.githubusercontent.com/twentyhq/twenty/main/packages/twenty-cli/schemas'; + 'https://raw.githubusercontent.com/twentyhq/twenty/main/packages/twenty-cli/src/constants/schemas'; export const APP_MANIFEST_SCHEMA_URL = `${SCHEMA_BASE_URL}/appManifest.schema.json`; export const AGENT_SCHEMA_URL = `${SCHEMA_BASE_URL}/agent.schema.json`; diff --git a/packages/twenty-cli/schemas/agent.schema.json b/packages/twenty-cli/src/constants/schemas/agent.schema.json similarity index 98% rename from packages/twenty-cli/schemas/agent.schema.json rename to packages/twenty-cli/src/constants/schemas/agent.schema.json index a2cae83d34..d173dc28c8 100644 --- a/packages/twenty-cli/schemas/agent.schema.json +++ b/packages/twenty-cli/src/constants/schemas/agent.schema.json @@ -1,6 +1,6 @@ { "$schema": "http://json-schema.org/draft-07/schema#", - "$id": "https://raw.githubusercontent.com/twentyhq/twenty/main/packages/twenty-cli/schemas/agent.schema.json", + "$id": "https://raw.githubusercontent.com/twentyhq/twenty/main/packages/twenty-cli/src/constants/schemas/agent.schema.json", "title": "Twenty Agent Manifest", "description": "Schema for Twenty AI agent configuration files", "type": "object", diff --git a/packages/twenty-cli/schemas/appManifest.schema.json b/packages/twenty-cli/src/constants/schemas/appManifest.schema.json similarity index 95% rename from packages/twenty-cli/schemas/appManifest.schema.json rename to packages/twenty-cli/src/constants/schemas/appManifest.schema.json index 410e9b60c5..2e70fec378 100644 --- a/packages/twenty-cli/schemas/appManifest.schema.json +++ b/packages/twenty-cli/src/constants/schemas/appManifest.schema.json @@ -1,6 +1,6 @@ { "$schema": "http://json-schema.org/draft-07/schema#", - "$id": "https://raw.githubusercontent.com/twentyhq/twenty/main/packages/twenty-cli/schemas/appManifest.schema.json", + "$id": "https://raw.githubusercontent.com/twentyhq/twenty/main/packages/twenty-cli/src/constants/schemas/appManifest.schema.json", "title": "Twenty App Manifest", "description": "Schema for Twenty application manifest files", "type": "object", @@ -94,7 +94,7 @@ "items": { "type": "object", "description": "Inline agent definition", - "$ref": "https://raw.githubusercontent.com/twentyhq/twenty/main/packages/twenty-cli/schemas/agent.schema.json" + "$ref": "https://raw.githubusercontent.com/twentyhq/twenty/main/packages/twenty-cli/src/constants/schemas/agent.schema.json" } }, "objects": { @@ -103,7 +103,7 @@ "items": { "type": "object", "description": "Inline object definition", - "$ref": "https://raw.githubusercontent.com/twentyhq/twenty/main/packages/twenty-cli/schemas/object.schema.json" + "$ref": "https://raw.githubusercontent.com/twentyhq/twenty/main/packages/twenty-cli/src/constants/schemas/object.schema.json" } } }, diff --git a/packages/twenty-cli/schemas/object.schema.json b/packages/twenty-cli/src/constants/schemas/object.schema.json similarity index 97% rename from packages/twenty-cli/schemas/object.schema.json rename to packages/twenty-cli/src/constants/schemas/object.schema.json index 2354f7bbae..d11839ad50 100644 --- a/packages/twenty-cli/schemas/object.schema.json +++ b/packages/twenty-cli/src/constants/schemas/object.schema.json @@ -1,6 +1,6 @@ { "$schema": "http://json-schema.org/draft-07/schema#", - "$id": "https://raw.githubusercontent.com/twentyhq/twenty/main/packages/twenty-cli/schemas/object.schema.json", + "$id": "https://raw.githubusercontent.com/twentyhq/twenty/main/packages/twenty-cli/src/constants/schemas/object.schema.json", "title": "Twenty Object Manifest", "description": "Schema for Twenty AI object configuration files", "type": "object", diff --git a/packages/twenty-cli/schemas/serverlessFunction.schema.json b/packages/twenty-cli/src/constants/schemas/serverlessFunction.schema.json similarity index 95% rename from packages/twenty-cli/schemas/serverlessFunction.schema.json rename to packages/twenty-cli/src/constants/schemas/serverlessFunction.schema.json index 7d52216f18..e2de157435 100644 --- a/packages/twenty-cli/schemas/serverlessFunction.schema.json +++ b/packages/twenty-cli/src/constants/schemas/serverlessFunction.schema.json @@ -1,6 +1,6 @@ { "$schema": "http://json-schema.org/draft-07/schema#", - "$id": "https://raw.githubusercontent.com/twentyhq/twenty/main/packages/twenty-cli/schemas/serverlessFunction.schema.json", + "$id": "https://raw.githubusercontent.com/twentyhq/twenty/main/packages/twenty-cli/src/constants/schemas/serverlessFunction.schema.json", "title": "Twenty Serverless Function Manifest", "description": "Schema for Twenty AI serverless function configuration files", "type": "object", @@ -41,7 +41,7 @@ "description": "Serverless function's triggers", "items": { "anyOf": [ - { "$ref": "https://raw.githubusercontent.com/twentyhq/twenty/main/packages/twenty-cli/schemas/trigger.schema.json" }, + { "$ref": "https://raw.githubusercontent.com/twentyhq/twenty/main/packages/twenty-cli/src/constants/schemas/trigger.schema.json" }, { "type": "object", "required": ["$ref"], diff --git a/packages/twenty-cli/schemas/trigger.schema.json b/packages/twenty-cli/src/constants/schemas/trigger.schema.json similarity index 94% rename from packages/twenty-cli/schemas/trigger.schema.json rename to packages/twenty-cli/src/constants/schemas/trigger.schema.json index 7ee88f13c4..1d1e5db4e1 100644 --- a/packages/twenty-cli/schemas/trigger.schema.json +++ b/packages/twenty-cli/src/constants/schemas/trigger.schema.json @@ -1,5 +1,5 @@ { - "$id": "https://raw.githubusercontent.com/twentyhq/twenty/main/packages/twenty-cli/schemas/trigger.schema.json", + "$id": "https://raw.githubusercontent.com/twentyhq/twenty/main/packages/twenty-cli/src/constants/schemas/trigger.schema.json", "type": "object", "required": ["universalIdentifier", "type"], "properties": { diff --git a/packages/twenty-cli/src/utils/app-template.ts b/packages/twenty-cli/src/utils/app-template.ts index 5dd0957329..59eb28bc06 100644 --- a/packages/twenty-cli/src/utils/app-template.ts +++ b/packages/twenty-cli/src/utils/app-template.ts @@ -1,7 +1,7 @@ import { randomUUID } from 'crypto'; import { getSchemaUrls } from './schema-validator'; import * as fs from 'fs-extra'; -import { BASE_APPLICATION_PROJECT_PATH } from '../constants/base-application-project-path'; +import { BASE_APPLICATION_PROJECT_PATH } from '../constants/constants-path'; import { writeJsoncFile } from '../utils/jsonc-parser'; import { join } from 'path'; import path from 'path'; diff --git a/packages/twenty-cli/src/utils/schema-validator.ts b/packages/twenty-cli/src/utils/schema-validator.ts index 6eedf577f6..1dbc82ad32 100644 --- a/packages/twenty-cli/src/utils/schema-validator.ts +++ b/packages/twenty-cli/src/utils/schema-validator.ts @@ -8,6 +8,7 @@ import { SERVERLESS_FUNCTION_SCHEMA_URL, TRIGGER_SCHEMA_URL, } from '../constants/schemas'; +import { BASE_SCHEMAS_PATH } from '../constants/constants-path'; export class SchemaValidationError extends Error { constructor( @@ -49,8 +50,7 @@ export const validateSchema = async ( let schema; for (const name of Object.keys(schemaUrls) as (keyof typeof schemaUrls)[]) { - const schemasDir = path.join(__dirname, '../../schemas'); - const schemaPath = path.join(schemasDir, `${name}.schema.json`); + const schemaPath = path.join(BASE_SCHEMAS_PATH, `${name}.schema.json`); ajv.addSchema(await fs.readJson(schemaPath)); if (name === schemaName) {