Add cli with flags. URL now customizable

This commit is contained in:
Paul Irish 2016-03-22 11:24:49 -07:00
Родитель 5a8849d65e
Коммит 10e5a9368a
3 изменённых файлов: 58 добавлений и 11 удалений

39
cli.js Executable file
Просмотреть файл

@ -0,0 +1,39 @@
#!/usr/bin/env node
/**
* Copyright 2016 Google Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
'use strict';
var chalk = require('chalk');
var meow = require('meow');
var lighthouse = require('./');
var cli = meow({
pkg: './package.json',
help: [
'Options',
' --help Show this help',
' --version Current version of package',
'',
'Usage',
' lighthouse [url]'
]
})
lighthouse({
url: cli.input[0],
flags: cli.flags
});

Просмотреть файл

@ -15,7 +15,7 @@
*/
'use strict';
const url = 'https://voice-memos.appspot.com';
const defaultUrl = 'https://voice-memos.appspot.com';
const ChromeProtocol = require('./helpers/browser/driver');
const Auditor = require('./auditor');
@ -46,13 +46,16 @@ const audits = [
require('./audits/manifest/start-url')
];
gatherer
.gather(gatherers, {url, driver})
.then(artifacts => auditor.audit(artifacts, audits))
.then(results => {
console.log(results);
}).catch(function(err) {
console.log('error encountered', err);
console.log(err.stack);
throw err;
});
module.exports = function(opts) {
var url = opts.url || defaultUrl;
gatherer
.gather(gatherers, {url, driver})
.then(artifacts => auditor.audit(artifacts, audits))
.then(results => {
console.log(results);
}).catch(function(err) {
console.log('error encountered', err);
console.log(err.stack);
throw err;
});
}

Просмотреть файл

@ -3,6 +3,9 @@
"version": "1.0.0",
"description": "",
"main": "index.js",
"bin": {
"lighthouse": "cli.js"
},
"directories": {
"test": "tests"
},
@ -27,10 +30,12 @@
},
"homepage": "https://github.com/googlechrome/big-rig#readme",
"dependencies": {
"chalk": "^1.1.1",
"chrome-devtools-frontend": "1.0.381789",
"chrome-remote-interface": "^0.11.0",
"devtools-timeline-model": "1.0.16",
"file": "^0.2.2",
"meow": "^3.7.0",
"traceviewer": "^1.0.8"
},
"devDependencies": {