Skip to content

Commit

Permalink
feat(build): Build images for linux
Browse files Browse the repository at this point in the history
  • Loading branch information
mrmeku committed Aug 29, 2018
1 parent 588274d commit b5ce360
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 30 deletions.
Binary file added apps/angular-console/src/assets/nautilus.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion electron/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@
"resolve": "1.8.1",
"universal-analytics": "^0.4.17",
"uuid": "^3.3.2",
"apollo-server-express": "^2.0.4",
"electron-store": "2.0.0"
},
"devDependencies": {
"electron": "^2.0.3"
"electron": "2.0.5"
}
}
35 changes: 23 additions & 12 deletions electron/src/electron.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
/* tslint:disable */

import {app, BrowserWindow, dialog, Menu} from 'electron';
import { app, BrowserWindow, dialog, Menu } from 'electron';
import * as path from 'path';
import {statSync} from 'fs';
import { statSync } from 'fs';
import * as os from 'os';
import {autoUpdater} from 'electron-updater';
import {reportEvent, reportException, setupEvents} from './analytics_and_settings';
import { autoUpdater } from 'electron-updater';
import {
reportEvent,
reportException,
setupEvents
} from './analytics_and_settings';

const fixPath = require('fix-path');
const getPort = require('get-port');
Expand Down Expand Up @@ -46,10 +50,7 @@ function createMenu() {
},
{
role: 'window',
submenu: [
{ role: 'minimize' },
{ role: 'close' }
]
submenu: [{ role: 'minimize' }, { role: 'close' }]
}
];
if (os.platform() === 'darwin') {
Expand Down Expand Up @@ -96,14 +97,22 @@ function createWindow() {
try {
win = new BrowserWindow(JSON.parse(store.get('windowBounds')));
} catch {
win = new BrowserWindow({ width: 800, height: 1400 });
win = new BrowserWindow({
width: 800,
height: 1400,
icon: path.join(__dirname, '/assets/icons/build/icon.png')
});
}

getPort({ port: 7777 }).then((port: number) => {
try {
startServer(port);
if (fileExists(path.join(currentDirectory, 'angular.json'))) {
win.loadURL(`http://localhost:${port}/workspace/${encodeURIComponent(currentDirectory)}/projects`);
win.loadURL(
`http://localhost:${port}/workspace/${encodeURIComponent(
currentDirectory
)}/projects`
);
} else {
win.loadURL(`http://localhost:${port}`);
}
Expand Down Expand Up @@ -155,10 +164,12 @@ function showRestartDialog() {
const dialogOptions = {
type: 'info',
buttons: ['Restart', 'Later'],
message: 'A new version of Angular Console has been downloaded. Restart Angular Console to install the new version.'
message:
'A new version of Angular Console has been downloaded. Restart Angular Console to install the new version.'
};
dialog.showMessageBox(dialogOptions, i => {
if (i === 0) { // Restart
if (i === 0) {
// Restart
reportEvent('Lifecycle', 'QuitAndInstall');
autoUpdater.quitAndInstall();
}
Expand Down
31 changes: 27 additions & 4 deletions package-scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,18 @@ const npsUtils = require('nps-utils');
const os = require('os');

function withPlatform(command) {
const platform = os.platform() === 'win32' ? 'win' : 'mac';
let platform;
switch (os.platform()) {
case 'win32':
platform = 'win';
break;
case 'darwin':
platform = 'mac';
break;
default:
platform = 'linux';
break;
}
return `${platform}.${command}`;
}

Expand Down Expand Up @@ -55,7 +66,19 @@ module.exports = {
'start-server': 'electron dist/electron --server',
'start-electron': 'NODE_ENV=development electron dist/electron',
'builder-dist': 'electron-builder --mac -p never',
'builder-dist-linux': 'electron-builder --linux -p never'
},
linux: {
'clean': 'rm -rf dist',
'compile': 'tsc -p electron/tsconfig.json',
'copy-assets': 'cp electron/package.json dist/electron/package.json && cp -r electron/assets dist/electron',
'copy-server': 'cp -r dist/server/src dist/electron/server',
'install-node-modules': 'cd dist/electron && yarn',
'copy-frontend': 'cp -r dist/apps/angular-console dist/electron/server/public',
'pack': 'electron-builder --linux --dir -p never',
'copy-to-osbuilds': 'cp -r dist/packages osbuilds/linux',
'start-server': 'electron dist/electron --server',
'start-electron': 'NODE_ENV=development electron dist/electron',
'builder-dist': 'electron-builder --linux -p never'
},
win: {
'clean': 'if exist dist rmdir dist /s /q',
Expand All @@ -75,10 +98,10 @@ module.exports = {
'prepare': npsUtils.series.nps(withPlatform('clean'), 'dev.compile-server-and-electron', 'frontend.build', withPlatform('copy-frontend'), withPlatform('pack')),
'server': npsUtils.series.nps('dev.compile-server-and-electron', withPlatform('start-server')),
'up': npsUtils.concurrent.nps('dev.server', 'frontend.serve'),
'dist': npsUtils.series.nps(withPlatform('prepare'), withPlatform('builder-dist'), withPlatform('copy-to-osbuilds'))
'dist': npsUtils.series.nps('dev.prepare', withPlatform('builder-dist'), withPlatform('copy-to-osbuilds'))
},
publish: {
'builder-publish': 'electron-builder --mac --win -p always --config.win.certificateSubjectName="Narwhal Technologies Inc."',
'builder-publish': 'electron-builder --mac --win --linux -p always --config.win.certificateSubjectName="Narwhal Technologies Inc."',
'publish': npsUtils.series.nps('dev.prepare', 'publish.builder-publish')
},
e2e: {
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@
"icon": "icon.ico"
},
"linux": {
"icon": "icon.png",
"target": [
"snap",
"deb",
"AppImage",
"tar.xz"
"deb",
"tar.gz"
],
"synopsis": "Angular Console",
"category": "Development"
Expand All @@ -53,7 +53,7 @@
"repo": "angular-console"
}
]
},
},
"dependencies": {
"@nrwl/nx": "6.2.1"
},
Expand Down
41 changes: 32 additions & 9 deletions server/src/api/read-editors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ export function readEditors() {
if (hasFinder()) {
editors.push({ name: 'Finder', icon: 'finder' });
}
if (hasNautilus()) {
editors.push({ name: 'Files', icon: 'nautilus' });
}
if (hasExplorer()) {
editors.push({ name: 'Explorer', icon: 'explorer' });
}
Expand All @@ -26,6 +29,8 @@ export function readEditors() {
export function openInEditor(editor: string, path: string) {
if (editor === 'Finder') {
openInFinder(path);
} else if (editor === 'Files') {
openInNautilus(path);
} else if (editor === 'Explorer') {
openInExplorer(path);
} else if (editor === 'VS Code') {
Expand All @@ -43,6 +48,10 @@ function hasFinder() {
return os.platform() === 'darwin';
}

function hasNautilus() {
return exists('nautilus');
}

function hasExplorer() {
return os.platform() === 'win32';
}
Expand All @@ -56,8 +65,7 @@ function hasVsCode() {
return false;
}
} else if (os.platform() === 'linux') {
// TODO implement linux support
return false;
return exists('code');
} else if (os.platform() === 'win32') {
try {
return (
Expand All @@ -82,8 +90,7 @@ function hasWebStorm() {
return false;
}
} else if (os.platform() === 'linux') {
// TODO implement linux support
return false;
return exists('wstorm') || exists('webstorm.sh');
} else if (os.platform() === 'win32') {
return hasExecutable('webstorm', process.cwd());
} else {
Expand All @@ -100,8 +107,7 @@ function hasIntellij() {
return false;
}
} else if (os.platform() === 'linux') {
// TODO implement linux support
return false;
return exists('idea');
} else if (os.platform() === 'win32') {
return hasExecutable('idea', process.cwd());
} else {
Expand All @@ -115,6 +121,10 @@ function openInFinder(path: string) {
}
}

function openInNautilus(path: string) {
exec(`nautilus ${path}`);
}

function openInExplorer(path: string) {
if (os.platform() === 'win32') {
exec(`start "" "${path}"`);
Expand All @@ -125,7 +135,7 @@ function openInVsCode(path: string) {
if (os.platform() === 'darwin') {
spawn('open', ['-a', 'Visual Studio Code', path], { detached: true });
} else if (os.platform() === 'linux') {
// TODO implement linux support
exec(`code ${path}`);
} else if (os.platform() === 'win32') {
exec(`code "${toWindows(path)}"`);
}
Expand All @@ -135,7 +145,11 @@ function openInWebStorm(path: string) {
if (os.platform() === 'darwin') {
spawn('open', ['-a', 'WebStorm', path], { detached: true });
} else if (os.platform() === 'linux') {
// TODO implement linux support
if (exists('wstorm')) {
exec(`wstorm ${path}`);
} else {
exec(`webstorm.sh ${path}`);
}
} else if (os.platform() === 'win32') {
spawn(findExecutable('webstorm', process.cwd()), [toWindows(path)], {
detached: true
Expand All @@ -147,7 +161,7 @@ function openInIntelliJ(path: string) {
if (os.platform() === 'darwin') {
spawn('open', ['-a', 'IntelliJ IDEA', path], { detached: true });
} else if (os.platform() === 'linux') {
// TODO implement linux support
exec(`idea ${path}`);
} else if (os.platform() === 'win32') {
spawn(findExecutable('idea', process.cwd()), [toWindows(path)], {
detached: true
Expand All @@ -161,3 +175,12 @@ function toWindows(path: string): string {
.filter(p => !!p)
.join('\\');
}

function exists(cmd: string): boolean {
try {
execSync(`which ${cmd}`).toString();
return true;
} catch (error) {
return false;
}
}

0 comments on commit b5ce360

Please sign in to comment.