@browsersync/bslive 0.0.7 → 0.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (155) hide show
  1. package/Cargo.toml +31 -2
  2. package/bin.js +3 -2
  3. package/bslive/Cargo.toml +16 -1
  4. package/bslive/build.rs +1 -1
  5. package/bslive/src/lib.rs +125 -4
  6. package/bsnext/Cargo.toml +21 -0
  7. package/bsnext/src/main.rs +116 -0
  8. package/crates/bsnext_client/Cargo.toml +8 -0
  9. package/crates/bsnext_client/build.rs +53 -0
  10. package/crates/bsnext_client/generated/dto.ts +147 -0
  11. package/crates/bsnext_client/generated/schema.ts +237 -0
  12. package/crates/bsnext_client/inject/dist/index.js +6540 -0
  13. package/crates/bsnext_client/inject/package.json +12 -0
  14. package/crates/bsnext_client/inject/src/console.ts +25 -0
  15. package/crates/bsnext_client/inject/src/index.ts +73 -0
  16. package/crates/bsnext_client/package-lock.json +2145 -0
  17. package/crates/bsnext_client/package.json +27 -0
  18. package/crates/bsnext_client/src/lib.rs +11 -0
  19. package/crates/bsnext_client/tsconfig.json +22 -0
  20. package/crates/bsnext_client/ui/dist/index.css +78 -0
  21. package/crates/bsnext_client/ui/dist/index.js +997 -0
  22. package/crates/bsnext_client/ui/index.html +18 -0
  23. package/crates/bsnext_client/ui/input.yml +19 -0
  24. package/crates/bsnext_client/ui/package.json +18 -0
  25. package/crates/bsnext_client/ui/src/components/bs-debug.ts +27 -0
  26. package/crates/bsnext_client/ui/src/components/bs-header.ts +33 -0
  27. package/crates/bsnext_client/ui/src/components/bs-icon.ts +101 -0
  28. package/crates/bsnext_client/ui/src/components/bs-server-detail.ts +21 -0
  29. package/crates/bsnext_client/ui/src/components/bs-server-identity.ts +24 -0
  30. package/crates/bsnext_client/ui/src/components/bs-server-list.ts +39 -0
  31. package/crates/bsnext_client/ui/src/index.ts +39 -0
  32. package/crates/bsnext_client/ui/styles/base.css.ts +17 -0
  33. package/crates/bsnext_client/ui/styles/reset.css +52 -0
  34. package/crates/bsnext_client/ui/styles/style.css +29 -0
  35. package/crates/bsnext_client/ui/svg/wordmark-white.svg +38 -0
  36. package/crates/bsnext_core/Cargo.toml +44 -0
  37. package/crates/bsnext_core/src/common_layers.rs +62 -0
  38. package/crates/bsnext_core/src/dir_loader.rs +230 -0
  39. package/crates/bsnext_core/src/dto.rs +341 -0
  40. package/crates/bsnext_core/src/handlers/mod.rs +1 -0
  41. package/crates/bsnext_core/src/handlers/proxy.rs +95 -0
  42. package/crates/bsnext_core/src/lib.rs +12 -0
  43. package/crates/bsnext_core/src/meta/mod.rs +5 -0
  44. package/crates/bsnext_core/src/not_found/mod.rs +1 -0
  45. package/crates/bsnext_core/src/not_found/not_found_service.rs +35 -0
  46. package/crates/bsnext_core/src/panic_handler.rs +32 -0
  47. package/crates/bsnext_core/src/raw_loader.rs +196 -0
  48. package/crates/bsnext_core/src/server/actor.rs +92 -0
  49. package/crates/bsnext_core/src/server/error.rs +41 -0
  50. package/crates/bsnext_core/src/server/handler_change.rs +85 -0
  51. package/crates/bsnext_core/src/server/handler_listen.rs +163 -0
  52. package/crates/bsnext_core/src/server/handler_patch.rs +42 -0
  53. package/crates/bsnext_core/src/server/handler_routes_updated.rs +27 -0
  54. package/crates/bsnext_core/src/server/handler_stop.rs +38 -0
  55. package/crates/bsnext_core/src/server/mod.rs +10 -0
  56. package/crates/bsnext_core/src/server/router/assets.rs +39 -0
  57. package/crates/bsnext_core/src/server/router/mod.rs +123 -0
  58. package/crates/bsnext_core/src/server/router/pub_api.rs +39 -0
  59. package/crates/bsnext_core/src/server/router/snapshots/bsnext_core__server__router__tests__test__handlers.snap +9 -0
  60. package/crates/bsnext_core/src/server/router/tests.rs +209 -0
  61. package/crates/bsnext_core/src/server/signals.rs +11 -0
  62. package/crates/bsnext_core/src/server/state.rs +23 -0
  63. package/crates/bsnext_core/src/servers_supervisor/actor.rs +199 -0
  64. package/crates/bsnext_core/src/servers_supervisor/file_changed_handler.rs +41 -0
  65. package/crates/bsnext_core/src/servers_supervisor/get_servers_handler.rs +24 -0
  66. package/crates/bsnext_core/src/servers_supervisor/input_changed_handler.rs +21 -0
  67. package/crates/bsnext_core/src/servers_supervisor/mod.rs +6 -0
  68. package/crates/bsnext_core/src/servers_supervisor/start_handler.rs +86 -0
  69. package/crates/bsnext_core/src/servers_supervisor/stop_handler.rs +26 -0
  70. package/crates/bsnext_core/src/ws/mod.rs +164 -0
  71. package/crates/bsnext_example/Cargo.toml +10 -0
  72. package/crates/bsnext_example/src/basic.rs +51 -0
  73. package/crates/bsnext_example/src/lib.rs +26 -0
  74. package/crates/bsnext_example/src/lit.rs +37 -0
  75. package/crates/bsnext_example/src/md.rs +18 -0
  76. package/crates/bsnext_fs/Cargo.toml +22 -0
  77. package/crates/bsnext_fs/src/actor.rs +123 -0
  78. package/crates/bsnext_fs/src/buffered_debounce.rs +166 -0
  79. package/crates/bsnext_fs/src/filter.rs +39 -0
  80. package/crates/bsnext_fs/src/inner_fs_event_handler.rs +94 -0
  81. package/crates/bsnext_fs/src/lib.rs +141 -0
  82. package/crates/bsnext_fs/src/remove_path_handler.rs +46 -0
  83. package/crates/bsnext_fs/src/stop_handler.rs +15 -0
  84. package/crates/bsnext_fs/src/stream.rs +167 -0
  85. package/crates/bsnext_fs/src/test/mod.rs +213 -0
  86. package/crates/bsnext_fs/src/watch_path_handler.rs +67 -0
  87. package/crates/bsnext_fs/src/watcher.rs +349 -0
  88. package/crates/bsnext_input/Cargo.toml +25 -0
  89. package/crates/bsnext_input/src/input_test/mod.rs +185 -0
  90. package/crates/bsnext_input/src/input_test/snapshots/bsnext_input__input_test__deserialize_3_headers.snap +29 -0
  91. package/crates/bsnext_input/src/input_test/snapshots/bsnext_input__input_test__deserialize_3_headers_control.snap +25 -0
  92. package/crates/bsnext_input/src/lib.rs +153 -0
  93. package/crates/bsnext_input/src/md.rs +541 -0
  94. package/crates/bsnext_input/src/paths.rs +64 -0
  95. package/crates/bsnext_input/src/route.rs +189 -0
  96. package/crates/bsnext_input/src/route_manifest.rs +186 -0
  97. package/crates/bsnext_input/src/server_config.rs +88 -0
  98. package/crates/bsnext_input/src/target.rs +7 -0
  99. package/crates/bsnext_input/src/watch_opt_test/mod.rs +68 -0
  100. package/crates/bsnext_input/src/yml.rs +1 -0
  101. package/crates/bsnext_output/Cargo.toml +16 -0
  102. package/crates/bsnext_output/src/json.rs +11 -0
  103. package/crates/bsnext_output/src/lib.rs +25 -0
  104. package/crates/bsnext_output/src/pretty.rs +147 -0
  105. package/crates/bsnext_resp/Cargo.toml +13 -0
  106. package/crates/bsnext_resp/src/js/snippet.html +1 -0
  107. package/crates/bsnext_resp/src/js/ws.js +1 -0
  108. package/crates/bsnext_resp/src/lib.rs +79 -0
  109. package/crates/bsnext_system/Cargo.toml +29 -0
  110. package/crates/bsnext_system/src/args.rs +47 -0
  111. package/crates/bsnext_system/src/lib.rs +227 -0
  112. package/crates/bsnext_system/src/monitor.rs +241 -0
  113. package/crates/bsnext_system/src/monitor_any_watchables.rs +133 -0
  114. package/crates/bsnext_system/src/start_kind/snapshots/bsnext_system__start_kind__start_from_paths__test__test-2.snap +12 -0
  115. package/crates/bsnext_system/src/start_kind/snapshots/bsnext_system__start_kind__start_from_paths__test__test.snap +30 -0
  116. package/crates/bsnext_system/src/start_kind/start_from_example.rs +49 -0
  117. package/crates/bsnext_system/src/start_kind/start_from_inputs.rs +67 -0
  118. package/crates/bsnext_system/src/start_kind/start_from_paths.rs +51 -0
  119. package/crates/bsnext_system/src/start_kind.rs +56 -0
  120. package/crates/bsnext_system/src/startup.rs +51 -0
  121. package/crates/bsnext_tracing/Cargo.toml +10 -0
  122. package/crates/bsnext_tracing/src/lib.rs +127 -0
  123. package/examples/basic/input.yml +5 -0
  124. package/examples/basic/public/index.html +15 -0
  125. package/examples/basic/public/reset.css +52 -0
  126. package/examples/basic/public/script.js +1 -0
  127. package/examples/basic/public/styles.css +3 -0
  128. package/examples/kitchen-sink/a-file.md +1 -0
  129. package/examples/kitchen-sink/api/1.json +1 -0
  130. package/examples/kitchen-sink/api/2.json +3 -0
  131. package/examples/kitchen-sink/app.js +1 -0
  132. package/examples/kitchen-sink/input.html +185 -0
  133. package/examples/kitchen-sink/input.yml +133 -0
  134. package/examples/kitchen-sink/styles-2.css +3 -0
  135. package/examples/lit/index.html +21 -0
  136. package/examples/lit/input.yml +5 -0
  137. package/examples/lit/lit.js +82 -0
  138. package/examples/lit/package-lock.json +62 -0
  139. package/examples/lit/package.json +15 -0
  140. package/examples/md-single/frontmatter.md +35 -0
  141. package/examples/md-single/md-single.md +35 -0
  142. package/examples/openai/.nvm +1 -0
  143. package/examples/openai/build.mjs +21 -0
  144. package/examples/openai/index.html +13 -0
  145. package/examples/openai/input.yml +59 -0
  146. package/examples/openai/package-lock.json +720 -0
  147. package/examples/openai/package.json +21 -0
  148. package/examples/openai/src/index.js +21 -0
  149. package/examples/openai/sse/01.txt +8 -0
  150. package/examples/proxy-simple/input.yml +9 -0
  151. package/examples/single/input.yaml +26 -0
  152. package/index.d.ts +2 -0
  153. package/index.js +2 -1
  154. package/package.json +17 -17
  155. package/run.sh +6 -0
