Compare commits
38 Commits
Author | SHA1 | Date | |
---|---|---|---|
af0d95f327 | |||
d0ac8f1418 | |||
62f8106fc6 | |||
e87b8c994b | |||
694ba7be25 | |||
952399c26e | |||
ab1e83b8bf | |||
67980f9f41 | |||
2d34397b9b | |||
2744e1a92b | |||
b8987b7913 | |||
95ffb06e77 | |||
71abbbb5f1 | |||
9dfa1a789e | |||
c68ea1c8fd | |||
8e943512f8 | |||
c010319076 | |||
cf03e58c6f | |||
d59875f23f | |||
6b13e46947 | |||
096c38de9e | |||
7292b45d33 | |||
3ddad53d29 | |||
617b49aaba | |||
2dcd93b431 | |||
0e2dc83409 | |||
2cb227632f | |||
d0f6e88388 | |||
e72a5cb4af | |||
0d3292dd1e | |||
54db436174 | |||
7075d7b36f | |||
98aca88b49 | |||
5f49845138 | |||
1d5e94244b | |||
7cc7c54587 | |||
24af38ed8b | |||
96b21b57ce |
17
.gitignore
vendored
17
.gitignore
vendored
@ -1,5 +1,20 @@
|
|||||||
.nogit/
|
.nogit/
|
||||||
node_modules/
|
|
||||||
|
# artifacts
|
||||||
coverage/
|
coverage/
|
||||||
public/
|
public/
|
||||||
pages/
|
pages/
|
||||||
|
|
||||||
|
# installs
|
||||||
|
node_modules/
|
||||||
|
|
||||||
|
# caches
|
||||||
|
.yarn/
|
||||||
|
.cache/
|
||||||
|
.rpt2_cache
|
||||||
|
|
||||||
|
# builds
|
||||||
|
dist/
|
||||||
|
dist_*/
|
||||||
|
|
||||||
|
# custom
|
149
.gitlab-ci.yml
149
.gitlab-ci.yml
@ -1,16 +1,16 @@
|
|||||||
# gitzone standard
|
# gitzone ci_default
|
||||||
image: hosttoday/ht-docker-node:npmci
|
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,109 +18,114 @@ stages:
|
|||||||
mirror:
|
mirror:
|
||||||
stage: security
|
stage: security
|
||||||
script:
|
script:
|
||||||
- npmci git mirror
|
- npmci git mirror
|
||||||
|
only:
|
||||||
|
- tags
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- lossless
|
||||||
- notpriv
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
snyk:
|
auditProductionDependencies:
|
||||||
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
stage: security
|
stage: security
|
||||||
script:
|
script:
|
||||||
- npmci command npm install -g snyk
|
- npmci npm prepare
|
||||||
- npmci command npm install --ignore-scripts
|
- npmci command npm install --production --ignore-scripts
|
||||||
- npmci command snyk test
|
- npmci command npm config set registry https://registry.npmjs.org
|
||||||
|
- npmci command npm audit --audit-level=high --only=prod --production
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
|
||||||
|
auditDevDependencies:
|
||||||
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
|
stage: security
|
||||||
|
script:
|
||||||
|
- npmci npm prepare
|
||||||
|
- npmci command npm install --ignore-scripts
|
||||||
|
- npmci command npm config set registry https://registry.npmjs.org
|
||||||
|
- npmci command npm audit --audit-level=high --only=dev
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
|
allow_failure: true
|
||||||
|
|
||||||
# ====================
|
# ====================
|
||||||
# test stage
|
# test stage
|
||||||
# ====================
|
# ====================
|
||||||
testLEGACY:
|
|
||||||
stage: test
|
|
||||||
script:
|
|
||||||
- npmci node install legacy
|
|
||||||
- npmci npm install
|
|
||||||
- npmci npm test
|
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
allow_failure: true
|
|
||||||
|
|
||||||
testLTS:
|
testStable:
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
- npmci node install lts
|
- npmci npm prepare
|
||||||
- npmci npm install
|
- npmci node install stable
|
||||||
- npmci npm test
|
- npmci npm install
|
||||||
|
- npmci npm test
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
|
||||||
|
testBuild:
|
||||||
testSTABLE:
|
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
- npmci node install stable
|
- npmci npm prepare
|
||||||
- npmci npm install
|
- npmci node install stable
|
||||||
- npmci npm test
|
- npmci npm install
|
||||||
|
- npmci command npm run build
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
|
||||||
|
|
||||||
release:
|
release:
|
||||||
stage: release
|
stage: release
|
||||||
script:
|
script:
|
||||||
- npmci node install stable
|
- 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
|
||||||
# ====================
|
# ====================
|
||||||
codequality:
|
codequality:
|
||||||
stage: metadata
|
stage: metadata
|
||||||
image: docker:stable
|
|
||||||
allow_failure: true
|
allow_failure: true
|
||||||
services:
|
only:
|
||||||
- docker:stable-dind
|
- tags
|
||||||
script:
|
script:
|
||||||
- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')
|
- npmci command npm install -g tslint typescript
|
||||||
- docker run
|
- npmci npm prepare
|
||||||
--env SOURCE_CODE="$PWD"
|
- npmci npm install
|
||||||
--volume "$PWD":/code
|
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
|
||||||
--volume /var/run/docker.sock:/var/run/docker.sock
|
|
||||||
"registry.gitlab.com/gitlab-org/security-products/codequality:$SP_VERSION" /code
|
|
||||||
artifacts:
|
|
||||||
paths: [codeclimate.json]
|
|
||||||
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-node:npmci
|
|
||||||
stage: metadata
|
stage: metadata
|
||||||
script:
|
script:
|
||||||
- npmci command npm install -g typedoc typescript
|
- npmci node install lts
|
||||||
|
- npmci command npm install -g @gitzone/tsdoc
|
||||||
|
- npmci npm prepare
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci command typedoc --module "commonjs" --target "ES2016" --out public/ ts/
|
- npmci command tsdoc
|
||||||
tags:
|
tags:
|
||||||
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
- notpriv
|
||||||
only:
|
only:
|
||||||
@ -128,15 +133,5 @@ pages:
|
|||||||
artifacts:
|
artifacts:
|
||||||
expire_in: 1 week
|
expire_in: 1 week
|
||||||
paths:
|
paths:
|
||||||
- public
|
- public
|
||||||
allow_failure: true
|
|
||||||
|
|
||||||
windowsCompatibility:
|
|
||||||
image: stefanscherer/node-windows:10-build-tools
|
|
||||||
stage: metadata
|
|
||||||
script:
|
|
||||||
- npm install & npm test
|
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
|
||||||
tags:
|
|
||||||
- windows
|
|
||||||
allow_failure: true
|
allow_failure: true
|
||||||
|
29
.vscode/launch.json
vendored
Normal file
29
.vscode/launch.json
vendored
Normal 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
26
.vscode/settings.json
vendored
Normal 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", "wcc"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
2
dist/index.d.ts
vendored
2
dist/index.d.ts
vendored
@ -1,2 +0,0 @@
|
|||||||
export * from './smartnpm.classes.npmregistry';
|
|
||||||
export * from './smartnpm.classes.npmpackage';
|
|
8
dist/index.js
vendored
8
dist/index.js
vendored
@ -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==
|
|
32
dist/smartnpm.classes.npmpackage.d.ts
vendored
32
dist/smartnpm.classes.npmpackage.d.ts
vendored
@ -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);
|
|
||||||
}
|
|
24
dist/smartnpm.classes.npmpackage.js
vendored
24
dist/smartnpm.classes.npmpackage.js
vendored
@ -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
|
|
6
dist/smartnpm.classes.npmregistry.d.ts
vendored
6
dist/smartnpm.classes.npmregistry.d.ts
vendored
@ -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[]>;
|
|
||||||
}
|
|
104
dist/smartnpm.classes.npmregistry.js
vendored
104
dist/smartnpm.classes.npmregistry.js
vendored
@ -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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRucG0uY2xhc3Nlcy5ucG1yZWdpc3RyeS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0bnBtLmNsYXNzZXMubnBtcmVnaXN0cnkudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7OztBQUFBLDhDQUE2QztBQUs3QyxVQUFVO0FBQ1YsK0VBQTBEO0FBRTFELE1BQWEsV0FBVztJQUF4QjtRQUNVLGlCQUFZLEdBQUcsa0NBQWtDLENBQUE7SUF5RTNELENBQUM7SUF4RU8sTUFBTSxDQUFFLGVBQThCOztZQUMxQyxJQUFJLFlBQVksR0FBRyxFQUFFLENBQUE7WUFDckIsSUFBSSxpQkFBaUIsR0FBRyxDQUFDLFlBQW9CLEVBQUUsRUFBRTtnQkFDL0MsWUFBWSxHQUFHLEdBQUcsWUFBWSxJQUFJLFlBQVksRUFBRSxDQUFBO1lBQ2xELENBQUMsQ0FBQTtZQUVELE9BQU87WUFDUCxJQUFJLGVBQWUsQ0FBQyxJQUFJLEVBQUU7Z0JBQUUsWUFBWSxHQUFHLEdBQUcsZUFBZSxDQUFDLElBQUksRUFBRSxDQUFBO2FBQUU7WUFFdEUsV0FBVztZQUNYLElBQUksZUFBZSxDQUFDLE1BQU0sRUFBRTtnQkFBRSxpQkFBaUIsQ0FBQyxVQUFVLGVBQWUsQ0FBQyxNQUFNLEVBQUUsQ0FBQyxDQUFBO2FBQUU7WUFDckYsSUFBSSxlQUFlLENBQUMsVUFBVSxFQUFFO2dCQUFFLGlCQUFpQixDQUFDLGNBQWMsZUFBZSxDQUFDLFVBQVUsRUFBRSxDQUFDLENBQUE7YUFBRTtZQUNqRyxJQUFJLGVBQWUsQ0FBQyxLQUFLLEVBQUU7Z0JBQUUsaUJBQWlCLENBQUMsU0FBUyxlQUFlLENBQUMsS0FBSyxFQUFFLENBQUMsQ0FBQTthQUFFO1lBRWxGLFNBQVM7WUFDVCxJQUFJLGVBQWUsQ0FBQyxVQUFVLEVBQUU7Z0JBQzlCLElBQUksZUFBZSxDQUFDLFVBQVUsS0FBSyxJQUFJLEVBQUU7b0JBQ3ZDLGlCQUFpQixDQUFDLGVBQWUsQ0FBQyxDQUFBO2lCQUNuQztxQkFBTTtvQkFDTCxpQkFBaUIsQ0FBQyxnQkFBZ0IsQ0FBQyxDQUFBO2lCQUNwQzthQUNGO1lBQ0QsSUFBSSxlQUFlLENBQUMsUUFBUSxFQUFFO2dCQUM1QixJQUFJLGVBQWUsQ0FBQyxRQUFRLEtBQUssSUFBSSxFQUFFO29CQUNyQyxpQkFBaUIsQ0FBQyxhQUFhLENBQUMsQ0FBQTtpQkFDakM7cUJBQU07b0JBQ0wsaUJBQWlCLENBQUMsY0FBYyxDQUFDLENBQUE7aUJBQ2xDO2FBQ0Y7WUFDRCxJQUFJLGVBQWUsQ0FBQyxRQUFRLEVBQUU7Z0JBQzVCLElBQUksZUFBZSxDQUFDLFFBQVEsS0FBSyxJQUFJLEVBQUU7b0JBQ3JDLGlCQUFpQixDQUFDLGFBQWEsQ0FBQyxDQUFBO2lCQUNqQztxQkFBTTtvQkFDTCxpQkFBaUIsQ0FBQyxjQUFjLENBQUMsQ0FBQTtpQkFDbEM7YUFDRjtZQUVELG1CQUFtQjtZQUNuQixJQUFJLGVBQWUsQ0FBQyxVQUFVLEVBQUU7Z0JBQUUsaUJBQWlCLENBQUMsZUFBZSxlQUFlLENBQUMsVUFBVSxFQUFFLENBQUMsQ0FBQTthQUFFO1lBQ2xHLElBQUksZUFBZSxDQUFDLFdBQVcsRUFBRTtnQkFBRSxpQkFBaUIsQ0FBQyxnQkFBZ0IsZUFBZSxDQUFDLFdBQVcsRUFBRSxDQUFDLENBQUE7YUFBRTtZQUVyRyxZQUFZO1lBQ1osSUFBSSxlQUFlLENBQUMsYUFBYSxFQUFFO2dCQUFFLGlCQUFpQixDQUFDLFVBQVUsZUFBZSxDQUFDLGFBQWEsRUFBRSxDQUFDLENBQUE7YUFBRTtZQUNuRyxJQUFJLGVBQWUsQ0FBQyxnQkFBZ0IsRUFBRTtnQkFBRSxpQkFBaUIsQ0FBQyxVQUFVLGVBQWUsQ0FBQyxnQkFBZ0IsRUFBRSxDQUFDLENBQUE7YUFBRTtZQUN6RyxJQUFJLGVBQWUsQ0FBQyxpQkFBaUIsRUFBRTtnQkFBRSxpQkFBaUIsQ0FBQyxVQUFVLGVBQWUsQ0FBQyxpQkFBaUIsRUFBRSxDQUFDLENBQUE7YUFBRTtZQUUzRyxPQUFPLENBQUMsUUFBUSxDQUFDLGFBQWEsQ0FBQyxJQUFJLENBQUMscUJBQXFCLE9BQU8sQ0FBQyxZQUFZLENBQUMsYUFBYSxDQUFDLFlBQVksRUFBRSxNQUFNLENBQUMsRUFBRSxDQUFDLENBQUE7WUFFcEgsSUFBSSxJQUFTLENBQUM7WUFDZCxJQUFJO2dCQUNGLElBQUksUUFBUSxHQUFHLENBQUMsTUFBTSxPQUFPLENBQUMsWUFBWSxDQUFDLE9BQU8sQ0FBQyxJQUFJLENBQUMsWUFBWSxHQUFHLFlBQVksRUFBRSxFQUFFLENBQUMsQ0FBQyxDQUFBO2dCQUN6RixJQUFJLEdBQUcsUUFBUSxDQUFDLElBQUksQ0FBQTthQUNyQjtZQUFDLFdBQU07Z0JBQ04sZ0JBQWdCO2FBQ2pCO1lBR0QsK0JBQStCO1lBQy9CLElBQUksWUFBWSxHQUFpQixFQUFFLENBQUE7WUFFbkMseUNBQXlDO1lBQ3pDLElBQUksQ0FBQyxJQUFJLElBQUksT0FBTyxJQUFJLEtBQUssUUFBUSxFQUFFO2dCQUNyQyxPQUFPLFlBQVksQ0FBQTthQUNwQjtZQUVELEtBQUssSUFBSSxVQUFVLElBQUksSUFBSSxDQUFDLE9BQU8sRUFBRTtnQkFDbkMsSUFBSSxZQUFZLEdBQUcsSUFBSSx3Q0FBVSxDQUFDLFVBQVUsQ0FBQyxPQUFPLENBQUMsQ0FBQTtnQkFDckQsWUFBWSxDQUFDLElBQUksQ0FBQyxZQUFZLENBQUMsQ0FBQTthQUNoQztZQUVELE9BQU8sWUFBWSxDQUFBO1FBQ3JCLENBQUM7S0FBQTtDQUNGO0FBMUVELGtDQTBFQyJ9
|
|
15
dist/smartnpm.interfaces.d.ts
vendored
15
dist/smartnpm.interfaces.d.ts
vendored
@ -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;
|
|
||||||
}
|
|
3
dist/smartnpm.interfaces.js
vendored
3
dist/smartnpm.interfaces.js
vendored
@ -1,3 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRucG0uaW50ZXJmYWNlcy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0bnBtLmludGVyZmFjZXMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IiJ9
|
|
4
dist/smartnpm.plugins.d.ts
vendored
4
dist/smartnpm.plugins.d.ts
vendored
@ -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 };
|
|
10
dist/smartnpm.plugins.js
vendored
10
dist/smartnpm.plugins.js
vendored
@ -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=
|
|
@ -2,5 +2,16 @@
|
|||||||
"npmci": {
|
"npmci": {
|
||||||
"npmGlobalTools": [],
|
"npmGlobalTools": [],
|
||||||
"npmAccessLevel": "public"
|
"npmAccessLevel": "public"
|
||||||
|
},
|
||||||
|
"gitzone": {
|
||||||
|
"projectType": "npm",
|
||||||
|
"module": {
|
||||||
|
"githost": "gitlab.com",
|
||||||
|
"gitscope": "pushrocks",
|
||||||
|
"gitrepo": "smartnpm",
|
||||||
|
"shortDescription": "interface with npm to retrieve package information",
|
||||||
|
"npmPackagename": "@pushrocks/smartnpm",
|
||||||
|
"license": "MIT"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
12170
package-lock.json
generated
12170
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
48
package.json
48
package.json
@ -1,28 +1,48 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartnpm",
|
"name": "@pushrocks/smartnpm",
|
||||||
"version": "1.0.9",
|
"version": "1.0.29",
|
||||||
"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": {
|
||||||
"test": "(tstest test/)",
|
"test": "(tstest test/)",
|
||||||
"build": "(tsbuild)"
|
"build": "(tsbuild --web)"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.0.22",
|
"@gitzone/tsbuild": "^2.1.25",
|
||||||
"@gitzone/tsrun": "^1.1.13",
|
"@gitzone/tsrun": "^1.2.12",
|
||||||
"@gitzone/tstest": "^1.0.15",
|
"@gitzone/tstest": "^1.0.54",
|
||||||
"@pushrocks/tapbundle": "^3.0.7",
|
"@pushrocks/tapbundle": "^3.2.14",
|
||||||
"@types/node": "^10.12.3",
|
"@types/node": "^15.0.1",
|
||||||
"tslint": "^5.11.0",
|
"tslint": "^6.1.3",
|
||||||
"tslint-config-prettier": "^1.15.0"
|
"tslint-config-prettier": "^1.18.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/consolecolor": "^2.0.1",
|
"@pushrocks/consolecolor": "^2.0.1",
|
||||||
"@pushrocks/smartlog": "^2.0.8",
|
"@pushrocks/levelcache": "^1.0.9",
|
||||||
"@pushrocks/smartrequest": "^1.1.14"
|
"@pushrocks/smartarchive": "^2.0.4",
|
||||||
}
|
"@pushrocks/smartfile": "^8.0.10",
|
||||||
|
"@pushrocks/smartpromise": "^3.1.5",
|
||||||
|
"@pushrocks/smartrequest": "^1.1.51",
|
||||||
|
"@pushrocks/smartversion": "^2.0.7",
|
||||||
|
"package-json": "^6.5.0"
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"ts/**/*",
|
||||||
|
"ts_web/**/*",
|
||||||
|
"dist/**/*",
|
||||||
|
"dist_*/**/*",
|
||||||
|
"dist_ts/**/*",
|
||||||
|
"dist_ts_web/**/*",
|
||||||
|
"assets/**/*",
|
||||||
|
"cli.js",
|
||||||
|
"npmextra.json",
|
||||||
|
"readme.md"
|
||||||
|
],
|
||||||
|
"browserslist": [
|
||||||
|
"last 1 chrome versions"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
46
readme.md
46
readme.md
@ -1,33 +1,39 @@
|
|||||||
# smartnpm
|
# @pushrocks/smartnpm
|
||||||
|
|
||||||
interface with npm to retrieve package information
|
interface with npm to retrieve package information
|
||||||
|
|
||||||
## Availabililty
|
## Availabililty and Links
|
||||||
|
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartnpm)
|
||||||
[](https://www.npmjs.com/package/smartnpm)
|
* [gitlab.com (source)](https://gitlab.com/pushrocks/smartnpm)
|
||||||
[](https://GitLab.com/pushrocks/smartnpm)
|
* [github.com (source mirror)](https://github.com/pushrocks/smartnpm)
|
||||||
[](https://github.com/pushrocks/smartnpm)
|
* [docs (typedoc)](https://pushrocks.gitlab.io/smartnpm/)
|
||||||
[](https://pushrocks.gitlab.io/smartnpm/)
|
|
||||||
|
|
||||||
## Status for master
|
## Status for master
|
||||||
|
|
||||||
[](https://GitLab.com/pushrocks/smartnpm/commits/master)
|
Status Category | Status Badge
|
||||||
[](https://GitLab.com/pushrocks/smartnpm/commits/master)
|
-- | --
|
||||||
[](https://www.npmjs.com/package/smartnpm)
|
GitLab Pipelines | [](https://lossless.cloud)
|
||||||
[](https://david-dm.org/pushrocks/smartnpm)
|
GitLab Pipline Test Coverage | [](https://lossless.cloud)
|
||||||
[](https://www.bithound.io/github/pushrocks/smartnpm/master/dependencies/npm)
|
npm | [](https://lossless.cloud)
|
||||||
[](https://www.bithound.io/github/pushrocks/smartnpm)
|
Snyk | [](https://lossless.cloud)
|
||||||
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
TypeScript Support | [](https://lossless.cloud)
|
||||||
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
node Support | [](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||||
[](http://standardjs.com/)
|
Code Style | [](https://lossless.cloud)
|
||||||
|
PackagePhobia (total standalone install weight) | [](https://lossless.cloud)
|
||||||
|
PackagePhobia (package size on registry) | [](https://lossless.cloud)
|
||||||
|
BundlePhobia (total size when bundled) | [](https://lossless.cloud)
|
||||||
|
Platform support | [](https://lossless.cloud) [](https://lossless.cloud)
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
Use TypeScript for best in class instellisense.
|
Use TypeScript for best in class instellisense.
|
||||||
|
|
||||||
For further information read the linked docs at the top of this README.
|
## 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.
|
||||||
|
|
||||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||||
> | By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
|
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
|
||||||
|
|
||||||
[](https://push.rocks)
|
[](https://maintainedby.lossless.com)
|
||||||
|
187
test/test.ts
187
test/test.ts
@ -1,22 +1,195 @@
|
|||||||
import { expect, tap } from '@pushrocks/tapbundle';
|
import { expect, tap } from '@pushrocks/tapbundle';
|
||||||
import * as smartnpm from '../ts/index';
|
import * as smartnpm from '../ts/index';
|
||||||
|
import { NpmRegistry } from '../ts/index';
|
||||||
|
|
||||||
let testRegistry: smartnpm.NpmRegistry;
|
let npmRegistry: smartnpm.NpmRegistry;
|
||||||
|
let verdaccioRegistry: smartnpm.NpmRegistry;
|
||||||
let testPackage: smartnpm.NpmPackage;
|
let testPackage: smartnpm.NpmPackage;
|
||||||
|
|
||||||
|
// lets test things with the standard npm registry
|
||||||
tap.test('should create valid instances', async () => {
|
tap.test('should create valid instances', async () => {
|
||||||
testRegistry = new smartnpm.NpmRegistry();
|
npmRegistry = new smartnpm.NpmRegistry();
|
||||||
expect(testRegistry).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 () => {
|
||||||
let packages = await testRegistry.search({
|
const packages = await npmRegistry.searchOnNpm({
|
||||||
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
|
||||||
|
tap.test('should create a verdaccio registry', async () => {
|
||||||
|
verdaccioRegistry = new NpmRegistry({
|
||||||
|
npmRegistryUrl: 'https://verdaccio.lossless.one',
|
||||||
|
});
|
||||||
|
expect(verdaccioRegistry).to.be.instanceOf(smartnpm.NpmRegistry);
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('should get package from verdaccio', async () => {
|
||||||
|
const npmPackage = await verdaccioRegistry.getPackageInfo('@pushrocks/smartupdate');
|
||||||
|
console.log(npmPackage);
|
||||||
|
expect(npmPackage.license).to.equal('MIT');
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('should get a specific file from a package', async () => {
|
||||||
|
const bundleFile = await verdaccioRegistry.getFileFromPackage(
|
||||||
|
'@pushrocks/websetup',
|
||||||
|
'ts/index.ts'
|
||||||
|
);
|
||||||
|
console.log(bundleFile.contentBuffer.toString());
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.start();
|
tap.start();
|
||||||
|
|
||||||
|
const hi = {
|
||||||
|
_id: '@pushrocks/smartversion',
|
||||||
|
_rev: '2-93b6e6391f7209fcbd1db76c92164777',
|
||||||
|
name: '@pushrocks/smartversion',
|
||||||
|
'dist-tags': { latest: '2.0.4' },
|
||||||
|
versions: {
|
||||||
|
'2.0.0': {
|
||||||
|
name: '@pushrocks/smartversion',
|
||||||
|
version: '2.0.0',
|
||||||
|
private: false,
|
||||||
|
description: 'handle semver with easy',
|
||||||
|
main: 'dist/index.js',
|
||||||
|
typings: 'dist/index.d.ts',
|
||||||
|
author: { name: 'Lossless GmbH' },
|
||||||
|
license: 'MIT',
|
||||||
|
scripts: { test: '(tstest test/)', build: '(tsbuild)' },
|
||||||
|
devDependencies: {
|
||||||
|
'@gitzone/tsbuild': '^2.0.22',
|
||||||
|
'@gitzone/tsrun': '^1.1.12',
|
||||||
|
'@gitzone/tstest': '^1.0.15',
|
||||||
|
'@pushrocks/tapbundle': '^3.0.5',
|
||||||
|
'@types/node': '^10.9.4',
|
||||||
|
},
|
||||||
|
dependencies: { '@types/semver': '^5.5.0', semver: '^5.5.1' },
|
||||||
|
gitHead: 'df6b1a9730551884aa4c4fae5577b2b11058f508',
|
||||||
|
_id: '@pushrocks/smartversion@2.0.0',
|
||||||
|
_npmVersion: '6.2.0',
|
||||||
|
_nodeVersion: '10.9.0',
|
||||||
|
_npmUser: { name: 'lossless', email: 'npm@lossless.com' },
|
||||||
|
dist: {
|
||||||
|
integrity:
|
||||||
|
'sha512-+loQHivWzEO39X/PEzi+UOptDveez0n8Eu/bDIht55wkjhav33HkNjab8MeK/g76gOia3ZHoPyqLTvD4yvXDiA==',
|
||||||
|
shasum: 'd663a39d77950de1a743adb0c2eb00e325d230df',
|
||||||
|
tarball: 'https://registry.npmjs.org/@pushrocks/smartversion/-/smartversion-2.0.0.tgz',
|
||||||
|
fileCount: 12,
|
||||||
|
unpackedSize: 12011,
|
||||||
|
'npm-signature':
|
||||||
|
'-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJbi7zUCRA9TVsSAnZWagAAigcP/0gRmizQkzjE9Gw8gCeK\n56m41mJQmtl6tRvYVyVGuqfiCaiLvB/B0fkKt2r/MNsJVjC372ayWKya4nev\nTOLSg+g4e9gnkyn8i1OFVE5kr8C4MvLc6P771v2UDXJF5c3pYq6i5fSyGz/s\ngpOuy/KxyVo5wH16yasGWDq9Gl58yp+7vZKR6cc+7Rlq0UhyezhDBRBiKkB0\nk6Y/4J4KWK7CmO+3Y/QUPGBxGmoUHNSiS5cz8vWbycRP7pT11asksgxNPGdv\nyeW/VNVLZkemwrXhSuYKM0DK6aZpjJxk3A8OAyDuHGfZDzAmyaRsfUL84Mgl\nlN1S92CCfuAOyA1os8rsrJU133TV8zVTck3IdmO4AqJ8aB3WNkmNYE5IHxWf\nnmhUUo1Rv/M5fJniTHOBGaeOahFqEp+8URNW1zylC3NoFwiUon1lvnMp1Dd1\nczGPWvQ12ZAeMOR/qpO4RRzTdD45iuvvj2NRhZZN1pthnhUi8XpgMIDuCODT\n2Srew7JBkdfX3F1q/LGgk9e+RYCWTlLPgmzOBUH39ljpfa70liAH5sU+yyfk\nFLfVQlLwWAEwRnkm4j/l/xBWJcwqVG2nDOOzScfYVG3BXSBHo4PfywhFdbnc\nQ3MMrJsrJPhppfMJEEQWlQSkNSCCEV7DDPeH4oK9tKRUdmDaKJpnb6tVZqzM\nBWac\r\n=0NZU\r\n-----END PGP SIGNATURE-----\r\n',
|
||||||
|
},
|
||||||
|
maintainers: [{ name: 'lossless', email: 'npm@lossless.com' }],
|
||||||
|
directories: {},
|
||||||
|
_npmOperationalInternal: {
|
||||||
|
host: 's3://npm-registry-packages',
|
||||||
|
tmp: 'tmp/smartversion_2.0.0_1535884499821_0.9273118882229912',
|
||||||
|
},
|
||||||
|
_hasShrinkwrap: false,
|
||||||
|
},
|
||||||
|
'2.0.3': {
|
||||||
|
name: '@pushrocks/smartversion',
|
||||||
|
version: '2.0.3',
|
||||||
|
private: false,
|
||||||
|
description: 'handle semver with easy',
|
||||||
|
main: 'dist/index.js',
|
||||||
|
typings: 'dist/index.d.ts',
|
||||||
|
author: { name: 'Lossless GmbH' },
|
||||||
|
license: 'MIT',
|
||||||
|
scripts: { test: '(tstest test/)', build: '(tsbuild)' },
|
||||||
|
devDependencies: {
|
||||||
|
'@gitzone/tsbuild': '^2.1.17',
|
||||||
|
'@gitzone/tsrun': '^1.2.8',
|
||||||
|
'@gitzone/tstest': '^1.0.24',
|
||||||
|
'@pushrocks/tapbundle': '^3.0.13',
|
||||||
|
'@types/node': '^12.7.5',
|
||||||
|
},
|
||||||
|
dependencies: { '@types/semver': '^6.0.2', semver: '^6.3.0' },
|
||||||
|
gitHead: 'e364545d0ef6ef7fa1b8467fb48d2b67f09f2d07',
|
||||||
|
_id: '@pushrocks/smartversion@2.0.3',
|
||||||
|
_nodeVersion: '12.10.0',
|
||||||
|
_npmVersion: '6.11.3',
|
||||||
|
dist: {
|
||||||
|
integrity:
|
||||||
|
'sha512-nhauxBGMxjJtXj+k1Z7H2yB184ZhWhU0NKN5ATwlgfEM4zbbZNjCFRLVg/7sOXvbS2b0QU1aStRQ+6QGC2hW4A==',
|
||||||
|
shasum: '9272da89412556946c5a3d5ba3b6a253154de6ae',
|
||||||
|
tarball: 'https://registry.npmjs.org/@pushrocks/smartversion/-/smartversion-2.0.3.tgz',
|
||||||
|
fileCount: 9,
|
||||||
|
unpackedSize: 9127,
|
||||||
|
'npm-signature':
|
||||||
|
'-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJdeRYfCRA9TVsSAnZWagAApCkP/RrWk6+hxpoTpflJ65x/\nm05egDhfyTs2BZKArkSnvtc+q6Fo3iDlumqiv3HRyHwDBFLgK5gAOgU0jyqW\nmhwumGMfKT4bzG65iU2z6FgS+RhEh3JaKzjgPohr1oEaLOaaKL0S9+Ybxt6u\nkwv4CgnmzQ/6zVZYJ+qFbV0v+n6iiuIbOTS8j7+X0nA/DkvvZ1Nwhng++vH8\nLm8lT78F/vcxHkSf2RfC6kabhVF+vVRBazq/cI4OQ+xjBQC2y+6YxEq/4Hsz\nKZBF9u2ZcyeI7NEuo1FaojvqvLX3lPxi9Xfw2PSO2iri+DS8KIOVgzwJ+9ih\nb1h/vpoFv8dbhZzkqSs/4rab3rvQYqy7AgvslI8mEeOQk/BhrjxQIvG0re3H\nzc0iWlNp6W3Lsf3/gmKGZbhl39ZgQxInfWLNW60ghqzUq85gyAwPDRb2yxez\nP7bMT0qb/bQSmAa63/q3qE+JAjZFQFDB6Pj6sO1p3csv0T+7mRj9T/4pSc8B\nv5rD9t0mVlAZXwmz3zDhpomct3bhUlAidw7tcax8sr9SowA2hqY3TB1uJ52y\nKPDVMQZ4Voi7kft+icYoVm1XkQMwmmedAoTbS49s52wW6dm4CWmnlBOZzzqN\neT4Q1INrTUXaMxRv/zxguk7TV8xi6gRf+EBDtnEKukITWTvvPsGq4SS9toRa\n9L6F\r\n=yVBx\r\n-----END PGP SIGNATURE-----\r\n',
|
||||||
|
},
|
||||||
|
maintainers: [{ name: 'lossless', email: 'npm@lossless.com' }],
|
||||||
|
_npmUser: { name: 'lossless', email: 'npm@lossless.com' },
|
||||||
|
directories: {},
|
||||||
|
_npmOperationalInternal: {
|
||||||
|
host: 's3://npm-registry-packages',
|
||||||
|
tmp: 'tmp/smartversion_2.0.3_1568216607132_0.9216415895294796',
|
||||||
|
},
|
||||||
|
_hasShrinkwrap: false,
|
||||||
|
},
|
||||||
|
'2.0.4': {
|
||||||
|
name: '@pushrocks/smartversion',
|
||||||
|
version: '2.0.4',
|
||||||
|
private: false,
|
||||||
|
description: 'handle semver with easy',
|
||||||
|
main: 'dist/index.js',
|
||||||
|
typings: 'dist/index.d.ts',
|
||||||
|
author: { name: 'Lossless GmbH' },
|
||||||
|
license: 'MIT',
|
||||||
|
scripts: { test: '(tstest test/)', build: '(tsbuild)' },
|
||||||
|
devDependencies: {
|
||||||
|
'@gitzone/tsbuild': '^2.1.17',
|
||||||
|
'@gitzone/tsrun': '^1.2.8',
|
||||||
|
'@gitzone/tstest': '^1.0.24',
|
||||||
|
'@pushrocks/tapbundle': '^3.0.13',
|
||||||
|
'@types/node': '^12.7.5',
|
||||||
|
tslint: '^5.20.0',
|
||||||
|
'tslint-config-prettier': '^1.18.0',
|
||||||
|
},
|
||||||
|
dependencies: { '@types/semver': '^6.0.2', semver: '^6.3.0' },
|
||||||
|
gitHead: 'bb8e7cb608f3a116e7bfb0b52dd5ce9a7c4eaec1',
|
||||||
|
_id: '@pushrocks/smartversion@2.0.4',
|
||||||
|
_nodeVersion: '12.10.0',
|
||||||
|
_npmVersion: '6.11.3',
|
||||||
|
dist: {
|
||||||
|
integrity:
|
||||||
|
'sha512-LrtaWRn1DD2zIUr8nVAsKwZ+Y55TFIVZ0z3xjwAQ46SoiTrFWooeQ2Xw18DqsEo1cEqMZyGAskaJkOaRkXHtUA==',
|
||||||
|
shasum: '7c6297f9c596e729001c2b6e2a8fa72c40ed42a9',
|
||||||
|
tarball: 'https://registry.npmjs.org/@pushrocks/smartversion/-/smartversion-2.0.4.tgz',
|
||||||
|
fileCount: 9,
|
||||||
|
unpackedSize: 9263,
|
||||||
|
'npm-signature':
|
||||||
|
'-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJdeRazCRA9TVsSAnZWagAAxX0P/j12DYB5zjZQh3/IpY1t\n+vzvLmTgn2b0lhheLxUX9EYMW+cethYbd8Q8p/SOsytfB2IHCKBdkpE5ZAIK\nsv7d/myZaihZ9RHCd/UQOj99b/KfdbN/7ndtEL7V4hmcNyWUmebeRsxMhxZ5\nLRvWMZiNsgdXbKxs6JpId3iuSFuTxRgL41smiklcW0nGRp9uMieN8TC3xmOW\nsia6JcvGNQT1/LD9XN6l9U/ZWfzOMaEtjv4Hd9XzOVv0SMYT5Nyv3JQV2Jd5\nc5G5aGZe0QXSB9LwnNUcXC3mrZ9+SvmqpECcV2BTJ+JJlzp4Pny51r2nPyC6\nypdsfTfDzAL6BIq433OScEyjRMcufLC+caGXPCjUhtPW6wlf9kTFiRd2L3uk\nWhg2LmFhL4bHz67ty2wAy8XlLYOS/QFOZLEZr7bZDhINkkqR5RQd5RfkMJ6Q\n0skcsspq69tWKrgY3Uh6aK30Z+g7C4V/KGfquz6EsET9xP+7MRTVcd+FLfC1\ndfCcfe3/l49oXbCPwApH9X8ETc3HDJuSRdfVV7PVsEzbOwN4sqTIS9vAHXDN\ncjAmrhbZkhA7VD4PNjhEov1veo/UOoNB7xlN4JLuRZ40SqCSr4akVnNImUDc\nCg+b16mZhlVpLNgjVjG9rgDD7zCn+zn9EZTsq3/qL4jEcf4JY+T2YKmf7AMb\nhmej\r\n=eqby\r\n-----END PGP SIGNATURE-----\r\n',
|
||||||
|
},
|
||||||
|
maintainers: [{ name: 'lossless', email: 'npm@lossless.com' }],
|
||||||
|
_npmUser: { name: 'lossless', email: 'npm@lossless.com' },
|
||||||
|
directories: {},
|
||||||
|
_npmOperationalInternal: {
|
||||||
|
host: 's3://npm-registry-packages',
|
||||||
|
tmp: 'tmp/smartversion_2.0.4_1568216754658_0.06886864906713819',
|
||||||
|
},
|
||||||
|
_hasShrinkwrap: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
time: {
|
||||||
|
created: '2018-09-02T10:34:59.735Z',
|
||||||
|
'2.0.0': '2018-09-02T10:34:59.913Z',
|
||||||
|
modified: '2019-09-11T15:45:58.404Z',
|
||||||
|
'2.0.3': '2019-09-11T15:43:27.294Z',
|
||||||
|
'2.0.4': '2019-09-11T15:45:54.786Z',
|
||||||
|
},
|
||||||
|
maintainers: [{ name: 'lossless', email: 'npm@lossless.com' }],
|
||||||
|
description: 'handle semver with easy',
|
||||||
|
author: { name: 'Lossless GmbH' },
|
||||||
|
license: 'MIT',
|
||||||
|
readme:
|
||||||
|
'# @pushrocks/smartversion\nhandle semver with easy\n\n## Availabililty and Links\n* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartversion)\n* [gitlab.com (source)](https://gitlab.com/pushrocks/smartversion)\n* [github.com (source mirror)](https://github.com/pushrocks/smartversion)\n* [docs (typedoc)](https://pushrocks.gitlab.io/smartversion/)\n\n## Status for master\n[](https://gitlab.com/pushrocks/smartversion/commits/master)\n[](https://gitlab.com/pushrocks/smartversion/commits/master)\n[](https://www.npmjs.com/package/@pushrocks/smartversion)\n[](https://snyk.io/test/npm/@pushrocks/smartversion)\n[](https://nodejs.org/dist/latest-v10.x/docs/api/)\n[](https://nodejs.org/dist/latest-v10.x/docs/api/)\n[](https://prettier.io/)\n\n## Usage\n\nUse TypeScript for best in class instellisense.\n\nFor further information read the linked docs at the top of this readme.\n\n> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)\n| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)\n\n[](https://maintainedby.lossless.com)\n',
|
||||||
|
readmeFilename: 'readme.md',
|
||||||
|
};
|
||||||
|
@ -1,27 +1,68 @@
|
|||||||
import * as plugins from './smartnpm.plugins';
|
import * as plugins from './smartnpm.plugins';
|
||||||
|
import { NpmRegistry } from './smartnpm.classes.npmregistry';
|
||||||
|
import { PackageDisttag } from './smartnpm.classes.packagedisttag';
|
||||||
|
import { PackageVersion, IVersionData } from './smartnpm.classes.packageversion';
|
||||||
|
|
||||||
export class NpmPackage {
|
export class NpmPackage {
|
||||||
name: string = null;
|
public static async createFromFullMetadataAndVersionData(
|
||||||
scope: string = null;
|
npmRegistryArg: NpmRegistry,
|
||||||
version: string = null;
|
fullMetadataArg: plugins.packageJson.FullMetadata,
|
||||||
description: string = null;
|
versionsDataArg: {
|
||||||
keywords: string[] = null;
|
name: string;
|
||||||
date: '2017-08-02T11:22:49.144Z';
|
'dist-tags': { [key: string]: string };
|
||||||
links: {
|
versions: { [key: string]: IVersionData };
|
||||||
|
}
|
||||||
|
) {
|
||||||
|
const npmPackage = new NpmPackage(npmRegistryArg);
|
||||||
|
Object.assign(npmPackage, fullMetadataArg);
|
||||||
|
npmPackage.allVersions = [];
|
||||||
|
npmPackage.allDistTags = [];
|
||||||
|
for (const versionArg of Object.keys(versionsDataArg.versions)) {
|
||||||
|
const packageVersion = PackageVersion.createFromVersionData(
|
||||||
|
versionsDataArg.versions[versionArg]
|
||||||
|
);
|
||||||
|
npmPackage.allVersions.push(packageVersion);
|
||||||
|
}
|
||||||
|
for (const distTagArg of Object.keys(versionsDataArg['dist-tags'])) {
|
||||||
|
const packageDistTag = new PackageDisttag(
|
||||||
|
distTagArg,
|
||||||
|
versionsDataArg['dist-tags'][distTagArg]
|
||||||
|
);
|
||||||
|
npmPackage.allDistTags.push(packageDistTag);
|
||||||
|
}
|
||||||
|
return npmPackage;
|
||||||
|
}
|
||||||
|
|
||||||
|
// INSTANCE
|
||||||
|
public name: string = null;
|
||||||
|
public scope: string = null;
|
||||||
|
public version: string = null;
|
||||||
|
public allVersions: PackageVersion[];
|
||||||
|
public allDistTags: PackageDisttag[];
|
||||||
|
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 dist: {
|
||||||
|
integrity: string;
|
||||||
|
shasum: string;
|
||||||
|
tarball: string;
|
||||||
|
};
|
||||||
|
public score: {
|
||||||
final: number;
|
final: number;
|
||||||
detail: {
|
detail: {
|
||||||
quality: number;
|
quality: number;
|
||||||
@ -29,13 +70,107 @@ export class NpmPackage {
|
|||||||
maintenance: number;
|
maintenance: number;
|
||||||
};
|
};
|
||||||
} = null;
|
} = null;
|
||||||
searchScore: number = null;
|
public searchScore: number = null;
|
||||||
|
|
||||||
constructor(descriptionArg) {
|
public npmRegistryRef: NpmRegistry;
|
||||||
for (let key in descriptionArg) {
|
constructor(npmRegistryArg: NpmRegistry) {
|
||||||
if (this[key] === null) {
|
this.npmRegistryRef = npmRegistryArg;
|
||||||
this[key] = descriptionArg[key];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* saves the package to disk
|
||||||
|
*/
|
||||||
|
public async saveToDisk(targetDir: string) {
|
||||||
|
const smartarchiveInstance = new plugins.smartarchive.SmartArchive();
|
||||||
|
await smartarchiveInstance.extractArchiveFromUrlToFs(this.dist.tarball, targetDir);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* saves the complete package to cache
|
||||||
|
*/
|
||||||
|
public async saveToCache() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get files from package
|
||||||
|
*/
|
||||||
|
public async getFilesFromPackage(
|
||||||
|
filePath: string,
|
||||||
|
optionsArg: {
|
||||||
|
distTag?: string;
|
||||||
|
version?: string;
|
||||||
|
},
|
||||||
|
returnOnFirstArg = false
|
||||||
|
): Promise<plugins.smartfile.Smartfile[]> {
|
||||||
|
const done = plugins.smartpromise.defer<plugins.smartfile.Smartfile[]>();
|
||||||
|
const smartarchiveInstance = new plugins.smartarchive.SmartArchive();
|
||||||
|
let tarballUrl = this.dist?.tarball;
|
||||||
|
if (optionsArg?.version || optionsArg?.distTag) {
|
||||||
|
if (optionsArg.distTag && optionsArg.version) {
|
||||||
|
throw new Error('Please either specify version OR disttag, not both.');
|
||||||
|
}
|
||||||
|
let targetVersion: plugins.smartversion.SmartVersion;
|
||||||
|
if (optionsArg.distTag) {
|
||||||
|
const targetDistTag = this.allDistTags.find((distTag) => {
|
||||||
|
return distTag.name === optionsArg.distTag;
|
||||||
|
});
|
||||||
|
if (targetDistTag) {
|
||||||
|
targetVersion = new plugins.smartversion.SmartVersion(targetDistTag.targetVersion);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
targetVersion = plugins.smartversion.SmartVersion.fromFuzzyString(optionsArg.version);
|
||||||
|
}
|
||||||
|
|
||||||
|
// lets find the best matching release
|
||||||
|
const versionStrings = this.allVersions.map((packageVersion) => packageVersion.version);
|
||||||
|
const bestMatchingVersion = targetVersion.getBestMatch(versionStrings);
|
||||||
|
if (!bestMatchingVersion) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
tarballUrl = this.allVersions.find(
|
||||||
|
(packageVersion) => packageVersion.version === bestMatchingVersion
|
||||||
|
).dist.tarball;
|
||||||
|
}
|
||||||
|
const fileObservable = await smartarchiveInstance.extractArchiveFromUrlToObservable(tarballUrl);
|
||||||
|
const wantedFilePath = plugins.path.join('package', filePath);
|
||||||
|
const allMatchingFiles: plugins.smartfile.Smartfile[] = [];
|
||||||
|
const subscription = fileObservable.subscribe(
|
||||||
|
(fileArg) => {
|
||||||
|
// returnOnFirstArg requires exact match
|
||||||
|
if (returnOnFirstArg && fileArg.path === wantedFilePath) {
|
||||||
|
// lets resolve with the wanted file
|
||||||
|
done.resolve([fileArg]);
|
||||||
|
subscription.unsubscribe();
|
||||||
|
} else if(fileArg.path.startsWith(wantedFilePath)) {
|
||||||
|
allMatchingFiles.push(fileArg);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
(err) => {
|
||||||
|
console.log(err);
|
||||||
|
},
|
||||||
|
() => {
|
||||||
|
done.resolve(allMatchingFiles);
|
||||||
|
subscription.unsubscribe();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
return done.promise;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get files from package
|
||||||
|
*/
|
||||||
|
public async getFileFromPackage(
|
||||||
|
filePath: string,
|
||||||
|
optionsArg?: {
|
||||||
|
distTag?: string;
|
||||||
|
version?: string;
|
||||||
|
}
|
||||||
|
): Promise<plugins.smartfile.Smartfile> {
|
||||||
|
const result = await this.getFilesFromPackage(filePath, optionsArg, true);
|
||||||
|
return result[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* updates the package with information from the registry
|
||||||
|
*/
|
||||||
|
update() {}
|
||||||
}
|
}
|
||||||
|
@ -1,16 +1,112 @@
|
|||||||
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';
|
||||||
|
|
||||||
// classes
|
// classes
|
||||||
import { NpmPackage } from './smartnpm.classes.npmpackage';
|
import { NpmPackage } from './smartnpm.classes.npmpackage';
|
||||||
|
import { RegistryCache } from './smartnpm.classes.registrycache';
|
||||||
|
|
||||||
|
export interface INpmRegistryConstructorOptions {
|
||||||
|
npmRegistryUrl?: string;
|
||||||
|
}
|
||||||
|
|
||||||
export class NpmRegistry {
|
export class NpmRegistry {
|
||||||
|
public options: INpmRegistryConstructorOptions;
|
||||||
|
public registryCache: RegistryCache;
|
||||||
private searchDomain = 'https://api.npms.io/v2/search?q=';
|
private searchDomain = 'https://api.npms.io/v2/search?q=';
|
||||||
async search(searchObjectArg: ISearchObject) {
|
|
||||||
|
constructor(optionsArg: INpmRegistryConstructorOptions = {}) {
|
||||||
|
const defaultOptions: INpmRegistryConstructorOptions = {
|
||||||
|
npmRegistryUrl: 'https://registry.npmjs.org',
|
||||||
|
};
|
||||||
|
this.options = {
|
||||||
|
...defaultOptions,
|
||||||
|
...optionsArg,
|
||||||
|
};
|
||||||
|
this.registryCache = new RegistryCache(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gets info about a package
|
||||||
|
* @param packageName
|
||||||
|
*/
|
||||||
|
public async getPackageInfo(packageName: string): Promise<NpmPackage> {
|
||||||
|
const fullMetadata = await plugins.packageJson(packageName, {
|
||||||
|
registryUrl: this.options.npmRegistryUrl,
|
||||||
|
fullMetadata: true,
|
||||||
|
}).catch(err => {
|
||||||
|
console.log(err);
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
const versionData = await plugins.packageJson(packageName, {
|
||||||
|
registryUrl: this.options.npmRegistryUrl,
|
||||||
|
allVersions: true
|
||||||
|
});
|
||||||
|
const npmPackage = await NpmPackage.createFromFullMetadataAndVersionData(this, fullMetadata, versionData as any);
|
||||||
|
return npmPackage;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* saves a package to disk
|
||||||
|
* @param packageName
|
||||||
|
* @param targetDir
|
||||||
|
*/
|
||||||
|
public async savePackageToDisk(packageName: string, targetDir: string): Promise<void> {
|
||||||
|
plugins.smartfile.fs.ensureDirSync(paths.nogitDir);
|
||||||
|
const npmPackage = await this.getPackageInfo(packageName);
|
||||||
|
await npmPackage.saveToDisk(targetDir);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gets a file from a package as Smartfile
|
||||||
|
*/
|
||||||
|
public async getFileFromPackage(packageNameArg: string, filePath: string, optionsArg?: {
|
||||||
|
distTag?: string;
|
||||||
|
version?: string;
|
||||||
|
}): Promise<plugins.smartfile.Smartfile> {
|
||||||
|
const fileId = `${this.options.npmRegistryUrl}//+//${packageNameArg}//+//${filePath}//+//${optionsArg?.distTag || optionsArg?.version}`;
|
||||||
|
const cachedFile: plugins.smartfile.Smartfile = await this.registryCache.getCachedFile(fileId);
|
||||||
|
if (!cachedFile) {
|
||||||
|
const npmPackage = await this.getPackageInfo(packageNameArg);
|
||||||
|
const fileResult = await npmPackage.getFileFromPackage(filePath, optionsArg);
|
||||||
|
this.registryCache.cacheSmartFile(fileId, fileResult);
|
||||||
|
return fileResult;
|
||||||
|
} else {
|
||||||
|
return cachedFile;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async getFilesFromPackage(packageNameArg: string, filePath: string, optionsArg: {
|
||||||
|
distTag?: string;
|
||||||
|
version?: string;
|
||||||
|
}): Promise<plugins.smartfile.Smartfile[]> {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
public async getPackageAsSmartfileVirtualDir(packageNameArg: string): Promise<plugins.smartfile.VirtualDirectory> {
|
||||||
|
/**
|
||||||
|
* TODO: rewrite as memory only
|
||||||
|
*/
|
||||||
|
const baseDir = plugins.path.join(paths.nogitDir, packageNameArg.replace('/', '__'));
|
||||||
|
await plugins.smartfile.fs.ensureDir(baseDir);
|
||||||
|
await this.savePackageToDisk(packageNameArg, baseDir);
|
||||||
|
const virtualDir = await plugins.smartfile.VirtualDirectory.fromFsDirPath(baseDir);
|
||||||
|
await plugins.smartfile.fs.remove(baseDir);
|
||||||
|
return virtualDir;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* searches for a package on npm
|
||||||
|
* @param searchObjectArg
|
||||||
|
*/
|
||||||
|
public async searchOnNpm(searchObjectArg: ISearchObject) {
|
||||||
|
if (this.options.npmRegistryUrl !== 'https://registry.npmjs.org') {
|
||||||
|
throw Error(`cannot search registries other than registry.gitlab.com`);
|
||||||
|
}
|
||||||
let searchString = '';
|
let searchString = '';
|
||||||
let addToSearchString = (addStringArg: string) => {
|
const addToSearchString = (addStringArg: string) => {
|
||||||
searchString = `${searchString}+${addStringArg}`;
|
searchString = `${searchString}+${addStringArg}`;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -72,30 +168,29 @@ export class NpmRegistry {
|
|||||||
addToSearchString(`author:${searchObjectArg.maintenanceWeight}`);
|
addToSearchString(`author:${searchObjectArg.maintenanceWeight}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
plugins.smartlog.defaultLogger.log(
|
console.log(
|
||||||
'info',
|
`info: Search on npm for ${plugins.consolecolor.coloredString(searchString, 'pink')}`
|
||||||
`Search on npm for ${plugins.consolecolor.coloredString(searchString, 'pink')}`
|
|
||||||
);
|
);
|
||||||
|
|
||||||
let body: any;
|
let body: any;
|
||||||
try {
|
try {
|
||||||
let response = await plugins.smartrequest.getJson(this.searchDomain + searchString, {});
|
const response = await plugins.smartrequest.getJson(this.searchDomain + searchString, {});
|
||||||
body = response.body;
|
body = response.body;
|
||||||
} catch {
|
} catch {
|
||||||
// we do nothing
|
// we do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
// lets create the packageArray
|
// lets create the packageArray
|
||||||
let packageArray: NpmPackage[] = [];
|
const packageArray: NpmPackage[] = [];
|
||||||
|
|
||||||
// if request failed just return it empty
|
// if request failed just return it empty
|
||||||
if (!body || typeof body === 'string') {
|
if (!body || typeof body === 'string') {
|
||||||
return packageArray;
|
return packageArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let packageArg of body.results) {
|
for (const packageSearchInfoArg of body.results) {
|
||||||
let localPackage = new NpmPackage(packageArg.package);
|
const npmPackage = await this.getPackageInfo(packageSearchInfoArg.package.name);
|
||||||
packageArray.push(localPackage);
|
packageArray.push(npmPackage);
|
||||||
}
|
}
|
||||||
|
|
||||||
return packageArray;
|
return packageArray;
|
||||||
|
11
ts/smartnpm.classes.packagedisttag.ts
Normal file
11
ts/smartnpm.classes.packagedisttag.ts
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
import * as plugins from './smartnpm.plugins';
|
||||||
|
|
||||||
|
export class PackageDisttag {
|
||||||
|
name: string;
|
||||||
|
targetVersion: string;
|
||||||
|
|
||||||
|
constructor(nameArg: string, targetVersionArg: string) {
|
||||||
|
this.name = nameArg;
|
||||||
|
this.targetVersion = targetVersionArg;
|
||||||
|
}
|
||||||
|
}
|
31
ts/smartnpm.classes.packageversion.ts
Normal file
31
ts/smartnpm.classes.packageversion.ts
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
import * as plugins from './smartnpm.plugins';
|
||||||
|
|
||||||
|
export interface IVersionData {
|
||||||
|
name: string;
|
||||||
|
version: string;
|
||||||
|
dependencies: { [key: string]: string };
|
||||||
|
devDependencies: { [key: string]: string };
|
||||||
|
dist: {
|
||||||
|
integrity: string;
|
||||||
|
shasum: string;
|
||||||
|
tarball: string;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export class PackageVersion implements IVersionData {
|
||||||
|
public static createFromVersionData(versionDataArg: IVersionData) {
|
||||||
|
const packageVersion = new PackageVersion();
|
||||||
|
Object.assign(packageVersion, versionDataArg);
|
||||||
|
return packageVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
name: string;
|
||||||
|
version: string;
|
||||||
|
dependencies: { [key: string]: string };
|
||||||
|
devDependencies: { [key: string]: string };
|
||||||
|
dist: {
|
||||||
|
integrity: string;
|
||||||
|
shasum: string;
|
||||||
|
tarball: string;
|
||||||
|
};
|
||||||
|
}
|
32
ts/smartnpm.classes.registrycache.ts
Normal file
32
ts/smartnpm.classes.registrycache.ts
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
import { NpmRegistry } from './smartnpm.classes.npmregistry';
|
||||||
|
import * as plugins from './smartnpm.plugins';
|
||||||
|
|
||||||
|
export class RegistryCache {
|
||||||
|
npmregistryRef: NpmRegistry;
|
||||||
|
public levelCache: plugins.levelcache.LevelCache;
|
||||||
|
|
||||||
|
constructor(npmRegistryRefArg: NpmRegistry) {
|
||||||
|
this.npmregistryRef = npmRegistryRefArg;
|
||||||
|
this.levelCache = new plugins.levelcache.LevelCache({
|
||||||
|
cacheId: encodeURIComponent(this.npmregistryRef.options.npmRegistryUrl),
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public async getCachedFile (fileId: string): Promise<plugins.smartfile.Smartfile> {
|
||||||
|
const cacheEntry = await this.levelCache.retrieveCacheEntryByKey(fileId);
|
||||||
|
if (cacheEntry) {
|
||||||
|
return plugins.smartfile.Smartfile.fromFoldedJson(cacheEntry.contents.toString());
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async cacheSmartFile (fileIdArg: string, smartfileArg: plugins.smartfile.Smartfile) {
|
||||||
|
if (smartfileArg) {
|
||||||
|
await this.levelCache.storeCacheEntryByKey(fileIdArg, new plugins.levelcache.CacheEntry({
|
||||||
|
contents: Buffer.from(smartfileArg.foldToJson()),
|
||||||
|
ttl: 60000
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
4
ts/smartnpm.paths.ts
Normal file
4
ts/smartnpm.paths.ts
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
import * as plugins from './smartnpm.plugins';
|
||||||
|
|
||||||
|
export const packageDir = plugins.path.join(__dirname, '../');
|
||||||
|
export const nogitDir = plugins.path.join(packageDir, '.nogit/');
|
@ -1,6 +1,20 @@
|
|||||||
import * as consolecolor from '@pushrocks/consolecolor';
|
// node native modules
|
||||||
import * as smartlog from '@pushrocks/smartlog';
|
import * as path from 'path';
|
||||||
smartlog.defaultLogger.enableConsole();
|
|
||||||
import * as smartrequest from '@pushrocks/smartrequest';
|
|
||||||
|
|
||||||
export { consolecolor, smartlog, smartrequest };
|
export { path };
|
||||||
|
|
||||||
|
// @pushrocks scope
|
||||||
|
import * as consolecolor from '@pushrocks/consolecolor';
|
||||||
|
import * as levelcache from '@pushrocks/levelcache';
|
||||||
|
import * as smartarchive from '@pushrocks/smartarchive';
|
||||||
|
import * as smartfile from '@pushrocks/smartfile';
|
||||||
|
import * as smartpromise from '@pushrocks/smartpromise';
|
||||||
|
import * as smartrequest from '@pushrocks/smartrequest';
|
||||||
|
import * as smartversion from '@pushrocks/smartversion';
|
||||||
|
|
||||||
|
export { consolecolor, levelcache, smartarchive, smartfile, smartpromise, smartrequest, smartversion };
|
||||||
|
|
||||||
|
// third party scope
|
||||||
|
import packageJson from 'package-json';
|
||||||
|
|
||||||
|
export { packageJson };
|
||||||
|
16
tslint.json
16
tslint.json
@ -1,3 +1,17 @@
|
|||||||
{
|
{
|
||||||
"extends": "tslint-config-standard"
|
"extends": ["tslint:latest", "tslint-config-prettier"],
|
||||||
|
"rules": {
|
||||||
|
"semicolon": [true, "always"],
|
||||||
|
"no-console": false,
|
||||||
|
"ordered-imports": false,
|
||||||
|
"object-literal-sort-keys": false,
|
||||||
|
"member-ordering": {
|
||||||
|
"options":{
|
||||||
|
"order": [
|
||||||
|
"static-method"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"defaultSeverity": "warning"
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user