update to working search
This commit is contained in:
parent
d9573937d0
commit
8edb49d9fb
3
dist/index.d.ts
vendored
3
dist/index.d.ts
vendored
@ -1 +1,2 @@
|
||||
export declare let standardExport: string;
|
||||
export * from './smartnpm.classes.npmregistry';
|
||||
export * from './smartnpm.classes.npmpackage';
|
||||
|
8
dist/index.js
vendored
8
dist/index.js
vendored
@ -1,4 +1,8 @@
|
||||
"use strict";
|
||||
function __export(m) {
|
||||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
|
||||
}
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.standardExport = 'Hi there! :) This is a exported string';
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUVXLFFBQUEsY0FBYyxHQUFHLHdDQUF3QyxDQUFBIn0=
|
||||
__export(require("./smartnpm.classes.npmregistry"));
|
||||
__export(require("./smartnpm.classes.npmpackage"));
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7OztBQUVBLG9EQUE4QztBQUM5QyxtREFBNkMifQ==
|
32
dist/smartnpm.classes.npmpackage.d.ts
vendored
Normal file
32
dist/smartnpm.classes.npmpackage.d.ts
vendored
Normal file
@ -0,0 +1,32 @@
|
||||
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
Normal file
24
dist/smartnpm.classes.npmpackage.js
vendored
Normal file
@ -0,0 +1,24 @@
|
||||
"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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRucG0uY2xhc3Nlcy5ucG1wYWNrYWdlLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRucG0uY2xhc3Nlcy5ucG1wYWNrYWdlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBRUE7SUE4QkUsWUFBYSxjQUFjO1FBN0IzQixTQUFJLEdBQVcsSUFBSSxDQUFBO1FBQ25CLFVBQUssR0FBVyxJQUFJLENBQUE7UUFDcEIsWUFBTyxHQUFXLElBQUksQ0FBQTtRQUN0QixnQkFBVyxHQUFXLElBQUksQ0FBQTtRQUMxQixhQUFRLEdBQWEsSUFBSSxDQUFBO1FBRXpCLFVBQUssR0FLRCxJQUFJLENBQUE7UUFDUixXQUFNLEdBRUYsSUFBSSxDQUFBO1FBQ1IsY0FBUyxHQUVMLElBQUksQ0FBQTtRQUNSLGdCQUFXLEdBQVEsSUFBSSxDQUFBO1FBQ3ZCLFVBQUssR0FPRCxJQUFJLENBQUE7UUFDUixnQkFBVyxHQUFXLElBQUksQ0FBQTtRQUd4QixHQUFHLENBQUMsQ0FBQyxJQUFJLEdBQUcsSUFBSSxjQUFjLENBQUMsQ0FBQyxDQUFDO1lBQy9CLEVBQUUsQ0FBQyxDQUFDLElBQUksQ0FBQyxHQUFHLENBQUMsS0FBSyxJQUFJLENBQUMsQ0FBQyxDQUFDO2dCQUN2QixJQUFJLENBQUMsR0FBRyxDQUFDLEdBQUcsY0FBYyxDQUFDLEdBQUcsQ0FBQyxDQUFBO1lBQ2pDLENBQUM7UUFDSCxDQUFDO0lBQ0gsQ0FBQztDQUNGO0FBckNELGdDQXFDQyJ9
|
6
dist/smartnpm.classes.npmregistry.d.ts
vendored
Normal file
6
dist/smartnpm.classes.npmregistry.d.ts
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
import { ISearchObject } from './smartnpm.interfaces';
|
||||
import { NpmPackage } from './smartnpm.classes.npmpackage';
|
||||
export declare class NpmRegistry {
|
||||
private searchDomain;
|
||||
search(searchObjectArg: ISearchObject): Promise<NpmPackage[]>;
|
||||
}
|
94
dist/smartnpm.classes.npmregistry.js
vendored
Normal file
94
dist/smartnpm.classes.npmregistry.js
vendored
Normal file
@ -0,0 +1,94 @@
|
||||
"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.beautylog.log(`Search for "${searchString}" on npm`);
|
||||
let response = (yield plugins.smartrequest.get(this.searchDomain + searchString, {}));
|
||||
let body = response.body;
|
||||
// lets create the response
|
||||
let 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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRucG0uY2xhc3Nlcy5ucG1yZWdpc3RyeS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0bnBtLmNsYXNzZXMubnBtcmVnaXN0cnkudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7OztBQUFBLDhDQUE2QztBQUs3QyxVQUFVO0FBQ1YsK0VBQTBEO0FBRTFEO0lBQUE7UUFDVSxpQkFBWSxHQUFHLGtDQUFrQyxDQUFBO0lBOEQzRCxDQUFDO0lBN0RPLE1BQU0sQ0FBRSxlQUE4Qjs7WUFDMUMsSUFBSSxZQUFZLEdBQUcsRUFBRSxDQUFBO1lBQ3JCLElBQUksaUJBQWlCLEdBQUcsQ0FBQyxZQUFvQjtnQkFDM0MsWUFBWSxHQUFHLEdBQUcsWUFBWSxJQUFJLFlBQVksRU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d.ts
vendored
Normal file
15
dist/smartnpm.interfaces.d.ts
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
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
Normal file
3
dist/smartnpm.interfaces.js
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRucG0uaW50ZXJmYWNlcy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0bnBtLmludGVyZmFjZXMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IiJ9
|
3
dist/smartnpm.plugins.d.ts
vendored
3
dist/smartnpm.plugins.d.ts
vendored
@ -1 +1,4 @@
|
||||
import 'typings-global';
|
||||
import * as beautylog from 'beautylog';
|
||||
import * as smartrequest from 'smartrequest';
|
||||
export { beautylog, smartrequest };
|
||||
|
6
dist/smartnpm.plugins.js
vendored
6
dist/smartnpm.plugins.js
vendored
@ -1,4 +1,8 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
require("typings-global");
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRucG0ucGx1Z2lucy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0bnBtLnBsdWdpbnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFBQSwwQkFBdUIifQ==
|
||||
const beautylog = require("beautylog");
|
||||
exports.beautylog = beautylog;
|
||||
const smartrequest = require("smartrequest");
|
||||
exports.smartrequest = smartrequest;
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRucG0ucGx1Z2lucy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0bnBtLnBsdWdpbnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFBQSwwQkFBdUI7QUFFdkIsdUNBQXNDO0FBSXBDLDhCQUFTO0FBSFgsNkNBQTRDO0FBSTFDLG9DQUFZIn0=
|
@ -13,6 +13,7 @@
|
||||
"tapbundle": "^1.0.13"
|
||||
},
|
||||
"dependencies": {
|
||||
"beautylog": "^6.1.10",
|
||||
"smartrequest": "^1.0.6",
|
||||
"typings-global": "^1.0.16"
|
||||
}
|
||||
|
18
test/test.ts
18
test/test.ts
@ -1,8 +1,22 @@
|
||||
import { expect, tap } from 'tapbundle'
|
||||
import * as smartnpm from '../ts/index'
|
||||
|
||||
tap.test('first test', async () => {
|
||||
console.log(smartnpm.standardExport)
|
||||
let testRegistry: smartnpm.NpmRegistry
|
||||
let testPackage: smartnpm.NpmPackage
|
||||
|
||||
tap.test('should create valid instances', async () => {
|
||||
testRegistry = new smartnpm.NpmRegistry()
|
||||
expect(testRegistry).to.be.instanceof(smartnpm.NpmRegistry)
|
||||
|
||||
testPackage = new smartnpm.NpmPackage({})
|
||||
expect(testPackage).to.be.instanceof(smartnpm.NpmPackage)
|
||||
})
|
||||
|
||||
tap.test('should produce a valid search string', async () => {
|
||||
let packages = await testRegistry.search({
|
||||
name: 'npmts'
|
||||
})
|
||||
expect(packages[0].name).to.equal('npmts')
|
||||
})
|
||||
|
||||
tap.start()
|
||||
|
@ -2,5 +2,3 @@ import * as plugins from './smartnpm.plugins'
|
||||
|
||||
export * from './smartnpm.classes.npmregistry'
|
||||
export * from './smartnpm.classes.npmpackage'
|
||||
|
||||
export let standardExport = 'Hi there! :) This is a exported string'
|
||||
|
@ -1,7 +1,40 @@
|
||||
import * as plugins from './smartnpm.plugins'
|
||||
|
||||
export class NpmPackage {
|
||||
search (searchObject: ISearchObject) {
|
||||
let response = await plugins.Smartrequest
|
||||
name: string = null
|
||||
scope: string = null
|
||||
version: string = null
|
||||
description: string = null
|
||||
keywords: string[] = null
|
||||
date: '2017-08-02T11:22:49.144Z'
|
||||
links: {
|
||||
npm: string
|
||||
homepage: string
|
||||
repository: string
|
||||
bugs: string
|
||||
} = null
|
||||
author: {
|
||||
name: 'Lossless GmbH'
|
||||
} = null
|
||||
publisher: {
|
||||
username: 'gitzone', email: 'npm@git.zone'
|
||||
} = null
|
||||
maintainers: any = null
|
||||
score: {
|
||||
final: number,
|
||||
detail: {
|
||||
quality: number,
|
||||
popularity: number,
|
||||
maintenance: number
|
||||
}
|
||||
} = null
|
||||
searchScore: number = null
|
||||
|
||||
constructor (descriptionArg) {
|
||||
for (let key in descriptionArg) {
|
||||
if (this[key] === null) {
|
||||
this[key] = descriptionArg[key]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,40 +1,27 @@
|
||||
import * as plugins from './smartnpm.plugins'
|
||||
|
||||
interface ISearchObject {
|
||||
// metadata
|
||||
author?: string
|
||||
maintainer: string
|
||||
scope?: string
|
||||
keywords: string[]
|
||||
|
||||
// status
|
||||
deprecated?: boolean
|
||||
unstable?: boolean
|
||||
insecure?: boolean
|
||||
|
||||
// search behaviour
|
||||
boostExact: boolean
|
||||
scoreEffect: number
|
||||
// interfaces
|
||||
import { ISearchObject } from './smartnpm.interfaces'
|
||||
|
||||
// Analytics
|
||||
qualityWeight: number
|
||||
popularityWeight: number
|
||||
maintenanceWeight: number
|
||||
}
|
||||
// classes
|
||||
import { NpmPackage } from './smartnpm.classes.npmpackage'
|
||||
|
||||
export class NpmRegistry {
|
||||
private searchDomain = 'https://api.npms.io/v2/search?q='
|
||||
search (searchObjectArg: ISearchObject) {
|
||||
async search (searchObjectArg: ISearchObject) {
|
||||
let searchString = ''
|
||||
let addToSearchString = (addStringArg: string) => {
|
||||
searchString = `${searchString} ${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) {
|
||||
@ -57,16 +44,29 @@ export class NpmRegistry {
|
||||
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}`) }
|
||||
|
||||
let response = (await plugins.smartrequest.get(this.searchDomain, {}))
|
||||
plugins.beautylog.log(`Search for "${searchString}" on npm`)
|
||||
|
||||
let response = (await plugins.smartrequest.get(this.searchDomain + searchString, {}))
|
||||
let body: any = response.body
|
||||
|
||||
// lets create the response
|
||||
let packageArray: NpmPackage[] = []
|
||||
|
||||
for (let packageArg of body.results) {
|
||||
let localPackage = new NpmPackage(packageArg.package)
|
||||
packageArray.push(localPackage)
|
||||
}
|
||||
|
||||
return packageArray
|
||||
}
|
||||
}
|
||||
|
25
ts/smartnpm.interfaces.ts
Normal file
25
ts/smartnpm.interfaces.ts
Normal file
@ -0,0 +1,25 @@
|
||||
|
||||
export interface ISearchObject {
|
||||
// name
|
||||
name?: string
|
||||
|
||||
// metadata
|
||||
author?: string
|
||||
maintainer?: string
|
||||
scope?: string
|
||||
keywords?: string[]
|
||||
|
||||
// status
|
||||
deprecated?: boolean
|
||||
unstable?: boolean
|
||||
insecure?: boolean
|
||||
|
||||
// search behaviour
|
||||
boostExact?: boolean
|
||||
scoreEffect?: number
|
||||
|
||||
// Analytics
|
||||
qualityWeight?: number
|
||||
popularityWeight?: number
|
||||
maintenanceWeight?: number
|
||||
}
|
@ -1,7 +1,9 @@
|
||||
import 'typings-global'
|
||||
|
||||
import * as beautylog from 'beautylog'
|
||||
import * as smartrequest from 'smartrequest'
|
||||
|
||||
export {
|
||||
beautylog,
|
||||
smartrequest
|
||||
}
|
||||
|
117
yarn.lock
117
yarn.lock
@ -30,6 +30,10 @@
|
||||
"@types/minimatch" "*"
|
||||
"@types/node" "*"
|
||||
|
||||
"@types/lodash@^4.14.55":
|
||||
version "4.14.72"
|
||||
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.72.tgz#f090cf6eb1fee1647a0efa1ebe18b0b78ed551c6"
|
||||
|
||||
"@types/minimatch@*":
|
||||
version "2.0.29"
|
||||
resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-2.0.29.tgz#5002e14f75e2d71e564281df0431c8c1b4a2a36a"
|
||||
@ -57,6 +61,14 @@ ansi-256-colors@^1.1.0:
|
||||
version "1.1.0"
|
||||
resolved "https://registry.yarnpkg.com/ansi-256-colors/-/ansi-256-colors-1.1.0.tgz#910de50efcc7c09e3d82f2f87abd6b700c18818a"
|
||||
|
||||
ansi-regex@^2.0.0:
|
||||
version "2.1.1"
|
||||
resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-2.1.1.tgz#c3b33ab5ee360d86e0e628f0468ae7ef27d654df"
|
||||
|
||||
ansi-styles@^2.2.1:
|
||||
version "2.2.1"
|
||||
resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-2.2.1.tgz#b432dd3358b634cf75e1e4664368240533c1ddbe"
|
||||
|
||||
assertion-error@^1.0.1:
|
||||
version "1.0.2"
|
||||
resolved "https://registry.yarnpkg.com/assertion-error/-/assertion-error-1.0.2.tgz#13ca515d86206da0bac66e834dd397d87581094c"
|
||||
@ -72,6 +84,19 @@ beautycolor@^1.0.7:
|
||||
ansi-256-colors "^1.1.0"
|
||||
typings-global "^1.0.14"
|
||||
|
||||
beautylog@^6.1.10:
|
||||
version "6.1.10"
|
||||
resolved "https://registry.yarnpkg.com/beautylog/-/beautylog-6.1.10.tgz#9c27e566937684cb689f9372d98cfa5415d50b72"
|
||||
dependencies:
|
||||
"@types/lodash" "^4.14.55"
|
||||
beautycolor "^1.0.7"
|
||||
figlet "^1.2.0"
|
||||
lodash "^4.17.4"
|
||||
ora "^1.1.0"
|
||||
smartenv "^2.0.0"
|
||||
smartq "^1.1.1"
|
||||
typings-global "^1.0.14"
|
||||
|
||||
bindings@^1.2.1:
|
||||
version "1.3.0"
|
||||
resolved "https://registry.yarnpkg.com/bindings/-/bindings-1.3.0.tgz#b346f6ecf6a95f5a815c5839fc7cdb22502f1ed7"
|
||||
@ -101,10 +126,30 @@ chai@^3.5.0:
|
||||
deep-eql "^0.1.3"
|
||||
type-detect "^1.0.0"
|
||||
|
||||
chalk@^1.0.0, chalk@^1.1.1:
|
||||
version "1.1.3"
|
||||
resolved "https://registry.yarnpkg.com/chalk/-/chalk-1.1.3.tgz#a8115c55e4a702fe4d150abd3872822a7e09fc98"
|
||||
dependencies:
|
||||
ansi-styles "^2.2.1"
|
||||
escape-string-regexp "^1.0.2"
|
||||
has-ansi "^2.0.0"
|
||||
strip-ansi "^3.0.0"
|
||||
supports-color "^2.0.0"
|
||||
|
||||
check-error@^1.0.2:
|
||||
version "1.0.2"
|
||||
resolved "https://registry.yarnpkg.com/check-error/-/check-error-1.0.2.tgz#574d312edd88bb5dd8912e9286dd6c0aed4aac82"
|
||||
|
||||
cli-cursor@^2.1.0:
|
||||
version "2.1.0"
|
||||
resolved "https://registry.yarnpkg.com/cli-cursor/-/cli-cursor-2.1.0.tgz#b35dac376479facc3e94747d41d0d0f5238ffcb5"
|
||||
dependencies:
|
||||
restore-cursor "^2.0.0"
|
||||
|
||||
cli-spinners@^1.0.0:
|
||||
version "1.0.0"
|
||||
resolved "https://registry.yarnpkg.com/cli-spinners/-/cli-spinners-1.0.0.tgz#ef987ed3d48391ac3dab9180b406a742180d6e6a"
|
||||
|
||||
concat-map@0.0.1:
|
||||
version "0.0.1"
|
||||
resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b"
|
||||
@ -152,6 +197,14 @@ es6-error@^4.0.2:
|
||||
version "4.0.2"
|
||||
resolved "https://registry.yarnpkg.com/es6-error/-/es6-error-4.0.2.tgz#eec5c726eacef51b7f6b73c20db6e1b13b069c98"
|
||||
|
||||
escape-string-regexp@^1.0.2:
|
||||
version "1.0.5"
|
||||
resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4"
|
||||
|
||||
figlet@^1.2.0:
|
||||
version "1.2.0"
|
||||
resolved "https://registry.yarnpkg.com/figlet/-/figlet-1.2.0.tgz#6c46537378fab649146b5a6143dda019b430b410"
|
||||
|
||||
foreach@^2.0.5:
|
||||
version "2.0.5"
|
||||
resolved "https://registry.yarnpkg.com/foreach/-/foreach-2.0.5.tgz#0bee005018aeb260d0a3af3ae658dd0136ec1b99"
|
||||
@ -175,6 +228,12 @@ glob@^7.0.0:
|
||||
once "^1.3.0"
|
||||
path-is-absolute "^1.0.0"
|
||||
|
||||
has-ansi@^2.0.0:
|
||||
version "2.0.0"
|
||||
resolved "https://registry.yarnpkg.com/has-ansi/-/has-ansi-2.0.0.tgz#34f5049ce1ecdf2b0649af3ef24e45ed35416d91"
|
||||
dependencies:
|
||||
ansi-regex "^2.0.0"
|
||||
|
||||
has@^1.0.1:
|
||||
version "1.0.1"
|
||||
resolved "https://registry.yarnpkg.com/has/-/has-1.0.1.tgz#8461733f538b0837c9361e39a9ab9e9704dc2f28"
|
||||
@ -232,6 +291,16 @@ left-pad@^1.1.3:
|
||||
version "1.1.3"
|
||||
resolved "https://registry.yarnpkg.com/left-pad/-/left-pad-1.1.3.tgz#612f61c033f3a9e08e939f1caebeea41b6f3199a"
|
||||
|
||||
lodash@^4.17.4:
|
||||
version "4.17.4"
|
||||
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.4.tgz#78203a4d1c328ae1d86dca6460e369b57f4055ae"
|
||||
|
||||
log-symbols@^1.0.2:
|
||||
version "1.0.2"
|
||||
resolved "https://registry.yarnpkg.com/log-symbols/-/log-symbols-1.0.2.tgz#376ff7b58ea3086a0f09facc74617eca501e1a18"
|
||||
dependencies:
|
||||
chalk "^1.0.0"
|
||||
|
||||
memwatch-next@^0.3.0:
|
||||
version "0.3.0"
|
||||
resolved "https://registry.yarnpkg.com/memwatch-next/-/memwatch-next-0.3.0.tgz#2111050f9a906e0aa2d72a4ec0f0089c78726f8f"
|
||||
@ -239,6 +308,10 @@ memwatch-next@^0.3.0:
|
||||
bindings "^1.2.1"
|
||||
nan "^2.3.2"
|
||||
|
||||
mimic-fn@^1.0.0:
|
||||
version "1.1.0"
|
||||
resolved "https://registry.yarnpkg.com/mimic-fn/-/mimic-fn-1.1.0.tgz#e667783d92e89dbd342818b5230b9d62a672ad18"
|
||||
|
||||
minimatch@^3.0.4:
|
||||
version "3.0.4"
|
||||
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.4.tgz#5166e286457f03306064be5497e8dbb0c3d32083"
|
||||
@ -270,6 +343,21 @@ once@^1.3.0:
|
||||
dependencies:
|
||||
wrappy "1"
|
||||
|
||||
onetime@^2.0.0:
|
||||
version "2.0.1"
|
||||
resolved "https://registry.yarnpkg.com/onetime/-/onetime-2.0.1.tgz#067428230fd67443b2794b22bba528b6867962d4"
|
||||
dependencies:
|
||||
mimic-fn "^1.0.0"
|
||||
|
||||
ora@^1.1.0:
|
||||
version "1.3.0"
|
||||
resolved "https://registry.yarnpkg.com/ora/-/ora-1.3.0.tgz#80078dd2b92a934af66a3ad72a5b910694ede51a"
|
||||
dependencies:
|
||||
chalk "^1.1.1"
|
||||
cli-cursor "^2.1.0"
|
||||
cli-spinners "^1.0.0"
|
||||
log-symbols "^1.0.2"
|
||||
|
||||
path-is-absolute@^1.0.0:
|
||||
version "1.0.1"
|
||||
resolved "https://registry.yarnpkg.com/path-is-absolute/-/path-is-absolute-1.0.1.tgz#174b9268735534ffbc7ace6bf53a5a9e1b5c5f5f"
|
||||
@ -294,6 +382,13 @@ resolve@^1.1.6:
|
||||
dependencies:
|
||||
path-parse "^1.0.5"
|
||||
|
||||
restore-cursor@^2.0.0:
|
||||
version "2.0.0"
|
||||
resolved "https://registry.yarnpkg.com/restore-cursor/-/restore-cursor-2.0.0.tgz#9f7ee287f82fd326d4fd162923d62129eee0dfaf"
|
||||
dependencies:
|
||||
onetime "^2.0.0"
|
||||
signal-exit "^3.0.2"
|
||||
|
||||
semver@^5.3.0:
|
||||
version "5.4.1"
|
||||
resolved "https://registry.yarnpkg.com/semver/-/semver-5.4.1.tgz#e059c09d8571f0540823733433505d3a2f00b18e"
|
||||
@ -306,6 +401,10 @@ shelljs@^0.7.8:
|
||||
interpret "^1.0.0"
|
||||
rechoir "^0.6.2"
|
||||
|
||||
signal-exit@^3.0.2:
|
||||
version "3.0.2"
|
||||
resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.2.tgz#b5fdc08f1287ea1178628e415e25132b73646c6d"
|
||||
|
||||
smartchai@^1.0.3:
|
||||
version "1.0.3"
|
||||
resolved "https://registry.yarnpkg.com/smartchai/-/smartchai-1.0.3.tgz#de6d010bb8b5aef24cb70b31a5f5334e8c41b72f"
|
||||
@ -324,6 +423,14 @@ smartdelay@^1.0.3:
|
||||
smartq "^1.1.1"
|
||||
typings-global "^1.0.16"
|
||||
|
||||
smartenv@^2.0.0:
|
||||
version "2.0.6"
|
||||
resolved "https://registry.yarnpkg.com/smartenv/-/smartenv-2.0.6.tgz#b38c679b0c151b9af548f68c3a072c29d1417e8d"
|
||||
dependencies:
|
||||
lodash "^4.17.4"
|
||||
smartq "^1.1.1"
|
||||
typings-global "^1.0.14"
|
||||
|
||||
smartq@^1.1.1, smartq@^1.1.6:
|
||||
version "1.1.6"
|
||||
resolved "https://registry.yarnpkg.com/smartq/-/smartq-1.1.6.tgz#0c1ff4336d95e95b4f1fdd8ccd7e2c5a323b8412"
|
||||
@ -349,6 +456,16 @@ smartshell@^1.0.6:
|
||||
typings-global "^1.0.19"
|
||||
which "^1.2.14"
|
||||
|
||||
strip-ansi@^3.0.0:
|
||||
version "3.0.1"
|
||||
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-3.0.1.tgz#6a385fb8853d952d5ff05d0e8aaf94278dc63dcf"
|
||||
dependencies:
|
||||
ansi-regex "^2.0.0"
|
||||
|
||||
supports-color@^2.0.0:
|
||||
version "2.0.0"
|
||||
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-2.0.0.tgz#535d045ce6b6363fa40117084629995e9df324c7"
|
||||
|
||||
tapbundle@^1.0.13:
|
||||
version "1.1.1"
|
||||
resolved "https://registry.yarnpkg.com/tapbundle/-/tapbundle-1.1.1.tgz#ec4172c0e82a77b1f6133fef2606311ede28a62d"
|
||||
|
Loading…
Reference in New Issue
Block a user