package/Cargo.toml CHANGED
@@ -1,5 +1,34 @@
1
- workspace.members = ["bslive"]
1
+ workspace.members = [
2
+ "bslive",
3
+ "bsnext",
4
+ "crates/*"
5
+ ]
2
6
  workspace.resolver = "2"
3
7
 
4
8
  [workspace.dependencies]
5
- tokio = { version = "1.37.0", features = ["full"] }
9
+ clap = { version = "4.5.3", features = ["derive"] }
10
+ axum = { version = "0.7.4", features = ["ws"] }
11
+ tokio = { version = "1", features = ["full"] }
12
+ tokio-stream = { version = "0.1.15", features = ["sync"] }
13
+ futures = "0.3.30"
14
+ futures-util = { version = "0.3", default-features = false, features = ["sink", "std"] }
15
+ tower = { version = "0.4.13" }
16
+ tower-http = { version = "0.5.0", features = ['trace', 'fs', 'compression-full', 'decompression-full', 'catch-panic', 'cors', 'timeout', 'set-header'] }
17
+ tracing = "0.1.40"
18
+ tracing-subscriber = { version = "0.3.18", features = ["env-filter", "json"] }
19
+ actix = "0.13.1"
20
+ actix-rt = "2.9.0"
21
+ anyhow = "1.0.69"
22
+ serde = { version = "1.0.152", features = ["derive"] }
23
+ serde_yaml = "0.9.33"
24
+ serde_json = "1.0.115"
25
+ thiserror = "1.0.58"
26
+ bytes = "1.6.0"
27
+ http = "1.1.0"
28
+ http-body-util = "0.1.1"
29
+ typeshare = "1"
30
+ random_word = { version = "0.4.3", features = ["en"] }
31
+ toml = { version = "0.8.12" }
32
+ mime_guess = "2.0.4"
33
+ tempfile = "3.10.1"
34
+ insta = { version = "1.38.0", features = ["yaml"] }
package/bin.js CHANGED
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  console.log('from cli package');
3
3
 
