Skip to content

Commit 8a8ebec

Browse files
author
Mark George
committed
Add prettier
1 parent f533060 commit 8a8ebec

35 files changed

+931
-978
lines changed

.eslintrc

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
{
2-
"plugins": [
3-
"jest"
4-
],
2+
"plugins": ["jest"],
53
"env": {
64
"browser": true,
75
"node": true,
@@ -18,7 +16,9 @@
1816
"plugin:@wordpress/eslint-plugin/recommended"
1917
],
2018
"rules": {
21-
"no-unused-vars": [ "error", { "args": "after-used", "argsIgnorePattern": "^_" }]
19+
"no-unused-vars": [
20+
"error",
21+
{ "args": "after-used", "argsIgnorePattern": "^_" }
22+
]
2223
}
2324
}
24-

.github/workflows/issues-to-projects.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ jobs:
1212
- uses: leonsteinhaeuser/[email protected]
1313
with:
1414
gh_token: ${{ secrets.PROJECT_MANAGEMENT_TOKEN }}
15-
organization: 'automattic'
15+
organization: "automattic"
1616
project_id: 322
1717
resource_node_id: ${{ github.event.issue.node_id }}

.github/workflows/jest-test.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
- name: Setup Node.js
1111
uses: actions/setup-node@v1
1212
with:
13-
node-version: '12'
13+
node-version: "12"
1414

1515
- name: Install Dependencies
1616
run: npm ci

.github/workflows/lint.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
- name: Setup Node.js
1111
uses: actions/setup-node@v1
1212
with:
13-
node-version: '12'
13+
node-version: "12"
1414

1515
- name: Install Dependencies
1616
run: npm ci

