Skip to content

Commit

Permalink
Merge pull request #123 from holochain/add-holo-and-hello-world-hc-0.2
Browse files Browse the repository at this point in the history
Add holo and hello world to hc 0.2
  • Loading branch information
robbiecarlton authored Sep 25, 2023
2 parents 34fb08b + 1a06907 commit 821439b
Show file tree
Hide file tree
Showing 40 changed files with 665 additions and 190 deletions.
3 changes: 1 addition & 2 deletions .github/actions/extend-space/action.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Extends disk space on github hosted runners


name: "Extend space"
description: "Teases out as much free space as possible"

Expand Down Expand Up @@ -58,4 +57,4 @@ runs:
-o lowerdir=${HOME}_lower,upperdir=$EXTENDED_PATH/home/upper,workdir=$EXTENDED_PATH/home/work \
$HOME
sudo chown $(id -u):$(id -g) $HOME
df -h
df -h
30 changes: 0 additions & 30 deletions .github/workflows/check-offline.yaml

This file was deleted.

1 change: 0 additions & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ jobs:

- name: Extend space
uses: ./.github/actions/extend-space

- name: Install nix
uses: cachix/install-nix-action@v23
with:
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ yarn-error.log*
*.sln
*.sw?
result*
.cargo
.cargo
18 changes: 18 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ serde = "1"
json_value_merge = "1.1.2"
temp-dir = "0.1"
semver = "1.0"
itertools = "0.10"

[dev-dependencies]
assert_cmd = "1.0"
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@ CLI to easily generate and edit holochain apps.
The easiest way to start using the scaffolding tool is through holonix:

```bash
nix-shell https://holochain.love
hc-scaffold --version
nix run github:holochain/holochain#hc-scaffold -- --version
```

Should print the version of the scaffolding tool.

## Usage

These are the commands that you can run with the scaffolding tool:
Refer to [the holochain developer instructions](https://developer.holochain.org/get-building/) to know how you can use the scaffolding tool to create your own apps.

These are the commands that you can run with the scaffolding tool inside of a holonix develop shell:

```bash
# Scaffold an example app
Expand Down
30 changes: 15 additions & 15 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions run_test.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
#!/usr/bin/env bash
set -e

rm -rf /tmp/hello-world
cd /tmp

hc-scaffold example hello-world
cd hello-world

nix develop --command bash -c "
set -e
npm i
npm t
"

rm -rf /tmp/forum-svelte

cd /tmp
Expand Down
74 changes: 8 additions & 66 deletions src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use crate::error::{ScaffoldError, ScaffoldResult};
use crate::file_tree::{
dir_content, file_content, insert_file, load_directory_into_memory, FileTree,
};
use crate::file_tree::{dir_content, file_content, load_directory_into_memory, FileTree};
use crate::scaffold::app::cargo::exec_metadata;
use crate::scaffold::app::nix::setup_nix_developer_environment;
use crate::scaffold::app::AppFileTree;
Expand Down Expand Up @@ -72,6 +70,9 @@ pub enum HcScaffold {
/// If "--templates-url" is given, the template must be located at the ".templates/<TEMPLATE NAME>" folder of the repository
/// If not, the template must be an option from the built-in templates: "vanilla", "vue", "lit", "svelte"
template: Option<String>,

#[structopt(long = "holo", hidden = true)]
holo_enabled: bool,
},
/// Set up the template used in this project
Template(HcScaffoldTemplate),
Expand Down Expand Up @@ -228,6 +229,7 @@ impl HcScaffold {
template,
templates_url,
templates_path,
holo_enabled,
} => {
let prompt = String::from("App name (no whitespaces):");
let name: String = match name {
Expand Down Expand Up @@ -305,6 +307,7 @@ impl HcScaffold {
&template_file_tree,
template_name,
scaffold_template,
holo_enabled,
)?;

let file_tree = MergeableFileSystemTree::<OsString, String>::from(dir! {
Expand Down Expand Up @@ -733,69 +736,7 @@ Collection "{}" scaffolded!
&template_file_tree,
template_name.clone(),
false,
)?;

// scaffold dna hello_world
let dna_name = String::from("hello_world");

let app_file_tree =
AppFileTree::get_or_choose(file_tree, &Some(name.clone()))?;
let ScaffoldedTemplate { file_tree, .. } =
scaffold_dna(app_file_tree, &template_file_tree, &dna_name)?;

// scaffold integrity zome hello_world
let dna_file_tree =
DnaFileTree::get_or_choose(file_tree, &Some(dna_name.clone()))?;
let dna_manifest_path = dna_file_tree.dna_manifest_path.clone();

let integrity_zome_name = String::from("hello_world_integrity");
let integrity_zome_path = PathBuf::new()
.join("dnas")
.join(&dna_name)
.join("zomes")
.join("integrity");
let ScaffoldedTemplate { file_tree, .. } =
scaffold_integrity_zome_with_path(
dna_file_tree,
&template_file_tree,
&integrity_zome_name,
&integrity_zome_path,
)?;

// scaffold integrity zome hello_world
let dna_file_tree =
DnaFileTree::from_dna_manifest_path(file_tree, &dna_manifest_path)?;

let coordinator_zome_name = String::from("hello_world");
let coordinator_zome_path = PathBuf::new()
.join("dnas")
.join(dna_name)
.join("zomes")
.join("coordinator");
let ScaffoldedTemplate { mut file_tree, .. } =
scaffold_coordinator_zome_in_path(
dna_file_tree,
&template_file_tree,
&coordinator_zome_name,
&Some(vec![integrity_zome_name]),
&coordinator_zome_path,
)?;

// Add "hello_world" function to coordinator
let hello_world_zome = format!(
r#"use hdk::prelude::*;
#[hdk_extern]
pub fn hello_world(_: ()) -> ExternResult<String> {{
Ok(String::from("hello world from a Holochain app!"))
}}
"#
);

insert_file(
&mut file_tree,
&coordinator_zome_path.join("hello_world/src/lib.rs"),
&hello_world_zome,
false,
)?;

file_tree
Expand All @@ -809,6 +750,7 @@ pub fn hello_world(_: ()) -> ExternResult<String> {{
&template_file_tree,
template_name.clone(),
false,
false,
)?;

// scaffold dna hello_world
Expand Down
3 changes: 2 additions & 1 deletion src/reserved_words.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use convert_case::{Case, Casing};

use crate::error::{ScaffoldError, ScaffoldResult};

const RESERVED_WORDS: [&str; 26] = [
const RESERVED_WORDS: [&str; 27] = [
"type",
"role",
"enum",
Expand All @@ -29,6 +29,7 @@ const RESERVED_WORDS: [&str; 26] = [
"EntryHash",
"ActionHash",
"AgentPubKey",
"Call",
];

// Returns an error if the given string is invalid due to it being a reserved word
Expand Down
4 changes: 2 additions & 2 deletions src/scaffold/entry_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,10 @@ pub fn scaffold_entry_type(
)?;
}

let zome_file_tree =
let mut zome_file_tree =
ZomeFileTree::from_zome_manifest(zome_file_tree.dna_file_tree, coordinator_zome.clone())?;

let zome_file_tree = add_crud_functions_to_coordinator(
zome_file_tree = add_crud_functions_to_coordinator(
zome_file_tree,
&integrity_zome_name,
&entry_def,
Expand Down
Loading

0 comments on commit 821439b

Please sign in to comment.