4
- const { start } = require("./index.js");
5
- start(process.argv.slice(1)).catch(console.error);
4
+ const { startSync } = require("./index.js");
5
+ let r = startSync(process.argv.slice(1));
6
+ console.log(r);
package/bslive/Cargo.toml CHANGED
@@ -7,10 +7,25 @@ version = "0.0.0"
7
7
  crate-type = ["cdylib"]
8
8
 
9
9
  [dependencies]
10
+ bsnext_core = { path = "../crates/bsnext_core" }
11
+ bsnext_input = { path = "../crates/bsnext_input" }
12
+ bsnext_fs = { path = "../crates/bsnext_fs" }
13
+ bsnext_tracing = { path = "../crates/bsnext_tracing" }
14
+ bsnext_system = { path = "../crates/bsnext_system" }
15
+ bsnext_output = { path = "../crates/bsnext_output" }
16
+
17
+ clap = { workspace = true }
18
+ tokio = { workspace = true }
19
+ tracing = { workspace = true }
20
+ actix = { workspace = true }
21
+ actix-rt = { workspace = true }
22
+ anyhow = { workspace = true }
23
+ serde = { workspace = true }
24
+ serde_json = { workspace = true }
25
+
10
26
  # Default enable napi4 feature, see https://nodejs.org/api/n-api.html#node-api-version-matrix
