UNPKG

electron-forge

Version:

A complete tool for building modern Electron applications

228 lines (227 loc) 9.05 kB
<!doctype html> <html lang="en"> <head> <title>Code coverage report for installers/darwin/zip.js</title> <meta charset="utf-8" /> <link rel="stylesheet" href="../../prettify.css" /> <link rel="stylesheet" href="../../base.css" /> <meta name="viewport" content="width=device-width, initial-scale=1"> <style type='text/css'> .coverage-summary .sorter { background-image: url(../../sort-arrow-sprite.png); } </style> </head> <body> <div class='wrapper'> <div class='pad1'> <h1> <a href="../../index.html">All files</a> / <a href="index.html">installers/darwin</a> zip.js </h1> <div class='clearfix'> <div class='fl pad1y space-right2'> <span class="strong">0% </span> <span class="quiet">Statements</span> <span class='fraction'>0/27</span> </div> <div class='fl pad1y space-right2'> <span class="strong">0% </span> <span class="quiet">Branches</span> <span class='fraction'>0/6</span> </div> <div class='fl pad1y space-right2'> <span class="strong">0% </span> <span class="quiet">Functions</span> <span class='fraction'>0/8</span> </div> <div class='fl pad1y space-right2'> <span class="strong">0% </span> <span class="quiet">Lines</span> <span class='fraction'>0/25</span> </div> </div> </div> <div class='status-line low'></div> <pre><table class="coverage"> <tr><td class="line-count quiet">1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55</td><td class="line-coverage quiet"><span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-no">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span></td><td class="text"><pre class="prettyprint lang-js">import fs from 'fs-promise'; import inquirer from 'inquirer'; import path from 'path'; import pify from 'pify'; import sudo from 'sudo-prompt'; import { exec, spawn } from 'child_process'; &nbsp; export default <span class="fstat-no" title="function not covered" >as</span>ync (filePath, installSpinner) =&gt; { <span class="cstat-no" title="statement not covered" > await new Promise(<span class="fstat-no" title="function not covered" >(r</span>esolve) =&gt; {</span> const child = <span class="cstat-no" title="statement not covered" >spawn('unzip', ['-q', '-o', path.basename(filePath)], {</span> cwd: path.dirname(filePath), }); <span class="cstat-no" title="statement not covered" > child.stdout.on('data', <span class="fstat-no" title="function not covered" >()</span> =&gt; {});</span> <span class="cstat-no" title="statement not covered" > child.stderr.on('data', <span class="fstat-no" title="function not covered" >()</span> =&gt; {});</span> <span class="cstat-no" title="statement not covered" > child.on('exit', <span class="fstat-no" title="function not covered" >()</span> =&gt; <span class="cstat-no" title="statement not covered" >resolve())</span>;</span> }); let writeAccess = <span class="cstat-no" title="statement not covered" >true;</span> <span class="cstat-no" title="statement not covered" > try {</span> <span class="cstat-no" title="statement not covered" > await fs.access('/Applications', fs.W_OK);</span> } catch (err) { <span class="cstat-no" title="statement not covered" > writeAccess = false;</span> } const appPath = <span class="cstat-no" title="statement not covered" >(await fs.readdir(path.dirname(filePath))).filter(<span class="fstat-no" title="function not covered" >fi</span>le =&gt; <span class="cstat-no" title="statement not covered" >file.endsWith('.app'))</span></span> .map(<span class="fstat-no" title="function not covered" >fi</span>le =&gt; <span class="cstat-no" title="statement not covered" >path.resolve(path.dirname(filePath), file))</span> .sort(<span class="fstat-no" title="function not covered" >(f</span>A, fB) =&gt; <span class="cstat-no" title="statement not covered" >fs.statSync(fA).ctime.getTime() - fs.statSync(fB).ctime.getTime())</span>[0]; &nbsp; const targetApplicationPath = <span class="cstat-no" title="statement not covered" >`/Applications/${path.basename(appPath)}`;</span> <span class="cstat-no" title="statement not covered" > if (await fs.exists(targetApplicationPath)) {</span> <span class="cstat-no" title="statement not covered" > installSpinner.stop();</span> const { confirm } = <span class="cstat-no" title="statement not covered" >await inquirer.createPromptModule()({</span> type: 'confirm', name: 'confirm', message: `The application "${path.basename(targetApplicationPath)}" appears to already exist in /Applications. Do you want to replace it?`, }); <span class="cstat-no" title="statement not covered" > if (!confirm) {</span> // eslint-disable-next-line no-throw-literal <span class="cstat-no" title="statement not covered" > throw 'Installation stopped by user';</span> } else { <span class="cstat-no" title="statement not covered" > installSpinner.start();</span> <span class="cstat-no" title="statement not covered" > await fs.remove(targetApplicationPath);</span> } } &nbsp; const moveCommand = <span class="cstat-no" title="statement not covered" >`mv "${appPath}" "${targetApplicationPath}"`;</span> <span class="cstat-no" title="statement not covered" > if (writeAccess) {</span> <span class="cstat-no" title="statement not covered" > await pify(exec)(moveCommand);</span> } else { <span class="cstat-no" title="statement not covered" > await pify(sudo.exec)(moveCommand, {</span> name: 'Electron Forge', }); } &nbsp; <span class="cstat-no" title="statement not covered" > spawn('open', ['-R', targetApplicationPath], { detached: true });</span> }; &nbsp;</pre></td></tr> </table></pre> <div class='push'></div><!-- for sticky footer --> </div><!-- /wrapper --> <div class='footer quiet pad2 space-top1 center small'> Code coverage generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Sun Jan 15 2017 16:57:41 GMT+1100 (AEDT) </div> </div> <script src="../../prettify.js"></script> <script> window.onload = function () { if (typeof prettyPrint === 'function') { prettyPrint(); } }; </script> <script src="../../sorter.js"></script> </body> </html>