Merge pull request #246 from XhmikosR/patch-1

Minor tweaks.
This commit is contained in:
Ben Zörb 2019-08-09 23:26:04 +02:00 committed by GitHub
commit 438253c03b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 27 additions and 8 deletions

4
cli.js
View File

@ -1,5 +1,7 @@
#!/usr/bin/env node
'use strict';
const os = require('os');
const fs = require('fs');
const meow = require('meow');
@ -111,7 +113,7 @@ cli.flags = _.reduce(
);
function processError(err) {
process.stderr.write(chalk.red(indentString('Error: ' + (err.message || err), 2)));
process.stderr.write(chalk.red(indentString(`Error: ${err.message || err}`, 2)));
process.stderr.write(os.EOL);
process.stderr.write(indentString(help, 2));
process.exit(1);

View File

@ -8,7 +8,9 @@
* http://bezoerb.mit-license.org/
* All rights reserved.
*/
'use strict';
const fs = require('fs');
const path = require('path');
const isString = require('lodash/isString');
@ -103,6 +105,7 @@ function inline(html, styles, options) {
// eslint-disable-next-line array-callback-return
o.replaceStylesheets.map(href => {
const link = document.createElement('link');
link.setAttribute('rel', 'stylesheet');
link.setAttribute('href', href);
document.addNoscript(link);
@ -130,6 +133,7 @@ function inline(html, styles, options) {
if (o.extract) {
const href = link.getAttribute('href');
const file = path.resolve(path.join(o.basePath || process.cwd, href));
if (fs.existsSync(file)) {
const orig = fs.readFileSync(file);
const diff = extractCss(orig, inlined, o.minify);

View File

@ -1,3 +1,5 @@
'use strict';
const prettier = require('prettier');
const CleanCSS = require('clean-css');
const postcss = require('postcss');

View File

@ -1,3 +1,5 @@
'use strict';
const fs = require('fs');
const path = require('path');
const {JSDOM} = require('jsdom');
@ -14,8 +16,8 @@ const UglifyJS = require('uglify-js');
function getScript() {
const loadCssMain = resolve.sync('fg-loadcss');
const loadCssBase = path.dirname(loadCssMain);
const loadCSS = fs.readFileSync(path.join(loadCssBase, 'cssrelpreload.js'), 'utf8');
return UglifyJS.minify(loadCSS).code.trim();
}
@ -117,7 +119,7 @@ class Dom {
.join(`\n${textIndent}`);
const styles = this.document.createElement('style');
styles.append(this.document.createTextNode('\n' + textIndent + text + '\n' + referenceIndent));
styles.append(this.document.createTextNode(`\n${textIndent}${text}\n${referenceIndent}`));
return styles;
}
@ -162,14 +164,14 @@ class Dom {
insertStylesBefore(css, referenceNode) {
const styles = this.createStyleNode(css);
referenceNode.before(styles);
styles.after(this.document.createTextNode('\n' + this.headIndent.indent));
styles.after(this.document.createTextNode(`\n${this.headIndent.indent}`));
}
appendStyles(css, referenceNode) {
const styles = this.createStyleNode(css);
referenceNode.append(styles);
styles.before(this.document.createTextNode(this.headIndent.indent));
styles.after(this.document.createTextNode('\n' + this.headIndent.indent));
styles.after(this.document.createTextNode(`\n${this.headIndent.indent}`));
}
addNoscript(link) {
@ -180,12 +182,12 @@ class Dom {
insertBefore(node, referenceNode) {
referenceNode.before(node);
node.after(this.document.createTextNode('\n' + this.headIndent.indent));
node.after(this.document.createTextNode(`\n${this.headIndent.indent}`));
}
insertAfter(node, referenceNode) {
referenceNode.after(node);
referenceNode.after(this.document.createTextNode('\n' + this.headIndent.indent));
referenceNode.after(this.document.createTextNode(`\n${this.headIndent.indent}`));
}
remove(node) {
@ -220,7 +222,7 @@ class Dom {
if (scriptAnchor) {
scriptAnchor.after(script);
scriptAnchor.after(this.document.createTextNode('\n' + this.headIndent.indent));
scriptAnchor.after(this.document.createTextNode(`\n${this.headIndent.indent}`));
}
}
}

View File

@ -1,4 +1,7 @@
/* eslint-env jest */
'use strict';
const path = require('path');
const readPkgUp = require('read-pkg-up');
const {read, strip, run, getArgs, pipe} = require('./helper');

View File

@ -1,4 +1,7 @@
/* eslint-env jest */
'use strict';
const path = require('path');
const fs = require('fs-extra');
const readPkgUp = require('read-pkg-up');

View File

@ -1,4 +1,7 @@
/* eslint-env jest */
'use strict';
const path = require('path');
const reaver = require('reaver');
const {extractCss} = require('../src/css.js');