Skip to content

Commit

Permalink
fixes attached NodeJS cannot be found in Linux and MAc
Browse files Browse the repository at this point in the history
  • Loading branch information
andy-portmen committed Jul 23, 2017
1 parent 06e7ba5 commit 2fdd96a
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 57 deletions.
2 changes: 1 addition & 1 deletion host.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var files = [];
var sprocess = [];

var config = {
version: '0.4.0'
version: '0.4.1'
};
// closing node when parent process is killed
process.stdin.resume();
Expand Down
6 changes: 3 additions & 3 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ if [ $? -eq 0 ]; then
fi
if [ $? -eq 0 ]; then
echo "Installer is using your system NodeJS."
node install.js `which node` $1
node install.js `which node`
else
MACHINE_TYPE=`uname -m`
echo "Installer is using the attached NodeJS"
if [ ${MACHINE_TYPE} == 'x86_64' ]; then
../node/x64/node install.js --add_node $1
../node/x64/node install.js --add_node
else
../node/x86/node install.js --add_node $1
../node/x86/node install.js --add_nodes
fi
fi
58 changes: 29 additions & 29 deletions linux/app/install.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* globals require, process */
'use strict';

var fs = require('fs');
Expand All @@ -10,17 +11,17 @@ if (share[0] === '~') {
share = path.resolve(share);
console.log(' -> Root directory is', share);

function exists (directory, callback) {
function exists(directory, callback) {
let root = '/';
let dirs = directory.split('/');
function one () {
const dirs = directory.split('/');
function one() {
root = path.join(root, dirs.shift());
fs.stat(root, (e) => {
fs.stat(root, e => {
if (!e && dirs.length) {
one();
}
else if (e && e.code === 'ENOENT') {
fs.mkdir(root, (e) => {
fs.mkdir(root, e => {
if (e) {
callback(e);
}
Expand All @@ -44,9 +45,9 @@ var dir = path.join(share, 'com.add0n.node');
var name = 'com.add0n.node';
var ids = require('./config.js').ids;

function manifest (root, type, callback) {
function manifest(root, type, callback) {
console.log(' -> Creating a directory at', root);
exists(root, (e) => {
exists(root, e => {
if (e) {
throw e;
}
Expand All @@ -63,34 +64,33 @@ function manifest (root, type, callback) {
"path": "${path.join(dir, 'run.sh')}",
"type": "stdio",
${origins}
}`, (e) => {
if (e) {
throw e;
}
callback();
});

}`, e => {
if (e) {
throw e;
}
callback();
});
});
}
function application (callback) {
function application(callback) {
console.log(' -> Creating a directory at', dir);
exists(dir, (e) => {
exists(dir, e => {
if (e) {
console.log('\x1b[31m', `-> You dont have permission to use "${share}" directory.` ,'\x1b[0m');
console.log('\x1b[31m', '-> Use custom directory instead. Example:' ,'\x1b[0m');
console.log('\x1b[31m', '-> ./install.sh --custom-dir=~/' ,'\x1b[0m');
console.log('\x1b[31m', `-> You dont have permission to use "${share}" directory.`, '\x1b[0m');
console.log('\x1b[31m', '-> Use custom directory instead. Example:', '\x1b[0m');
console.log('\x1b[31m', '-> ./install.sh --custom-dir=~/', '\x1b[0m');

throw e;
}
let isNode = process.argv.filter(a => a === '--add_node').length === 0;
let run = isNode ? `#!/bin/bash\n${process.argv[2]} host.js` : '#!/bin/bash\n./node host.js';
fs.writeFile(path.join(dir, 'run.sh'), run, (e) => {
const isNode = process.argv.filter(a => a === '--add_node').length === 0;
const run = `#!/bin/bash\n${process.argv[0]} host.js`;
fs.writeFile(path.join(dir, 'run.sh'), run, e => {
if (e) {
throw e;
}
fs.chmodSync(path.join(dir, 'run.sh'), '0755');
if (!isNode) {
fs.createReadStream('../node').pipe(fs.createWriteStream(path.join(dir, 'node')));
fs.createReadStream(process.argv[0]).pipe(fs.createWriteStream(path.join(dir, 'node')));
fs.chmodSync(path.join(dir, 'node'), '0755');
}
fs.createReadStream('host.js').pipe(fs.createWriteStream(path.join(dir, 'host.js')));
Expand All @@ -100,9 +100,9 @@ function application (callback) {
});
});
}
function chrome (callback) {
function chrome(callback) {
if (ids.chrome.length) {
let loc = path.join(
const loc = path.join(
process.env.HOME,
'.config/google-chrome/NativeMessagingHosts'
);
Expand All @@ -113,9 +113,9 @@ function chrome (callback) {
callback();
}
}
function chromium (callback) {
function chromium(callback) {
if (ids.chrome.length) {
let loc = path.join(
const loc = path.join(
process.env.HOME,
'.config/chromium/NativeMessagingHosts'
);
Expand All @@ -126,9 +126,9 @@ function chromium (callback) {
callback();
}
}
function firefox (callback) {
function firefox(callback) {
if (ids.firefox.length) {
let loc = path.join(
const loc = path.join(
process.env.HOME,
'.mozilla/native-messaging-hosts'
);
Expand Down
49 changes: 25 additions & 24 deletions mac/app/install.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* globals require, process */
'use strict';

var fs = require('fs');
Expand All @@ -10,17 +11,17 @@ if (share[0] === '~') {
share = path.resolve(share);
console.log(' -> Root directory is', share);

function exists (directory, callback) {
function exists(directory, callback) {
let root = '/';
let dirs = directory.split('/');
function one () {
const dirs = directory.split('/');
function one() {
root = path.join(root, dirs.shift());
fs.stat(root, (e) => {
fs.stat(root, e => {
if (!e && dirs.length) {
one();
}
else if (e && e.code === 'ENOENT') {
fs.mkdir(root, (e) => {
fs.mkdir(root, e => {
if (e) {
callback(e);
}
Expand All @@ -44,9 +45,9 @@ var dir = path.join(share, 'com.add0n.node');
var name = 'com.add0n.node';
var ids = require('./config.js').ids;

function manifest (root, type, callback) {
function manifest(root, type, callback) {
console.log(' -> Creating a directory at', root);
exists(root, (e) => {
exists(root, e => {
if (e) {
throw e;
}
Expand All @@ -64,18 +65,18 @@ function manifest (root, type, callback) {
"path": "${path.join(dir, 'run.sh')}",
"type": "stdio",
${origins}
}`, (e) => {
if (e) {
throw e;
}
callback();
});
}`, e => {
if (e) {
throw e;
}
callback();
});
});
}

function application (callback) {
function application(callback) {
console.log(' -> Creating a directory at', dir);
exists(dir, (e) => {
exists(dir, e => {
if (e) {
console.log('\x1b[31m', `-> You dont have permission to use "${share}" directory.` ,'\x1b[0m');
console.log('\x1b[31m', '-> Use custom directory instead. Example:' ,'\x1b[0m');
Expand All @@ -84,10 +85,10 @@ function application (callback) {
throw e;
}

let isNode = process.argv.filter(a => a === '--add_node').length === 0;
let run = isNode ? `#!/bin/bash\n${process.argv[2]} host.js` : '#!/bin/bash\n./node host.js';
const isNode = process.argv.filter(a => a === '--add_node').length === 0;
const run = `#!/bin/bash\n${process.argv[0]} host.js`;

fs.writeFile(path.join(dir, 'run.sh'), run, (e) => {
fs.writeFile(path.join(dir, 'run.sh'), run, e => {
if (e) {
throw e;
}
Expand All @@ -105,9 +106,9 @@ function application (callback) {
});
}

function chrome (callback) {
function chrome(callback) {
if (ids.chrome.length) {
let loc = path.join(
const loc = path.join(
process.env.HOME,
'Library/Application Support/Google/Chrome/NativeMessagingHosts'
);
Expand All @@ -118,9 +119,9 @@ function chrome (callback) {
callback();
}
}
function chromium (callback) {
function chromium(callback) {
if (ids.chrome.length) {
let loc = path.join(
const loc = path.join(
process.env.HOME,
'Library/Application Support/Chromium/NativeMessagingHosts'
);
Expand All @@ -131,9 +132,9 @@ function chromium (callback) {
callback();
}
}
function firefox (callback) {
function firefox(callback) {
if (ids.firefox.length) {
let loc = path.join(
const loc = path.join(
process.env.HOME,
'Library/Application Support/Mozilla/NativeMessagingHosts'
);
Expand Down

0 comments on commit 2fdd96a

Please sign in to comment.