Skip to content

Commit

Permalink
Merge pull request #181 from r-vdp/add_holo_dev_server
Browse files Browse the repository at this point in the history
  • Loading branch information
c12i authored Mar 21, 2024
2 parents a2e388d + a59c2ac commit f693a20
Show file tree
Hide file tree
Showing 15 changed files with 253 additions and 157 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
scope: [ hello_world ]
scope:
- hello_world
- holo_integration
steps:
- uses: actions/checkout@v4

Expand Down
156 changes: 104 additions & 52 deletions run_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,93 +10,145 @@ SCOPE=
# parse args
while getopts ":t:s:" opt; do
case $opt in
t) TEMPLATE_NAME="$OPTARG";;
s) SCOPE="$OPTARG";;
\?) echo "Invalid option: -$OPTARG" >&2
exit 1;;
:) echo "Option -$OPTARG requires an argument." >&2
exit 1;;
t) TEMPLATE_NAME="$OPTARG" ;;
s) SCOPE="$OPTARG" ;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
:)
echo "Option -$OPTARG requires an argument." >&2
exit 1
;;
esac
done

cleanup_tmp() {
rm -rf $TEMPLATE_PATH/$1
rm -rf "${TEMPLATE_PATH:?}/$1"
}

print_version() {
echo $(hc-scaffold --version)
echo "$(hc-scaffold --version)"
}

setup_and_build_happ() {
print_version
cleanup_tmp $1

cd $TEMPLATE_PATH
hc-scaffold --template $2 web-app $1 --setup-nix true
cd $1

hc-scaffold dna forum
hc-scaffold zome posts --integrity dnas/forum/zomes/integrity/ --coordinator dnas/forum/zomes/coordinator/
hc-scaffold entry-type post --reference-entry-hash false --crud crud --link-from-original-to-each-update true --fields title:String:TextField,content:String:TextArea
hc-scaffold entry-type comment --reference-entry-hash false --crud crud --link-from-original-to-each-update false --fields post_hash:ActionHash::Post
hc-scaffold entry-type like --reference-entry-hash false --crud crd --fields like_hash:Option\<ActionHash\>::Like,string_list:Vec\<String\>
hc-scaffold entry-type certificate --reference-entry-hash true --crud cr --fields post_hash:ActionHash::Post,agent:AgentPubKey::certified,certifications_hashes:Vec\<EntryHash\>::Certificate,certificate_type:Enum::CertificateType:TypeOne.TypeTwo,dna_hash:DnaHash

hc-scaffold collection global all_posts post
hc-scaffold collection by-author posts_by_author post
hc-scaffold collection global all_likes like
hc-scaffold collection global all_posts_entry_hash post:EntryHash
hc-scaffold collection by-author posts_by_author_entry_hash post:EntryHash

hc-scaffold link-type post like --delete true --bidirectional false
hc-scaffold link-type comment like:EntryHash --delete true --bidirectional true
hc-scaffold link-type certificate:EntryHash like --delete false --bidirectional false
hc-scaffold link-type agent:creator post:EntryHash --delete false --bidirectional true

nix develop --command bash -c "
print_version
cleanup_tmp "$1"

cd $TEMPLATE_PATH
hc-scaffold --template "$2" web-app "$1" --setup-nix true
cd "$1"

hc-scaffold dna forum
hc-scaffold zome posts --integrity dnas/forum/zomes/integrity/ --coordinator dnas/forum/zomes/coordinator/
hc-scaffold entry-type post --reference-entry-hash false --crud crud --link-from-original-to-each-update true --fields title:String:TextField,content:String:TextArea
hc-scaffold entry-type comment --reference-entry-hash false --crud crud --link-from-original-to-each-update false --fields post_hash:ActionHash::Post
hc-scaffold entry-type like --reference-entry-hash false --crud crd --fields like_hash:Option\<ActionHash\>::Like,string_list:Vec\<String\>
hc-scaffold entry-type certificate --reference-entry-hash true --crud cr --fields post_hash:ActionHash::Post,agent:AgentPubKey::certified,certifications_hashes:Vec\<EntryHash\>::Certificate,certificate_type:Enum::CertificateType:TypeOne.TypeTwo,dna_hash:DnaHash

hc-scaffold collection global all_posts post
hc-scaffold collection by-author posts_by_author post
hc-scaffold collection global all_likes like
hc-scaffold collection global all_posts_entry_hash post:EntryHash
hc-scaffold collection by-author posts_by_author_entry_hash post:EntryHash

hc-scaffold link-type post like --delete true --bidirectional false
hc-scaffold link-type comment like:EntryHash --delete true --bidirectional true
hc-scaffold link-type certificate:EntryHash like --delete false --bidirectional false
hc-scaffold link-type agent:creator post:EntryHash --delete false --bidirectional true

nix develop --command bash -c "
set -e
npm i
npm run build -w ui
npm t
npm run package
"
cd ..
cd ..
}

