Skip to content

Commit

Permalink
mqttx-cli: init at 1.10.1
Browse files Browse the repository at this point in the history
  • Loading branch information
pineapplehunter authored and Shogo Takata committed Sep 2, 2024
1 parent 56b912b commit f5a59bb
Show file tree
Hide file tree
Showing 3 changed files with 200 additions and 0 deletions.
77 changes: 77 additions & 0 deletions pkgs/by-name/mq/mqttx-cli/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
{
"name": "mqttx-cli",
"version": "1.10.1",
"description": "MQTTX Command Line Tools",
"keywords": [
"mqtt",
"publish/subscribe",
"publish",
"subscribe"
],
"scripts": {
"dev": "tsc -w",
"build": "tsc"
},
"main": "./dist/src/index.js",
"bin": {
"mqttx": "./bin/index.js"
},
"license": "Apache-2.0",
"engines": {
"node": ">=18"
},
"dependencies": {
"@inquirer/prompts": "^5.0.3",
"axios": "^0.27.2",
"cbor": "^9.0.1",
"chalk": "~4.1.2",
"cli-table3": "^0.6.3",
"commander": "^9.3.0",
"compare-versions": "^5.0.1",
"concat-stream": "^2.0.0",
"core-js": "^3.26.0",
"ini": "^4.1.2",
"js-yaml": "^4.1.0",
"json-bigint": "^1.0.0",
"lodash": "^4.17.21",
"mqtt": "^4.3.7",
"ora": "^5.4.1",
"protobufjs": "^7.2.3",
"pump": "^3.0.0",
"readable-stream": "^3.6.0",
"signale": "^1.4.0",
"split2": "^4.1.0"
},
"devDependencies": {
"@faker-js/faker": "^8.1.0",
"@types/concat-stream": "^2.0.0",
"@types/debug": "^4.1.12",
"@types/ini": "^4.1.0",
"@types/js-yaml": "^4.0.5",
"@types/json-bigint": "^1.0.4",
"@types/lodash": "^4.17.1",
"@types/node": "^17.0.43",
"@types/pump": "^1.1.1",
"@types/readable-stream": "^2.3.13",
"@types/signale": "^1.4.4",
"@types/split2": "^3.2.1",
"@types/ws": "^8.5.3",
"typescript": "^4.7.3"
},
"pkg": {
"targets": [
"node18-linux-x64",
"node18-macos-x64",
"node18-win-x64",
"node18-alpine-x64",
"node18-linux-arm64",
"node18-macos-arm64",
"node18-win-arm64",
"node18-alpine-arm64"
],
"outputPath": "release",
"scripts": [
"dist/src/scenarios/**/*"
]
}
}
62 changes: 62 additions & 0 deletions pkgs/by-name/mq/mqttx-cli/package.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
mkYarnPackage,
fetchYarnDeps,
fetchFromGitHub,
lib,
testers,
mqttx-cli,
}:

mkYarnPackage rec {
pname = "mqttx-cli";
version = "1.10.1";

src = fetchFromGitHub {
owner = "emqx";
repo = "MQTTX";
rev = "v${version}";
hash = "sha256-ge6NpehP/4fEUZMqpDB494ut4OfOEpTZOvQMAX9dB/E=";
};

packageJSON = ./package.json;
yarnLock = "${src}/cli/yarn.lock";

offlineCache = fetchYarnDeps {
yarnLock = "${src}/cli/yarn.lock";
hash = "sha256-WfMKuMCetbrmja5jq3VvEaD7/Z6Nj+/BY7qZiiR8U6g=";
};

preConfigure = ''
cd cli
'';

buildPhase = ''
runHook preBuild
yarn --offline build
runHook postBuild
'';

postInstall = ''
# remove some devDependencies which are using up storage
rm -r $out/libexec/mqttx-cli/node_modules/{typescript,@types}
# rename binary so it does not conflict with the desktop app
mv $out/bin/mqttx $out/bin/mqttx-cli
'';

passthru = {
updateScript = ./update.sh;
tests.version = testers.testVersion { package = mqttx-cli; };
};

meta = {
description = "MQTTX Command Line Tools";
homepage = "https://mqttx.app/";
changelog = "https://mqttx.app/changelogs/v${version}";
license = lib.licenses.asl20;
maintainers = with lib.maintainers; [ pineapplehunter ];
platforms = lib.platforms.all;
mainProgram = "mqttx-cli";
};
}
61 changes: 61 additions & 0 deletions pkgs/by-name/mq/mqttx-cli/update.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/usr/bin/env nix-shell
#!nix-shell -i bash --pure -p cacert curl gnused jq nix-prefetch-github prefetch-yarn-deps nix git

set -ex

pname=mqttx-cli
owner=emqx
repo=MQTTX
dirname=$(dirname "$0")

evalProp()
{
prop=$1
(cd "$dirname" && nix eval --raw -f ../../../.. "$pname.$prop")
}

updateSrcHash()
{
version=$1
prevHash=$(evalProp src.outputHash)
hash=$(nix-prefetch-github --rev "v$version" $owner $repo | jq '.hash' -r)
sed -i "s|$prevHash|$hash|g" "$dirname/package.nix"
}

updateVersion()
{
prevVersion=$(evalProp version)
sed -i "s|$prevVersion|$1|g" "$dirname/package.nix"
}

updatePackageJson()
{
version=$1
url="https://raw.githubusercontent.com/$owner/$repo/v$version/cli/package.json"
curl "$url" -L -o "$dirname/package.json"
}

updateYarnHash()
{
version=$1
url="https://raw.githubusercontent.com/$owner/$repo/v$version/cli/yarn.lock"
prevHash=$(evalProp offlineCache.outputHash)
hash32=$(prefetch-yarn-deps <(curl -L "$url"))
hash=$(nix-hash --to-base64 --type sha256 --sri "$hash32")
sed -i "s|$prevHash|$hash|g" "$dirname/package.nix"
}

currentVersion=$(evalProp version)

latestTag=$(curl "https://api.github.com/repos/$owner/$repo/releases/latest" | jq -r ".tag_name")
latestVersion="$(expr "$latestTag" : 'v\(.*\)')"

if [[ "$currentVersion" == "$latestVersion" ]]; then
echo "$repo is up-to-date: ${currentVersion}"
exit 0
fi

updateVersion "$latestVersion"
updateSrcHash "$latestVersion"
updatePackageJson "$latestVersion"
updateYarnHash "$latestVersion"

0 comments on commit f5a59bb

Please sign in to comment.