Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
28ba2cb
CLI: Introduce MimicConfigHandler for multiple tasks management
ncomerci Dec 29, 2025
02aebba
CLI: Add task filtering functionality with include/exclude flags
ncomerci Dec 29, 2025
ce2b416
cli: fixes
ncomerci Dec 29, 2025
9567244
fix: build command
ncomerci Dec 30, 2025
61a9029
fix: test command
ncomerci Dec 30, 2025
7fe826a
fix: getTestPath
ncomerci Dec 30, 2025
2906ee5
Merge branch 'main' into cli/support-multiple-tasks
ncomerci Dec 30, 2025
c4da1ae
Merge branch 'main' into cli/support-multiple-tasks
ncomerci Dec 30, 2025
3fe1160
Merge branch 'main' into cli/support-multiple-tasks
ncomerci Jan 6, 2026
6c1cb78
chore: requested changes
ncomerci Jan 6, 2026
4fdf927
test: added mimic config cases
ncomerci Jan 7, 2026
0d86d68
chore: requested changes
ncomerci Jan 7, 2026
32ad5b2
chore: rollback constants
lgalende Jan 8, 2026
91aca09
chore: requested changes
ncomerci Jan 9, 2026
6865dcc
chore: requested changes
ncomerci Jan 12, 2026
5fe7fc0
feat: execute tasks independently
ncomerci Jan 12, 2026
056fab3
refactor: minor tweaks
ncomerci Jan 12, 2026
982d7cd
Merge branch 'main' into cli/support-multiple-tasks
ncomerci Jan 13, 2026
97a4eaa
refactor: cli commands
ncomerci Jan 13, 2026
8c32c4f
Merge branch 'main' into cli/support-multiple-tasks
ncomerci Jan 13, 2026
5de9882
feat: task handling with default task support
ncomerci Jan 14, 2026
4b0baf3
refactor: simplify return types
ncomerci Jan 14, 2026
7a0f7c1
fix: tests
ncomerci Jan 14, 2026
bf9504e
refactor: update error handling in CLI commands
ncomerci Jan 14, 2026
34499ca
refactor: test command
ncomerci Jan 14, 2026
2069491
refactor: rename 'path' to 'task' in task configuration and related c…
ncomerci Jan 14, 2026
49ffa4e
refactor: change interfaces to types
ncomerci Jan 14, 2026
1076c7c
fix: tests
ncomerci Jan 14, 2026
7748138
refactor: improve error handling and simplify task execution in CLI c…
ncomerci Jan 14, 2026
a476220
refactor: consolidate task filtering logic
ncomerci Jan 14, 2026
1530c94
refactor: code improvements
ncomerci Jan 14, 2026
92153ee
chore: requested change
ncomerci Jan 14, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"@types/lodash": "^4.17.15",
"@types/mocha": "^10.0.1",
"@types/node": "^22.10.5",
"@types/sinon": "^21.0.0",
"axios-mock-adapter": "^2.1.0",
"chai": "^4.3.7",
"eslint-config-mimic": "^0.0.3",
Expand Down
43 changes: 32 additions & 11 deletions packages/cli/src/commands/build.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { Command, Flags } from '@oclif/core'

import Codegen from './codegen'
import Compile from './compile'
import { build } from '../core'
import { createConfirmClean, runTasks } from '../helpers'
import MimicConfigHandler, { taskFilterFlags } from '../lib/MimicConfigHandler'
import { coreLogger } from '../log'

export default class Build extends Command {
static override description = 'Runs code generation and then compiles the task'
Expand All @@ -20,18 +22,37 @@ export default class Build extends Command {
description: 'remove existing generated types before generating new files',
default: false,
}),
...taskFilterFlags,
}

public async run(): Promise<void> {
const { flags } = await this.parse(Build)
const { manifest, task, output, types, clean } = flags

const codegenArgs: string[] = ['--manifest', manifest, '--output', types]
if (clean) codegenArgs.push('--clean')

await Codegen.run(codegenArgs)

const compileArgs: string[] = ['--task', task, '--manifest', manifest, '--output', output]
await Compile.run(compileArgs)
const { manifest, task, output, types, clean, include, exclude } = flags

const tasks = MimicConfigHandler.getFilteredTasks(this, {
defaultTask: {
manifest,
task: task,
output,
types,
},
include,
exclude,
})
await runTasks(this, tasks, async (config) => {
await build(
{
manifestPath: config.manifest,
taskPath: config.task,
outputDir: config.output,
typesDir: config.types,
clean,
confirmClean: createConfirmClean(this, config.types, coreLogger),
},
coreLogger
)

coreLogger.info(`Build complete! Artifacts in ${config.output}/`)
})
}
}
77 changes: 29 additions & 48 deletions packages/cli/src/commands/codegen.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { confirm } from '@inquirer/prompts'
import { Command, Flags } from '@oclif/core'
import * as fs from 'fs'
import { join } from 'path'

import { AbisInterfaceGenerator, InputsInterfaceGenerator, ManifestHandler } from '../lib'
import log from '../log'
import { Manifest } from '../types'
import { codegen } from '../core'
import { createConfirmClean, runTasks } from '../helpers'
import MimicConfigHandler, { taskFilterFlags } from '../lib/MimicConfigHandler'
import { coreLogger } from '../log'

