()
| 4 | import { URL } from 'url'; |
| 5 | |
| 6 | export const compile = (): void => { |
| 7 | const directory = new URL('../contracts', import.meta.url); |
| 8 | const result = fs.readdirSync(directory) |
| 9 | .filter((fn) => fn.endsWith('.cash')); |
| 10 | |
| 11 | fs.mkdirSync(new URL('../artifacts', import.meta.url), { recursive: true }); |
| 12 | |
| 13 | result.forEach((fn) => { |
| 14 | const contractFile = new URL(fn, `${directory}/`); |
| 15 | const jsonOutputFile = new URL(`../artifacts/${fn.replace('.cash', '.json')}`, import.meta.url); |
| 16 | const tsOutputFile = new URL(`../artifacts/${fn.replace('.cash', '.artifact.ts')}`, import.meta.url); |
| 17 | |
| 18 | try { |
| 19 | const contents = fs.readFileSync(contractFile, { encoding: 'utf-8' }); |
| 20 | const artifact = compileString(contents); |
| 21 | |
| 22 | fs.writeFileSync(jsonOutputFile, formatArtifact(artifact, 'json')); |
| 23 | fs.writeFileSync(tsOutputFile, formatArtifact(artifact, 'ts')); |
| 24 | } catch (error: any) { |
| 25 | console.error(`Error compiling ${fn}: ${error.message}`); |
| 26 | return; |
| 27 | } |
| 28 | |
| 29 | console.log(`Successfully compiled ${fn}`); |
| 30 | }); |
| 31 | }; |
| 32 | |
| 33 | compile(); |
no test coverage detected