Skip to content

Commit 2d98c0f

Browse files
committed
build: Removed NW support in favor of Electron
This includes a simple script to make a release ready for packaging under the directory `dist-electron`.
1 parent 9454750 commit 2d98c0f

File tree

12 files changed

+140
-154
lines changed

12 files changed

+140
-154
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ src/installer/installer.exe
2929
# Builds
3030
dist/*
3131
dist-dev/*
32+
dist-electron
3233
!dist-dev/vendor
3334
doc/jsdoc
3435
src/server/*.sqlite

Gruntfile.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ module.exports = function(grunt) {
3232

3333
grunt.file.defaultEncoding = 'utf-8';
3434

35-
//grunt.loadNpmTasks('grunt-nw-builder');
3635
grunt.loadNpmTasks('grunt-eslint');
3736
grunt.loadNpmTasks('grunt-mocha-test');
3837
grunt.loadNpmTasks('grunt-mocha');
@@ -161,14 +160,6 @@ module.exports = function(grunt) {
161160
'src/packages/default/*/scheme.html'
162161
]
163162
}
164-
},
165-
nwjs: {
166-
options: {
167-
version: '0.12.3',
168-
platforms: ['win64', 'linux64'],
169-
buildDir: '.nw'
170-
},
171-
src: ['src/templates/nw/package.json', '.standalone/**/*']
172163
}
173164
});
174165
};

