11import arg from 'arg' ;
22import chalkTemplate from 'chalk-template' ;
3- import { existsSync , readFileSync , writeFileSync , createWriteStream } from 'fs' ;
3+ import { createWriteStream , existsSync , readFileSync , writeFileSync } from 'fs' ;
44import path , { join } from 'path' ;
55import YAML from 'yaml' ;
66import { APIClient } from './APIClient.js' ;
@@ -26,6 +26,7 @@ async function main() {
2626 '--help' : Boolean ,
2727 '--quiet' : Boolean ,
2828 '--version' : Boolean ,
29+ '--elf' : String ,
2930 '--expect-text' : String ,
3031 '--fail-text' : String ,
3132 '--serial-log-file' : String ,
@@ -42,6 +43,7 @@ async function main() {
4243 ) ;
4344
4445 const quiet = args [ '--quiet' ] ;
46+ const elf = args [ '--elf' ] ;
4547 const expectText = args [ '--expect-text' ] ;
4648 const failText = args [ '--fail-text' ] ;
4749 const serialLogFile = args [ '--serial-log-file' ] ;
@@ -74,8 +76,9 @@ async function main() {
7476 const rootDir = args . _ [ 0 ] || '.' ;
7577 const configPath = `${ rootDir } /wokwi.toml` ;
7678 const diagramFile = `${ rootDir } /diagram.json` ;
79+ const configExists = existsSync ( configPath ) ;
7780
78- if ( ! existsSync ( configPath ) ) {
81+ if ( ! elf && ! configExists ) {
7982 console . error ( `Error: wokwi.toml not found in ${ path . resolve ( rootDir ) } ` ) ;
8083 process . exit ( 1 ) ;
8184 }
@@ -85,12 +88,22 @@ async function main() {
8588 process . exit ( 1 ) ;
8689 }
8790
88- const configData = readFileSync ( configPath , 'utf8' ) ;
89- const config = await parseConfig ( configData , rootDir ) ;
90- const diagram = readFileSync ( diagramFile , 'utf8' ) ;
91-
92- const firmwarePath = join ( rootDir , config . wokwi . firmware ) ;
93- const elfPath = join ( rootDir , config . wokwi . elf ) ;
91+ let firmwarePath ;
92+ let elfPath ;
93+ let config ;
94+
95+ if ( configExists ) {
96+ const configData = readFileSync ( configPath , 'utf8' ) ;
97+ config = await parseConfig ( configData , rootDir ) ;
98+
99+ firmwarePath = elf ?? join ( rootDir , config . wokwi . firmware ) ;
100+ elfPath = elf ?? join ( rootDir , config . wokwi . elf ) ;
101+ } else if ( elf ) {
102+ firmwarePath = elf ;
103+ elfPath = elf ;
104+ } else {
105+ throw new Error ( 'Internal error: neither elf nor config exists' ) ;
106+ }
94107
95108 if ( ! existsSync ( firmwarePath ) ) {
96109 console . error ( `Error: firmware file not found: ${ path . resolve ( firmwarePath ) } ` ) ;
@@ -102,7 +115,9 @@ async function main() {
102115 process . exit ( 1 ) ;
103116 }
104117
105- const chips = loadChips ( config . chip ?? [ ] , rootDir ) ;
118+ const diagram = readFileSync ( diagramFile , 'utf8' ) ;
119+
120+ const chips = loadChips ( config ?. chip ?? [ ] , rootDir ) ;
106121
107122 const resolvedScenarioFile = scenarioFile ? path . resolve ( rootDir , scenarioFile ) : null ;
108123 if ( resolvedScenarioFile && ! existsSync ( resolvedScenarioFile ) ) {
0 commit comments