Skip to content

Commit

Permalink
fix(cli): rename buildDir to staticDistDir
Browse files Browse the repository at this point in the history
BREAKING CHANGE: buildDir -> staticDistDir
  • Loading branch information
patrickhulce committed Nov 8, 2019
1 parent 14666ac commit 6244102
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 17 deletions.
4 changes: 2 additions & 2 deletions docs/cli.md
Expand Up @@ -86,7 +86,7 @@ Options:
--headful Run with a headful Chrome [boolean]
--additive Skips clearing of previous collect data [boolean]
--url The URL to run Lighthouse on.
--buildDir The build directory where your HTML files to run
--staticDistDir The build directory where your HTML files to run
Lighthouse on are located.
--settings The Lighthouse settings and flags to use when collecting
--numberOfRuns, -n The number of times to run Lighthouse.
Expand All @@ -100,7 +100,7 @@ Options:
```
lhci collect --numberOfRuns=5 --url=https://example.com
lhci collect --start-server-command="yarn serve" --url=http://localhost:8080/
lhci collect --buildDir=./dist
lhci collect --staticDistDir=./dist
lhci collect --url=https://example-1.com --url=https://example-2.com
```

Expand Down
2 changes: 1 addition & 1 deletion docs/getting-started.md
Expand Up @@ -149,7 +149,7 @@ fi

#### Deploy Your Code

To run Lighthouse CI, the code you'd like to test with Lighthouse needs to be available on a server. You can either use the built-in Lighthouse CI server, a custom local development server, or deploy to a public/intranet location. For this example, we'll assume your site is already built in a local directory called `./dist`, and we'll use the the `http-server` node package as an example custom server implementation (do not follow this structure just to use `http-server`, it is less fully featured than `lhci collect --build-dir=./dist`, see [Run Lighthouse CI](#run-lighthouse-ci) for more).
To run Lighthouse CI, the code you'd like to test with Lighthouse needs to be available on a server. You can either use the built-in Lighthouse CI server, a custom local development server, or deploy to a public/intranet location. For this example, we'll assume your site is already built in a local directory called `./dist`, and we'll use the the `http-server` node package as an example custom server implementation (do not follow this structure just to use `http-server`, it is less fully featured than `lhci collect --static-dist-dir=./dist`, see [Run Lighthouse CI](#run-lighthouse-ci) for more).

```bash
#!/bin/bash
Expand Down
9 changes: 5 additions & 4 deletions packages/cli/src/autorun/autorun.js
Expand Up @@ -68,13 +68,13 @@ function findBuildDir() {
if (!fs.statSync(fullDirPath).isDirectory()) continue;
const contents = fs.readdirSync(fullDirPath);
if (contents.some(file => file.endsWith('.html'))) {
process.stdout.write(`Automatically determined ./${dir} as \`buildDir\`.\n`);
process.stdout.write(`Automatically determined ./${dir} as \`staticDistDir\`.\n`);
process.stdout.write(`Set it explicitly in lighthouserc.json if incorrect.\n\n`);
return fullDirPath;
}
}

throw new Error('Unable to determine `buildDir`; Set it explicitly in lighthouserc.json');
throw new Error('Unable to determine `staticDistDir`; Set it explicitly in lighthouserc.json');
}

/** @return {string} */
Expand Down Expand Up @@ -116,10 +116,11 @@ async function runCommand(options) {
if (healthcheckStatus !== 0) process.exit(healthcheckStatus);

const collectHasUrlOrBuildDir =
ciConfiguration.collect && (ciConfiguration.collect.url || ciConfiguration.collect.buildDir);
ciConfiguration.collect &&
(ciConfiguration.collect.url || ciConfiguration.collect.staticDistDir);
const collectArgs = collectHasUrlOrBuildDir
? [getStartServerCommandFlag()]
: [`--build-dir=${findBuildDir()}`];
: [`--static-dist-dir=${findBuildDir()}`];
const collectStatus = runChildCommand('collect', [...defaultFlags, ...collectArgs]).status;
if (collectStatus !== 0) process.exit(collectStatus);

Expand Down
6 changes: 3 additions & 3 deletions packages/cli/src/collect/collect.js
Expand Up @@ -23,7 +23,7 @@ function buildCommand(yargs) {
headful: {type: 'boolean', description: 'Run with a headful Chrome'},
additive: {type: 'boolean', description: 'Skips clearing of previous collect data'},
url: {description: 'The URL to run Lighthouse on.'},
buildDir: {
staticDistDir: {
description: 'The build directory where your HTML files to run Lighthouse on are located.',
},
startServerCommand: {
Expand Down Expand Up @@ -83,9 +83,9 @@ async function determineUrls(options) {
};
}

if (!options.buildDir) throw new Error('Either url or buildDir required');
if (!options.staticDistDir) throw new Error('Either url or staticDistDir required');

const pathToBuildDir = path.resolve(process.cwd(), options.buildDir);
const pathToBuildDir = path.resolve(process.cwd(), options.staticDistDir);
const server = new FallbackServer(pathToBuildDir);
await server.listen();
process.stdout.write(`Started a web server on port ${server.port}...\n`);
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/test/autorun-static-dir.test.js
Expand Up @@ -31,7 +31,7 @@ describe('Lighthouse CI autorun CLI', () => {
⚠️ GitHub token set
Healthcheck passed!
Automatically determined ./build as \`buildDir\`.
Automatically determined ./build as \`staticDistDir\`.
Set it explicitly in lighthouserc.json if incorrect.
Started a web server on port XXXX...
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/test/cli.test.js
Expand Up @@ -26,7 +26,7 @@ describe('Lighthouse CI CLI', () => {
const rcMatrixFile = path.join(__dirname, 'fixtures/lighthouserc-matrix.json');
const rcExtendedFile = path.join(__dirname, 'fixtures/lighthouserc-extended.json');
const budgetsFile = path.join(__dirname, 'fixtures/budgets.json');
const buildDir = path.join(__dirname, 'fixtures');
const staticDistDir = path.join(__dirname, 'fixtures');
const tmpSqlFilePath = getSqlFilePath();

let server;
Expand Down Expand Up @@ -142,11 +142,11 @@ describe('Lighthouse CI CLI', () => {
});

describe('collect', () => {
it('should collect results from buildDir', () => {
it('should collect results from staticDistDir', () => {
const {stdout, stderr, status} = runCLI([
'collect',
`--rc-file=${rcFile}`,
`--build-dir=${buildDir}`,
`--static-dist-dir=${staticDistDir}`,
]);

const stdoutClean = stdout.replace(/:\d{4,6}/g, ':XXXX').replace(/port \d{4,6}/, 'port XXXX');
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/test/fixtures/checkout.html
Expand Up @@ -2,7 +2,7 @@
<html>
<head>
<meta charset="utf-8" />
<title>checkout test page for buildDir usage</title>
<title>checkout test page for staticDistDir usage</title>
</head>
<body>
test
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/test/fixtures/index.html
Expand Up @@ -2,7 +2,7 @@
<html>
<head>
<meta charset="utf-8" />
<title>index test page for buildDir usage</title>
<title>index test page for staticDistDir usage</title>
</head>
<body>
test
Expand Down
2 changes: 1 addition & 1 deletion types/collect.d.ts
Expand Up @@ -40,7 +40,7 @@ declare global {

export interface Options {
url?: string | string[];
buildDir?: string;
staticDistDir?: string;
startServerCommand?: string;
method: 'node';
numberOfRuns: number;
Expand Down

0 comments on commit 6244102

Please sign in to comment.