setup_and_build_hello_world() {
print_version
cleanup_tmp hello-world
print_version
cleanup_tmp hello-world

cd $TEMPLATE_PATH
hc-scaffold --template vanilla example hello-world
cd hello-world
cd $TEMPLATE_PATH
hc-scaffold --template vanilla example hello-world
cd hello-world

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

if [[ -n "$SCOPE" && "$SCOPE" == "hello_world" ]]; then
setup_and_build_hello_world
exit 0 # Exit early
if [[ -n "$SCOPE" ]]; then

case "$SCOPE" in
"hello_world")
setup_and_build_hello_world
;;
"holo_integration")
rm -rf /tmp/holo-flake
cd /tmp

hc-scaffold --template vue web-app holo-flake --setup-nix true
cd holo-flake

nix develop --command bash -c "
set -e
# Check if holo-dev-server is in the path
if command -v holo-dev-server >/dev/null 2>&1; then
echo 'holo-dev-server is available in the PATH while it should not'
exit 1
else
echo 'holo-dev-server is NOT available in the PATH'
fi
"

rm -rf /tmp/holo-flake
cd /tmp

hc-scaffold --template vue web-app holo-flake --setup-nix true --holo
cd holo-flake

nix develop --command bash -c "
set -e
# Check if holo-dev-server is in the path
if command -v holo-dev-server >/dev/null 2>&1; then
echo 'holo-dev-server is available in the PATH'
else
echo 'holo-dev-server is NOT available in the PATH'
exit 1
fi
"

rm -rf /tmp/holo-flake
cd /tmp
;;
*)
echo "Error: SCOPE must be one of 'hello_world', 'holo_integration', but got $SCOPE."
exit 1
;;
esac

exit 0 # Exit early
fi

if [[ -z "$APP_NAME" || -z "$TEMPLATE_NAME" ]]; then
echo "Error: APP_NAME and TEMPLATE_NAME environment variables must be set."
exit 1
echo "Error: APP_NAME and TEMPLATE_NAME environment variables must be set."
exit 1
fi

case "$TEMPLATE_NAME" in
"svelte" | "lit" | "vue" | "vanilla")
# Valid template name, proceed
;;
# Valid template name, proceed
;;
*)
echo "Error: TEMPLATE_NAME must be one of 'svelte', 'lit', 'vue', or 'vanilla'."
exit 1
;;
echo "Error: TEMPLATE_NAME must be one of 'svelte', 'lit', 'vue', or 'vanilla'."
exit 1
;;
esac

cleanup_tmp "$APP_NAME"
Expand Down
12 changes: 9 additions & 3 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,9 @@ pub enum HcScaffoldCommand {
Example {
/// Name of the example to scaffold. One of ['hello-world', 'forum'].
example: Option<Example>,

#[structopt(long = "holo", hidden = true)]
holo_enabled: bool,
},
}

