electron-userland / electron-prebuilt-compile

electron-prebuilt with Babel and React built-in
167 stars 50 forks source link

How to use for package.json bin script? #63

Closed philipptrenz closed 6 years ago

philipptrenz commented 6 years ago

Hey there,

I want to ship electron-prebuilt-compile within my npm package and define how to start from cli with node. What I'm searching for is something similar to this cli.js file:

#!/usr/bin/env node

var spawn = require('child_process').spawn
var electron = require('electron-prebuilt')
var join = require('path').join

var app = spawn(electron, ['main.js'], { 
  stdio: 'inherit',
  cwd: join(__dirname) 
}).on('exit', function (i, m) {
  process.exit()
})

so I can define in my package.json

"bin": {
    "my-startup-command": "./cli.js"
  },

I tried to just swap electron-prebuilt to electron-prebuilt-compile but it results in the following error:

child_process.js:360
    throw new TypeError('"file" argument must be a non-empty string');
    ^

TypeError: "file" argument must be a non-empty string
    at normalizeSpawnArguments (child_process.js:360:11)
    at exports.spawn (child_process.js:465:38)
    at Object.<anonymous> (/Users/philipp/git/photo-booth/cli.js:7:11)
    at Module._compile (module.js:569:30)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:503:32)
    at tryModuleLoad (module.js:466:12)
    at Function.Module._load (module.js:458:3)
    at Function.Module.runMain (module.js:605:10)
    at startup (bootstrap_node.js:158:16)

Any suggestions? Thanks!

philipptrenz commented 6 years ago

Found a solution:

#!/usr/bin/env node

var spawn = require('child_process').spawn
var join = require('path').join

var app = spawn('npm', ['start'], { 
  stdio: 'inherit',
  cwd: join(__dirname, '..') 
}).on('exit', function (i, m) {
  process.exit()
})