Skip to content

Commit

Permalink
feat: add maven central (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
levibostian committed Oct 2, 2023
1 parent 2ebeeef commit 50c355a
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 2 deletions.
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,12 @@ To see if a package has been uploaded to CocoaPods, use the `cocoapods` package

Here is an example with the CLI:

`npx is-it-deployed --package-manager cocoapods --package-name CustomerIO --package-version 2.8.3`
`npx is-it-deployed --package-manager cocoapods --package-name CustomerIO --package-version 2.8.3`

## Maven

To see if a package has been uploaded to the Maven Central repository, use the `maven` package manager with the module or the CLI.

Here is an example with the CLI:

`npx is-it-deployed --package-manager maven --package-name 'io.customer.android:tracking' --package-version 3.6.6`
21 changes: 21 additions & 0 deletions src/e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,27 @@ describe('cocoapods', () => {
it('should return false for package version that has not been deployed', async () => {
const result = await isItDeployed({ packageManager: 'cocoapods', packageName: 'CustomerIO', packageVersion: '99.99.99' })

expect(result).toBe(false)
})
})

describe('maven', () => {
it('should return true for package that does exist with a specific version', async () => {
const result = await isItDeployed({ packageManager: 'maven', packageName: 'io.customer.android:tracking', packageVersion: '3.6.6' })
expect(result).toBe(true)
})

it('should return false for package that does exist', async () => {
const randomString100CharsLong = Array.from({ length: 100 }, () => String.fromCharCode(Math.floor(Math.random() * 62) + 48)).join('');

const result = await isItDeployed({ packageManager: 'maven', packageName: randomString100CharsLong, packageVersion: '1.0.0' })

expect(result).toBe(false)
})

it('should return false for package version that has not been deployed', async () => {
const result = await isItDeployed({ packageManager: 'maven', packageName: 'io.customer.android:tracking', packageVersion: '99.99.99' })

expect(result).toBe(false)
})
})
5 changes: 4 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { NpmPackageManager } from "./packageManagers/npm";
import { CocoapodsPackageManager } from "./packageManagers/cocoapods";
import { MavenPackageManager } from "./packageManagers/maven";

export const isItDeployed = (args: { packageManager: 'npm' | 'cocoapods', packageName: string, packageVersion: string }) => {
export const isItDeployed = (args: { packageManager: 'npm' | 'cocoapods' | 'maven', packageName: string, packageVersion: string }) => {
switch (args.packageManager) {
case 'npm':
return NpmPackageManager.doesItExist(args)
case 'cocoapods':
return CocoapodsPackageManager.doesItExist(args)
case 'maven':
return MavenPackageManager.doesItExist(args)
default:
throw new Error('Package manager not supported');
}
Expand Down
16 changes: 16 additions & 0 deletions src/packageManagers/maven.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import http from "tiny-json-http"
import { MavenPackageManager } from "./maven"

it('should create expected maven http path given a package name', async() => {
const givenPackageName = 'io.customer.android:tracking'
const givenVersion = '3.6.6'
const expectedPath = 'https://repo.maven.apache.org/maven2/io/customer/android/tracking/3.6.6/'

jest.spyOn(http, 'get').mockImplementation(() => Promise.resolve({body: []}))

await MavenPackageManager.doesItExist({ packageName: givenPackageName, packageVersion: givenVersion })

const actual = (http.get as jest.Mock).mock.calls[0][0].url

expect(actual).toBe(expectedPath)
})
17 changes: 17 additions & 0 deletions src/packageManagers/maven.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { PackageManager } from ".";
import http from "tiny-json-http"

export const MavenPackageManager: PackageManager = {
doesItExist: async (args: { packageName: string, packageVersion: string }) => {
// given packageName: 'io.customer.android:tracking', we want to generate the path 'io/customer/android/tracking/'
const packageNameSplit = args.packageName.split(/[.:]/); // splits by . or :
const packagePath = packageNameSplit.join('/');

try {
await http.get({url: `https://repo.maven.apache.org/maven2/${packagePath}/${args.packageVersion}/`})
return true
} catch (error) {
return false
}
}
}

0 comments on commit 50c355a

Please sign in to comment.