Expand Down Expand Up @@ -674,7 +677,10 @@ Collection "{}" scaffolded!
println!("{}", i);
}
}
HcScaffoldCommand::Example { example } => {
HcScaffoldCommand::Example {
example,
holo_enabled,
} => {
let example = match example {
Some(e) => e,
None => choose_example()?,
Expand All @@ -695,7 +701,7 @@ Collection "{}" scaffolded!
Some(String::from("A simple 'hello world' application.")),
false,
&template_file_tree,
false,
holo_enabled,
)?;

file_tree
Expand All @@ -707,7 +713,7 @@ Collection "{}" scaffolded!
Some(String::from("A simple 'forum' application.")),
false,
&template_file_tree,
false,
holo_enabled,
)?;

// scaffold dna hello_world
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
//! web-app/
//!
//! Each folder corresponds to the templates that are created when running a specific command. Here are the steps executed:
//!
//!
//! 1. The user executes a scaffolding command, like `hc scaffold web-app`.
//! - Optionally, they may pass a `--template` argument, specifying the template name or local path to use.
//! - The `--template` value is saved in the root `package.json` file's `hcScaffold` key for future reference and to prevent the use of different templates in the same project.
Expand Down
2 changes: 1 addition & 1 deletion src/scaffold/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl AppFileTree {
pub fn file_tree(self) -> FileTree {
self.file_tree
}

pub fn file_tree_ref<'a>(&'a self) -> &'a FileTree {
&self.file_tree
}
Expand Down
32 changes: 24 additions & 8 deletions src/scaffold/app/nix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,21 @@ use crate::error::{ScaffoldError, ScaffoldResult};
use crate::file_tree::*;
use crate::versions::holochain_nix_version;

pub fn flake_nix() -> FileTree {
pub fn flake_nix(holo_enabled: bool) -> FileTree {
let holochain_nix_version = holochain_nix_version();

let holo_inputs = holo_enabled
.then_some(
r#"
hds-releases.url = "github:holo-host/hds-releases";
"#,
)
.unwrap_or("");

let holo_packages = holo_enabled
.then_some("inputs'.hds-releases.packages.holo-dev-server-bin")
.unwrap_or("");

file!(format!(
r#"{{
description = "Template for Holochain app development";
Expand All @@ -23,6 +36,7 @@ pub fn flake_nix() -> FileTree {
nixpkgs.follows = "holochain-flake/nixpkgs";
flake-parts.follows = "holochain-flake/flake-parts";
{holo_inputs}
}};
outputs = inputs:
Expand All @@ -43,6 +57,7 @@ pub fn flake_nix() -> FileTree {
inputsFrom = [ inputs'.holochain-flake.devShells.holonix ];
packages = [
pkgs.nodejs_20
{holo_packages}
# more packages go here
];
}};
Expand All @@ -67,14 +82,15 @@ pub fn setup_nix_developer_environment(dir: &PathBuf) -> ScaffoldResult<()> {
.stderr(Stdio::null())
.current_dir(dir)
.args(["rev-parse", "--is-inside-work-tree"])
.output() {
Ok(output) => {
if output.status.success() && output.stdout == b"true\n" {
return Err(ScaffoldError::NixSetupError("- detected that Scaffolding is running inside an existing Git repository, please choose a different location to scaffold".to_string()));
}
},
Err(_) => {} // Ignore errors, Git isn't necessarily available.
.output()
{
Ok(output) => {
if output.status.success() && output.stdout == b"true\n" {
return Err(ScaffoldError::NixSetupError("- detected that Scaffolding is running inside an existing Git repository, please choose a different location to scaffold".to_string()));
}
}
Err(_) => {} // Ignore errors, Git isn't necessarily available.
}

println!("Setting up nix development environment...");

Expand Down
3 changes: 2 additions & 1 deletion src/scaffold/collection/coordinator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,8 @@ fn add_delete_link_in_delete_function(
"delete_{}",
entry_type_reference.entry_type.to_case(Case::Snake)
),
)? else {
)?
else {
return Ok((dna_file_tree, false));
};

Expand Down
2 changes: 1 addition & 1 deletion src/scaffold/dna/coordinator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub fn new_coordinator_zome_manifest(
let location = zome_wasm_location(&dna_file_tree, &name);
let zome_manifest = ZomeManifest {
name: name.clone().into(),
hash: None,
hash: None,
location,
dependencies: maybe_dependencies.clone().map(|dz| {
dz.into_iter()
Expand Down
Loading

0 comments on commit f693a20

Please sign in to comment.