Skip to content

Commit be46b75

Browse files
committed
chore: some codespaces fixes, improved boxes, added badges
1 parent fa78607 commit be46b75

File tree

11 files changed

+190
-108
lines changed

11 files changed

+190
-108
lines changed

.devcontainer/assets/react_cta_badge.svg

Lines changed: 19 additions & 0 deletions
Loading

.devcontainer/assets/token_cta_badge.svg

Lines changed: 19 additions & 0 deletions
Loading

.devcontainer/assets/vanilla_cta_badge.svg

Lines changed: 19 additions & 0 deletions
Loading

.devcontainer/scripts/onCreateCommand.sh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,14 @@ if ! grep -q "PXE_URL" ~/.bashrc; then
1010
echo "export PXE_URL=https://\$CODESPACE_NAME-8080.preview.\$GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN" >> ~/.bashrc
1111
fi
1212

13+
if ! grep -q "alias sandbox" ~/.bashrc; then
14+
echo "alias sandbox=\"npx create-aztec-app sandbox\"" >> ~/.bashrc
15+
fi
16+
17+
source ~/.bashrc
1318
yes | npx create-aztec-app -t $TYPE -n $NAME -s
14-
mv react/* react/.* .
15-
rm -rf react
19+
mv $NAME/* $NAME/.* .
20+
rm -rf $NAME
1621

1722
yarn
1823

.devcontainer/scripts/postAttachCommand.sh

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ NAME=$2
55
apt install gh
66
gh codespace ports visibility 8080:public -c $CODESPACE_NAME
77

8-
(nohup /usr/local/bin/aztec sandbox &)
8+
npx create-aztec-app sandbox start
99

1010
r=$(tput sgr0) # Reset color
1111
bold=$(tput bold) # Bold text
@@ -52,14 +52,16 @@ echo "${bold}${b}██╔══██║ ███╔╝ ██║ ██
5252
echo "${bold}${p}██║ ██║███████╗ ██║ ███████╗╚██████╗${r}"
5353
echo "${bold}${y}╚═╝ ╚═╝╚══════╝ ╚═╝ ╚══════╝ ╚═════╝${r}"
5454
echo
55-
print_colored "${bold}Sandbox Codespace" "cyan"
5655
print_colored "${bold}Your codespace is ready with your chosen box! 🎉" "cyan"
56+
print_colored "You can now yarn dev or any other package.json script." "cyan"
5757
echo
58-
print_colored "All the packages are already installed, and you can now run yarn dev or any other package.json script." "magenta"
59-
print_colored "You can also use this codespace for its running sandbox, by connecting your local environment to it." "magenta"
58+
print_colored "Manage the running development network by running:" "magenta"
59+
print_colored "sandbox [start, stop, logs, etc]" "green"
60+
print_colored "example: \"sandbox logs\""
6061
echo
61-
print_colored "To do so, set the PXE_URL to this codespace's sandbox URL:" "magenta"
62+
print_colored "You can also connect your local environment to it." "magenta"
63+
print_colored "To do so, prepend your commands with this codespace's sandbox URL:" "magenta"
6264
print_colored "${PXE_URL}" "green"
63-
print_colored "ex. PXE_URL=\"${PXE_URL}\" yarn dev"
65+
print_colored "example: PXE_URL=\"${PXE_URL}\" yarn dev"
6466
echo
6567
print_colored "${bold}Enjoy your sandbox! 🏖️" "orange"

README.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ All the packages that make up [Aztec](https://docs.aztec.network).
66
- [**`yarn-project`**](/yarn-project): Typescript code for client and backend
77
- [**`docs`**](/docs): Documentation source for the docs site
88

9+
## Getting Started
10+
11+
Want to start quickly? Get started in minutes with a free Github Codespace.
12+
13+
[![One-Click React Starter](.devcontainer/assets/react_cta_badge.svg)](https://codespaces.new/AztecProtocol/aztec-packages?devcontainer_path=.devcontainer%2Freact%2Fdevcontainer.json) [![One-Click HTML/TS Starter](.devcontainer/assets/vanilla_cta_badge.svg)](https://codespaces.new/AztecProtocol/aztec-packages?devcontainer_path=.devcontainer%2Fvanilla%2Fdevcontainer.json) [![One-Click Token Starter](.devcontainer/assets/token_cta_badge.svg)](https://codespaces.new/AztecProtocol/aztec-packages?devcontainer_path=.devcontainer%2Ftoken%2Fdevcontainer.json)
14+
915
## Popular packages
1016

1117
- [Aztec.nr](./noir-projects/aztec-nr/): A [Noir](https://noir-lang.org) framework for smart contracts on Aztec.
@@ -70,17 +76,17 @@ Recovering if the sync is not happening with basic pull commands:
7076
- manually editing the parent variable in noir/noir-repo/.gitrepo: this is the parent of the last sync commit on aztec side. If you get errors with a commit not being found in the upstream repo, and the commit mentioned is not the commit variable above, it might indicate this is somehow incorrect. This can happen when commit content is ported without its history, e.g. squashes
7177
- use pull --force ONLY where you would use git reset. That is, if you really want to match some upstream noir for a purpose its fine, but you'll lose local changes (if any)
7278

73-
7479
## Earthly
7580

7681
Earthly is a reproducible build tool that aims to combine the functionality of Docker, Makefiles and BASH.
7782
Non-build earthly targets should start with 'test', 'run', or 'bench' as a general rule (but not hard rule) while builds can be nouns or start with build-.
7883
If something is a bundle of targets for CI, we can do e.g. build-ci, test-ci etc.
7984
See barretenberg/cpp/Earthfile for an example of a fairly involved Earthfile that can be used for inspiration.
80-
Earthly docs https://docs.earthly.dev/ are extensive and show the various build patterns.
85+
Earthly docs <https://docs.earthly.dev/> are extensive and show the various build patterns.
8186

8287
In a nutshell:
88+
8389
- Docker-like syntax defines all builds. We lean on docker heavily for when to rebuild and cache, and how to run in a reproducible manner.
8490
- It supports modularization of the build manifest into multiple directories that can be imported. Simple functions and conditional logic can be used.
8591
- We provide two modes, one for CI by passing --ci and one for local with incremental builds.
86-
- We do NOT provide a native execution story for anything but Linux and WASM currently.
92+
- We do NOT provide a native execution story for anything but Linux and WASM currently.

boxes/bin.js

Lines changed: 58 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,22 @@
22
import { Command, Option } from "commander";
33
const program = new Command();
44
import { chooseProject } from "./scripts/steps/chooseBox.js";
5-
import { sandboxRun } from "./scripts/steps/sandbox/run.js";
6-
import { sandboxInstallOrUpdate } from "./scripts/steps/sandbox/install.js";
5+
import {
6+
install,
7+
update,
8+
sandboxInstallOrUpdate,
9+
} from "./scripts/steps/sandbox/install.js";
710
import axios from "axios";
811
import pino from "pino";
912
import pretty from "pino-pretty";
1013
import ora from "ora";
1114
import { AZTEC_REPO } from "./scripts/config.js";
15+
import {
16+
start,
17+
stop,
18+
log,
19+
sandboxRunStep,
20+
} from "./scripts/steps/sandbox/run.js";
1221

1322
const getLatestStable = async () => {
1423
const { data } = await axios.get(
@@ -83,40 +92,52 @@ const init = async ({ debug, github_token, version }) => {
8392
global.spinner = ora({ color: "blue" });
8493
};
8594

86-
program.option("-d, --debug", "output extra debugging");
87-
program.option("-gh, --github_token <github_token>", "a github token");
88-
program.option("-v, --version <version>", "a version number or master tag");
89-
program.option("-s, --skip-sandbox", "install and run sandbox after cloning");
90-
91-
program.option(
92-
"-t, --project-type <projectType>",
93-
"the type of the project to clone ('app' or 'contract')",
94-
);
95-
program.option(
96-
"-n, --project-name <projectName>",
97-
"the name of the project to clone",
98-
);
99-
program.parse();
95+
const sandbox = program.command("sandbox");
96+
sandbox.description("Manage the Aztec Sandbox");
97+
sandbox.command("start").action(start);
98+
sandbox.command("logs").action(log);
99+
sandbox.command("stop").action(stop);
100+
sandbox.command("install").action(install);
101+
sandbox.command("update").action(update);
102+
103+
program
104+
.command("new", { isDefault: true })
105+
.description("An Aztec project with a built-in development network")
106+
.option("-d, --debug", "output extra debugging")
107+
.option("-gh, --github_token <github_token>", "a github token")
108+
.option("-v, --version <version>", "a version number or master tag")
109+
.option(
110+
"-s, --skip-sandbox",
111+
"skip sandbox installation and run after cloning",
112+
)
113+
.option(
114+
"-t, --project-type <projectType>",
115+
"the type of the project to clone ('app' or 'contract')",
116+
)
117+
.option(
118+
"-n, --project-name <projectName>",
119+
"the name of the project to clone",
120+
)
121+
.action(async (options) => {
122+
// this is some bad code, but it's def fun
123+
// I'm matching all keys started with project and
124+
// then using using modulo to say "if one is defined, two must be defined"
125+
const optsKeys = Object.keys(options).filter((e) => /project*/g.test(e));
126+
if (optsKeys.length % 2) {
127+
throw Error("You must define both the project type and the project name");
128+
}
129+
130+
const { projectType, projectName, skipSandbox } = options;
131+
// SETUP: Initialize global variables
132+
await init(options);
133+
// // STEP 1: Choose the boilerplate
134+
await chooseProject({ projectType, projectName });
135+
136+
if (skipSandbox) return;
137+
// // STEP 2: Install the Sandbox
138+
await sandboxInstallOrUpdate({ skipQuestion: skipSandbox });
139+
// STEP 3: Running the Sandbox
140+
await sandboxRunStep({ skipQuestion: skipSandbox });
141+
});
100142

