From 2302f00cc76512257e0b461982caef10817ffe4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Pedro=20Sousa?= Date: Thu, 29 Feb 2024 14:24:49 +0000 Subject: [PATCH] script now dynamically fetches boxes from the specificed tag --- .circleci/config.yml | 4 +- boxes/{ => boxes}/react/.eslintrc.cjs | 0 boxes/{ => boxes}/react/.gitignore | 0 boxes/{ => boxes}/react/.prettierignore | 0 boxes/{ => boxes}/react/.prettierrc.json | 0 boxes/{ => boxes}/react/README.md | 0 boxes/{ => boxes}/react/index.html | 0 boxes/{ => boxes}/react/package.json | 3 +- boxes/{ => boxes}/react/playwright.config.ts | 0 boxes/{ => boxes}/react/src/config.ts | 0 .../react/src/contracts/Nargo.toml | 0 .../react/src/contracts/src/main.nr | 0 .../react/src/hooks/useContract.tsx | 0 .../{ => boxes}/react/src/hooks/useNumber.tsx | 0 boxes/{ => boxes}/react/src/index.tsx | 0 .../{ => boxes}/react/src/pages/contract.tsx | 0 boxes/{ => boxes}/react/src/pages/home.tsx | 0 boxes/{ => boxes}/react/tests/browser.spec.ts | 0 boxes/{ => boxes}/react/tests/node.test.ts | 0 boxes/{ => boxes}/react/tsconfig.json | 0 boxes/{ => boxes}/react/webpack.config.js | 0 .../vanilla}/.eslintrc.cjs | 0 .../{vanilla-js => boxes/vanilla}/.gitignore | 0 .../vanilla}/.prettierignore | 0 .../vanilla}/.prettierrc.json | 0 boxes/{vanilla-js => boxes/vanilla}/README.md | 0 .../vanilla}/package.json | 3 +- .../vanilla}/playwright.config.ts | 0 .../vanilla}/src/config.ts | 0 .../vanilla}/src/contracts/Nargo.toml | 0 .../vanilla}/src/contracts/src/main.nr | 0 .../vanilla}/src/index.html | 0 .../vanilla}/src/index.ts | 0 .../vanilla}/tests/browser.spec.ts | 0 .../vanilla}/tsconfig.json | 0 .../vanilla}/webpack.config.js | 0 boxes/docker-compose.yml | 2 +- boxes/package.json | 3 +- boxes/scripts/steps/chooseBox.js | 14 +++--- boxes/scripts/steps/sandbox/install.js | 16 ++++--- boxes/scripts/utils.js | 45 ++++++++++++++++++- 41 files changed, 69 insertions(+), 21 deletions(-) rename boxes/{ => boxes}/react/.eslintrc.cjs (100%) rename boxes/{ => boxes}/react/.gitignore (100%) rename boxes/{ => boxes}/react/.prettierignore (100%) rename boxes/{ => boxes}/react/.prettierrc.json (100%) rename boxes/{ => boxes}/react/README.md (100%) rename boxes/{ => boxes}/react/index.html (100%) rename boxes/{ => boxes}/react/package.json (98%) rename boxes/{ => boxes}/react/playwright.config.ts (100%) rename boxes/{ => boxes}/react/src/config.ts (100%) rename boxes/{ => boxes}/react/src/contracts/Nargo.toml (100%) rename boxes/{ => boxes}/react/src/contracts/src/main.nr (100%) rename boxes/{ => boxes}/react/src/hooks/useContract.tsx (100%) rename boxes/{ => boxes}/react/src/hooks/useNumber.tsx (100%) rename boxes/{ => boxes}/react/src/index.tsx (100%) rename boxes/{ => boxes}/react/src/pages/contract.tsx (100%) rename boxes/{ => boxes}/react/src/pages/home.tsx (100%) rename boxes/{ => boxes}/react/tests/browser.spec.ts (100%) rename boxes/{ => boxes}/react/tests/node.test.ts (100%) rename boxes/{ => boxes}/react/tsconfig.json (100%) rename boxes/{ => boxes}/react/webpack.config.js (100%) rename boxes/{vanilla-js => boxes/vanilla}/.eslintrc.cjs (100%) rename boxes/{vanilla-js => boxes/vanilla}/.gitignore (100%) rename boxes/{vanilla-js => boxes/vanilla}/.prettierignore (100%) rename boxes/{vanilla-js => boxes/vanilla}/.prettierrc.json (100%) rename boxes/{vanilla-js => boxes/vanilla}/README.md (100%) rename boxes/{vanilla-js => boxes/vanilla}/package.json (94%) rename boxes/{vanilla-js => boxes/vanilla}/playwright.config.ts (100%) rename boxes/{vanilla-js => boxes/vanilla}/src/config.ts (100%) rename boxes/{vanilla-js => boxes/vanilla}/src/contracts/Nargo.toml (100%) rename boxes/{vanilla-js => boxes/vanilla}/src/contracts/src/main.nr (100%) rename boxes/{vanilla-js => boxes/vanilla}/src/index.html (100%) rename boxes/{vanilla-js => boxes/vanilla}/src/index.ts (100%) rename boxes/{vanilla-js => boxes/vanilla}/tests/browser.spec.ts (100%) rename boxes/{vanilla-js => boxes/vanilla}/tsconfig.json (100%) rename boxes/{vanilla-js => boxes/vanilla}/webpack.config.js (100%) diff --git a/.circleci/config.yml b/.circleci/config.yml index dc87d950ce72..8a6c26ef9556 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -552,7 +552,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: @@ -564,7 +564,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: diff --git a/boxes/react/.eslintrc.cjs b/boxes/boxes/react/.eslintrc.cjs similarity index 100% rename from boxes/react/.eslintrc.cjs rename to boxes/boxes/react/.eslintrc.cjs diff --git a/boxes/react/.gitignore b/boxes/boxes/react/.gitignore similarity index 100% rename from boxes/react/.gitignore rename to boxes/boxes/react/.gitignore diff --git a/boxes/react/.prettierignore b/boxes/boxes/react/.prettierignore similarity index 100% rename from boxes/react/.prettierignore rename to boxes/boxes/react/.prettierignore diff --git a/boxes/react/.prettierrc.json b/boxes/boxes/react/.prettierrc.json similarity index 100% rename from boxes/react/.prettierrc.json rename to boxes/boxes/react/.prettierrc.json diff --git a/boxes/react/README.md b/boxes/boxes/react/README.md similarity index 100% rename from boxes/react/README.md rename to boxes/boxes/react/README.md diff --git a/boxes/react/index.html b/boxes/boxes/react/index.html similarity index 100% rename from boxes/react/index.html rename to boxes/boxes/react/index.html diff --git a/boxes/react/package.json b/boxes/boxes/react/package.json similarity index 98% rename from boxes/react/package.json rename to boxes/boxes/react/package.json index e574eab8ba61..2292213f5607 100644 --- a/boxes/react/package.json +++ b/boxes/boxes/react/package.json @@ -1,5 +1,6 @@ { - "name": "@aztec/box-react", + "name": "@aztec/react", + "description": "React App", "private": true, "version": "0.1.0", "type": "module", diff --git a/boxes/react/playwright.config.ts b/boxes/boxes/react/playwright.config.ts similarity index 100% rename from boxes/react/playwright.config.ts rename to boxes/boxes/react/playwright.config.ts diff --git a/boxes/react/src/config.ts b/boxes/boxes/react/src/config.ts similarity index 100% rename from boxes/react/src/config.ts rename to boxes/boxes/react/src/config.ts diff --git a/boxes/react/src/contracts/Nargo.toml b/boxes/boxes/react/src/contracts/Nargo.toml similarity index 100% rename from boxes/react/src/contracts/Nargo.toml rename to boxes/boxes/react/src/contracts/Nargo.toml diff --git a/boxes/react/src/contracts/src/main.nr b/boxes/boxes/react/src/contracts/src/main.nr similarity index 100% rename from boxes/react/src/contracts/src/main.nr rename to boxes/boxes/react/src/contracts/src/main.nr diff --git a/boxes/react/src/hooks/useContract.tsx b/boxes/boxes/react/src/hooks/useContract.tsx similarity index 100% rename from boxes/react/src/hooks/useContract.tsx rename to boxes/boxes/react/src/hooks/useContract.tsx diff --git a/boxes/react/src/hooks/useNumber.tsx b/boxes/boxes/react/src/hooks/useNumber.tsx similarity index 100% rename from boxes/react/src/hooks/useNumber.tsx rename to boxes/boxes/react/src/hooks/useNumber.tsx diff --git a/boxes/react/src/index.tsx b/boxes/boxes/react/src/index.tsx similarity index 100% rename from boxes/react/src/index.tsx rename to boxes/boxes/react/src/index.tsx diff --git a/boxes/react/src/pages/contract.tsx b/boxes/boxes/react/src/pages/contract.tsx similarity index 100% rename from boxes/react/src/pages/contract.tsx rename to boxes/boxes/react/src/pages/contract.tsx diff --git a/boxes/react/src/pages/home.tsx b/boxes/boxes/react/src/pages/home.tsx similarity index 100% rename from boxes/react/src/pages/home.tsx rename to boxes/boxes/react/src/pages/home.tsx diff --git a/boxes/react/tests/browser.spec.ts b/boxes/boxes/react/tests/browser.spec.ts similarity index 100% rename from boxes/react/tests/browser.spec.ts rename to boxes/boxes/react/tests/browser.spec.ts diff --git a/boxes/react/tests/node.test.ts b/boxes/boxes/react/tests/node.test.ts similarity index 100% rename from boxes/react/tests/node.test.ts rename to boxes/boxes/react/tests/node.test.ts diff --git a/boxes/react/tsconfig.json b/boxes/boxes/react/tsconfig.json similarity index 100% rename from boxes/react/tsconfig.json rename to boxes/boxes/react/tsconfig.json diff --git a/boxes/react/webpack.config.js b/boxes/boxes/react/webpack.config.js similarity index 100% rename from boxes/react/webpack.config.js rename to boxes/boxes/react/webpack.config.js diff --git a/boxes/vanilla-js/.eslintrc.cjs b/boxes/boxes/vanilla/.eslintrc.cjs similarity index 100% rename from boxes/vanilla-js/.eslintrc.cjs rename to boxes/boxes/vanilla/.eslintrc.cjs diff --git a/boxes/vanilla-js/.gitignore b/boxes/boxes/vanilla/.gitignore similarity index 100% rename from boxes/vanilla-js/.gitignore rename to boxes/boxes/vanilla/.gitignore diff --git a/boxes/vanilla-js/.prettierignore b/boxes/boxes/vanilla/.prettierignore similarity index 100% rename from boxes/vanilla-js/.prettierignore rename to boxes/boxes/vanilla/.prettierignore diff --git a/boxes/vanilla-js/.prettierrc.json b/boxes/boxes/vanilla/.prettierrc.json similarity index 100% rename from boxes/vanilla-js/.prettierrc.json rename to boxes/boxes/vanilla/.prettierrc.json diff --git a/boxes/vanilla-js/README.md b/boxes/boxes/vanilla/README.md similarity index 100% rename from boxes/vanilla-js/README.md rename to boxes/boxes/vanilla/README.md diff --git a/boxes/vanilla-js/package.json b/boxes/boxes/vanilla/package.json similarity index 94% rename from boxes/vanilla-js/package.json rename to boxes/boxes/vanilla/package.json index c2ef87596a40..535661825ca5 100644 --- a/boxes/vanilla-js/package.json +++ b/boxes/boxes/vanilla/package.json @@ -1,5 +1,6 @@ { - "name": "@aztec/box-vanilla", + "name": "@aztec/vanilla", + "description": "Vanilla HTML/JS App", "private": true, "version": "0.1.0", "type": "module", diff --git a/boxes/vanilla-js/playwright.config.ts b/boxes/boxes/vanilla/playwright.config.ts similarity index 100% rename from boxes/vanilla-js/playwright.config.ts rename to boxes/boxes/vanilla/playwright.config.ts diff --git a/boxes/vanilla-js/src/config.ts b/boxes/boxes/vanilla/src/config.ts similarity index 100% rename from boxes/vanilla-js/src/config.ts rename to boxes/boxes/vanilla/src/config.ts diff --git a/boxes/vanilla-js/src/contracts/Nargo.toml b/boxes/boxes/vanilla/src/contracts/Nargo.toml similarity index 100% rename from boxes/vanilla-js/src/contracts/Nargo.toml rename to boxes/boxes/vanilla/src/contracts/Nargo.toml diff --git a/boxes/vanilla-js/src/contracts/src/main.nr b/boxes/boxes/vanilla/src/contracts/src/main.nr similarity index 100% rename from boxes/vanilla-js/src/contracts/src/main.nr rename to boxes/boxes/vanilla/src/contracts/src/main.nr diff --git a/boxes/vanilla-js/src/index.html b/boxes/boxes/vanilla/src/index.html similarity index 100% rename from boxes/vanilla-js/src/index.html rename to boxes/boxes/vanilla/src/index.html diff --git a/boxes/vanilla-js/src/index.ts b/boxes/boxes/vanilla/src/index.ts similarity index 100% rename from boxes/vanilla-js/src/index.ts rename to boxes/boxes/vanilla/src/index.ts diff --git a/boxes/vanilla-js/tests/browser.spec.ts b/boxes/boxes/vanilla/tests/browser.spec.ts similarity index 100% rename from boxes/vanilla-js/tests/browser.spec.ts rename to boxes/boxes/vanilla/tests/browser.spec.ts diff --git a/boxes/vanilla-js/tsconfig.json b/boxes/boxes/vanilla/tsconfig.json similarity index 100% rename from boxes/vanilla-js/tsconfig.json rename to boxes/boxes/vanilla/tsconfig.json diff --git a/boxes/vanilla-js/webpack.config.js b/boxes/boxes/vanilla/webpack.config.js similarity index 100% rename from boxes/vanilla-js/webpack.config.js rename to boxes/boxes/vanilla/webpack.config.js diff --git a/boxes/docker-compose.yml b/boxes/docker-compose.yml index 73b72d71195b..76aaa91338bd 100644 --- a/boxes/docker-compose.yml +++ b/boxes/docker-compose.yml @@ -33,4 +33,4 @@ services: ETHEREUM_HOST: http://ethereum:8545 CHAIN_ID: 31337 PXE_URL: http://aztec:8080 - BOX: ${BOX:-box-vanilla} + BOX: ${BOX:-vanilla} diff --git a/boxes/package.json b/boxes/package.json index 18ccb377c1d2..900f56fc2f5b 100644 --- a/boxes/package.json +++ b/boxes/package.json @@ -9,8 +9,7 @@ "publish": "yarn npm publish" }, "workspaces": [ - "react", - "vanilla-js" + "boxes/*" ], "bin": "VERSION=${VERSION:+} bin.js", "resolutions": { diff --git a/boxes/scripts/steps/chooseBox.js b/boxes/scripts/steps/chooseBox.js index 6cc63e4ffa85..31644542df1d 100644 --- a/boxes/scripts/steps/chooseBox.js +++ b/boxes/scripts/steps/chooseBox.js @@ -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; diff --git a/boxes/scripts/steps/sandbox/install.js b/boxes/scripts/steps/sandbox/install.js index abfc74f84b0f..83af3d5a02d3 100644 --- a/boxes/scripts/steps/sandbox/install.js +++ b/boxes/scripts/steps/sandbox/install.js @@ -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}?`, diff --git a/boxes/scripts/utils.js b/boxes/scripts/utils.js index a54179d0db18..c15b1a8aef3e 100644 --- a/boxes/scripts/utils.js +++ b/boxes/scripts/utils.js @@ -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"), ); @@ -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