11
27
  napi = { version = "2.12.2", default-features = false, features = ["napi4", "tokio_rt", "tokio_full"] }
12
28
  napi-derive = "2.12.2"
13
- tokio = { workspace = true }
14
29
 
15
30
  [build-dependencies]
16
31
  napi-build = "2.0.1"
package/bslive/build.rs CHANGED
@@ -1,5 +1,5 @@
1
1
  extern crate napi_build;
2
2
 
3
3
  fn main() {
4
- napi_build::setup();
4
+ napi_build::setup();
5
5
  }
package/bslive/src/lib.rs CHANGED
@@ -3,12 +3,133 @@
3
3
  #[macro_use]
4
4
  extern crate napi_derive;
5
5
 
6
+ use actix::Actor;
7
+ use std::env::current_dir;
8
+ use std::io::Write;
9
+ use std::path::PathBuf;
6
10
  use std::time::Duration;
11
+
12
+ use clap::Parser;
13
+
14
+ use bsnext_core::dto::ExternalEvents;
15
+ use bsnext_output::{OutputWriter, Writers};
16
+ use bsnext_system::args::Args;
17
+ use bsnext_system::start_kind::StartKind;
18
+ use bsnext_system::startup::{DidStart, StartupResult};
19
+ use bsnext_system::{BsSystem, Start};
20
+ use bsnext_tracing::{init_tracing, OutputFormat, WriteOption};
21
+ use tokio::sync::{mpsc, oneshot};
7
22
  use tokio::time::sleep;
8
23
 
9
24
  #[napi]
