Skip to content

Commit

Permalink
cli: compile out TS; add TSC checking of jsdoc types
Browse files Browse the repository at this point in the history
  • Loading branch information
brendankenny committed Nov 4, 2017
1 parent efe0e48 commit efea8ce
Show file tree
Hide file tree
Showing 40 changed files with 580 additions and 2,058 deletions.
7 changes: 0 additions & 7 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,9 @@
**/dist/**
lighthouse-extension/app/scripts


**/closure/*/*
coverage/**

# Typescript compiled
!lighthouse-cli/index.js
lighthouse-cli/*.js
lighthouse-cli/commands/*.js
lighthouse-cli/types/*.js

# Generated files
plots/out*

Expand Down
10 changes: 0 additions & 10 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,6 @@ last-run-results.html

closure-error.log

!lighthouse-cli/index.js
lighthouse-cli/*.map
lighthouse-cli/*.js

lighthouse-cli/commands/*.map
lighthouse-cli/commands/*.js

lighthouse-cli/types/*.js
lighthouse-cli/types/*.map

/chrome-linux/
/chrome-win32/
/chrome.zip
Expand Down
4 changes: 1 addition & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ cache:
yarn: true
directories:
- node_modules
- lighthouse-cli/node_modules
- lighthouse-extension/node_modules
- lighthouse-viewer/node_modules
- /home/travis/.rvm/gems/
Expand All @@ -31,7 +30,6 @@ before_script:
- yarn build-all
script:
- yarn bundlesize
- yarn test-cli-formatting
- yarn lint
- yarn unit
- yarn closure
Expand All @@ -45,7 +43,7 @@ before_cache:
- rm -rf ./node_modules/temp-devtoolsfrontend/
- rm -rf ./node_modules/temp-devtoolsprotocol/
after_success:
- ./lighthouse-core/scripts/generate-combined-coverage.sh
- yarn coveralls
after_failure:
- grep 'No screenshots' perf.json && travis-artifacts upload --path perf-0.trace.json
addons:
Expand Down
6 changes: 0 additions & 6 deletions lighthouse-cli/.clang-format

This file was deleted.

1 change: 1 addition & 0 deletions lighthouse-cli/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
!.eslintrc.js
13 changes: 13 additions & 0 deletions lighthouse-cli/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* @license Copyright 2017 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';

module.exports = {
extends: '../.eslintrc.js',
parserOptions: {
ecmaVersion: 2017,
},
};
22 changes: 0 additions & 22 deletions lighthouse-cli/README.md

This file was deleted.

48 changes: 30 additions & 18 deletions lighthouse-cli/bin.ts → lighthouse-cli/bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,51 +5,57 @@
*/
'use strict';

import {existsSync} from 'fs';
import * as path from 'path';
const existsSync = require('fs').existsSync;
const path = require('path');

import * as Commands from './commands/commands';
import * as Printer from './printer';
import {getFlags} from './cli-flags';
import {runLighthouse} from './run';
const commands = require('./commands/commands.js');
const printer = require('./printer.js');
const getFlags = require('./cli-flags.js').getFlags;
const runLighthouse = require('./run').runLighthouse;

const log = require('lighthouse-logger');
// @ts-ignore
const perfOnlyConfig = require('../lighthouse-core/config/perf.json');
// @ts-ignore
const pkg = require('../package.json');
const Sentry = require('../lighthouse-core/lib/sentry');

// accept noop modules for these, so the real dependency is optional.
import {updateNotifier} from './shim-modules';
import {askPermission} from './sentry-prompt';
const updateNotifier = require('update-notifier');
const askPermission = require('./sentry-prompt').askPermission;

/**
* @return {boolean}
*/
function isDev() {
return existsSync(path.join(__dirname, '../.git'));
}

// Tell user if there's a newer version of LH.
updateNotifier({pkg}).notify();

const cliFlags = getFlags();
const /** @type {!LH.Flags} */ cliFlags = getFlags();

// Process terminating command
if (cliFlags.listAllAudits) {
Commands.ListAudits();
commands.listAudits();
}

// Process terminating command
if (cliFlags.listTraceCategories) {
Commands.ListTraceCategories();
commands.listTraceCategories();
}

/** @type {string} */
const url = cliFlags._[0];

let config: Object|null = null;
/** @type {!LH.Config|undefined} */
let config;
if (cliFlags.configPath) {
// Resolve the config file path relative to where cli was called.
cliFlags.configPath = path.resolve(process.cwd(), cliFlags.configPath);
config = require(cliFlags.configPath);
config = /** @type {!LH.Config} */ (require(cliFlags.configPath));
} else if (cliFlags.perf) {
config = perfOnlyConfig;
config = /** @type {!LH.Config} */ (perfOnlyConfig);
}

// set logging preferences
Expand All @@ -61,11 +67,13 @@ if (cliFlags.verbose) {
}
log.setLevel(cliFlags.logLevel);

