Comparing version 1.0.1 to 1.0.2
@@ -10,17 +10,9 @@ "use strict"; | ||
const argv = yargs_1.default.argv; | ||
this.projectName = argv.name; | ||
this.projectSlug = argv.slug; | ||
this.apiUrl = argv.api; | ||
this.siteUrl = argv.url; | ||
this.siteKey = argv.key; | ||
this.key = argv.key; | ||
if (!this.key) { | ||
throw new Error("--key flag is missing"); | ||
} | ||
} | ||
isAllParamsSet() { | ||
return (this.apiUrl && | ||
this.projectName && | ||
this.projectSlug && | ||
this.siteUrl && | ||
this.siteKey); | ||
} | ||
} | ||
exports.QaToolsCli = QaToolsCli; | ||
//# sourceMappingURL=cli.js.map |
#!/usr/bin/env node | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; | ||
result["default"] = mod; | ||
return result; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const cli_1 = require("./cli"); | ||
const ajax_1 = require("rxjs/ajax"); | ||
@@ -19,50 +8,23 @@ const rxjs_1 = require("rxjs"); | ||
const xmlhttprequest_1 = require("xmlhttprequest"); | ||
const lighthouse_1 = __importDefault(require("lighthouse")); | ||
const chromeLauncher = __importStar(require("chrome-launcher")); | ||
const cli_1 = require("./cli"); | ||
const config_file_1 = require("./config-file"); | ||
const audit_1 = require("./audit"); | ||
class QaTools { | ||
constructor() { | ||
this.cli = new cli_1.QaToolsCli(); | ||
this.opts = { | ||
chromeFlags: ["--disable-gpu", "--headless", "--no-zygote", "--no-sandbox"] | ||
}; | ||
if (!this.cli.isAllParamsSet()) { | ||
throw new Error("Some flags are missing, you need to use --slug, --api, --name, --url, --key"); | ||
} | ||
this.initialize(this.cli.siteUrl, this.opts).then(results => { | ||
const metrics = this.getMetrics(results); | ||
this.sendResults(metrics).subscribe(res => console.log(res)); | ||
}); | ||
this.file = new config_file_1.QaToolsConfig(); | ||
this.audit = new audit_1.QaAudit(this.file.config); | ||
this.audit | ||
.launch() | ||
.pipe(operators_1.mergeMap(results => this.sendResults(results))) | ||
.subscribe(test => console.log(test)); | ||
} | ||
initialize(url, opts, config = null) { | ||
return chromeLauncher | ||
.launch({ chromeFlags: opts.chromeFlags }) | ||
.then(chrome => { | ||
opts.port = chrome.port; | ||
return lighthouse_1.default(url, opts, config).then(results => { | ||
return chrome.kill().then(() => results.lhr.categories); | ||
}); | ||
}); | ||
} | ||
getMetrics(results) { | ||
return JSON.stringify({ | ||
name: this.cli.projectName, | ||
slug: this.cli.projectSlug, | ||
performances: this.percentify(results.performance), | ||
accessibility: this.percentify(results.accessibility), | ||
bestpractices: this.percentify(results["best-practices"]), | ||
seo: this.percentify(results.seo), | ||
pwa: this.percentify(results.pwa) | ||
}); | ||
} | ||
percentify(val) { | ||
return Math.round(val.score * 100); | ||
} | ||
sendResults(datas) { | ||
return ajax_1.ajax({ | ||
createXHR: () => new xmlhttprequest_1.XMLHttpRequest(), | ||
url: `${this.cli.apiUrl}/${this.cli.projectSlug}`, | ||
url: `${this.file.config.api}/${this.file.config.slug}`, | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
Authorization: "Bearer " + this.cli.siteKey | ||
Authorization: "Bearer " + this.cli.key | ||
}, | ||
@@ -69,0 +31,0 @@ body: datas |
{ | ||
"name": "@yoozly/qa", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
11408
9
167
2
1