电子打包命令行应用程序

时间:2019-09-14 12:03:17

标签: node.js terminal electron command-line-interface electron-packager

我目前正在尝试打包节点应用程序index.js并从终端运行它,例如

./test testit

我的设置

index.js:

const commander = require('commander')

commander
    .command('testit')
    .action(function(args) {
        console.log('success')
    })

commander.parse(process.argv)

package.json:

{
  "name": "test",
  "version": "1.0.0",
  "description": "Test",
  "main": "index.js",
  "dependencies": {
    "commander": "^3.0.1"
  },
  "author": "",
  "license": "MIT",
  "devDependencies": {
    "electron": "^6.0.9",
    "electron-packager": "^14.0.6"
  }
}

我不需要图形用户界面的东西,我只希望它从终端开始。

我成功打包了我的应用程序:

"electron-packager . --platform=darwin --arch=x64 --app-version=1.0.0 --out=builds

但是当我从终端执行它时,它以某种方式卡住了并且不会返回。.此外,电子图标出现在边栏中,我不想发生...我只想从cli运行它

当我单击电子图标时,它显示一个对话框,其中包含:

Uncaught Exception:
TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type undefined
    at validateString (internal/validators.js:107:11)
    at basename (path.js:1149:5)
    at Command.parse (path/to/dir/test/release-builds/test-darwin-x64/test.app/Contents/Resources/app/node_modules/commander/index.js:446:30)
    at Object.<anonymous> (path/to/dir/test/release-builds/test-darwin-x64/test.app/Contents/Resources/app/index.js:9:11)
    at Module._compile (internal/modules/cjs/loader.js:786:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:798:10)
    at Module.load (internal/modules/cjs/loader.js:645:32)
    at Function.Module._load (internal/modules/cjs/loader.js:560:12)
    at Object.<anonymous> (path/to/dir/test/release-builds/test-darwin-x64/test.app/Contents/Resources/electron.asar/browser/init.js:181:12)
    at Module._compile (internal/modules/cjs/loader.js:786:30)

关于如何仅打包我的应用以便在cli中执行的任何想法?

感谢和问候!

0 个答案:

没有答案