Skip to content

Commit

Permalink
adding environment variable to be check to prevent electron from inst…
Browse files Browse the repository at this point in the history
…alling (#4)
  • Loading branch information
obecny authored Dec 5, 2017
1 parent 183f773 commit 00b3da0
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 42 deletions.
29 changes: 29 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# IntelliJ project files
.idea
*.iml
out
gen### Node template
# Logs
logs
*.log
npm-debug.log*

# Runtime data
pids
*.pid
*.seed

# Dependency directories
node_modules
jspm_packages

# Optional npm cache directory
.npm

# Optional REPL history
.node_repl_history

.DS_Store
temp/
/build/
build
12 changes: 6 additions & 6 deletions cli.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/usr/bin/env node

var electron = require('./')
var electron = require("./");

var proc = require('child_process')
var proc = require("child_process");

var child = proc.spawn(electron, process.argv.slice(2), {stdio: 'inherit'})
child.on('close', function (code) {
process.exit(code)
})
var child = proc.spawn(electron, process.argv.slice(2), {stdio: "inherit"});
child.on("close", function (code) {
process.exit(code);
});
10 changes: 5 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
var fs = require('fs')
var path = require('path')
var fs = require("fs");
var path = require("path");

var pathFile = path.join(__dirname, 'path.txt')
var pathFile = path.join(__dirname, "path.txt");

if (fs.existsSync(pathFile)) {
module.exports = path.join(__dirname, fs.readFileSync(pathFile, 'utf-8'))
module.exports = path.join(__dirname, fs.readFileSync(pathFile, "utf-8"));
} else {
throw new Error('Electron failed to install correctly, please delete node_modules/electron and try installing again')
throw new Error("Electron failed to install correctly, please delete node_modules/electron and try installing again");
}
72 changes: 41 additions & 31 deletions install.js
Original file line number Diff line number Diff line change
@@ -1,65 +1,75 @@
#!/usr/bin/env node

// maintainer note - x.y.z-ab version in package.json -> x.y.z
var version = require('./package').version
var version = require("./package").version;

var fs = require('fs')
var os = require('os')
var path = require('path')
var extract = require('extract-zip')
var download = require('electron-download')
var fs = require("fs");
var os = require("os");
var path = require("path");
var extract = require("extract-zip");
var download = require("electron-download");

var installedVersion = null
var installedVersion = null;
try {
installedVersion = fs.readFileSync(path.join(__dirname, 'dist', 'version'), 'utf-8').replace(/^v/, '')
installedVersion = fs.readFileSync(path.join(__dirname, "dist", "version"), "utf-8").replace(/^v/, "");
} catch (ignored) {
// do nothing
}

var platformPath = getPlatformPath()
if (process.env.DONT_INSTALL_ELECTRON == "1") {
process.exit(0);
}

var platformPath = getPlatformPath();

if (installedVersion === version && fs.existsSync(path.join(__dirname, platformPath))) {
process.exit(0)
process.exit(0);
}

// downloads if not cached
download({
mirror: 'https://github.com/castlabs/electron-releases/releases/download/v',
mirror: "https://github.com/castlabs/electron-releases/releases/download/v",
cache: process.env.electron_config_cache,
version: version,
platform: process.env.npm_config_platform,
arch: process.env.npm_config_arch,
strictSSL: process.env.npm_config_strict_ssl === 'true',
force: process.env.force_no_cache === 'true',
quiet: ['info', 'verbose', 'silly', 'http'].indexOf(process.env.npm_config_loglevel) === -1
}, extractFile)
strictSSL: process.env.npm_config_strict_ssl === "true",
force: process.env.force_no_cache === "true",
quiet: ["info", "verbose", "silly", "http"].indexOf(process.env.npm_config_loglevel) === -1
}, extractFile);

// unzips and makes path.txt point at the correct executable
function extractFile (err, zipPath) {
if (err) return onerror(err)
extract(zipPath, {dir: path.join(__dirname, 'dist')}, function (err) {
if (err) return onerror(err)
fs.writeFile(path.join(__dirname, 'path.txt'), platformPath, function (err) {
if (err) return onerror(err)
})
})
if (err) {
return onerror(err);
}
extract(zipPath, {dir: path.join(__dirname, "dist")}, function (err) {
if (err) {
return onerror(err);
}
fs.writeFile(path.join(__dirname, "path.txt"), platformPath, function (err) {
if (err) {
return onerror(err);
}
});
});
}

function onerror (err) {
throw err
throw err;
}

function getPlatformPath () {
var platform = process.env.npm_config_platform || os.platform()
var platform = process.env.npm_config_platform || os.platform();

switch (platform) {
case 'darwin':
return 'dist/Electron.app/Contents/MacOS/Electron'
case 'freebsd':
case 'linux':
return 'dist/electron'
case 'win32':
return 'dist/electron.exe'
case "darwin":
return "dist/Electron.app/Contents/MacOS/Electron";
case "freebsd":
case "linux":
return "dist/electron";
case "win32":
return "dist/electron.exe";
default:
throw new Error('Electron builds are not available on platform: ' + platform)
}
Expand Down

0 comments on commit 00b3da0

Please sign in to comment.