Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions boxes/blank/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"copy-webpack-plugin": "^11.0.0",
"html-webpack-plugin": "^5.6.0",
"stream-browserify": "^3.0.0",
"ts-loader": "^9.5.1",
"tty-browserify": "^0.0.1",
"typescript": "^5.0.4",
"util": "^0.12.5",
Expand Down
2 changes: 1 addition & 1 deletion boxes/blank/src/contracts/target/blank-Blank.json
Comment thread
signorecello marked this conversation as resolved.
Outdated

Large diffs are not rendered by default.

91 changes: 89 additions & 2 deletions boxes/npx.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,26 @@ import pty from "node-pty";
import path from "path";
import os from "os";
import fs from "fs";
import { parse, stringify } from "@iarna/toml";
import chalk from "chalk";
import axios from "axios";

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

const { GITHUB_TOKEN } = process.env;

const axiosOpts = {};
if (GITHUB_TOKEN) {
axiosOpts.headers = { Authorization: `token ${GITHUB_TOKEN}` };
}

const { data } = await axios.get(
`https://api.github.com/repos/AztecProtocol/aztec-packages/releases`,
axiosOpts,
);
const version = data[0].tag_name.split("-v")[1];

function updatePathEnvVar() {
// Detect the user's shell profile file based on common shells and environment variables
const homeDir = os.homedir();
Expand Down Expand Up @@ -43,6 +58,70 @@ function updatePathEnvVar() {
info(`Added ${targetDir} to PATH in ${shellProfile}.`);
}

export function prettyPrintNargoToml(config) {
const withoutDependencies = Object.fromEntries(
Object.entries(config).filter(([key]) => key !== "dependencies"),
);

const partialToml = stringify(withoutDependencies);
const dependenciesToml = Object.entries(config.dependencies).map(
([name, dep]) => {
const depToml = stringify.value(dep);
return `${name} = ${depToml}`;
},
);

return (
partialToml + "\n[dependencies]\n" + dependenciesToml.join("\n") + "\n"
);
}

async function replacePaths(rootDir) {
const files = fs.readdirSync(path.resolve(".", rootDir), {
withFileTypes: true,
});

files.forEach((file) => {
const filePath = path.join(rootDir, file.name);
// console.log(filePath);
if (file.isDirectory()) {
replacePaths(filePath); // Recursively search subdirectories
} else if (file.name === "Nargo.toml") {
let content = parse(fs.readFileSync(filePath, "utf8"));

try {
Object.keys(content.dependencies).forEach((dep) => {
const directory = content.dependencies[dep].path.replace(
"../../../../",
"",
);
Comment thread
signorecello marked this conversation as resolved.
Outdated
content.dependencies[dep] = {
git: "https://github.com/AztecProtocol/aztec-packages/",
tag: `aztec-packages-v${version}`,
directory,
};
});
} catch (e) {
console.log("No Noir dependencies to update");
}

fs.writeFileSync(filePath, prettyPrintNargoToml(content), "utf8");
} else if (file.name === "package.json") {
try {
let content = JSON.parse(fs.readFileSync(filePath, "utf8"));
content.dependencies = {
...content.dependencies,
"@aztec/accounts": `${version}`,
"@aztec/aztec.js": `${version}`,
};
Comment thread
signorecello marked this conversation as resolved.
Outdated
fs.writeFileSync(filePath, JSON.stringify(content), "utf8");
} catch (e) {
console.log("No package.json to update");
}
}
});
}

program.action(async () => {
const appType = await select({
message: "Please choose your boilerplate:",
Expand All @@ -61,14 +140,22 @@ program.action(async () => {
default: "my-aztec-app",
});

const emitter = tiged(`AztecProtocol/aztec-packages/boxes/${appType}`);

chalk.blue("Cloning the boilerplate code...");
const emitter = tiged(
`AztecProtocol/aztec-packages/boxes/${appType}#aztec-packages-v${version}`,
{
disableCache: true,
verbose: true,
mode: "git",
},
);

emitter.on("info", (info) => {
log(info.message);
});

await emitter.clone(`./${appName}`).then(() => {
replacePaths(`./${appName}`);
log(chalk.bgGreen("Your code is ready!"));
});
} catch (error) {
Expand Down
8 changes: 5 additions & 3 deletions boxes/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "create-aztec-app",
"name": "create-aztec",
"packageManager": "yarn@4.1.0",
"version": "0.1.0",
"version": "0.1.1",
"type": "module",
"scripts": {
"compile": "yarn workspaces foreach -A -v run compile",
Expand All @@ -23,10 +23,12 @@
"@aztec/protocol-contracts": "portal:../yarn-project/protocol-contracts",
"@aztec/types": "portal:../yarn-project/types"
},
"devDependencies": {
"dependencies": {
"@iarna/toml": "^2.2.5",
"@inquirer/confirm": "^3.0.0",
"@inquirer/input": "^2.0.0",
"@inquirer/select": "^2.0.0",
"axios": "^1.6.7",
"chalk": "^5.3.0",
"commander": "^12.0.0",
"node-pty": "^1.0.0",
Expand Down
Loading