fix(core): update

This commit is contained in:
Philipp Kunz 2020-03-17 00:38:58 +00:00
parent 0d3292dd1e
commit e72a5cb4af
23 changed files with 788 additions and 936 deletions

4
.gitignore vendored
View File

@ -15,8 +15,6 @@ node_modules/
# builds # builds
dist/ dist/
dist_web/ dist_*/
dist_serve/
dist_ts_web/
# custom # custom

View File

@ -3,14 +3,14 @@ image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
cache: cache:
paths: paths:
- .npmci_cache/ - .npmci_cache/
key: "$CI_BUILD_STAGE" key: '$CI_BUILD_STAGE'
stages: stages:
- security - security
- test - test
- release - release
- metadata - metadata
# ==================== # ====================
# security stage # security stage
@ -18,21 +18,24 @@ stages:
mirror: mirror:
stage: security stage: security
script: script:
- npmci git mirror - npmci git mirror
tags: tags:
- docker - lossless
- notpriv - docker
- notpriv
snyk: audit:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security stage: security
script: script:
- npmci npm prepare - npmci npm prepare
- npmci command npm install -g snyk
- npmci command npm install --ignore-scripts - npmci command npm install --ignore-scripts
- npmci command snyk test - npmci command npm config set registry https://registry.npmjs.org
- npmci command npm audit --audit-level=moderate
tags: tags:
- docker - lossless
- notpriv - docker
- notpriv
# ==================== # ====================
# test stage # test stage
@ -41,37 +44,40 @@ snyk:
testStable: testStable:
stage: test stage: test
script: script:
- npmci npm prepare - npmci npm prepare
- npmci node install stable - npmci node install stable
- npmci npm install - npmci npm install
- npmci npm test - npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/ coverage: /\d+.?\d+?\%\s*coverage/
tags: tags:
- docker - lossless
- priv - docker
- priv
testBuild: testBuild:
stage: test stage: test
script: script:
- npmci npm prepare - npmci npm prepare
- npmci node install lts - npmci node install stable
- npmci npm install - npmci npm install
- npmci command npm run build - npmci command npm run build
coverage: /\d+.?\d+?\%\s*coverage/ coverage: /\d+.?\d+?\%\s*coverage/
tags: tags:
- docker - lossless
- notpriv - docker
- notpriv
release: release:
stage: release stage: release
script: script:
- npmci node install lts - npmci node install stable
- npmci npm publish - npmci npm publish
only: only:
- tags - tags
tags: tags:
- docker - lossless
- notpriv - docker
- notpriv
# ==================== # ====================
# metadata stage # metadata stage
@ -81,33 +87,35 @@ codequality:
allow_failure: true allow_failure: true
script: script:
- npmci command npm install -g tslint typescript - npmci command npm install -g tslint typescript
- npmci npm prepare
- npmci npm install - npmci npm install
- npmci command "tslint -c tslint.json ./ts/**/*.ts" - npmci command "tslint -c tslint.json ./ts/**/*.ts"
tags: tags:
- docker - lossless
- priv - docker
- priv
trigger: trigger:
stage: metadata stage: metadata
script: script:
- npmci trigger - npmci trigger
only: only:
- tags - tags
tags: tags:
- docker - lossless
- notpriv - docker
- notpriv
pages: pages:
image: hosttoday/ht-docker-dbase:npmci
services:
- docker:stable-dind
stage: metadata stage: metadata
script: script:
- npmci node install lts
- npmci command npm install -g @gitzone/tsdoc - npmci command npm install -g @gitzone/tsdoc
- npmci npm prepare - npmci npm prepare
- npmci npm install - npmci npm install
- npmci command tsdoc - npmci command tsdoc
tags: tags:
- lossless
- docker - docker
- notpriv - notpriv
only: only:
@ -115,5 +123,5 @@ pages:
artifacts: artifacts:
expire_in: 1 week expire_in: 1 week
paths: paths:
- public - public
allow_failure: true allow_failure: true

29
.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,29 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "current file",
"type": "node",
"request": "launch",
"args": [
"${relativeFile}"
],
"runtimeArgs": ["-r", "@gitzone/tsrun"],
"cwd": "${workspaceRoot}",
"protocol": "inspector",
"internalConsoleOptions": "openOnSessionStart"
},
{
"name": "test.ts",
"type": "node",
"request": "launch",
"args": [
"test/test.ts"
],
"runtimeArgs": ["-r", "@gitzone/tsrun"],
"cwd": "${workspaceRoot}",
"protocol": "inspector",
"internalConsoleOptions": "openOnSessionStart"
}
]
}

