Unverified Commit d6f326af authored by Gaétan Lepage's avatar Gaétan Lepage Committed by GitHub
Browse files

the-unarchiver: init at 4.3.8 (#371773)

parents 2ea7851e 5b3170b1
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
{
  "version": "4.3.8",
  "url": "https://dl.devmate.com/com.macpaw.site.theunarchiver/146/1715865652/TheUnarchiver-146.zip",
  "hash": "sha256-VcgNT7z7KtdAZxya8DS4Kuk323AAh3Mv/2L7LpUS2NU="
}
+41 −0
Original line number Diff line number Diff line
{
  lib,
  stdenvNoCC,
  fetchurl,
  unzip,
}:
let
  info = lib.importJSON ./info.json;
in
stdenvNoCC.mkDerivation (finalAttrs: {
  pname = "the-unarchiver";
  inherit (info) version;

  src = fetchurl { inherit (info) url hash; };

  sourceRoot = ".";
  nativeBuildInputs = [ unzip ];

  installPhase = ''
    runHook preInstall

    mkdir -p $out/Applications
    mv "The Unarchiver.app" $out/Applications

    runHook postInstall
  '';

  passthru.updateScript = ./update/update.mjs;

  meta = {
    description = "Unpacks archive files";
    homepage = "https://theunarchiver.com/";
    license = lib.licenses.unfree;
    maintainers = with lib.maintainers; [ xiaoxiangmoe ];
    platforms = [
      "aarch64-darwin"
      "x86_64-darwin"
    ];
    sourceProvenance = with lib.sourceTypes; [ binaryNativeCode ];
  };
})
+9 −0
Original line number Diff line number Diff line
{
  "compilerOptions": {
    "allowJs": true,
    "checkJs": true,
    "module": "NodeNext",
    "noEmit": true,
    "strict": true
  }
}
+103 −0
Original line number Diff line number Diff line
#!/usr/bin/env nix-shell
/*
#!nix-shell -i node --pure --packages cacert nodejs yq-go nix
*/
import * as assert from "node:assert/strict";
import * as child_process from "node:child_process";
import * as fsPromises from "node:fs/promises";
import * as path from "node:path";

const __dirname = import.meta.dirname;

/** @typedef {{
  rss: {
    channel: {
      item: Array<{
        pubDate: string;
        enclosure: {
          "+@url": string;
          "+@length": string;
          "+@type": string;
          "+@sparkle:version": string;
          "+@sparkle:shortVersionString": string;
        };
      }>
    }
  }
}} UpdatesXmlInfo */

/** @typedef {{
  version: string;
  url: string;
  hash: string;
}} Info */

const UPDATE_URL =
  "https://updateinfo.devmate.com/com.macpaw.site.theunarchiver/updates.xml";

async function main() {
  const filePath = path.join(__dirname, "../info.json");
  /** @type {Info} */
  const oldInfo = JSON.parse(
    await fsPromises.readFile(filePath, { encoding: "utf-8" })
  );

  const response = await fetch(UPDATE_URL);
  assert.ok(response.ok, `Failed to fetch ${UPDATE_URL}`);
  /** @type {UpdatesXmlInfo} */
  const updatesXmlInfo = JSON.parse(
    child_process
      .execSync(`yq eval --input-format=xml --output-format=json`, {
        input: Buffer.from(await response.arrayBuffer()),
      })
      .toString()
  );
  const items = updatesXmlInfo?.rss?.channel?.item;
  assert.ok(Array.isArray(items), "items is required");
  const item = items.sort(
    (a, b) => new Date(b.pubDate).getTime() - new Date(a.pubDate).getTime()
  )[0];
  const {
    "+@url": url,
    "+@sparkle:shortVersionString": version,
    "+@length": fileSize,
  } = item.enclosure;
  assert.ok(url, "url is required");
  assert.ok(version, "version is required");
  assert.ok(fileSize, "fileSize is required");

  if (oldInfo.url === url && oldInfo.version === version) {
    console.log("[update] No updates found");
    return;
  }

  const [prefetchHash, prefetchStorePath] = child_process
    .execSync(`nix-prefetch-url --print-path ${url}`)
    .toString()
    .split("\n");

  const downloadedFileSize = (await fsPromises.stat(prefetchStorePath)).size;
  if (Number(fileSize) !== downloadedFileSize) {
    console.error(
      `File size mismatch: expected ${fileSize}, got ${downloadedFileSize}`
    );
    process.exit(1);
  }
  const hash = child_process
    .execSync(`nix hash convert --hash-algo sha256 --to sri ${prefetchHash}`)
    .toString()
    .trim();
  /** @type {Info} */
  const info = {
    version,
    url,
    hash,
  };
  console.log(`[update] Updating Notion ${oldInfo.version} -> ${info.version}`);
  await fsPromises.writeFile(filePath, JSON.stringify(info, null, 2) + "\n", {
    encoding: "utf-8",
  });
  console.log("[update] Updating Notion complete");
}

main();