ForSure Logo
ForSure
CLILanguageDocumentationComponents

Getting Started

IntroductionInstallationQuick StartDownloads

Syntax

Basic SyntaxFile StructureCommentsAttributesImport Directives

AI & Neural Network

OverviewExamplesAdvanced FeaturesTeam UsageAPI Reference

Examples

Basic ExamplesIntermediate ExamplesAdvanced Examples

CLI Reference

CommandsOptionsConfiguration

API Reference

OverviewNode APIProgrammatic Usage

Tools & Extensions

VS Code ExtensionSyntax HighlightingEditor Integrations
ForSure Logo
ForSure

A powerful file structure definition language and CLI tool for developers.

GitHubTwitter

Products

CLI LanguageWeb EditorIDE Extensions

Resources

DocumentationExamplesTemplatesBlog

Company

AboutCareersContactPrivacy Policy

© 2026 ForSure. All rights reserved.

TermsPrivacyCookies

API Reference

Programmatic access to ForSure functionality through APIs and SDKs.

Overview

ForSure provides multiple ways to integrate with your applications and workflows:

Node.js API

Use ForSure programmatically in Node.js applications

Node.js API →

Programmatic Usage

Direct integration with ForSure core functionality

Programmatic Usage →

Quick Start

Get started with the ForSure API in minutes:

javascript
// Install the ForSure package npm install @forsure/cli // Import in your application import { ForSure } from '@forsure/cli' // Create a new ForSure instance const forsure = new ForSure() // Parse a ForSure file const project = await forsure.parse('project.forsure') // Generate the file structure await forsure.generate(project, { output: './dist' })

Core APIs

File Parser API

Parse and validate ForSure files:

javascript
import { Parser } from '@forsure/parser' const parser = new Parser() // Parse a ForSure file const ast = await parser.parseFile('project.forsure') // Validate the AST const validation = parser.validate(ast) if (!validation.valid) { console.error('Validation errors:', validation.errors) } // Get file tree const fileTree = parser.buildFileTree(ast) console.log(fileTree)

Generator API

Generate file structures from parsed ForSure files:

javascript
import { Generator } from '@forsure/generator' const generator = new Generator({ outputDir: './output', overwrite: false, dryRun: false }) // Generate files const result = await generator.generate(fileTree) console.log(`Generated ${result.files.length} files`) console.log(`Created ${result.directories.length} directories`)

Template Engine API

Use ForSure's template system for code generation:

javascript
import { TemplateEngine } from '@forsure/templates' const templates = new TemplateEngine({ templateDir: './templates', variables: { author: 'Your Name', license: 'MIT' } }) // Render a template const component = await templates.render('react-component.tsx', { name: 'MyButton', props: ['onClick', 'children'], typescript: true }) // Write to file await templates.writeFile('MyButton.tsx', component)

Configuration

Configure the API to match your needs:

javascript
import { ForSure } from '@forsure/cli' const forsure = new ForSure({ // Global configuration config: './.forsurerc.json', // Generator options generator: { outputDir: './dist', overwrite: true, dryRun: false, templates: './templates' }, // Parser options parser: { strict: true, allowComments: true, validateImports: true }, // Template variables variables: { author: 'Your Name', version: '1.0.0', license: 'MIT' } })

Error Handling

Proper error handling for robust applications:

javascript
import { ForSure, ParseError, GenerateError } from '@forsure/cli' async function processProject(filePath) { try { const forsure = new ForSure() // Parse the file const ast = await forsure.parse(filePath) // Validate const validation = forsure.validate(ast) if (!validation.valid) { throw new Error(`Validation failed: ${validation.errors.join(', ')}`) } // Generate await forsure.generate(ast, { output: './output' }) console.log('Project generated successfully') } catch (error) { if (error instanceof ParseError) { console.error('Parse error:', error.message) console.error('Location:', error.line, error.column) } else if (error instanceof GenerateError) { console.error('Generation error:', error.message) console.error('File:', error.file) } else { console.error('Unexpected error:', error) } } }

Events & Hooks

Listen to events and hook into the generation process:

javascript
import { ForSure } from '@forsure/cli' const forsure = new ForSure() // Listen to parse events forsure.on('parse:start', (file) => { console.log(`Parsing ${file}...`) }) forsure.on('parse:complete', (ast) => { console.log('Parsing complete') }) // Listen to generation events forsure.on('generate:file:start', (file) => { console.log(`Generating ${file.path}...`) }) forsure.on('generate:file:complete', (file) => { console.log(`Generated ${file.path}`) }) forsure.on('generate:complete', (result) => { console.log(`Generated ${result.files.length} files`) }) // Custom hooks forsure.hook('before:generate', async (context) => { // Custom logic before generation console.log('Preparing for generation...') }) forsure.hook('after:generate', async (context) => { // Custom logic after generation console.log('Cleaning up after generation...') })

TypeScript Support

Full TypeScript support with type definitions:

typescript
import { ForSure, FileTree, GeneratorOptions } from '@forsure/cli' interface CustomOptions extends GeneratorOptions { customFeature: boolean metadata?: Record<string, any> } async function generateProject( filePath: string, options: CustomOptions ): Promise<void> { const forsure = new ForSure() const ast: FileTree = await forsure.parse(filePath) await forsure.generate(ast, { outputDir: options.outputDir, customFeature: options.customFeature, metadata: options.metadata }) } // Usage with type safety generateProject('project.forsure', { outputDir: './dist', customFeature: true, metadata: { version: '1.0.0' } })

Next Steps

Explore specific API documentation:

  • Node.js API Documentation →
  • Programmatic Usage Guide →
  • CLI Reference →
  • See API Examples →