Skip to content

Commit

Permalink
To summarize the changes made in this commit:
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
dgmjr committed Oct 8, 2023
1 parent d8ef2ef commit 734cad5
Show file tree
Hide file tree
Showing 14 changed files with 261 additions and 143 deletions.
15 changes: 15 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
7 changes: 4 additions & 3 deletions NuGetPush.nuproj
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<!--
* NuGetPush.nuproj
*
*
* Created: 2022-11-27-04:36:43
* Modified: 2022-11-27-04:36:44
*
*
* Author: David G. Moore, Jr. <[email protected]>
*
*
* Copyright © 2022-2023 David G. Moore, Jr., All Rights Reserved
* License: MIT (https://opensource.org/licenses/MIT)
-->
Expand All @@ -17,6 +17,7 @@
<Description>This is a simple MSBuild task that allows you to push a NuGet package to a NuGet server.</Description>
<MinVerTagPrefix>v</MinVerTagPrefix>
<GitHubOrg>dgmjr-io</GitHubOrg>
<ProjectGuid>2498EED9-9158-41BD-9D4A-246A70A1D9E2</ProjectGuid>
</PropertyGroup>
<ItemGroup>
<Content Include="./Sdk/*" PackagePath="Sdk/%(Filename)%(Extension)" />
Expand Down
21 changes: 21 additions & 0 deletions NuGetPush.sln
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions Scripts/.npmignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
login.txt
.npmrc
node_modules/
4 changes: 0 additions & 4 deletions Scripts/delete-github-package-version

This file was deleted.

1 change: 1 addition & 0 deletions Scripts/delete-github-package-version
21 changes: 17 additions & 4 deletions Scripts/delete-github-package-version.ps1
Original file line number Diff line number Diff line change
@@ -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
}
35 changes: 28 additions & 7 deletions Scripts/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 10 additions & 4 deletions Scripts/package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
{
"$schema": "https://json.schemastore.org/package.json",
"homepage": "https://github.com/dgmjr-io/NuGetPush.git",
"author": {
"email": "[email protected]",
"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",
Expand All @@ -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"
Expand All @@ -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"
}
}
14 changes: 9 additions & 5 deletions Scripts/ts/constants.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
/*
/*
* constants.ts
*
*
* Created: 2023-03-28-11:52:17
* Modified: 2023-03-28-11:52:17
*
*
* Author: David G. Moore, Jr. <[email protected]>
*
*
* 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';
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
};
61 changes: 49 additions & 12 deletions Scripts/ts/delete-github-package-version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,55 @@
*/

import process from 'process';

Check failure on line 13 in Scripts/ts/delete-github-package-version.ts

View workflow job for this annotation

GitHub Actions / build

Cannot find module 'process' or its corresponding type declarations.
import { deletePackageVersionAsync } from "./github-cli";
import { deletePackageVersionAsync } from "./github-cli.js";
import { PackageType } from './github-cli-types.js';
import yargs from 'yargs/yargs';

Check failure on line 16 in Scripts/ts/delete-github-package-version.ts

View workflow job for this annotation

GitHub Actions / build

Cannot find module 'yargs/yargs' or its corresponding type declarations.
import { hideBin } from 'yargs/helpers';

Check failure on line 17 in Scripts/ts/delete-github-package-version.ts

View workflow job for this annotation

GitHub Actions / build

Cannot find module 'yargs/helpers' or its corresponding type declarations.
import { SemVer } from "semver";

Check failure on line 18 in Scripts/ts/delete-github-package-version.ts

View workflow job for this annotation

GitHub Actions / build

Cannot find module 'semver' or its corresponding type declarations.
// const argv = yargs(hideBin(process.argv));

if (process.argv.length < 3) {
console.error("Usage: delete-github-package-version <orgId> <packageId> <version> [gh token]");
process.exit();
}
const main = async () => {

Check failure on line 21 in Scripts/ts/delete-github-package-version.ts

View workflow job for this annotation

GitHub Actions / build

An async function or method in ES5/ES3 requires the 'Promise' constructor. Make sure you have a declaration for the 'Promise' constructor or include 'ES2015' in your '--lib' option.

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 <org> <package-id> <package-version> <package-type> [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) });
})();
40 changes: 21 additions & 19 deletions Scripts/ts/github-cli-types.ts
Original file line number Diff line number Diff line change
@@ -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. <[email protected]>
*
*
* 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";
Loading

0 comments on commit 734cad5

Please sign in to comment.