2017-01-05 10 views
0

私はElectron Frameworkを初めて使いました。自分のカスタムconfig.jsonをプロジェクトルートに追加し、ファイルにアクセスします。main.js私はNPM開始を使用してプロジェクトを実行しますが、私は電子ビルダーを使用してexeファイルを作成するとき、私はエラーメッセージを取得するときにこのファイルが正常にロードされている: - :電子:私のカスタムconfig.jsonがロードされていません

- ここ

Uncaught Error: ENOENT: no such file or directory, open 'C:\Users\Rohaan Ishfaq\AppData\Local\Programs\examsoft_V0.20\config.json 

をmain.jsファイルであります

// Module for creating child processes 
const spawn = require('child_process').spawn; 
// Module for path manipulations 
const path = require('path'); 
// Module to create calls between windows 
const ipc = require('electron').ipcRenderer; 
// Module jQuery 
const $ = require('jquery'); 
// Module for file manipulations 
const fs = require('fs'); 
// config json 
const config = JSON.parse(fs.readFileSync('config.json', 'utf-8')); 

(function main() { 

    init(); 
    events(); 

    function init() { 
     createSSHKey(); 
    } 

    function events() { 

     // get login btn by id 
     const loginBtn = $('#login'); 
     // register event listener 
     loginBtn.click(function (event) { 
      ipc.send('change-to-login'); 
     }); 
    } 

    function createSSHKey() { 
     if(!fs.existsSync(config.utilsPath)) 
      alert(config.utilsPath + ' doesn\'t exist'); 
     else { 
      var sshKeyPath = path.normalize(config.sshKeygenPath); 
      //trigger .bat file 
      ls = spawn('cmd.exe', ['/c', sshKeyPath]); 

      //on data 
      ls.stdout.on('data', function (data) { 
       console.log('stdout: ' + data); 
      }); 

      //on error 
      ls.stderr.on('data', function (data) { 
       alert('Error Occured: '+ data); 
       process.exit(1); 
      }); 

      //on exit 
      ls.on('exit', function (code) { 
       alert('SSH key pair has been created successfully. Check '+config.usersPath+process.env.USERNAME+config.sshDirectoryPath+' directory'); 
       enableLogin(); 
      }); 
     } 
    } 

    function enableLogin() { 
     $('#login').text('Start'); 
     $('#login').prop('disabled', false); 
    } 

})(); 

このような問題に直面して問題を解決した人は誰ですか?

答えて

0

あなたのアプリはasarアーカイブに入っているので、ファイルに直接アクセスするには、extraFilesオプションを設定してください。

+0

extraFilesオプションの使用例を教えてください。例えば、 – Ronio

+0

。 '' extraResources ":" **/config.json "、' 'ビルド'(https://github.com/Quacky2200/Spotify-Web-Player-for-Linux/blob/master/package.json#L18 )。 – develar

関連する問題