From 1f74958e87b36788aeb965ea9231835de81ba023 Mon Sep 17 00:00:00 2001 From: Lutz Roeder Date: Sat, 26 Jun 2021 07:48:48 -0700 Subject: [PATCH] Update winget.js --- Makefile | 4 +- publish/cask.js | 26 +++++++------ publish/winget.js | 98 +++++++++++++++++++++++++++++++++++------------ 3 files changed, 89 insertions(+), 39 deletions(-) diff --git a/Makefile b/Makefile index fba27f5dcd..6cbde0f614 100644 --- a/Makefile +++ b/Makefile @@ -101,7 +101,7 @@ publish_cask: rm -rf ./dist/homebrew-cask sleep 4 git clone --depth=2 https://x-access-token:$(GITHUB_TOKEN)@github.com/$(GITHUB_USER)/homebrew-cask.git ./dist/homebrew-cask - node ./publish/cask.js ./package.json ./dist/homebrew-cask/Casks/netron.rb + node ./publish/cask.js ./dist/homebrew-cask/Casks/netron.rb git -C ./dist/homebrew-cask add --all git -C ./dist/homebrew-cask commit -m "Update $$(node -pe "require('./package.json').productName") to $$(node -pe "require('./package.json').version")" git -C ./dist/homebrew-cask push @@ -115,7 +115,7 @@ publish_winget: rm -rf ./dist/winget-pkgs sleep 4 git clone --depth=2 https://x-access-token:$(GITHUB_TOKEN)@github.com/$(GITHUB_USER)/winget-pkgs.git ./dist/winget-pkgs - node ./publish/winget.js ./package.json ./dist/winget-pkgs/manifests + node ./publish/winget.js ./dist/winget-pkgs/manifests git -C ./dist/winget-pkgs add --all git -C ./dist/winget-pkgs commit -m "Update $$(node -pe "require('./package.json').name") to $$(node -pe "require('./package.json').version")" git -C ./dist/winget-pkgs push diff --git a/publish/cask.js b/publish/cask.js index b94bb9974c..11faadf6e8 100644 --- a/publish/cask.js +++ b/publish/cask.js @@ -1,12 +1,13 @@ const fs = require('fs'); +const path = require('path'); const http = require('http'); const https = require('https'); const crypto = require('crypto'); -const packageManifestFile = process.argv[2]; -const caskFile = process.argv[3]; +const configuration = require('../package.json'); +const caskFile = process.argv[2]; const get = (url, timeout) => { return new Promise((resolve, reject) => { @@ -58,18 +59,21 @@ const get = (url, timeout) => { }); }; -const packageManifest = JSON.parse(fs.readFileSync(packageManifestFile, 'utf-8')); -const name = packageManifest.name; -const version = packageManifest.version; -const productName = packageManifest.productName; -const description = packageManifest.description; -const repository = 'https://github.com/' + packageManifest.repository; +const name = configuration.name; +const version = configuration.version; +const productName = configuration.productName; +const description = configuration.description; +const repository = 'https://github.com/' + configuration.repository; const url = repository + '/releases/download/v#{version}/' + productName + '-#{version}-mac.zip'; const location = url.replace(/#{version}/g, version); get(location).then((data) => { const sha256 = crypto.createHash('sha256').update(data).digest('hex').toLowerCase(); - const lines = [ + const caskDir = path.dirname(caskFile); + if (!fs.existsSync(caskDir)){ + fs.mkdirSync(caskDir, { recursive: true }); + } + fs.writeFileSync(caskFile, [ 'cask "' + name + '" do', ' version "' + version + '"', ' sha256 "' + sha256 + '"', @@ -90,9 +94,7 @@ get(location).then((data) => { ' app "' + productName + '.app"', 'end', '' - ]; - fs.writeFileSync(caskFile, lines.join('\n')); - + ].join('\n')); }).catch((err) => { console.log(err.message); }); diff --git a/publish/winget.js b/publish/winget.js index 285aeef2fe..a18953d2e3 100644 --- a/publish/winget.js +++ b/publish/winget.js @@ -5,8 +5,9 @@ const http = require('http'); const https = require('https'); const path = require('path'); -const packageManifestFile = process.argv[2]; -const manifestDir = process.argv[3]; +const manifestDir = process.argv[2]; +const configuration = require('../package.json'); +const builder = fs.readFileSync('./electron-builder.yml', 'utf-8'); const get = (url, timeout) => { return new Promise((resolve, reject) => { @@ -58,41 +59,88 @@ const get = (url, timeout) => { }); }; -const packageManifest = JSON.parse(fs.readFileSync(packageManifestFile, 'utf-8')); -const name = packageManifest.name; -const version = packageManifest.version; -const productName = packageManifest.productName; -const publisher = packageManifest.author.name; -const repository = packageManifest.repository; -const url = 'https://github.com/' + repository + '/releases/download/v' + version + '/' + productName + '-Setup-' + version + '.exe'; +const name = configuration.name; +const version = configuration.version; +const productName = configuration.productName; +const publisher = configuration.author.name; +const packageIdentifier = publisher.replace(' ', '') + '.' + productName; +const license = 'Copyright (c) ' + publisher; +const repository = 'https://github.com/' + configuration.repository; +const url = repository + '/releases/download/v' + version + '/' + productName + '-Setup-' + version + '.exe'; +const extensions = builder.split('\n').filter((line) => line.startsWith(' ext')).map((line) => / {4}ext: (.*)\s*/.exec(line)[1]).sort().map((extension) => '- ' + extension).join('\n'); get(url).then((data) => { const sha256 = crypto.createHash('sha256').update(data).digest('hex').toUpperCase(); - const lines = [ - 'PackageIdentifier: ' + publisher.replace(' ', '') + '.' + productName, + const versionDir = path.join(manifestDir, publisher[0].toLowerCase(), publisher.replace(' ', ''), productName, version); + if (!fs.existsSync(versionDir)){ + fs.mkdirSync(versionDir, { recursive: true }); + } + const manifestFile = path.join(versionDir, packageIdentifier); + fs.writeFileSync(manifestFile + '.yaml', [ + 'PackageIdentifier: ' + packageIdentifier, 'PackageVersion: ' + version, - 'PackageName: ' + productName, - 'Publisher: ' + publisher, - 'Moniker: ' + name, - 'ShortDescription: ' + packageManifest.description, - 'License: Copyright (c) ' + publisher, - 'PackageUrl: ' + 'https://github.com/' + repository, + 'DefaultLocale: en-US', + 'ManifestType: version', + 'ManifestVersion: 1.0.0', + '' + ].join('\n')); + fs.writeFileSync(manifestFile + '.installer.yaml', [ + 'PackageIdentifier: ' + packageIdentifier, + 'PackageVersion: ' + version, + 'Platform:', + '- Windows.Desktop', + 'InstallModes:', + '- silent', + '- silentWithProgress', 'Installers:', '- Architecture: x86', + ' Scope: user', ' InstallerType: nullsoft', ' InstallerUrl: ' + url, ' InstallerSha256: ' + sha256, + ' InstallerLocale: en-US', + ' InstallerSwitches:', + ' Custom: /NORESTART', + ' UpgradeBehavior: install', + '- Architecture: arm64', + ' Scope: user', + ' InstallerType: nullsoft', + ' InstallerUrl: ' + url, + ' InstallerSha256: ' + sha256, + ' InstallerLocale: en-US', + ' InstallerSwitches:', + ' Custom: /NORESTART', + ' UpgradeBehavior: install', + 'FileExtensions:', + extensions, + 'ManifestType: installer', + 'ManifestVersion: 1.0.0', + '' + ].join('\n')); + fs.writeFileSync(manifestFile + '.locale.en-US.yaml', [ + 'PackageIdentifier: ' + packageIdentifier, + 'PackageVersion: ' + version, + 'PackageName: ' + productName, 'PackageLocale: en-US', - 'ManifestType: singleton', + 'PackageUrl: ' + repository, + 'Publisher: ' + publisher, + 'PublisherUrl: ' + repository, + 'PublisherSupportUrl: ' + repository + '/issues', + 'Author: ' + publisher, + 'License: ' + license, + 'Copyright: ' + license, + 'CopyrightUrl: ' + repository + '/blob/main/LICENSE', + 'ShortDescription: ' + configuration.description, + 'Description: ' + configuration.description, + 'Moniker: ' + name, + 'Tags:', + '- machine-learning', + '- deep-learning', + '- neural-network', + 'ManifestType: defaultLocale', 'ManifestVersion: 1.0.0', '' - ]; - const versionDir = path.join(manifestDir, publisher[0].toLowerCase(), publisher.replace(' ', ''), productName, version); - if (!fs.existsSync(versionDir)){ - fs.mkdirSync(versionDir); - } - const manifestFile = path.join(versionDir, publisher.replace(' ', '') + '.' + productName + '.yaml'); - fs.writeFileSync(manifestFile, lines.join('\n')); + ].join('\n')); }).catch((err) => { console.log(err.message); });