Skip to content
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

feat: Use app to generate composites #20

Merged
merged 1 commit into from
Sep 22, 2023
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
1 change: 0 additions & 1 deletion cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ publish = false

[dependencies]
anyhow.workspace = true
askama = "0.12.0"
ceramic-config = { path = "../ceramic-config", version = "0.1.52" }
clap = { version = "4.1.4", features = ["derive"] }
did-method-key = "0.2"
Expand Down
25 changes: 21 additions & 4 deletions cli/src/install/ceramic_app_template.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
use crate::DidAndPrivateKey;
use std::path::Path;
use tokio::io::AsyncWriteExt;

use crate::install::npm::npm_install;

const REPO: &'static str = "https://github.com/ceramicstudio/EthDenver2023Demo";
const ZIP_PATH: &'static str = "/archive/refs/heads/main.zip";

pub async fn install_ceramic_app_template(
key: &DidAndPrivateKey,
working_directory: &Path,
project_name: &str,
template_branch: &Option<String>,
daemon_config_file: impl AsRef<Path>,
) -> anyhow::Result<()> {
log::info!("Setting up application template from {}", REPO);
let data = reqwest::get(format!("{}{}", REPO, ZIP_PATH))
let zip_path = format!(
"/archive/refs/heads/{}.zip",
template_branch
.as_ref()
.map(|s| s.as_str())
.unwrap_or("main")
);
let data = reqwest::get(format!("{}{}", REPO, zip_path))
.await?
.bytes()
.await?;
Expand All @@ -35,7 +44,7 @@ pub async fn install_ceramic_app_template(

tokio::fs::rename(&unzip_dir, &output_dir).await?;

npm_install(&output_dir, &None).await?;
npm_install(&output_dir, &None, false).await?;

let readme = output_dir.join("README.md");
let mut f = tokio::fs::OpenOptions::new()
Expand Down Expand Up @@ -72,9 +81,17 @@ You can check out [Create Ceramic App repo](https://github.com/ceramicstudio/cre
let demo_config_file = output_dir.join("composedb.config.json");
tokio::fs::copy(&daemon_config_file, &demo_config_file).await?;

let seed_file = output_dir.join("admin_seed.txt");
tokio::fs::write(&seed_file, key.pk().as_bytes()).await?;

log::info!("Building composites");

crate::install::models::build_composite(&working_directory, &output_dir).await?;
tokio::process::Command::new("npm")
.current_dir(&output_dir)
.arg("run")
.arg("dev")
.status()
.await?;

log::info!(
r#"Application demo is available at {}. To run the demo application
Expand Down
14 changes: 7 additions & 7 deletions cli/src/install/ceramic_daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub async fn install_ceramic_daemon(
cfg: &Config,
version: &Option<semver::Version>,
ceramic_config_file: &Path,
quiet: bool,
start_ceramic: Option<bool>,
) -> anyhow::Result<Option<JoinHandle<()>>> {
verify_db::verify(&cfg).await?;

Expand All @@ -39,14 +39,14 @@ pub async fn install_ceramic_daemon(
if let Some(v) = version.as_ref() {
program.push_str(&format!("@{}", v.to_string()));
}
npm_install_package(&working_directory, &program).await?;
npm_install_package(&working_directory, &program, true).await?;

let ans = if quiet {
true
} else {
Confirm::new(&format!("Would you like ceramic started as a daemon?"))
let ans = match start_ceramic {
Some(true) => true,
Some(false) => false,
None => Confirm::new(&format!("Would you like ceramic started as a daemon?"))
.with_default(true)
.prompt()?
.prompt()?,
};

let ceramic_path = working_directory
Expand Down
4 changes: 2 additions & 2 deletions cli/src/install/compose_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub async fn install_compose_db(
if let Some(v) = version.as_ref() {
program.push_str(&format!("@{}", v.to_string()));
}
npm_install_package(working_directory, &program).await?;
npm_install_package(working_directory, &program, true).await?;

let env_file = working_directory.join("composedb.env");
let mut f = tokio::fs::OpenOptions::new()
Expand Down Expand Up @@ -60,7 +60,7 @@ pub async fn install_compose_db(
cfg.network.id.clone()
};
let network_name = convert_network_identifier(&network_id_for_model_list);

log::info!(
r#"
ComposeDB cli now available.
Expand Down
1 change: 0 additions & 1 deletion cli/src/install/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
pub mod ceramic_app_template;
pub mod ceramic_daemon;
pub mod compose_db;
mod models;
mod npm;
mod verify_db;

Expand Down
228 changes: 0 additions & 228 deletions cli/src/install/models.rs

This file was deleted.

7 changes: 6 additions & 1 deletion cli/src/install/npm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use tokio::process::Command;
pub async fn npm_install_package(
working_directory: impl AsRef<Path>,
package: &str,
globally: bool,
) -> anyhow::Result<()> {
let status = Command::new("npm")
.args(&["init", "--yes"])
Expand All @@ -16,17 +17,21 @@ pub async fn npm_install_package(
anyhow::bail!("Failed to init npm, cannot download {}", package);
}

npm_install(working_directory, &Some(&package)).await?;
npm_install(working_directory, &Some(&package), globally).await?;

Ok(())
}

pub async fn npm_install(
working_directory: impl AsRef<Path>,
package: &Option<&str>,
globally: bool,
) -> anyhow::Result<()> {
let msg = "Installing dependencies";
let mut args = vec!["install"];
if globally {
args.push("-g");
}
let msg = if let Some(p) = package {
args.push(p);
format!("{} for {}", msg, p)
Expand Down
Loading