Skip to content

Commit

Permalink
refactor: renaming, removing unused features and styling (#33)
Browse files Browse the repository at this point in the history
* docs: remove todo comments

* style: add rustfmt.toml file

* remove ept parachain

* refactor: rename vanilla per base parachain

* refactor: replace println per log

* style: cargo fmt
  • Loading branch information
AlexD10S authored Mar 7, 2024
1 parent 7737357 commit 37c8491
Show file tree
Hide file tree
Showing 31 changed files with 1,213 additions and 1,330 deletions.
10 changes: 3 additions & 7 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
[submodule "templates/ept"]
path = templates/ept
url = git@github.com:paritytech/extended-parachain-template.git

[submodule "templates/vanilla-parachain"]
path = templates/vanilla-parachain
url = git@github.com:r0guelabs/vanilla-parachain.git
[submodule "templates/base-parachain"]
path = templates/base-parachain
url = git@github.com:r0gue-io/base-parachain.git

24 changes: 24 additions & 0 deletions .rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Basic
edition = "2021"
hard_tabs = true
max_width = 100
use_small_heuristics = "Max"
# Imports
imports_granularity = "Crate"
reorder_imports = true
# Consistency
newline_style = "Unix"
# Misc
chain_width = 80
spaces_around_ranges = false
binop_separator = "Back"
reorder_impl_items = false
match_arm_leading_pipes = "Preserve"
match_arm_blocks = false
match_block_trailing_comma = true
trailing_comma = "Vertical"
trailing_semicolon = false
use_field_init_shorthand = true
# Format comments
comment_width = 100
wrap_comments = true
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ Use `pop` to either clone of your existing templates or instantiate a new parach
```sh
# Create a minimal parachain template
pop new parachain my-app
# Get the extended-parachain-template
pop new parachain my-app ept
# Get a pallet-contracts enabled template
pop new parachain my-app cpt
# Get a evm compatible parachain template
Expand Down
14 changes: 7 additions & 7 deletions src/commands/build/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ use crate::engines::contract_engine::build_smart_contract;

#[derive(Args)]
pub struct BuildContractCommand {
#[arg(short = 'p', long, help = "Path for the contract project, [default: current directory]")]
pub(crate) path: Option<PathBuf>,
#[arg(short = 'p', long, help = "Path for the contract project, [default: current directory]")]
pub(crate) path: Option<PathBuf>,
}

impl BuildContractCommand {
pub(crate) fn execute(&self) -> anyhow::Result<()> {
build_smart_contract(&self.path)?;
log::info("The smart contract has been successfully built.")?;
Ok(())
}
pub(crate) fn execute(&self) -> anyhow::Result<()> {
build_smart_contract(&self.path)?;
log::info("The smart contract has been successfully built.")?;
Ok(())
}
}
22 changes: 11 additions & 11 deletions src/commands/build/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ pub(crate) mod parachain;
#[derive(Args)]
#[command(args_conflicts_with_subcommands = true)]
pub(crate) struct BuildArgs {
#[command(subcommand)]
pub command: BuildCommands,
#[command(subcommand)]
pub command: BuildCommands,
}

#[derive(Subcommand)]
pub(crate) enum BuildCommands {
/// Build a parachain template
#[cfg(feature = "parachain")]
#[clap(alias = "p")]
Parachain(parachain::BuildParachainCommand),
/// Compiles the contract, generates metadata, bundles both together in a
/// `<name>.contract` file
#[cfg(feature = "contract")]
#[clap(alias = "c")]
Contract(contract::BuildContractCommand),
/// Build a parachain template
#[cfg(feature = "parachain")]
#[clap(alias = "p")]
Parachain(parachain::BuildParachainCommand),
/// Compiles the contract, generates metadata, bundles both together in a
/// `<name>.contract` file
#[cfg(feature = "contract")]
#[clap(alias = "c")]
Contract(contract::BuildContractCommand),
}
34 changes: 17 additions & 17 deletions src/commands/build/parachain.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
use crate::style::{style, Theme};
use clap::Args;
use cliclack::{clear_screen, intro, outro, set_theme};
use std::path::PathBuf;
use cliclack::{clear_screen,intro, set_theme, outro};
use crate::style::{style, Theme};

use crate::engines::parachain_engine::build_parachain;


#[derive(Args)]
pub struct BuildParachainCommand {
#[arg(short = 'p', long = "path", help = "Directory path for your project, [default: current directory]")]
pub(crate) path: Option<PathBuf>,
#[arg(
short = 'p',
long = "path",
help = "Directory path for your project, [default: current directory]"
)]
pub(crate) path: Option<PathBuf>,
}

impl BuildParachainCommand {
pub(crate) fn execute(&self) -> anyhow::Result<()> {
clear_screen()?;
intro(format!(
"{}: Building a parachain",
style(" Pop CLI ").black().on_magenta()
))?;
set_theme(Theme);
build_parachain(&self.path)?;
pub(crate) fn execute(&self) -> anyhow::Result<()> {
clear_screen()?;
intro(format!("{}: Building a parachain", style(" Pop CLI ").black().on_magenta()))?;
set_theme(Theme);
build_parachain(&self.path)?;

outro("Build Completed Successfully!")?;
Ok(())
}
}
outro("Build Completed Successfully!")?;
Ok(())
}
}
4 changes: 2 additions & 2 deletions src/commands/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub(crate) mod new;
pub(crate) mod build;
pub(crate) mod up;
pub(crate) mod new;
pub(crate) mod test;
pub(crate) mod up;
56 changes: 27 additions & 29 deletions src/commands/new/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,41 +7,39 @@ use crate::engines::contract_engine::create_smart_contract;

#[derive(Args)]
pub struct NewContractCommand {
#[arg(help = "Name of the contract")]
pub(crate) name: String,
#[arg(short = 'p', long, help = "Path for the contract project, [default: current directory]")]
pub(crate) path: Option<PathBuf>,
#[arg(help = "Name of the contract")]
pub(crate) name: String,
#[arg(short = 'p', long, help = "Path for the contract project, [default: current directory]")]
pub(crate) path: Option<PathBuf>,
}

impl NewContractCommand {
pub(crate) fn execute(&self) -> anyhow::Result<()> {
create_smart_contract(self.name.clone(), &self.path)?;
log::info(format!(
"Smart contract created! Located in the following directory {:?}",
self.path.clone().unwrap_or(PathBuf::from(format!("/{}", self.name))).display()
))?;
Ok(())
}
pub(crate) fn execute(&self) -> anyhow::Result<()> {
create_smart_contract(self.name.clone(), &self.path)?;
log::info(format!(
"Smart contract created! Located in the following directory {:?}",
self.path.clone().unwrap_or(PathBuf::from(format!("/{}", self.name))).display()
))?;
Ok(())
}
}

#[cfg(test)]
mod tests {
use super::*;
use std::fs;
use super::*;
use std::fs;

#[test]
fn test_new_contract_command_execute() -> anyhow::Result<()> {
let command = NewContractCommand {
name: "test_contract".to_string(),
path: Some(PathBuf::new())
};
let result = command.execute();
assert!(result.is_ok());

// Clean up
if let Err(err) = fs::remove_dir_all("test_contract") {
eprintln!("Failed to delete directory: {}", err);
}
Ok(())
}
#[test]
fn test_new_contract_command_execute() -> anyhow::Result<()> {
let command =
NewContractCommand { name: "test_contract".to_string(), path: Some(PathBuf::new()) };
let result = command.execute();
assert!(result.is_ok());

// Clean up
if let Err(err) = fs::remove_dir_all("test_contract") {
eprintln!("Failed to delete directory: {}", err);
}
Ok(())
}
}
28 changes: 14 additions & 14 deletions src/commands/new/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@ pub mod parachain;
#[derive(Args)]
#[command(args_conflicts_with_subcommands = true)]
pub struct NewArgs {
#[command(subcommand)]
pub command: NewCommands,
#[command(subcommand)]
pub command: NewCommands,
}

#[derive(Subcommand)]
pub enum NewCommands {
/// Generate a new parachain template
#[cfg(feature = "parachain")]
#[clap(alias = "p")]
Parachain(parachain::NewParachainCommand),
/// Generate a new pallet template
#[cfg(feature = "parachain")]
#[clap(alias = "m")] // (m)odule, as p used above
Pallet(pallet::NewPalletCommand),
/// Generate a new smart contract template
#[cfg(feature = "contract")]
#[clap(alias = "c")]
Contract(contract::NewContractCommand),
/// Generate a new parachain template
#[cfg(feature = "parachain")]
#[clap(alias = "p")]
Parachain(parachain::NewParachainCommand),
/// Generate a new pallet template
#[cfg(feature = "parachain")]
#[clap(alias = "m")] // (m)odule, as p used above
Pallet(pallet::NewPalletCommand),
/// Generate a new smart contract template
#[cfg(feature = "contract")]
#[clap(alias = "c")]
Contract(contract::NewContractCommand),
}
44 changes: 21 additions & 23 deletions src/commands/new/pallet.rs
Original file line number Diff line number Diff line change
@@ -1,30 +1,28 @@
use crate::engines::pallet_engine::{create_pallet_template, TemplatePalletConfig};
use clap::Args;
use crate::engines::pallet_engine::{TemplatePalletConfig, create_pallet_template};

#[derive(Args)]
pub struct NewPalletCommand {
#[arg(help = "Name of the pallet", default_value = "pallet-template")]
pub(crate) name: String,
#[arg(short, long, help = "Name of authors", default_value = "Anonymous")]
pub(crate) authors: Option<String>,
#[arg(
short,
long,
help = "Pallet description",
default_value = "Frame Pallet"
)]
pub(crate) description: Option<String>,
#[arg(short = 'p', long, help = "Path to the pallet, [default: current directory]")]
pub(crate) path: Option<String>,
#[arg(help = "Name of the pallet", default_value = "pallet-template")]
pub(crate) name: String,
#[arg(short, long, help = "Name of authors", default_value = "Anonymous")]
pub(crate) authors: Option<String>,
#[arg(short, long, help = "Pallet description", default_value = "Frame Pallet")]
pub(crate) description: Option<String>,
#[arg(short = 'p', long, help = "Path to the pallet, [default: current directory]")]
pub(crate) path: Option<String>,
}

impl NewPalletCommand {
pub(crate) fn execute(&self) -> anyhow::Result<()> {
create_pallet_template(self.path.clone(), TemplatePalletConfig {
name: self.name.clone(),
authors: self.authors.clone().expect("default values"),
description: self.description.clone().expect("default values"),
})?;
Ok(())
}
}
pub(crate) fn execute(&self) -> anyhow::Result<()> {
create_pallet_template(
self.path.clone(),
TemplatePalletConfig {
name: self.name.clone(),
authors: self.authors.clone().expect("default values"),
description: self.description.clone().expect("default values"),
},
)?;
Ok(())
}
}
Loading

0 comments on commit 37c8491

Please sign in to comment.