@@ -10,6 +10,7 @@ import { detectProjectType } from './projectType.js';
10
10
export async function initProjectWizard ( rootDir : string , opts : { diagramFile ?: string } ) {
11
11
const configPath = path . join ( rootDir , 'wokwi.toml' ) ;
12
12
const diagramFilePath = path . resolve ( rootDir , opts . diagramFile ?? 'diagram.json' ) ;
13
+ const launchJsonPath = path . join ( rootDir , '.vscode' , 'launch.json' ) ;
13
14
14
15
intro ( `Wokwi CLI - Project Initialization Wizard` ) ;
15
16
@@ -94,21 +95,72 @@ export async function initProjectWizard(rootDir: string, opts: { diagramFile?: s
94
95
elfPath = elfPathResponse ;
95
96
}
96
97
98
+ let vsCodeDebug : boolean = false ;
99
+ if ( projectType === 'esp-idf' ) {
100
+ const vsCodeDebugAnswer = await confirm ( {
101
+ message : `Setup VS Code debugging for ESP-IDF project?` ,
102
+ initialValue : true ,
103
+ } ) ;
104
+ if ( isCancel ( vsCodeDebugAnswer ) ) {
105
+ cancel ( 'Operation cancelled.' ) ;
106
+ process . exit ( 0 ) ;
107
+ }
108
+ if ( vsCodeDebugAnswer ) {
109
+ vsCodeDebug = true ;
110
+ }
111
+
112
+ if ( vsCodeDebug && existsSync ( launchJsonPath ) ) {
113
+ const shouldContinue = await confirm ( {
114
+ message : `VS Code debugging configuration already exists in .vscode/launch.json. This operation will overwrite it. Continue?` ,
115
+ initialValue : false ,
116
+ } ) ;
117
+ if ( ! shouldContinue || isCancel ( shouldContinue ) ) {
118
+ cancel ( 'Operation cancelled.' ) ;
119
+ process . exit ( 0 ) ;
120
+ }
121
+ }
122
+ }
123
+
124
+ const tomlContent = [
125
+ `# Wokwi Configuration File` ,
126
+ `# Reference: https://docs.wokwi.com/vscode/project-config` ,
127
+ `[wokwi]` ,
128
+ `version = 1` ,
129
+ `firmware = '${ firmwarePath } '` ,
130
+ `elf = '${ elfPath } '` ,
131
+ ] ;
132
+ if ( vsCodeDebug ) {
133
+ tomlContent . push ( `gdbServerPort=3333` ) ;
134
+ }
135
+
97
136
log . info ( `Writing wokwi.toml...` ) ;
98
- writeFileSync (
99
- configPath ,
100
- `# Wokwi Configuration File
101
- # Reference: https://docs.wokwi.com/vscode/project-config
102
-
103
- [wokwi]
104
- version = 1
105
- firmware = '${ firmwarePath } '
106
- elf = '${ elfPath } '
107
- ` ,
108
- ) ;
137
+ writeFileSync ( configPath , tomlContent . join ( '\n' ) + '\n' ) ;
109
138
110
139
log . info ( `Writing diagram.json...` ) ;
111
140
writeFileSync ( diagramFilePath , JSON . stringify ( createDiagram ( boardType as string ) , null , 2 ) ) ;
112
141
142
+ if ( vsCodeDebug ) {
143
+ log . info ( `Writing .vscode/launch.json...` ) ;
144
+ const vsCodeLaunchJson = {
145
+ version : '0.2.0' ,
146
+ configurations : [
147
+ {
148
+ name : 'Wokwi GDB' ,
149
+ type : 'cppdbg' ,
150
+ request : 'launch' ,
151
+ // eslint-disable-next-line no-template-curly-in-string
152
+ program : '${workspaceFolder}/' + elfPath ,
153
+ // eslint-disable-next-line no-template-curly-in-string
154
+ cwd : '${workspaceFolder}' ,
155
+ MIMode : 'gdb' ,
156
+ // eslint-disable-next-line no-template-curly-in-string
157
+ miDebuggerPath : '${command:espIdf.getToolchainGdb}' ,
158
+ miDebuggerServerAddress : 'localhost:3333' ,
159
+ } ,
160
+ ] ,
161
+ } ;
162
+ writeFileSync ( launchJsonPath , JSON . stringify ( vsCodeLaunchJson , null , 2 ) ) ;
163
+ }
164
+
113
165
outro ( `You're all set!` ) ;
114
166
}
0 commit comments