forked from nystudio107/rollup-plugin-critical
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
7,165 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
name: Node.js CI | ||
on: | ||
push: | ||
branches: [ master, develop ] | ||
pull_request: | ||
branches: [ master, develop ] | ||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: true | ||
matrix: | ||
node-version: [12.x, 14.x, 15.x] | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
- run: npm ci | ||
- run: npm run build --if-present | ||
- run: npm run test --if-present | ||
# Only run the coverage once | ||
- if: ${{ matrix.node-version == '14.x' }} | ||
name: Get Coverage for badge | ||
run: | | ||
# var SUMMARY = [ | ||
# '', | ||
# '=============================== Coverage summary ===============================', | ||
# 'Statements : 32.5% ( 39/120 )', | ||
# 'Branches : 38.89% ( 21/54 )', | ||
# 'Functions : 21.74% ( 5/23 )', | ||
# 'Lines : 31.93% ( 38/119 )', | ||
# '================================================================================', | ||
# '' | ||
# ]; | ||
# SUMMARY = SUMMARY.split('\n')[5]; // 'Lines : 31.93% ( 38/119 )' | ||
# SUMMARY = SUMMARY.split(':')[1].split('(')[0].trim(); // '31.93%' | ||
SUMMARY="$(npm test -- --coverageReporters='text-summary' | tail -2 | head -1)" | ||
TOKENS=($SUMMARY) | ||
# process.env.COVERAGE = '31.93%'; | ||
echo "COVERAGE=$(echo ${TOKENS[2]})" >> $GITHUB_ENV | ||
# var REF = 'refs/pull/27/merge.json'; | ||
REF=${{ github.ref }} | ||
# console.log('github.ref: ' + REF); | ||
echo "github.ref: $REF" | ||
# var PATHS = REF.split('/'); | ||
IFS='/' read -ra PATHS <<< "$REF" | ||
# var BRANCH_NAME = PATHS[1] + PATHS[2]; | ||
BRANCH_NAME="${PATHS[1]}_${PATHS[2]}" | ||
# console.log(BRANCH_NAME); // 'pull_27' | ||
echo $BRANCH_NAME | ||
# process.env.BRANCH = 'pull_27'; | ||
echo "BRANCH=$(echo ${BRANCH_NAME})" >> $GITHUB_ENV | ||
- if: ${{ matrix.node-version == '14.x' }} | ||
name: Create the Badge | ||
uses: schneegans/[email protected] | ||
with: | ||
auth: ${{ secrets.GIST_SECRET }} | ||
gistID: 550f6ee414a26e0c8eae7cb6af3c214e | ||
filename: rollup-plugin-critical__${{ env.BRANCH }}.json | ||
label: Test Coverage | ||
message: ${{ env.COVERAGE }} | ||
color: green | ||
namedLogo: jest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# BUILD FILES | ||
node_modules/ | ||
yarn-error.log | ||
npm-debug.log | ||
coverage/ | ||
src/__tests__/test_critical.min.css | ||
|
||
# MISC FILES | ||
.cache | ||
.DS_Store | ||
.idea | ||
.project | ||
.settings | ||
*.esproj | ||
*.sublime-workspace | ||
*.sublime-project | ||
*.tmproj | ||
*.tmproject | ||
.vscode/* | ||
!.vscode/settings.json | ||
!.vscode/tasks.json | ||
!.vscode/launch.json | ||
!.vscode/extensions.json | ||
config.codekit3 | ||
prepros-6.config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
checks: | ||
javascript: true | ||
build: | ||
environment: | ||
node: v14.17.0 | ||
nodes: | ||
analysis: | ||
tests: | ||
override: | ||
- js-scrutinizer-run | ||
tests: true | ||
coverage: | ||
tests: | ||
override: | ||
- command: 'npm run test' | ||
coverage: | ||
file: 'coverage/clover.xml' | ||
format: 'clover' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Rollup Plugin Critical | ||
|
||
All notable changes to this project will be documented in this file. | ||
|
||
## 1.0.0 - 2021-05-30 | ||
### Added | ||
* Initial release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
ARG TAG=14-alpine | ||
FROM nystudio107/node-dev-base:$TAG | ||
|
||
WORKDIR /app/ | ||
|
||
CMD ["run build"] | ||
|
||
ENTRYPOINT ["npm"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2020 Petr Tsymbarovich | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
TAG?=14-alpine | ||
CONTAINER?=$(shell basename $(CURDIR)) | ||
DOCKERRUN=docker container run \ | ||
--name ${CONTAINER} \ | ||
--rm \ | ||
-t \ | ||
-v `pwd`:/app \ | ||
${CONTAINER}:${TAG} | ||
|
||
.PHONY: docker build install test update npm | ||
|
||
docker: | ||
docker build \ | ||
. \ | ||
-t ${CONTAINER}:${TAG} \ | ||
--build-arg TAG=${TAG} \ | ||
--no-cache | ||
build: docker install update | ||
${DOCKERRUN} \ | ||
run build | ||
install: docker | ||
${DOCKERRUN} \ | ||
install | ||
test: docker install | ||
${DOCKERRUN} \ | ||
run test | ||
update: docker | ||
${DOCKERRUN} \ | ||
update | ||
npm: docker | ||
${DOCKERRUN} \ | ||
$(filter-out $@,$(MAKECMDGOALS)) | ||
%: | ||
@: | ||
# ref: https://stackoverflow.com/questions/6273608/how-to-pass-argument-to-makefile-from-command-line |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "esnext", | ||
"moduleResolution": "node", | ||
"sourceMap": false, | ||
"strict": true, | ||
"noImplicitReturns": true, | ||
"noUnusedLocals": true, | ||
"newLine": "lf", | ||
"esModuleInterop": true | ||
}, | ||
"include": [ | ||
"../src" | ||
], | ||
"exclude": [ | ||
"../src/__tests__" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"extends": "./base", | ||
"compilerOptions": { | ||
"module": "commonjs", | ||
"outDir": "../dist/cjs" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"extends": "./base", | ||
"compilerOptions": { | ||
"module": "es6", | ||
"outDir": "../dist/esm" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"extends": "./base", | ||
"compilerOptions": { | ||
"declaration": true, | ||
"emitDeclarationOnly": true, | ||
"outDir": "../dist" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const path_1 = __importDefault(require("path")); | ||
const critical = require('critical'); | ||
const criticalSuffix = '_critical.min.css'; | ||
const defaultCriticalConfig = { | ||
inline: false, | ||
minify: true, | ||
extract: false, | ||
width: 1200, | ||
height: 1200, | ||
concurrency: 4, | ||
penthouse: { | ||
blockJSRequests: false | ||
} | ||
}; | ||
function PluginCritical(pluginConfig, callback) { | ||
return { | ||
name: 'critical', | ||
async writeBundle(outputOptions, bundle) { | ||
const css = []; | ||
// Find all of the generated CSS assets | ||
if (bundle) { | ||
for (const chunk of Object.values(bundle)) { | ||
if (chunk.type === 'asset' && chunk.fileName.endsWith('.css')) { | ||
if (outputOptions.dir !== undefined) { | ||
const cssFile = path_1.default.join(outputOptions.dir, chunk.fileName); | ||
css.push(cssFile); | ||
} | ||
} | ||
} | ||
// If we have no CSS, skip bundle | ||
if (!css.length) { | ||
return; | ||
} | ||
} | ||
// Iterate through the pages | ||
for (const page of pluginConfig.criticalPages) { | ||
const criticalBase = pluginConfig.criticalBase; | ||
const criticalSrc = pluginConfig.criticalUrl + page.uri; | ||
const criticalDest = page.template + criticalSuffix; | ||
// Merge in our options | ||
const options = Object.assign({ css }, defaultCriticalConfig, { | ||
base: criticalBase, | ||
src: criticalSrc, | ||
target: criticalDest, | ||
}, pluginConfig.criticalConfig); | ||
// Generate the Critical CSS | ||
console.log(`Generating critical CSS from ${criticalSrc} to ${criticalDest}`); | ||
await critical.generate(options, (err) => { | ||
if (err) { | ||
console.error(err); | ||
} | ||
if (callback) { | ||
callback(err); | ||
} | ||
}); | ||
} | ||
} | ||
}; | ||
} | ||
; | ||
exports.default = PluginCritical; |
Oops, something went wrong.