export default class Codegen extends Command {
static override description = 'Generates typed interfaces for declared inputs and ABIs from your manifest.yaml file'
Expand All @@ -14,56 +12,39 @@ export default class Codegen extends Command {

static override flags = {
manifest: Flags.string({ char: 'm', description: 'Specify a custom manifest file path', default: 'manifest.yaml' }),
output: Flags.string({ char: 'o', description: 'Ouput directory for generated types', default: './src/types' }),
output: Flags.string({ char: 'o', description: 'Output directory for generated types', default: './src/types' }),
clean: Flags.boolean({
char: 'c',
description: 'Remove existing generated types before generating new files',
default: false,
}),
...taskFilterFlags,
}

public async run(): Promise<void> {
const { flags } = await this.parse(Codegen)
const { manifest: manifestDir, output: outputDir, clean } = flags
const manifest = ManifestHandler.load(this, manifestDir)

if (clean) {
const shouldDelete = await confirm({
message: `Are you sure you want to ${log.warnText('delete')} all the contents in ${log.highlightText(outputDir)}. This action is ${log.warnText('irreversible')}`,
default: false,
})
if (!shouldDelete) {
console.log('You can remove the --clean flag from your command')
console.log('Stopping initialization...')
this.exit(0)
}
log.startAction(`Deleting contents of ${outputDir}`)
if (fs.existsSync(outputDir)) fs.rmSync(outputDir, { recursive: true, force: true })
}

log.startAction('Generating code')
if (Object.keys(manifest.inputs).length == 0 && Object.keys(manifest.abis).length == 0) {
log.stopAction()
return
}

if (!fs.existsSync(outputDir)) fs.mkdirSync(outputDir, { recursive: true })

generateAbisCode(manifest, outputDir, manifestDir)
generateInputsCode(manifest, outputDir)
log.stopAction()
const { manifest, output, clean, include, exclude } = flags

const tasks = MimicConfigHandler.getFilteredTasks(this, {
defaultTask: {
manifest,
types: output,
task: '',
output: '',
},
include,
exclude,
})
await runTasks(this, tasks, async (config) => {
await codegen(
{
manifestPath: config.manifest,
outputDir: config.types,
clean,
confirmClean: createConfirmClean(this, config.types, coreLogger),
},
coreLogger
)
})
}
}

function generateAbisCode(manifest: Manifest, outputDir: string, manifestDir: string) {
for (const [contractName, path] of Object.entries(manifest.abis)) {
const abi = JSON.parse(fs.readFileSync(join(manifestDir, '../', path), 'utf-8'))
const abiInterface = AbisInterfaceGenerator.generate(abi, contractName)
if (abiInterface.length > 0) fs.writeFileSync(`${outputDir}/${contractName}.ts`, abiInterface)
}
}

function generateInputsCode(manifest: Manifest, outputDir: string) {
const inputsInterface = InputsInterfaceGenerator.generate(manifest.inputs)
if (inputsInterface.length > 0) fs.writeFileSync(`${outputDir}/index.ts`, inputsInterface)
}
70 changes: 29 additions & 41 deletions packages/cli/src/commands/compile.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { Command, Flags } from '@oclif/core'
import * as fs from 'fs'
import * as path from 'path'

import ManifestHandler from '../lib/ManifestHandler'
import { execBinCommand } from '../lib/packageManager'
import log from '../log'
import { compile } from '../core'
import { runTasks } from '../helpers'
import MimicConfigHandler, { taskFilterFlags } from '../lib/MimicConfigHandler'
import { coreLogger } from '../log'

export default class Compile extends Command {
static override description = 'Compiles task'
Expand All @@ -15,45 +14,34 @@ export default class Compile extends Command {
task: Flags.string({ char: 't', description: 'task to compile', default: 'src/task.ts' }),
manifest: Flags.string({ char: 'm', description: 'manifest to validate', default: 'manifest.yaml' }),
output: Flags.string({ char: 'o', description: 'output directory', default: './build' }),
...taskFilterFlags,
}

public async run(): Promise<void> {
const { flags } = await this.parse(Compile)
const { task: taskFile, output: outputDir, manifest: manifestDir } = flags

const absTaskFile = path.resolve(taskFile)
const absOutputDir = path.resolve(outputDir)

if (!fs.existsSync(absOutputDir)) fs.mkdirSync(absOutputDir, { recursive: true })

log.startAction('Verifying Manifest')
const manifest = ManifestHandler.load(this, manifestDir)
log.startAction('Compiling')

const ascArgs = [
absTaskFile,
'--target',
'release',
'--outFile',
path.join(absOutputDir, 'task.wasm'),
'--optimize',
'--exportRuntime',
'--transform',
'json-as/transform',
]

const result = execBinCommand('asc', ascArgs, process.cwd())
if (result.status !== 0) {
this.error('AssemblyScript compilation failed', {
code: 'BuildError',
suggestions: ['Check the AssemblyScript file'],
})
}

log.startAction('Saving files')

fs.writeFileSync(path.join(outputDir, 'manifest.json'), JSON.stringify(manifest, null, 2))
log.stopAction()
console.log(`Build complete! Artifacts in ${outputDir}/`)
const { task: taskPath, output, manifest, include, exclude } = flags

const tasks = MimicConfigHandler.getFilteredTasks(this, {
defaultTask: {
manifest,
task: taskPath,
output,
types: '',
},
include,
exclude,
})
await runTasks(this, tasks, async (config) => {
await compile(
{
manifestPath: config.manifest,
taskPath: config.task,
outputDir: config.output,
},
coreLogger
)

coreLogger.info(`Build complete! Artifacts in ${config.output}/`)
})
}
}
Loading