if (cliFlags.output === Printer.OutputMode[Printer.OutputMode.json] && !cliFlags.outputPath) {
if (cliFlags.output === printer.OutputMode.json && !cliFlags.outputPath) {
cliFlags.outputPath = 'stdout';
}

export async function run() {
/**
* @return {!Promise<(void|!Object)>}
*/
async function run() {
if (typeof cliFlags.enableErrorReporting === 'undefined') {
cliFlags.enableErrorReporting = await askPermission();
}
Expand All @@ -85,3 +93,7 @@ export async function run() {

return runLighthouse(url, cliFlags, config);
}

module.exports = {
run,
};
56 changes: 30 additions & 26 deletions lighthouse-cli/cli-flags.ts → lighthouse-cli/cli-flags.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@
*/
'use strict';

/* eslint-disable max-len */

const yargs = require('yargs');
// @ts-ignore
const pkg = require('../package.json');
const Driver = require('../lighthouse-core/gather/driver.js');
const printer = require('./printer');

import {GetValidOutputOptions, OutputMode} from './printer';

export interface Flags {
port: number, chromeFlags: string, output: any, outputPath: string, saveArtifacts: boolean,
saveAssets: boolean, view: boolean, maxWaitForLoad: number, logLevel: string,
hostname: string, blockedUrlPatterns: string[], enableErrorReporting: boolean
}

export function getFlags(manualArgv?: string) {
/**
* @param {string=} manualArgv
* @return {!LH.Flags}
*/
function getFlags(manualArgv) {
// @ts-ignore yargs() is incorrectly typed as not returning itself
const y = manualArgv ? yargs(manualArgv) : yargs;

return y.help('help')
.version(() => pkg.version)
.showHelpOnFail(false, 'Specify --help for available options')
Expand Down Expand Up @@ -47,16 +47,16 @@ export function getFlags(manualArgv?: string) {
.group(['verbose', 'quiet'], 'Logging:')
.describe({
verbose: 'Displays verbose logging',
quiet: 'Displays no progress, debug logs or errors'
quiet: 'Displays no progress, debug logs or errors',
})

.group(
[
'save-assets', 'save-artifacts', 'list-all-audits', 'list-trace-categories',
'additional-trace-categories', 'config-path', 'chrome-flags', 'perf', 'port',
'hostname', 'max-wait-for-load', 'enable-error-reporting'
],
'Configuration:')
[
'save-assets', 'save-artifacts', 'list-all-audits', 'list-trace-categories',
'additional-trace-categories', 'config-path', 'chrome-flags', 'perf', 'port',
'hostname', 'max-wait-for-load', 'enable-error-reporting',
],
'Configuration:')
.describe({
'enable-error-reporting':
'Enables error reporting (prompts once by default, setting this flag will force error reporting to that state).',
Expand Down Expand Up @@ -90,31 +90,31 @@ export function getFlags(manualArgv?: string) {
.describe({
'output': `Reporter for the results, supports multiple values`,
'output-path': `The file path to output the results. Use 'stdout' to write to stdout.
If using JSON output, default is stdout.
If using HTML output, default is a file in the working directory with a name based on the test URL and date.
If using multiple outputs, --output-path is ignored.
Example: --output-path=./lighthouse-results.html`,
'view': 'Open HTML report in your browser'
If using JSON output, default is stdout.
If using HTML output, default is a file in the working directory with a name based on the test URL and date.
If using multiple outputs, --output-path is ignored.
Example: --output-path=./lighthouse-results.html`,
'view': 'Open HTML report in your browser',
})

// boolean values
.boolean([
'disable-storage-reset', 'disable-device-emulation', 'disable-cpu-throttling',
'disable-network-throttling', 'save-assets', 'save-artifacts', 'list-all-audits',
'list-trace-categories', 'perf', 'view', 'verbose', 'quiet', 'help'
'list-trace-categories', 'perf', 'view', 'verbose', 'quiet', 'help',
])
.choices('output', GetValidOutputOptions())
.choices('output', printer.getValidOutputOptions())
// force as an array
.array('blocked-url-patterns')

// default values
.default('chrome-flags', '')
.default('disable-cpu-throttling', false)
.default('output', GetValidOutputOptions()[OutputMode.domhtml])
.default('output', 'domhtml')
.default('port', 0)
.default('hostname', 'localhost')
.default('max-wait-for-load', Driver.MAX_WAIT_FOR_FULLY_LOADED)
.check((argv: {listAllAudits?: boolean, listTraceCategories?: boolean, _: Array<any>}) => {
.check(/** @param {!LH.Flags} argv */ (argv) => {
// Make sure lighthouse has been passed a url, or at least one of --list-all-audits
// or --list-trace-categories. If not, stop the program and ask for a url
if (!argv.listAllAudits && !argv.listTraceCategories && argv._.length === 0) {
Expand All @@ -128,3 +128,7 @@ Example: --output-path=./lighthouse-results.html`,
.wrap(yargs.terminalWidth())
.argv;
}

module.exports = {
getFlags,
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
* 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';

import ListAudits from './list-audits';
import ListTraceCategories from './list-trace-categories';
const listAudits = require('./list-audits.js');
const listTraceCategories = require('./list-trace-categories.js');

export {ListAudits, ListTraceCategories}
module.exports = {
listAudits,
listTraceCategories,
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
* 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';

const lighthouse = require('../../lighthouse-core');

export default function ListAudits() {
const audits = lighthouse.getAuditList().map((i: string) => i.replace(/\.js$/, ''));

function listAudits() {
const audits = lighthouse.getAuditList().map((i) => i.replace(/\.js$/, ''));
process.stdout.write(JSON.stringify({audits}, null, 2));
process.exit(0);
}

module.exports = listAudits;
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
* 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';

const lighthouse = require('../../lighthouse-core');

export default function listTraceCategories() {
function listTraceCategories() {
const traceCategories = lighthouse.traceCategories;

process.stdout.write(JSON.stringify({traceCategories}));
process.exit(0);
}

module.exports = listTraceCategories;
13 changes: 0 additions & 13 deletions lighthouse-cli/compiled-check.js

This file was deleted.

12 changes: 6 additions & 6 deletions lighthouse-cli/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/bin/env node

'use strict'

require('./compiled-check.js')('bin.js');
require('./compiled-check.js')('printer.js');
require('./compiled-check.js')('shim-modules.js');
/**
* @license Copyright 2017 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';

require('./bin.js').run();
Loading

0 comments on commit efea8ce

Please sign in to comment.