-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
unknown
committed
Nov 19, 2023
1 parent
785a631
commit 4625788
Showing
5 changed files
with
193 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { ChocolateyInfo } from "../../types/windows/chocolatey.ts"; | ||
import { Nuspec } from "../../types/windows/nuspec.ts"; | ||
import { EncodingError } from "../encoding/errors.ts"; | ||
import { readXml } from "../encoding/xml.ts"; | ||
import { getEnvValue } from "../environment/env.ts"; | ||
import { FileError } from "../filesystem/errors.ts"; | ||
import { glob } from "../filesystem/mod.ts"; | ||
import { WindowsError } from "./errors.ts"; | ||
|
||
/** | ||
* Function to get installed Chocolatey packages. | ||
* By default will use the `ChocolateyInstall` ENV value to determine base path | ||
* @param alt_base Optional alternative Chocolatey installation base_path | ||
* @returns Array of `ChocolateyInfo` or `WindowsError` | ||
*/ | ||
export function getChocolateyInfo( | ||
alt_base?: string, | ||
): ChocolateyInfo[] | WindowsError { | ||
let base_path = getEnvValue("ChocolateyInstall"); | ||
if (base_path === "" && alt_base === undefined) { | ||
return []; | ||
} else if (alt_base != undefined) { | ||
base_path = alt_base; | ||
} | ||
|
||
const glob_path = `${base_path}\\lib\\*\\*.nuspec`; | ||
const globs = glob(glob_path); | ||
if (globs instanceof FileError) { | ||
return new WindowsError( | ||
"CHOCOLATEYINFO", | ||
`failed to glob ${glob_path}: ${globs.message}`, | ||
); | ||
} | ||
|
||
const packages = []; | ||
for (const path of globs) { | ||
// Read the Nuspec XML file | ||
const xml_data = readXml(path.full_path) as unknown as Nuspec; | ||
if (xml_data instanceof EncodingError) { | ||
console.warn(`failed to parse ${path.full_path}: ${xml_data.message}`); | ||
continue; | ||
} | ||
|
||
// Try to grab some info | ||
const chocolate: ChocolateyInfo = { | ||
name: xml_data.package.metadata[0].id[0], | ||
version: xml_data.package.metadata[0].version[0], | ||
summary: typeof xml_data.package.metadata[0].summary === "undefined" | ||
? "" | ||
: xml_data.package.metadata[0].summary[0], | ||
author: xml_data.package.metadata[0].authors[0], | ||
license: typeof xml_data.package.metadata[0].licenseUrl === "undefined" | ||
? "" | ||
: xml_data.package.metadata[0].licenseUrl[0], | ||
tags: typeof xml_data.package.metadata[0].tags === "undefined" | ||
? [] | ||
: xml_data.package.metadata[0].tags[0].split(" "), | ||
path: path.full_path, | ||
}; | ||
packages.push(chocolate); | ||
} | ||
|
||
return packages; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export interface ChocolateyInfo { | ||
name: string; | ||
version: string; | ||
summary: string; | ||
author: string; | ||
license: string; | ||
tags: string[]; | ||
path: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
/** | ||
* Partial implementation of nuspec. Mainly for Chocolatey packages. | ||
* | ||
* https://learn.microsoft.com/en-us/nuget/reference/nuspec | ||
* | ||
* Sample output: | ||
* ```json | ||
* { | ||
"package": { | ||
"$": { | ||
"xmlns": "http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd" | ||
}, | ||
"metadata": [ | ||
{ | ||
"id": [ | ||
"7zip" | ||
], | ||
"version": [ | ||
"23.1.0" | ||
], | ||
"title": [ | ||
"7-Zip" | ||
], | ||
"authors": [ | ||
"Igor Pavlov" | ||
], | ||
"owners": [ | ||
"chocolatey-community,Rob Reynolds" | ||
], | ||
"licenseUrl": [ | ||
"http://www.7-zip.org/license.txt" | ||
], | ||
"projectUrl": [ | ||
"http://www.7-zip.org/" | ||
], | ||
"iconUrl": [ | ||
"https://cdn.jsdelivr.net/gh/chocolatey-community/chocolatey-packages@68b91a851cee97e55c748521aa6da6211dd37c98/icons/7zip.svg" | ||
], | ||
"requireLicenseAcceptance": [ | ||
"false" | ||
], | ||
"description": [ | ||
"7-Zip is a file archiver with a high compression ratio.\n\n## Features\n- High compression ratio in [7z format](http://www.7-zip.org/7z.html) with **LZMA** and **LZMA2** compression\n- Supported formats:\n- Packing / unpacking: 7z, XZ, BZIP2, GZIP, TAR, ZIP and WIM\n- Unpacking only: AR, ARJ, CAB, CHM, CPIO, CramFS, DMG, EXT, FAT, GPT, HFS, IHEX, ISO, LZH, LZMA, MBR, MSI, NSIS, NTFS, QCOW2, RAR, RPM, SquashFS, UDF, UEFI, VDI, VHD, VMDK, WIM, XAR and Z.\n- For ZIP and GZIP formats, **7-Zip** provides a compression ratio that is 2-10 % better than the ratio provided by PKZip and WinZip\n- Strong AES-256 encryption in 7z and ZIP formats\n- Self-extracting capability for 7z format\n- Integration with Windows Shell\n- Powerful File Manager\n- Powerful command line version\n- Plugin for FAR Manager\n- Localizations for 87 languages\n\n## Notes\n- The installer for 7-Zip is known to close the Explorer process. This means you may lose current work. If it doesn't automatically restart explorer, type `explorer` on the command shell to restart it.\n- **If the package is out of date please check [Version History](#versionhistory) for the latest submitted version. If you have a question, please ask it in [Chocolatey Community Package Discussions](https://github.com/chocolatey-community/chocolatey-packages/discussions) or raise an issue on the [Chocolatey Community Packages Repository](https://github.com/chocolatey-community/chocolatey-packages/issues) if you have problems with the package. Disqus comments will generally not be responded to.**" | ||
], | ||
"summary": [ | ||
"7-Zip is a file archiver with a high compression ratio." | ||
], | ||
"releaseNotes": [ | ||
"http://www.7-zip.org/history.txt" | ||
], | ||
"tags": [ | ||
"7zip zip archiver admin foss" | ||
], | ||
"packageSourceUrl": [ | ||
"https://github.com/chocolatey-community/chocolatey-packages/tree/master/automatic/7zip" | ||
], | ||
"docsUrl": [ | ||
"http://www.7-zip.org/faq.html" | ||
], | ||
"mailingListUrl": [ | ||
"https://sourceforge.net/p/sevenzip/discussion/45797/" | ||
], | ||
"bugTrackerUrl": [ | ||
"https://sourceforge.net/p/sevenzip/_list/tickets?source=navbar" | ||
], | ||
"dependencies": [ | ||
{ | ||
"dependency": [ | ||
{ | ||
"$": { | ||
"id": "7zip.install", | ||
"version": "[23.1.0]" | ||
} | ||
} | ||
] | ||
} | ||
] | ||
} | ||
] | ||
} | ||
} | ||
* ``` | ||
*/ | ||
export interface Nuspec { | ||
package: { | ||
$: { | ||
xmlns: string; | ||
}; | ||
metadata: { | ||
id: string[]; | ||
version: string[]; | ||
title: string[]; | ||
authors: string[]; | ||
description: string[]; | ||
/**NUSPEC states this is deprecated */ | ||
owners?: string[]; | ||
licenseUrl?: string[]; | ||
projectUrl?: string[]; | ||
license?: string[]; | ||
iconUrl?: string[]; | ||
requireLicenseAcceptance?: string[]; | ||
summary?: string[]; | ||
tags?: string[]; | ||
copyright?: string[]; | ||
}[]; | ||
}; | ||
} |