From 734cad59deac477b8cbd17c7710fdf7e80ec76df Mon Sep 17 00:00:00 2001 From: "David G. Moore, Jr" Date: Sun, 8 Oct 2023 03:30:05 -0400 Subject: [PATCH] To summarize the changes made in this commit: - Added `.vscode/launch.json` file. - Added `.vscode/tasks.json` file. - Modified `NuGetPush.nuproj` to include the `ProjectGuid` property. - Modified `NuGetPush.sln` to include the `ProjectGuid` property. - Modified `.npmignore` to include the `node_modules/` directory. - Deleted `Scripts/delete-github-package-version` file. - Added `Scripts/delete-github-package-version` file as a symlink to `./bin/delete-github-package-version`. - Modified `Scripts/delete-github-package-version.ps1` to use PowerShell instead of Zsh. - Modified `Scripts/package-lock.json` to update various dependencies. - Modified `Scripts/package.json` to update various dependencies and add a `homepage` field. - Modified `Scripts/ts/constants.ts` to update the `GITHUB_API_VERSION` constant. - Modified `Scripts/ts/delete-github-package-version.ts` to use `yargs` for command-line argument parsing and added type annotations. - Modified `Scripts/ts/github-cli-types.ts` to add the `PackageType` type. - Modified `Scripts/ts/github-cli.ts` to update the `deletePackageVersionAsync` and `deletePackageAsync` functions. - Modified `Scripts/ts/index.ts` to update the import statements. - Modified `Scripts/tsconfig.json` to update the `compilerOptions` section. --- .vscode/tasks.json | 15 ++ NuGetPush.nuproj | 7 +- NuGetPush.sln | 21 +++ Scripts/.npmignore | 1 + Scripts/delete-github-package-version | 5 +- Scripts/delete-github-package-version.ps1 | 21 ++- Scripts/package-lock.json | 35 ++++- Scripts/package.json | 14 +- Scripts/ts/constants.ts | 14 +- Scripts/ts/delete-github-package-version.ts | 61 ++++++-- Scripts/ts/github-cli-types.ts | 40 ++--- Scripts/ts/github-cli.ts | 156 ++++++++++---------- Scripts/ts/index.ts | 8 +- Scripts/tsconfig.json | 6 +- 14 files changed, 261 insertions(+), 143 deletions(-) create mode 100644 .vscode/tasks.json mode change 100755 => 120000 Scripts/delete-github-package-version diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 00000000000..432e9154dcf --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,15 @@ +{ + "$schena": "https://json.schemastore.org/task.json", + "version": "2.0.0", + "tasks": [ + { + "type": "npm", + "script": "build", + "path": "Scripts", + "group": "build", + "problemMatcher": [], + "label": "npm: build - Scripts", + "detail": "npm install --repository https://repository.npmjs.org; tsc" + } + ] +} diff --git a/NuGetPush.nuproj b/NuGetPush.nuproj index c69526f3584..cc8058839ea 100644 --- a/NuGetPush.nuproj +++ b/NuGetPush.nuproj @@ -1,11 +1,11 @@ @@ -17,6 +17,7 @@ This is a simple MSBuild task that allows you to push a NuGet package to a NuGet server. v dgmjr-io + 2498EED9-9158-41BD-9D4A-246A70A1D9E2 diff --git a/NuGetPush.sln b/NuGetPush.sln index d23a01062f0..1ef057e6c51 100644 --- a/NuGetPush.sln +++ b/NuGetPush.sln @@ -1,8 +1,29 @@ Microsoft Visual Studio Solution File, Format Version 12.00 +# +Project("{82B4Z3B9B-A64C-4715-B499-D71E9CA2BD60}") = "NuGetPush", "NuGetPush.nuproj", "{2498EED9-9158-41BD-9D4A-246A70A1D9E2}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|Any CPU = Release|Any CPU + Release|x64 = Release|x64 + Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution + {2498EED9-9158-41BD-9D4A-246A70A1D9E2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2498EED9-9158-41BD-9D4A-246A70A1D9E2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2498EED9-9158-41BD-9D4A-246A70A1D9E2}.Debug|x64.ActiveCfg = Debug|Any CPU + {2498EED9-9158-41BD-9D4A-246A70A1D9E2}.Debug|x64.Build.0 = Debug|Any CPU + {2498EED9-9158-41BD-9D4A-246A70A1D9E2}.Debug|x86.ActiveCfg = Debug|Any CPU + {2498EED9-9158-41BD-9D4A-246A70A1D9E2}.Debug|x86.Build.0 = Debug|Any CPU + {2498EED9-9158-41BD-9D4A-246A70A1D9E2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2498EED9-9158-41BD-9D4A-246A70A1D9E2}.Release|Any CPU.Build.0 = Release|Any CPU + {2498EED9-9158-41BD-9D4A-246A70A1D9E2}.Release|x64.ActiveCfg = Release|Any CPU + {2498EED9-9158-41BD-9D4A-246A70A1D9E2}.Release|x64.Build.0 = Release|Any CPU + {2498EED9-9158-41BD-9D4A-246A70A1D9E2}.Release|x86.ActiveCfg = Release|Any CPU + {2498EED9-9158-41BD-9D4A-246A70A1D9E2}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Scripts/.npmignore b/Scripts/.npmignore index 8993d6cf1cd..c2864d683ef 100644 --- a/Scripts/.npmignore +++ b/Scripts/.npmignore @@ -1,2 +1,3 @@ login.txt .npmrc +node_modules/ diff --git a/Scripts/delete-github-package-version b/Scripts/delete-github-package-version deleted file mode 100755 index 3aa1838a0ac..00000000000 --- a/Scripts/delete-github-package-version +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/zsh - -# // ts-node "$( cd ${0%/*} && pwd -P )/ts/delete-github-package-version.ts" $ 1 $2 $3 $4 $5 $6 $7 $8 $9 -node "$( cd ${0%/*} && pwd -P )/js/delete-github-package-version.js" $@ diff --git a/Scripts/delete-github-package-version b/Scripts/delete-github-package-version new file mode 120000 index 00000000000..a5357cf9937 --- /dev/null +++ b/Scripts/delete-github-package-version @@ -0,0 +1 @@ +./bin/delete-github-package-version \ No newline at end of file diff --git a/Scripts/delete-github-package-version.ps1 b/Scripts/delete-github-package-version.ps1 index 719c3686471..dc1d1266ec8 100755 --- a/Scripts/delete-github-package-version.ps1 +++ b/Scripts/delete-github-package-version.ps1 @@ -1,15 +1,28 @@ +#!/usr/bin/env pwsh -# // ts-node "$( cd ${0%/*} && pwd -P )/ts/delete-github-package-version.ts" $ 1 $2 $3 $4 $5 $6 $7 $8 $9 [CmdletBinding()] +[Alias("Delete-GitHubPackageVersion")] param( + [Parameter(Mandatory)] [Alias("pkg", "p")] [string]$PackageId, + [Parameter(Mandatory)] [Alias("ver", "v")] [string]$PackageVersion, [Alias("t", "gh")] - [string]$GitHubToken, + [string]$GitHubToken = $env:GITHUB_TOKEN, + [Parameter(Mandatory)] [Alias("org")] - [string]$GitHubOrganization + [string]$GitHubOrganization, + [Alias("type")] + [ValidateSet("npm", "maven", "rubygems", "docker", "nuget", "container", IgnoreCase, ErrorMessage = "The package type must be one of the following: npm, maven, rubygems, docker, nuget, container")] + [string]$PackageType = "nuget" ) -node "$PSScriptRoot/js/delete-github-package-version.js" $GitHubOrganization $PackageId $PackageVersion ($GitHubToken ?? $env:GITHUB_TOKEN) +process { + Write-Output "node '$PSScriptRoot/js/delete-github-package-version.js' $GitHubOrganization $PackageId $PackageVersion $PackageType $GitHubToken" + node "$PSScriptRoot/js/delete-github-package-version.js" $GitHubOrganization $PackageId $PackageVersion $PackageType $GitHubToken + Write-Output "" + Write-Output "ts-node '$PSScriptRoot/ts/delete-github-package-version.ts' -o $GitHubOrganization -i $PackageId -v "$PackageVersion" -t $PackageType -k $GitHubToken" + ts-node $PSScriptRoot/ts/delete-github-package-version.ts -o $GitHubOrganization -i $PackageId -v "$PackageVersion" -t $PackageType -k $GitHubToken +} diff --git a/Scripts/package-lock.json b/Scripts/package-lock.json index 1ff1828ebcf..801f11c6891 100644 --- a/Scripts/package-lock.json +++ b/Scripts/package-lock.json @@ -1,5 +1,5 @@ { - "name": "github-packages-push", + "name": "@dgmjr/github-packages-push", "version": "0.0.1", "lockfileVersion": 1, "requires": true, @@ -300,9 +300,9 @@ } }, "@tsconfig/node16": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/@tsconfig/node16/-/node16-1.0.4.tgz", - "integrity": "sha512-vxhUy4J8lyeyinH7Azl1pdd43GJhZH/tP2weN8TntQblOY+A0XbT8DJk1/oCPuOOyg/Ja757rG0CgHcWC8OfMA==" + "version": "16.1.1", + "resolved": "https://registry.npmjs.org/@tsconfig/node16/-/node16-16.1.1.tgz", + "integrity": "sha512-+pio93ejHN4nINX4pXqfnR/fPLRtJBaT4ORaa5RH0Oc1zoYmo2B2koG+M328CQhHKn1Wj6FcOxCDFXAot9NhvA==" }, "@types/aws-lambda": { "version": "8.10.114", @@ -332,6 +332,27 @@ "resolved": "https://registry.npmjs.org/@types/node/-/node-18.15.10.tgz", "integrity": "sha512-9avDaQJczATcXgfmMAW3MIWArOO7A+m90vuCFLr8AotWf8igO/mRoYukrk2cqZVtv38tHs33retzHEilM7FpeQ==" }, + "@types/semver": { + "version": "7.5.3", + "resolved": "https://registry.npmjs.org/@types/semver/-/semver-7.5.3.tgz", + "integrity": "sha512-OxepLK9EuNEIPxWNME+C6WwbRAOOI2o2BaQEGzz5Lu2e4Z5eDnEo+/aVEDMIXywoJitJ7xWd641wrGLZdtwRyw==", + "dev": true + }, + "@types/yargs": { + "version": "17.0.28", + "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-17.0.28.tgz", + "integrity": "sha512-N3e3fkS86hNhtk6BEnc0rj3zcehaxx8QWhCROJkqpl5Zaoi7nAic3jH8q94jVD3zu5LGk+PUB6KAiDmimYOEQw==", + "dev": true, + "requires": { + "@types/yargs-parser": "*" + } + }, + "@types/yargs-parser": { + "version": "21.0.1", + "resolved": "https://registry.npmjs.org/@types/yargs-parser/-/yargs-parser-21.0.1.tgz", + "integrity": "sha512-axdPBuLuEJt0c4yI5OZssC19K2Mq1uKdrfZBzuxLvaztgqUtFYZUNw7lETExPYJR9jdEoIg4mb7RQKRQzOkeGQ==", + "dev": true + }, "agent-base": { "version": "6.0.2", "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-6.0.2.tgz", @@ -1593,9 +1614,9 @@ "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==" }, "yargs": { - "version": "17.6.2", - "resolved": "https://registry.npmjs.org/yargs/-/yargs-17.6.2.tgz", - "integrity": "sha512-1/9UrdHjDZc0eOU0HxOHoS78C69UD3JRMvzlJ7S79S2nTaWRA/whGCTV8o9e/N/1Va9YIV7Q4sOxD8VV4pCWOw==", + "version": "17.7.2", + "resolved": "https://registry.npmjs.org/yargs/-/yargs-17.7.2.tgz", + "integrity": "sha512-7dSzzRQ++CKnNI/krKnYRV7JKKPUXMEh61soaHKg9mrWEhzFWhFnxPxGl+69cD1Ou63C13NUPCnmIcrvqCuM6w==", "requires": { "cliui": "^8.0.1", "escalade": "^3.1.1", diff --git a/Scripts/package.json b/Scripts/package.json index f2e69231fa6..53da43a614c 100644 --- a/Scripts/package.json +++ b/Scripts/package.json @@ -1,12 +1,18 @@ { + "$schema": "https://json.schemastore.org/package.json", + "homepage": "https://github.com/dgmjr-io/NuGetPush.git", "author": { "email": "david@dgmjr.io", "name": "David G. Moore, Jr.", - "url": "https://github.com/dgmjr" + "url": "https://github.com/dgmjr", + "gthubusername": "dgmjr" }, + "type": "module", "description": "A TypeScript library, which allows deleting from GitHub packages", "devDependencies": { - "@tsconfig/node16": "^1.0.3" + "@tsconfig/node16": "^1.0.3", + "@types/semver": "^7.5.3", + "@types/yargs": "^17.0.28" }, "keywords": [ "github", @@ -20,7 +26,7 @@ "url": "https://github.com/dgmjr-io/NuGetPush.git" }, "scripts": { - "build-ts": "tsc", + "build": "npm install --registry https://registry.npmjs.org; tsc", "uninstall": "npm uninstall github-packages-push", "watch-ts": "tsc --watch", "clean": "rm -rf node_modules;rm -rf js;rm -rf **/*.js" @@ -31,6 +37,6 @@ "form-data": "^4.0.0", "npm-cli-login": "^1.0.0", "octokit": "^2.0.14", - "yargs": "^17.6.2" + "yargs": "^17.7.2" } } diff --git a/Scripts/ts/constants.ts b/Scripts/ts/constants.ts index 602ac706c27..c72055d6397 100644 --- a/Scripts/ts/constants.ts +++ b/Scripts/ts/constants.ts @@ -1,14 +1,14 @@ -/* +/* * constants.ts - * + * * Created: 2023-03-28-11:52:17 * Modified: 2023-03-28-11:52:17 - * + * * Author: David G. Moore, Jr. - * + * * Copyright © 2022 - 2023 David G. Moore, Jr., All Rights Reserved * License: MIT (https://opensource.org/licenses/MIT) - */ + */ export const GITHUB_API_URL = "https://api.github.com"; export const GITHUB_API_VERSION = '2022-11-28'; @@ -16,3 +16,7 @@ export const GITHUB_API_VERSION_HEADER_NAME = "X-GitHub-Api-Version" export const GITHUB_API_RESPONSE_CONTENT_TYPE = "application/vnd.github.v3+json"; export const GITHUB_API_VERSION_HEADER = { [GITHUB_API_VERSION_HEADER_NAME]: GITHUB_API_VERSION }; export const GITHUB_API_ACCEPT_HEADER = { Accept: GITHUB_API_RESPONSE_CONTENT_TYPE }; +export const GITHUB_API_STANDARD_HEADERS = { + [GITHUB_API_VERSION_HEADER_NAME]: GITHUB_API_VERSION, + Accept: GITHUB_API_RESPONSE_CONTENT_TYPE +}; diff --git a/Scripts/ts/delete-github-package-version.ts b/Scripts/ts/delete-github-package-version.ts index 0f277eb116e..78bf410bbaa 100755 --- a/Scripts/ts/delete-github-package-version.ts +++ b/Scripts/ts/delete-github-package-version.ts @@ -11,18 +11,55 @@ */ import process from 'process'; -import { deletePackageVersionAsync } from "./github-cli"; +import { deletePackageVersionAsync } from "./github-cli.js"; +import { PackageType } from './github-cli-types.js'; +import yargs from 'yargs/yargs'; +import { hideBin } from 'yargs/helpers'; +import { SemVer } from "semver"; +// const argv = yargs(hideBin(process.argv)); -if (process.argv.length < 3) { - console.error("Usage: delete-github-package-version [gh token]"); - process.exit(); -} +const main = async () => { -var orgId = process.argv.slice(2)[0]; -var packageId = process.argv.slice(2)[1]; -var version = process.argv.slice(2)[2]; -var token: string = (process.argv.slice(2).length == 4 ? process.argv.slice(2)[3] : process.env.GITHUB_TOKEN) as string; + console.log(`yargs: ${JSON.stringify(yargs)}`); + + // console.log(`argv: ${JSON.stringify(argv)}`); + + const ToSemVer = (stringVer: string) => new SemVer(stringVer); + console.log(`ToSemVer: ${JSON.stringify(ToSemVer)}`); + + const ToPackageType = (stringType: string) => stringType as PackageType; + console.log(`ToPackageType: ${JSON.stringify(ToPackageType)}`); + + const argv = await yargs(hideBin(process.argv)) + .usage("Usage: $0 [github-token]") + .option("org", { "type": "string", "describe": "The organization that owns the package", "demandOption": true, "string": true, "message": "The organization is required", "alias": ["o", "organization", "org"] }) + .option("package-id", { "type": "string", "describe": "The package's ID/name", "demandOption": true, "string": true, "message": "The package ID is required", "alias": ["i", "id", "package-id", "pkgid"] }) + .option("package-version", { "describe": "The package's semver version number", "demandOption": true, "message": "Package version is required", "alias": ["v", "version", "package-version"], "coerce": ToSemVer }) + .option("type", { "type": "string", "describe": "The package's type (one of npm, maven, rubygems, docker, nuget, container)", "choices": ["npm", "maven", "rubygems", "docker", "nuget", "container"], "alias": ["t", "type", "package-tyoe"], "default": "nuget", "coerce": ToPackageType }) + .option("token", { "type": "string", "describe": "The GitHub API token", "alias": ["token", "t"], "string": true, "default": process.env.GITHUB_TOKEN }) + // .showCompletionScript() + .showHelpOnFail(true) + .help() + .argv; + + console.log(`argv: ${JSON.stringify(argv)}`); + + // const Argsv = await argv.argv; + + // console.log(`argsv: ${JSON.stringify(Argsv)}`); + + const orgId = argv.org; + const packageId = argv.packageId; + const version = argv.packageVersion; + const packageType = argv.type; + const token = argv.token; + + console.log(`Args: org: ${orgId}, packageId: ${packageId}, version: ${version}, packageType: ${packageType}, token: ${token}`); + + await deletePackageVersionAsync(orgId, packageId, version, packageType, token); +}; + +console.log(`main: ${main}`); + +main(); -(async () => { - await deletePackageVersionAsync(orgId, packageId, version, token).then(() => process.exit(0)).catch((err) => { console.error(err); process.exit(1) }); -})(); diff --git a/Scripts/ts/github-cli-types.ts b/Scripts/ts/github-cli-types.ts index a7116fb5f58..e66a0fc0fe0 100644 --- a/Scripts/ts/github-cli-types.ts +++ b/Scripts/ts/github-cli-types.ts @@ -1,31 +1,33 @@ -/* +/* * github-cli-types.ts - * + * * Created: 2022-11-27-05:39:27 * Modified: 2022-12-05-04:14:47 - * + * * Author: David G. Moore, Jr. - * + * * Copyright © 2022-2023 David G. Moore, Jr., All Rights Reserved * License: MIT (https://opensource.org/licenses/MIT) - */ + */ export interface PackageVersion { - id: number; - name: string; - package_html_url: string; - url: string; - created_at: string; - updated_at: string; - visibility: string; - package_type: string; - downloads_count: number; - description: string; - html_url: string; - license: string; + id: number; + name: string; + package_html_url: string; + url: string; + created_at: string; + updated_at: string; + visibility: string; + package_type: string; + downloads_count: number; + description: string; + html_url: string; + license: string; } export interface ApiMessage { - message: string; - documentation_url: string; + message: string; + documentation_url: string; } + +export type PackageType = "nuget" | "npm" | "docker" | "maven" | "rubygems" | "container"; diff --git a/Scripts/ts/github-cli.ts b/Scripts/ts/github-cli.ts index 45ac29e18c0..b2d038f9743 100644 --- a/Scripts/ts/github-cli.ts +++ b/Scripts/ts/github-cli.ts @@ -10,92 +10,90 @@ * License: MIT (https://opensource.org/licenses/MIT) */ -import {GITHUB_API_RESPONSE_CONTENT_TYPE, GITHUB_API_VERSION, GITHUB_API_VERSION_HEADER_NAME} from "./constants"; -import {Octokit} from "@octokit/core"; +import { GITHUB_API_RESPONSE_CONTENT_TYPE, GITHUB_API_VERSION, GITHUB_API_VERSION_HEADER_NAME, GITHUB_API_STANDARD_HEADERS } from "./constants.js"; +import { PackageType } from "./github-cli-types.js"; +import { Octokit } from "@octokit/core"; +import { SemVer } from "semver"; -var octokit = new Octokit({ auth: process.env.GITHUB_TOKEN }); +export async function deletePackageVersionAsync(orgId: string, packageId: string, version: SemVer, package_type: PackageType = "nuget", token: string | undefined): Promise { + return new Promise(async (resolve, reject) => { + console.log(`Attempting to authorize with token "${token}...`); + if (token != undefined) { + var octokit = new Octokit({ auth: token }); + } + else { + throw "Error: no authorization token was passed."; + } -export async function deletePackageVersionAsync(orgId: string, packageId: string, version: string, token: string|undefined): Promise { - return new Promise(async (resolve, reject) => { - if (token != undefined) + try { + console.log(`Authorizing with token "${token}...`); + var versions = await octokit.request("GET /orgs/{org}/packages/{package_type}/{package_name}/versions", { - octokit = new Octokit({ auth: token }); - } - - try { - var versions = await octokit.request("GET /orgs/{org}/packages/{package_type}/{package_name}/versions", - { - org: orgId, - package_type: "nuget", - package_name: packageId, - headers: { - [GITHUB_API_VERSION_HEADER_NAME]: GITHUB_API_VERSION, - Accept: GITHUB_API_RESPONSE_CONTENT_TYPE - } - }); + org: orgId, + package_type, + package_name: packageId, + headers: GITHUB_API_STANDARD_HEADERS + }); - console.log("Using GitHub API to delete package version..."); - var versionToDelete = versions.data.find(v => v.name == version); + console.log("Using GitHub API to delete package version..."); + var versionToDelete = versions.data.find(v => v.name == version.format()); - const versionId = versionToDelete?.id; + const versionId = versionToDelete?.id; - if (versionId && versionId != undefined) { - var deleteResponse = await octokit.request("DELETE /orgs/{org}/packages/{package_type}/{package_name}/versions/{package_version_id}", - { - org: orgId, - package_type: "nuget", - package_name: packageId, - package_version_id: versionId, - headers: { - [GITHUB_API_VERSION_HEADER_NAME]: GITHUB_API_VERSION, - Accept: GITHUB_API_RESPONSE_CONTENT_TYPE - } - }); - if (deleteResponse.status != 204) { - console.log(`The package version was not deleted because the server encountered an error: ${deleteResponse.status}`); - reject(deleteResponse.status); - } - } - else { - console.log(`The package version ${version} was not found. Skipping...`); - } - resolve(); + if (versionId && versionId != undefined) { + var deleteResponse = await octokit.request("DELETE /orgs/{org}/packages/{package_type}/{package_name}/versions/{package_version_id}", + { + org: orgId, + package_type, + package_name: packageId, + package_version_id: versionId, + headers: GITHUB_API_STANDARD_HEADERS + }); + if (deleteResponse.status != 204) { + console.log(`The package version was not deleted because the server encountered an error: ${deleteResponse.status}`); + reject(deleteResponse.status); } - catch (ex) { - reject(ex); - } - }); + } + else { + console.log(`The package version ${version} was not found. Skipping...`); + } + resolve(); + } + catch (ex) { + reject(ex); + } + }); } -export async function deletePackageAsync(orgId: string, packageId: string, token:string|undefined) : Promise { - return new Promise(async (resolve, reject) => { - if (token != undefined) { - octokit = new Octokit({ auth: token }); - } - var deletePackageResultJsonString = ""; - console.log(`Deleting package ${packageId}...`); - try { - var deleteResponse = await octokit.request("DELETE '/orgs/{org}/GET /user/packages/GET /user/packages/{package_type}/{package_name}", - { - org: orgId, - package_type: "nuget", - package_name: packageId, - headers: { - [GITHUB_API_VERSION_HEADER_NAME]: GITHUB_API_VERSION, - Accept: GITHUB_API_RESPONSE_CONTENT_TYPE - } - }); - if (deleteResponse.status == 204) { - console.log("The package was deleted successfully.") - resolve(); - } - else { - console.log(`The package ${packageId} was not deleted because the server encountered an error: ${deleteResponse.status}`); - reject(deleteResponse.status); - } - } - catch(ex) { - reject(ex); - } - }); +export async function deletePackageAsync(orgId: string, packageId: string, token: string | undefined): Promise { + return new Promise(async (resolve, reject) => { + if (token != undefined) { + var octokit = new Octokit({ auth: token }); + } + else { + throw "Error: no authorization token was passed."; + } + var deletePackageResultJsonString = ""; + console.log(`Deleting package ${packageId}...`); + try { + var deleteResponse = await octokit.request("DELETE '/orgs/{org}/GET /user/packages/GET /user/packages/{package_type}/{package_name}", + { + org: orgId, + package_type: "nuget", + package_name: packageId, + headers: GITHUB_API_STANDARD_HEADERS + }); + if (deleteResponse.status == 204) { + console.log("The package was deleted successfully.") + resolve(); + } + else { + console.log(`The package ${packageId} was not deleted because the server encountered an error: ${deleteResponse.status}`); + reject(deleteResponse.status); + } + } + catch (ex) { + reject(ex); + } + }); } diff --git a/Scripts/ts/index.ts b/Scripts/ts/index.ts index ba45b3d2145..dcb552ced88 100644 --- a/Scripts/ts/index.ts +++ b/Scripts/ts/index.ts @@ -1,8 +1,8 @@ -import * as constants from "./constants"; +import * as constants from "./constants.js"; export { constants }; -import * as delete_github_package_version from "./delete-github-package-version"; +import * as delete_github_package_version from "./delete-github-package-version.js"; export { delete_github_package_version }; -import * as github_cli_types from "./github-cli-types"; +import * as github_cli_types from "./github-cli-types.js"; export { github_cli_types }; -import * as github_cli from "./github-cli"; +import * as github_cli from "./github-cli.js"; export { github_cli }; diff --git a/Scripts/tsconfig.json b/Scripts/tsconfig.json index 4acf632b7b1..64ded724cbc 100644 --- a/Scripts/tsconfig.json +++ b/Scripts/tsconfig.json @@ -1,12 +1,14 @@ { "extends": "@tsconfig/node16/tsconfig.json", "include": [ - "/**/index.ts" + "./ts/*.*" ], "compilerOptions": { "baseUrl": ".", "outDir": "./js", - "module": "ESNext" + "module": "Node16", + "moduleResolution": "Node16", + "noImplicitAny": false }, "exclude": [ "**/node_modules/**",