Skip to content
This repository has been archived by the owner on May 31, 2023. It is now read-only.

Commit

Permalink
Merge pull request #5 from Greenhouse-Lab/electron-build-process
Browse files Browse the repository at this point in the history
Electron build process
  • Loading branch information
m-murphy authored Jul 26, 2017
2 parents da9375a + 99b99a2 commit 76754ed
Show file tree
Hide file tree
Showing 15 changed files with 9,403 additions and 34 deletions.
10 changes: 9 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,12 @@

.DS_STORE
\.vscode/
*.sqlite
*.sqlite
dist
darwin-pybuild
win-pybuild
node_modules
app
run.spec

yarn-error\.log
95 changes: 95 additions & 0 deletions build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import os
import sys
import shutil


VENV_PATH = os.path.join(os.environ.get("WORKON_HOME"), "sample_db")
WINE_PYINSTALLER_PATH = os.path.join(os.path.expanduser("~"), ".wine", "drive_c", "Python27", "Scripts", "pyinstaller.exe")
WINE_PIP_PATH = os.path.join(os.path.expanduser("~"), ".wine", "drive_c", "Python27", "Scripts", "pip.exe")
if sys.platform == 'win32':
activate_script = os.path.join(VENV_PATH, "Scripts", "activate_this.py")
else:
activate_script = os.path.join(VENV_PATH, "bin", "activate_this.py")
execfile(activate_script, dict(__file__=activate_script))

BUILD_PATH = './app'
SERVER_SRC_PATH = './src/sample-db-py/'
SERVER_SRC_STATIC_PATH = os.path.join(SERVER_SRC_PATH, 'sample_db', 'static')
CLIENT_SRC_PATH = './src/sample-db-app/'
ELECTRON_SRC_PATH = './src/electron/'

SERVER_BUILD_PATH = os.path.join(BUILD_PATH, 'db-server')
CLIENT_BUILD_PATH = os.path.join(BUILD_PATH, 'db-app')

if not os.path.exists(BUILD_PATH):
os.mkdir(BUILD_PATH)

def clean_build():
if os.path.exists(BUILD_PATH):
shutil.rmtree(BUILD_PATH)
os.mkdir(BUILD_PATH)

def build_static_files():
if not os.path.exists(os.path.join(SERVER_BUILD_PATH, 'static')):
os.mkdir(os.path.join(SERVER_BUILD_PATH, 'static'))
for f in os.listdir(SERVER_SRC_STATIC_PATH):
shutil.copy(os.path.join(SERVER_SRC_STATIC_PATH, f), os.path.join(SERVER_BUILD_PATH, 'static'))

def build_win_server():
print("Building Windows Server...")
if os.path.exists(os.path.join(SERVER_BUILD_PATH, 'win32')):
shutil.rmtree(os.path.join(SERVER_BUILD_PATH, 'win32'))
if sys.platform != 'win32':
os.system("wine {} install -q -r {}".format(WINE_PIP_PATH, os.path.join(SERVER_SRC_PATH, 'requirements.txt')))
os.system('wine {} -y --clean --distpath {} --workpath win-pybuild --log-level ERROR --hiddenimport email.mime.message {}'.format(
WINE_PYINSTALLER_PATH,
os.path.join(SERVER_BUILD_PATH, 'win32'),
os.path.join(SERVER_SRC_PATH, 'run.py'),
)
)
else:
os.system("pip install -q -r {}".format(os.path.join(SERVER_SRC_PATH, 'requirements.txt')))
os.system('pyinstaller -y --clean --distpath {} --workpath darwin-pybuild --log-level ERROR --hiddenimport email.mime.message {}'.format(
os.path.join(SERVER_BUILD_PATH, 'win32'),
os.path.join(SERVER_SRC_PATH, 'run.py')
)
)

def build_darwin_server():
if sys.platform == 'darwin':
print("Building Mac Server")
os.system("pip install -q -r {}".format(os.path.join(SERVER_SRC_PATH, 'requirements.txt')))
os.system('pyinstaller -y --clean --distpath {} --workpath darwin-pybuild --log-level ERROR --hiddenimport email.mime.message {}'.format(
os.path.join(SERVER_BUILD_PATH, 'darwin'),
os.path.join(SERVER_SRC_PATH, 'run.py')
)
)
else:
raise Exception("Cannot compile darwin on non-darwin system.")

