pkg icon indicating copy to clipboard operation
pkg copied to clipboard

Packaging up penthouse

Open wdavis opened this issue 9 years ago • 0 comments

I have a package that creates critical css for a website provided within a config like so:

node app.js --cfg config.json

Running it un-pkg'd works great and I can successfully pkg the app (after a fix for svgo and including the phantomjs binaries in the same dir).

But, if I run the compiled pkg, I get this output:

./criticalcss-macos --cfg config.json

Unhandled rejection Error: Unable to open config: "/snapshot/critical/node_modules/penthouse/lib/phantomjs/config.json"
Can't open '/snapshot/critical/node_modules/penthouse/lib/phantomjs/core.js'

    at ChildProcess.<anonymous> (/snapshot/critical/node_modules/penthouse/lib/index.js:295:29)
    at emitTwo (events.js:125:13)
    at ChildProcess.emit (events.js:213:7)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:197:12)

Unhandled rejection Error: Unable to open config: "/snapshot/critical/node_modules/penthouse/lib/phantomjs/config.json"
Can't open '/snapshot/critical/node_modules/penthouse/lib/phantomjs/core.js'

    at ChildProcess.<anonymous> (/snapshot/critical/node_modules/penthouse/lib/index.js:295:29)
    at emitTwo (events.js:125:13)
    at ChildProcess.emit (events.js:213:7)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:197:12)

I can confirm that the /snapshot/critical/node_modules/penthouse/lib/phantomjs/config.json and /snapshot/critical/node_modules/penthouse/lib/phantomjs/core.js files do exist within the pkg'd application, but for some reason penthouse is having trouble with them.

Any ideas on why /snapshot/critical/node_modules/penthouse/lib/phantomjs/config.json and /snapshot/critical/node_modules/penthouse/lib/phantomjs/core.js are not able to be opened after pkg'ing the app?


package.json:

{
	"name": "criticalcss",
	"bin": "app.js",
	"pkg": {
		"assets": [
			"node_modules/svgo/.svgo.yml"
		],
		"scripts": [
			"node_modules/svgo/plugins/*"
		]
	},
	"dependencies": {
		"critical": "^0.9.1",
		"minimist": "^1.2.0",
		"unirest": "^0.5.1"
	}
}

config.json (passed as a parameter to the app)

{
	"root": "/path/to/website/root",
	"domain": "http://mywebsite.dev",
	"uris": [
		"/",
		"/services"
	],
	"css": [
		"/css/base.css"
	]
}

app.js

'use strict';

const critical = require('critical');

const unirest = require('unirest');
const path = require('path');

let argv = require('minimist')(process.argv.slice(2));

var config = JSON.parse(require('fs').readFileSync(argv.cfg, 'utf8'));

config.css = config.css.map(function(css)
{
	return config.root+css;
});

config.uris.forEach(function(uri)
{
	var request = unirest.get(config.domain+uri);
	request.headers({
		'User-Agent': 'Critical v0.1'
	});

	request.send().end(function(response)
	{
		var filteredUri = 'critical-base';
		if(uri !== '/')
		{
			filteredUri = 'critical-'+uri.replace('/', '');
		}

		critical.generate({
		    inline: false,
		    folder: config.root,
		    html: response.body,
		    dest: config.root+'/'+filteredUri+'.php',
		    css: config.css,
		    width: 1300,
		    height: 900,
		    minify: true
		});
	});
});

wdavis avatar Sep 08 '17 15:09 wdavis