zip-rust.ts•1.8 kB
import JSZip from 'jszip';
import type { GenericOptions } from './build-generic';
import type { Contract } from './contract';
import { printContract, removeCreateLevelAttributes } from './print';
import {
contractOptionsToContractName,
createRustLibFile,
printContractCargo,
printRustNameTest,
workspaceCargo,
} from './zip-shared';
const readme = `\
# Sample Rust Contract Environment
This project demonstrates a basic Rust contract environment use case. It comes with a contract generated by [OpenZeppelin Wizard](https://wizard.openzeppelin.com/) and a test for that contract. Make sure you have the required dependencies and keep building!
## Go further
Continue your development journey with [Stellar CLI](https://github.com/stellar/stellar-cli).
## Installing dependencies
- See [Rust and Stellar installation guide](https://developers.stellar.org/docs/build/smart-contracts/getting-started/setup).
- See [Git installation guide](https://github.com/git-guides/install-git).
`;
export const createRustZipEnvironment = (c: Contract, opts: GenericOptions) => {
const zip = new JSZip();
const contractName = contractOptionsToContractName(opts?.kind || 'contract');
zip.file(`contracts/${contractName}/src/contract.rs`, removeCreateLevelAttributes(printContract(c)));
zip.file(`contracts/${contractName}/src/test.rs`, printRustNameTest(c));
zip.file(`contracts/${contractName}/src/lib.rs`, createRustLibFile);
zip.file(`contracts/${contractName}/Cargo.toml`, printContractCargo(contractName));
zip.file('Cargo.toml', workspaceCargo);
return zip;
};
const addRustProjectReadme = (zip: JSZip) => zip.file('README.md', readme);
export const zipRustProject = async (c: Contract, opts: GenericOptions) =>
addRustProjectReadme(createRustZipEnvironment(c, opts));