cli: Add `idl-ts` option to build command (#940)
This commit is contained in:
parent
e22eb4c3d7
commit
ac3fbe8d38
|
@ -20,6 +20,7 @@ incremented for features.
|
||||||
* cli: fix dns in NODE_OPTIONS ([#928](https://github.com/project-serum/anchor/pull/928)).
|
* cli: fix dns in NODE_OPTIONS ([#928](https://github.com/project-serum/anchor/pull/928)).
|
||||||
* cli: output TypeScript IDL in `idl parse` subcommand ([#941](https://github.com/project-serum/anchor/pull/941)).
|
* cli: output TypeScript IDL in `idl parse` subcommand ([#941](https://github.com/project-serum/anchor/pull/941)).
|
||||||
* cli: Add fields `os` and `cpu` to npm package `@project-serum/anchor-cli` ([#976](https://github.com/project-serum/anchor/pull/976)).
|
* cli: Add fields `os` and `cpu` to npm package `@project-serum/anchor-cli` ([#976](https://github.com/project-serum/anchor/pull/976)).
|
||||||
|
* cli: Allow specify output directory for TypeScript IDL ([#940](https://github.com/project-serum/anchor/pull/940)).
|
||||||
|
|
||||||
## [0.18.0] - 2021-10-24
|
## [0.18.0] - 2021-10-24
|
||||||
|
|
||||||
|
|
|
@ -67,6 +67,9 @@ pub enum Command {
|
||||||
/// Output directory for the IDL.
|
/// Output directory for the IDL.
|
||||||
#[clap(short, long)]
|
#[clap(short, long)]
|
||||||
idl: Option<String>,
|
idl: Option<String>,
|
||||||
|
/// Output directory for the TypeScript IDL.
|
||||||
|
#[clap(short = 't', long)]
|
||||||
|
idl_ts: Option<String>,
|
||||||
/// True if the build artifact needs to be deterministic and verifiable.
|
/// True if the build artifact needs to be deterministic and verifiable.
|
||||||
#[clap(short, long)]
|
#[clap(short, long)]
|
||||||
verifiable: bool,
|
verifiable: bool,
|
||||||
|
@ -314,6 +317,7 @@ pub fn entry(opts: Opts) -> Result<()> {
|
||||||
Command::New { name } => new(&opts.cfg_override, name),
|
Command::New { name } => new(&opts.cfg_override, name),
|
||||||
Command::Build {
|
Command::Build {
|
||||||
idl,
|
idl,
|
||||||
|
idl_ts,
|
||||||
verifiable,
|
verifiable,
|
||||||
program_name,
|
program_name,
|
||||||
solana_version,
|
solana_version,
|
||||||
|
@ -321,6 +325,7 @@ pub fn entry(opts: Opts) -> Result<()> {
|
||||||
} => build(
|
} => build(
|
||||||
&opts.cfg_override,
|
&opts.cfg_override,
|
||||||
idl,
|
idl,
|
||||||
|
idl_ts,
|
||||||
verifiable,
|
verifiable,
|
||||||
program_name,
|
program_name,
|
||||||
solana_version,
|
solana_version,
|
||||||
|
@ -513,6 +518,7 @@ fn new_program(name: &str) -> Result<()> {
|
||||||
pub fn build(
|
pub fn build(
|
||||||
cfg_override: &ConfigOverride,
|
cfg_override: &ConfigOverride,
|
||||||
idl: Option<String>,
|
idl: Option<String>,
|
||||||
|
idl_ts: Option<String>,
|
||||||
verifiable: bool,
|
verifiable: bool,
|
||||||
program_name: Option<String>,
|
program_name: Option<String>,
|
||||||
solana_version: Option<String>,
|
solana_version: Option<String>,
|
||||||
|
@ -530,14 +536,17 @@ pub fn build(
|
||||||
|
|
||||||
let cargo = Manifest::discover()?;
|
let cargo = Manifest::discover()?;
|
||||||
|
|
||||||
fs::create_dir_all(cfg_parent.join("target/idl"))?;
|
|
||||||
fs::create_dir_all(cfg_parent.join("target/types"))?;
|
|
||||||
|
|
||||||
let idl_out = match idl {
|
let idl_out = match idl {
|
||||||
Some(idl) => Some(PathBuf::from(idl)),
|
Some(idl) => Some(PathBuf::from(idl)),
|
||||||
None => Some(cfg_parent.join("target/idl")),
|
None => Some(cfg_parent.join("target/idl")),
|
||||||
};
|
};
|
||||||
let idl_ts_out = Some(cfg_parent.join("target/types"));
|
fs::create_dir_all(idl_out.as_ref().unwrap())?;
|
||||||
|
|
||||||
|
let idl_ts_out = match idl_ts {
|
||||||
|
Some(idl_ts) => Some(PathBuf::from(idl_ts)),
|
||||||
|
None => Some(cfg_parent.join("target/types")),
|
||||||
|
};
|
||||||
|
fs::create_dir_all(idl_ts_out.as_ref().unwrap())?;
|
||||||
|
|
||||||
let solana_version = match solana_version.is_some() {
|
let solana_version = match solana_version.is_some() {
|
||||||
true => solana_version,
|
true => solana_version,
|
||||||
|
@ -940,6 +949,7 @@ fn verify(
|
||||||
build(
|
build(
|
||||||
cfg_override,
|
cfg_override,
|
||||||
None,
|
None,
|
||||||
|
None,
|
||||||
true,
|
true,
|
||||||
None,
|
None,
|
||||||
match solana_version.is_some() {
|
match solana_version.is_some() {
|
||||||
|
@ -1457,6 +1467,7 @@ fn test(
|
||||||
build(
|
build(
|
||||||
cfg_override,
|
cfg_override,
|
||||||
None,
|
None,
|
||||||
|
None,
|
||||||
false,
|
false,
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
|
@ -2364,6 +2375,7 @@ fn publish(
|
||||||
build(
|
build(
|
||||||
cfg_override,
|
cfg_override,
|
||||||
None,
|
None,
|
||||||
|
None,
|
||||||
true,
|
true,
|
||||||
Some(program_name),
|
Some(program_name),
|
||||||
cfg.solana_version.clone(),
|
cfg.solana_version.clone(),
|
||||||
|
@ -2458,6 +2470,7 @@ fn localnet(
|
||||||
build(
|
build(
|
||||||
cfg_override,
|
cfg_override,
|
||||||
None,
|
None,
|
||||||
|
None,
|
||||||
false,
|
false,
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
|
|
|
@ -30,15 +30,9 @@ token = "{}"
|
||||||
|
|
||||||
pub fn idl_ts(idl: &Idl) -> Result<String> {
|
pub fn idl_ts(idl: &Idl) -> Result<String> {
|
||||||
let mut idl = idl.clone();
|
let mut idl = idl.clone();
|
||||||
idl.accounts = idl
|
for acc in idl.accounts.iter_mut() {
|
||||||
.accounts
|
acc.name = acc.name.to_mixed_case();
|
||||||
.into_iter()
|
}
|
||||||
.map(|acc| {
|
|
||||||
let mut acc = acc;
|
|
||||||
acc.name = acc.name.to_mixed_case();
|
|
||||||
acc
|
|
||||||
})
|
|
||||||
.collect();
|
|
||||||
let idl_json = serde_json::to_string_pretty(&idl)?;
|
let idl_json = serde_json::to_string_pretty(&idl)?;
|
||||||
Ok(format!(
|
Ok(format!(
|
||||||
r#"export type {} = {};
|
r#"export type {} = {};
|
||||||
|
|
Loading…
Reference in New Issue