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

Nov 0.1 backports #160

Merged
merged 8 commits into from
Nov 28, 2023
Merged
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ edition = "2021"
name = "holochain_scaffolding_cli"
version = "0.1.10"
description = "CLI to easily generate and modify holochain apps"
license-file = "LICENSE_CAL-1.0"
license = "CAL-1.0"
homepage = "https://developer.holochain.org"
documentation = "https://docs.rs/holochain_scaffolding_cli"
repository = "https://github.com/holochain/scaffolding"
Expand Down
159 changes: 0 additions & 159 deletions LICENSE_CAL-1.0

This file was deleted.

24 changes: 12 additions & 12 deletions flake.lock

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

4 changes: 0 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@
//!
//! Templates have this directory structure:
//!
//! ```
//! coordinator-zome/
//! dna/
//! entry-type/
Expand All @@ -92,7 +91,6 @@
//! integrity-zome/
//! link-type/
//! web-app/
//! ```
//!
//! Each folder corresponds to the templates that are going to be created when running a specific command. This is the steps that are executed:
//!
Expand Down Expand Up @@ -123,7 +121,6 @@
//!
//! The `field-types` folder is special. It has the following directory structure:
//!
//! ```
//! ActionHash/
//! type.hbs
//! AgentPubKey/
Expand Down Expand Up @@ -168,7 +165,6 @@
//! imports.hbs
//! render.hbs
//! type.hbs
//! ```
//!
//! As you can see, the top-level folders are the rust types that are possible to use as the field types for an entry. The `type.hbs` file in each of the folders contains the typescript type for that rust type, so that it can be rendered in the frontend.
//!
Expand Down
17 changes: 17 additions & 0 deletions src/scaffold/app/nix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,23 @@ pub fn setup_nix_developer_environment(dir: &PathBuf) -> ScaffoldResult<()> {
));
}

// This is here to catch the issue from this thread https://discourse.nixos.org/t/nix-flakes-nix-store-source-no-such-file-or-directory/17836
// If you run Scaffolding inside a Git repository when the `nix flake update` will fail. At some point Nix should report this so we don't need
// to worry about it but for now this helps solve a strange error message.
match Command::new("git")
.stdout(Stdio::piped())
.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.
}

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

add_extra_experimental_features()?;
Expand Down
81 changes: 53 additions & 28 deletions src/templates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,37 @@ pub fn register_concat_helper<'a>(mut h: Handlebars<'a>) -> Handlebars<'a> {
#[derive(Clone, Copy)]
pub struct MergeScope;

fn get_scope_open_and_close_char_indexes(
text: &String,
scope_opener: &String,
) -> Result<(usize, usize), RenderError> {
let mut index = text.find(scope_opener.as_str()).ok_or(RenderError::new(
"Given scope opener not found in the given parameter",
))?;

index = index + scope_opener.len() - 1;
let scope_opener_index = index.clone();
let mut scope_count = 1;

while scope_count > 0 {
index += 1;
match text.chars().nth(index) {
Some('{') => {
scope_count += 1;
}
Some('}') => {
scope_count -= 1;
}
None => {
return Err(RenderError::new("Malformed scopes"));
}
_ => {}
}
}

Ok((scope_opener_index, index))
}

impl HelperDef for MergeScope {
fn call<'reg: 'rc, 'rc>(
&self,
Expand Down Expand Up @@ -125,35 +156,11 @@ impl HelperDef for MergeScope {
))?
.to_string();

let mut index = s.find(scope_opener.as_str()).ok_or(RenderError::new(
"Given scope opener not found in the given parameter",
))?;

index += scope_opener.len();
let scope_opener_index = index.clone();
index -= 1;
let mut scope_count = 1;

while scope_count > 0 {
index += 1;
match s.chars().nth(index) {
Some('{') => {
scope_count += 1;
}
Some('}') => {
scope_count -= 1;
}
None => {
return Err(RenderError::new("Malformed scopes"));
}
_ => {}
}
}

// Here index is the position of the correct closing '}' for the scope
let (scope_opener_index, scope_close_index) =
get_scope_open_and_close_char_indexes(&s, &scope_opener)?;

out.write(&s[0..=scope_opener_index])?;
let previous_scope_content = &s[scope_opener_index..index].to_string();
let previous_scope_content = &s[(scope_opener_index + 1)..scope_close_index].to_string();

let mut data = ctx
.data()
Expand All @@ -167,7 +174,7 @@ impl HelperDef for MergeScope {
rc.set_context(Context::wraps(data)?);
t.render(r, ctx, rc, out)?;

out.write(&s[index..])?;
out.write(&s[scope_close_index..])?;
Ok(())
}
}
Expand Down Expand Up @@ -516,3 +523,21 @@ pub fn choose_or_get_template(

Ok(chosen_template_name)
}

