@cxtms/cx-schema

中文文档
1.9.285发布于 2026/10/27MITTypeScriptCommonJS构建来源已验证近 30 天下载 3613

Schema validation package for CXTMS YAML modules

原始使用文档
文档目录35 节
  1. Features
  2. Installation
  3. Quick Start
  4. CLI Commands
  5. validate (default)
  6. init
  7. create
  8. report
  9. schema
  10. example
  11. list
  12. CLI Options
  13. Output Formats
  14. Pretty (default)
  15. Compact
  16. JSON
  17. Programmatic API
  18. Templates
  19. Module Template
  20. Workflow Template
  21. Available Schemas
  22. Module Schemas
  23. Workflow Schemas
  24. Exit Codes
  25. CI/CD Integration
  26. GitHub Actions
  27. GitLab CI
  28. Pre-commit Hook
  29. VS Code Integration
  30. Environment Variables
  31. Development
  32. Building from Source
  33. Testing Locally
  34. License
  35. Support

@cxtms/cx-schema

npm version npm downloads Build Status License: MIT

Schema validation package for CXTMS YAML modules and workflows. This package provides comprehensive validation for YAML-based configurations used in CXTMS.

Features

  • Module & Workflow Validation: Validate both UI modules and workflow definitions
  • CLI Tool: Full-featured command-line interface with multiple commands
  • Project Scaffolding: init command to bootstrap new projects
  • Template Generation: create command to generate modules and workflows from templates
  • Report Generation: Generate validation reports in HTML, Markdown, or JSON formats
  • Auto-Detection: Automatically detects file type (module vs workflow)
  • TypeScript Support: Full TypeScript types and declarations included
  • VS Code Integration: Optional setup for YAML schema validation in VS Code
  • Detailed Error Reporting: Clear error messages with paths and suggestions

Installation

npm install @cxtms/cx-schema

Quick Start

# Initialize a new project
npx cxtms init

# Create a new module
npx cxtms create module orders

# Create a new workflow
npx cxtms create workflow invoice-processor

