Skip to content

Commit

Permalink
script now dynamically fetches boxes from the specificed tag
Browse files Browse the repository at this point in the history
  • Loading branch information
signorecello committed Mar 4, 2024
1 parent 27b409d commit b650025
Show file tree
Hide file tree
Showing 41 changed files with 70 additions and 22 deletions.
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ jobs:
- *setup_env
- run:
name: "Test"
command: cond_spot_run_compose boxes 4 ./docker-compose.yml BOX=box-vanilla
command: cond_spot_run_compose boxes 4 ./docker-compose.yml BOX=vanilla
aztec_manifest_key: boxes

boxes-react:
Expand All @@ -588,7 +588,7 @@ jobs:
- *setup_env
- run:
name: "Test"
command: cond_spot_run_compose boxes 4 ./docker-compose.yml BOX=box-react
command: cond_spot_run_compose boxes 4 ./docker-compose.yml BOX=react
aztec_manifest_key: boxes

end-to-end:
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 2 additions & 1 deletion boxes/react/package.json → boxes/boxes/react/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "@aztec/box-react",
"name": "@aztec/react",
"description": "React App",
"private": true,
"version": "0.1.0",
"type": "module",
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "@aztec/box-vanilla",
"name": "@aztec/vanilla",
"description": "Vanilla HTML/JS App",
"private": true,
"version": "0.1.0",
"type": "module",
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion boxes/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ services:
ETHEREUM_HOST: http://ethereum:8545
CHAIN_ID: 31337
PXE_URL: http://aztec:8080
BOX: ${BOX:-box-vanilla}
BOX: ${BOX:-vanilla}
5 changes: 2 additions & 3 deletions boxes/package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
{
"name": "create-aztec-app",
"packageManager": "[email protected]",
"version": "0.2.2",
"version": "0.2.3",
"type": "module",
"scripts": {
"compile": "yarn workspaces foreach -A -v run compile",
"build": "yarn workspaces foreach -A -v run build",
"publish": "yarn npm publish"
},
"workspaces": [
"react",
"vanilla-js"
"boxes/*"
],
"bin": "VERSION=${VERSION:+} bin.js",
"resolutions": {
Expand Down
14 changes: 7 additions & 7 deletions boxes/scripts/steps/chooseBox.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import select from "@inquirer/select";
import input from "@inquirer/input";
import tiged from "tiged";
import { replacePaths } from "../utils.js";
import { getAvailableBoxes, replacePaths } from "../utils.js";
import chalk from "chalk";
import axios from "axios";
const { log } = console;

export async function chooseAndCloneBox(tag, version) {
const availableBoxes = await getAvailableBoxes(tag, version);
const appType = await select({
message: "Please choose your Aztec boilerplate:",
choices: [
{ value: "vanilla-js", name: "HTML/TS project" },
{ value: "react", name: "React project" },
{ value: "skip", name: "Skip this step" },
],
message: `Please choose your Aztec boilerplate:`,
choices: availableBoxes.map((box) => {
return { value: box.name, name: box.description };
}),
});

if (appType === "skip") return;
Expand Down
16 changes: 11 additions & 5 deletions boxes/scripts/steps/sandbox/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,17 @@ export async function sandboxInstallOrUpdate(stable, version) {
sandboxVersion !== version &&
!["latest", "master"].includes(version)
) {
log(
chalk.bgYellow(
`The sandbox is version ${sandboxVersion} but the boilerplate is version ${version}. Things may not work as expected. You should manually update versions in package.json and Nargo.toml`,
),
);
const answer = await confirm({
message: `The sandbox is version ${sandboxVersion} but your chosen version is ${version}. Do you want to install version ${version}?`,
default: true,
});

if (answer) {
execSync(
`${["latest", "master"].includes(version) ? "VERSION=master" : ""} $HOME/.aztec/bin/aztec-up`,
{ stdio: "inherit" },
);
}
} else if (sandboxVersion !== stable) {
const answer = await confirm({
message: `The Sandbox is not up to date. Do you want to update it to ${stable}?`,
Expand Down
45 changes: 43 additions & 2 deletions boxes/scripts/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,54 @@ import path from "path";
import os from "os";
import fs from "fs";
import { parse, stringify } from "@iarna/toml";
import axios from "axios";

const { log, warn, info } = console;
const targetDir = path.join(os.homedir(), ".aztec/bin"); // Use os.homedir() to get $HOME

export async function getAvailableBoxes(tag, version) {
const { GITHUB_TOKEN } = process.env;
const axiosOpts = {};
if (GITHUB_TOKEN) {
axiosOpts.headers = { Authorization: `token ${GITHUB_TOKEN}` };
}

// TODO: Remove this try catch. Boxes are currently in "boxes" but from this PR on, they will be in "boxes/boxes"
let data;
try {
({ data } = await axios.get(
`https://api.github.com/repos/AztecProtocol/aztec-packages/contents/boxes/boxes?ref=${tag}`,
axiosOpts,
));
} catch (e) {
if (e.response.statusText === "Not Found") {
({ data } = await axios.get(
`https://api.github.com/repos/AztecProtocol/aztec-packages/contents/boxes?ref=${tag}`,
axiosOpts,
));
}
}

let availableBoxes = data
.filter(
(content) => content.type === "dir" && !content.name.startsWith("."),
)
.map(async ({ path, name }) => {
({ data } = await axios.get(
`https://raw.githubusercontent.com/AztecProtocol/aztec-packages/${["latest", "master"].includes(tag) ? "master" : tag}/${path}/package.json`,
axiosOpts,
));

return {
name,
description: data.description || name,
};
});

return await Promise.all(availableBoxes);
}

export function prettyPrintNargoToml(config) {
console.log(config);
const withoutDependencies = Object.fromEntries(
Object.entries(config).filter(([key]) => key !== "dependencies"),
);
Expand Down Expand Up @@ -59,7 +101,6 @@ export async function replacePaths(rootDir, tag, version) {
});

files.forEach((file) => {
console.log(file);
const filePath = path.join(rootDir, file.name);
if (file.isDirectory()) {
replacePaths(filePath, tag, version); // Recursively search subdirectories
Expand Down

0 comments on commit b650025

Please sign in to comment.