From c4380d3dc0ff4c88b9f8abc324fbdfad5aa1cf08 Mon Sep 17 00:00:00 2001 From: Leila Wang Date: Mon, 18 Sep 2023 17:28:59 +0000 Subject: [PATCH] Fix compile script. --- .../private-token/src/contracts/Nargo.toml | 4 +- yarn-project/cli/src/unbox.ts | 38 +++++++++++++------ 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/yarn-project/boxes/private-token/src/contracts/Nargo.toml b/yarn-project/boxes/private-token/src/contracts/Nargo.toml index a5e601e1620..433e7ba3cfd 100644 --- a/yarn-project/boxes/private-token/src/contracts/Nargo.toml +++ b/yarn-project/boxes/private-token/src/contracts/Nargo.toml @@ -5,5 +5,5 @@ compiler_version = "0.1" type = "contract" [dependencies] -aztec = { git="https://github.com/AztecProtocol/aztec-packages", tag="master", directory="yarn-project/noir-libs/noir-aztec" } -value_note = { git="https://github.com/AztecProtocol/aztec-packages", tag="master", directory="yarn-project/noir-libs/value-note" } \ No newline at end of file +aztec = { git="https://github.com/AztecProtocol/aztec-packages", tag="master", directory="yarn-project/aztec-nr/aztec" } +value_note = { git="https://github.com/AztecProtocol/aztec-packages", tag="master", directory="yarn-project/aztec-nr/value-note" } \ No newline at end of file diff --git a/yarn-project/cli/src/unbox.ts b/yarn-project/cli/src/unbox.ts index d14911a0406..23c8d3695c0 100644 --- a/yarn-project/cli/src/unbox.ts +++ b/yarn-project/cli/src/unbox.ts @@ -16,6 +16,7 @@ import * as path from 'path'; const GITHUB_OWNER = 'AztecProtocol'; const GITHUB_REPO = 'aztec-packages'; +const GITHUB_TAG_PREFIX = 'aztec-packages'; const NOIR_CONTRACTS_PATH = 'yarn-project/noir-contracts/src/contracts'; const BOXES_PATH = 'yarn-project/boxes'; @@ -77,25 +78,24 @@ async function copyFolderFromGithub(data: JSZip, repositoryFolderPath: string, l * monorepo on github. this will copy over the `yarn-projects/boxes/{contract_name}` folder * as well as the specified `directoryPath` if the box doesn't include source code * `directoryPath` should point to a single noir contract in `yarn-projects/noir-contracts/src/contracts/...` - * @param tagVersion - the version of the CLI that is running. we pull from the corresponding tag in the monorepo + * @param tag - The git tag to pull. * @param directoryPath - path to a noir contract's source code (folder) in the github repo * @param outputPath - local path that we will copy the noir contracts and web3 starter kit to * @returns */ async function downloadContractAndBoxFromGithub( - tagVersion: string, + tag: string, contractName: string, outputPath: string, log: LogFn, ): Promise { - const tagName = `aztec-packages-v${tagVersion}`; // small string conversion, in the ABI the contract name looks like PrivateToken // but in the repostory it looks like private_token const kebabCaseContractName = contractNameToFolder(contractName, '-'); log(`Downloading @aztex/boxes/${kebabCaseContractName} to ${outputPath}...`); // Step 1: Fetch the monorepo ZIP from GitHub, matching the CLI version - const url = `https://github.com/${GITHUB_OWNER}/${GITHUB_REPO}/archive/refs/tags/${tagName}.zip`; + const url = `https://github.com/${GITHUB_OWNER}/${GITHUB_REPO}/archive/refs/tags/${tag}.zip`; const response = await fetch(url); const buffer = await response.arrayBuffer(); @@ -104,7 +104,7 @@ async function downloadContractAndBoxFromGithub( // Step 2: copy the '@aztec/boxes/{contract-name}' subpackage to the output directory // this is currently only implemented for PrivateToken under 'boxes/private-token/' - const repoDirectoryPrefix = `${GITHUB_REPO}-${tagName}`; + const repoDirectoryPrefix = `${GITHUB_REPO}-${tag}`; const boxPath = `${repoDirectoryPrefix}/${BOXES_PATH}/${kebabCaseContractName}`; await copyFolderFromGithub(data, boxPath, outputPath, log); @@ -144,14 +144,20 @@ async function downloadContractAndBoxFromGithub( * something usable by the copied standalone unboxed folder. Adjusts relative paths * and package versions. * @param packageVersion - CLI npm version, which determines what npm version to grab + * @param tag - The git tag. * @param outputPath - relative path where we are copying everything * @param log - logger */ -async function updatePackagingConfigurations(packageVersion: string, outputPath: string, log: LogFn): Promise { +async function updatePackagingConfigurations( + packageVersion: string, + tag: string, + outputPath: string, + log: LogFn, +): Promise { await updatePackageJsonVersions(packageVersion, outputPath, log); await updateTsConfig('tsconfig.json', outputPath, log); await updateTsConfig('tsconfig.dest.json', outputPath, log); - await updateNargoToml(packageVersion, outputPath, log); + await updateNargoToml(tag, outputPath, log); } /** @@ -160,14 +166,14 @@ async function updatePackagingConfigurations(packageVersion: string, outputPath: * @param outputPath - relative path where we are copying everything * @param log - logger */ -async function updateNargoToml(packageVersion: string, outputPath: string, log: LogFn): Promise { +async function updateNargoToml(tag: string, outputPath: string, log: LogFn): Promise { const nargoTomlPath = path.join(outputPath, 'src', 'contracts', 'Nargo.toml'); const fileContent = await fs.readFile(nargoTomlPath, 'utf-8'); const lines = fileContent.split('\n'); - const updatedLines = lines.map(line => line.replace(/tag="master"/g, `tag="v${packageVersion}"`)); + const updatedLines = lines.map(line => line.replace(/tag="master"/g, `tag="${tag}"`)); const updatedContent = updatedLines.join('\n'); await fs.writeFile(nargoTomlPath, updatedContent); - log(`Updated Nargo.toml to point to local copy of noir-libs.`); + log(`Updated Nargo.toml to point to the compatible version of aztec noir libs.`); } /** @@ -300,11 +306,19 @@ export async function unboxContract( } const outputPath = await createDirectory(outputDirectoryName, log); + const tag = `${GITHUB_TAG_PREFIX}-v${packageVersion}`; // downloads the selected contract's relevant folder in @aztec/boxes/{contract_name} // and the noir source code from `noir-contracts` into `${outputDirectoryName}/src/contracts` // if not present in the box - await downloadContractAndBoxFromGithub(packageVersion, contractName, outputPath, log); + await downloadContractAndBoxFromGithub(tag, contractName, outputPath, log); // make adjustments for packaging to work as a standalone, as opposed to part of yarn workspace // as in the monorepo source files - await updatePackagingConfigurations(packageVersion, outputPath, log); + await updatePackagingConfigurations(packageVersion, tag, outputPath, log); + + log(''); + log(`${contractName} has been successfully initialised!`); + log('To get started, simply run the following commands:'); + log(` cd ${outputDirectoryName}`); + log(' yarn'); + log(' yarn start:dev'); }