### LUMOS CLI `validate` Command Example Source: https://www.npmjs.com/package/@getlumos/cli/package/%40getlumos/cli/v/0.1_activeTab=dependencies Shows an example of running the `lumos validate` command and the expected output when the schema syntax is valid. ```bash npx lumos validate schema.lumos # ✅ Schema is valid ``` -------------------------------- ### Generate Code with Different Output Options (CLI Examples) Source: https://www.npmjs.com/package/@getlumos/cli/package/%40getlumos/cli_activeTab=readme Explore various ways to use the `lumos generate` command. Examples include generating both Rust and TypeScript, only Rust, or only TypeScript by specifying the respective output paths. ```bash # Generate both Rust and TypeScript npx lumos generate schema.lumos \ --output-rust programs/src/state.rs \ --output-typescript app/src/types.ts # Generate only Rust npx lumos generate schema.lumos --output-rust src/state.rs # Generate only TypeScript npx lumos generate schema.lumos --output-typescript src/types.ts ``` -------------------------------- ### Install @getlumos/cli Package Source: https://www.npmjs.com/package/@getlumos/cli/package/%40getlumos/cli_activeTab=readme Install the @getlumos/cli package using npm, yarn, or pnpm. This is the first step to using the LUMOS schema language CLI for code generation. ```bash npm install @getlumos/cli # or yarn add @getlumos/cli # or pnpm add @getlumos/cli ``` -------------------------------- ### Lumos CLI 'generate' command options and examples Source: https://www.npmjs.com/package/@getlumos/cli/package/%40getlumos/cli_activeTab=code Details the command-line interface for generating code with Lumos, including arguments for the schema path and options for specifying output file paths for Rust and TypeScript. Provides examples for generating both or either language. ```bash lumos generate [options] Options: --output-rust Output path for Rust code --output-typescript Output path for TypeScript code Examples: # Generate both Rust and TypeScript npx lumos generate schema.lumos \ --output-rust programs/src/state.rs \ --output-typescript app/src/types.ts # Generate only Rust npx lumos generate schema.lumos --output-rust src/state.rs # Generate only TypeScript npx lumos generate schema.lumos --output-typescript src/types.ts ``` -------------------------------- ### Install GetLumos CLI Dependencies and Build Source: https://www.npmjs.com/package/@getlumos/cli/package/%40getlumos/cli_activeTab=readme This set of npm commands covers the essential development workflow for the GetLumos CLI. It includes installing dependencies, building the WASM and TypeScript components, running tests, and using a watch mode for development. ```bash # Install dependencies npm install # Build WASM + TypeScript npm run build # Run tests npm test # Watch mode npm run test:watch ``` -------------------------------- ### LUMOS Schema Definition Example Source: https://www.npmjs.com/package/@getlumos/cli/package/%40getlumos/cli_activeTab=dependencies An example of defining a PlayerAccount struct in the LUMOS schema language. This schema will be used to generate Rust and TypeScript code for Solana. ```lumos #[solana] #[account] struct PlayerAccount { wallet: PublicKey, username: String, level: u16, experience: u64, } ``` -------------------------------- ### Use Generated Rust Code in Anchor Program Source: https://www.npmjs.com/package/@getlumos/cli/package/%40getlumos/cli_activeTab=readme Import and use the generated Rust types, such as `PlayerAccount`, within your Solana Anchor program. This example demonstrates initializing a player account with basic data. ```rust use generated::PlayerAccount; #[program] pub mod my_program { pub fn create_player(ctx: Context) -> Result<()> { let player = &mut ctx.accounts.player; player.wallet = ctx.accounts.authority.key(); player.level = 1; Ok(()) } } ``` -------------------------------- ### Define a LUMOS Schema for Solana Accounts Source: https://www.npmjs.com/package/@getlumos/cli/package/%40getlumos/cli_activeTab=readme Define your data structures in a `.lumos` file using schema syntax. This example shows a `PlayerAccount` with fields like wallet, username, level, and experience, marked for Solana and account usage. ```plaintext # schema.lumos #[solana] #[account] struct PlayerAccount { wallet: PublicKey, username: String, level: u16, experience: u64, } ``` -------------------------------- ### Create a LUMOS Schema File Source: https://www.npmjs.com/package/@getlumos/cli/package/%40getlumos/cli/v/0.1_activeTab=dependencies Example of a .lumos schema file defining a PlayerAccount structure with Solana-specific attributes and data types. This schema will be used to generate Rust and TypeScript code. ```plaintext #/schema.lumos #[solana] #[account] struct PlayerAccount { wallet: PublicKey, username: String, level: u16, experience: u64, } ``` -------------------------------- ### Set up GitHub Actions for GetLumos CLI Build Source: https://www.npmjs.com/package/@getlumos/cli/package/%40getlumos/cli_activeTab=readme This GitHub Actions workflow demonstrates how to set up a CI/CD pipeline that includes installing Node.js dependencies, running the '@getlumos/cli' generate command (via 'npm run generate'), and building the project. It assumes 'npm run generate' is configured in your package.json to use the Lumos CLI. ```yaml name: Build on: [push, pull_request] jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: node-version: '20' - run: npm install - run: npm run generate # Uses @getlumos/cli - run: npm run build ``` -------------------------------- ### CLI Command: Generate Source: https://www.npmjs.com/package/@getlumos/cli/package/%40getlumos/cli_activeTab=dependents Details the 'lumos generate' command, including its syntax, available options for specifying output paths for Rust and TypeScript, and examples for different generation scenarios. ```bash lumos generate [options] Options: --output-rust Output path for Rust code --output-typescript Output path for TypeScript code Examples: # Generate both Rust and TypeScript npx lumos generate schema.lumos \ --output-rust programs/src/state.rs \ --output-typescript app/src/types.ts # Generate only Rust npx lumos generate schema.lumos --output-rust src/state.rs # Generate only TypeScript npx lumos generate schema.lumos --output-typescript src/types.ts ``` -------------------------------- ### Lumos CLI 'validate' command example Source: https://www.npmjs.com/package/@getlumos/cli/package/%40getlumos/cli_activeTab=code Demonstrates the usage of the `lumos validate` command, which checks the syntax of a `.lumos` schema file without generating any code. It provides feedback on whether the schema is valid. ```bash lumos validate Example: npx lumos validate schema.lumos # ✅ Schema is valid ``` -------------------------------- ### Define a PlayerAccount Schema in LUMOS Source: https://www.npmjs.com/package/@getlumos/cli/package/%40getlumos/cli/v/0.1 Example of a schema definition file (`schema.lumos`) for a `PlayerAccount` struct. This schema uses LUMOS syntax with Solana-specific annotations and defines fields like wallet, username, level, and experience. ```lumos #[solana] #[account] struct PlayerAccount { wallet: PublicKey, username: String, level: u16, experience: u64, } ``` -------------------------------- ### Integrate Vite Plugin with GetLumos CLI Source: https://www.npmjs.com/package/@getlumos/cli/package/%40getlumos/cli_activeTab=readme This snippet shows how to integrate the GetLumos CLI as a Vite plugin. It uses the 'generate' function to output TypeScript definitions from a 'schema.lumos' file during the build process. This requires the '@getlumos/cli' package to be installed. ```javascript // vite.config.js import { generate } from '@getlumos/cli'; export default { plugins: [ { name: 'lumos', async buildStart() { await generate('schema.lumos', { outputTypeScript: 'src/generated.ts', }); }, }, ], }; ``` -------------------------------- ### Use Generated TypeScript Code in Frontend Source: https://www.npmjs.com/package/@getlumos/cli/package/%40getlumos/cli_activeTab=readme Import and utilize the generated TypeScript types and schemas, like `PlayerAccount` and `PlayerAccountSchema`, in your frontend application. This example shows deserializing account data using Borsh. ```typescript import { PlayerAccount, PlayerAccountSchema } from './generated'; const player = borsh.deserialize( PlayerAccountSchema, accountData ); console.log(player.username, player.level); ``` -------------------------------- ### Make GetLumos CLI Executable Source: https://www.npmjs.com/package/@getlumos/cli/package/%40getlumos/cli_activeTab=readme This command provides a solution for 'Permission denied' errors when running the GetLumos CLI. It uses 'chmod +x' to make the CLI executable, which is often necessary after installation in certain environments. ```bash chmod +x node_modules/@getlumos/cli/dist/cli.js ``` -------------------------------- ### CLI Command: lumos generate with Options Source: https://www.npmjs.com/package/@getlumos/cli/package/%40getlumos/cli/v/0.1_activeTab=dependents Details the `lumos generate` CLI command, explaining its parameters and options. It highlights how to specify output paths for Rust and TypeScript code, and provides examples for generating both or only one type of output. ```shell lumos generate [options] Options: --output-rust Output path for Rust code --output-typescript Output outputTypeScript code Examples: # Generate both Rust and TypeScript npx lumos generate schema.lumos \ --output-rust programs/src/state.rs \ --output-typescript app/src/types.ts # Generate only Rust npx lumos generate schema.lumos --output-rust src/state.rs # Generate only TypeScript npx lumos generate schema.lumos --output-typescript src/types.ts ``` -------------------------------- ### CLI Command: Validate Source: https://www.npmjs.com/package/@getlumos/cli/package/%40getlumos/cli_activeTab=dependents Describes the 'lumos validate' command, used to check the syntax of a .lumos schema file without generating any code. Provides an example of its usage and expected output. ```bash lumos validate Example: npx lumos validate schema.lumos # ✅ Schema is valid ``` -------------------------------- ### Check Node.js Version for WASM Initialization Source: https://www.npmjs.com/package/@getlumos/cli/package/%40getlumos/cli_activeTab=readme This command is used to troubleshoot WASM module initialization failures with the GetLumos CLI. It checks the installed Node.js version, which must be >= 16.0.0 for the WASM bindings to function correctly. ```bash node --version # Should be >= v16.0.0 ``` -------------------------------- ### Integrate Webpack Plugin with GetLumos CLI Source: https://www.npmjs.com/package/@getlumos/cli/package/%40getlumos/cli_activeTab=readme This example demonstrates how to use the GetLumos CLI as a Webpack plugin. It defines a custom plugin that hooks into the 'beforeCompile' Webpack lifecycle event to generate TypeScript files from a 'schema.lumos' file. The '@getlumos/cli' package is a dependency. ```javascript // webpack.config.js const { generate } = require('@getlumos/cli'); class LumosPlugin { apply(compiler) { compiler.hooks.beforeCompile.tapPromise('LumosPlugin', async () => { await generate('schema.lumos', { outputTypeScript: 'src/generated.ts', }); }); } } module.exports = { plugins: [new LumosPlugin()], }; ``` -------------------------------- ### Configure Vercel/Netlify Build Command for GetLumos CLI Source: https://www.npmjs.com/package/@getlumos/cli/package/%40getlumos/cli_activeTab=readme This JSON snippet shows how to configure the build script for Vercel or Netlify to include the GetLumos CLI generation step. It chains the 'lumos generate' command with 'vite build' using the '&&' operator, ensuring schema generation precedes the Vite build process. ```json { "scripts": { "build": "lumos generate schema.lumos --output-typescript src/generated.ts && vite build" } } ``` -------------------------------- ### Generate Rust and TypeScript Code from Schema (CLI) Source: https://www.npmjs.com/package/@getlumos/cli/package/%40getlumos/cli_activeTab=readme Use the `npx lumos generate` command to create Rust and TypeScript code from your `.lumos` schema file. Specify output paths for both languages using `--output-rust` and `--output-typescript` flags. ```bash npx lumos generate schema.lumos \ --output-rust src/generated.rs \ --output-typescript src/generated.ts ``` -------------------------------- ### Use Generated Rust Code in Anchor Program Source: https://www.npmjs.com/package/@getlumos/cli/package/%40getlumos/cli_activeTab=dependents Demonstrates how to use the generated 'PlayerAccount' struct within a Solana Anchor program. Includes a 'create_player' function that initializes the account. ```rust use generated::PlayerAccount; #[program] pub mod my_program { pub fn create_player(ctx: Context) -> Result<()> { let player = &mut ctx.accounts.player; player.wallet = ctx.accounts.authority.key(); player.level = 1; Ok(()) } } ``` -------------------------------- ### LUMOS CLI `generate` Command Options Source: https://www.npmjs.com/package/@getlumos/cli/package/%40getlumos/cli/v/0.1_activeTab=dependencies Details the arguments and options for the `lumos generate` command. It requires a schema path and accepts optional `--output-rust` and `--output-typescript` flags to specify output file locations. ```bash lumos generate [options] Options: --output-rust Output path for Rust code --output-typescript Output path for TypeScript code ``` -------------------------------- ### Generate Rust and TypeScript Code from Schema (Programmatic) Source: https://www.npmjs.com/package/@getlumos/cli/package/%40getlumos/cli_activeTab=readme Utilize the `generate` function from the @getlumos/cli package to programmatically generate Rust and TypeScript code. Pass the schema path and an options object with output paths for Rust and TypeScript. ```javascript import { generate } from '@getlumos/cli'; await generate('schema.lumos', { outputRust: 'src/generated.rs', outputTypeScript: 'src/generated.ts', }); ``` -------------------------------- ### Programmatic API: `generate` Function Details Source: https://www.npmjs.com/package/@getlumos/cli/package/%40getlumos/cli_activeTab=readme Understand the parameters and return value of the programmatic `generate` function. It takes a schema path and an options object, returning a promise with generated Rust and TypeScript code strings. ```javascript import { generate } from '@getlumos/cli'; const result = await generate('schema.lumos', { outputRust: 'src/generated.rs', outputTypeScript: 'src/generated.ts', }); console.log('Rust code length:', result.rust.length); console.log('TypeScript code length:', result.typescript.length); ``` -------------------------------- ### Integrate Code Generation into package.json Scripts Source: https://www.npmjs.com/package/@getlumos/cli/package/%40getlumos/cli_activeTab=readme Add `lumos generate` commands to your `package.json` scripts for easier execution. This allows you to run code generation, builds, and development tasks with simple npm commands. ```json { "scripts": { "generate": "lumos generate schema.lumos --output-rust programs/src/state.rs --output-typescript app/src/types.ts", "build": "npm run generate && anchor build", "dev": "npm run generate && npm run start" } } ``` -------------------------------- ### package.json Scripts Integration Source: https://www.npmjs.com/package/@getlumos/cli/package/%40getlumos/cli_activeTab=dependents Shows how to integrate LUMOS CLI commands into the 'scripts' section of a 'package.json' file. Enables running code generation and build processes via npm scripts. ```json { "scripts": { "generate": "lumos generate schema.lumos --output-rust programs/src/state.rs --output-typescript app/src/types.ts", "build": "npm run generate && anchor build", "dev": "npm run generate && npm run start" } } ``` -------------------------------- ### Use generated TypeScript PlayerAccount in a frontend application Source: https://www.npmjs.com/package/@getlumos/cli/package/%40getlumos/cli_activeTab=code Illustrates how to use the generated TypeScript code in a frontend application. It demonstrates deserializing account data using Borsh and accessing the `PlayerAccount` properties. ```typescript import { PlayerAccount, PlayerAccountSchema } from './generated'; const player = borsh.deserialize( PlayerAccountSchema, accountData ); console.log(player.username, player.level); ``` -------------------------------- ### Programmatic API: generate function signature and parameters Source: https://www.npmjs.com/package/@getlumos/cli/index Describes the 'generate' function from the @getlumos/cli programmatic API, detailing its parameters: schemaPath and options (outputRust, outputTypeScript). ```javascript generate(schemaPath, options) **Parameters:** * `schemaPath` (string): Path to `.lumos` schema file * `options` (object): * `outputRust` (string, optional): Output path for Rust code * `outputTypeScript` (string, optional): Output path for TypeScript code ``` -------------------------------- ### Integrate LUMOS Generation into package.json Scripts Source: https://www.npmjs.com/package/@getlumos/cli/package/%40getlumos/cli/v/0.1 Configuration snippet for `package.json` to add `lumos generate` commands to npm scripts. This allows for easier execution of code generation as part of the build or development workflow. ```json { "scripts": { "generate": "lumos generate schema.lumos --output-rust programs/src/state.rs --output-typescript app/src/types.ts", "build": "npm run generate && anchor build", "dev": "npm run generate && npm run start" } } Then: npm run generate # Generate code npm run build # Generate + build Anchor program ``` -------------------------------- ### Programmatic API: generate function parameters and return value Source: https://www.npmjs.com/package/@getlumos/cli/package/%40getlumos/cli_activeTab=code Details the programmatic `generate` function, outlining its parameters (`schemaPath`, `options`) and the structure of the returned `GeneratedCode` object, which contains the generated Rust and TypeScript code as strings. ```javascript import { generate } from '@getlumos/cli'; /** * Generate code from a schema file. * @param schemaPath (string): Path to `.lumos` schema file * @param options (object): * @param outputRust (string, optional): Output path for Rust code * @param outputTypeScript (string, optional): Output path for TypeScript code * @returns Promise * @param rust (string): Generated Rust code * @param typescript (string): Generated TypeScript code */ const result = await generate('schema.lumos', { outputRust: 'src/generated.rs', outputTypeScript: 'src/generated.ts', }); console.log('Rust code length:', result.rust.length); console.log('TypeScript code length:', result.typescript.length); ``` -------------------------------- ### Generate Rust and TypeScript code from .lumos schema (Programmatic) Source: https://www.npmjs.com/package/@getlumos/cli/package/%40getlumos/cli_activeTab=code Shows how to invoke the `generate` function from the @getlumos/cli package programmatically to generate Rust and TypeScript code from a schema file. This is useful for build scripts or custom tooling. ```javascript import { generate } from '@getlumos/cli'; await generate('schema.lumos', { outputRust: 'src/generated.rs', outputTypeScript: 'src/generated.ts', }); ``` -------------------------------- ### Generate Code from LUMOS Schema Source: https://www.npmjs.com/package/@getlumos/cli/package/%40getlumos/cli/v/0.1_activeTab=versions Generates Rust and TypeScript code from a .lumos schema file. Supports both CLI execution via npx and programmatic usage within JavaScript/TypeScript projects. Specifies output paths for the generated files. ```bash npx lumos generate schema.lumos \ --output-rust src/generated.rs \ --output-typescript src/generated.ts ``` ```javascript import { generate } from '@getlumos/cli'; await generate('schema.lumos', { outputRust: 'src/generated.rs', outputTypeScript: 'src/generated.ts', }); ``` -------------------------------- ### Programmatic API: `validate` Function Details Source: https://www.npmjs.com/package/@getlumos/cli/package/%40getlumos/cli_activeTab=readme Learn how to use the programmatic `validate` function. It accepts a schema path and returns a promise with a validation result, indicating whether the schema is valid and providing an error message if it's not. ```javascript import { validate } from '@getlumos/cli'; const result = await validate('schema.lumos'); if (!result.valid) { console.error('Validation failed:', result.error); process.exit(1); } ``` -------------------------------- ### LUMOS CLI `validate` Command Source: https://www.npmjs.com/package/@getlumos/cli/package/%40getlumos/cli/v/0.1_activeTab=dependencies Explains the `lumos validate` command, which checks the syntax of a .lumos schema file without generating any code. It takes the schema path as an argument. ```bash lumos validate ``` -------------------------------- ### Programmatic API: validate function parameters and return value Source: https://www.npmjs.com/package/@getlumos/cli/package/%40getlumos/cli_activeTab=code Describes the programmatic `validate` function, specifying its `schemaPath` parameter and the `ValidationResult` object it returns, which indicates whether the schema is valid and includes an error message if it's not. ```javascript import { validate } from '@getlumos/cli'; /** * Validate a schema file. * @param schemaPath (string): Path to `.lumos` schema file * @returns Promise * @param valid (boolean): Whether schema is valid * @param error (string, optional): Error message if invalid */ const result = await validate('schema.lumos'); if (!result.valid) { console.error('Validation failed:', result.error); process.exit(1); } ``` -------------------------------- ### Validate Schema Syntax with `lumos validate` Source: https://www.npmjs.com/package/@getlumos/cli/package/%40getlumos/cli_activeTab=readme Use the `lumos validate` command to check the syntax of your `.lumos` schema file without generating any code. This is useful for ensuring schema correctness before proceeding with code generation. ```bash lumos validate schema.lumos # ✅ Schema is valid ``` -------------------------------- ### Programmatic API: validate function signature and parameters Source: https://www.npmjs.com/package/@getlumos/cli/index Outlines the 'validate' function from the @getlumos/cli programmatic API, specifying its single parameter: schemaPath (string). ```javascript validate(schemaPath) **Parameters:** * `schemaPath` (string): Path to `.lumos` schema file ```