From a96563ef4e8a750c23fab947604d8db213985009 Mon Sep 17 00:00:00 2001 From: ioedeveloper Date: Sat, 15 Feb 2025 17:25:24 +0000 Subject: [PATCH] Save noir program in build directory. --- .../src/app/services/noirPluginClient.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/apps/noir-compiler/src/app/services/noirPluginClient.ts b/apps/noir-compiler/src/app/services/noirPluginClient.ts index f15d70fdf1..cf8bd4e5d0 100644 --- a/apps/noir-compiler/src/app/services/noirPluginClient.ts +++ b/apps/noir-compiler/src/app/services/noirPluginClient.ts @@ -7,6 +7,7 @@ import type { FileManager } from '@noir-lang/noir_wasm/dist/node/main' import pathModule from 'path' import { DEFAULT_TOML_CONFIG } from '../actions/constants' import NoirParser from './noirParser' +import { extractNameFromKey, extractParentFromKey } from '@remix-ui/helper' export class NoirPluginClient extends PluginClient { public internalEvents: EventManager public fm: FileManager @@ -28,10 +29,9 @@ export class NoirPluginClient extends PluginClient { onActivation(): void { this.internalEvents.emit('noir_activated') - this.setup() } - async setup(): Promise { + async setupNargoToml(): Promise { // @ts-ignore const nargoTomlExists = await this.call('fileManager', 'exists', 'Nargo.toml') @@ -39,12 +39,12 @@ export class NoirPluginClient extends PluginClient { await this.call('fileManager', 'writeFile', 'Nargo.toml', DEFAULT_TOML_CONFIG) const fileBytes = new TextEncoder().encode(DEFAULT_TOML_CONFIG) - this.fm.writeFile('Nargo.toml', new Blob([fileBytes]).stream()) + await this.fm.writeFile('Nargo.toml', new Blob([fileBytes]).stream()) } else { const nargoToml = await this.call('fileManager', 'readFile', 'Nargo.toml') const fileBytes = new TextEncoder().encode(nargoToml) - this.fm.writeFile('Nargo.toml', new Blob([fileBytes]).stream()) + await this.fm.writeFile('Nargo.toml', new Blob([fileBytes]).stream()) } } @@ -54,9 +54,13 @@ export class NoirPluginClient extends PluginClient { this.emit('statusChanged', { key: 'loading', title: 'Compiling Noir Program...', type: 'info' }) // @ts-ignore this.call('terminal', 'log', { type: 'log', value: 'Compiling ' + path }) + await this.setupNargoToml() const program = await compile_program(this.fm, null, this.logFn.bind(this), this.debugFn.bind(this)) + const dir = extractParentFromKey(path) + const filename = extractNameFromKey(path) + const outputPath = `${dir}/build/${filename.replace('.nr', '.json')}` - this.call('fileManager', 'writeFile', path.replace('.nr', '.json'), JSON.stringify(program, null, 2)) + this.call('fileManager', 'writeFile', outputPath, JSON.stringify(program, null, 2)) this.internalEvents.emit('noir_compiling_done') this.emit('statusChanged', { key: 'succeed', title: 'Noir circuit compiled successfully', type: 'success' }) // @ts-ignore