Skip to content

PromptScript API


Class: Compiler

Defined in: compiler/src/compiler.ts:50

Compiler that orchestrates the PromptScript compilation pipeline.

Pipeline stages: 1. Resolve - Parse and resolve inheritance/imports 2. Validate - Check AST against validation rules 3. Format - Generate output for target platforms

Example

const compiler = new Compiler({
  resolver: { registryPath: './registry' },
  validator: { requiredGuards: ['@core/guards/compliance'] },
  formatters: [new GitHubFormatter()],
});

const result = await compiler.compile('./project.prs');
if (result.success) {
  for (const [outputPath, output] of result.outputs) {
    console.log(`Generated: ${outputPath}`);
  }
}

Constructors

Constructor

new Compiler(options): Compiler

Defined in: compiler/src/compiler.ts:55

Parameters

options

CompilerOptions

Returns

Compiler

Methods

compile()

compile(entryPath): Promise\<CompileResult>

Defined in: compiler/src/compiler.ts:67

Compile a PromptScript file through the full pipeline.

Parameters

entryPath

string

Path to the entry file

Returns

Promise\<CompileResult>

Compilation result with outputs, errors, and stats


compileAll()

compileAll(entryPath): Promise\<CompileResult>

Defined in: compiler/src/compiler.ts:196

Compile to all registered formatters. Useful when you want to ensure all formatters are used regardless of config.

Parameters

entryPath

string

Path to the entry file

Returns

Promise\<CompileResult>

Compilation result with all formatter outputs


compileFile()

compileFile(filePath): Promise\<CompileResult>

Defined in: compiler/src/compiler.ts:185

Compile a PromptScript file from a file path. This is an alias for compile() for consistency with the documented API.

Parameters

filePath

string

Path to the PromptScript file

Returns

Promise\<CompileResult>

Compilation result


getFormatters()

getFormatters(): readonly Formatter[]

Defined in: compiler/src/compiler.ts:174

Get the configured formatters.

Returns

readonly Formatter[]


watch()

watch(entryPath, options): Promise\<Watcher>

Defined in: compiler/src/compiler.ts:230

Watch for file changes and recompile automatically.

Parameters

entryPath

string

Path to the entry file to compile

options

WatchOptions = {}

Watch options

Returns

Promise\<Watcher>

Watcher handle to control the watch process

Example

const watcher = await compiler.watch('./project.prs', {
  onCompile: (result) => {
    if (result.success) {
      console.log('Compiled successfully');
    }
  },
});

// Later, stop watching
await watcher.close();