10
- async fn start(args: Vec<String>) -> napi::bindgen_prelude::Result<i32> {
11
- println!("{:?}", args);
12
- sleep(Duration::from_secs(2)).await;
13
- Ok(32)
25
+ async fn start(_args: Vec<String>) -> napi::bindgen_prelude::Result<i32> {
26
+ eprintln!("async not supported yet");
27
+ sleep(Duration::from_secs(2)).await;
28
+ Ok(32)
29
+ }
30
+
31
+ /// Launch in a blocking way
32
+ #[napi]
33
+ fn start_sync(args: Vec<String>) -> napi::bindgen_prelude::Result<i32> {
34
+ let sys = actix_rt::System::new();
35
+ println!("sync args {:?}", args);
36
+ std::env::set_var("RUST_LIB_BACKTRACE", "0");
37
+ let result = sys.block_on(async move {
38
+ match main_sync(args).await {
39
+ Ok(_) => 0,
40
+ Err(e) => {
41
+ eprintln!("{:?}", e);
42
+ 1
43
+ }
44
+ }
45
+ });
46
+ Ok(result)
47
+ }
48
+
49
+ async fn main_sync(args: Vec<String>) -> Result<(), anyhow::Error> {
50
+ let cwd = PathBuf::from(current_dir().unwrap().to_string_lossy().to_string());
51
+ let args = Args::parse_from(&args);
52
+ let format_clone = args.format;
53
+
54
+ let write_opt = if args.write_log {
55
+ WriteOption::File
56
+ } else {
57
+ WriteOption::None
58
+ };
59
+ init_tracing(args.log_level, args.format, write_opt);
60
+ tracing::debug!("{:#?}", args);
61
+
62
+ let (tx, rx) = oneshot::channel();
63
+ let (startup_oneshot_sender, startup_oneshot_receiver) = oneshot::channel::<StartupResult>();
64
+ let (events_sender, mut events_receiver) = mpsc::channel::<ExternalEvents>(1);
65
+
66
+ let system = BsSystem::new();
67
+ let sys_addr = system.start();
68
+
69
+ let start_kind = StartKind::from_args(args);
70
+
71
+ let start = Start {
72
+ kind: start_kind,
73
+ cwd: Some(cwd),
74
+ ack: tx,
75
+ events_sender,
76
+ startup_oneshot_sender,
77
+ };
78
+
79
+ sys_addr.do_send(start);
80
+
81
+ match startup_oneshot_receiver.await {
82
+ Ok(Ok(DidStart::Started)) => tracing::info!("started..."),
83
+ Ok(Err(e)) => return Err(e.into()),
84
+ Err(e) => return Err(e.into()),
85
+ };
86
+
87
+ let events_handler = tokio::spawn(async move {
88
+ let events = vec![];
89
+ let stdout = &mut std::io::stdout();
90
+ let printer = match format_clone {
91
+ None | Some(OutputFormat::Normal) => Writers::Pretty,
92
+ Some(OutputFormat::Json) => Writers::Json,
93
+ };
94
+ while let Some(evt) = events_receiver.recv().await {
95
+ match printer.handle_event(stdout, &evt) {
96
+ Ok(_v) => {}
97
+ Err(e) => tracing::error!("could not write to stdout {e}"),
98
+ }
99
+ match stdout.flush() {
100
+ Ok(_) => {}
101
+ Err(e) => tracing::error!("could not flush {e}"),
102
+ };
103
+ }
104
+ events
105
+ });
106
+
107
+ match rx.await {
108
+ Ok(_) => {
109
+ tracing::info!("servers ended");
110
+ }
111
+ Err(e) => {
112
+ // dropped? this is ok
113
+ tracing::trace!(?e, "");
114
+ }
115
+ };
116
+
117
+ match events_handler.await {
118
+ Ok(v) => {
119
+ tracing::info!(?v, "events seen");
120
+ let errors = v
121
+ .iter()
122
+ .filter(|e| matches!(e, ExternalEvents::StartupFailed(..)))
123
+ .collect::<Vec<_>>();
124
+ if !errors.is_empty() {
125
+ tracing::info!("stopped for the following reasons");
126
+ for msg in errors {
127
+ tracing::error!(?msg);
128
+ }
129
+ return Err(anyhow::anyhow!("exited..."));
130
+ }
131
+ }
132
+ Err(e) => tracing::error!(?e),
133
+ }
134
+ Ok(())
14
135
  }
@@ -0,0 +1,21 @@
1
+ [package]
2
+ name = "bsnext"
3
+ version = "0.1.0"
4
+ edition = "2021"
5
+
6
+ [dependencies]
7
+ bsnext_core = { path = "../crates/bsnext_core" }
8
+ bsnext_input = { path = "../crates/bsnext_input" }
9
+ bsnext_fs = { path = "../crates/bsnext_fs" }
10
+ bsnext_tracing = { path = "../crates/bsnext_tracing" }
11
+ bsnext_system = { path = "../crates/bsnext_system" }
12
+ bsnext_output = { path = "../crates/bsnext_output" }
13
+
14
+ clap = { workspace = true }
15
+ tokio = { workspace = true }
16
+ tracing = { workspace = true }
17
+ actix = { workspace = true }
18
+ actix-rt = { workspace = true }
19
+ anyhow = { workspace = true }
20
+ serde = { workspace = true }
21
+ serde_json = { workspace = true }
@@ -0,0 +1,116 @@
1
+ use actix::Actor;
2
+ use std::env::current_dir;
3
+ use std::io::Write;
4
+ use std::path::PathBuf;
5
+
6
+ use bsnext_core::dto::ExternalEvents;
7
+ use bsnext_output::{OutputWriter, Writers};
8
+ use bsnext_system::args::Args;
9
+ use bsnext_system::start_kind::StartKind;
10
+ use bsnext_system::startup::{DidStart, StartupResult};
11
+ use bsnext_system::{BsSystem, Start};
12
+ use bsnext_tracing::{init_tracing, OutputFormat, WriteOption};
13
+ use clap::Parser;
14
+ use tokio::sync::{mpsc, oneshot};
15
+
16
+ #[actix_rt::main]
17
+ async fn main() -> Result<(), anyhow::Error> {
18
+ std::env::set_var("RUST_LIB_BACKTRACE", "0");
19
+ let cwd = PathBuf::from(current_dir().unwrap().to_string_lossy().to_string());
20
+ let args = Args::parse();
21
+ let format_clone = args.format;
22
+ let write_opt = if args.write_log {
23
+ WriteOption::File
24
+ } else {
25
+ WriteOption::None
26
+ };
27
+
28
+ init_tracing(args.log_level, args.format, write_opt);
29
+ tracing::debug!("{:#?}", args);
30
+
31
+ let (tx, rx) = oneshot::channel();
32
+ let (startup_oneshot_sender, startup_oneshot_receiver) = oneshot::channel::<StartupResult>();
33
+ let (events_sender, mut events_receiver) = mpsc::channel::<ExternalEvents>(1);
34
+
35
+ let system = BsSystem::new();
36
+ let sys_addr = system.start();
37
+
38
+ let start_kind = StartKind::from_args(args);
39
+
40
+ let start = Start {
41
+ kind: start_kind,
42
+ cwd: Some(cwd),
43
+ ack: tx,
44
+ events_sender,
45
+ startup_oneshot_sender,
46
+ };
47
+
48
+ sys_addr.do_send(start);
49
+
50
+ match startup_oneshot_receiver.await? {
51
+ Ok(DidStart::Started) => tracing::info!("started..."),
52
+ Err(e) => return Err(e.into()),
53
+ };
54
+
55
+ let events_handler = tokio::spawn(async move {
56
+ let events = vec![];
57
+ let stdout = &mut std::io::stdout();
58
+ let printer = match format_clone {
59
+ None | Some(OutputFormat::Normal) => Writers::Pretty,
60
+ Some(OutputFormat::Json) => Writers::Json,
61
+ };
62
+ while let Some(evt) = events_receiver.recv().await {
63
+ tracing::debug!(external_event=?evt);
64
+ match printer.handle_event(stdout, &evt) {
65
+ Ok(_v) => {}
66
+ Err(e) => tracing::error!("could not write to stdout {e}"),
67
+ }
68
+ match stdout.flush() {
69
+ Ok(_) => {}
70
+ Err(e) => tracing::error!("could not flush {e}"),
71
+ };
72
+ // let as_evt = ExternalEvent {
73
+ // level: EventLevel::External,
74
+ // fields: evt,
75
+ // };
76
+ // let json = serde_json::to_string_pretty(&as_evt).unwrap();
77
+ // println!("{json}");
78
+ // match handle_event(stdout, &evt) {
79
+ // Ok(_) => {
80
+ // events.push(evt);
81
+ // }
82
+ // Err(e) => tracing::error!("could not write to stdout {e}"),
83
+ // }
84
+ }
85
+ events
86
+ });
87
+
88
+ match rx.await {
89
+ Ok(_) => {
90
+ tracing::info!("servers ended");
91
+ }
92
+ Err(e) => {
93
+ // dropped? this is ok
94
+ tracing::trace!(?e, "");
95
+ }
96
+ };
97
+
98
+ match events_handler.await {
99
+ Ok(v) => {
100
+ tracing::info!(?v, "events seen");
101
+ let errors = v
102
+ .iter()
103
+ .filter(|e| matches!(e, ExternalEvents::StartupFailed(..)))
104
+ .collect::<Vec<_>>();
105
+ if !errors.is_empty() {
106
+ tracing::info!("stopped for the following reasons");
107
+ for msg in errors {
108
+ tracing::error!(?msg);
109
+ }
110
+ return Err(anyhow::anyhow!("exited..."));
111
+ }
112
+ }
113
+ Err(e) => tracing::error!(?e),
114
+ }
115
+ Ok(())
116
+ }
@@ -0,0 +1,8 @@
1
+ [package]
2
+ name = "bsnext_client"
3
+ version = "0.1.0"
4
+ edition = "2021"
5
+
6
+ # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7
+
8
+ [dependencies]
@@ -0,0 +1,53 @@
1
+ use std::env::current_dir;
2
+ use std::io::Write;
3
+ use std::process::Command;
4
+ use std::{env, io};
5
+
6
+ fn main() {
7
+ if env::var("CI").is_ok() {
8
+ return;
9
+ }
10
+ let curr = current_dir().expect("current dir");
11
+ let root = curr
12
+ .parent()
13
+ .expect("parent")
14
+ .parent()
15
+ .expect("parent 2")
16
+ .to_path_buf();
17
+ let output = Command::new("typeshare")
18
+ .args([
19
+ "crates/bsnext_core",
20
+ "--lang=typescript",
21
+ "--output-file=crates/bsnext_client/generated/dto.ts",
22
+ ])
23
+ .current_dir(&root)
24
+ .output()
25
+ .expect("build types");
26
+
27
+ io::stdout().write_all(&output.stdout).unwrap();
28
+ io::stderr().write_all(&output.stderr).unwrap();
29
+
30
+ assert!(output.status.success());
31
+
32
+ let output = Command::new("npm")
33
+ .args(["run", "schema"])
34
+ .current_dir(root.join("crates").join("bsnext_client"))
35
+ .output()
36
+ .expect("build schema");
37
+
38
+ io::stdout().write_all(&output.stdout).unwrap();
39
+ io::stderr().write_all(&output.stderr).unwrap();
40
+
41
+ assert!(output.status.success());
42
+
43
+ let output = Command::new("npm")
44
+ .args(["run", "build"])
45
+ .current_dir(root.join("crates").join("bsnext_client"))
46
+ .output()
47
+ .expect("sh command failed to start");
48
+
49
+ io::stdout().write_all(&output.stdout).unwrap();
50
+ io::stderr().write_all(&output.stderr).unwrap();
51
+
52
+ assert!(output.status.success());
53
+ }
@@ -0,0 +1,147 @@
1
+ /*
2
+ Generated by typeshare 1.9.2
3
+ */
4
+
5
+ export type RouteKindDTO =
6
+ | { kind: "Html", payload: {
7
+ html: string;
8
+ }}
9
+ | { kind: "Json", payload: {
10
+ json_str: string;
11
+ }}
12
+ | { kind: "Raw", payload: {
13
+ raw: string;
14
+ }}
15
+ | { kind: "Sse", payload: {
16
+ sse: string;
17
+ }}
18
+ | { kind: "Proxy", payload: {
19
+ proxy: string;
20
+ }}
21
+ | { kind: "Dir", payload: {
22
+ dir: string;
23
+ }};
24
+
25
+ export interface RouteDTO {
26
+ path: string;
27
+ kind: RouteKindDTO;
28
+ }
29
+
30
+ export interface ServerDesc {
31
+ routes: RouteDTO[];
32
+ id: string;
33
+ }
34
+
35
+ export type IdentityDTO =
36
+ | { kind: "Both", payload: {
37
+ name: string;
38
+ bind_address: string;
39
+ }}
40
+ | { kind: "Address", payload: {
41
+ bind_address: string;
42
+ }}
43
+ | { kind: "Named", payload: {
44
+ name: string;
45
+ }};
46
+
47
+ export interface ServerDTO {
48
+ id: string;
49
+ identity: IdentityDTO;
50
+ socket_addr: string;
51
+ }
52
+
53
+ export interface GetServersMessageResponse {
54
+ servers: ServerDTO[];
55
+ }
56
+
57
+ export type ServerChange =
58
+ | { kind: "Stopped", payload: {
59
+ bind_address: string;
60
+ }}
61
+ | { kind: "Started", payload?: undefined }
62
+ | { kind: "Patched", payload?: undefined };
63
+
64
+ export interface ServerChangeSetItem {
65
+ identity: IdentityDTO;
66
+ change: ServerChange;
67
+ }
68
+
69
+ export interface ServerChangeSet {
70
+ items: ServerChangeSetItem[];
71
+ }
72
+
73
+ export interface ServersStarted {
74
+ servers_resp: GetServersMessageResponse;
75
+ changeset: ServerChangeSet;
76
+ }
77
+
78
+ export enum EventLevel {
79
+ External = "BSLIVE_EXTERNAL",
80
+ }
81
+
82
+ export type ExternalEvents =
83
+ | { kind: "ServersStarted", payload: ServersStarted }
84
+ | { kind: "Watching", payload: Watching }
85
+ | { kind: "WatchingStopped", payload: StoppedWatching }
86
+ | { kind: "FileChanged", payload: FileChanged }
87
+ | { kind: "FilesChanged", payload: FilesChangedDTO }
88
+ | { kind: "InputFileChanged", payload: FileChanged }
89
+ | { kind: "InputAccepted", payload: InputAccepted }
90
+ | { kind: "StartupFailed", payload: InputErrorDTO };
91
+
92
+ export interface ExternalEvent {
93
+ level: EventLevel;
94
+ fields: ExternalEvents;
95
+ }
96
+
97
+ export interface InputAccepted {
98
+ path: string;
99
+ }
100
+
101
+ export interface FileChanged {
102
+ path: string;
103
+ }
104
+
105
+ export interface FilesChangedDTO {
106
+ paths: string[];
107
+ }
108
+
109
+ export interface DebounceDTO {
110
+ kind: string;
111
+ ms: string;
112
+ }
113
+
114
+ export interface Watching {
115
+ paths: string[];
116
+ debounce: DebounceDTO;
117
+ }
118
+
119
+ export interface StoppedWatching {
120
+ paths: string[];
121
+ }
122
+
123
+ export type InputErrorDTO =
124
+ | { kind: "MissingInputs", payload: string }
125
+ | { kind: "InvalidInput", payload: string }
126
+ | { kind: "NotFound", payload: string }
127
+ | { kind: "InputWriteError", payload: string }
128
+ | { kind: "PathError", payload: string }
129
+ | { kind: "PortError", payload: string }
130
+ | { kind: "DirError", payload: string };
131
+
132
+ export type ClientEvent =
133
+ | { kind: "Change", payload: ChangeDTO };
134
+
135
+ export type ChangeDTO =
136
+ | { kind: "Fs", payload: {
137
+ path: string;
138
+ change_kind: ChangeKind;
139
+ }}
140
+ | { kind: "FsMany", payload: ChangeDTO[] };
141
+
142
+ export enum ChangeKind {
143
+ Changed = "Changed",
144
+ Added = "Added",
145
+ Removed = "Removed",
146
+ }
147
+