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

Backport 0.2 #178

Merged
merged 5 commits into from
Jan 12, 2024
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
9 changes: 9 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ on:
branches: [ develop, develop-0.1, develop-0.2 ]

jobs:
cargotest:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: dtolnay/rust-toolchain@stable

- run: cargo test --no-fail-fast

testbuild:
runs-on: ubuntu-latest
steps:
Expand Down
2 changes: 1 addition & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ Add new entry definitions to your zome with:
let file_tree = load_directory_into_memory(&current_dir)?;
let template_file_tree = choose_or_get_template_file_tree(&file_tree, &template)?;

let name: String = match name {
let name = match name {
Some(n) => {
check_case(&n, "entry type name", Case::Snake)?;
n
Expand Down
1 change: 1 addition & 0 deletions src/scaffold/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +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
9 changes: 8 additions & 1 deletion src/scaffold/entry_type/fields.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use dialoguer::{theme::ColorfulTheme, Confirm, Select};
use regex::Regex;

use crate::{
error::ScaffoldResult,
error::{ScaffoldError, ScaffoldResult},
file_tree::{dir_content, FileTree},
scaffold::zome::ZomeFileTree,
utils::{check_case, input_with_case, input_with_case_and_initial_text},
Expand Down Expand Up @@ -261,6 +261,13 @@ pub fn choose_field(
));
}

if all_options.is_empty() {
return Err(ScaffoldError::NoEntryTypesDefFoundForIntegrityZome(
zome_file_tree.dna_file_tree.dna_manifest.name(),
zome_file_tree.zome_manifest.name.to_string(),
))
}

let selection = Select::with_theme(&ColorfulTheme::default())
.with_prompt(String::from("Which entry type is this field referring to?"))
.default(0)
Expand Down
86 changes: 0 additions & 86 deletions src/templates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,89 +295,3 @@ 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::*;
use handlebars::Handlebars;
use serde_json::{Map, Value};

#[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);
}

#[test]
fn test_merge_match_scope() {
let h = Handlebars::new();

let mut h = register_helpers(h);

let code = String::from(
r#"
export class A {
nestedFn1() {

}
}
export class B {
nestedFn() {
// First line
}
}
"#,
);
let mut map = Map::new();
map.insert(
String::from("previous_file_content"),
Value::String(String::from(code)),
);
let context = Context::from(Value::Object(map));
let template = r#"
{{#merge previous_file_content}}
{{#match_scope "export class A {"}}
nestedFn2() {

}
{{previous_scope_content}}
{{/match_scope}}
{{#match_scope "export class B {"}}
{{#merge previous_scope_content}}
{{#match_scope "nestedFn() {"}}
{{previous_scope_content}}
// New line
{{/match_scope}}
{{/merge}}
{{/match_scope}}
{{/merge}}
"#;

assert_eq!(
h.render_template_with_context(template, &context).unwrap(),
r#"
export class A {
nestedFn2() {

}
nestedFn1() {

}
}
export class B {
nestedFn() {
// First line
// New line
}
}
"#,
);
}
}
58 changes: 19 additions & 39 deletions src/templates/helpers/merge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use handlebars::{
use serde::{Deserialize, Serialize};
use serde_json::{Map, Number, Value};

fn get_scope_open_and_close_char_indexes(
pub fn get_scope_open_and_close_char_indexes(
text: &String,
scope_opener: &String,
) -> Result<(usize, usize), RenderError> {
Expand Down Expand Up @@ -237,7 +237,7 @@ mod tests {
// Note this useful idiom: importing names from outer (for mod tests) scope.
use super::*;
use handlebars::Handlebars;
use serde_json::{Map, Value};
use serde_json::json;

#[test]
fn test_get_scope_open_and_close_char_indexes() {
Expand All @@ -257,19 +257,14 @@ mod tests {

let h = register_merge(h);

let code = String::from(
r#"class A {
let code = r#"
class A {
// Multiline
// Comment
}
"#,
);
let mut map = Map::new();
map.insert(
String::from("previous_file_content"),
Value::String(String::from(code.clone())),
);
let context = Context::from(Value::Object(map));
"#;
let value = json!({"previous_file_content": code});
let context = Context::from(value);
let template = r#"{{#merge previous_file_content}}
{{/merge}}
"#;
Expand All @@ -286,19 +281,13 @@ mod tests {

let h = register_merge(h);

let code = String::from(
r#"class A {
let code = r#"class A {
// Multiline
// Comment
}
"#,
);
let mut map = Map::new();
map.insert(
String::from("previous_file_content"),
Value::String(String::from(code)),
);
let context = Context::from(Value::Object(map));
"#;
let value = json!({"previous_file_content": code});
let context = Context::from(value);
let template = r#"
{{#merge previous_file_content}}
{{#match_scope "class A {"}}
Expand Down Expand Up @@ -330,8 +319,7 @@ class A {

let h = register_merge(h);

let code = String::from(
r#"export class A {
let code = r#"export class A {
nestedFn1() {
// First line
}
Expand All @@ -341,21 +329,13 @@ export class B {
// First line
}
}
"#,
);
let mut map = Map::new();
map.insert(
String::from("previous_file_content"),
Value::String(String::from(code)),
);
map.insert(
String::from("class_functions"),
Value::Array(vec![
Value::String(String::from("nestedFn2")),
Value::String(String::from("nestedFn3")),
]),
);
let context = Context::from(Value::Object(map));
"#;
let value = json!({
"previous_file_content": code,
"class_functions": ["nestedFn2", "nestedFn3"]
});

let context = Context::from(value);
let template = r#"{{#merge previous_file_content}}
{{#match_scope "export class B {"}}
{{#merge untrimmed_previous_scope_content}}
Expand Down
4 changes: 3 additions & 1 deletion templates/lit/web-app/ui/.gitignore.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
.DS_Store

## npm
/node_modules/
/**/node_modules/
/npm-debug.log

## testing
Expand All @@ -19,6 +19,8 @@
/_site/
/dist/
/out-tsc/
/target/
/.cargo

storybook-static
.rollup.cache
Expand Down
3 changes: 2 additions & 1 deletion templates/svelte/web-app/ui/.gitignore.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
.DS_Store

## npm
/node_modules/
/**/node_modules/
/npm-debug.log

## testing
Expand All @@ -19,6 +19,7 @@
/_site/
/dist/
/out-tsc/
/target/

storybook-static
.rollup.cache
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub enum EntryTypes {
Hello(Hello),
}

/// Definition of a link type to be used for linking from an anchor to all created entreis
/// Definition of a link type to be used for linking from an anchor to all created entries
#[derive(Serialize, Deserialize)]
#[hdk_link_types]
pub enum LinkTypes {
Expand Down
3 changes: 2 additions & 1 deletion templates/vanilla/web-app/.gitignore.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
.DS_Store

## npm
/node_modules/
/**/node_modules/
/npm-debug.log

## testing
Expand All @@ -19,6 +19,7 @@
/_site/
/dist/
/out-tsc/
/target/

storybook-static
.rollup.cache
Expand Down
3 changes: 2 additions & 1 deletion templates/vue/web-app/ui/.gitignore.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
.DS_Store

## npm
/node_modules/
/**/node_modules/
/npm-debug.log

## testing
Expand All @@ -19,6 +19,7 @@
/_site/
/dist/
/out-tsc/
/target/

storybook-static
.rollup.cache
Expand Down