Skip to content

Commit

Permalink
Merge branch 'main' into avery/dont-warn
Browse files Browse the repository at this point in the history
  • Loading branch information
EverlastingBugstopper authored Apr 11, 2022
2 parents deeeca4 + 60b0b75 commit 0e3949d
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 63 deletions.
31 changes: 31 additions & 0 deletions crates/houston/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use directories_next::ProjectDirs;
use serde::{Deserialize, Serialize};

use crate::HoustonProblem;

Expand Down Expand Up @@ -67,6 +68,36 @@ impl Config {
fs::remove_dir_all(&self.home)
.map_err(|_| HoustonProblem::NoConfigFound(self.home.to_string()))
}

/// Writes elv2 = "accept" to self.home.join("elv2.toml")
pub fn accept_elv2_license(&self) -> Result<(), HoustonProblem> {
let toml_path = self.get_elv2_toml_path();
let elv2_toml = Elv2Toml { did_accept: true };
let contents = toml::to_string(&elv2_toml)?;
std::fs::write(&toml_path, &contents)?;
Ok(())
}

/// Retrieves the value of sefl.home.join("elv2.toml")
pub fn did_accept_elv2_license(&self) -> bool {
let toml_path = self.get_elv2_toml_path();
if let Ok(contents) = std::fs::read_to_string(&toml_path) {
if let Ok(elv2_toml) = toml::from_str::<Elv2Toml>(&contents) {
eprintln!("{}", &elv2_toml.did_accept);
return elv2_toml.did_accept;
}
}
false
}

fn get_elv2_toml_path(&self) -> Utf8PathBuf {
self.home.join("elv2_license.toml")
}
}

#[derive(Serialize, Deserialize)]
struct Elv2Toml {
did_accept: bool,
}

#[cfg(test)]
Expand Down
37 changes: 12 additions & 25 deletions installers/npm/binary.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ const os = require("os");
const cTable = require("console.table");
const libc = require("detect-libc");
const { join } = require("path");
const { spawnSync } = require("child_process");
const { configureProxy } = require("axios-proxy-builder");

const error = (msg) => {
Expand Down Expand Up @@ -112,33 +111,21 @@ const run = () => {

const install = () => {
const binary = getBinary();

const proxy = configureProxy(binary.url);

binary.install(proxy);

let pluginInstallCommand = `${binary.binaryPath} install --plugin`;
let commands = [
`${pluginInstallCommand} supergraph@latest-0`,
`${pluginInstallCommand} supergraph@latest-2`,
];
for (command of commands) {
try {
spawnSync(command, {
stdio: "inherit",
shell: true,
});
} catch (e) {
console.error(
`'${command.replace(
binary.binaryPath,
binary.name
)}' failed with message '${
e.message
}'. 'rover supergraph compose' might not work properly on your machine.`
);
}
}
// use setTimeout so the message prints after the install happens.
setTimeout(() => {
// these messages are duplicated in `src/command/install/mod.rs`
// for the curl installer.
console.log(
"If you would like to disable Rover's anonymized usage collection, you can set APOLLO_TELEMETRY_DISABLED=1"
);
console.log(
"You can check out our documentation at https://go.apollo.dev/r/docs."
),
400;
});
};

module.exports = {
Expand Down
13 changes: 0 additions & 13 deletions installers/npm/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,3 @@

const { install } = require("./binary");
install();

// use setTimeout so the message prints after the install happens.zzs
setTimeout(() => {
// these messages are duplicated in `src/command/install/mod.rs`
// for the curl installer.
console.log(
"If you would like to disable Rover's anonymized usage collection, you can set APOLLO_TELEMETRY_DISABLED=1"
);
console.log(
"You can check out our documentation at https://go.apollo.dev/r/docs."
),
400;
});
44 changes: 19 additions & 25 deletions src/command/install/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,24 +43,38 @@ impl Install {
override_install_path: Option<Utf8PathBuf>,
client_config: StudioClientConfig,
) -> Result<RoverOutput> {
let accept_elv2_license = if let Some(elv2_license_accepted) = self.elv2_license_accepted {
if elv2_license_accepted {
client_config.config.accept_elv2_license()?;
true
} else {
false
}
} else {
client_config.config.did_accept_elv2_license()
};

let client = client_config.get_reqwest_client();
let binary_name = PKG_NAME.to_string();
let installer =
self.get_installer(binary_name.to_string(), override_install_path.clone())?;
let installer = self.get_installer(binary_name.to_string(), override_install_path)?;

if let Some(plugin) = &self.plugin {
let plugin_name = plugin.get_name();

let requires_elv2_license = plugin.requires_elv2_license();
let install_location = installer
.install_plugin(
&plugin_name,
&plugin.get_tarball_url()?,
plugin.requires_elv2_license(),
self.elv2_license_accepted.unwrap_or(false),
requires_elv2_license,
accept_elv2_license,
&client,
None,
)
.with_context(|| format!("Could not install {}", &plugin_name))?;
if requires_elv2_license && !accept_elv2_license {
// we made it past the install, which means they accepted the y/N prompt
client_config.config.accept_elv2_license()?;
}
let plugin_name = format!("{}-{}", &plugin_name, &plugin.get_major_version());
if install_location.is_some() {
eprintln!("{} was successfully installed. Great!", &plugin_name);
Expand Down Expand Up @@ -109,26 +123,6 @@ impl Install {
eprintln!("{} was not installed. To override the existing installation, you can pass the `--force` flag to the installer.", &binary_name);
}

if cfg!(feature = "composition-js") && self.plugin.is_none() {
eprintln!("installing 'rover supergraph compose' plugins... ");
let mut plugin_installer = Install {
force: self.force,
plugin: Some(Plugin::Supergraph(FederationVersion::LatestFedOne)),
elv2_license_accepted: self.elv2_license_accepted,
};
plugin_installer.get_versioned_plugin(
override_install_path.clone(),
client_config.clone(),
false,
)?;
plugin_installer.plugin = Some(Plugin::Supergraph(FederationVersion::LatestFedTwo));
plugin_installer.get_versioned_plugin(
override_install_path,
client_config,
false,
)?;
eprintln!("done installing plugins!");
}
Ok(RoverOutput::EmptySuccess)
}
}
Expand Down

0 comments on commit 0e3949d

Please sign in to comment.