Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
46 changes: 0 additions & 46 deletions yarn-project/noir-contracts/scripts/compile.sh

Copy link
Copy Markdown
Contributor Author

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

This file was deleted.

2 changes: 2 additions & 0 deletions yarn-project/noir-contracts/scripts/types.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ process() {
CONTRACT=$1

cd $ROOT
NODE_OPTIONS=--no-warnings yarn ts-node --esm src/scripts/copy_source.ts $CONTRACT_NAME

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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 compile_all.sh

echo "Creating types for $CONTRACT"
NODE_OPTIONS=--no-warnings yarn ts-node --esm src/scripts/copy_output.ts $CONTRACT_NAME
}
Expand Down
82 changes: 82 additions & 0 deletions yarn-project/noir-contracts/src/scripts/copy_source.ts
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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// stored in `noir-contracts` under snake case nameing
// stored in `noir-contracts` under snake case naming

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);
}