Compare commits

...

6 Commits

Author SHA1 Message Date
0d3292dd1e 1.0.14 2020-03-08 19:34:37 +00:00
54db436174 fix(core): update 2020-03-08 19:34:36 +00:00
7075d7b36f 1.0.13 2019-09-06 16:29:46 +02:00
98aca88b49 fix(core): update 2019-09-06 16:29:45 +02:00
5f49845138 1.0.12 2019-09-06 13:22:54 +02:00
1d5e94244b fix(core): update 2019-09-06 13:22:54 +02:00
5 changed files with 38 additions and 36 deletions

2
package-lock.json generated
View File

@ -1,6 +1,6 @@
{ {
"name": "@pushrocks/smartnpm", "name": "@pushrocks/smartnpm",
"version": "1.0.11", "version": "1.0.14",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {

View File

@ -1,6 +1,6 @@
{ {
"name": "@pushrocks/smartnpm", "name": "@pushrocks/smartnpm",
"version": "1.0.11", "version": "1.0.14",
"private": false, "private": false,
"description": "interface with npm to retrieve package information", "description": "interface with npm to retrieve package information",
"main": "dist/index.js", "main": "dist/index.js",

View File

@ -11,15 +11,15 @@ tap.test('should create valid instances', async () => {
npmRegistry = new smartnpm.NpmRegistry(); npmRegistry = new smartnpm.NpmRegistry();
expect(npmRegistry).to.be.instanceof(smartnpm.NpmRegistry); expect(npmRegistry).to.be.instanceof(smartnpm.NpmRegistry);
testPackage = new smartnpm.NpmPackage({}); testPackage = new smartnpm.NpmPackage();
expect(testPackage).to.be.instanceof(smartnpm.NpmPackage); expect(testPackage).to.be.instanceof(smartnpm.NpmPackage);
}); });
tap.test('should produce a valid search string and this return npmts', async () => { tap.test('should produce a valid search string and this return npmts', async () => {
const packages = await npmRegistry.search({ const packages = await npmRegistry.search({
name: 'npmts' name: '@pushrocks/smartupdate'
}); });
expect(packages[0].name).to.equal('npmts'); expect(packages[0].name).to.equal('@pushrocks/smartupdate');
}); });
// lets test things with the verdaccio registry // lets test things with the verdaccio registry
@ -31,8 +31,8 @@ tap.test('should create a verdaccio registry', async () => {
}); });
tap.test('should get package from verdaccui', async () => { tap.test('should get package from verdaccui', async () => {
const packageInfo = await verdaccioRegistry.getPackageInfo('@pushrocks/smartupdate'); const npmPackage = await verdaccioRegistry.getPackageInfo('@pushrocks/smartupdate');
expect(packageInfo.license).to.equal('MIT'); expect(npmPackage.license).to.equal('MIT');
}); });
tap.start(); tap.start();

View File

@ -1,27 +1,36 @@
import * as plugins from './smartnpm.plugins'; import * as plugins from './smartnpm.plugins';
import { NpmRegistry } from './smartnpm.classes.npmregistry';
export class NpmPackage { export class NpmPackage {
name: string = null; public static async createFromFullMetadata(npmRegistry: NpmRegistry, fullMetadata: plugins.packageJson.FullMetadata) {
scope: string = null; const npmPackage = new NpmPackage();
version: string = null; Object.assign(npmPackage, fullMetadata);
description: string = null; return npmPackage;
keywords: string[] = null; }
date: '2017-08-02T11:22:49.144Z';
links: { // INSTANCE
public name: string = null;
public scope: string = null;
public version: string = null;
public description: string = null;
public keywords: string[] = null;
public date: string;
public license: string;
public links: {
npm: string; npm: string;
homepage: string; homepage: string;
repository: string; repository: string;
bugs: string; bugs: string;
} = null; };
author: { public author: {
name: 'Lossless GmbH'; name: 'Lossless GmbH';
} = null; };
publisher: { public publisher: {
username: 'gitzone'; username: 'gitzone';
email: 'npm@git.zone'; email: 'npm@git.zone';
} = null; };
maintainers: any = null; public maintainers: any = null;
score: { public score: {
final: number; final: number;
detail: { detail: {
quality: number; quality: number;
@ -29,13 +38,5 @@ export class NpmPackage {
maintenance: number; maintenance: number;
}; };
} = null; } = null;
searchScore: number = null; public searchScore: number = null;
constructor(descriptionArg) {
for (let key in descriptionArg) {
if (this[key] === null) {
this[key] = descriptionArg[key];
}
}
}
} }

View File

@ -25,12 +25,13 @@ export class NpmRegistry {
}; };
} }
public async getPackageInfo(packageName: string) { public async getPackageInfo(packageName: string): Promise<NpmPackage> {
const result = await plugins.packageJson(packageName, { const fullMetadata = await plugins.packageJson(packageName, {
registryUrl: this.options.npmRegistryUrl, registryUrl: this.options.npmRegistryUrl,
fullMetadata: true fullMetadata: true
}); });
return result; const npmPackage = await NpmPackage.createFromFullMetadata(this, fullMetadata);
return npmPackage;
} }
public async search(searchObjectArg: ISearchObject) { public async search(searchObjectArg: ISearchObject) {
@ -121,9 +122,9 @@ export class NpmRegistry {
return packageArray; return packageArray;
} }
for (const packageArg of body.results) { for (const packageSearchInfoArg of body.results) {
const localPackage = new NpmPackage(packageArg.package); const npmPackage = await this.getPackageInfo(packageSearchInfoArg.package.name);
packageArray.push(localPackage); packageArray.push(npmPackage);
} }
return packageArray; return packageArray;