Skip to content

Commit

Permalink
Binaries in production!
Browse files Browse the repository at this point in the history
  • Loading branch information
ganeshrvel committed Oct 25, 2018
1 parent d401b51 commit 44c3e7e
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 42 deletions.
71 changes: 37 additions & 34 deletions app/api/sys/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import mkdirp from 'mkdirp';
import path from 'path';
import moment from 'moment';
import { log } from '@Log';
import { mtp as mtpCli } from '@Binaries';
import { mtp as _mtpCli } from '@Binaries';
import { spawn, exec } from 'child_process';
import findLodash from 'lodash/find';
import { deviceTypeConst } from '../../constants';
Expand All @@ -31,6 +31,42 @@ import { msToTime, unixTimestampNow } from '../../utils/date';
const readdir = Promise.promisify(fs.readdir);
const execPromise = Promise.promisify(exec);

/**
* If you are reading this then let me tell you something "bunch of idiots are working at Apple inc."
*
* This is made to support flex quotes parser for mtp cli.
*/
export const escapeShellMtp = cmd => {
if (cmd.indexOf(`\\"`) !== -1 && cmd.indexOf(`"\\`) !== -1) {
return cmd
.replace(/`/g, '\\`')
.replace(/\\/g, `\\\\\\\\`)
.replace(/"/g, `\\\\\\"`);
}
if (cmd.indexOf(`"\\"`) !== -1) {
return cmd
.replace(/`/g, '\\`')
.replace(/\\/g, `\\\\\\\\`)
.replace(/"/g, `\\\\\\"`);
} else if (cmd.indexOf(`\\"`) !== -1) {
return cmd
.replace(/`/g, '\\`')
.replace(/\\/g, `\\\\\\`)
.replace(/"/g, `\\\\\\\\"`);
} else if (cmd.indexOf(`"\\`) !== -1) {
return cmd
.replace(/`/g, '\\`')
.replace(/\\/g, `\\\\\\\\`)
.replace(/"/g, `\\\\\\"`);
}
return cmd
.replace(/`/g, '\\`')
.replace(/\\/g, `\\\\\\`)
.replace(/"/g, `\\\\\\"`);
};

const mtpCli = `"${escapeShellMtp(_mtpCli)}"`;

const promisifiedExec = command => {
try {
return new Promise((resolve, reject) => {
Expand Down Expand Up @@ -827,36 +863,3 @@ const fetchExtension = (fileName, isFolder) => {
? null
: fileName.substring(fileName.lastIndexOf('.') + 1);
};

/**
* If you are reading this then let me tell you something "bunch of idiots are working at Apple inc."
* This is made to support flex quotes parser for mtp cli.
*/
export const escapeShellMtp = cmd => {
if (cmd.indexOf(`\\"`) !== -1 && cmd.indexOf(`"\\`) !== -1) {
return cmd
.replace(/`/g, '\\`')
.replace(/\\/g, `\\\\\\\\`)
.replace(/"/g, `\\\\\\"`);
}
if (cmd.indexOf(`"\\"`) !== -1) {
return cmd
.replace(/`/g, '\\`')
.replace(/\\/g, `\\\\\\\\`)
.replace(/"/g, `\\\\\\"`);
} else if (cmd.indexOf(`\\"`) !== -1) {
return cmd
.replace(/`/g, '\\`')
.replace(/\\/g, `\\\\\\`)
.replace(/"/g, `\\\\\\\\"`);
} else if (cmd.indexOf(`"\\`) !== -1) {
return cmd
.replace(/`/g, '\\`')
.replace(/\\/g, `\\\\\\\\`)
.replace(/"/g, `\\\\\\"`);
}
return cmd
.replace(/`/g, '\\`')
.replace(/\\/g, `\\\\\\`)
.replace(/"/g, `\\\\\\"`);
};
1 change: 1 addition & 0 deletions app/constants/env.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';

export const IS_DEV = process.env.NODE_ENV !== 'production';
export const IS_PROD = process.env.NODE_ENV === 'production';
4 changes: 2 additions & 2 deletions app/containers/HomePage/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ class Home extends Component {

async componentWillMount() {
/*
todo: time out help tool tip\
todo: binary for production
todo: app.requestSingleInstanceLock()
todo: time out help tool tip
todo: production app not relaunching unless full quit
todo: error boundary
todo: copy paste cut redo undo in prod
Expand Down
16 changes: 16 additions & 0 deletions app/utils/binaries.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict';
import path from 'path';
import { remote } from 'electron';
import getPlatform from './get-platform';
import { IS_PROD } from '../constants/env';
import { PATHS } from './paths';

const { root } = PATHS;
const { isPackaged, getAppPath } = remote.app;

const binariesPath =
IS_PROD && isPackaged
? path.join(path.dirname(getAppPath()), '..', './Resources', './bin')
: path.join(root, './resources', getPlatform(), './bin');

export const mtp = path.resolve(path.join(binariesPath, './mtp-cli'));
19 changes: 19 additions & 0 deletions app/utils/get-platform.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
'use strict';

import { platform } from 'os';

export default () => {
switch (platform()) {
case 'aix':
case 'freebsd':
case 'linux':
case 'openbsd':
case 'android':
return 'linux';
case 'darwin':
case 'sunos':
return 'mac';
case 'win32':
return 'win';
}
};
5 changes: 0 additions & 5 deletions binaries/index.js

This file was deleted.

9 changes: 9 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@
"main.prod.js.map",
"package.json"
],
"extraFiles": [
{
"from": "resources/mac/bin",
"to": "Resources/bin",
"filter": [
"**/*"
]
}
],
"dmg": {
"contents": [
{
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion webpack/config.base.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export default {
resolve: {
extensions: ['.js', '.jsx', '.json'],
alias: {
'@Binaries': path.resolve(__dirname, '../binaries/'),
'@Binaries': path.resolve(__dirname, '../app/utils/binaries.js'),
'@Log': path.resolve(__dirname, '../app/utils/log.js'),
'@Alerts': path.resolve(__dirname, '../app/containers/Alerts/actions.js')
},
Expand Down

0 comments on commit 44c3e7e

Please sign in to comment.