Skip to content

Commit

Permalink
same penthouse.js
Browse files Browse the repository at this point in the history
  • Loading branch information
pocketjoso committed Jun 11, 2014
1 parent a968ba5 commit 0ec80a4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/index.js
Expand Up @@ -7,7 +7,7 @@ var spawn = require('child_process').spawn;
var phantomjs = require('phantomjs');
var phantomJsBinPath = phantomjs.path;
var configString = ('--config=' + path.join(__dirname, 'phantomjs', 'config.json'));
var script = path.join(__dirname, 'phantomjs', 'script.js');
var script = path.join(__dirname, 'phantomjs', 'penthouse.js');

module.exports = function (options, callback) {
var scriptArgs = [options.url, options.css, options.width, options.height],
Expand Down
20 changes: 16 additions & 4 deletions lib/phantomjs/script.js → lib/phantomjs/penthouse.js
Expand Up @@ -2,6 +2,18 @@
// https://github.com/pocketjoso/penthouse
// Author: Jonas Ohlsson
// License: MIT
// Version 0.2.0

// USAGE (when run standalone):
// phantomjs penthouse.js [URL to page] [CSS file] > [critical path CSS file]

// to run on HTTPS sites two flags must be passed in, directly after phantomjs in the call:
// --ignore-ssl-errors=true --ssl-protocol=tlsv1

// optional parameters: [WIDTH], [HEIGHT] - must follow [CSS file] param in this order. Defaults to 1300, 900.

// DEPENDENCIES
// + "phantomjs" : "~1.9.7"

'use strict';

Expand Down Expand Up @@ -48,15 +60,15 @@ var parseArguments = function () {
var options = {};

//url needs to be passed in
if (system.args.length < 5) {
log('Usage: penthouse <some URL> <path to css file> <width> <height>');
if (system.args.length < 3) {
log('Usage: penthouse <some URL> <path to css file>');

This comment has been minimized.

Copy link
@pocketjoso

pocketjoso Jun 11, 2014

Author Owner

(I pushed the width and height to be optional from within the script, so also for standalone calls) My note here is not on this change, but on the merge of this file and the base dir penthouse.js:
This feedback is incorrect for when called standalone... Makes me wonder if we have to use two different files. Can we somehow know from inside here whether the script was called via Node or not? We would have to pass in an extra argument... which wouldn't really scale well. Any ideas?

This comment has been minimized.

Copy link
@fatso83

fatso83 Jun 11, 2014

Collaborator

I just wrote you an email explaining how a Makefile could be suitable for exactly something like this. Funny coincidence :) This is basically what I would create:

  • one common base script that knows nothing about this special logic
  • one additional script containing logic for dealing with user feedback
  • a build script / Makefile with a "standalone" task that simply appended the additional script to the start of the first. Would basically look something like this
install: 
        npm install

test: install
        npm test

standalone:
        cat lib/phantomjs/core.js lib/phantomjs/commandline.js  > ./penthouse.js

.PHONY: standalone

Then whenever you have made some changes to the core logic, you just run make and it builds your standalone version.

This comment has been minimized.

Copy link
@pocketjoso

pocketjoso via email Jun 11, 2014

Author Owner

This comment has been minimized.

Copy link
@fatso83

fatso83 via email Jun 11, 2014

Collaborator

This comment has been minimized.

Copy link
@pocketjoso

pocketjoso via email Jun 11, 2014

Author Owner
phantom.exit(1);
}

options.url = system.args[1];
options.cssFilePath = system.args[2];
options.width = system.args[3];
options.height = system.args[4];
options.width = system.args[3] || 1300;
options.height = system.args[4] || 900;

return options;
};
Expand Down
3 changes: 2 additions & 1 deletion penthouse.js
Expand Up @@ -2,8 +2,9 @@
// https://github.com/pocketjoso/penthouse
// Author: Jonas Ohlsson
// License: MIT
// Version 0.2.0

// USAGE:
// USAGE (when run standalone):
// phantomjs penthouse.js [URL to page] [CSS file] > [critical path CSS file]

// to run on HTTPS sites two flags must be passed in, directly after phantomjs in the call:
Expand Down

0 comments on commit 0ec80a4

Please sign in to comment.