@aztec/cli 0.7.5 → 0.7.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/unbox.ts CHANGED
@@ -16,6 +16,7 @@ import * as path from 'path';
16
16
 
17
17
  const GITHUB_OWNER = 'AztecProtocol';
18
18
  const GITHUB_REPO = 'aztec-packages';
19
+ const GITHUB_TAG_PREFIX = 'aztec-packages';
19
20
  const NOIR_CONTRACTS_PATH = 'yarn-project/noir-contracts/src/contracts';
20
21
  const BOXES_PATH = 'yarn-project/boxes';
21
22
 
@@ -77,25 +78,24 @@ async function copyFolderFromGithub(data: JSZip, repositoryFolderPath: string, l
77
78
  * monorepo on github. this will copy over the `yarn-projects/boxes/{contract_name}` folder
78
79
  * as well as the specified `directoryPath` if the box doesn't include source code
79
80
  * `directoryPath` should point to a single noir contract in `yarn-projects/noir-contracts/src/contracts/...`
80
- * @param tagVersion - the version of the CLI that is running. we pull from the corresponding tag in the monorepo
81
+ * @param tag - The git tag to pull.
81
82
  * @param directoryPath - path to a noir contract's source code (folder) in the github repo
82
83
  * @param outputPath - local path that we will copy the noir contracts and web3 starter kit to
83
84
  * @returns
84
85
  */
85
86
  async function downloadContractAndBoxFromGithub(
86
- tagVersion: string,
87
+ tag: string,
87
88
  contractName: string,
88
89
  outputPath: string,
89
90
  log: LogFn,
90
91
  ): Promise<void> {
91
- const tagName = `aztec-packages-v${tagVersion}`;
92
92
  // small string conversion, in the ABI the contract name looks like PrivateToken
93
93
  // but in the repostory it looks like private_token
94
94
 
95
95
  const kebabCaseContractName = contractNameToFolder(contractName, '-');
96
96
  log(`Downloading @aztex/boxes/${kebabCaseContractName} to ${outputPath}...`);
97
97
  // Step 1: Fetch the monorepo ZIP from GitHub, matching the CLI version
98
- const url = `https://github.com/${GITHUB_OWNER}/${GITHUB_REPO}/archive/refs/tags/${tagName}.zip`;
98
+ const url = `https://github.com/${GITHUB_OWNER}/${GITHUB_REPO}/archive/refs/tags/${tag}.zip`;
99
99
  const response = await fetch(url);
100
100
  const buffer = await response.arrayBuffer();
101
101
 
@@ -104,7 +104,7 @@ async function downloadContractAndBoxFromGithub(
104
104
 
105
105
  // Step 2: copy the '@aztec/boxes/{contract-name}' subpackage to the output directory
106
106
  // this is currently only implemented for PrivateToken under 'boxes/private-token/'
107
- const repoDirectoryPrefix = `${GITHUB_REPO}-${tagName}`;
107
+ const repoDirectoryPrefix = `${GITHUB_REPO}-${tag}`;
108
108
 
109
109
  const boxPath = `${repoDirectoryPrefix}/${BOXES_PATH}/${kebabCaseContractName}`;
110
110
  await copyFolderFromGithub(data, boxPath, outputPath, log);
@@ -144,14 +144,20 @@ async function downloadContractAndBoxFromGithub(
144
144
  * something usable by the copied standalone unboxed folder. Adjusts relative paths
145
145
  * and package versions.
146
146
  * @param packageVersion - CLI npm version, which determines what npm version to grab
147
+ * @param tag - The git tag.
147
148
  * @param outputPath - relative path where we are copying everything
148
149
  * @param log - logger
149
150
  */
150
- async function updatePackagingConfigurations(packageVersion: string, outputPath: string, log: LogFn): Promise<void> {
151
+ async function updatePackagingConfigurations(
152
+ packageVersion: string,
153
+ tag: string,
154
+ outputPath: string,
155
+ log: LogFn,
156
+ ): Promise<void> {
151
157
  await updatePackageJsonVersions(packageVersion, outputPath, log);
152
158
  await updateTsConfig('tsconfig.json', outputPath, log);
153
159
  await updateTsConfig('tsconfig.dest.json', outputPath, log);
154
- await updateNargoToml(packageVersion, outputPath, log);
160
+ await updateNargoToml(tag, outputPath, log);
155
161
  }
156
162
 
157
163
  /**
@@ -160,14 +166,14 @@ async function updatePackagingConfigurations(packageVersion: string, outputPath:
160
166
  * @param outputPath - relative path where we are copying everything
161
167
  * @param log - logger
162
168
  */
163
- async function updateNargoToml(packageVersion: string, outputPath: string, log: LogFn): Promise<void> {
169
+ async function updateNargoToml(tag: string, outputPath: string, log: LogFn): Promise<void> {
164
170
  const nargoTomlPath = path.join(outputPath, 'src', 'contracts', 'Nargo.toml');
165
171
  const fileContent = await fs.readFile(nargoTomlPath, 'utf-8');
166
172
  const lines = fileContent.split('\n');
167
- const updatedLines = lines.map(line => line.replace(/tag="master"/g, `tag="v${packageVersion}"`));
173
+ const updatedLines = lines.map(line => line.replace(/tag="master"/g, `tag="${tag}"`));
168
174
  const updatedContent = updatedLines.join('\n');
169
175
  await fs.writeFile(nargoTomlPath, updatedContent);
170
- log(`Updated Nargo.toml to point to local copy of noir-libs.`);
176
+ log(`Updated Nargo.toml to point to the compatible version of aztec noir libs.`);
171
177
  }
172
178
 
173
179
  /**
@@ -300,11 +306,19 @@ export async function unboxContract(
300
306
  }
301
307
  const outputPath = await createDirectory(outputDirectoryName, log);
302
308
 
309
+ const tag = `${GITHUB_TAG_PREFIX}-v${packageVersion}`;
303
310
  // downloads the selected contract's relevant folder in @aztec/boxes/{contract_name}
304
311
  // and the noir source code from `noir-contracts` into `${outputDirectoryName}/src/contracts`
305
312
  // if not present in the box
306
- await downloadContractAndBoxFromGithub(packageVersion, contractName, outputPath, log);
313
+ await downloadContractAndBoxFromGithub(tag, contractName, outputPath, log);
307
314
  // make adjustments for packaging to work as a standalone, as opposed to part of yarn workspace
308
315
  // as in the monorepo source files
309
- await updatePackagingConfigurations(packageVersion, outputPath, log);
316
+ await updatePackagingConfigurations(packageVersion, tag, outputPath, log);
317
+
318
+ log('');
319
+ log(`${contractName} has been successfully initialised!`);
320
+ log('To get started, simply run the following commands:');
321
+ log(` cd ${outputDirectoryName}`);
322
+ log(' yarn');
323
+ log(' yarn start:dev');
310
324
  }