def build_client():
if os.path.exists(CLIENT_BUILD_PATH):
shutil.rmtree(CLIENT_BUILD_PATH)
os.system("cd {} && yarn && webpack".format(CLIENT_SRC_PATH))
shutil.move(os.path.join(CLIENT_SRC_PATH, "app"), CLIENT_BUILD_PATH)


def build_electron():
for f in os.listdir(ELECTRON_SRC_PATH):
shutil.copy(os.path.join(ELECTRON_SRC_PATH, f), BUILD_PATH)

def make_dist():
if sys.platform != 'win32':
os.system('yarn dist')
else:
os.system('yarn dist-win')

if __name__=='__main__':
clean_build()
build_win_server()
if sys.platform == 'darwin':
build_darwin_server()
build_static_files()
build_client()
build_electron()
make_dist()
Empty file added electron-config.json
Empty file.
29 changes: 29 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "sample-db",
"version": "1.0.1",
"license": "MIT",
"scripts": {
"dist-mac": "electron-builder -m",
"dist-win": "electron-builder -w",
"dist": "electron-builder -m -w"
},
"devDependencies": {
"electron": "^1.6.11",
"electron-builder": "^19.16.2"
},
"build": {
"productName": "SampleDB",
"directories": {
"app": "app",
"output": "dist"
},
"asarUnpack": ["**/*"],
"compression": "maximum",
"mac": {
"target": "dmg"
},
"win": {
"target": "nsis"
}
}
}
21 changes: 19 additions & 2 deletions src/electron/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@ const pids = [];

function createWindow () {
// Create the browser window.
mainWindow = new BrowserWindow({width: 800, height: 600, title: "SampleDB" })

if (!mainWindow) {
mainWindow = new BrowserWindow({width: 800, height: 600, title: "SampleDB" })
}

mainWindow.loadURL(url.format({
pathname: 'index.html',
protocol: 'file',
Expand All @@ -37,6 +40,7 @@ function createWindow () {
// when you should delete the corresponding element.
mainWindow = null
})
createWindow = () => {};
}

// This method will be called when Electron has finished
Expand All @@ -45,10 +49,23 @@ function createWindow () {
app.on('ready', () => {

env = Object.create(process.env);
let serverPath;
env.CONFIG = 'Production';
sampledb = spawn(path.join(__dirname, 'db-server', 'run', 'run'), options={

if (ps.platform==='win32') {
serverPath = __dirname.split("\\");
serverPath = serverPath.slice(0, serverPath.length - 1);
serverPath = serverPath.join("\\");
} else {
serverPath = __dirname.split("/");
serverPath = serverPath.slice(0, serverPath.length - 1);
serverPath = serverPath.join("/");
}

sampledb = spawn(path.join(serverPath, 'app.asar.unpacked', 'db-server', ps.platform, 'run', 'run'), options={
env: env
});
console.log(sampledb.pid);
pids.push(sampledb.pid);

// Make electron sever local files called from the app.
Expand Down
13 changes: 5 additions & 8 deletions src/electron/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,16 @@
"version": "1.0.0",
"description": "Sample Database management application.",
"main": "main.js",
"scripts": {
"start": "electron ."
},
"repository": "https://github.com/greenhouse-lab/sample_db",
"keywords": [
"Matrix",
"barcode",
"sample",
"management"
],
"author": "Maxwell Murphy ",
"license": "AGPL",
"devDependencies": {
"electron": "~1.6.2"
}
"author": {
"name": "Maxwell Murphy",
"email": "[email protected]"
},
"license": "AGPL"
}
3 changes: 2 additions & 1 deletion src/sample-db-app/.angular-cli.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"project": {
"name": "sample-db-app"
"name": "sample-db-app",
"ejected": true
},
"apps": [
{
Expand Down
Empty file.
Loading

0 comments on commit 76754ed

Please sign in to comment.