From 39e1c2da8a0a5bd1e207e485e3177820a489c978 Mon Sep 17 00:00:00 2001 From: Jonathan Irhodia Date: Sun, 29 Sep 2024 18:05:54 +0100 Subject: [PATCH] chore: add basic barebone for CLI (#194) * chore: add basic barebone for CLI * chore: add support for template generation * chore: add module and template reads * chore: add routes * fix issues with tenplate output * fix generic artifact generation issues * remove unused dep * add starter templates * final templates * update starter template * wip on generator * wrap up generator * fix exports * format * clippy * cleanup * cleanup * cleanup --- Cargo.lock | 470 ++++++++++++++---- Cargo.toml | 2 +- crates/Cargo.lock | 353 ++++++++++--- crates/cli/Cargo.toml | 10 +- crates/cli/src/bin/cmd/default.rs | 40 +- crates/cli/src/bin/cmd/generate.rs | 143 ++++++ crates/cli/src/bin/cmd/mod.rs | 18 +- crates/cli/src/bin/cmd/new.rs | 109 ++++ crates/cli/src/bin/cmd/validate.rs | 26 - crates/cli/src/bin/main.rs | 15 +- crates/cli/src/data.rs | 29 +- crates/cli/src/lib.rs | 159 +++++- crates/cli/src/runner.rs | 14 - crates/cli/src/templates/controller.hbs | 20 + crates/cli/src/templates/gate.hbs | 18 + crates/cli/src/templates/middleware.hbs | 19 + crates/cli/src/templates/mod.hbs | 3 + crates/cli/src/templates/module.hbs | 9 + crates/cli/src/templates/route.hbs | 12 + crates/cli/src/templates/service.hbs | 12 + crates/core/src/factory.rs | 2 +- crates/core/src/lib.rs | 2 +- crates/hyper/src/lib.rs | 2 +- crates/swagger/src/lib.rs | 2 +- crates/vercel/src/lib.rs | 2 +- .../version-0.4/providers/index.md | 0 starter-templates/with-basic/Cargo.toml | 8 + starter-templates/with-basic/src/main.rs | 14 + .../with-basic/src/routes/echo_route.rs | 12 + .../with-basic/src/routes/mod.rs | 1 + starter-templates/with-ramhorns/Cargo.toml | 9 + starter-templates/with-ramhorns/src/main.rs | 3 + starter-templates/with-vercel/Cargo.toml | 14 + .../with-vercel/api/[[...all]].rs | 12 + .../with-vercel/public/index.html | 12 + starter-templates/with-vercel/src/main.rs | 3 + 36 files changed, 1281 insertions(+), 298 deletions(-) create mode 100644 crates/cli/src/bin/cmd/generate.rs create mode 100644 crates/cli/src/bin/cmd/new.rs delete mode 100644 crates/cli/src/bin/cmd/validate.rs delete mode 100644 crates/cli/src/runner.rs create mode 100644 crates/cli/src/templates/controller.hbs create mode 100644 crates/cli/src/templates/gate.hbs create mode 100644 crates/cli/src/templates/middleware.hbs create mode 100644 crates/cli/src/templates/mod.hbs create mode 100644 crates/cli/src/templates/module.hbs create mode 100644 crates/cli/src/templates/route.hbs create mode 100644 crates/cli/src/templates/service.hbs delete mode 100644 sites/docs/versioned_docs/version-0.4/providers/index.md create mode 100644 starter-templates/with-basic/Cargo.toml create mode 100644 starter-templates/with-basic/src/main.rs create mode 100644 starter-templates/with-basic/src/routes/echo_route.rs create mode 100644 starter-templates/with-basic/src/routes/mod.rs create mode 100644 starter-templates/with-ramhorns/Cargo.toml create mode 100644 starter-templates/with-ramhorns/src/main.rs create mode 100644 starter-templates/with-vercel/Cargo.toml create mode 100644 starter-templates/with-vercel/api/[[...all]].rs create mode 100644 starter-templates/with-vercel/public/index.html create mode 100644 starter-templates/with-vercel/src/main.rs diff --git a/Cargo.lock b/Cargo.lock index 3e81d50d..6e31451b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -41,12 +41,67 @@ dependencies = [ "libc", ] +[[package]] +name = "anstream" +version = "0.6.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64e15c1ab1f89faffbf04a634d5e1962e9074f2741eef6d97f3c4e322426d526" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "is_terminal_polyfill", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bec1de6f59aedf83baf9ff929c98f2ad654b97c9510f4e70cf6f661d49fd5b1" + +[[package]] +name = "anstyle-parse" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb47de1e80c2b463c735db5b217a0ddc39d612e7ac9e2e96a5aed1f57616c1cb" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d36fc52c7f6c869915e99412912f22093507da8d9e942ceaf66fe4b7c14422a" +dependencies = [ + "windows-sys 0.52.0", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5bf74e1b6e971609db8ca7a9ce79fd5768ab6ae46441c572e46cf596f59e57f8" +dependencies = [ + "anstyle", + "windows-sys 0.52.0", +] + [[package]] name = "anyhow" version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" +[[package]] +name = "arrayvec" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" + [[package]] name = "async-attributes" version = "1.1.2" @@ -239,17 +294,6 @@ version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" -[[package]] -name = "atty" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" -dependencies = [ - "hermit-abi 0.1.19", - "libc", - "winapi", -] - [[package]] name = "auto_enums" version = "0.8.5" @@ -344,6 +388,19 @@ dependencies = [ "rustc-demangle", ] +[[package]] +name = "bae" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33b8de67cc41132507eeece2584804efcb15f85ba516e34c944b7667f480397a" +dependencies = [ + "heck 0.3.3", + "proc-macro-error", + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "base64" version = "0.21.7" @@ -370,11 +427,17 @@ name = "basic_app" version = "0.1.0" dependencies = [ "async-std", - "ngyn", + "ngyn 0.4.5", "ngyn-hyper 0.1.0", "tokio", ] +[[package]] +name = "beef" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a8241f3ebb85c056b509d4327ad0358fbbba6ffb340bf388f26350aeda225b1" + [[package]] name = "bitflags" version = "1.3.2" @@ -422,11 +485,13 @@ dependencies = [ "anyhow", "clap", "console", + "convert_case", + "dialoguer", "exitcode", + "include_dir", + "lazy_static", + "ramhorns", "serde", - "serde_derive", - "serde_json", - "serde_yaml", "tracing", "tracing-subscriber", "tracing-tree", @@ -459,29 +524,37 @@ dependencies = [ [[package]] name = "clap" -version = "3.2.25" +version = "4.5.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ea181bf566f71cb9a5d17a59e1871af638180a18fb0035c92ae62b705207123" +checksum = "3e5a21b8495e732f1b3c364c9949b201ca7bae518c502c80256c96ad79eaf6ac" dependencies = [ - "atty", - "bitflags 1.3.2", - "clap_lex", - "indexmap 1.9.3", - "once_cell", - "strsim 0.10.0", - "termcolor", - "textwrap", + "clap_builder", ] [[package]] -name = "clap_lex" -version = "0.2.4" +name = "clap_builder" +version = "4.5.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5" +checksum = "8cf2dd12af7a047ad9d6da2b6b249759a22a7abc0f474c1dae1777afa4b21a73" dependencies = [ - "os_str_bytes", + "anstream", + "anstyle", + "clap_lex", + "strsim", ] +[[package]] +name = "clap_lex" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1462739cb27611015575c0c11df5df7601141071f07518d56fcc1be504cbec97" + +[[package]] +name = "colorchoice" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3fd119d74b830634cea2a0f58bbd0d54540518a14397557951e79340abc28c0" + [[package]] name = "colored" version = "2.1.0" @@ -526,6 +599,15 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "convert_case" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec182b0ca2f35d8fc196cf3404988fd8b8c739a4d270ff118a398feb0cbec1ca" +dependencies = [ + "unicode-segmentation", +] + [[package]] name = "core-foundation-sys" version = "0.8.6" @@ -617,7 +699,7 @@ dependencies = [ "ident_case", "proc-macro2", "quote", - "strsim 0.11.1", + "strsim", "syn 2.0.77", ] @@ -643,6 +725,18 @@ dependencies = [ "syn 2.0.77", ] +[[package]] +name = "dialoguer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59c6f2989294b9a498d3ad5491a79c6deb604617378e1cdc4bfc1c1361fe2f87" +dependencies = [ + "console", + "shell-words", + "tempfile", + "zeroize", +] + [[package]] name = "diff" version = "0.1.13" @@ -924,7 +1018,7 @@ dependencies = [ "hyper 1.4.0", "juniper", "juniper_hyper", - "ngyn", + "ngyn 0.4.5", "ngyn-hyper 0.1.1", "serde", "serde_json", @@ -981,6 +1075,15 @@ version = "0.14.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" +[[package]] +name = "heck" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c" +dependencies = [ + "unicode-segmentation", +] + [[package]] name = "heck" version = "0.4.1" @@ -993,15 +1096,6 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" -[[package]] -name = "hermit-abi" -version = "0.1.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" -dependencies = [ - "libc", -] - [[package]] name = "hermit-abi" version = "0.3.9" @@ -1208,6 +1302,25 @@ dependencies = [ "unicode-normalization", ] +[[package]] +name = "include_dir" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "923d117408f1e49d914f1a379a309cffe4f18c05cf4e3d12e613a15fc81bd0dd" +dependencies = [ + "include_dir_macros", +] + +[[package]] +name = "include_dir_macros" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7cab85a7ed0bd5f0e76d93846e0147172bed2e2d3f859bcc33a8d9699cad1a75" +dependencies = [ + "proc-macro2", + "quote", +] + [[package]] name = "indexmap" version = "1.9.3" @@ -1249,6 +1362,12 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "is_terminal_polyfill" +version = "1.70.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" + [[package]] name = "itertools" version = "0.12.1" @@ -1447,6 +1566,39 @@ dependencies = [ "value-bag", ] +[[package]] +name = "logos" +version = "0.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff1ceb190eb9bdeecdd8f1ad6a71d6d632a50905948771718741b5461fb01e13" +dependencies = [ + "logos-derive", +] + +[[package]] +name = "logos-codegen" +version = "0.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90be66cb7bd40cb5cc2e9cfaf2d1133b04a3d93b72344267715010a466e0915a" +dependencies = [ + "beef", + "fnv", + "lazy_static", + "proc-macro2", + "quote", + "regex-syntax 0.8.4", + "syn 2.0.77", +] + +[[package]] +name = "logos-derive" +version = "0.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "45154231e8e96586b39494029e58f12f8ffcb5ecf80333a603a13aa205ea8cbd" +dependencies = [ + "logos-codegen", +] + [[package]] name = "macrotest" version = "1.0.13" @@ -1519,10 +1671,23 @@ dependencies = [ "async-trait", "http 1.1.0", "ngyn-hyper 0.1.1", - "ngyn_macros", + "ngyn_macros 0.4.5", "ngyn_shared 0.4.5", ] +[[package]] +name = "ngyn" +version = "0.4.5" +source = "git+https://github.com/ngyn-rs/ngyn?branch=dev#d4d6fa35746c08cb181b7468e28224ffa967cb20" +dependencies = [ + "async-std", + "async-trait", + "http 1.1.0", + "ngyn-hyper 0.1.1 (git+https://github.com/ngyn-rs/ngyn?branch=dev)", + "ngyn_macros 0.4.5 (git+https://github.com/ngyn-rs/ngyn?branch=dev)", + "ngyn_shared 0.4.5 (git+https://github.com/ngyn-rs/ngyn?branch=dev)", +] + [[package]] name = "ngyn-hyper" version = "0.1.0" @@ -1547,6 +1712,18 @@ dependencies = [ "tokio", ] +[[package]] +name = "ngyn-hyper" +version = "0.1.1" +source = "git+https://github.com/ngyn-rs/ngyn?branch=dev#d4d6fa35746c08cb181b7468e28224ffa967cb20" +dependencies = [ + "http-body-util", + "hyper 1.4.0", + "hyper-util", + "ngyn_shared 0.4.5 (git+https://github.com/ngyn-rs/ngyn?branch=dev)", + "tokio", +] + [[package]] name = "ngyn-shuttle" version = "0.1.1" @@ -1559,7 +1736,7 @@ dependencies = [ name = "ngyn-swagger" version = "0.1.0" dependencies = [ - "ngyn", + "ngyn 0.4.5", "ngyn-swagger-macros", "serde", "serde_json", @@ -1585,6 +1762,16 @@ dependencies = [ "vercel_runtime", ] +[[package]] +name = "ngyn-vercel" +version = "0.1.1" +source = "git+https://github.com/ngyn-rs/ngyn?branch=dev#d4d6fa35746c08cb181b7468e28224ffa967cb20" +dependencies = [ + "ngyn_shared 0.4.5 (git+https://github.com/ngyn-rs/ngyn?branch=dev)", + "tokio", + "vercel_runtime", +] + [[package]] name = "ngyn_macros" version = "0.4.5" @@ -1596,6 +1783,17 @@ dependencies = [ "syn 2.0.77", ] +[[package]] +name = "ngyn_macros" +version = "0.4.5" +source = "git+https://github.com/ngyn-rs/ngyn?branch=dev#d4d6fa35746c08cb181b7468e28224ffa967cb20" +dependencies = [ + "http 1.1.0", + "ngyn_shared 0.4.5 (git+https://github.com/ngyn-rs/ngyn?branch=dev)", + "quote", + "syn 2.0.77", +] + [[package]] name = "ngyn_shared" version = "0.4.0" @@ -1627,6 +1825,21 @@ dependencies = [ "url", ] +[[package]] +name = "ngyn_shared" +version = "0.4.5" +source = "git+https://github.com/ngyn-rs/ngyn?branch=dev#d4d6fa35746c08cb181b7468e28224ffa967cb20" +dependencies = [ + "async-trait", + "bytes", + "http 1.1.0", + "http-body-util", + "regex", + "serde", + "serde_json", + "url", +] + [[package]] name = "nu-ansi-term" version = "0.46.0" @@ -1728,12 +1941,6 @@ dependencies = [ "num-traits", ] -[[package]] -name = "os_str_bytes" -version = "6.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2355d85b9a3786f481747ced0e0ff2ba35213a1f9bd406ed906554d7af805a1" - [[package]] name = "overload" version = "0.1.1" @@ -1930,6 +2137,24 @@ dependencies = [ "prost", ] +[[package]] +name = "pulldown-cmark" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76979bea66e7875e7509c4ec5300112b316af87fa7a252ca91c448b32dfe3993" +dependencies = [ + "bitflags 2.6.0", + "memchr", + "pulldown-cmark-escape", + "unicase", +] + +[[package]] +name = "pulldown-cmark-escape" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd348ff538bc9caeda7ee8cad2d1d48236a1f443c1fa3913c6a02fe0043b1dd3" + [[package]] name = "query_map" version = "0.7.0" @@ -1950,6 +2175,34 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "ramhorns" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8adbbcd308f58fe5348325adcb6646b6e04ce53eca4bb1188ea7952aa435c31c" +dependencies = [ + "arrayvec", + "beef", + "fnv", + "logos", + "pulldown-cmark", + "ramhorns-derive", +] + +[[package]] +name = "ramhorns-derive" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74ead572d301d184a2789e9b7460b08aefd70472a448e9e5e54e4124e598c355" +dependencies = [ + "bae", + "fnv", + "heck 0.4.1", + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "rand" version = "0.8.5" @@ -2192,19 +2445,6 @@ dependencies = [ "serde", ] -[[package]] -name = "serde_yaml" -version = "0.9.34+deprecated" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a8b1a1a2ebf674015cc02edccce75287f1a0130d394307b36743c2f5d504b47" -dependencies = [ - "indexmap 2.2.6", - "itoa", - "ryu", - "serde", - "unsafe-libyaml", -] - [[package]] name = "sharded-slab" version = "0.1.7" @@ -2214,6 +2454,12 @@ dependencies = [ "lazy_static", ] +[[package]] +name = "shell-words" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24188a676b6ae68c3b2cb3a01be17fbf7240ce009799bb56d5b1409051e78fde" + [[package]] name = "shuttle-codegen" version = "0.46.0" @@ -2398,12 +2644,6 @@ version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a8348af2d9fc3258c8733b8d9d8db2e56f54b2363a4b5b81585c7875ed65e65" -[[package]] -name = "strsim" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" - [[package]] name = "strsim" version = "0.11.1" @@ -2486,20 +2726,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" [[package]] -name = "termcolor" -version = "1.4.1" +name = "tempfile" +version = "3.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755" +checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" dependencies = [ - "winapi-util", + "cfg-if", + "fastrand 2.1.0", + "once_cell", + "rustix 0.38.34", + "windows-sys 0.59.0", ] -[[package]] -name = "textwrap" -version = "0.16.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23d434d3f8967a09480fb04132ebe0a3e088c173e6d0ee7897abbdf4eab0f8b9" - [[package]] name = "thiserror" version = "1.0.61" @@ -2806,6 +3044,15 @@ version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" +[[package]] +name = "unicase" +version = "2.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7d2d4dafb69621809a81864c9c1b864479e1235c0dd4e199924b9742439ed89" +dependencies = [ + "version_check", +] + [[package]] name = "unicode-bidi" version = "0.3.15" @@ -2828,16 +3075,16 @@ dependencies = [ ] [[package]] -name = "unicode-width" -version = "0.1.13" +name = "unicode-segmentation" +version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0336d538f7abc86d282a4189614dfaa90810dfc2c6f6427eaf88e16311dd225d" +checksum = "f6ccf251212114b54433ec949fd6a7841275f9ada20dddd2f29e9ceea4501493" [[package]] -name = "unsafe-libyaml" -version = "0.2.11" +name = "unicode-width" +version = "0.1.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "673aac59facbab8a9007c7f6108d11f63b603f7cabff99fabf650fea5c32b861" +checksum = "0336d538f7abc86d282a4189614dfaa90810dfc2c6f6427eaf88e16311dd225d" [[package]] name = "untrusted" @@ -2880,6 +3127,12 @@ version = "2.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "daf8dba3b7eb870caf1ddeed7bc9d2a049f3cfdfae7cb521b087cc33ae4c49da" +[[package]] +name = "utf8parse" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" + [[package]] name = "uuid" version = "1.9.1" @@ -2936,9 +3189,9 @@ checksum = "5a84c137d37ab0142f0f2ddfe332651fdbf252e7b7dbb4e67b6c1f1b2e925101" name = "vercel_app" version = "0.2.8" dependencies = [ - "ngyn", + "ngyn 0.4.5", "ngyn-swagger", - "ngyn-vercel", + "ngyn-vercel 0.1.1", "serde", "serde_json", "tokio", @@ -3091,7 +3344,7 @@ name = "weather_api" version = "0.2.0" dependencies = [ "dotenv", - "ngyn", + "ngyn 0.4.5", "ngyn-shuttle", "serde", "serde_json", @@ -3145,15 +3398,6 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" -[[package]] -name = "winapi-util" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d4cc384e1e73b93bafa6fb4f1df8c41695c8a91cf9c4c64358067d15a7b6c6b" -dependencies = [ - "windows-sys 0.52.0", -] - [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" @@ -3187,6 +3431,15 @@ dependencies = [ "windows-targets 0.52.6", ] +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets 0.52.6", +] + [[package]] name = "windows-targets" version = "0.48.5" @@ -3308,6 +3561,33 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" +[[package]] +name = "with-basic" +version = "0.1.0" +dependencies = [ + "ngyn 0.4.5 (git+https://github.com/ngyn-rs/ngyn?branch=dev)", + "tokio", +] + +[[package]] +name = "with-ramhorns" +version = "0.1.0" +dependencies = [ + "ngyn 0.4.5 (git+https://github.com/ngyn-rs/ngyn?branch=dev)", + "ramhorns", + "tokio", +] + +[[package]] +name = "with-vercel" +version = "0.1.0" +dependencies = [ + "ngyn 0.4.5 (git+https://github.com/ngyn-rs/ngyn?branch=dev)", + "ngyn-vercel 0.1.1 (git+https://github.com/ngyn-rs/ngyn?branch=dev)", + "tokio", + "vercel_runtime", +] + [[package]] name = "zeroize" version = "1.8.1" diff --git a/Cargo.toml b/Cargo.toml index a3172747..0c72bf2b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [workspace] -members = ["crates/*", "examples/*"] +members = ["crates/*", "examples/*", "starter-templates/*"] resolver = "2" [workspace.dependencies] diff --git a/crates/Cargo.lock b/crates/Cargo.lock index 60b8d879..0bedd559 100644 --- a/crates/Cargo.lock +++ b/crates/Cargo.lock @@ -41,12 +41,67 @@ dependencies = [ "libc", ] +[[package]] +name = "anstream" +version = "0.6.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64e15c1ab1f89faffbf04a634d5e1962e9074f2741eef6d97f3c4e322426d526" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "is_terminal_polyfill", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bec1de6f59aedf83baf9ff929c98f2ad654b97c9510f4e70cf6f661d49fd5b1" + +[[package]] +name = "anstyle-parse" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb47de1e80c2b463c735db5b217a0ddc39d612e7ac9e2e96a5aed1f57616c1cb" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d36fc52c7f6c869915e99412912f22093507da8d9e942ceaf66fe4b7c14422a" +dependencies = [ + "windows-sys 0.52.0", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5bf74e1b6e971609db8ca7a9ce79fd5768ab6ae46441c572e46cf596f59e57f8" +dependencies = [ + "anstyle", + "windows-sys 0.52.0", +] + [[package]] name = "anyhow" version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" +[[package]] +name = "arrayvec" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" + [[package]] name = "async-attributes" version = "1.1.2" @@ -239,17 +294,6 @@ version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" -[[package]] -name = "atty" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" -dependencies = [ - "hermit-abi 0.1.19", - "libc", - "winapi", -] - [[package]] name = "autocfg" version = "1.3.0" @@ -332,6 +376,19 @@ dependencies = [ "rustc-demangle", ] +[[package]] +name = "bae" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33b8de67cc41132507eeece2584804efcb15f85ba516e34c944b7667f480397a" +dependencies = [ + "heck 0.3.3", + "proc-macro-error", + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "base64" version = "0.21.7" @@ -353,6 +410,12 @@ dependencies = [ "serde", ] +[[package]] +name = "beef" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a8241f3ebb85c056b509d4327ad0358fbbba6ffb340bf388f26350aeda225b1" + [[package]] name = "bitflags" version = "1.3.2" @@ -406,11 +469,13 @@ dependencies = [ "anyhow", "clap", "console", + "convert_case", + "dialoguer", "exitcode", + "include_dir", + "lazy_static", + "ramhorns", "serde", - "serde_derive", - "serde_json", - "serde_yaml", "tracing", "tracing-subscriber", "tracing-tree", @@ -446,28 +511,36 @@ dependencies = [ [[package]] name = "clap" -version = "3.2.25" +version = "4.5.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ea181bf566f71cb9a5d17a59e1871af638180a18fb0035c92ae62b705207123" +checksum = "3e5a21b8495e732f1b3c364c9949b201ca7bae518c502c80256c96ad79eaf6ac" dependencies = [ - "atty", - "bitflags 1.3.2", + "clap_builder", +] + +[[package]] +name = "clap_builder" +version = "4.5.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8cf2dd12af7a047ad9d6da2b6b249759a22a7abc0f474c1dae1777afa4b21a73" +dependencies = [ + "anstream", + "anstyle", "clap_lex", - "indexmap 1.9.3", - "once_cell", "strsim", - "termcolor", - "textwrap", ] [[package]] name = "clap_lex" -version = "0.2.4" +version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5" -dependencies = [ - "os_str_bytes", -] +checksum = "1462739cb27611015575c0c11df5df7601141071f07518d56fcc1be504cbec97" + +[[package]] +name = "colorchoice" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3fd119d74b830634cea2a0f58bbd0d54540518a14397557951e79340abc28c0" [[package]] name = "colored" @@ -513,6 +586,15 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "convert_case" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec182b0ca2f35d8fc196cf3404988fd8b8c739a4d270ff118a398feb0cbec1ca" +dependencies = [ + "unicode-segmentation", +] + [[package]] name = "core-foundation-sys" version = "0.8.7" @@ -575,6 +657,18 @@ dependencies = [ "winapi", ] +[[package]] +name = "dialoguer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59c6f2989294b9a498d3ad5491a79c6deb604617378e1cdc4bfc1c1361fe2f87" +dependencies = [ + "console", + "shell-words", + "tempfile", + "zeroize", +] + [[package]] name = "diff" version = "0.1.13" @@ -883,6 +977,15 @@ version = "0.14.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" +[[package]] +name = "heck" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c" +dependencies = [ + "unicode-segmentation", +] + [[package]] name = "heck" version = "0.4.1" @@ -895,15 +998,6 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" -[[package]] -name = "hermit-abi" -version = "0.1.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" -dependencies = [ - "libc", -] - [[package]] name = "hermit-abi" version = "0.3.9" @@ -1104,6 +1198,25 @@ dependencies = [ "unicode-normalization", ] +[[package]] +name = "include_dir" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "923d117408f1e49d914f1a379a309cffe4f18c05cf4e3d12e613a15fc81bd0dd" +dependencies = [ + "include_dir_macros", +] + +[[package]] +name = "include_dir_macros" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7cab85a7ed0bd5f0e76d93846e0147172bed2e2d3f859bcc33a8d9699cad1a75" +dependencies = [ + "proc-macro2", + "quote", +] + [[package]] name = "indexmap" version = "1.9.3" @@ -1144,6 +1257,12 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "is_terminal_polyfill" +version = "1.70.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" + [[package]] name = "itertools" version = "0.12.1" @@ -1296,6 +1415,39 @@ dependencies = [ "value-bag", ] +[[package]] +name = "logos" +version = "0.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff1ceb190eb9bdeecdd8f1ad6a71d6d632a50905948771718741b5461fb01e13" +dependencies = [ + "logos-derive", +] + +[[package]] +name = "logos-codegen" +version = "0.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90be66cb7bd40cb5cc2e9cfaf2d1133b04a3d93b72344267715010a466e0915a" +dependencies = [ + "beef", + "fnv", + "lazy_static", + "proc-macro2", + "quote", + "regex-syntax 0.8.4", + "syn 2.0.76", +] + +[[package]] +name = "logos-derive" +version = "0.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "45154231e8e96586b39494029e58f12f8ffcb5ecf80333a603a13aa205ea8cbd" +dependencies = [ + "logos-codegen", +] + [[package]] name = "macrotest" version = "1.0.13" @@ -1550,12 +1702,6 @@ dependencies = [ "num-traits", ] -[[package]] -name = "os_str_bytes" -version = "6.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2355d85b9a3786f481747ced0e0ff2ba35213a1f9bd406ed906554d7af805a1" - [[package]] name = "overload" version = "0.1.1" @@ -1755,6 +1901,24 @@ dependencies = [ "prost", ] +[[package]] +name = "pulldown-cmark" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76979bea66e7875e7509c4ec5300112b316af87fa7a252ca91c448b32dfe3993" +dependencies = [ + "bitflags 2.6.0", + "memchr", + "pulldown-cmark-escape", + "unicase", +] + +[[package]] +name = "pulldown-cmark-escape" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd348ff538bc9caeda7ee8cad2d1d48236a1f443c1fa3913c6a02fe0043b1dd3" + [[package]] name = "query_map" version = "0.7.0" @@ -1775,6 +1939,34 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "ramhorns" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8adbbcd308f58fe5348325adcb6646b6e04ce53eca4bb1188ea7952aa435c31c" +dependencies = [ + "arrayvec", + "beef", + "fnv", + "logos", + "pulldown-cmark", + "ramhorns-derive", +] + +[[package]] +name = "ramhorns-derive" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74ead572d301d184a2789e9b7460b08aefd70472a448e9e5e54e4124e598c355" +dependencies = [ + "bae", + "fnv", + "heck 0.4.1", + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "rand" version = "0.8.5" @@ -1972,19 +2164,6 @@ dependencies = [ "serde", ] -[[package]] -name = "serde_yaml" -version = "0.9.34+deprecated" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a8b1a1a2ebf674015cc02edccce75287f1a0130d394307b36743c2f5d504b47" -dependencies = [ - "indexmap 2.4.0", - "itoa", - "ryu", - "serde", - "unsafe-libyaml", -] - [[package]] name = "sharded-slab" version = "0.1.7" @@ -1994,6 +2173,12 @@ dependencies = [ "lazy_static", ] +[[package]] +name = "shell-words" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24188a676b6ae68c3b2cb3a01be17fbf7240ce009799bb56d5b1409051e78fde" + [[package]] name = "shlex" version = "1.3.0" @@ -2163,9 +2348,9 @@ checksum = "7a8348af2d9fc3258c8733b8d9d8db2e56f54b2363a4b5b81585c7875ed65e65" [[package]] name = "strsim" -version = "0.10.0" +version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" [[package]] name = "strum" @@ -2237,20 +2422,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" [[package]] -name = "termcolor" -version = "1.4.1" +name = "tempfile" +version = "3.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755" +checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" dependencies = [ - "winapi-util", + "cfg-if", + "fastrand 2.1.1", + "once_cell", + "rustix 0.38.34", + "windows-sys 0.59.0", ] -[[package]] -name = "textwrap" -version = "0.16.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23d434d3f8967a09480fb04132ebe0a3e088c173e6d0ee7897abbdf4eab0f8b9" - [[package]] name = "thiserror" version = "1.0.63" @@ -2556,6 +2739,15 @@ version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" +[[package]] +name = "unicase" +version = "2.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7d2d4dafb69621809a81864c9c1b864479e1235c0dd4e199924b9742439ed89" +dependencies = [ + "version_check", +] + [[package]] name = "unicode-bidi" version = "0.3.15" @@ -2578,16 +2770,16 @@ dependencies = [ ] [[package]] -name = "unicode-width" -version = "0.1.13" +name = "unicode-segmentation" +version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0336d538f7abc86d282a4189614dfaa90810dfc2c6f6427eaf88e16311dd225d" +checksum = "f6ccf251212114b54433ec949fd6a7841275f9ada20dddd2f29e9ceea4501493" [[package]] -name = "unsafe-libyaml" -version = "0.2.11" +name = "unicode-width" +version = "0.1.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "673aac59facbab8a9007c7f6108d11f63b603f7cabff99fabf650fea5c32b861" +checksum = "0336d538f7abc86d282a4189614dfaa90810dfc2c6f6427eaf88e16311dd225d" [[package]] name = "url" @@ -2607,6 +2799,12 @@ version = "2.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "daf8dba3b7eb870caf1ddeed7bc9d2a049f3cfdfae7cb521b087cc33ae4c49da" +[[package]] +name = "utf8parse" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" + [[package]] name = "uuid" version = "1.10.0" @@ -2807,15 +3005,6 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" -[[package]] -name = "winapi-util" -version = "0.1.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" -dependencies = [ - "windows-sys 0.59.0", -] - [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" diff --git a/crates/cli/Cargo.toml b/crates/cli/Cargo.toml index c4861876..31ff200f 100644 --- a/crates/cli/Cargo.toml +++ b/crates/cli/Cargo.toml @@ -40,17 +40,19 @@ pkg-fmt = "txz" [dependencies] -clap = { version = "3.2.25", features = ["cargo"], optional = true } +clap = { version = "4.5", features = ["cargo"], optional = true } +convert_case = "0.6" +dialoguer = "0.10" serde = "1.0" -serde_json = "1" -serde_derive = "1" -serde_yaml = "^0.9.0" anyhow = "1" console = "^0.15.0" +lazy_static = "1" +ramhorns = "1" exitcode = "^1.1.2" tracing = "^0.1.34" tracing-tree = { version = "0.2.1" } tracing-subscriber = { version = "0.3.1", features = ["env-filter"] } +include_dir = "0.7.4" [features] diff --git a/crates/cli/src/bin/cmd/default.rs b/crates/cli/src/bin/cmd/default.rs index cfa8652e..0f5d41b3 100644 --- a/crates/cli/src/bin/cmd/default.rs +++ b/crates/cli/src/bin/cmd/default.rs @@ -1,45 +1,29 @@ use anyhow::Result; -use clap::{crate_version, ArgAction}; -use clap::{Arg, ArgMatches, Command}; +use clap::{crate_version, Arg, ArgAction}; +use clap::{ArgMatches, Command}; use tracing::info; -pub fn command() -> Command<'static> { +pub fn command() -> Command { Command::new("ngyn ") .version(crate_version!()) - .about("A starter project for Rust") - .arg( - Arg::new("dry_run") - .short('d') - .long("dry-run") - .value_name("EXAMPLE_KEY") - .help("Dry run with examples given in EXAMPLE_KEY"), - ) - .arg( - Arg::new("reporter") - .short('r') - .long("reporter") - .value_name("REPORTER") - .value_parser(["console"]) - .help("Reporter to use (default: 'console')"), - ) - .arg( - Arg::new("no_banner") - .long("no-banner") - .help("Don't show the banner") - .action(ArgAction::SetTrue), - ) + .about("A powerful and flexible web application framework for Rust.") .arg( Arg::new("verbose") .long("verbose") .help("Show details about interactions") .action(ArgAction::SetTrue), ) + .after_help("For more information on a specific command, run 'ngyn help [SUBCOMMAND]' or 'ngyn [SUBCOMMAND] --help'.\n\nDocumentation: https://ngyn.rs/docs\nReport bugs: https://github.com/ngyn-rs/ngyn/issues") } -pub fn run(matches: &ArgMatches) -> Result { +pub fn run(cmd: &mut Command, matches: &ArgMatches) -> Result { info!("default cmd {:?}", matches.get_one::("reporter")); - println!("going to run {}", cargo_ngyn::CMD); - cargo_ngyn::run(); + let version = crate_version!(); + + println!("ngyn {}", version); + + cmd.print_long_help().unwrap(); + Ok(cargo_ngyn::CmdExit { code: exitcode::OK, message: None, diff --git a/crates/cli/src/bin/cmd/generate.rs b/crates/cli/src/bin/cmd/generate.rs new file mode 100644 index 00000000..24feb8bf --- /dev/null +++ b/crates/cli/src/bin/cmd/generate.rs @@ -0,0 +1,143 @@ +use anyhow::Result; +use cargo_ngyn::{generate_file_name, generate_generic, generate_schematic}; +use clap::{Arg, ArgAction, ArgMatches, Command}; +use ramhorns::Content; +use tracing::info; + +/// `ngyn generate` command +/// +/// Allows the generation of schematics and other artifacts such as controllers, services, gates, middlewares, and modules. +pub fn command() -> Command { + Command::new("generate") + .alias("g") + .about("Generate schematics and other artifacts") + .arg( + Arg::new("name") + .short('n') + .long("name") + .value_name("NAME") + .help("Name of the schematic or artifact to generate") + .required(true), + ) + .arg( + Arg::new("dry_run") + .short('d') + .long("dry-run") + .value_name("DRY_RUN") + .action(ArgAction::SetTrue) + .help("Print out the generated files without writing them to disk"), + ) + .arg( + Arg::new("controller") + .short('c') + .long("controller") + .value_name("CONTROLLER") + .action(ArgAction::SetTrue) + .help("Generate a controller to handle requests"), + ) + .arg( + Arg::new("service") + .short('s') + .long("service") + .value_name("SERVICE") + .action(ArgAction::SetTrue) + .help("Generate a service"), + ) + .arg( + Arg::new("module") + .short('m') + .long("module") + .value_name("MODULE") + .action(ArgAction::SetTrue) + .default_value("true") + .help("Generate a module (default)"), + ) + .arg( + Arg::new("middleware") + .short('w') + .long("middleware") + .value_name("MIDDLEWARE") + .action(ArgAction::SetTrue) + .help("Generate a middleware"), + ) + .arg( + Arg::new("gate") + .short('g') + .long("gate") + .value_name("GATE") + .action(ArgAction::SetTrue) + .help("Generate a gate"), + ) + .arg( + Arg::new("route") + .short('r') + .long("route") + .action(ArgAction::SetTrue) + .value_name("ROUTE") + .help("Generate a route"), + ) +} + +pub fn run(_matches: &ArgMatches, subcommand_matches: &ArgMatches) -> Result { + info!( + "generate cmd {:?}", + subcommand_matches.get_one::("name") + ); + + let schematic_name = subcommand_matches.get_one::("name").unwrap(); + let mut services = Vec::new(); + + if let Some(service) = subcommand_matches.get_one::("service") { + if service.is_truthy() { + info!("generate service {:?}", schematic_name); + services.push(generate_file_name(schematic_name, "service")); + generate_schematic(schematic_name, "service", Vec::new())?; + } + } + + if let Some(gate) = subcommand_matches.get_one::("gate") { + if gate.is_truthy() { + info!("generate gate {:?}", schematic_name); + services.push(generate_file_name(schematic_name, "gate")); + generate_schematic(schematic_name, "gate", Vec::new())?; + } + } + + if let Some(middleware) = subcommand_matches.get_one::("middleware") { + if middleware.is_truthy() { + info!("generate middleware {:?}", schematic_name); + services.push(generate_file_name(schematic_name, "middleware")); + generate_generic(schematic_name, "middleware")?; + println!("Generated middleware {schematic_name}"); + } + } + + if let Some(controller) = subcommand_matches.get_one::("controller") { + if controller.is_truthy() { + info!("generate controller {:?}", schematic_name); + generate_schematic(schematic_name, "controller", Vec::new())?; + println!("Generated controller {schematic_name}"); + } + } + + if let Some(route) = subcommand_matches.get_one::("route") { + if route.is_truthy() { + info!("generate route {:?}", schematic_name); + generate_generic(schematic_name, "route")?; + println!("Generated route {schematic_name}") + } + } + + if let Some(module) = subcommand_matches.get_one::("module") { + if module.is_truthy() { + info!("generate module {:?}", schematic_name); + generate_schematic(schematic_name, "module", Vec::new())?; + println!("Generated module {schematic_name}"); + } + } + + Ok(cargo_ngyn::CmdExit { + code: exitcode::OK, + message: None, + }) +} diff --git a/crates/cli/src/bin/cmd/mod.rs b/crates/cli/src/bin/cmd/mod.rs index 580f4c2b..a9e7268c 100644 --- a/crates/cli/src/bin/cmd/mod.rs +++ b/crates/cli/src/bin/cmd/mod.rs @@ -1,30 +1,18 @@ pub mod default; -pub mod validate; +pub mod generate; +pub mod new; use std::process::exit; use anyhow::Result; use cargo_ngyn::CmdExit; use clap::ArgMatches; -use console::{style, Style}; +use console::Style; use tracing::debug; use tracing::metadata::LevelFilter; use tracing_subscriber::prelude::__tracing_subscriber_SubscriberExt; use tracing_subscriber::util::SubscriberInitExt; use tracing_subscriber::{EnvFilter, Registry}; -pub const BANNER: &str = r#" - B A N N E R -"#; -pub fn banner(v: &str, matches: &ArgMatches) { - if !matches.get_flag("no_banner") { - println!( - "{}\n {}", - style(BANNER).magenta(), - style(v).dim() - ); - } -} - pub fn tracing(matches: &ArgMatches) { let level = if matches.get_flag("verbose") { LevelFilter::INFO diff --git a/crates/cli/src/bin/cmd/new.rs b/crates/cli/src/bin/cmd/new.rs new file mode 100644 index 00000000..94f2e8a0 --- /dev/null +++ b/crates/cli/src/bin/cmd/new.rs @@ -0,0 +1,109 @@ +use anyhow::Result; +use clap::{Arg, ArgMatches, Command}; +use convert_case::Casing; +use include_dir::Dir; +use lazy_static::lazy_static; + +lazy_static! { + static ref TEMPLATES: Vec<&'static str> = vec!["basic", "ramhorns", "vercel"]; + static ref TEMPLATES_DIR: Vec> = vec![ + include_dir::include_dir!("./starter-templates/with-basic"), + include_dir::include_dir!("./starter-templates/with-ramhorns"), + include_dir::include_dir!("./starter-templates/with-vercel") + ]; +} + +/// `ngyn new` command +/// +/// Used to create a new project. +pub fn command() -> Command { + Command::new("new") + .alias("n") + .about("Create a new project") + .arg( + Arg::new("name") + .short('n') + .long("name") + .value_name("NAME") + .help("Name of the project to create"), + ) + .arg( + Arg::new("dry_run") + .short('d') + .long("dry-run") + .value_name("DRY_RUN") + .help("Print out the generated files without writing them to disk"), + ) + .arg( + Arg::new("template") + .short('t') + .long("template") + .value_name("TEMPLATE") + .help("Use a template to create the project"), + ) + .arg( + Arg::new("force") + .short('f') + .long("force") + .value_name("FORCE") + .help("Force the creation of the project"), + ) +} + +pub fn run(_matches: &ArgMatches, subcommand_matches: &ArgMatches) -> Result { + if let Some(name) = subcommand_matches.get_one::("name") { + println!("Creating new project: {}", name); + } else { + let name = dialoguer::Input::::new() + .with_prompt("Name of the project to create") + .interact()?; + let name = name.to_case(convert_case::Case::Snake); + + let template = dialoguer::Select::new() + .with_prompt("Use a template to create the project") + .items(&TEMPLATES) + .default(0) + .interact()?; + + let cwd = std::env::current_dir()?; + let project_dir = cwd.join(name); + + let force = if project_dir.exists() { + dialoguer::Confirm::new() + .with_prompt("Project directory already exists. Overwrite?") + .interact()? + } else { + true + }; + + if !force { + return Ok(cargo_ngyn::CmdExit { + code: exitcode::OK, + message: Some("Project directory already exists. Exiting...".to_string()), + }); + } + + // safely remove current project directory and create a new one + if project_dir.exists() { + std::fs::remove_dir_all(&project_dir)?; + } else { + std::fs::create_dir_all(&project_dir)?; + } + + let template_dir = &TEMPLATES_DIR[template]; + let template_files = template_dir.files(); + + for file in template_files { + let file_path = project_dir.join(file.path()); + let file_content = file.contents_utf8().unwrap(); + + std::fs::create_dir_all(file_path.parent().unwrap())?; + std::fs::write(file_path, file_content)?; + } + } + + Ok(cargo_ngyn::CmdExit { + code: exitcode::OK, + message: None, + }) +} diff --git a/crates/cli/src/bin/cmd/validate.rs b/crates/cli/src/bin/cmd/validate.rs deleted file mode 100644 index 7b4cfa53..00000000 --- a/crates/cli/src/bin/cmd/validate.rs +++ /dev/null @@ -1,26 +0,0 @@ -use anyhow::Result; -use clap::{Arg, ArgAction, ArgMatches, Command}; - -pub fn command() -> Command<'static> { - Command::new("validate") - .about("Validate keys") - .arg( - Arg::new("list") - .long("list") - .help("Show provider list") - .action(ArgAction::SetTrue), - ) - .arg( - Arg::new("csv_in") - .long("--csv-in") - .value_name("FILE") - .help("Read providers and params via CSV"), - ) -} - -pub fn run(_matches: &ArgMatches, _subcommand_matches: &ArgMatches) -> Result { - Ok(cargo_ngyn::CmdExit { - code: exitcode::OK, - message: None, - }) -} diff --git a/crates/cli/src/bin/main.rs b/crates/cli/src/bin/main.rs index 5cc4f5f6..639ced53 100644 --- a/crates/cli/src/bin/main.rs +++ b/crates/cli/src/bin/main.rs @@ -4,20 +4,21 @@ mod cmd; fn main() { - let app = cmd::default::command().subcommand(cmd::validate::command()); + let mut app = cmd::default::command() + .subcommand(cmd::generate::command()) + .subcommand(cmd::new::command()); - let v = app.render_version(); - let matches = app.get_matches(); + // let v = app.render_version(); + let matches = app.clone().get_matches(); // use info! or trace! etc. to log - // to instrument use `#[tracing::instrument(level = "trace", skip(session), err)]` cmd::tracing(&matches); - cmd::banner(&v, &matches); let res = matches.subcommand().map_or_else( - || cmd::default::run(&matches), + || cmd::default::run(&mut app, &matches), |tup| match tup { - ("validate", subcommand_matches) => cmd::validate::run(&matches, subcommand_matches), + ("generate", subcommand_matches) => cmd::generate::run(&matches, subcommand_matches), + ("new", subcommand_matches) => cmd::new::run(&matches, subcommand_matches), _ => unreachable!(), }, ); diff --git a/crates/cli/src/data.rs b/crates/cli/src/data.rs index 4b303f4c..a43fed1a 100644 --- a/crates/cli/src/data.rs +++ b/crates/cli/src/data.rs @@ -1,27 +1,22 @@ // use anyhow::anyhow; // use anyhow::Result as AnyResult; -use std::collections::HashMap; - -use serde_derive::{Deserialize, Serialize}; - -#[derive(Debug, Serialize, Deserialize)] -pub struct Definitions { - pub providers: HashMap, -} +use ramhorns::Content; pub struct CmdExit { pub code: exitcode::ExitCode, pub message: Option, } -pub const CMD: &str = r#"hello"#; - -#[cfg(test)] -mod tests { - use super::*; +#[derive(Content)] +pub struct Mods { + pub name: String, + pub suffix: String, +} - #[test] - fn test_foo() { - assert_eq!(CMD.len(), 5); - } +#[derive(Content)] +pub struct Schematic { + pub name: String, + pub mods: Vec, + pub services: Vec, + pub initial: String, } diff --git a/crates/cli/src/lib.rs b/crates/cli/src/lib.rs index 4f61f0d1..8dfe97ea 100644 --- a/crates/cli/src/lib.rs +++ b/crates/cli/src/lib.rs @@ -1,8 +1,159 @@ #![allow(clippy::missing_const_for_fn)] -// #![warn(missing_docs)] // uncomment for docs mod data; -mod runner; -pub use data::{CmdExit, CMD}; +use anyhow::{anyhow, Result}; +use convert_case::Casing; +pub use data::CmdExit; +use data::{Mods, Schematic}; +use tracing::info; -pub use self::runner::run; +pub fn generate_file_name(name: &str, suffix: &str) -> String { + format!("{}_{}", name, suffix).to_case(convert_case::Case::Snake) +} + +fn read_template_file(file_name: &str) -> Result { + match file_name { + "service" => Ok(include_str!("templates/service.hbs").to_string()), + "gate" => Ok(include_str!("templates/gate.hbs").to_string()), + "middleware" => Ok(include_str!("templates/middleware.hbs").to_string()), + "controller" => Ok(include_str!("templates/controller.hbs").to_string()), + "module" => Ok(include_str!("templates/module.hbs").to_string()), + "route" => Ok(include_str!("templates/route.hbs").to_string()), + "mod" => Ok(include_str!("templates/mod.hbs").to_string()), + _ => Err(anyhow!("Template not found")), + } +} + +fn render_mods(mod_path: &str, schematic: &Schematic) -> Result<()> { + let mod_template = read_template_file("mod")?; + let mod_tpl = ramhorns::Template::new(mod_template)?; + + mod_tpl.render_to_file(mod_path, &schematic)?; + Ok(()) +} + +fn render_templates( + schematic_path: &str, + mod_path: &str, + suffix: &str, + schematic: Schematic, +) -> Result { + // read templates to render + let template = read_template_file(suffix)?; + let mod_template = read_template_file("mod")?; + + // parse templates + let tpl = ramhorns::Template::new(template)?; + let mod_tpl = ramhorns::Template::new(mod_template)?; + + mod_tpl.render_to_file(mod_path, &schematic)?; + + tpl.render_to_file( + schematic_path, + &Schematic { + initial: String::default(), + mods: Vec::new(), + ..schematic + }, + ) + .unwrap(); + + Ok(true) +} + +pub fn generate_generic(name: &str, suffix: &str) -> Result { + let cwd = std::env::current_dir()?.to_str().unwrap().to_string(); + let file_name = generate_file_name(name, suffix); + let schematic_root = format!("{}/src/{}s", cwd, suffix); + + // ensure the module directory exists + // if it doesn't, create it + if !std::path::Path::new(&schematic_root).exists() { + info!("Creating new {}s module", suffix); + + std::fs::create_dir_all(&schematic_root)?; + let main_path = format!("{}/src/main.rs", cwd); + let main_content = format!( + "mod {suffix}s;\n{main_content}", + main_content = std::fs::read_to_string(&main_path)? + ); + + // write mods to the main.rs file + info!("Updating main.rs with new module"); + std::fs::write(&main_path, main_content)?; + } + + // path to the module + let schematic_path = format!("{}/{}.rs", schematic_root, file_name); + let mod_path = format!("{}/mod.rs", schematic_root); + + // ensure the mod file exists + // if it doesn't, create it + if !std::path::Path::new(&mod_path).exists() { + std::fs::write(&mod_path, "")?; + } + + let schematic = Schematic { + name: file_name.to_string(), + mods: vec![Mods { + name: file_name.to_string(), + suffix: suffix.to_string(), + }], + services: Vec::new(), + initial: std::fs::read_to_string(&mod_path)?, + }; + + render_templates(&schematic_path, &mod_path, suffix, schematic) +} + +pub fn generate_schematic(name: &str, suffix: &str, services: Vec) -> Result { + let cwd = std::env::current_dir()?.to_str().unwrap().to_string(); + let file_name = generate_file_name(name, suffix); + let schematic_root = format!("{}/src/modules/{}", cwd, name); + + // ensure the module directory exists + // if it doesn't, create it + if !std::path::Path::new(&schematic_root).exists() { + info!("Creating new {} module", name); + std::fs::create_dir_all(&schematic_root)?; + let mod_path = format!("{}/../mod.rs", schematic_root); + let mods = vec![Mods { + name: name.to_string(), + suffix: suffix.to_string(), + }]; + let schmatic = Schematic { + name: name.to_string(), + mods, + services: Vec::new(), + initial: std::fs::read_to_string(&mod_path)?, + }; + + info!("Updating mod.rs with new module"); + render_mods(&mod_path, &schmatic)?; + } + + // path to the module + let schematic_path = format!("{}/{}.rs", schematic_root, file_name); + let mod_path = format!("{}/mod.rs", schematic_root); + + // ensure the mod file exists + // if it doesn't, create it + if !std::path::Path::new(&mod_path).exists() { + std::fs::write(&mod_path, "")?; + } + let mods = vec![Mods { + name: file_name.to_string(), + suffix: file_name.to_case(convert_case::Case::Pascal), + }]; + + info!("Writing out templates {}", mod_path); + + let schematic = Schematic { + name: file_name.to_case(convert_case::Case::Pascal), + mods, + services, + initial: std::fs::read_to_string(&mod_path)?, + }; + + render_templates(&schematic_path, &mod_path, suffix, schematic) +} diff --git a/crates/cli/src/runner.rs b/crates/cli/src/runner.rs deleted file mode 100644 index 1249aac1..00000000 --- a/crates/cli/src/runner.rs +++ /dev/null @@ -1,14 +0,0 @@ -pub fn run() { - println!("running!"); -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_run() { - run(); - assert_eq!(5, 5); - } -} diff --git a/crates/cli/src/templates/controller.hbs b/crates/cli/src/templates/controller.hbs new file mode 100644 index 00000000..4512321c --- /dev/null +++ b/crates/cli/src/templates/controller.hbs @@ -0,0 +1,20 @@ +use ngyn::prelude::*; + +{{#services}} +use super::{{name}}::{{suffix}}; +{{/services}} + +#[controller] +pub struct {{name}} { + {{#services}} + {{name}}: {{suffix}}, + {{/services}} +} + +#[routes] +impl {{name}} { + #[get("/")] + fn index(&self) -> String { + "Hello, world!".to_string() + } +} diff --git a/crates/cli/src/templates/gate.hbs b/crates/cli/src/templates/gate.hbs new file mode 100644 index 00000000..7fb1899b --- /dev/null +++ b/crates/cli/src/templates/gate.hbs @@ -0,0 +1,18 @@ +use ngyn::prelude::*; + +{{#services}} +use super::{{name}}::{{suffix}}; +{{/services}} + +#[injectable] +pub struct {{name}} { +{{#services}} + pub {{name}}: {{suffix}}, +{{/services}} +} + +impl NgynGate for {{name}} { + async fn can_activate(&self, cx: &mut NgynContext, res: &mut NgynResponse) -> bool { + true + } +} \ No newline at end of file diff --git a/crates/cli/src/templates/middleware.hbs b/crates/cli/src/templates/middleware.hbs new file mode 100644 index 00000000..57feeb84 --- /dev/null +++ b/crates/cli/src/templates/middleware.hbs @@ -0,0 +1,19 @@ +use ngyn::prelude::*; + +{{#services}} +use super::{{name}}::{{suffix}}; +{{/services}} + +#[injectable] +pub struct {{name}} { + {{#services}} + #[inject] + pub {{name}}: {{suffix}}, + {{/services}} +} + +impl NgynMiddleware for {{name}} { + fn handle(&self, cx: &mut NgynContext, res: &mut NgynResponse) ) { + println!("{{name}} works!"); + } +} diff --git a/crates/cli/src/templates/mod.hbs b/crates/cli/src/templates/mod.hbs new file mode 100644 index 00000000..eda91dfd --- /dev/null +++ b/crates/cli/src/templates/mod.hbs @@ -0,0 +1,3 @@ +{{#mods}} +pub mod {{name}}; +{{/mods}}{{initial}} \ No newline at end of file diff --git a/crates/cli/src/templates/module.hbs b/crates/cli/src/templates/module.hbs new file mode 100644 index 00000000..69affeaf --- /dev/null +++ b/crates/cli/src/templates/module.hbs @@ -0,0 +1,9 @@ +use ngyn::prelude::*; + +{{#mods}} +use super::{{name}}::{{suffix}}; +{{/mods}} + +#[module(controllers = [{{#mods}}{{suffix}},{{/mods}}])] +/// Module `{{name}}` +pub struct {{name}} {} diff --git a/crates/cli/src/templates/route.hbs b/crates/cli/src/templates/route.hbs new file mode 100644 index 00000000..c90b76e9 --- /dev/null +++ b/crates/cli/src/templates/route.hbs @@ -0,0 +1,12 @@ +use ngyn::prelude::*; + +/// `{{name}}` route +/// +/// # Description +/// This is the `{{name}}` route +/// +/// # Arguments +/// * `_cx` - The context of the current request +pub fn {{name}}<'a>(_cx: &'a mut NgynContext) -> String { + "Process {{name}}".to_string() +} diff --git a/crates/cli/src/templates/service.hbs b/crates/cli/src/templates/service.hbs new file mode 100644 index 00000000..06160734 --- /dev/null +++ b/crates/cli/src/templates/service.hbs @@ -0,0 +1,12 @@ +use ngyn::prelude::*; + +{{#services}} +use super::{{name}}::{{suffix}}; +{{/services}} + +#[injectable] +pub struct {{name}} { + {{#services}} + pub {{name}}: {{suffix}}, + {{/services}} +} diff --git a/crates/core/src/factory.rs b/crates/core/src/factory.rs index 6237abbf..fb764c70 100644 --- a/crates/core/src/factory.rs +++ b/crates/core/src/factory.rs @@ -1,5 +1,5 @@ use ngyn_hyper::HyperApplication; -use ngyn_shared::{core::NgynEngine, traits::NgynModule}; +use ngyn_shared::{core::engine::NgynEngine, traits::NgynModule}; /// The `NgynFactory` struct is used to create instances of `NgynEngine`. pub struct NgynFactory { diff --git a/crates/core/src/lib.rs b/crates/core/src/lib.rs index 5c510e31..eba13f33 100644 --- a/crates/core/src/lib.rs +++ b/crates/core/src/lib.rs @@ -17,7 +17,7 @@ pub mod prelude { pub use crate::macros::*; pub use ngyn_hyper::HyperApplication; pub use ngyn_shared::{ - core::{handler::*, engine::NgynEngine}, + core::{engine::NgynEngine, handler::*}, server::{ Body, JsonResponse, JsonResult, NgynContext, NgynRequest, NgynResponse, Param, Query, Transducer, diff --git a/crates/hyper/src/lib.rs b/crates/hyper/src/lib.rs index a01494c5..5e696f8e 100644 --- a/crates/hyper/src/lib.rs +++ b/crates/hyper/src/lib.rs @@ -3,7 +3,7 @@ use hyper::body::Incoming; use hyper::server::conn::http1; use hyper::{service::service_fn, Request}; use hyper_util::rt::TokioIo; -use ngyn_shared::core::{NgynPlatform, PlatformData}; +use ngyn_shared::core::engine::{NgynPlatform, PlatformData}; use std::sync::Arc; use tokio::net::TcpListener; diff --git a/crates/swagger/src/lib.rs b/crates/swagger/src/lib.rs index fa0debaa..8db2fe9b 100644 --- a/crates/swagger/src/lib.rs +++ b/crates/swagger/src/lib.rs @@ -1,7 +1,7 @@ use std::sync::Arc; use ngyn::shared::{ - core::NgynEngine, + core::engine::NgynEngine, server::NgynResponse, traits::{NgynController, NgynModule}, }; diff --git a/crates/vercel/src/lib.rs b/crates/vercel/src/lib.rs index 39861e00..d0215a38 100644 --- a/crates/vercel/src/lib.rs +++ b/crates/vercel/src/lib.rs @@ -1,5 +1,5 @@ use ngyn_shared::{ - core::{NgynPlatform, PlatformData}, + core::engine::{NgynPlatform, PlatformData}, server::response::ReadBytes, }; use vercel_runtime::{Body, Error, Request, Response as VercelResponse}; diff --git a/sites/docs/versioned_docs/version-0.4/providers/index.md b/sites/docs/versioned_docs/version-0.4/providers/index.md deleted file mode 100644 index e69de29b..00000000 diff --git a/starter-templates/with-basic/Cargo.toml b/starter-templates/with-basic/Cargo.toml new file mode 100644 index 00000000..9c03cec8 --- /dev/null +++ b/starter-templates/with-basic/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "with-basic" +version = "0.1.0" +edition = "2021" + +[dependencies] +ngyn = { git = "https://github.com/ngyn-rs/ngyn", branch = "dev" } +tokio = { version = "1", features = ["full"] } diff --git a/starter-templates/with-basic/src/main.rs b/starter-templates/with-basic/src/main.rs new file mode 100644 index 00000000..41f73cc7 --- /dev/null +++ b/starter-templates/with-basic/src/main.rs @@ -0,0 +1,14 @@ +mod routes; + +use ngyn::prelude::*; +use routes::echo_route::echo_route; + +#[tokio::main] +async fn main() { + let mut app = HyperApplication::default(); + + app.get("/", handler(echo_route)); + + println!("Starting server at http://127.0.0.1:8080"); + let _ = app.listen("0.0.0.0:8080").await; +} diff --git a/starter-templates/with-basic/src/routes/echo_route.rs b/starter-templates/with-basic/src/routes/echo_route.rs new file mode 100644 index 00000000..1a15c841 --- /dev/null +++ b/starter-templates/with-basic/src/routes/echo_route.rs @@ -0,0 +1,12 @@ +use ngyn::prelude::*; + +/// `echo_route` route +/// +/// # Description +/// This is the `echo_route` route +/// +/// # Arguments +/// * `_cx` - The context of the current request +pub fn echo_route(_cx: &mut NgynContext) -> String { + "Process echo_route".to_string() +} diff --git a/starter-templates/with-basic/src/routes/mod.rs b/starter-templates/with-basic/src/routes/mod.rs new file mode 100644 index 00000000..0bc274fc --- /dev/null +++ b/starter-templates/with-basic/src/routes/mod.rs @@ -0,0 +1 @@ +pub mod echo_route; diff --git a/starter-templates/with-ramhorns/Cargo.toml b/starter-templates/with-ramhorns/Cargo.toml new file mode 100644 index 00000000..a943e7d6 --- /dev/null +++ b/starter-templates/with-ramhorns/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "with-ramhorns" +version = "0.1.0" +edition = "2021" + +[dependencies] +ngyn = { git = "https://github.com/ngyn-rs/ngyn", branch = "dev" } +ramhorns = { version = "1" } +tokio = { version = "1", features = ["full"] } diff --git a/starter-templates/with-ramhorns/src/main.rs b/starter-templates/with-ramhorns/src/main.rs new file mode 100644 index 00000000..e7a11a96 --- /dev/null +++ b/starter-templates/with-ramhorns/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +} diff --git a/starter-templates/with-vercel/Cargo.toml b/starter-templates/with-vercel/Cargo.toml new file mode 100644 index 00000000..00cffcc6 --- /dev/null +++ b/starter-templates/with-vercel/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "with-vercel" +version = "0.1.0" +edition = "2021" + +[[bin]] +name = "all" +path = "api/[[...all]].rs" + +[dependencies] +ngyn = { git = "https://github.com/ngyn-rs/ngyn", branch = "dev" } +ngyn-vercel = { git = "https://github.com/ngyn-rs/ngyn", branch = "dev" } +tokio = { version = "1", features = ["full"] } +vercel_runtime = { version = "1.1.0" } diff --git a/starter-templates/with-vercel/api/[[...all]].rs b/starter-templates/with-vercel/api/[[...all]].rs new file mode 100644 index 00000000..3e10a466 --- /dev/null +++ b/starter-templates/with-vercel/api/[[...all]].rs @@ -0,0 +1,12 @@ +use ngyn_vercel::VercelApplication; +use vercel_runtime::{run, Body, Error, Request, Response}; + +#[tokio::main] +async fn main() -> Result<(), Error> { + run(handler).await +} + +pub async fn handler(req: Request) -> Result, Error> { + let app: VercelApplication = VercelApplication::default(); + app.handle(req).await +} diff --git a/starter-templates/with-vercel/public/index.html b/starter-templates/with-vercel/public/index.html new file mode 100644 index 00000000..17a8e53a --- /dev/null +++ b/starter-templates/with-vercel/public/index.html @@ -0,0 +1,12 @@ + + + + + + Vercel Ngyn Starter + + +

Welcome to the Vercel Ngyn Starter

+ See a route served with Ngyn on the Vercel platform + + diff --git a/starter-templates/with-vercel/src/main.rs b/starter-templates/with-vercel/src/main.rs new file mode 100644 index 00000000..e7a11a96 --- /dev/null +++ b/starter-templates/with-vercel/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +}