Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Dominik Freiberger authored and Dominik Freiberger committed Oct 12, 2016
1 parent 937d5f1 commit 94d1a26
Show file tree
Hide file tree
Showing 49 changed files with 2,210 additions and 3,757 deletions.
3 changes: 0 additions & 3 deletions .babelrc

This file was deleted.

3 changes: 3 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": ["semistandard", "standard-react"]
}
17 changes: 0 additions & 17 deletions .eslintrc.json

This file was deleted.

3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
out
build
releases
19 changes: 0 additions & 19 deletions LICENSE

This file was deleted.

10 changes: 3 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,17 @@ Erkennt eine `FRITZ!WLAN Repeater DVB-C` Box im Netzwerk und zeigt die verfügba
### Quelltext
```
npm install
npm run build
npm start
```

### Binaries
* Unter Github [Release](https://github.com/freemountain/fritz-player/releases/tag/v0.0.1)
* Unter Github [Release](https://github.com/freemountain/fritz-player/releases/tag/v0.0.2)
* OSX funktioniert
* Linux
* libvlc muss vorhanden sein
* startet, mehr wurde nicht getestet, da kein WebGL in VM
* Windows noch nicht unterstützt

* Linux und Windows noch nicht unterstützt

## Release History
* 0.0.1 - init
* 0.0.2 - update and refactor to es6


## License
Expand Down
162 changes: 97 additions & 65 deletions build.js
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,84 +1,116 @@
#!/usr/bin/env node

require('shelljs/global');
var program = require('commander');

var legalPlatforms = ['osx', 'linux', 'win'];
var envVar = {
win: {
'NW_VERSION': '0.12.3',
'NW_PLATFORM': 'win64',
'WCJS_PLATFORM':'win',
'WCJS_ARCH':'x64',
'WCJS_RUNTIME': 'electron'
},
osx: {
'NW_VERSION': '0.12.3',
'NW_PLATFORM': 'osx64',
'WCJS_PLATFORM':'osx',
'WCJS_ARCH':'x64',
'WCJS_RUNTIME': 'electron'
},
linux: {
'NW_VERSION': '0.12.3',
'NW_PLATFORM': 'linux64',
'WCJS_PLATFORM':'linux',
'WCJS_ARCH':'x64',
'WCJS_RUNTIME': 'electron'
}
config.verbose = true;
const spawn = require('child-process-promise').spawn;
const path = require('path');
const packager = require('electron-packager');

function run (cmd, arg) {
let _arg = arg || [];

if (typeof arg === 'string') _arg = [arg];

const promise = spawn(cmd, _arg);
const child = promise.childProcess;

child.stdout.pipe(process.stdout);
child.stderr.pipe(process.stderr);

return promise;
}

var getVar = (v) => envVar[platform][v];
var getEnv = (v) => v + '=' + getVar(v);
function runBackground (cmd, arg) {
run(cmd, arg);

function die(msg) {
console.log('PANIC: ', msg);
exit(-1);
return new Promise(resolve => resolve());
}

function sync(target, destination, exclude) {
exclude = exclude || ['node_modules'];
var toClean = ls(destination).filter((f) => exclude.indexOf(f) === -1 );
toClean.forEach((f) => rm('-r', destination + f));
cp('-R', target, destination);
function npmInstall (dir) {
pushd(dir);

return run('npm', 'install').then(() => popd());
}

program
.version('0.0.1')
.option('-P, --pack', 'pack step')
.option('-p, --platform [p]', 'dd')
.option('-f, --force', 'false')
.parse(process.argv);
function setUp (dir) {
mkdir(dir);

var platform = process.platform;
var force = program.force || false;
var packStep = program.pack || false;
cp('src/index.html', path.join(dir, 'index.html'));
cp('src/package.json', path.join(dir, 'package.json'));

if(program.platform) platform = program.platform;
if(platform === 'darwin') platform = 'osx';
return new Promise(resolve => resolve());
}

if(legalPlatforms.indexOf(platform) === -1)
die('platform "' + platform + '" not supported');
function transpileSrc (input, output, watch) {
const cmd = 'node_modules/.bin/babel';
const arg = ['--plugins', 'transform-react-jsx',
'--presets', 'es2015-node6',
'--ignore', 'node_modules',
'--source-maps', 'true',
'--out-dir', output];

console.log('Platform: ', platform);
console.log('Force: ', force);
return run(cmd, arg.concat(input))
.then(() => {
if (watch === true) return runBackground(cmd, arg.concat(['--watch', input]));
});
}

mkdir('-p', 'out/work/node');
function runElectron (dir) {
return run('node_modules/.bin/electron', dir)
.then(() => process.exit(0));
}

rm('out/work/package.json');
rm('out/work/index.html');
cp('nw_package.json', 'out/work/package.json');
cp('src/index.html', 'out/work/index.html');
function copyDir (src, dest, force) {
if (test('-d', dest) && !force) return new Promise(resolve => resolve());

sync('src/node/*', 'out/work/node');
cd('out/work/node');
rm('-rf', dest);

if (force) rm('-rf', 'node_modules');
exec(getEnv('WCJS_ARCH') + ' ' + getEnv('WCJS_PLATFORM') + ' npm install');
cd('../../../');
cp('-R', src, dest);

console.log('build browser bundle...');
exec('./node_modules/.bin/browserify src/browser.js -t babelify --s app --outfile out/work/bundle.js');
return new Promise(resolve => resolve());
}

function packApp () {
const options = {
dir: './build',
name: 'fritz',
platform: 'darwin',
arch: 'x64',
out: './releases/',
overwrite: true,
prune: false,
asar: false,
version: '1.4.0'
};

return new Promise((resolve, reject) => {
packager(options, function (err, appPaths) {
if (err) return reject(err);

resolve(appPaths);
});
});
}

if(!packStep) exit();
console.log('build app bundle...');
exec('./node_modules/.bin/nwbuild -v ' + getVar('NW_VERSION') + ' -p ' + getVar('NW_PLATFORM') + ' -o out out/work');
if (process.argv[2] === 'dev') {
setUp('build')
.then(() => copyDir('node_modules/wcjs-prebuilt/bin/', 'build/wcjs'))
.then(() => npmInstall('build'))
.then(() => transpileSrc('src', 'build', true))
.then(() => runElectron('build'))
.catch(e => console.error(e));
}

if (process.argv[2] === 'build') {
setUp('build')
.then(() => npmInstall('build'))
.then(() => transpileSrc('src', 'build'))
.then(() => packApp())
.then((out) => {
if (process.platform !== 'darwin') return;

const dest = path.join(__dirname, out[0], 'fritz.app/Contents/Resources/app/wcjs/');
return copyDir('node_modules/wcjs-prebuilt/bin/', dest, true);
})
.catch(e => console.error(e));
}
68 changes: 0 additions & 68 deletions dev.js

This file was deleted.

8 changes: 0 additions & 8 deletions nw_package.json

This file was deleted.

Loading

0 comments on commit 94d1a26

Please sign in to comment.