fix(CI): update CI build

This commit is contained in:
2018-09-01 16:40:42 +02:00
parent fa0d5af74e
commit 79a3420aa5
10 changed files with 175 additions and 427 deletions

View File

@ -1,4 +1,4 @@
import * as plugins from './smartnpm.plugins'
import * as plugins from './smartnpm.plugins';
export * from './smartnpm.classes.npmregistry'
export * from './smartnpm.classes.npmpackage'
export * from './smartnpm.classes.npmregistry';
export * from './smartnpm.classes.npmpackage';

View File

@ -1,39 +1,40 @@
import * as plugins from './smartnpm.plugins'
import * as plugins from './smartnpm.plugins';
export class NpmPackage {
name: string = null
scope: string = null
version: string = null
description: string = null
keywords: string[] = null
date: '2017-08-02T11:22:49.144Z'
name: string = null;
scope: string = null;
version: string = null;
description: string = null;
keywords: string[] = null;
date: '2017-08-02T11:22:49.144Z';
links: {
npm: string
homepage: string
repository: string
bugs: string
} = null
npm: string;
homepage: string;
repository: string;
bugs: string;
} = null;
author: {
name: 'Lossless GmbH'
} = null
name: 'Lossless GmbH';
} = null;
publisher: {
username: 'gitzone', email: 'npm@git.zone'
} = null
maintainers: any = null
username: 'gitzone';
email: 'npm@git.zone';
} = null;
maintainers: any = null;
score: {
final: number,
final: number;
detail: {
quality: number,
popularity: number,
maintenance: number
}
} = null
searchScore: number = null
quality: number;
popularity: number;
maintenance: number;
};
} = null;
searchScore: number = null;
constructor (descriptionArg) {
constructor(descriptionArg) {
for (let key in descriptionArg) {
if (this[key] === null) {
this[key] = descriptionArg[key]
this[key] = descriptionArg[key];
}
}
}

View File

@ -1,83 +1,102 @@
import * as plugins from './smartnpm.plugins'
import * as plugins from './smartnpm.plugins';
// interfaces
import { ISearchObject } from './smartnpm.interfaces'
import { ISearchObject } from './smartnpm.interfaces';
// classes
import { NpmPackage } from './smartnpm.classes.npmpackage'
import { NpmPackage } from './smartnpm.classes.npmpackage';
export class NpmRegistry {
private searchDomain = 'https://api.npms.io/v2/search?q='
async search (searchObjectArg: ISearchObject) {
let searchString = ''
private searchDomain = 'https://api.npms.io/v2/search?q=';
async search(searchObjectArg: ISearchObject) {
let searchString = '';
let addToSearchString = (addStringArg: string) => {
searchString = `${searchString}+${addStringArg}`
}
searchString = `${searchString}+${addStringArg}`;
};
// name
if (searchObjectArg.name) { searchString = `${searchObjectArg.name}` }
if (searchObjectArg.name) {
searchString = `${searchObjectArg.name}`;
}
// metadata
if (searchObjectArg.author) { addToSearchString(`author:${searchObjectArg.author}`) }
if (searchObjectArg.maintainer) { addToSearchString(`maintainer:${searchObjectArg.maintainer}`) }
if (searchObjectArg.scope) { addToSearchString(`scope:${searchObjectArg.scope}`) }
if (searchObjectArg.author) {
addToSearchString(`author:${searchObjectArg.author}`);
}
if (searchObjectArg.maintainer) {
addToSearchString(`maintainer:${searchObjectArg.maintainer}`);
}
if (searchObjectArg.scope) {
addToSearchString(`scope:${searchObjectArg.scope}`);
}
// status
if (searchObjectArg.deprecated) {
if (searchObjectArg.deprecated === true) {
addToSearchString(`is:deprecated`)
addToSearchString(`is:deprecated`);
} else {
addToSearchString(`not:deprecated`)
addToSearchString(`not:deprecated`);
}
}
if (searchObjectArg.unstable) {
if (searchObjectArg.unstable === true) {
addToSearchString(`is:unstable`)
addToSearchString(`is:unstable`);
} else {
addToSearchString(`not:unstable`)
addToSearchString(`not:unstable`);
}
}
if (searchObjectArg.insecure) {
if (searchObjectArg.insecure === true) {
addToSearchString(`is:insecure`)
addToSearchString(`is:insecure`);
} else {
addToSearchString(`not:insecure`)
addToSearchString(`not:insecure`);
}
}
// search behaviour
if (searchObjectArg.boostExact) { addToSearchString(`boost-exact:${searchObjectArg.boostExact}`) }
if (searchObjectArg.scoreEffect) { addToSearchString(`score-effect:${searchObjectArg.scoreEffect}`) }
if (searchObjectArg.boostExact) {
addToSearchString(`boost-exact:${searchObjectArg.boostExact}`);
}
if (searchObjectArg.scoreEffect) {
addToSearchString(`score-effect:${searchObjectArg.scoreEffect}`);
}
// analytics
if (searchObjectArg.qualityWeight) { addToSearchString(`author:${searchObjectArg.qualityWeight}`) }
if (searchObjectArg.popularityWeight) { addToSearchString(`author:${searchObjectArg.popularityWeight}`) }
if (searchObjectArg.maintenanceWeight) { addToSearchString(`author:${searchObjectArg.maintenanceWeight}`) }
if (searchObjectArg.qualityWeight) {
addToSearchString(`author:${searchObjectArg.qualityWeight}`);
}
if (searchObjectArg.popularityWeight) {
addToSearchString(`author:${searchObjectArg.popularityWeight}`);
}
if (searchObjectArg.maintenanceWeight) {
addToSearchString(`author:${searchObjectArg.maintenanceWeight}`);
}
plugins.smartlog.defaultLogger.info(`Search on npm for ${plugins.consolecolor.coloredString(searchString, 'pink')}`)
plugins.smartlog.defaultLogger.info(
`Search on npm for ${plugins.consolecolor.coloredString(searchString, 'pink')}`
);
let body: any;
try {
let response = (await plugins.smartrequest.getJson(this.searchDomain + searchString, {}))
body = response.body
let response = await plugins.smartrequest.getJson(this.searchDomain + searchString, {});
body = response.body;
} catch {
// we do nothing
}
// lets create the packageArray
let packageArray: NpmPackage[] = []
let packageArray: NpmPackage[] = [];
// if request failed just return it empty
if (!body || typeof body === 'string') {
return packageArray
return packageArray;
}
for (let packageArg of body.results) {
let localPackage = new NpmPackage(packageArg.package)
packageArray.push(localPackage)
let localPackage = new NpmPackage(packageArg.package);
packageArray.push(localPackage);
}
return packageArray
return packageArray;
}
}

View File

@ -1,25 +1,24 @@
export interface ISearchObject {
// name
name?: string
name?: string;
// metadata
author?: string
maintainer?: string
scope?: string
keywords?: string[]
author?: string;
maintainer?: string;
scope?: string;
keywords?: string[];
// status
deprecated?: boolean
unstable?: boolean
insecure?: boolean
deprecated?: boolean;
unstable?: boolean;
insecure?: boolean;
// search behaviour
boostExact?: boolean
scoreEffect?: number
boostExact?: boolean;
scoreEffect?: number;
// Analytics
qualityWeight?: number
popularityWeight?: number
maintenanceWeight?: number
qualityWeight?: number;
popularityWeight?: number;
maintenanceWeight?: number;
}