diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..25c8fdb --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +node_modules +package-lock.json \ No newline at end of file diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..e6175ef --- /dev/null +++ b/.travis.yml @@ -0,0 +1,4 @@ +language: node_js +node_js: + - '8' + - '10' diff --git a/license b/license new file mode 100644 index 0000000..d81d966 --- /dev/null +++ b/license @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2019 Bart Veneman + +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. \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..4f5650d --- /dev/null +++ b/package.json @@ -0,0 +1,37 @@ +{ + "name": "distill-css", + "description": "PACKAGE_DESCRIPTION", + "version": "0.1.0", + "homepage": "https://www.projectwallace.com/oss", + "repository": "PACKAGE_REPOSITORY", + "issues": "PACKAGE_ISSUES", + "license": "MIT", + "author": "Bart Veneman", + "keywords": [ + "PACKAGE_KEYWORD" + ], + "scripts": { + "test": "xo && ava test" + }, + "files": [ + "src" + ], + "main": "src/index.js", + "engines": { + "node": ">=8.0" + }, + "xo": { + "prettier": true + }, + "devDependencies": { + "ava": "^1.3.1", + "chromium": "^2.1.0", + "create-test-server": "^2.4.0", + "prettier": "^1.16.4", + "puppeteer-core": "^1.13.0", + "xo": "^0.24.0" + }, + "dependencies": { + "puppeteer": "^1.13.0" + } +} diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..f4ecfd1 --- /dev/null +++ b/readme.md @@ -0,0 +1,94 @@ +
+

extract-css-core

+

Extract all CSS from a given url, both server side and client side rendered.

+
+ +[![NPM Version](https://img.shields.io/npm/v/extract-css-core.svg)](https://www.npmjs.com/package/extract-css-core) +[![Build Status](https://travis-ci.org/bartveneman/extract-css-core.svg?branch=master)](https://travis-ci.org/bartveneman/extract-css-core) +[![Known Vulnerabilities](https://snyk.io/test/github/bartveneman/extract-css-core/badge.svg)](https://snyk.io/test/github/bartveneman/extract-css-core) +[![Weekly downloads](https://img.shields.io/npm/dw/extract-css-core.svg)](https://www.npmjs.com/package/extract-css-core) +![Dependencies Status](https://img.shields.io/david/bartveneman/extract-css-core.svg) +![Dependencies Status](https://img.shields.io/david/dev/bartveneman/extract-css-core.svg) +[![XO code style](https://img.shields.io/badge/code_style-XO-5ed9c7.svg)](https://github.com/sindresorhus/xo) +[![Project: Wallace](https://img.shields.io/badge/Project-Wallace-29c87d.svg)](https://www.projectwallace.com/oss) + +## Problem, solution and shortcomings + +### Problem + +Existing packages like [get-css](https://github.com/cssstats/cssstats/tree/master/packages/get-css) look at a server-generated piece of HTML and get all the `` and ` + + + +
+ + + + + + + + diff --git a/test/fixture.css b/test/fixture.css new file mode 100644 index 0000000..b82e370 --- /dev/null +++ b/test/fixture.css @@ -0,0 +1,3 @@ +body { + color: teal; +} diff --git a/test/index.js b/test/index.js new file mode 100644 index 0000000..752bff2 --- /dev/null +++ b/test/index.js @@ -0,0 +1,154 @@ +const test = require("ava"); +const createTestServer = require("create-test-server"); +const { readFileSync } = require("fs"); +const { resolve } = require("path"); +const extractCss = require(".."); + +let server; +const expected = readFileSync(resolve(__dirname, "fixture.css"), "utf8"); + +test.before(async () => { + server = await createTestServer(); + + server.get("/fixture.css", (req, res) => { + res.send(expected); + }); +}); + +test.after(async () => { + await server.close(); +}); + +test("it fetches css from a page with CSS in a server generated inside the ", async t => { + const url = "/server-link-head"; + server.get(url, (req, res) => { + res.send(` + + + + + + + `); + }); + + const actual = await extractCss(server.url + url); + + t.is(actual, expected); +}); + +test("it fetches css from a page with CSS in server generated + + + `); + }); + + const actual = await extractCss(server.url + url); + + t.is(actual, expected.trim()); +}); + +test("it finds JS generated CSS", async t => { + const path = "/js-generated-link"; + const cssInJsExampleHtml = readFileSync( + resolve(__dirname, "js-create-link-element.html"), + "utf8" + ); + + server.get(path, (req, res) => { + res.send(cssInJsExampleHtml); + }); + + const actual = await extractCss(server.url + path); + + t.is(actual, expected); +}); + +test("it finds JS generated + + +

Title

+ + + + diff --git a/test/snapshots/index.js.md b/test/snapshots/index.js.md new file mode 100644 index 0000000..14c1072 --- /dev/null +++ b/test/snapshots/index.js.md @@ -0,0 +1,33 @@ +# Snapshot report for `test/index.js` + +The actual snapshot is saved in `index.js.snap`. + +Generated by [AVA](https://ava.li). + +## it combines server generated and