26
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,26 @@
{
"json.schemas": [
{
"fileMatch": ["/npmextra.json"],
"schema": {
"type": "object",
"properties": {
"npmci": {
"type": "object",
"description": "settings for npmci"
},
"gitzone": {
"type": "object",
"description": "settings for gitzone",
"properties": {
"projectType": {
"type": "string",
"enum": ["website", "element", "service", "npm"]
}
}
}
}
}
}
]
}

2
dist/index.d.ts vendored
View File

@ -1,2 +0,0 @@
export * from './smartnpm.classes.npmregistry';
export * from './smartnpm.classes.npmpackage';

8
dist/index.js vendored
View File

@ -1,8 +0,0 @@
"use strict";
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
Object.defineProperty(exports, "__esModule", { value: true });
__export(require("./smartnpm.classes.npmregistry"));
__export(require("./smartnpm.classes.npmpackage"));
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7OztBQUVBLG9EQUE4QztBQUM5QyxtREFBNkMifQ==

View File

@ -1,32 +0,0 @@
export declare class NpmPackage {
name: string;
scope: string;
version: string;
description: string;
keywords: string[];
date: '2017-08-02T11:22:49.144Z';
links: {
npm: string;
homepage: string;
repository: string;
bugs: string;
};
author: {
name: 'Lossless GmbH';
};
publisher: {
username: 'gitzone';
email: 'npm@git.zone';
};
maintainers: any;
score: {
final: number;
detail: {
quality: number;
popularity: number;
maintenance: number;
};
};
searchScore: number;
constructor(descriptionArg: any);
}

View File

@ -1,24 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class NpmPackage {
constructor(descriptionArg) {
this.name = null;
this.scope = null;
this.version = null;
this.description = null;
this.keywords = null;
this.links = null;
this.author = null;
this.publisher = null;
this.maintainers = null;
this.score = null;
this.searchScore = null;
for (let key in descriptionArg) {
if (this[key] === null) {
this[key] = descriptionArg[key];
}
}
}
}
exports.NpmPackage = NpmPackage;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRucG0uY2xhc3Nlcy5ucG1wYWNrYWdlLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRucG0uY2xhc3Nlcy5ucG1wYWNrYWdlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBRUEsTUFBYSxVQUFVO0lBOEJyQixZQUFhLGNBQWM7UUE3QjNCLFNBQUksR0FBVyxJQUFJLENBQUE7UUFDbkIsVUFBSyxHQUFXLElBQUksQ0FBQTtRQUNwQixZQUFPLEdBQVcsSUFBSSxDQUFBO1FBQ3RCLGdCQUFXLEdBQVcsSUFBSSxDQUFBO1FBQzFCLGFBQVEsR0FBYSxJQUFJLENBQUE7UUFFekIsVUFBSyxHQUtELElBQUksQ0FBQTtRQUNSLFdBQU0sR0FFRixJQUFJLENBQUE7UUFDUixjQUFTLEdBRUwsSUFBSSxDQUFBO1FBQ1IsZ0JBQVcsR0FBUSxJQUFJLENBQUE7UUFDdkIsVUFBSyxHQU9ELElBQUksQ0FBQTtRQUNSLGdCQUFXLEdBQVcsSUFBSSxDQUFBO1FBR3hCLEtBQUssSUFBSSxHQUFHLElBQUksY0FBYyxFQUFFO1lBQzlCLElBQUksSUFBSSxDQUFDLEdBQUcsQ0FBQyxLQUFLLElBQUksRUFBRTtnQkFDdEIsSUFBSSxDQUFDLEdBQUcsQ0FBQyxHQUFHLGNBQWMsQ0FBQyxHQUFHLENBQUMsQ0FBQTthQUNoQztTQUNGO0lBQ0gsQ0FBQztDQUNGO0FBckNELGdDQXFDQyJ9

View File

@ -1,6 +0,0 @@
import { ISearchObject } from './smartnpm.interfaces';
import { NpmPackage } from './smartnpm.classes.npmpackage';
export declare class NpmRegistry {
private searchDomain;
search(searchObjectArg: ISearchObject): Promise<NpmPackage[]>;
}

