-
Notifications
You must be signed in to change notification settings - Fork 266
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: token box copies noir source files from noir-contracts on bootstrap #2940
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,6 +44,8 @@ process() { | |
CONTRACT=$1 | ||
|
||
cd $ROOT | ||
NODE_OPTIONS=--no-warnings yarn ts-node --esm src/scripts/copy_source.ts $CONTRACT_NAME | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. placeing here since we already loop over contracts, even though its a little more appropriate in |
||
echo "Creating types for $CONTRACT" | ||
NODE_OPTIONS=--no-warnings yarn ts-node --esm src/scripts/copy_output.ts $CONTRACT_NAME | ||
} | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,82 @@ | ||||||
/* eslint-disable jsdoc/require-jsdoc */ | ||||||
import { createConsoleLogger } from '@aztec/foundation/log'; | ||||||
|
||||||
import * as fs from 'fs'; | ||||||
import snakeCase from 'lodash.snakecase'; | ||||||
import * as path from 'path'; | ||||||
import { format } from 'util'; | ||||||
|
||||||
// heavily copying yarn-project/noir-contracts/src/scripts/copy_output.ts | ||||||
const log = createConsoleLogger('aztec:noir-contracts:source_copy'); | ||||||
|
||||||
/** | ||||||
* for the typechecker... | ||||||
*/ | ||||||
interface NoirSourceCopy { | ||||||
name: string; | ||||||
target: string; | ||||||
exclude: string[]; | ||||||
} | ||||||
|
||||||
const NOIR_SOURCE_COPIES: NoirSourceCopy[] = [ | ||||||
{ name: 'PrivateToken', target: '../boxes/private-token/src/artifacts', exclude: [] }, | ||||||
]; | ||||||
|
||||||
/** | ||||||
* Sometimes we want to duplicate the noir source code elsewhere, | ||||||
* for example in the boxes we provide as Aztec Quickstarts. | ||||||
* @param contractName - UpperCamelCase contract name that we check need copying | ||||||
*/ | ||||||
function copyNrFilesExceptInterface(contractName: string): void { | ||||||
// stored in `noir-contracts` under snake case nameing | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
const snakeCaseContractName = `${snakeCase(contractName)}_contract`; | ||||||
const projectDirPath = `src/contracts/${snakeCaseContractName}`; | ||||||
|
||||||
for (const noirCopy of NOIR_SOURCE_COPIES) { | ||||||
if (noirCopy.name === contractName) { | ||||||
const target = noirCopy.target; | ||||||
|
||||||
try { | ||||||
// Ensure target directory exists | ||||||
if (!fs.existsSync(target)) { | ||||||
throw Error(`target copy path ${target} doesnt exist`); | ||||||
} | ||||||
// Read the project directory | ||||||
const files = fs.readdirSync(projectDirPath); | ||||||
|
||||||
// Filter and copy *.nr files except interface.nr | ||||||
files | ||||||
.filter( | ||||||
file => | ||||||
file.endsWith('.nr') && | ||||||
file !== 'interface.nr' && | ||||||
(!noirCopy.exclude || !noirCopy.exclude.includes(file)), | ||||||
) | ||||||
.forEach(file => { | ||||||
const sourcePath = path.join(projectDirPath, file); | ||||||
const targetPath = path.join(target, file); | ||||||
log(`copying ${sourcePath} to ${targetPath}`); | ||||||
fs.copyFileSync(sourcePath, targetPath); | ||||||
}); | ||||||
|
||||||
log(`Copied .nr files from ${contractName} to ${target} successfully!`); | ||||||
} catch (err) { | ||||||
log(format(`Error copying files from ${contractName} to ${target}:`, err)); | ||||||
} | ||||||
} | ||||||
} | ||||||
} | ||||||
|
||||||
const main = () => { | ||||||
const contractName = process.argv[2]; | ||||||
if (!contractName) throw new Error(`Missing argument contract name`); | ||||||
|
||||||
copyNrFilesExceptInterface(contractName); | ||||||
}; | ||||||
|
||||||
try { | ||||||
main(); | ||||||
} catch (err: unknown) { | ||||||
log(format(`Error copying build output`, err)); | ||||||
process.exit(1); | ||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doesnt seem to be used