Save noir program in build directory.

ioedeveloper 7 days ago
parent 8a38a2acdf
commit a96563ef4e
  1. 14
      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<void> {
async setupNargoToml(): Promise<void> {
// @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

Loading…
Cancel
Save