-
-
Notifications
You must be signed in to change notification settings - Fork 222
/
appcenter.rs
202 lines (185 loc) · 6.5 KB
/
appcenter.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
use std::env;
use std::ffi::OsStr;
use std::fs;
use anyhow::{anyhow, Result};
use clap::{Arg, ArgMatches, Command};
use console::style;
use if_chain::if_chain;
use log::info;
use crate::api::{Api, NewRelease};
use crate::config::Config;
use crate::utils::appcenter::{get_appcenter_package, get_react_native_appcenter_release};
use crate::utils::args::{validate_distribution, ArgExt};
use crate::utils::file_search::ReleaseFileSearch;
use crate::utils::file_upload::UploadContext;
use crate::utils::sourcemaps::SourceMapProcessor;
pub fn make_command(command: Command) -> Command {
command
.about("Upload react-native projects for AppCenter.")
.org_arg()
.project_arg(false)
.arg(
Arg::new("deployment")
.long("deployment")
.value_name("DEPLOYMENT")
.help("The name of the deployment. [Production, Staging]"),
)
.arg(
Arg::new("bundle_id")
.value_name("BUNDLE_ID")
.long("bundle-id")
.help(
"Explicitly provide the bundle ID instead of \
parsing the source projects. This allows you to push \
codepush releases for iOS on platforms without Xcode or \
codepush releases for Android when you use different \
bundle IDs for release and debug etc.",
),
)
.arg(
Arg::new("version_name")
.value_name("VERSION_NAME")
.long("version-name")
.help("Override version name in release name"),
)
.arg(
Arg::new("dist")
.long("dist")
.value_name("DISTRIBUTION")
.multiple_occurrences(true)
.validator(validate_distribution)
.help("The names of the distributions to publish. Can be supplied multiple times."),
)
.arg(
Arg::new("print_release_name")
.long("print-release-name")
.help("Print the release name instead."),
)
.arg(
Arg::new("release_name")
.value_name("RELEASE_NAME")
.long("release-name")
.conflicts_with_all(&["bundle_id", "version_name"])
.help("Override the entire release-name"),
)
.arg(
Arg::new("app_name")
.value_name("APP_NAME")
.required(true)
.help("The name of the AppCenter application."),
)
.arg(
Arg::new("platform")
.value_name("PLATFORM")
.required(true)
.help("The name of the app platform. [ios, android]"),
)
.arg(
Arg::new("paths")
.value_name("PATH")
.required(true)
.multiple_occurrences(true)
.help("A list of folders with assets that should be processed."),
)
.arg(
Arg::new("wait")
.long("wait")
.help("Wait for the server to fully process uploaded files."),
)
}
pub fn execute(matches: &ArgMatches) -> Result<()> {
let config = Config::current();
let here = env::current_dir()?;
let here_str: &str = &here.to_string_lossy();
let (org, project) = config.get_org_and_project(matches)?;
let app = matches.value_of("app_name").unwrap();
let platform = matches.value_of("platform").unwrap();
let deployment = matches.value_of("deployment").unwrap_or("Staging");
let api = Api::current();
let print_release_name = matches.is_present("print_release_name");
info!(
"Issuing a command for Organization: {} Project: {}",
org, project
);
if !print_release_name {
println!(
"{} Fetching latest AppCenter deployment info",
style(">").dim()
);
}
let package = get_appcenter_package(app, deployment)?;
let release = get_react_native_appcenter_release(
&package,
platform,
matches.value_of("bundle_id"),
matches.value_of("version_name"),
matches.value_of("release_name"),
)?;
if print_release_name {
println!("{}", release);
return Ok(());
}
println!(
"{} Processing react-native AppCenter sourcemaps",
style(">").dim()
);
let mut processor = SourceMapProcessor::new();
for path in matches.values_of("paths").unwrap() {
let entries = fs::read_dir(path)
.map_err(|e| anyhow!(e).context(format!("Failed processing path: \"{}\"", &path)))?;
for entry in entries.flatten() {
if_chain! {
if let Some(filename) = entry.file_name().to_str();
if let Some(ext) = entry.path().extension();
if ext == OsStr::new("jsbundle") ||
ext == OsStr::new("map") ||
ext == OsStr::new("bundle");
then {
let url = format!("~/{}", filename);
processor.add(&url, ReleaseFileSearch::collect_file(entry.path())?)?;
}
}
}
}
processor.rewrite(&[here_str])?;
processor.add_sourcemap_references()?;
let release = api.new_release(
&org,
&NewRelease {
version: (*release).to_string(),
projects: vec![project.to_string()],
..Default::default()
},
)?;
match matches.values_of("dist") {
None => {
println!(
"Uploading sourcemaps for release {} (no distribution value given; use --dist to set distribution value)",
&release.version
);
processor.upload(&UploadContext {
org: &org,
project: Some(&project),
release: &release.version,
dist: None,
wait: matches.is_present("wait"),
})?;
}
Some(dists) => {
for dist in dists {
println!(
"Uploading sourcemaps for release {} distribution {}",
&release.version, dist
);
processor.upload(&UploadContext {
org: &org,
project: Some(&project),
release: &release.version,
dist: Some(dist),
wait: matches.is_present("wait"),
})?;
}
}
}
Ok(())
}