Compare commits
51 Commits
Author | SHA1 | Date | |
---|---|---|---|
0b1b6deb98 | |||
d5636aaf9a | |||
0276faa949 | |||
c0d64926a0 | |||
7737014464 | |||
349360cdc6 | |||
983a860e2f | |||
c375d9ba10 | |||
e874c935bb | |||
001a79252c | |||
634d1c3570 | |||
cd8c9bcdaa | |||
f6d3d0987b | |||
60a1de38ce | |||
0ef6d0ccb2 | |||
8e538fd84d | |||
6745115db7 | |||
5ebce389d3 | |||
b4100688ac | |||
77d515d915 | |||
aa71105b2d | |||
e0ccb6c076 | |||
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 |
4
.gitignore
vendored
4
.gitignore
vendored
@ -15,8 +15,6 @@ node_modules/
|
||||
|
||||
# builds
|
||||
dist/
|
||||
dist_web/
|
||||
dist_serve/
|
||||
dist_ts_web/
|
||||
dist_*/
|
||||
|
||||
# custom
|
103
.gitlab-ci.yml
103
.gitlab-ci.yml
@ -3,14 +3,14 @@ image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
|
||||
cache:
|
||||
paths:
|
||||
- .npmci_cache/
|
||||
key: "$CI_BUILD_STAGE"
|
||||
- .npmci_cache/
|
||||
key: '$CI_BUILD_STAGE'
|
||||
|
||||
stages:
|
||||
- security
|
||||
- test
|
||||
- release
|
||||
- metadata
|
||||
- security
|
||||
- test
|
||||
- release
|
||||
- metadata
|
||||
|
||||
# ====================
|
||||
# security stage
|
||||
@ -18,21 +18,37 @@ stages:
|
||||
mirror:
|
||||
stage: security
|
||||
script:
|
||||
- npmci git mirror
|
||||
- npmci git mirror
|
||||
only:
|
||||
- tags
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
snyk:
|
||||
auditProductionDependencies:
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
stage: security
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci command npm install -g snyk
|
||||
- npmci command npm install --ignore-scripts
|
||||
- npmci command snyk test
|
||||
- npmci command npm install --production --ignore-scripts
|
||||
- npmci command npm config set registry https://registry.npmjs.org
|
||||
- npmci command npm audit --audit-level=high --only=prod --production
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
- docker
|
||||
allow_failure: true
|
||||
|
||||
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
|
||||
@ -41,37 +57,36 @@ snyk:
|
||||
testStable:
|
||||
stage: test
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci npm test
|
||||
- npmci npm prepare
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci npm test
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
- priv
|
||||
- docker
|
||||
|
||||
testBuild:
|
||||
stage: test
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci node install lts
|
||||
- npmci npm install
|
||||
- npmci command npm run build
|
||||
- npmci npm prepare
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci command npm run build
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
- docker
|
||||
|
||||
release:
|
||||
stage: release
|
||||
script:
|
||||
- npmci node install lts
|
||||
- npmci npm publish
|
||||
- npmci node install stable
|
||||
- npmci npm publish
|
||||
only:
|
||||
- tags
|
||||
- tags
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
# ====================
|
||||
# metadata stage
|
||||
@ -79,35 +94,39 @@ release:
|
||||
codequality:
|
||||
stage: metadata
|
||||
allow_failure: true
|
||||
only:
|
||||
- tags
|
||||
script:
|
||||
- npmci command npm install -g tslint typescript
|
||||
- npmci npm prepare
|
||||
- npmci npm install
|
||||
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
|
||||
tags:
|
||||
- docker
|
||||
- priv
|
||||
- lossless
|
||||
- docker
|
||||
- priv
|
||||
|
||||
trigger:
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci trigger
|
||||
- npmci trigger
|
||||
only:
|
||||
- tags
|
||||
- tags
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
pages:
|
||||
image: hosttoday/ht-docker-dbase:npmci
|
||||
services:
|
||||
- docker:stable-dind
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci node install lts
|
||||
- npmci command npm install -g @gitzone/tsdoc
|
||||
- npmci npm prepare
|
||||
- npmci npm install
|
||||
- npmci command tsdoc
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
only:
|
||||
@ -115,5 +134,5 @@ pages:
|
||||
artifacts:
|
||||
expire_in: 1 week
|
||||
paths:
|
||||
- public
|
||||
- public
|
||||
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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q0FBVSxDQUFDLFVBQVUsQ0FBQyxPQUFPLENBQUMsQ0FBQTtnQkFDckQsWUFBWSxDQUFDLElBQUksQ0FBQyxZQUFZLENBQUMsQ0FBQTthQUNoQztZQUVELE9BQU8sWUFBWSxDQUFBO1FBQ3JCLENBQUM7S0FBQTtDQUNGO0FBMUVELGtDQTBFQyJ9
|
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=
|
@ -4,6 +4,7 @@
|
||||
"npmAccessLevel": "public"
|
||||
},
|
||||
"gitzone": {
|
||||
"projectType": "npm",
|
||||
"module": {
|
||||
"githost": "gitlab.com",
|
||||
"gitscope": "pushrocks",
|
||||
|
21483
package-lock.json
generated
21483
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
49
package.json
49
package.json
@ -1,40 +1,49 @@
|
||||
{
|
||||
"name": "@pushrocks/smartnpm",
|
||||
"version": "1.0.14",
|
||||
"version": "2.0.0",
|
||||
"private": false,
|
||||
"description": "interface with npm to retrieve package information",
|
||||
"main": "dist/index.js",
|
||||
"typings": "dist/index.d.ts",
|
||||
"main": "dist_ts/index.js",
|
||||
"typings": "dist_ts/index.d.ts",
|
||||
"type": "module",
|
||||
"author": "Lossless GmbH",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"test": "(tstest test/)",
|
||||
"build": "(tsbuild)"
|
||||
"build": "(tsbuild --web --allowimplicitany)"
|
||||
},
|
||||
"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.4",
|
||||
"tslint": "^5.19.0",
|
||||
"tslint-config-prettier": "^1.18.0"
|
||||
"@gitzone/tsbuild": "^2.1.61",
|
||||
"@gitzone/tsrun": "^1.2.32",
|
||||
"@gitzone/tstest": "^1.0.70",
|
||||
"@pushrocks/tapbundle": "^5.0.3",
|
||||
"@types/node": "^17.0.23"
|
||||
},
|
||||
"dependencies": {
|
||||
"@pushrocks/consolecolor": "^2.0.1",
|
||||
"@pushrocks/smartlog": "^2.0.19",
|
||||
"@pushrocks/smartrequest": "^1.1.23",
|
||||
"package-json": "^6.5.0"
|
||||
"@pushrocks/levelcache": "^3.0.1",
|
||||
"@pushrocks/smartarchive": "^3.0.2",
|
||||
"@pushrocks/smartfile": "^9.0.6",
|
||||
"@pushrocks/smartpath": "^5.0.5",
|
||||
"@pushrocks/smartpromise": "^3.1.7",
|
||||
"@pushrocks/smartrequest": "^1.1.56",
|
||||
"@pushrocks/smarttime": "^3.0.45",
|
||||
"@pushrocks/smartversion": "^2.0.7",
|
||||
"package-json": "^7.0.0"
|
||||
},
|
||||
"files": [
|
||||
"ts/*",
|
||||
"ts_web/*",
|
||||
"dist/*",
|
||||
"dist_web/*",
|
||||
"dist_ts_web/*",
|
||||
"assets/*",
|
||||
"ts/**/*",
|
||||
"ts_web/**/*",
|
||||
"dist/**/*",
|
||||
"dist_*/**/*",
|
||||
"dist_ts/**/*",
|
||||
"dist_ts_web/**/*",
|
||||
"assets/**/*",
|
||||
"cli.js",
|
||||
"npmextra.json",
|
||||
"readme.md"
|
||||
],
|
||||
"browserslist": [
|
||||
"last 1 chrome versions"
|
||||
]
|
||||
}
|
||||
|
28
readme.md
28
readme.md
@ -8,24 +8,28 @@ interface with npm to retrieve package information
|
||||
* [docs (typedoc)](https://pushrocks.gitlab.io/smartnpm/)
|
||||
|
||||
## Status for master
|
||||
[](https://gitlab.com/pushrocks/smartnpm/commits/master)
|
||||
[](https://gitlab.com/pushrocks/smartnpm/commits/master)
|
||||
[](https://www.npmjs.com/package/@pushrocks/smartnpm)
|
||||
[](https://snyk.io/test/npm/@pushrocks/smartnpm)
|
||||
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||
[](https://prettier.io/)
|
||||
|
||||
Status Category | Status Badge
|
||||
-- | --
|
||||
GitLab Pipelines | [](https://lossless.cloud)
|
||||
GitLab Pipline Test Coverage | [](https://lossless.cloud)
|
||||
npm | [](https://lossless.cloud)
|
||||
Snyk | [](https://lossless.cloud)
|
||||
TypeScript Support | [](https://lossless.cloud)
|
||||
node Support | [](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||
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
|
||||
|
||||
Use TypeScript for best in class instellisense.
|
||||
|
||||
For further information read the linked docs at the top of this README.
|
||||
## Contribution
|
||||
|
||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||
> | By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
|
||||
|
||||
[](https://push.rocks)
|
||||
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.
|
||||
|
||||
|
50
test/test.ts
50
test/test.ts
@ -1,6 +1,6 @@
|
||||
import { expect, tap } from '@pushrocks/tapbundle';
|
||||
import * as smartnpm from '../ts/index';
|
||||
import { NpmRegistry } from '../ts/index';
|
||||
import * as smartnpm from '../ts/index.js';
|
||||
import { NpmRegistry } from '../ts/index.js';
|
||||
|
||||
let npmRegistry: smartnpm.NpmRegistry;
|
||||
let verdaccioRegistry: smartnpm.NpmRegistry;
|
||||
@ -9,30 +9,56 @@ let testPackage: smartnpm.NpmPackage;
|
||||
// lets test things with the standard npm registry
|
||||
tap.test('should create valid instances', async () => {
|
||||
npmRegistry = new smartnpm.NpmRegistry();
|
||||
expect(npmRegistry).to.be.instanceof(smartnpm.NpmRegistry);
|
||||
expect(npmRegistry).toBeInstanceOf(smartnpm.NpmRegistry);
|
||||
|
||||
testPackage = new smartnpm.NpmPackage();
|
||||
expect(testPackage).to.be.instanceof(smartnpm.NpmPackage);
|
||||
testPackage = new smartnpm.NpmPackage(npmRegistry);
|
||||
expect(testPackage).toBeInstanceOf(smartnpm.NpmPackage);
|
||||
});
|
||||
|
||||
tap.test('should produce a valid search string and this return npmts', async () => {
|
||||
const packages = await npmRegistry.search({
|
||||
name: '@pushrocks/smartupdate'
|
||||
const packages = await npmRegistry.searchOnNpm({
|
||||
name: '@pushrocks/smartupdate',
|
||||
});
|
||||
expect(packages[0].name).to.equal('@pushrocks/smartupdate');
|
||||
expect(packages[0].name).toEqual('@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'
|
||||
npmRegistryUrl: 'https://verdaccio.lossless.one',
|
||||
});
|
||||
expect(verdaccioRegistry).to.be.instanceOf(smartnpm.NpmRegistry);
|
||||
expect(verdaccioRegistry).toBeInstanceOf(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');
|
||||
expect(npmPackage.license).to.equal('MIT');
|
||||
expect(npmPackage.license).toEqual('MIT');
|
||||
});
|
||||
|
||||
tap.test('should get a specific file from a package', async () => {
|
||||
const wantedFile = await verdaccioRegistry.getFileFromPackage(
|
||||
'@pushrocks/websetup',
|
||||
'./ts/index.ts'
|
||||
);
|
||||
console.log(wantedFile.contentBuffer.toString());
|
||||
});
|
||||
|
||||
tap.test('should get a specific file from a package', async () => {
|
||||
const wantedFiles = await verdaccioRegistry.getFilesFromPackage(
|
||||
'@pushrocks/websetup',
|
||||
'ts/'
|
||||
);
|
||||
for(const file of wantedFiles) {
|
||||
console.log(file.path);
|
||||
}
|
||||
});
|
||||
|
||||
tap.test('should not get a nonexisting file from a package', async () => {
|
||||
const wantedFileNotThere = await verdaccioRegistry.getFileFromPackage(
|
||||
'@pushrocks/websetup',
|
||||
'ts/notthere'
|
||||
);
|
||||
expect(wantedFileNotThere).toBeNull();
|
||||
});
|
||||
|
||||
tap.start();
|
||||
|
@ -1,4 +1,4 @@
|
||||
import * as plugins from './smartnpm.plugins';
|
||||
import * as plugins from './smartnpm.plugins.js';
|
||||
|
||||
export * from './smartnpm.classes.npmregistry';
|
||||
export * from './smartnpm.classes.npmpackage';
|
||||
export * from './smartnpm.classes.npmregistry.js';
|
||||
export * from './smartnpm.classes.npmpackage.js';
|
||||
|
@ -1,10 +1,35 @@
|
||||
import * as plugins from './smartnpm.plugins';
|
||||
import { NpmRegistry } from './smartnpm.classes.npmregistry';
|
||||
import * as plugins from './smartnpm.plugins.js';
|
||||
import { NpmRegistry } from './smartnpm.classes.npmregistry.js';
|
||||
import { PackageDisttag } from './smartnpm.classes.packagedisttag.js';
|
||||
import { PackageVersion, IVersionData } from './smartnpm.classes.packageversion.js';
|
||||
|
||||
export class NpmPackage {
|
||||
public static async createFromFullMetadata(npmRegistry: NpmRegistry, fullMetadata: plugins.packageJson.FullMetadata) {
|
||||
const npmPackage = new NpmPackage();
|
||||
Object.assign(npmPackage, fullMetadata);
|
||||
public static async createFromFullMetadataAndVersionData(
|
||||
npmRegistryArg: NpmRegistry,
|
||||
fullMetadataArg: plugins.packageJson.FullMetadata,
|
||||
versionsDataArg: {
|
||||
name: string;
|
||||
'dist-tags': { [key: string]: string };
|
||||
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;
|
||||
}
|
||||
|
||||
@ -12,6 +37,8 @@ export class NpmPackage {
|
||||
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;
|
||||
@ -30,6 +57,11 @@ export class NpmPackage {
|
||||
email: 'npm@git.zone';
|
||||
};
|
||||
public maintainers: any = null;
|
||||
public dist: {
|
||||
integrity: string;
|
||||
shasum: string;
|
||||
tarball: string;
|
||||
};
|
||||
public score: {
|
||||
final: number;
|
||||
detail: {
|
||||
@ -39,4 +71,117 @@ export class NpmPackage {
|
||||
};
|
||||
} = null;
|
||||
public searchScore: number = null;
|
||||
|
||||
public npmRegistryRef: NpmRegistry;
|
||||
constructor(npmRegistryArg: NpmRegistry) {
|
||||
this.npmRegistryRef = npmRegistryArg;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 targetVersionString: string;
|
||||
if (optionsArg.distTag) {
|
||||
const targetDistTag = this.allDistTags.find((distTag) => {
|
||||
return distTag.name === optionsArg.distTag;
|
||||
});
|
||||
if (targetDistTag) {
|
||||
targetVersionString = targetDistTag.targetVersion;
|
||||
}
|
||||
} else {
|
||||
targetVersionString = optionsArg.version;
|
||||
}
|
||||
|
||||
// lets find the best matching release
|
||||
const bestMatchingVersion = this.getBestMatchingVersion(targetVersionString);
|
||||
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(!returnOnFirstArg && 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] || null;
|
||||
}
|
||||
|
||||
/**
|
||||
* updates the package with information from the registry
|
||||
*/
|
||||
update() {}
|
||||
|
||||
/** */
|
||||
public getBestMatchingVersion(versionArg: string): string {
|
||||
// lets find the best matching release
|
||||
const targetVersion = plugins.smartversion.SmartVersion.fromFuzzyString(versionArg);
|
||||
const versionStrings = this.allVersions.map((packageVersion) => packageVersion.version);
|
||||
const bestMatchingVersion = targetVersion.getBestMatch(versionStrings);
|
||||
if (!bestMatchingVersion) {
|
||||
return null;
|
||||
}
|
||||
return bestMatchingVersion;
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,12 @@
|
||||
import * as plugins from './smartnpm.plugins';
|
||||
import * as plugins from './smartnpm.plugins.js';
|
||||
import * as paths from './smartnpm.paths.js';
|
||||
|
||||
// interfaces
|
||||
import { ISearchObject } from './smartnpm.interfaces';
|
||||
import { ISearchObject } from './smartnpm.interfaces.js';
|
||||
|
||||
// classes
|
||||
import { NpmPackage } from './smartnpm.classes.npmpackage';
|
||||
import { NpmPackage } from './smartnpm.classes.npmpackage.js';
|
||||
import { ICacheDescriptor, RegistryCache } from './smartnpm.classes.registrycache.js';
|
||||
|
||||
export interface INpmRegistryConstructorOptions {
|
||||
npmRegistryUrl?: string;
|
||||
@ -12,29 +14,124 @@ export interface INpmRegistryConstructorOptions {
|
||||
|
||||
export class NpmRegistry {
|
||||
public options: INpmRegistryConstructorOptions;
|
||||
public registry: string;
|
||||
public registryCache: RegistryCache;
|
||||
private searchDomain = 'https://api.npms.io/v2/search?q=';
|
||||
|
||||
constructor(optionsArg: INpmRegistryConstructorOptions = {}) {
|
||||
const defaultOptions: INpmRegistryConstructorOptions = {
|
||||
npmRegistryUrl: 'https://registry.npmjs.org'
|
||||
npmRegistryUrl: 'https://registry.npmjs.org',
|
||||
};
|
||||
this.options = {
|
||||
...defaultOptions,
|
||||
...optionsArg
|
||||
...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
|
||||
fullMetadata: true,
|
||||
}).catch(err => {
|
||||
console.log(err);
|
||||
return null;
|
||||
});
|
||||
const npmPackage = await NpmPackage.createFromFullMetadata(this, fullMetadata);
|
||||
const versionData = await plugins.packageJson(packageName, {
|
||||
registryUrl: this.options.npmRegistryUrl,
|
||||
allVersions: true
|
||||
});
|
||||
const npmPackage = await NpmPackage.createFromFullMetadataAndVersionData(this, fullMetadata, versionData as any);
|
||||
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> {
|
||||
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, filePathArg: string, optionsArg?: {
|
||||
distTag?: string;
|
||||
version?: string;
|
||||
}): Promise<plugins.smartfile.Smartfile> {
|
||||
// lets create a cache descriptor
|
||||
const cacheDescriptor: ICacheDescriptor = {
|
||||
registryUrl: this.options.npmRegistryUrl,
|
||||
packageName: packageNameArg,
|
||||
filePath: filePathArg,
|
||||
distTag: optionsArg?.distTag,
|
||||
version: optionsArg?.version
|
||||
};
|
||||
|
||||
// lets see if we have something cached
|
||||
const cachedFile: plugins.smartfile.Smartfile = await this.registryCache.getCachedFile(cacheDescriptor);
|
||||
|
||||
// lets handle both occasions
|
||||
if (!cachedFile) {
|
||||
const npmPackage = await this.getPackageInfo(packageNameArg);
|
||||
if (!optionsArg?.version && !optionsArg?.distTag) {
|
||||
const latestAvailable = npmPackage.allDistTags.find(packageArg => packageArg.name === 'latest');
|
||||
if (!latestAvailable) {
|
||||
optionsArg = {
|
||||
version: npmPackage.getBestMatchingVersion('*')
|
||||
};
|
||||
}
|
||||
}
|
||||
const fileResult = await npmPackage.getFileFromPackage(filePathArg, optionsArg);
|
||||
if (fileResult) {
|
||||
this.registryCache.cacheSmartFile(cacheDescriptor, fileResult);
|
||||
}
|
||||
return fileResult;
|
||||
} else {
|
||||
return cachedFile;
|
||||
}
|
||||
}
|
||||
|
||||
public async getFilesFromPackage(packageNameArg: string, filePath: string, optionsArg?: {
|
||||
distTag?: string;
|
||||
version?: string;
|
||||
}): Promise<plugins.smartfile.Smartfile[]> {
|
||||
const npmPackage = await this.getPackageInfo(packageNameArg);
|
||||
if (!optionsArg?.version && !optionsArg?.distTag) {
|
||||
const latestAvailable = npmPackage.allDistTags.find(packageDistTagArg => packageDistTagArg.name === 'latest');
|
||||
if (!latestAvailable) {
|
||||
optionsArg = {
|
||||
version: npmPackage.getBestMatchingVersion('*')
|
||||
};
|
||||
}
|
||||
}
|
||||
return npmPackage.getFilesFromPackage(filePath, optionsArg);
|
||||
}
|
||||
|
||||
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`);
|
||||
}
|
||||
@ -101,9 +198,8 @@ export class NpmRegistry {
|
||||
addToSearchString(`author:${searchObjectArg.maintenanceWeight}`);
|
||||
}
|
||||
|
||||
plugins.smartlog.defaultLogger.log(
|
||||
'info',
|
||||
`Search on npm for ${plugins.consolecolor.coloredString(searchString, 'pink')}`
|
||||
console.log(
|
||||
`info: Search on npm for ${plugins.consolecolor.coloredString(searchString, 'pink')}`
|
||||
);
|
||||
|
||||
let body: any;
|
||||
|
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.js';
|
||||
|
||||
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.js';
|
||||
|
||||
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;
|
||||
};
|
||||
}
|
50
ts/smartnpm.classes.registrycache.ts
Normal file
50
ts/smartnpm.classes.registrycache.ts
Normal file
@ -0,0 +1,50 @@
|
||||
import { NpmRegistry } from './smartnpm.classes.npmregistry.js';
|
||||
import * as plugins from './smartnpm.plugins.js';
|
||||
|
||||
|
||||
export interface ICacheDescriptor {
|
||||
registryUrl: string;
|
||||
packageName: string;
|
||||
filePath: string;
|
||||
distTag?: string;
|
||||
version?: string;
|
||||
}
|
||||
|
||||
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 (cacheDescriptorArg: ICacheDescriptor): Promise<plugins.smartfile.Smartfile> {
|
||||
const cacheEntry = await this.levelCache.retrieveCacheEntryByKey(this.getCacheDescriptorAsString(cacheDescriptorArg));
|
||||
if (cacheEntry) {
|
||||
return plugins.smartfile.Smartfile.fromFoldedJson(cacheEntry.contents.toString());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public async cacheSmartFile (cacheDescriptorArg: ICacheDescriptor, smartfileArg: plugins.smartfile.Smartfile) {
|
||||
if (smartfileArg && cacheDescriptorArg.version) {
|
||||
await this.levelCache.storeCacheEntryByKey(this.getCacheDescriptorAsString(cacheDescriptorArg), new plugins.levelcache.CacheEntry({
|
||||
contents: Buffer.from(smartfileArg.foldToJson()),
|
||||
ttl: plugins.smarttime.getMilliSecondsFromUnits({hours: 1})
|
||||
}));
|
||||
} else {
|
||||
await this.levelCache.storeCacheEntryByKey(this.getCacheDescriptorAsString(cacheDescriptorArg), new plugins.levelcache.CacheEntry({
|
||||
contents: Buffer.from(smartfileArg.foldToJson()),
|
||||
ttl: plugins.smarttime.getMilliSecondsFromUnits({minutes: 1})
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
public getCacheDescriptorAsString(cacheDescriptorArg?: ICacheDescriptor) {
|
||||
return `${cacheDescriptorArg.registryUrl}//+//${cacheDescriptorArg.packageName}//+//${cacheDescriptorArg.filePath}//+//${cacheDescriptorArg.distTag || cacheDescriptorArg.version}`;
|
||||
}
|
||||
}
|
4
ts/smartnpm.paths.ts
Normal file
4
ts/smartnpm.paths.ts
Normal file
@ -0,0 +1,4 @@
|
||||
import * as plugins from './smartnpm.plugins.js';
|
||||
|
||||
export const packageDir = plugins.path.join(plugins.smartpath.get.dirnameFromImportMetaUrl(import.meta.url), '../');
|
||||
export const nogitDir = plugins.path.join(packageDir, '.nogit/');
|
@ -1,10 +1,20 @@
|
||||
// node native modules
|
||||
import * as path from 'path';
|
||||
|
||||
export { path };
|
||||
|
||||
// @pushrocks scope
|
||||
import * as consolecolor from '@pushrocks/consolecolor';
|
||||
import * as smartlog from '@pushrocks/smartlog';
|
||||
smartlog.defaultLogger.enableConsole();
|
||||
import * as levelcache from '@pushrocks/levelcache';
|
||||
import * as smartarchive from '@pushrocks/smartarchive';
|
||||
import * as smartfile from '@pushrocks/smartfile';
|
||||
import * as smartpath from '@pushrocks/smartpath';
|
||||
import * as smartpromise from '@pushrocks/smartpromise';
|
||||
import * as smartrequest from '@pushrocks/smartrequest';
|
||||
import * as smartversion from '@pushrocks/smartversion';
|
||||
import * as smarttime from '@pushrocks/smarttime';
|
||||
|
||||
export { consolecolor, smartlog, smartrequest };
|
||||
export { consolecolor, levelcache, smartarchive, smartfile, smartpath, smartpromise, smartrequest, smartversion, smarttime };
|
||||
|
||||
// third party scope
|
||||
import packageJson from 'package-json';
|
||||
|
9
tsconfig.json
Normal file
9
tsconfig.json
Normal file
@ -0,0 +1,9 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"experimentalDecorators": true,
|
||||
"useDefineForClassFields": false,
|
||||
"target": "ES2022",
|
||||
"module": "ES2022",
|
||||
"moduleResolution": "nodenext"
|
||||
}
|
||||
}
|
17
tslint.json
17
tslint.json
@ -1,17 +0,0 @@
|
||||
{
|
||||
"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