Skip to content

Commit 1273f3f

Browse files
authored
Merge pull request #89 from AztecProtocol/zpedro/0.34.0
feat: goodbye noir-starter, hello noirenberg
2 parents 64e1339 + b4ca59b commit 1273f3f

File tree

9 files changed

+207
-494
lines changed

9 files changed

+207
-494
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ package-lock.json
66

77
# To use with nektos/act
88
.github/event.json
9+
npx.js
10+
bin/*.js

bin/shell.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { execSync } from 'child_process';
2+
import logSymbols from 'log-symbols';
3+
import ora from 'ora';
4+
5+
export function sourceShellConfig() {
6+
const shell = execSync('echo $SHELL', { encoding: 'utf-8' }).trim();
7+
8+
if (shell.includes('bash')) {
9+
execSync('source ~/.bashrc', { stdio: 'inherit' });
10+
} else if (shell.includes('zsh')) {
11+
execSync(`zsh -c "source ~/.zshrc"`, { stdio: 'inherit' });
12+
} else if (shell.includes('fish')) {
13+
execSync(`fish -c "source ~/.config/fish/config.fish"`, { stdio: 'inherit' });
14+
} else {
15+
throw new Error('Unsupported shell environment');
16+
}
17+
}
18+
19+
export function exec(cmd: string, options = {}) {
20+
return execSync(cmd, {
21+
encoding: 'utf-8',
22+
stdio: 'pipe',
23+
...options,
24+
});
25+
}
26+
const spinner = ora({ color: 'blue', discardStdin: false });
27+
28+
export function installInstallers() {
29+
try {
30+
exec('which noirup', { stdio: 'ignore' });
31+
spinner.succeed('noirup is already installed');
32+
} catch {
33+
spinner.start('Installing noirup');
34+
exec('curl -L https://raw.githubusercontent.com/noir-lang/noirup/main/install | bash');
35+
spinner.stopAndPersist({ symbol: logSymbols.success });
36+
}
37+
try {
38+
exec('which bbup', { stdio: 'ignore' });
39+
spinner.succeed('bbup is already installed');
40+
} catch {
41+
spinner.start('Installing bbup');
42+
exec(
43+
'curl -L https://raw.githubusercontent.com/AztecProtocol/aztec-packages/master/barretenberg/cpp/installation/install | bash',
44+
);
45+
spinner.stopAndPersist({ symbol: logSymbols.success });
46+
}
47+
sourceShellConfig();
48+
}

bin/versions.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import axios from 'axios';
2+
3+
export async function getBbVersion(noirVersion: string) {
4+
const url = `https://raw.githubusercontent.com/noir-lang/noir/v${noirVersion}/scripts/install_bb.sh`;
5+
6+
try {
7+
const { data } = await axios.get(url);
8+
const versionMatch = data.match(/VERSION="([\d.]+)"/);
9+
const version = versionMatch ? versionMatch[1] : null;
10+
11+
return version;
12+
} catch (e) {
13+
throw new Error(e);
14+
}
15+
}

bun.lockb

34.9 KB
Binary file not shown.

install

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# Function to check if a command exists
6+
command_exists() {
7+
command -v "$1" >/dev/null 2>&1
8+
}
9+
10+
# Function to install NVM and Node.js
11+
install_nvm_and_node() {
12+
echo "Installing NVM..."
13+
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
14+
15+
# Load NVM
16+
export NVM_DIR="$HOME/.nvm"
17+
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
18+
19+
# Install the latest LTS version of Node.js
20+
echo "Installing the latest LTS version of Node.js..."
21+
nvm install --lts
22+
23+
# Use the installed version
24+
nvm use --lts
25+
26+
# Verify installation
27+
node --version
28+
npm --version
29+
}
30+
31+
# Check if NVM is installed
32+
if ! command_exists nvm; then
33+
install_nvm_and_node
34+
fi
35+
36+
37+
# Install noirenberg globally
38+
echo "Installing noirenberg..."
39+
npm install -g noirenberg
40+
41+
echo "Installation complete. You can now use the 'noirenberg' command."
42+
echo "Please restart your terminal or run 'source ~/.bashrc' (or your shell's equivalent) to start using noirenberg."

npx.js

Lines changed: 0 additions & 39 deletions
This file was deleted.

npx.ts

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#!/usr/bin/env node
2+
import { Command, Option } from 'commander';
3+
import select from '@inquirer/select';
4+
import input from '@inquirer/input';
5+
import shelljs from 'shelljs';
6+
const program = new Command();
7+
import tiged from 'tiged';
8+
import { sourceShellConfig, exec, installInstallers } from './bin/shell.js';
9+
import ora from 'ora';
10+
import logSymbols from 'log-symbols';
11+
import { getBbVersion } from './bin/versions.js';
12+
import { execSync } from 'child_process';
13+
14+
const spinner = ora({ color: 'blue', discardStdin: false });
15+
16+
program
17+
.command('install', { isDefault: true })
18+
.description('Installs compatible versions of Noir and Barretenberg.')
19+
.addOption(
20+
new Option(
21+
'-n --nightly',
22+
'Install the nightly version of Noir and the compatible version of Barretenberg',
23+
).conflicts('version'),
24+
)
25+
.option(
26+
'-v, --version <version>',
27+
'Install a specific version of Noir and the compatible version of Barretenberg',
28+
)
29+
.hook('preAction', () => {
30+
installInstallers();
31+
})
32+
.action(async ({ nightly, version }) => {
33+
try {
34+
spinner.start(
35+
`Installing nargo ${nightly ? 'nightly' : version ? `version ${version}` : 'stable'}`,
36+
);
37+
exec(`noirup ${nightly ? '-n' : version ? `-v ${version}` : ''}`);
38+
sourceShellConfig();
39+
const output = exec('nargo --version');
40+
const nargoVersion = output.match(/nargo version = (\d+\.\d+\.\d+)/)!;
41+
spinner.succeed(`Installed nargo version ${nargoVersion[1]}`);
42+
43+
spinner.start(`Getting compatible barretenberg version`);
44+
const compatibleVersion = await getBbVersion(nargoVersion[1]);
45+
exec(`bbup -v ${compatibleVersion}`);
46+
const bbVersion = exec('bb --version');
47+
spinner.text = `Installed barretenberg version ${bbVersion}`;
48+
spinner.succeed();
49+
} catch (error) {
50+
spinner.fail(`Error installing Noir and Barretenberg`);
51+
throw error;
52+
}
53+
});
54+
55+
program
56+
.command('new')
57+
.description('Bootstraps a ready-to-go Noir project with Noir and Barretenberg')
58+
.option('-v, --verbose', 'Show verbose output')
59+
.option('-f, --force', 'Force overwriting existing files')
60+
.action(async ({ verbose, force }) => {
61+
const appType = await select({
62+
message: 'Please choose an option:',
63+
choices: [
64+
{ value: 'vite-hardhat', name: 'Browser App using Vite' },
65+
{ value: 'with-foundry', name: 'Solidity App using Foundry' },
66+
],
67+
});
68+
69+
const appName = await input({
70+
message: 'Your app name:',
71+
default: 'my-noir-app',
72+
});
73+
74+
spinner.start(`Bootstrapping ${appType}`);
75+
const emitter = tiged(`noir-lang/noir-starter/${appType}`, {
76+
disableCache: true,
77+
force,
78+
verbose,
79+
});
80+
81+
emitter.on('info', info => {
82+
verbose && spinner.info(info.message);
83+
});
84+
85+
emitter.clone(`./${appName}`).then(() => {
86+
spinner.succeed(`Bootstrapped ${appType} at ${appName}`);
87+
});
88+
});
89+
90+
program.parse();

package.json

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
11
{
2-
"name": "create-noir",
2+
"name": "noirenberg",
33
"version": "0.1.1",
44
"type": "module",
5-
"description": "This is a reference repo to help you get started with writing zero-knowledge circuits with [Noir](https://noir-lang.org/).",
5+
"description": "This repo contains starter projects using Noir and Barretenberg, together with a CLI tool to help you get started.",
66
"bin": "npx.js",
77
"author": "",
88
"license": "ISC",
9+
"scripts": {
10+
"start": "bunx tsx npx.ts",
11+
"compile": "tsc npx.ts --esModuleInterop true --module nodenext && chmod +x npx.js",
12+
"publish": "bun compile && npm publish"
13+
},
914
"dependencies": {
1015
"@inquirer/input": "^1.2.16",
1116
"@inquirer/select": "^1.3.3",
17+
"axios": "^1.7.7",
1218
"commander": "^11.1.0",
19+
"log-symbols": "^7.0.0",
20+
"ora": "^8.1.0",
1321
"tiged": "^2.12.6"
1422
}
1523
}

0 commit comments

Comments
 (0)