-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(compiler): add CompilerCli8 class
- Loading branch information
Showing
5 changed files
with
47 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { resolve } from 'path'; | ||
import CompilerCli, { getPackagePath } from './Cli'; | ||
|
||
/** | ||
* @category contract | ||
*/ | ||
export default class CompilerCli8 extends CompilerCli { | ||
/** | ||
* @param options - Options | ||
* @param options.ignoreVersion - Don't ensure that the compiler is supported | ||
*/ | ||
constructor( | ||
{ ignoreVersion }: { ignoreVersion?: boolean } = {}, | ||
) { | ||
super(resolve(getPackagePath(), './bin/aesophia_cli_8'), { ignoreVersion }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
export * from './index-browser'; | ||
|
||
export { default as CompilerCli } from './contract/compiler/Cli'; | ||
export { default as CompilerCli8 } from './contract/compiler/Cli8'; | ||
export { default as getFileSystem } from './contract/compiler/getFileSystem'; | ||
export { default as CompilerHttpNode } from './contract/compiler/HttpNode'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { createHash } from 'crypto'; | ||
import { dirname } from 'path'; | ||
import { writeFileSync, readFileSync, mkdirSync } from 'fs'; | ||
|
||
const path = './bin/aesophia_cli_8'; | ||
const hash = 'tZdsd7XH1e4C10MIzM0TY0IFcpkPBZqZMPdJ1ln9GDVsgjVCCK86YKCK5KtKqQzhNKSXaE01ZjAfTEYOSV7uIg=='; | ||
|
||
function ensureBinaryCorrect() { | ||
const buffer = readFileSync(path); | ||
const h = createHash('sha512').update(buffer).digest('base64'); | ||
if (h !== hash) throw new Error('Wrong hash'); | ||
} | ||
|
||
try { | ||
ensureBinaryCorrect(); | ||
} catch { | ||
console.log('Fetching aesophia_cli_8'); | ||
const request = await fetch( | ||
'https://github.com/aeternity/aesophia_cli/raw/df63ff9f4fdcfc437c90b90914fd1a7081d2bbbe/aesophia_cli', | ||
); | ||
const body = Buffer.from(await request.arrayBuffer()); | ||
mkdirSync(dirname(path), { recursive: true }); | ||
writeFileSync(path, body); | ||
ensureBinaryCorrect(); | ||
} |