@@ -220,33 +220,33 @@ export const menuItems: MenuItem[] = [
220
220
saveFile ( ocdDocument ) . then ( ( resp ) => console . info ( 'Saved' , resp ) )
221
221
}
222
222
} ,
223
- {
224
- label : 'OpenTofu (Terraform)' ,
225
- click : ( ocdDocument : OcdDocument , setOcdDocument : Function ) => { // Convert to call to Electron API
226
- const writeTerraformFile = async ( dirHandle : FileSystemDirectoryHandle , filename : string , contents : string [ ] ) => {
227
- const fileHandle : FileSystemFileHandle = await dirHandle . getFileHandle ( filename , { create : true } )
228
- // @ts -ignore
229
- const writable = await fileHandle . createWritable ( )
230
- await writable . write ( contents . join ( '\n' ) )
231
- await writable . close ( )
232
- return writable
233
- }
234
- const saveFile = async ( ocdDocument : OcdDocument ) => {
235
- try {
236
- // @ts -ignore
237
- const handle = await showDirectoryPicker ( )
238
- // const writable = await handle.createWritable()
239
- const exporter = new OcdTerraformExporter ( )
240
- const terraform = exporter . export ( ocdDocument . design )
241
- const fileWriters = Object . entries ( terraform ) . map ( ( [ k , v ] ) => writeTerraformFile ( handle , k , v ) )
242
- return Promise . all ( fileWriters )
243
- } catch ( err : any ) {
244
- console . error ( err . name , err . message ) ;
245
- }
246
- }
247
- saveFile ( ocdDocument ) . then ( ( resp ) => console . info ( 'Saved' , resp ) )
248
- }
249
- } ,
223
+ // {
224
+ // label: 'OpenTofu (Terraform)',
225
+ // click: (ocdDocument: OcdDocument, setOcdDocument: Function) => { // Convert to call to Electron API
226
+ // const writeTerraformFile = async (dirHandle: FileSystemDirectoryHandle, filename: string, contents: string[]) => {
227
+ // const fileHandle: FileSystemFileHandle = await dirHandle.getFileHandle(filename, {create: true})
228
+ // // @ts -ignore
229
+ // const writable = await fileHandle.createWritable()
230
+ // await writable.write(contents.join('\n'))
231
+ // await writable.close()
232
+ // return writable
233
+ // }
234
+ // const saveFile = async (ocdDocument: OcdDocument) => {
235
+ // try {
236
+ // // @ts -ignore
237
+ // const handle = await showDirectoryPicker()
238
+ // // const writable = await handle.createWritable()
239
+ // const exporter = new OcdTerraformExporter()
240
+ // const terraform = exporter.export(ocdDocument.design)
241
+ // const fileWriters = Object.entries(terraform).map(([k, v]) => writeTerraformFile(handle, k, v))
242
+ // return Promise.all(fileWriters)
243
+ // } catch (err: any) {
244
+ // console.error(err.name, err.message);
245
+ // }
246
+ // }
247
+ // saveFile(ocdDocument).then((resp) => console.info('Saved', resp))
248
+ // }
249
+ // },
250
250
{
251
251
label : 'Resource Manager' ,
252
252
click : ( ocdDocument : OcdDocument , setOcdDocument : Function , ocdConsoleConfig : OcdConsoleConfig , setOcdConsoleConfig : Function , activeFile : Record < string , any > , setActiveFile : Function ) => {
@@ -256,6 +256,21 @@ export const menuItems: MenuItem[] = [
256
256
setOcdDocument ( clone )
257
257
}
258
258
} ,
259
+ {
260
+ label : 'OpenTofu (Terraform)' ,
261
+ click : ( ocdDocument : OcdDocument , setOcdDocument : Function , ocdConsoleConfig : OcdConsoleConfig , setOcdConsoleConfig : Function , activeFile : Record < string , any > , setActiveFile : Function ) => {
262
+ const suggestedFilename = activeFile . name . replaceAll ( '.okit' , '.xlsx' )
263
+ const design = JSON . parse ( JSON . stringify ( ocdDocument . design ) ) // Resolve cloning issue when design changed
264
+ console . debug ( 'Export Excel Design:' , design )
265
+ OcdDesignFacade . exportToTerraform ( design , suggestedFilename ) . then ( ( results ) => {
266
+ if ( ! results . canceled ) {
267
+ console . debug ( 'Design Exported to OpenTofu' )
268
+ } else {
269
+ console . debug ( 'Design Exported to OpenTofu Cancelled' )
270
+ }
271
+ } ) . catch ( ( resp ) => { console . warn ( 'Save Design Failed with' , resp ) } )
272
+ }
273
+ } ,
259
274
{
260
275
label : 'Excel' ,
261
276
click : ( ocdDocument : OcdDocument , setOcdDocument : Function , ocdConsoleConfig : OcdConsoleConfig , setOcdConsoleConfig : Function , activeFile : Record < string , any > , setActiveFile : Function ) => {
0 commit comments