bin/build-electron.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/bin/bash
2+
#
3+
# Creates an 'electron' build ready for packaging
4+
#
5+
6+
DIR=dist-electron
7+
DIST=${DIR}/dist-dev
8+
9+
10+
rm -rf ${DIR}
11+
mkdir -p ${DIST}
12+
13+
# OS.js client
14+
node osjs build
15+
cp -r dist-dev/*.* ${DIST}
16+
cp -r src/client ${DIR}/dist-dev/client
17+
cp -r dist/themes ${DIR}/dist-dev/themes
18+
19+
# Packages
20+
mkdir ${DIR}/packages-tmp
21+
for r in `find dist/packages/*/* -maxdepth 1 -type d -prune`; do
22+
pn=`basename $r`
23+
rn=`basename $(dirname ${r})`
24+
mkdir -p ${DIR}/packages-tmp/${rn}
25+
cp -r src/packages/${rn}/${pn} ${DIR}/packages-tmp/${rn}/${pn}
26+
done
27+
28+
rm -rf ${DIR}/dist-dev/packages
29+
mv ${DIR}/packages-tmp ${DIR}/dist-dev/packages
30+
31+
# Electron base
32+
cp -r src/templates/electron/*.* ${DIR}/
33+
34+
# OS.js server and dependencies
35+
cp src/server/*.json ${DIR}/
36+
(cd ${DIR}; npm install)
37+
cp -r src/server/node ${DIR}/node_modules/osjs
38+
39+
# Misc
40+
cp -r dist/vendor ${DIR}/dist-dev/vendor
41+
mkdir -p ${DIR}/vfs/home/demo

src/build/core.js

Lines changed: 10 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,10 @@ function readScript(target, verbose, compress, list) {
7979
}
8080

8181
var data = compress ? _ugly.minify(path, {comments: false}).code : _fs.readFileSync(path).toString();
82-
if ( target !== 'nw' ) {
83-
data = data.replace(/\/\*\![\s\S]*?\*\//, '')
84-
.replace(/console\.(log|debug|info|group|groupStart|groupEnd|count)\((.*)\);/g, '')
85-
.replace(/(?:\/\*(?:[\s\S]*?)\*\/)|(?:^\s*\/\/(?:.*)$)/gm, '')
86-
.replace(/^\s*[\r\n]/gm, '');
87-
}
82+
data = data.replace(/\/\*\![\s\S]*?\*\//, '')
83+
.replace(/console\.(log|debug|info|group|groupStart|groupEnd|count)\((.*)\);/g, '')
84+
.replace(/(?:\/\*(?:[\s\S]*?)\*\/)|(?:^\s*\/\/(?:.*)$)/gm, '')
85+
.replace(/^\s*[\r\n]/gm, '');
8886

8987
return data;
9088
}).join('\n');
@@ -107,12 +105,11 @@ function readStyle(target, verbose, compress, list) {
107105
data = new Cleancss().minify(data).styles;
108106
}
109107

110-
if ( target !== 'nw' ) {
111-
data = data.replace(/\/\*\![\s\S]*?\*\//, '')
112-
.replace('@charset "UTF-8";', '')
113-
.replace(/(?:\/\*(?:[\s\S]*?)\*\/)|(?:^\s*\/\/(?:.*)$)/gm, '')
114-
.replace(/^\s*[\r\n]/gm, '');
115-
}
108+
data = data.replace(/\/\*\![\s\S]*?\*\//, '')
109+
.replace('@charset "UTF-8";', '')
110+
.replace(/(?:\/\*(?:[\s\S]*?)\*\/)|(?:^\s*\/\/(?:.*)$)/gm, '')
111+
.replace(/^\s*[\r\n]/gm, '');
112+
116113
return data;
117114
}).join('\n');
118115
}
@@ -189,48 +186,6 @@ function getBuildFiles(opts) {
189186
};
190187
}
191188

192-
/*
193-
* Build NW files
194-
*/
195-
function buildNW() {
196-
return new Promise(function(resolve) {
197-
const dest = _path.join(ROOT, 'dist');
198-
199-
_fs.mkdirSync(_path.join(dest, 'vfs'));
200-
_fs.mkdirSync(_path.join(dest, 'vfs', 'home'));
201-
_fs.mkdirSync(_path.join(dest, 'vfs', 'home', 'demo'));
202-
203-
_fs.copySync(
204-
_path.join(ROOT, 'README.md'),
205-
_path.join(dest, 'vfs', 'home', 'demo', 'README.md')
206-
);
207-
_fs.copySync(
208-
_path.join(ROOT, 'src', 'templates', 'nw', 'package.json'),
209-
_path.join(dest, 'package.json')
210-
);
211-
_fs.copySync(
212-
_path.join(ROOT, 'src', 'server', 'packages.json'),
213-
_path.join(dest, 'packages.json')
214-
);
215-
216-
// Install dependencies
217-
_fs.copySync(
218-
_path.join(ROOT, 'src', 'server', 'node'),
219-
_path.join(dest, 'node_modules', 'osjs')
220-
);
221-
_fs.copySync(
222-
_path.join(ROOT, 'src', 'templates', 'nw', 'index.js'),
223-
_path.join(dest, 'node_modules', 'osjs', 'index.js')
224-
);
225-
226-
const cmd = 'cd "' + dest + '" && npm install';
227-
require('child_process').exec(cmd, function(err, stdout, stderr) {
228-
console.log(stderr, stdout);
229-
resolve();
230-
});
231-
});
232-
}
233-
234189
/*
235190
* File adder wrapper
236191
*/
@@ -364,11 +319,7 @@ const TARGETS = {
364319
_utils.createStandaloneScheme(src, '/dialogs.html', _path.join(ROOT, 'dist', '_dialogs.js'));
365320
}
366321

367-
if ( cli.option('nw') ) {
368-
buildNW().then(resolve).catch(reject);
369-
} else {
370-
resolve();
371-
}
322+
resolve();
372323
});
373324
}
374325

src/client/javascript/core/connection.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,10 @@
267267

268268
if ( this.offline ) {
269269
cbError('You are currently off-line and cannot perform this operation!');
270+
return;
270271
} else if ( (API.getConfig('Connection.Type') === 'standalone') ) {
271272
cbError('You are currently running locally and cannot perform this operation!');
273+
return;
272274
}
273275

274276
if ( method.match(/^FS:/) ) {

src/conf/500-build.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@
5555
"src/client/javascript/core/search-engine.js",
5656
"src/client/javascript/core/connections/http.js",
5757
"src/client/javascript/core/connections/ws.js",
58-
"src/client/javascript/core/connections/nw.js",
5958
"src/client/javascript/core/auth/demo.js",
6059
"src/client/javascript/core/auth/database.js",
6160
"src/client/javascript/core/auth/pam.js",

src/server/node/core/instance.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,16 @@ const ENV = {
106106
* Loads generated configuration file
107107
*/
108108
function loadConfiguration(opts) {
109+
Object.keys(opts).forEach(function(k) {
110+
if ( typeof ENV[k] !== 'undefined' && typeof opts[k] !== 'undefined' ) {
111+
ENV[k] = opts[k];
112+
}
113+
});
114+
115+
if ( opts.ROOT ) {
116+
ENV.ROOTDIR = opts.ROOT;
117+
}
118+
109119
const path = _path.join(ENV.SERVERDIR, 'settings.json');
110120

111121
function _load(resolve, reject) {
@@ -121,23 +131,13 @@ function loadConfiguration(opts) {
121131
ENV.PORT = config.http.port;
122132
}
123133

124-
Object.keys(opts).forEach(function(k) {
125-
if ( typeof ENV[k] !== 'undefined' && typeof opts[k] !== 'undefined' ) {
126-
ENV[k] = opts[k];
127-
}
128-
});
129-
130-
if ( opts.ROOT ) {
131-
ENV.ROOTDIR = opts.ROOT;
132-
}
133-
134134
if ( typeof opts.LOGLEVEL === 'number' ) {
135135
ENV.LOGLEVEL = opts.LOGLEVEL;
136136
} else if ( typeof config.logging === 'number' ) {
137137
ENV.LOGLEVEL = config.logging;
138138
}
139139

140-
ENV.PKGDIR = _path.join(ENV.ROOTDIR, 'src/packages');
140+
ENV.PKGDIR = opts.PKGDIR || _path.join(ENV.ROOTDIR, 'src/packages');
141141
LOGGER = _osjs.logger.create(ENV.LOGLEVEL);
142142

143143
Object.keys(config.proxies).forEach(function(k) {

src/client/javascript/core/connections/nw.js renamed to src/templates/electron/main.js

Lines changed: 55 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* this list of conditions and the following disclaimer in the documentation
1414
* and/or other materials provided with the distribution.
1515
*
16-
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND
1717
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
1818
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
1919
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
@@ -27,52 +27,69 @@
2727
* @author Anders Evenrud <[email protected]>
2828
* @licence Simplified BSD License
2929
*/
30+
'use strict';
3031

31-
(function(API, Utils, Connection) {
32-
'use strict';
32+
const electron = require('electron');
33+
const app = electron.app
34+
const BrowserWindow = electron.BrowserWindow;
35+
const path = require('path');
36+
const url = require('url');
37+
const osjs = require('osjs/core/instance');
3338

34-
function NWConnection() {
35-
Connection.apply(this, arguments);
36-
this.nw = require('osjs');
37-
}
38-
39-
NWConnection.prototype = Object.create(Connection.prototype);
40-
NWConnection.constructor = Connection;
39+
let mainWindow;
4140

42-
NWConnection.prototype.init = function(callback) {
43-
/* TODO
44-
this.nw.init({
45-
root: process.cwd()
46-
}, callback);
47-
*/
41+
function createServer() {
42+
if ( app.server ) {
43+
return Promise.resolve();
44+
}
4845

49-
callback('Sorry, but this is not working at the moment');
46+
const opts = {
47+
DIST: 'dist-dev',
48+
ROOT: __dirname,
49+
PKGDIR: path.join(__dirname, 'dist-dev', 'packages'),
50+
SERVERDIR: __dirname,
51+
PORT: 8000,
52+
//LOGLEVEL: 15,
53+
AUTH: 'demo',
54+
STORAGE: 'demo'
5055
};
5156

52-
NWConnection.prototype.destroy = function() {
53-
this.nw = null;
54-
return Connection.prototype.destroy.apply(this, arguments);
55-
};
57+
return new Promise(function(resolve, reject) {
58+
osjs.init(opts).then(function() {
59+
resolve(osjs.run());
60+
}).catch(reject);
61+
});
62+
}
5663

57-
NWConnection.prototype._request = function(isVfs, method, args, options, onsuccess, onerror) {
58-
onerror = onerror || function() {
59-
console.warn('NWConnection::request()', 'error', arguments);
60-
};
64+
function createWindow() {
65+
createServer().then(function() {
66+
mainWindow = new BrowserWindow({
67+
width: 800,
68+
height: 600
69+
});
6170

62-
var res = Connection.prototype._request.apply(this, arguments);
63-
if ( res !== false ) {
64-
return res;
65-
}
71+
mainWindow.loadURL('http://localhost:8000');
6672

67-
onerror('Sorry, but this is not working at the moment');
68-
return false;
69-
};
73+
//mainWindow.webContents.openDevTools();
74+
75+
mainWindow.on('closed', function() {
76+
mainWindow = null
77+
})
78+
}).catch(function(err) {
79+
alert(err);
80+
});
81+
}
7082

71-
/////////////////////////////////////////////////////////////////////////////
72-
// EXPORTS
73-
/////////////////////////////////////////////////////////////////////////////
83+
app.on('ready', createWindow)
7484

75-
OSjs.Connections = OSjs.Connections || {};
76-
OSjs.Connections.nw = NWConnection;
85+
app.on('window-all-closed', function() {
86+
if ( process.platform !== 'darwin' ) {
87+
app.quit();
88+
}
89+
})
7790

78-
})(OSjs.API, OSjs.Utils, OSjs.Core.Connection);
91+
app.on('activate', function() {
92+
if ( mainWindow === null ) {
93+
createWindow();
94+
}
95+
})

src/templates/electron/package.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "osjs-electron",
3+
"version": "1.0.0",
4+
"description": "A basic OS.js Electron implementation",
5+
"main": "main.js",
6+
"scripts": {
7+
"start": "electron ."
8+
},
9+
"keywords": [
10+
"OS.js",
11+
"Electron"
12+
],
13+
"author": "Anders Evenrud <[email protected]>",
14+
"devDependencies": {
15+
"electron": "^1.4.1"
16+
}
17+
}

src/templates/electron/renderer.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// This file is required by the index.html file and will
2+
// be executed in the renderer process for that window.
3+
// All of the Node.js APIs are available in this process.

src/templates/nw/index.js

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)