View File

@ -1,104 +0,0 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const plugins = require("./smartnpm.plugins");
// classes
const smartnpm_classes_npmpackage_1 = require("./smartnpm.classes.npmpackage");
class NpmRegistry {
constructor() {
this.searchDomain = 'https://api.npms.io/v2/search?q=';
}
search(searchObjectArg) {
return __awaiter(this, void 0, void 0, function* () {
let searchString = '';
let addToSearchString = (addStringArg) => {
searchString = `${searchString}+${addStringArg}`;
};
// 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}`);
}
// status
if (searchObjectArg.deprecated) {
if (searchObjectArg.deprecated === true) {
addToSearchString(`is:deprecated`);
}
else {
addToSearchString(`not:deprecated`);
}
}
if (searchObjectArg.unstable) {
if (searchObjectArg.unstable === true) {
addToSearchString(`is:unstable`);
}
else {
addToSearchString(`not:unstable`);
}
}
if (searchObjectArg.insecure) {
if (searchObjectArg.insecure === true) {
addToSearchString(`is:insecure`);
}
else {
addToSearchString(`not:insecure`);
}
}
// search behaviour
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}`);
}
plugins.smartlog.defaultLogger.info(`Search on npm for ${plugins.consolecolor.coloredString(searchString, 'pink')}`);
let body;
try {
let response = (yield plugins.smartrequest.getJson(this.searchDomain + searchString, {}));
body = response.body;
}
catch (_a) {
// we do nothing
}
// lets create the packageArray
let packageArray = [];
// if request failed just return it empty
if (!body || typeof body === 'string') {
return packageArray;
}
for (let packageArg of body.results) {
let localPackage = new smartnpm_classes_npmpackage_1.NpmPackage(packageArg.package);
packageArray.push(localPackage);
}
return packageArray;
});
}
}
exports.NpmRegistry = NpmRegistry;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRucG0uY2xhc3Nlcy5ucG1yZWdpc3RyeS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0bnBtLmNsYXNzZXMubnBtcmVnaXN0cnkudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7OztBQUFBLDhDQUE2QztBQUs3QyxVQUFVO0FBQ1YsK0VBQTBEO0FBRTFELE1BQWEsV0FBVztJQUF4QjtRQUNVLGlCQUFZLEdBQUcsa0NBQWtDLENBQUE7SUF5RTNELENBQUM7SUF4RU8sTUFBTSxDQUFFLGVBQThCOztZQUMxQyxJQUFJLFlBQVksR0FBRyxFQUFFLENBQUE7WUFDckIsSUFBSSxpQkFBaUIsR0FBRyxDQUFDLFlBQW9CLEVBQUUsRUFBRTtnQkFDL0MsWUFBWSxHQUFHLEdBQUcsWUFBWSxJQUFJLFlBQVksRUFBRSxDQUFBO1lBQ2xELENBQUMsQ0FBQTtZQUVELE9BQU87WUFDUCxJQUFJLGVBQWUsQ0FBQyxJQUFJLEVBQUU7Z0JBQUUsWUFBWSxHQUFHLEdBQUcsZUFBZSxDQUFDLElBQUksRUFBRSxDQUFBO2FBQUU7WUFFdEUsV0FBVztZQUNYLElBQUksZUFBZSxDQUFDLE1BQU0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BQWdCO2FBQ2pCO1lBR0QsK0JBQStCO1lBQy9CLElBQUksWUFBWSxHQUFpQixFQUFFLENBQUE7WUFFbkMseUNBQXlDO1lBQ3pDLElBQUksQ0FBQyxJQUFJLElBQUksT0FBTyxJQUFJLEtBQUssUUFBUSxFQUFFO2dCQUNyQyxPQUFPLFlBQVksQ0FBQTthQUNwQjtZQUVELEtBQUssSUFBSSxVQUFVLElBQUksSUFBSSxDQUFDLE9BQU8sRUFBRTtnQkFDbkMsSUFBSSxZQUFZLEdBQUcsSUFBSSx3Q0FBVSxDQUFDLFVBQVUsQ0FBQyxPQUFPLENBQUMsQ0FBQTtnQkFDckQsWUFBWSxDQUFDLElBQUksQ0FBQyxZQUFZLENBQUMsQ0FBQTthQUNoQztZQUVELE9BQU8sWUFBWSxDQUFBO1FBQ3JCLENBQUM7S0FBQTtDQUNGO0FBMUVELGtDQTBFQyJ9

View File

@ -1,15 +0,0 @@
export interface ISearchObject {
name?: string;
author?: string;
maintainer?: string;
scope?: string;
keywords?: string[];
deprecated?: boolean;
unstable?: boolean;
insecure?: boolean;
boostExact?: boolean;
scoreEffect?: number;
qualityWeight?: number;
popularityWeight?: number;
maintenanceWeight?: number;
}

View File

@ -1,3 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRucG0uaW50ZXJmYWNlcy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0bnBtLmludGVyZmFjZXMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IiJ9

View File

@ -1,4 +0,0 @@
import * as consolecolor from '@pushrocks/consolecolor';
import * as smartlog from '@pushrocks/smartlog';
import * as smartrequest from '@pushrocks/smartrequest';
export { consolecolor, smartlog, smartrequest };

View File

@ -1,10 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const consolecolor = require("@pushrocks/consolecolor");
exports.consolecolor = consolecolor;
const smartlog = require("@pushrocks/smartlog");
exports.smartlog = smartlog;
smartlog.defaultLogger.enableConsole();
const smartrequest = require("@pushrocks/smartrequest");
exports.smartrequest = smartrequest;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRucG0ucGx1Z2lucy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0bnBtLnBsdWdpbnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFBQSx3REFBd0Q7QUFLL0Msb0NBQVk7QUFKckIsZ0RBQWdEO0FBSXpCLDRCQUFRO0FBSC9CLFFBQVEsQ0FBQyxhQUFhLENBQUMsYUFBYSxFQUFFLENBQUM7QUFDdkMsd0RBQXdEO0FBRXZCLG9DQUFZIn0=

View File

@ -4,6 +4,7 @@
"npmAccessLevel": "public" "npmAccessLevel": "public"
}, },
"gitzone": { "gitzone": {
"projectType": "npm",
"module": { "module": {
"githost": "gitlab.com", "githost": "gitlab.com",
"gitscope": "pushrocks", "gitscope": "pushrocks",

1237
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -3,8 +3,8 @@
"version": "1.0.14", "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_ts/index.js",
"typings": "dist/index.d.ts", "typings": "dist_ts/index.d.ts",
"author": "Lossless GmbH", "author": "Lossless GmbH",
"license": "MIT", "license": "MIT",
"scripts": { "scripts": {
@ -12,29 +12,32 @@
"build": "(tsbuild)" "build": "(tsbuild)"
}, },
"devDependencies": { "devDependencies": {
"@gitzone/tsbuild": "^2.1.17", "@gitzone/tsbuild": "^2.1.22",
"@gitzone/tsrun": "^1.2.8", "@gitzone/tsrun": "^1.2.8",
"@gitzone/tstest": "^1.0.24", "@gitzone/tstest": "^1.0.28",
"@pushrocks/tapbundle": "^3.0.13", "@pushrocks/tapbundle": "^3.2.1",
"@types/node": "^12.7.4", "@types/node": "^13.9.1",
"tslint": "^5.19.0", "tslint": "^6.1.0",
"tslint-config-prettier": "^1.18.0" "tslint-config-prettier": "^1.18.0"
}, },
"dependencies": { "dependencies": {
"@pushrocks/consolecolor": "^2.0.1", "@pushrocks/consolecolor": "^2.0.1",
"@pushrocks/smartlog": "^2.0.19", "@pushrocks/smartarchive": "^1.0.12",
"@pushrocks/smartrequest": "^1.1.23", "@pushrocks/smartfile": "^7.0.11",
"@pushrocks/smartlog": "^2.0.21",
"@pushrocks/smartrequest": "^1.1.47",
"package-json": "^6.5.0" "package-json": "^6.5.0"
}, },
"files": [ "files": [
"ts/*", "ts/**/*",
"ts_web/*", "ts_web/**/*",
"dist/*", "dist/**/*",
"dist_web/*", "dist_*/**/*",
"dist_ts_web/*", "dist_ts/**/*",
"assets/*", "dist_ts_web/**/*",
"assets/**/*",
"cli.js", "cli.js",
"npmextra.json", "npmextra.json",
"readme.md" "readme.md"
] ]
} }

View File

@ -8,7 +8,7 @@ interface with npm to retrieve package information
* [docs (typedoc)](https://pushrocks.gitlab.io/smartnpm/) * [docs (typedoc)](https://pushrocks.gitlab.io/smartnpm/)
## Status for master ## Status for master
[![build status](https://gitlab.com/pushrocks/smartnpm/badges/master/build.svg)](https://gitlab.com/pushrocks/smartnpm/commits/master) [![pipeline status](https://gitlab.com/pushrocks/smartnpm/badges/master/pipeline.svg)](https://gitlab.com/pushrocks/smartnpm/commits/master)
[![coverage report](https://gitlab.com/pushrocks/smartnpm/badges/master/coverage.svg)](https://gitlab.com/pushrocks/smartnpm/commits/master) [![coverage report](https://gitlab.com/pushrocks/smartnpm/badges/master/coverage.svg)](https://gitlab.com/pushrocks/smartnpm/commits/master)
[![npm downloads per month](https://img.shields.io/npm/dm/@pushrocks/smartnpm.svg)](https://www.npmjs.com/package/@pushrocks/smartnpm) [![npm downloads per month](https://img.shields.io/npm/dm/@pushrocks/smartnpm.svg)](https://www.npmjs.com/package/@pushrocks/smartnpm)
[![Known Vulnerabilities](https://snyk.io/test/npm/@pushrocks/smartnpm/badge.svg)](https://snyk.io/test/npm/@pushrocks/smartnpm) [![Known Vulnerabilities](https://snyk.io/test/npm/@pushrocks/smartnpm/badge.svg)](https://snyk.io/test/npm/@pushrocks/smartnpm)
@ -27,6 +27,10 @@ For further information read the linked docs at the top of this README.
[![repo-footer](https://pushrocks.gitlab.io/assets/repo-footer.svg)](https://push.rocks) [![repo-footer](https://pushrocks.gitlab.io/assets/repo-footer.svg)](https://push.rocks)
## Contribution
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :)
For further information read the linked docs at the top of this readme. For further information read the linked docs at the top of this readme.
> MIT licensed | **&copy;** [Lossless GmbH](https://lossless.gmbh) > MIT licensed | **&copy;** [Lossless GmbH](https://lossless.gmbh)

View File

@ -11,12 +11,12 @@ 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(npmRegistry);
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.searchOnNpm({
name: '@pushrocks/smartupdate' name: '@pushrocks/smartupdate'
}); });
expect(packages[0].name).to.equal('@pushrocks/smartupdate'); expect(packages[0].name).to.equal('@pushrocks/smartupdate');
@ -30,9 +30,17 @@ tap.test('should create a verdaccio registry', async () => {
expect(verdaccioRegistry).to.be.instanceOf(smartnpm.NpmRegistry); expect(verdaccioRegistry).to.be.instanceOf(smartnpm.NpmRegistry);
}); });
tap.test('should get package from verdaccui', async () => { tap.test('should get package from verdaccio', async () => {
const npmPackage = await verdaccioRegistry.getPackageInfo('@pushrocks/smartupdate'); const npmPackage = await verdaccioRegistry.getPackageInfo('@pushrocks/smartupdate');
console.log(npmPackage);
expect(npmPackage.license).to.equal('MIT'); expect(npmPackage.license).to.equal('MIT');
}); });
tap.test('should get a specific file from a package', async () => {
const bundleFile = await verdaccioRegistry.getFileFromPackage(
'@pushrocks/websetup',
'dist_bundle/bundle.js'
);
});
tap.start(); tap.start();

View File

@ -2,8 +2,11 @@ import * as plugins from './smartnpm.plugins';
import { NpmRegistry } from './smartnpm.classes.npmregistry'; import { NpmRegistry } from './smartnpm.classes.npmregistry';
export class NpmPackage { export class NpmPackage {
public static async createFromFullMetadata(npmRegistry: NpmRegistry, fullMetadata: plugins.packageJson.FullMetadata) { public static async createFromFullMetadata(
const npmPackage = new NpmPackage(); npmRegistryArg: NpmRegistry,
fullMetadata: plugins.packageJson.FullMetadata
) {
const npmPackage = new NpmPackage(npmRegistryArg);
Object.assign(npmPackage, fullMetadata); Object.assign(npmPackage, fullMetadata);
return npmPackage; return npmPackage;
} }
@ -30,6 +33,11 @@ export class NpmPackage {
email: 'npm@git.zone'; email: 'npm@git.zone';
}; };
public maintainers: any = null; public maintainers: any = null;
public dist: {
integrity: string;
shasum: string;
tarball: string;
};
public score: { public score: {
final: number; final: number;
detail: { detail: {
@ -39,4 +47,17 @@ export class NpmPackage {
}; };
} = null; } = null;
public searchScore: number = null; public searchScore: number = null;
public npmRegistry: NpmRegistry;
constructor(npmRegistryArg: NpmRegistry) {
this.npmRegistry = npmRegistryArg;
}
/**
* saves the package to disk
*/
public async saveToDisk(targetDir: string) {
const smartarchiveInstance = new plugins.smartarchive.SmartArchive();
await smartarchiveInstance.extractArchiveFromUrl(this.dist.tarball, targetDir);
}
} }

View File

@ -1,4 +1,5 @@
import * as plugins from './smartnpm.plugins'; import * as plugins from './smartnpm.plugins';
import * as paths from './smartnpm.paths';
// interfaces // interfaces
import { ISearchObject } from './smartnpm.interfaces'; import { ISearchObject } from './smartnpm.interfaces';
@ -25,6 +26,10 @@ export class NpmRegistry {
}; };
} }
/**
* gets info about a package
* @param packageName
*/
public async getPackageInfo(packageName: string): Promise<NpmPackage> { public async getPackageInfo(packageName: string): Promise<NpmPackage> {
const fullMetadata = await plugins.packageJson(packageName, { const fullMetadata = await plugins.packageJson(packageName, {
registryUrl: this.options.npmRegistryUrl, registryUrl: this.options.npmRegistryUrl,
@ -34,7 +39,35 @@ export class NpmRegistry {
return npmPackage; return npmPackage;
} }
public async search(searchObjectArg: ISearchObject) { /**
* saves a package to disk
* @param packageName
* @param targetDir
*/
public async savePackageToDisk(packageName: string, targetDir: string): Promise<void> {
const npmPackage = await this.getPackageInfo(packageName);
await npmPackage.saveToDisk(targetDir);
}
/**
* gets a file from a package as Smartfile
*/
public async getFileFromPackage(packageName: string, filePath: string) {
const baseDir = plugins.path.join(paths.nogitDir, packageName.replace('/', '__'));
await plugins.smartfile.fs.ensureDir(baseDir);
await this.savePackageToDisk(packageName, baseDir);
const smartfile = await plugins.smartfile.Smartfile.fromFilePath(
plugins.path.join(baseDir, 'package', filePath)
);
await plugins.smartfile.fs.remove(baseDir);
return smartfile;
}
/**
* searches for a package on npm
* @param searchObjectArg
*/
public async searchOnNpm(searchObjectArg: ISearchObject) {
if (this.options.npmRegistryUrl !== 'https://registry.npmjs.org') { if (this.options.npmRegistryUrl !== 'https://registry.npmjs.org') {
throw Error(`cannot search registries other than registry.gitlab.com`); throw Error(`cannot search registries other than registry.gitlab.com`);
} }

5
ts/smartnpm.paths.ts Normal file
View File

@ -0,0 +1,5 @@
import * as plugins from './smartnpm.plugins';
export const packageDir = plugins.path.join(__dirname, '../');
export const nogitDir = plugins.path.join(packageDir, '.nogit/');
plugins.smartfile.fs.ensureDirSync(nogitDir);

View File

@ -1,10 +1,17 @@
// node native modules
import * as path from 'path';
export { path };
// @pushrocks scope // @pushrocks scope
import * as consolecolor from '@pushrocks/consolecolor'; import * as consolecolor from '@pushrocks/consolecolor';
import * as smartarchive from '@pushrocks/smartarchive';
import * as smartfile from '@pushrocks/smartfile';
import * as smartlog from '@pushrocks/smartlog'; import * as smartlog from '@pushrocks/smartlog';
smartlog.defaultLogger.enableConsole(); smartlog.defaultLogger.enableConsole();
import * as smartrequest from '@pushrocks/smartrequest'; import * as smartrequest from '@pushrocks/smartrequest';
export { consolecolor, smartlog, smartrequest }; export { consolecolor, smartarchive, smartfile, smartlog, smartrequest };
// third party scope // third party scope
import packageJson from 'package-json'; import packageJson from 'package-json';