Skip to content

Commit e8269ed

Browse files
authored
notion-app: init at 4.2.0 (NixOS#367650)
2 parents da630e7 + 9ffa81f commit e8269ed

File tree

4 files changed

+151
-0
lines changed

4 files changed

+151
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"x86_64-darwin": {
3+
"version": "4.2.0",
4+
"url": "https://desktop-release.notion-static.com/Notion-4.2.0.zip",
5+
"hash": "sha512-FLptPNEtS9fTevSeGC00hDtpgSks+8JtEKRTtWlYPtI0vpA1KqixBdv2OaNSK1W7Krlsl25RpTOl8cJdQxcv4Q=="
6+
},
7+
"aarch64-darwin": {
8+
"version": "4.2.0",
9+
"url": "https://desktop-release.notion-static.com/Notion-arm64-4.2.0.zip",
10+
"hash": "sha512-cxfO3Bm7ZzAQMi0Pdwd3nvQlRPjn4w7j0ojYUCcn660YsBtoVkpNhiuqg9pbWzY0Umh+/8Zig9CGXKjjP94Iww=="
11+
}
12+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
lib,
3+
stdenvNoCC,
4+
fetchurl,
5+
unzip,
6+
}:
7+
let
8+
info =
9+
(builtins.fromJSON (builtins.readFile ./info.json))."${stdenvNoCC.targetPlatform.system}"
10+
or (throw "notion-app: unsupported system ${stdenvNoCC.targetPlatform.system}");
11+
in
12+
stdenvNoCC.mkDerivation (finalAttrs: {
13+
pname = "notion-app";
14+
version = info.version;
15+
16+
src = fetchurl { inherit (info) url hash; };
17+
18+
sourceRoot = ".";
19+
nativeBuildInputs = [ unzip ];
20+
installPhase = ''
21+
runHook preInstall
22+
23+
mkdir -p $out/Applications
24+
mv Notion.app $out/Applications
25+
26+
runHook postInstall
27+
'';
28+
29+
passthru.updateScript = ./update/update.mjs;
30+
31+
meta = {
32+
description = "App to write, plan, collaborate, and get organised";
33+
homepage = "https://www.notion.so/";
34+
license = lib.licenses.unfree;
35+
maintainers = with lib.maintainers; [ xiaoxiangmoe ];
36+
platforms = [
37+
"x86_64-darwin"
38+
"aarch64-darwin"
39+
];
40+
sourceProvenance = with lib.sourceTypes; [ binaryNativeCode ];
41+
};
42+
})
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"compilerOptions": {
3+
"allowJs": true,
4+
"checkJs": true,
5+
"module": "NodeNext",
6+
"noEmit": true,
7+
"strict": true
8+
}
9+
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#!/usr/bin/env nix-shell
2+
/*
3+
#!nix-shell -i node --pure --packages cacert nodejs yq-go
4+
*/
5+
import * as assert from "node:assert/strict";
6+
import * as child_process from "node:child_process";
7+
import * as fsPromises from "node:fs/promises";
8+
import * as path from "node:path";
9+
10+
const __dirname = import.meta.dirname;
11+
12+
/** @typedef {{
13+
version: string;
14+
path: `${string}.zip`;
15+
sha512: string;
16+
releaseDate: string;
17+
files: Array<{ url: string; sha512: string; size: number }>;
18+
}} LiveCheckInfo */
19+
20+
/** @typedef {{
21+
version: string;
22+
url: string;
23+
hash: `sha512-${string}`;
24+
}} Info */
25+
26+
/** @typedef {{
27+
"x86_64-darwin": Info;
28+
"aarch64-darwin": Info;
29+
}} InfoMap */
30+
31+
const BASE_URL = "https://desktop-release.notion-static.com/";
32+
/**
33+
*
34+
* @param {"latest-mac.yml" | "arm64-mac.yml"} liveCheckFile
35+
* @returns {Promise<Info>}
36+
*/
37+
async function getInfo(liveCheckFile) {
38+
const url = /** @type {const} */ (`${BASE_URL}${liveCheckFile}`);
39+
const response = await fetch(url);
40+
assert.ok(response.ok, `Failed to fetch ${url}`);
41+
/** @type {LiveCheckInfo} */
42+
const { version, path, sha512 } = JSON.parse(
43+
child_process
44+
.execSync(`yq eval --output-format=json`, {
45+
input: Buffer.from(await response.arrayBuffer()),
46+
})
47+
.toString()
48+
);
49+
assert.ok(version, "version is required");
50+
assert.ok(path, "path is required");
51+
assert.ok(sha512, "sha512 is required");
52+
return {
53+
version,
54+
url: BASE_URL + path,
55+
hash: `sha512-${sha512}`,
56+
};
57+
}
58+
59+
async function main() {
60+
const filePath = path.join(__dirname, "../info.json");
61+
/** @type {InfoMap} */
62+
const oldInfo = JSON.parse(
63+
await fsPromises.readFile(filePath, { encoding: "utf-8" })
64+
);
65+
/** @type {InfoMap} */
66+
const info = {
67+
"x86_64-darwin": await getInfo("latest-mac.yml"),
68+
"aarch64-darwin": await getInfo("arm64-mac.yml"),
69+
};
70+
if (JSON.stringify(oldInfo) === JSON.stringify(info)) {
71+
console.log("[update] No updates found");
72+
return;
73+
}
74+
const platforms = /** @type {const} */ (["x86_64-darwin", "aarch64-darwin"]);
75+
for (const platform of platforms) {
76+
console.log(
77+
`[update] Updating Notion ${platform} ${oldInfo[platform].version} -> ${info[platform].version}`
78+
);
79+
}
80+
await fsPromises.writeFile(
81+
filePath,
82+
JSON.stringify(info, null, 2) + "\n",
83+
"utf-8"
84+
);
85+
console.log("[update] Updating Notion complete");
86+
}
87+
88+
main();

0 commit comments

Comments
 (0)