LICENSE.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
The files in this project are Copyright © Automattic Inc, 2021, and licensed under the The GPLv2 (or later) from the [Free Software Foundation](http://www.fsf.org/). Its text follows.
1+
The files in this project are Copyright © Automattic Inc, 2021, and licensed under the The GPLv2 (or later) from the [Free Software Foundation](http://www.fsf.org/). Its text follows.
22

33
Version 2, June 1991
44

@@ -27,7 +27,6 @@ The precise terms and conditions for copying, distribution and modification foll
2727

2828
### GNU General Public License Terms and Conditions for Copying, Distribution, and Modification
2929

30-
3130
<ol start="0">
3231

3332
<li>This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does.</li>

README.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,31 @@
11
# jetpack-boost-critical-css-gen
2+
23
Critical CSS Generator built for Jetpack Boost. It can generate Critical CSS on the server-side using Puppeteer, or on the client-side using iframes. It also supports generating blocks of Critical CSS that can apply to multiple URLs, and/or multiple viewports.
34

45
# Warning
6+
57
This is a work in progress, and its API is not guaranteed to be stable. :)
68

79
# Basic API
10+
811
```
912
const { BrowserInterfacePlaywright, BrowserInterfacePuppeteer, BrowserInterfaceIframe, generateCriticalCSS } = require( 'jetpack-boost-critical-css-gen' );
1013
const [css, warnings] = generateCriticalCSS( options );
1114
```
1215

1316
Where `options` is an object with the following keys:
17+
1418
- `urls` (required) - An array of URLs to generate Critical CSS for.
1519
- `viewports` (required) - An array of viewport sizes to generate Critical CSS for. Each entry should be an object with a `width` and `height` property.
1620
- `browserInterface` (required) - An instance of `BrowserInterfacePlaywright` or `BrowserInterfacePuppeteer` or `BrowserInterfaceIframe` which defines an interface for the Generator to query the (real or virtual) browser.
1721
- `progressCallback` - A callback to receive progress information, with two arguments; `step` and `stepCount`. Each are integers; progress percentage can be expressed in the form `percentage = step * 100 / stepCount`.
1822
- `filters` - An object describing a filter to run each property and/or atRule through for inclusion.
1923

2024
Example usage:
25+
2126
```
2227
const { BrowserInterfaceIframe, generateCriticalCSS } = require( 'jetpack-boost-critical-css-gen' );
23-
28+
2429
const [css, warnings] = await generateCriticalCSS( {
2530
urls: [ 'http://example.com' ],
2631
viewports: [ { width: 800, height: 600 } ],

bin/generate.js

+24-27
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,47 @@
1-
const playwright = require( 'playwright' );
2-
const {
3-
generateCriticalCSS,
4-
BrowserInterfacePlaywright,
5-
} = require( '../index' );
1+
const playwright = require("playwright");
2+
const { generateCriticalCSS, BrowserInterfacePlaywright } = require("../index");
63

74
async function main() {
8-
const urls = process.argv.slice( 2 );
5+
const urls = process.argv.slice(2);
96

10-
if ( urls.length === 0 ) {
11-
console.log( 'Usage: node bin/generate.js [url1] [url2] ...' );
7+
if (urls.length === 0) {
8+
console.log("Usage: node bin/generate.js [url1] [url2] ...");
129
}
1310

14-
console.log( 'Loading pages: ' );
15-
console.log( urls );
11+
console.log("Loading pages: ");
12+
console.log(urls);
1613

1714
const browser = await playwright.chromium.launch();
1815
const testPages = {};
19-
for ( const url of urls ) {
20-
testPages[ url ] = await browser.newPage();
21-
await testPages[ url ].goto( url );
16+
for (const url of urls) {
17+
testPages[url] = await browser.newPage();
18+
await testPages[url].goto(url);
2219
}
2320

24-
console.log( 'Generating Critical CSS...' );
21+
console.log("Generating Critical CSS...");
2522

26-
const [ css, warnings ] = await generateCriticalCSS( {
23+
const [css, warnings] = await generateCriticalCSS({
2724
urls,
2825
viewports: [
2926
{ width: 414, height: 896 },
3027
{ width: 1200, height: 800 },
3128
{ width: 1920, height: 1080 },
3229
],
33-
browserInterface: new BrowserInterfacePlaywright( testPages ),
34-
} );
30+
browserInterface: new BrowserInterfacePlaywright(testPages),
31+
});
3532

36-
if ( warnings.length ) {
37-
console.log( '\n\nwarnings => ' );
38-
console.log( warnings );
33+
if (warnings.length) {
34+
console.log("\n\nwarnings => ");
35+
console.log(warnings);
3936
}
4037

41-
console.log( 'css => ' );
42-
console.log( css );
38+
console.log("css => ");
39+
console.log(css);
4340
}
4441

4542
main()
46-
.catch( ( err ) => {
47-
console.error( err );
48-
process.exit( 1 );
49-
} )
50-
.then( () => process.exit( 0 ) );
43+
.catch((err) => {
44+
console.error(err);
45+
process.exit(1);
46+
})
47+
.then(() => process.exit(0));

package-lock.json

+22
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
"scripts": {
99
"build": "tsc --declaration && rollup -c",
1010
"prepare": "npm run build",
11-
"lint": "eslint . && echo '✔ eslint ran successfully.'",
12-
"lint:fix": "eslint --fix . && echo '✔ eslint ran successfully.'",
11+
"lint": "prettier --check . && eslint . && echo '✔ eslint and prettier ran successfully.'",
12+
"lint:fix": "prettier --write . && eslint --fix . && echo '✔ eslint and prettier ran successfully.'",
1313
"test": "NODE_ENV=test jest --forceExit --config=tests/config/jest.config.js"
1414
},
1515
"husky": {
@@ -32,6 +32,7 @@
3232
"jest-environment-puppeteer": "^6.1.1",
3333
"os-browserify": "^0.3.0",
3434
"path-browserify": "^1.0.1",
35+
"prettier": "^2.7.1",
3536
"puppeteer": "^16.2.0",
3637
"rollup": "^2.78.1",
3738
"rollup-plugin-polyfill-node": "^0.10.2",

rollup.config.js

+27-25
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,37 @@
1-
import commonjs from '@rollup/plugin-commonjs';
2-
import resolve from '@rollup/plugin-node-resolve';
3-
import json from '@rollup/plugin-json';
4-
import { terser } from 'rollup-plugin-terser';
5-
import nodePolyfills from 'rollup-plugin-polyfill-node';
6-
import typescript from '@rollup/plugin-typescript';
1+
import commonjs from "@rollup/plugin-commonjs";
2+
import resolve from "@rollup/plugin-node-resolve";
3+
import json from "@rollup/plugin-json";
4+
import { terser } from "rollup-plugin-terser";
5+
import nodePolyfills from "rollup-plugin-polyfill-node";
6+
import typescript from "@rollup/plugin-typescript";
77

88
export default {
9-
input: 'src/index.ts',
10-
output: [ {
11-
sourcemap: true,
12-
format: 'iife',
13-
name: 'CriticalCSSGenerator',
14-
file: 'dist/bundle.js',
15-
},
16-
{
17-
sourcemap: true,
18-
format: 'iife',
19-
name: 'CriticalCSSGenerator',
20-
file: 'dist/bundle.min.js',
21-
plugins: [ terser() ],
22-
}],
9+
input: "src/index.ts",
10+
output: [
11+
{
12+
sourcemap: true,
13+
format: "iife",
14+
name: "CriticalCSSGenerator",
15+
file: "dist/bundle.js",
16+
},
17+
{
18+
sourcemap: true,
19+
format: "iife",
20+
name: "CriticalCSSGenerator",
21+
file: "dist/bundle.min.js",
22+
plugins: [terser()],
23+
},
24+
],
2325

2426
plugins: [
25-
resolve( { browser: true, preferBuiltins: false } ),
26-
typescript( {
27+
resolve({ browser: true, preferBuiltins: false }),
28+
typescript({
2729
sourceMap: true,
2830
inlineSources: false,
29-
} ),
30-
commonjs( {
31+
}),
32+
commonjs({
3133
transformMixedEsModules: true,
32-
} ),
34+
}),
3335
nodePolyfills(),
3436
json(),
3537
],

0 commit comments

Comments
 (0)