# Panics - if it can't create the output file
(input_paths: impl AsRef<[QsyncInput]>, output_path: &Path)
| 547 | /// # Panics |
| 548 | /// - if it can't create the output file |
| 549 | pub fn process(input_paths: impl AsRef<[QsyncInput]>, output_path: &Path) { |
| 550 | let mut state: BuildState = BuildState { |
| 551 | types: String::new(), |
| 552 | hooks: vec![], |
| 553 | unprocessed_files: Vec::<PathBuf>::new(), |
| 554 | is_debug: false, // we should remove this later on and have a global is_debug state, not BuildState-specific is_debug |
| 555 | }; |
| 556 | |
| 557 | state.types.push_str( |
| 558 | r#"/** |
| 559 | Hooks in this file were generated by create-rust-app's query-sync feature. |
| 560 | |
| 561 | You likely have a `qsync.rs` binary in this project which you can use to |
| 562 | regenerate this file. |
| 563 | |
| 564 | To specify a specific a specific return type for a hook, use the |
| 565 | `#[qsync(return_type = "<typescript return type>")]` attribute above |
| 566 | your endpoint functions (which are decorated by the actix_web attributes |
| 567 | (#[get(...)], #[post(...)], etc). |
| 568 | |
| 569 | If it doesn't correctly guess whether it's a mutation or query based on |
| 570 | the actix_web attributes, then you can manually override that by specifying |
| 571 | the mutate property: `#[qsync(mutate=true)]`. |
| 572 | */ |
| 573 | "#, |
| 574 | ); |
| 575 | |
| 576 | state.types.push_str( |
| 577 | "import { UseQueryOptions, useMutation, useQuery, useQueryClient } from 'react-query'\n", |
| 578 | ); |
| 579 | |
| 580 | state |
| 581 | .types |
| 582 | .push_str("\nimport { useAuth } from './hooks/useAuth'\n"); |
| 583 | |
| 584 | for qsync_input in input_paths.as_ref() { |
| 585 | let input_path = qsync_input.path.clone(); |
| 586 | let options = qsync_input.clone().options; |
| 587 | let is_debug = options.is_debug; |
| 588 | let endpoint_prefix = options.url_base; |
| 589 | |
| 590 | if !input_path.exists() { |
| 591 | if is_debug { |
| 592 | println!("Path `{input_path:#?}` does not exist"); |
| 593 | } |
| 594 | |
| 595 | state.unprocessed_files.push(input_path); |
| 596 | continue; |
| 597 | } |
| 598 | |
| 599 | let base_input_path = input_path.clone(); |
| 600 | |
| 601 | if input_path.clone().is_dir() { |
| 602 | for entry in WalkDir::new(input_path.clone()).sort_by_file_name() { |
| 603 | if let Ok(dir_entry) = entry { |
| 604 | let path = dir_entry.into_path(); |
| 605 | |
| 606 | // skip dir files because they're going to be recursively crawled by WalkDir |
no test coverage detected