Skip to content

Commit e6b13c2

Browse files
committed
small tweaks
1 parent 4119591 commit e6b13c2

File tree

18 files changed

+177
-45
lines changed

18 files changed

+177
-45
lines changed

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ wasm:
22
cd data-wasm && make
33

44
data:
5-
cd data && make -B
5+
cd data && make
66

77
format:
88
cd data && make format
99
cd data-lib && make format
1010
cd data-wasm && make format
11+
cd website && bun run format
1112

1213
lint:
1314
cd data && make lint

README.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,65 @@ A stats website for the Obsidian Eco-System.
44

55
https://www.moritzjung.dev/obsidian-stats/
66

7+
## Project Structure
8+
9+
The project is split into 4 parts.
10+
11+
1. The website located in `website`
12+
2. A shared Rust library in `data-lib`
13+
3. The data collection code in `data`
14+
4. The data analysis code used for the website in `data-wasm`
15+
16+
All collected data is persisted in the `data/out` folder and tracked in Git, except for cloned plugin repos.
17+
18+
The project uses Makefiles that sometimes think targets are up to date. In that case you can add the `-B` flag to the make command.
19+
20+
### How to Build
21+
22+
Requirements:
23+
24+
1. [Bun](https://bun.com/)
25+
2. [Latest Rust Compiler](https://rustup.rs/)
26+
3. [wasm-pack](https://github.com/drager/wasm-pack)
27+
4. Probably be on Linux, idk
28+
29+
To test and build the website locally you first need to build the `data-wasm` folder.
30+
For this you can run `make wasm` in the repo root.
31+
32+
After this you can navigate to the `website` folder and install dependencies with `bun i`.
33+
Then you can run either the dev server with `bun run dev` or build the website via `bun run build`.
34+
35+
### How to Run Data Collection
36+
37+
Requirements:
38+
39+
1. [Latest Rust Compiler](https://rustup.rs/)
40+
2. Probably Linux, idk
41+
3. 10+ minutes of time
42+
43+
Depending on your goal, the first thing you might want to run is `make submodule-update`.
44+
45+
After that you can run the data collection via `make data`.
46+
47+
The data collection consists of multiple phases:
48+
49+
1. Theme Data
50+
1. Read theme data from the `obsidian-releases` repo
51+
2. Build and save theme data to `data/out/theme-data`
52+
2. Plugin Data
53+
1. Read plugin data from the `obsidian-releases` repo, including download data
54+
2. Build plugin, download, and version data
55+
3. Save that data to `data/out/plugin-data`
56+
3. Clone Plugin Repos to `data/out/plugin-repos`
57+
4. Extract extra data from plugin repos to `data/out/plugin-repo-data`
58+
5. Process licenses from `choosealicense.com` to `data/out/licenses.json`
59+
6. Obsidian Releases Data
60+
1. Get release data from GitHub releases, process, and save to `data/out/releases-github-raw`. This data is incremental.
61+
2. Interpolate download data and save to `data/out/releases-github-interpolated`
62+
3. Get the Obsidian changelog, process and save to `data/out/releases-changelog`
63+
64+
Currently you select which steps to run by commenting out the steps that you don't want in `data/src/main.rs`.
65+
766
## Credits
867

968
I want to thank the following people:

data-lib/src/license.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,4 @@ pub struct Licenses {
3737
pub conditions: Vec<String>,
3838
pub limitations: Vec<String>,
3939
pub descriptions: LicenseDescriptionNested,
40-
}
40+
}

data-lib/src/plugin/bundlers.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ impl Bundler {
2222

2323
pub fn get_identifier(&self) -> &'static str {
2424
match self {
25-
Bundler::Esbuild => "ESBuild",
25+
Bundler::Esbuild => "esbuild",
2626
Bundler::Rollup => "Rollup",
2727
Bundler::Webpack => "Webpack",
2828
Bundler::Vite => "Vite",
@@ -31,12 +31,12 @@ impl Bundler {
3131
}
3232

3333
pub fn from_identifier(identifier: &str) -> Option<Self> {
34-
match identifier {
35-
"ESBuild" => Some(Bundler::Esbuild),
36-
"Rollup" => Some(Bundler::Rollup),
37-
"Webpack" => Some(Bundler::Webpack),
38-
"Vite" => Some(Bundler::Vite),
39-
"Turbo" => Some(Bundler::Turbo),
34+
match identifier.to_lowercase().as_str() {
35+
"esbuild" => Some(Bundler::Esbuild),
36+
"rollup" => Some(Bundler::Rollup),
37+
"webpack" => Some(Bundler::Webpack),
38+
"vite" => Some(Bundler::Vite),
39+
"turbo" => Some(Bundler::Turbo),
4040
_ => None,
4141
}
4242
}

data-lib/src/plugin/data_array.rs

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@ use wasm_bindgen::prelude::wasm_bindgen;
44

55
use crate::{
66
common::{
7-
increment_named_data_points, to_percentage, CountMonthlyDataPoint, DownloadDataPoint, HallOfFameDataPoint, InactivityByReleaseDataPoint, IndividualDownloadDataPoint, OverviewDataPoint, RemovedByReleaseDataPoint
7+
CountMonthlyDataPoint, DownloadDataPoint, HallOfFameDataPoint,
8+
InactivityByReleaseDataPoint, IndividualDownloadDataPoint, OverviewDataPoint,
9+
RemovedByReleaseDataPoint, increment_named_data_points, to_percentage,
810
},
911
date::Date,
1012
license::Licenses,
1113
plugin::{
12-
full::FullPluginData, LicenseInfo, NamedDataPoint, PluginData, PluginExtraData, PluginLicenseDataPoints, PluginRepoDataPoints
14+
LicenseInfo, NamedDataPoint, PluginData, PluginExtraData, PluginLicenseDataPoints,
15+
PluginRepoDataPoints, full::FullPluginData,
1316
},
1417
};
1518

@@ -512,13 +515,14 @@ impl PluginDataArrayView {
512515

513516
match &repo_data.file_license {
514517
LicenseInfo::Known(name) => {
515-
let license_data = licenses
516-
.licenses
517-
.iter()
518-
.find(|l| *name == l.spdx_id);
518+
let license_data = licenses.licenses.iter().find(|l| *name == l.spdx_id);
519519

520520
if let Some(license_data) = license_data {
521-
increment_named_data_points(&mut points.licenses, &license_data.spdx_id, 1.0);
521+
increment_named_data_points(
522+
&mut points.licenses,
523+
&license_data.spdx_id,
524+
1.0,
525+
);
522526

523527
for permission in &license_data.permissions {
524528
increment_named_data_points(&mut points.permissions, permission, 1.0);
@@ -531,11 +535,19 @@ impl PluginDataArrayView {
531535
}
532536
} else {
533537
// I think we should never hit this path, as we make sure that the license is known during data extraction.
534-
increment_named_data_points(&mut points.licenses, &LicenseInfo::Unrecognized.to_fancy_string(), 1.0);
538+
increment_named_data_points(
539+
&mut points.licenses,
540+
&LicenseInfo::Unrecognized.to_fancy_string(),
541+
1.0,
542+
);
535543
}
536544
}
537545
other => {
538-
increment_named_data_points(&mut points.licenses, &other.to_fancy_string(), 1.0);
546+
increment_named_data_points(
547+
&mut points.licenses,
548+
&other.to_fancy_string(),
549+
1.0,
550+
);
539551
}
540552
}
541553
});

data-lib/src/plugin/full.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ use crate::{
55
common::{DownloadDataPoint, EntryChangeDataPoint, VersionDataPoint},
66
date::Date,
77
plugin::{
8-
warnings::{get_plugin_warnings, PluginWarning}, FundingUrl, LicenseInfo, PluginData, PluginExtraData, PluginRepoData
8+
FundingUrl, LicenseInfo, PluginData, PluginExtraData, PluginRepoData,
9+
warnings::{PluginWarning, get_plugin_warnings},
910
},
1011
};
1112

data-lib/src/plugin/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,8 @@ impl From<Option<LicenseInfo>> for LicenseInfo {
151151
}
152152
}
153153

154-
155154
impl From<Option<&LicenseInfo>> for LicenseInfo {
156155
fn from(value: Option<&LicenseInfo>) -> Self {
157156
value.cloned().unwrap_or(LicenseInfo::NotFound)
158157
}
159-
}
158+
}

data-lib/src/plugin/warnings.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
use serde::Serialize;
22
use tsify::Tsify;
33

4-
use crate::{commit::StringCommit, date::Date, plugin::{full::FullPluginData, LicenseInfo}};
4+
use crate::{
5+
commit::StringCommit,
6+
date::Date,
7+
plugin::{LicenseInfo, full::FullPluginData},
8+
};
59

610
#[derive(Tsify, Debug, Clone, Serialize)]
711
#[tsify(into_wasm_abi)]

data-lib/src/release/mod.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ pub struct ChangelogDataPoint {
134134
pub number_of_patches: usize,
135135
}
136136

137-
#[derive(Tsify, Debug, Clone, Serialize, Deserialize, Hash, PartialEq, Eq)]
137+
#[derive(Tsify, Debug, Clone, Hash, PartialEq, Eq)]
138138
#[tsify(into_wasm_abi)]
139139
pub enum ChangeLogChangeCategory {
140140
BreakingChange,
@@ -171,6 +171,15 @@ impl ChangeLogChangeCategory {
171171
}
172172
}
173173

174+
impl Serialize for ChangeLogChangeCategory {
175+
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
176+
where
177+
S: serde::Serializer,
178+
{
179+
serializer.serialize_str(&self.to_fancy_string())
180+
}
181+
}
182+
174183
impl From<Option<ChangeLogChangeCategory>> for ChangeLogChangeCategory {
175184
fn from(value: Option<ChangeLogChangeCategory>) -> Self {
176185
value.unwrap_or(ChangeLogChangeCategory::Uncategorized)
@@ -209,7 +218,7 @@ impl From<&str> for ChangeLogChangeCategory {
209218
}
210219
}
211220

212-
#[derive(Tsify, Debug, Clone, Serialize, Deserialize)]
221+
#[derive(Tsify, Debug, Clone, Serialize)]
213222
#[tsify(into_wasm_abi)]
214223
pub struct ChangelogChanges {
215224
pub version: Version,

data/src/plugins/extra.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ use std::{fs, path::Path};
33
use data_lib::{
44
input_data::{ObsCommunityPluginDeprecations, ObsCommunityPluginRemoved},
55
plugin::{
6-
bundlers::Bundler, packages::PackageManager, testing::TestingFramework, LicenseInfo, PluginData, PluginExtraData, PluginRepoData
6+
LicenseInfo, PluginData, PluginExtraData, PluginRepoData, bundlers::Bundler,
7+
packages::PackageManager, testing::TestingFramework,
78
},
89
};
910
use hashbrown::HashMap;
@@ -156,11 +157,13 @@ pub fn extract_data_from_repo(
156157
|| lower_case_file == "license.md"
157158
});
158159

159-
let file_license = license_file.and_then(|file| {
160-
fs::read_to_string(format!("{repo_path}/{file}")).map(|license_text| {
161-
license_comparer.compare(&plugin.id, &license_text)
162-
}).ok()
163-
}).into();
160+
let file_license = license_file
161+
.and_then(|file| {
162+
fs::read_to_string(format!("{repo_path}/{file}"))
163+
.map(|license_text| license_comparer.compare(&plugin.id, &license_text))
164+
.ok()
165+
})
166+
.into();
164167

165168
Ok(PluginRepoData {
166169
uses_typescript,

0 commit comments

Comments
 (0)