Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

accept files as parameters #28 #29

Merged
merged 1 commit into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .github/workflows/npm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: npm-publish
on:
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20.x'
registry-url: 'https://registry.npmjs.org'
- run: npm ci
- run: npm publish --provenance --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
25 changes: 20 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ Using modules
```html
<script type="module">

import {parse, render} from 'https://esm.sh/@tbela99/css-parser@0.6.0/web';
import {extract} from 'https://esm.sh/@tbela99/critical@1.1.1/browser';
import {parse, render} from 'https://esm.sh/@tbela99/css-parser@0.7.1/web';
import {extract} from 'https://esm.sh/@tbela99/critical@1.2.0/browser';

const results = await extract({fonts: true});
// css is optimized using https://www.npmjs.com/package/@tbela99/css-parser
Expand All @@ -26,8 +26,8 @@ Using modules

Without using modules
```html
<script src="https://cdn.jsdelivr.net/gh/tbela99/critical@1.1.1/dist/browser-umd.js"></script>
<script src="https://cdn.jsdelivr.net/gh/tbela99/css-parser@0.6.0/dist/index-umd-web.js"></script>
<script src="https://cdn.jsdelivr.net/gh/tbela99/critical@1.2.0/dist/browser-umd.js"></script>
<script src="https://cdn.jsdelivr.net/gh/tbela99/css-parser@0.7.1/dist/index-umd-web.js"></script>
<script>

(async () => {
Expand Down Expand Up @@ -175,6 +175,7 @@ Options:
-k, --browser-type use a mobile browser
[string] [choices: "mobile", "desktop"]
-r, --random-browser use a random browser [boolean] [default: false]
-u, --random-user-agent use a random user agent [boolean] [default: false]
-i, --screenshot Generate screenshots [boolean]
-s, --secure enable or disable security settings such as CSP and same
origin policy [boolean]
Expand Down Expand Up @@ -203,12 +204,21 @@ Options:

### Example

### Read data from URL

```shell

$ critical-cli https://github.com/ https://nodejs.org --secure=no -i -d '1440x900' -d '1366x768' --json
```

### Read data from cli
### Read data from file(s)

```shell

$ critical-cli pages/dashboard.html pages/404.html --secure=no -i -d '1440x900' -d '1366x768' --json
```

### Read data from STDIN

```shell

Expand All @@ -217,6 +227,11 @@ $ cat pages/dashboard.html | critical-cli --base=pages/ --secure=no -i -d '1440x

## CHANGELOG

### V1.2.0

- accept files parameters in addition to urls
- add missing cli argument 'random-user-agent'

### V1.1.1

- fix node 22 compatibility issues
Expand Down
7 changes: 7 additions & 0 deletions bin/args.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@
"type": "boolean",
"default": false
},
"random-user-agent": {
"alias": "u",
"demandOption": false,
"description": "use a random user agent",
"type": "boolean",
"default": false
},
"screenshot": {
"alias": "i",
"demandOption": false,
Expand Down
14 changes: 10 additions & 4 deletions dist/browser-umd.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/browser-umd.js.map

Large diffs are not rendered by default.

14 changes: 10 additions & 4 deletions dist/browser.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/browser.js.map

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions dist/critical/fontscript.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/critical/fontscript.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 7 additions & 3 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,13 @@ interface CriticalCliResult {
html: string
}

/**
* execute critical css generation
*/
declare function critical(options: CriticalOptions): Promise<CriticalCliResult>;
/**
* execute critical css generation
*/
declare function critical(url: string, options: CriticalOptions): Promise<CriticalCliResult>;
declare function isWhiteSpace(codepoint: number): boolean;
declare function splitRule(buffer: string): string[][];

export { critical, isWhiteSpace, splitRule };
export { critical };
119 changes: 8 additions & 111 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion jsr.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tbela99/critical",
"version": "1.1.1",
"version": "1.2.0",
"publish": {
"include": [
"src",
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.1.1",
"version": "1.2.0",
"name": "@tbela99/critical",
"description": "Generate critical CSS path from HTML pages to enable instantaneous rendering",
"type": "module",
Expand Down Expand Up @@ -43,7 +43,8 @@
"critical",
"critical-css-path",
"critical-path",
"critical-css"
"critical-css",
"above-the-fold"
],
"devDependencies": {
"@esm-bundle/chai": "^4.3.4-fix.0",
Expand Down
Loading