MCPcopy Create free account
hub / github.com/CashScript/cashscript / compile

Function compile

examples/testing-suite/tasks/compile.ts:6–31  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

4import { URL } from 'url';
5
6export 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
33compile();

Callers 1

compile.tsFile · 0.85

Calls 2

compileStringFunction · 0.90
formatArtifactFunction · 0.90

Tested by

no test coverage detected