Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
guillemcordoba committed Mar 5, 2024
1 parent 3bf3d97 commit 1c81d47
Show file tree
Hide file tree
Showing 21 changed files with 201 additions and 62 deletions.
2 changes: 2 additions & 0 deletions run_test_app.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ hc-scaffold link-type comment like --delete true --bidirectional false
hc-scaffold link-type certificate like --delete false --bidirectional false
hc-scaffold link-type agent:creator post --delete false --bidirectional false

git add .

npm i

npm i -w ui @holochain-open-dev/file-storage
Expand Down
2 changes: 2 additions & 0 deletions run_test_module.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ hc-scaffold link-type --zome posts_integrity comment like --delete true --bidir
hc-scaffold link-type --zome posts_integrity certificate like --delete false --bidirectional false
hc-scaffold link-type --zome posts_integrity agent:creator post --delete false --bidirectional false

git add .

npm i

npm run format -w ui
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ async fn create_a_{{snake_case referenceable.name}}_and_get_{{snake_case collect
// Use prebuilt dna file
let dna_path = std::env::current_dir()
.unwrap()
.join("../../../workdir/{{dna_role_name}}.dna");
.join(std::env::var("DNA_PATH").expect("DNA_PATH not set, must be run using nix flake check"));
let dna = SweetDnaFile::from_bundle(&dna_path).await.unwrap();

// Set up conductors
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{{previous_file_content}}

[dev-dependencies]
fixt = "*"
fixt = "0.3.0-beta-dev"
futures = { version = "0.3.1", default-features = false }
hdk = { workspace = true, features = ["encoding", "test_utils"] }
holochain = { workspace = true }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{ inputs, rootPath, ... }:

{
perSystem =
{ inputs'
, self'
, ...
}: {
packages.{{zome_manifest.name}} = inputs.hcUtils.outputs.lib.rustZome {
workspacePath = rootPath;
holochain = inputs'.holochain;
crateCargoTomlPath = ./Cargo.toml;
};

# Test only this zome and its integrity in isolation
checks.{{zome_manifest.name }}= inputs.hcUtils.outputs.lib.sweettest {
workspacePath = rootPath;
holochain = inputs'.holochain;
dna = inputs.hcUtils.outputs.lib.dna {
dnaManifest = ''
---
manifest_version: "1"
name: test_dna
integrity:
network_seed: ~
properties: ~
origin_time: 1709638576394039
zomes:
- name: {{zome_manifest.name}}_integrity
coordinator:
zomes:
- name: my_zome
hash: ~
dependencies:
- {{zome_manifest.name}}_integrity
dylib: ~
'';
zomes = inputs.hcUtils.outputs.lib.filterZomes self'.packages;
holochain = inputs'.holochain;
};
crateCargoTomlPath = ./Cargo.toml;
};

};
}

35 changes: 35 additions & 0 deletions templates/app/dna/dnas/{{dna_name}}/dna.nix.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{ inputs, holochainSources, ... }:

{
# Import all ./zomes/coordinator/*/zome.nix and ./zomes/integrity/*/zome.nix
imports = (
map (m: "${./.}/zomes/coordinator/${m}/zome.nix")
(builtins.attrNames (builtins.readDir ./zomes/coordinator))
)
++
(
map (m: "${./.}/zomes/integrity/${m}/zome.nix")
(builtins.attrNames (builtins.readDir ./zomes/integrity))
)
;
perSystem =
{ inputs'
, self'
, lib
, ...
}: {
packages.{{dna_name}} = inputs.hcUtils.outputs.lib.dna {
dnaManifestPath = ./workdir/dna.yaml;
holochain = inputs'.holochain;
zomes = inputs.hcUtils.outputs.lib.filterZomes (
inputs.nixpkgs.lib.attrsets.mergeAttrsList (
[ self'.packages ]
++ builtins.map (s: s.packages) holochainSources inputs'
) # Merge all the holochain packages from this repository with the holochain sources repositories
) // {
# Override specific zomes here, e.g.:
# profiles_integrity = inputs'.profiles.packages.profiles_integrity;
};
};
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ async fn create_{{snake_case entry_type.name}}_test() {
// Use prebuilt dna file
let dna_path = std::env::current_dir()
.unwrap()
.join("../../../workdir/{{dna_role_name}}.dna");
.join(std::env::var("DNA_PATH").expect("DNA_PATH not set, must be run using nix flake check"));
let dna = SweetDnaFile::from_bundle(&dna_path).await.unwrap();

// Set up conductors
Expand All @@ -56,7 +56,7 @@ async fn create_and_read_{{snake_case entry_type.name}}() {
// Use prebuilt dna file
let dna_path = std::env::current_dir()
.unwrap()
.join("../../../workdir/{{dna_role_name}}.dna");
.join(std::env::var("DNA_PATH").expect("DNA_PATH not set, must be run using nix flake check"));
let dna = SweetDnaFile::from_bundle(&dna_path).await.unwrap();

// Set up conductors
Expand Down Expand Up @@ -95,7 +95,7 @@ async fn create_and_update_{{snake_case entry_type.name}}() {
// Use prebuilt dna file
let dna_path = std::env::current_dir()
.unwrap()
.join("../../../workdir/{{dna_role_name}}.dna");
.join(std::env::var("DNA_PATH").expect("DNA_PATH not set, must be run using nix flake check"));
let dna = SweetDnaFile::from_bundle(&dna_path).await.unwrap();

// Set up conductors
Expand Down Expand Up @@ -173,7 +173,7 @@ async fn create_and_delete_{{snake_case entry_type.name}}() {
// Use prebuilt dna file
let dna_path = std::env::current_dir()
.unwrap()
.join("../../../workdir/{{dna_role_name}}.dna");
.join(std::env::var("DNA_PATH").expect("DNA_PATH not set, must be run using nix flake check"));
let dna = SweetDnaFile::from_bundle(&dna_path).await.unwrap();

// Set up conductors
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{ inputs, rootPath, ... }:

{
perSystem =
{ inputs'
, ...
}: {
packages.{{zome_manifest.name}} = inputs.hcUtils.outputs.lib.rustZome {
workspacePath = rootPath;
holochain = inputs'.holochain;
crateCargoTomlPath = ./Cargo.toml;
};
};
}

Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ async fn link_a_{{snake_case from_referenceable.name}}_to_a_{{snake_case to_refe
// Use prebuilt dna file
let dna_path = std::env::current_dir()
.unwrap()
.join("../../../workdir/{{dna_role_name}}.dna");
.join(std::env::var("DNA_PATH").expect("DNA_PATH not set, must be run using nix flake check"));
let dna = SweetDnaFile::from_bundle(&dna_path).await.unwrap();

// Set up conductors
Expand Down
56 changes: 47 additions & 9 deletions templates/app/web-app/flake.nix.hbs
Original file line number Diff line number Diff line change
@@ -1,18 +1,56 @@
{{#merge previous_file_content}}
{{#match_scope "inputs = {"}}
{{previous_scope_content}}
{
description = "Template for Holochain app development";

scaffolding.url = "github:holochain-open-dev/templates";
{{/match_scope}}
{{#match_scope "devShells.default = pkgs.mkShell {"}}
inputs = {
versions.url = "github:holochain/holochain?dir=versions/weekly";

inputsFrom = [ inputs'.holochain-flake.devShells.holonix ];
holochain.url = "github:holochain/holochain";
holochain.inputs.versions.follows = "versions";

nixpkgs.follows = "holochain/nixpkgs";
flake-parts.follows = "holochain/flake-parts";

scaffolding.url = "github:holochain-open-dev/templates";
hcUtils.url = "github:holochain-open-dev/common";

# hApp dependencies
profiles.url = "github:holochain-open-dev/profiles/nixify";
};

outputs = inputs:
inputs.flake-parts.lib.mkFlake
{
inherit inputs;
specialArgs.rootPath = ./.;
# All the repositories that output zomes, dnas or happs packages
specialArgs.holochainSources = inputs': with inputs'; [
profiles
# Add more here
];
}
{
imports = [
./happ.nix
];

systems = builtins.attrNames inputs.holochain.devShells;
perSystem =
{ inputs'
, config
, pkgs
, system
, ...
}: {
devShells.default = pkgs.mkShell {
inputsFrom = [ inputs'.holochain.devShells.holonix ];

packages = with pkgs; [
nodejs_20
cargo-nextest
] ++ [
inputs'.scaffolding.packages.hc-scaffold-app-template
];
{{/match_scope}}
{{/merge}}
};
};
};
}
30 changes: 30 additions & 0 deletions templates/app/web-app/happ.nix.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{ inputs, holochainSources, ... }:

{
# Import all `dnas/*/dna.nix` files
imports = (
map (m: "${./.}/dnas/${m}/dna.nix")
(builtins.attrNames (if builtins.pathExists ./dnas then builtins.readDir ./dnas else {} ))
);

perSystem =
{ inputs'
, lib
, self'
, ...
}: {
packages.{{snake_case app_name}} = inputs.hcUtils.outputs.lib.happ {
holochain = inputs'.holochain;
happManifestPath = ./workdir/happ.yaml;
dnas = inputs.hcUtils.outputs.lib.filterDnas (
inputs.nixpkgs.lib.attrsets.mergeAttrsList (
[ self'.packages ]
++ builtins.map (s: s.packages) holochainSources inputs'
) # Merge all the holochain packages from this repository with the holochain sources repositories
) // {
# Override specific dnas here, e.g.:
# my_dna = inputs'.some_input.packages.my_dna;
};
};
};
}
5 changes: 0 additions & 5 deletions templates/app/web-app/optimize-wasms.sh.hbs

This file was deleted.

5 changes: 2 additions & 3 deletions templates/app/web-app/package.json.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@
"network": "hc s clean && npm run build:happ && UI_PORT=8888 concurrently -k \"npm start -w ui\" \"npm run launch:happ\" \"holochain-playground\"",
"test": "npm run build:happ && cargo nextest run -j 1 && npm test -w tests",
"launch:happ": "echo \"pass\" | RUST_LOG=warn hc launch --piped -n $AGENTS workdir/{{app_name}}.happ --ui-port $UI_PORT network -b https://bootstrap.holo.host webrtc wss://signal.holo.host",
"package": "npm run build:zomes && sh optimize-wasms.sh && npm run package -w ui && hc web-app pack workdir --recursive",
"build:happ": "npm run build:zomes && hc app pack workdir --recursive",
"build:zomes": "CARGO_TARGET_DIR=target cargo build --release --target wasm32-unknown-unknown"
"package": "nix build .#{{snake_case app_name}} -o workdir/{{snake_case app_name}}.happ && npm run package -w ui && hc web-app pack workdir --recursive",
"build:happ": "nix build .#{{snake_case app_name}}.meta.debug -o workdir/{{snake_case app_name}}-debug.happ"
},
"devDependencies": {
"@holochain-playground/cli": "^0.1.0",
Expand Down
2 changes: 1 addition & 1 deletion templates/app/web-app/ui/package.json.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"dependencies": {
"@holochain/client": "^0.17.0-dev.7",
"@holochain-open-dev/elements": "^0.8.4",
"@holochain-open-dev/profiles": "^0.17.3",
"@holochain-open-dev/profiles": "https://gitpkg.now.sh/holochain-open-dev/profiles/ui?nixify",
"@holochain-open-dev/stores": "^0.8.11",
"@holochain-open-dev/utils": "^0.16.5",
"@lit/context": "^1.0.0",
Expand Down
29 changes: 0 additions & 29 deletions templates/app/web-app/ui/vite.config.ts.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,7 @@ import checker from "vite-plugin-checker";
import path from "path";
import { viteStaticCopy } from "vite-plugin-static-copy";

const components = [
"dropdown",
"menu",
"menu-item",
"checkbox",
"divider",
"menu-label",
"option",
"select",
"tooltip",
"card",
"icon-button",
"button",
"icon",
"alert",
"input",
"spinner",
"avatar",
"skeleton",
];
const exclude = components.map(
(c) => `@shoelace-style/shoelace/dist/components/${c}/${c}.js`
);
export default defineConfig({
optimizeDeps: {
exclude: [
...exclude,
"@holochain-open-dev/elements/dist/elements/display-error.js",
],
},
plugins: [
checker({
typescript: true,
Expand Down
5 changes: 5 additions & 0 deletions templates/app/web-app/workdir/app-path.ts.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { dirname } from 'path';
import { fileURLToPath } from 'url';

export const appPath =
dirname(fileURLToPath(import.meta.url)) + '/../../workdir/{{snake_case app_name}}-debug.happ';
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ async fn create_a_{{snake_case referenceable.name}}_and_get_{{snake_case collect
// Use prebuilt dna file
let dna_path = std::env::current_dir()
.unwrap()
.join("../../../workdir/{{dna_role_name}}.dna");
.join(std::env::var("DNA_PATH").expect("DNA_PATH not set, must be run using nix flake check"));

let dna = SweetDnaFile::from_bundle(&dna_path).await.unwrap();

// Set up conductors
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{{previous_file_content}}

[dev-dependencies]
fixt = "*"
fixt = "0.3.0-beta-dev"
futures = { version = "0.3.1", default-features = false }
hdk = { workspace = true, features = ["encoding", "test_utils"] }
holochain = { workspace = true }
Expand Down
Loading

0 comments on commit 1c81d47

Please sign in to comment.