101-
// this is some bad code, but it's def fun
102-
// I'm matching all keys started with project and
103-
// then using using modulo to say "if one is defined, two must be defined"
104-
const optsKeys = Object.keys(program.opts()).filter((e) => /project*/g.test(e));
105-
if (optsKeys.length % 2) {
106-
throw Error("You must define both the project type and the project name");
107-
}
108-
109-
program.action(async (options) => {
110-
const { projectType, projectName, skipSandbox } = options;
111-
// SETUP: Initialize global variables
112-
await init(options);
113-
// STEP 1: Choose the boilerplate
114-
await chooseProject({ projectType, projectName });
115-
116-
if (skipSandbox) return;
117-
// STEP 2: Install the Sandbox
118-
await sandboxInstallOrUpdate({ skipQuestion: skipSandbox });
119-
// STEP 3: Running the Sandbox
120-
await sandboxRun({ skipQuestion: skipSandbox });
121-
});
122143
program.parse();

boxes/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "create-aztec-app",
33
"packageManager": "yarn@4.1.0",
4-
"version": "0.3.16",
4+
"version": "0.4.2",
55
"type": "module",
66
"scripts": {
77
"compile": "yarn workspaces foreach -A -v run compile",
@@ -31,7 +31,6 @@
3131
"@inquirer/select": "^2.0.0",
3232
"axios": "^1.6.7",
3333
"commander": "^12.0.0",
34-
"node-pty": "^1.0.0",
3534
"ora": "^8.0.1",
3635
"pino": "^8.19.0",
3736
"pino-pretty": "^10.3.1",

boxes/scripts/steps/chooseBox.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,18 @@ import {
66
replacePaths,
77
clone,
88
} from "../utils.js";
9+
import { execSync } from "child_process";
910
import { getPlaceholders } from "../config.js";
1011

12+
async function initGit({ dir }) {
13+
execSync(`yes | git -C ${dir} init`);
14+
}
15+
1116
async function chooseAndCloneBox({ projectName }) {
17+
// if the user has already chosen a project name, we should skip the input
18+
// and use the one they've chosen
19+
const skipName = projectName || undefined;
20+
1221
const availableBoxes = await getAvailableBoxes();
1322
if (!projectName) {
1423
projectName = await select({
@@ -32,9 +41,11 @@ async function chooseAndCloneBox({ projectName }) {
3241
type: "box",
3342
tag,
3443
version,
35-
name: projectName,
44+
name: skipName,
3645
});
3746

47+
await initGit({ dir: rootDir });
48+
3849
await replacePaths({
3950
rootDir,
4051
tag,
@@ -46,7 +57,10 @@ async function chooseAndCloneBox({ projectName }) {
4657

4758
async function chooseAndCloneContract({ projectName }) {
4859
const availableContracts = await getAvailableContracts();
49-
// let user choose one of the contracts in noir-projects
60+
61+
// if the user has already chosen a project name, we should skip the input
62+
// and use the one they've chosen
63+
const skipName = projectName || undefined;
5064

5165
if (!projectName) {
5266
projectName = await select({
@@ -70,9 +84,11 @@ async function chooseAndCloneContract({ projectName }) {
7084
type: "contract",
7185
tag,
7286
version,
73-
name: projectName,
87+
name: skipName,
7488
});
7589

90+
await initGit({ dir: rootDir });
91+
7692
await replacePaths({
7793
rootDir,
7894
tag,

boxes/scripts/steps/sandbox/install.js

Lines changed: 9 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,14 @@
11
import confirm from "@inquirer/confirm";
22
import { execSync } from "child_process";
3-
import pty from "node-pty";
4-
import { updatePathEnvVar } from "../../utils.js";
53

6-
const runPty = async (command, { success: exitSuccess, error }) => {
7-
try {
8-
const ptySession = new Promise((resolve, reject) => {
9-
const ptyProcess = pty.spawn("bash", [], {
10-
name: "xterm-color",
11-
cols: 80,
12-
rows: 30,
13-
cwd: process.cwd(),
14-
env: process.env,
15-
});
16-
17-
ptyProcess.on("data", function (data) {
18-
process.stdout.write(data);
19-
});
20-
21-
ptyProcess.write(command);
22-
23-
ptyProcess.on("exit", async function (exitCode, signal) {
24-
await updatePathEnvVar();
25-
resolve();
26-
if (exitCode === 0) {
27-
success(exitSuccess);
28-
} else {
29-
error(e);
30-
}
31-
});
32-
});
33-
34-
await ptySession;
35-
} catch (e) {
36-
error(e);
37-
}
38-
};
4+
export async function install() {
5+
execSync(
6+
"curl -s install.aztec.network | NON_INTERACTIVE=1 BIN_PATH=$HOME/.aztec/bin bash -s",
7+
);
8+
}
399

40-
async function installSandbox() {
41-
await runPty("yes | bash -i <(curl -s install.aztec.network); exit\n", {
42-
success: "The Sandbox is installed!",
43-
error:
44-
"Failed to install the Sandbox. Please visit the docs at https://docs.aztec.network",
45-
});
10+
export async function update() {
11+
execSync("$HOME/.aztec/bin/aztec-up", { stdio: "inherit" });
4612
}
4713

4814
function findOutUserVersion() {
@@ -106,7 +72,7 @@ export async function sandboxInstallOrUpdate() {
10672
default: true,
10773
});
10874
if (answer) {
109-
await installSandbox();
75+
await install();
11076
}
11177
} else if (
11278
// Another situation is where the sandbox matches the stable version (i.e. 0.24.0) or master
@@ -141,7 +107,7 @@ export async function sandboxInstallOrUpdate() {
141107

142108
if (answer) {
143109
// again abusing the fact that the user has VERSION in the path
144-
execSync(`$HOME/.aztec/bin/aztec-up`, { stdio: "inherit" });
110+
update();
145111
}
146112
}
147113
}

0 commit comments

Comments
 (0)