Skip to content

Commit

Permalink
Merge pull request #246 from XhmikosR/patch-1
Browse files Browse the repository at this point in the history
Minor tweaks.
  • Loading branch information
bezoerb committed Aug 9, 2019
2 parents dbe6a3a + 2d529d3 commit 438253c
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 8 deletions.
4 changes: 3 additions & 1 deletion cli.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env node

'use strict';

const os = require('os');
const fs = require('fs');
const meow = require('meow');
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/css.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

const prettier = require('prettier');
const CleanCSS = require('clean-css');
const postcss = require('postcss');
Expand Down
16 changes: 9 additions & 7 deletions src/dom.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

const fs = require('fs');
const path = require('path');
const {JSDOM} = require('jsdom');
Expand All @@ -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();
}

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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}`));
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions test/cli.test.js
Original file line number Diff line number Diff line change
@@ -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');
Expand Down
3 changes: 3 additions & 0 deletions test/helper/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
/* eslint-env jest */

'use strict';

const path = require('path');
const fs = require('fs-extra');
const readPkgUp = require('read-pkg-up');
Expand Down
3 changes: 3 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
/* eslint-env jest */

'use strict';

const path = require('path');
const reaver = require('reaver');
const {extractCss} = require('../src/css.js');
Expand Down

0 comments on commit 438253c

Please sign in to comment.