Skip to content

Commit

Permalink
Update winget.js
Browse files Browse the repository at this point in the history
  • Loading branch information
lutzroeder committed Jun 26, 2021
1 parent 66affd3 commit 1f74958
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 39 deletions.
4 changes: 2 additions & 2 deletions Makefile
Expand Up @@ -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
Expand All @@ -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
Expand Down
26 changes: 14 additions & 12 deletions 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) => {
Expand Down Expand Up @@ -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 + '"',
Expand All @@ -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);
});
98 changes: 73 additions & 25 deletions publish/winget.js
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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);
});

0 comments on commit 1f74958

Please sign in to comment.