Skip to content

Commit

Permalink
Add support to filter the projects to compile
Browse files Browse the repository at this point in the history
  • Loading branch information
tbezman committed Apr 15, 2022
1 parent c95074e commit d041784
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 12 deletions.
40 changes: 28 additions & 12 deletions compiler/Cargo.lock

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

1 change: 1 addition & 0 deletions compiler/crates/relay-bin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ schema-documentation = { path = "../schema-documentation" }
simplelog = "0.10.0"
thiserror = "1.0.30"
tokio = { version = "1.15", features = ["full", "test-util", "tracing"] }
intern = { path = "../intern" }
38 changes: 38 additions & 0 deletions compiler/crates/relay-bin/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

use clap::{ArgEnum, Parser};
use common::ConsoleLogger;
use intern::string_key::{Intern, StringKey};
use log::{error, info};
use relay_compiler::{
build_project::artifact_writer::ArtifactValidationWriter, compiler::Compiler, config::Config,
Expand All @@ -23,6 +24,7 @@ use std::{
env::{self, current_dir},
path::PathBuf,
process::Command,
str::FromStr,
sync::Arc,
};

Expand Down Expand Up @@ -56,6 +58,11 @@ struct CompileCommand {
#[clap(long, short)]
watch: bool,

/// A list of projects to compile.
/// If excluded, all projects will be compiled
#[clap(long)]
projects: Vec<String>,

/// Compile using this config file. If not provided, searches for a config in
/// package.json under the `relay` key or `relay.config.json` files among other up
/// from the current working directory.
Expand Down Expand Up @@ -191,6 +198,35 @@ fn configure_logger(output: OutputKind, terminal_mode: TerminalMode) {
TermLogger::init(log_level, log_config, terminal_mode, ColorChoice::Auto).unwrap();
}

/// Update Config if the `project` flag is set
fn set_project_flag(config: &mut Config, project: Vec<String>) {
if project.is_empty() {
return;
}
for project_config in config.projects.values_mut() {
project_config.enabled = false;
}
for selected_project in project {
let selected_project = selected_project.intern();

if let Some(project_config) = config.projects.get_mut(&selected_project) {
project_config.enabled = true;
} else {
error!(
"Project `{}` not found, available projects: {}.",
selected_project,
config
.projects
.keys()
.map(|name| name.lookup())
.collect::<Vec<_>>()
.join(", ")
);
std::process::exit(1);
}
}
}

async fn handle_compiler_command(command: CompileCommand) -> Result<(), Error> {
configure_logger(command.output, TerminalMode::Mixed);

Expand All @@ -205,6 +241,8 @@ async fn handle_compiler_command(command: CompileCommand) -> Result<(), Error> {

let mut config = get_config(command.config)?;

set_project_flag(&mut config, command.projects);

if command.validate {
config.artifact_writer = Box::new(ArtifactValidationWriter::default());
}
Expand Down

0 comments on commit d041784

Please sign in to comment.