# Validate files
npx cxtms modules/*.yaml workflows/*.yaml

# Generate validation report
npx cxtms report modules/*.yaml --report report.html

CLI Commands

validate (default)

Validate YAML file(s) against JSON Schema definitions.

cxtms [files...]
cxtms validate [files...]

# Examples
cxtms modules/orders-module.yaml
cxtms modules/*.yaml workflows/*.yaml
cxtms --verbose modules/orders-module.yaml
cxtms --format json modules/orders-module.yaml

init

Initialize a new CX project with configuration files.

cxtms init

Creates:

  • app.yaml - Project configuration
  • README.md - Project documentation
  • AGENTS.md - AI assistant instructions for validation
  • modules/ - Directory for module files
  • workflows/ - Directory for workflow files

create

Create a new module or workflow from template.

cxtms create <type> <name>

# Examples
cxtms create module orders
cxtms create workflow invoice-generator

Generated files include:

  • Unique UUID identifiers
  • fileName property for GitHub repo tracking
  • Sample structure with common patterns

report

Generate validation report for multiple files.

cxtms report [files...] --report <output-file>

# Examples
cxtms report modules/*.yaml --report report.html
cxtms report workflows/*.yaml --report report.md
cxtms report modules/*.yaml workflows/*.yaml --report results.json

Report formats (auto-detected from extension):

  • HTML - Styled report with summary cards and detailed errors
  • Markdown - Documentation-friendly tables and lists
  • JSON - Machine-readable for CI/CD pipelines

schema

Display the JSON Schema definition for a component or task.

cxtms schema <name>

# Examples
cxtms schema form
cxtms schema dataGrid
cxtms schema workflow
cxtms schema foreach

example

Show example YAML for a component or task.

cxtms example <name>

# Examples
cxtms example form
cxtms example workflow

list

List all available schemas for validation.

cxtms list
cxtms list --type module
cxtms list --type workflow

CLI Options

OptionShortDescription
--help-hShow help message
--version-vShow version number
--type <type>-tValidation type: module, workflow, or auto (default: auto)
--format <format>-fOutput format: pretty, json, or compact (default: pretty)
--schemas <path>-sPath to custom schemas directory
--verboseShow detailed output with schema paths
--quiet-qOnly show errors, suppress other output
--report <file>-rGenerate report to file (html, md, or json)
--report-format <fmt>Report format: html, markdown, or json

Output Formats

Pretty (default)

Human-readable output with colored formatting and detailed error info.

╔═══════════════════════════════════════════════════════════════════╗
║                  CX SCHEMA VALIDATION REPORT                     ║
╚═══════════════════════════════════════════════════════════════════╝

  File:    modules/my-module.yaml
  Type:    module
  Status:  ✓ PASSED
  Errors:  0
  Warnings:0

Compact

Minimal output for batch processing.

PASS modules/orders-module.yaml
PASS modules/contacts-module.yaml
FAIL modules/broken-module.yaml (3 errors)

JSON

JSON output for programmatic processing.

{
  "isValid": true,
  "errors": [],
  "warnings": [],
  "summary": {
    "file": "modules/my-module.yaml",
    "status": "PASSED",
    "errorCount": 0
  }
}

Programmatic API

import { ModuleValidator, WorkflowValidator } from '@cxtms/cx-schema';

// Validate a module
const moduleValidator = new ModuleValidator({
  schemasPath: './.cx-schema'
});
const moduleResult = await moduleValidator.validateModule('modules/orders.yaml');

// Validate a workflow
const workflowValidator = new WorkflowValidator({
  schemasPath: './.cx-schema/workflows'
});
const workflowResult = await workflowValidator.validateWorkflow('workflows/process.yaml');

if (moduleResult.isValid) {
  console.log('✓ Module is valid');
} else {
  moduleResult.errors.forEach(error => {
    console.error(`${error.type}: ${error.message} at ${error.path}`);
  });
}

Templates

Templates are stored in the templates/ directory and use placeholder syntax:

PlaceholderDescription
{{name}}Sanitized name (lowercase, dashes)
{{displayName}}Title case display name
{{uuid}}Generated UUID
{{fileName}}Relative path to the file

Module Template

Generated modules include:

  • Module metadata with appModuleId and fileName
  • Sample entities and permissions
  • Routes for list and detail views
  • Layout components with dataGrid and form

Workflow Template

Generated workflows include:

  • Workflow metadata with workflowId and fileName
  • Sample inputs, outputs, and variables
  • Activity with common task examples (Log, Query/GraphQL, switch)
  • Manual trigger

Available Schemas

Module Schemas

Components: layout, form, dataGrid, tabs, tab, field, button, collection, dropdown, datasource, calendar, card, navbar, timeline

Fields: text, textarea, number, select, select-async, date, datetime, time, checkbox, radio, attachment, autocomplete-googleplaces

Actions: navigate, navigateBack, mutation, query, notification, dialog, workflow, setFields, setStore, validateForm

Workflow Schemas

Core: workflow, activity, input, output, variable, trigger, schedule

Control Flow: foreach, switch, while, validation

Utilities: map, setVariable, httpRequest, log, error, csv, export, template

Entities: order, contact, commodity, job, attachment, charge, payment

Communication: email-send, document-render, document-send

Query: graphql (Query/GraphQL, Query/GraphQL@1)

Exit Codes

CodeDescription
0Validation passed (no errors)
1Validation failed (errors found)
2CLI error (invalid arguments, file not found, etc.)

CI/CD Integration

GitHub Actions

- name: Validate YAML files
  run: |
    npx cxtms --format compact modules/*.yaml workflows/*.yaml

- name: Generate validation report
  run: |
    npx cxtms report modules/*.yaml workflows/*.yaml --report validation-report.html

- name: Upload report
  uses: actions/upload-artifact@v3
  with:
    name: validation-report
    path: validation-report.html

GitLab CI

validate:
  script:
    - npx cxtms --format json modules/*.yaml > validation-results.json
  artifacts:
    paths:
      - validation-results.json

Pre-commit Hook

#!/bin/bash
# .git/hooks/pre-commit

staged_files=$(git diff --cached --name-only --diff-filter=ACM | grep -E '\.(yaml|yml)$')

if [ -n "$staged_files" ]; then
  npx cxtms --format compact $staged_files
  if [ $? -ne 0 ]; then
    echo "Validation failed. Please fix errors before committing."
    exit 1
  fi
fi

VS Code Integration

To enable YAML schema validation and autocomplete in VS Code:

node node_modules/@cxtms/cx-schema/scripts/setup-vscode.js

This creates/updates .vscode/settings.json with schema associations.

Environment Variables

VariableDescription
CX_SCHEMA_PATHDefault path to schemas directory
NO_COLORDisable colored output

Development

Building from Source

git clone <repository>
cd cx-schema
npm install
npm run build

Testing Locally

npm pack
# In another project:
npm install /path/to/cxtms-cx-schema-1.0.0.tgz

License

MIT

Support

For issues and questions, please visit the GitHub repository.

版本与发布记录

@cxtms/cx-schema 共发布 140 个版本,首次发布于 2025/12/13;过去 12 个月发布了 140 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.9.285latest2026/10/2714 天前
1.9.2842026/10/2715 天前
1.9.2832026/10/2418 天前
1.9.2822026/10/2319 天前
1.9.2812026/10/2220 天前
1.9.2802026/10/2121 天前

关于 @cxtms/cx-schema 的常见问题

@cxtms/cx-schema 是什么?

Schema validation package for CXTMS YAML modules

如何安装 @cxtms/cx-schema?

在项目目录运行 npm install @cxtms/cx-schema,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 cxtms、cx-cli,可以用 npx cxtms 直接运行。

@cxtms/cx-schema 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@cxtms/cx-schema 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@cxtms/cx-schema 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=14.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@cxtms/cx-schema 可以商用吗?

@cxtms/cx-schema 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@cxtms/cx-schema 的下载量有多少?

根据 npm 官方下载统计,@cxtms/cx-schema 在 2026/10/11 – 2026/11/09 这 30 天内被下载 3,613 次,日均约 120 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@cxtms/cx-schema 还在维护吗?

最新版本 1.9.285 发布于 2026/10/27(14 天前);至今共发布 140 个版本,其中过去 12 个月发布了 140 个;首次发布于 2025/12/13。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。