1
1
import arg from 'arg' ;
2
2
import chalkTemplate from 'chalk-template' ;
3
- import { existsSync , readFileSync , writeFileSync , createWriteStream } from 'fs' ;
3
+ import { createWriteStream , existsSync , readFileSync , writeFileSync } from 'fs' ;
4
4
import path , { join } from 'path' ;
5
5
import YAML from 'yaml' ;
6
6
import { APIClient } from './APIClient.js' ;
@@ -26,6 +26,7 @@ async function main() {
26
26
'--help' : Boolean ,
27
27
'--quiet' : Boolean ,
28
28
'--version' : Boolean ,
29
+ '--elf' : String ,
29
30
'--expect-text' : String ,
30
31
'--fail-text' : String ,
31
32
'--serial-log-file' : String ,
@@ -42,6 +43,7 @@ async function main() {
42
43
) ;
43
44
44
45
const quiet = args [ '--quiet' ] ;
46
+ const elf = args [ '--elf' ] ;
45
47
const expectText = args [ '--expect-text' ] ;
46
48
const failText = args [ '--fail-text' ] ;
47
49
const serialLogFile = args [ '--serial-log-file' ] ;
@@ -74,8 +76,9 @@ async function main() {
74
76
const rootDir = args . _ [ 0 ] || '.' ;
75
77
const configPath = `${ rootDir } /wokwi.toml` ;
76
78
const diagramFile = `${ rootDir } /diagram.json` ;
79
+ const configExists = existsSync ( configPath ) ;
77
80
78
- if ( ! existsSync ( configPath ) ) {
81
+ if ( ! elf && ! configExists ) {
79
82
console . error ( `Error: wokwi.toml not found in ${ path . resolve ( rootDir ) } ` ) ;
80
83
process . exit ( 1 ) ;
81
84
}
@@ -85,12 +88,22 @@ async function main() {
85
88
process . exit ( 1 ) ;
86
89
}
87
90
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
+ }
94
107
95
108
if ( ! existsSync ( firmwarePath ) ) {
96
109
console . error ( `Error: firmware file not found: ${ path . resolve ( firmwarePath ) } ` ) ;
@@ -102,7 +115,9 @@ async function main() {
102
115
process . exit ( 1 ) ;
103
116
}
104
117
105
- const chips = loadChips ( config . chip ?? [ ] , rootDir ) ;
118
+ const diagram = readFileSync ( diagramFile , 'utf8' ) ;
119
+
120
+ const chips = loadChips ( config ?. chip ?? [ ] , rootDir ) ;
106
121
107
122
const resolvedScenarioFile = scenarioFile ? path . resolve ( rootDir , scenarioFile ) : null ;
108
123
if ( resolvedScenarioFile && ! existsSync ( resolvedScenarioFile ) ) {
0 commit comments