#[cfg(test)]
mod tests {
// Note this useful idiom: importing names from outer (for mod tests) scope.
use super::*;

#[test]
fn test_get_scope_open_and_close_char_indexes() {
let text = String::from("const s = {};");
let scope_opener = String::from("const s = {");

let (scope_opener_index, scope_close_index) =
get_scope_open_and_close_char_indexes(&text, &scope_opener).unwrap();

assert_eq!(scope_opener_index, 10);
assert_eq!(scope_close_index, 11);
}
}
3 changes: 2 additions & 1 deletion templates/lit/web-app/package.json.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@
"devDependencies": {
"@holochain-playground/cli": "^0.1.1",
"concurrently": "^6.2.1",
"rimraf": "^3.0.2",
{{#if holo_enabled}}
"concurrently-repeat": "^0.0.1",
{{/if}}
"rimraf": "^3.0.2"
"new-port-cli": "^1.0.0"
},
"engines": {
"npm": ">=7.0.0"
Expand Down
7 changes: 4 additions & 3 deletions templates/svelte/web-app/package.json.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@
{{/if}}
"package": "npm run build:happ && npm run package -w ui && hc web-app pack workdir --recursive",
"build:happ": "npm run build:zomes && hc app pack workdir --recursive",
"build:zomes": "RUSTFLAGS='' CARGO_TARGET_DIR=target cargo build --release --target wasm32-unknown-unknown"
"build:zomes": "RUSTFLAGS='' CARGO_TARGET_DIR=target cargo build --release --target wasm32-unknown-unknown"
},
"devDependencies": {
"devDependencies": {
"@holochain-playground/cli": "^0.1.1",
"concurrently": "^6.2.1",
"rimraf": "^3.0.2",
{{#if holo_enabled}}
"concurrently-repeat": "^0.0.1",
{{/if}}
"rimraf": "^3.0.2"
"new-port-cli": "^1.0.0"
},
"engines": {
"npm": ">=7.0.0"
Expand Down
4 changes: 2 additions & 2 deletions templates/svelte/web-app/ui/package.json.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"start": "vite --clearScreen false --port $UI_PORT",
"build": "npm run check && vite build",
"check": "svelte-check --tsconfig ./tsconfig.json",
"package": "npm run build && cd public && bestzip ../dist.zip *"
"package": "npm run build && cd dist && bestzip ../dist.zip *"
},
"dependencies": {
"@holochain/client": "{{holochain_client_version}}",
Expand All @@ -17,7 +17,7 @@
"@material/mwc-textfield": "^0.27.0",
"@material/mwc-textarea": "^0.27.0",
"@material/mwc-icon-button": "^0.27.0",
"@material/mwc-checkbox": "^0.27.0",
"@material/mwc-checkbox": "^0.27.0",
"@material/mwc-snackbar": "^0.27.0",
"@material/mwc-slider": "^0.27.0",
"@material/mwc-select": "^0.27.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
</div>

<div v-else style="display: flex; flex-direction: column">
<span v-if="error">Error fetching the {{lower_case (plural referenceable.name)}}: {{{{raw}}}} {{error.data.data}}.{{{{/raw}}}}</span>
<span v-if="error">Error fetching the {{lower_case (plural referenceable.name)}}: {{{{raw}}}} {{error.data}}.{{{{/raw}}}}</span>
<div v-else-if="hashes && hashes.length > 0" style="margin-bottom: 8px">
<{{pascal_case referenceable.name}}Detail
v-for="hash in hashes"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export default defineComponent({
this.$emit('{{kebab_case entry_type.name}}-created', record.signed_action.hashed.hash);
} catch (e: any) {
const errorSnackbar = this.$refs['create-error'] as Snackbar;
errorSnackbar.labelText = `Error creating the {{lower_case entry_type.name}}: ${e.data.data}`;
errorSnackbar.labelText = `Error creating the {{lower_case entry_type.name}}: ${e.data}`;
errorSnackbar.show();
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
</div>

<div v-else style="display: flex; flex-direction: column">
<span v-if="error">Error fetching the {{lower_case (plural ../entry_type.name)}}: {{{{raw}}}} {{error.data.data}}.{{{{/raw}}}}</span>
<span v-if="error">Error fetching the {{lower_case (plural ../entry_type.name)}}: {{{{raw}}}} {{error.data}}.{{{{/raw}}}}</span>
<div v-else-if="hashes && hashes.length > 0" style="margin-bottom: 8px">
<{{pascal_case ../entry_type.name}}Detail
v-for="hash in hashes"
Expand All @@ -20,7 +20,7 @@
<script lang="ts">
import { defineComponent, inject, ComputedRef } from 'vue';
import { decode } from '@msgpack/msgpack';
import { AppAgentClient, Record, AgentPubKey, EntryHash, ActionHash } from '@holochain/client';
import { AppAgentClient, Record, AgentPubKey, EntryHash, ActionHash, CallZomeResponse } from '@holochain/client';
import '@material/mwc-circular-progress';
import {{pascal_case ../entry_type.name}}Detail from './{{pascal_case ../entry_type.name}}Detail.vue';

Expand All @@ -29,7 +29,7 @@ export default defineComponent({
{{pascal_case ../entry_type.name}}Detail
},
props: {
{{camel_case linked_from.singular_arg}}Hash: {
{{camel_case linked_from.singular_arg}}: {
type: Object,
required: true
}
Expand All @@ -42,18 +42,19 @@ export default defineComponent({
}
},
async mounted() {
if (this.{{camel_case linked_from.singular_arg}}Hash === undefined) {
if (this.{{camel_case linked_from.singular_arg}} === undefined) {
throw new Error(`The {{camel_case linked_from.singular_arg}}Hash input is required for the {{pascal_case (plural ../entry_type.name)}}For{{pascal_case linked_from.name}} element`);
}

try {
this.hashes = await this.client.callZome({
const records = await this.client.callZome({
cap_secret: null,
role_name: '{{dna_role_name}}',
role_name: '{{../dna_role_name}}',
zome_name: '{{../coordinator_zome_manifest.name}}',
fn_name: 'get_{{snake_case (plural ../entry_type.name)}}_for_{{snake_case linked_from.name}}',
payload: this.{{camel_case linked_from.singular_arg}}Hash,
payload: this.{{camel_case linked_from.singular_arg}},
});
this.hashes = records.map((r: CallZomeResponse) => r.signed_action.hashed.hash);
} catch (e) {
this.error = e;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export default defineComponent({
this.$emit('{{kebab_case entry_type.name}}-updated', updateRecord.signed_action.hashed.hash);
} catch (e: any) {
const errorSnackbar = this.$refs['update-error'] as Snackbar;
errorSnackbar.labelText = `Error updating the {{lower_case entry_type.name}}: ${e.data.data}`;
errorSnackbar.labelText = `Error updating the {{lower_case entry_type.name}}: ${e.data}`;
errorSnackbar.show();
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export default defineComponent({
this.fetch{{pascal_case entry_type.name}}();
} catch (e: any) {
const errorSnackbar = this.$refs['delete-error'] as Snackbar;
errorSnackbar.labelText = `Error deleting the {{lower_case entry_type.name}}: ${e.data.data}`;
errorSnackbar.labelText = `Error deleting the {{lower_case entry_type.name}}: ${e.data}`;
errorSnackbar.show();
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{{{{raw}}}} {{ {{{{/raw}}}} new Date({{variable_to_read}} / 1000).toLocaleString() {{{{raw}}}} }} {{{{/raw}}}}
{{{{raw}}}} {{ {{{{/raw}}}} {{variable_to_read}} ? new Date({{variable_to_read}} / 1000).toLocaleString() : 'Missing timestamp' {{{{raw}}}} }} {{{{/raw}}}}
2 changes: 1 addition & 1 deletion templates/vue/field-types/bool/Checkbox/edit/imports.hbs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
import '@material/mwc-checkbox';
impor '@material/mwc-formfield';
import '@material/mwc-formfield';
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
</div>

<div v-else style="display: flex; flex-direction: column">
<span v-if="error">Error fetching the {{lower_case (plural from_referenceable.name)}}: {{{{raw}}}} {{error.data.data}}.{{{{/raw}}}}</span>
<span v-if="error">Error fetching the {{lower_case (plural from_referenceable.name)}}: {{{{raw}}}} {{error.data}}.{{{{/raw}}}}</span>
<div v-else-if="hashes && hashes.length > 0" style="margin-bottom: 8px">
<{{pascal_case from_referenceable.name}}Detail
v-for="hash in hashes"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
</div>

<div v-else style="display: flex; flex-direction: column">
<span v-if="error">Error fetching the {{lower_case (plural to_referenceable.name)}}: {{{{raw}}}} {{error.data.data}}.{{{{/raw}}}}</span>
<span v-if="error">Error fetching the {{lower_case (plural to_referenceable.name)}}: {{{{raw}}}} {{error.data}}.{{{{/raw}}}}</span>
<div v-else-if="hashes && hashes.length > 0" style="margin-bottom: 8px">
<{{pascal_case to_referenceable.name}}Detail
v-for="hash in hashes"
Expand Down
Loading