Skip to content

Commit 524a2f4

Browse files
♻️ Sort items recursively
1 parent 192b4ff commit 524a2f4

File tree

1 file changed

+34
-15
lines changed

1 file changed

+34
-15
lines changed

src/index.ts

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,23 @@
11
import { setFailed } from "@actions/core";
2-
import { cosmicSync, config } from "@anandchowdhary/cosmic";
2+
import { config, cosmicSync } from "@anandchowdhary/cosmic";
33
import {
4-
Spotify,
5-
Rescuetime,
6-
LastFm,
7-
PocketCasts,
8-
Wakatime,
94
Clockify,
5+
Goodreads,
106
GoogleFit,
7+
LastFm,
118
OuraRing,
12-
Goodreads,
9+
PocketCasts,
10+
Rescuetime,
11+
Spotify,
1312
Twitter,
13+
Wakatime,
1414
} from "@stethoscope-js/integrations";
15-
import simpleGit from "simple-git";
16-
import { readdir, pathExists, lstat, ensureFile, writeFile } from "fs-extra";
15+
import Dot from "dot-object";
16+
import { ensureFile, lstat, pathExists, readdir, writeFile } from "fs-extra";
1717
import { join } from "path";
1818
import recursiveReaddir from "recursive-readdir";
19-
import Dot from "dot-object";
2019

2120
const dot = new Dot("/");
22-
const git = simpleGit();
2321
cosmicSync("stethoscope");
2422

2523
const items = Object.keys(config("integrations") || {});
@@ -41,7 +39,10 @@ export const run = async () => {
4139
Twitter,
4240
]) {
4341
const integration = new ClassName();
44-
if (items.includes(integration.name) && config("integrations")[integration.name].frequency === "daily") {
42+
if (
43+
items.includes(integration.name) &&
44+
config("integrations")[integration.name].frequency === "daily"
45+
) {
4546
console.log("Updating", integration.name);
4647
await integration.update();
4748
} else {
@@ -65,7 +66,7 @@ export const run = async () => {
6566
const files = (await recursiveReaddir(join(".", "data", category, "summary")))
6667
.map((path) => path.split(`${join(".", "data", category, "summary")}/`)[1])
6768
.sort((a, b) =>
68-
a.localeCompare(b, undefined, {
69+
a.localeCompare(b, "en", {
6970
numeric: true,
7071
sensitivity: "base",
7172
})
@@ -76,8 +77,10 @@ export const run = async () => {
7677
const prefix = path.join("/") === "" ? "root" : path.join("/");
7778
data[prefix] = true;
7879
});
79-
const items = recursivelyClean2(
80-
recursivelyClean1(JSON.parse(JSON.stringify(dot.object(data)).replace(/_check_/g, "")))
80+
const items = recursivelyArrange(
81+
recursivelyClean2(
82+
recursivelyClean1(JSON.parse(JSON.stringify(dot.object(data)).replace(/_check_/g, "")))
83+
)
8184
);
8285
await ensureFile(join(".", "data", category, "api.json"));
8386
await writeFile(join(".", "data", category, "api.json"), JSON.stringify(items, null, 2));
@@ -119,6 +122,22 @@ function recursivelyClean2(items: any) {
119122
return items;
120123
}
121124

125+
function recursivelyArrange(items: any) {
126+
if (Array.isArray(items)) {
127+
items = items.sort((a, b) =>
128+
a.localeCompare(b, "en", {
129+
numeric: true,
130+
sensitivity: "base",
131+
})
132+
);
133+
} else if (typeof items === "object") {
134+
Object.keys(items).forEach((key) => {
135+
items[key] = recursivelyArrange(items[key]);
136+
});
137+
}
138+
return items;
139+
}
140+
122141
run()
123142
.then(() => {})
124143
.catch((error) => {

0 commit comments

Comments
 (0)