Skip to content

Commit

Permalink
Creating app with Electron
Browse files Browse the repository at this point in the history
  • Loading branch information
cheton committed Apr 27, 2016
1 parent 4a5b126 commit 0d6a934
Show file tree
Hide file tree
Showing 31 changed files with 637 additions and 91 deletions.
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
tmp
node_modules
npm-debug.log
/dist
/coverage
/.nyc_output
/coverage
/dist
/output
3 changes: 2 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
tmp
npm-debug.log
/coverage
/.nyc_output
/coverage
/output
65 changes: 53 additions & 12 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,68 @@
sudo: required
os:
- linux
dist: trusty

services:
- docker

language: node_js

os:
- linux
- osx

node_js:
- '5'
- '4'
- '0.12'
- '0.10'
- '5'

env:
global:
- CXX=g++-4.8
- secure: "KPf6trtYLBDc2S/fF7H4VkNOAQ2Gc9sFj3v8aHOhNWDagACEHaPjIZdr3MGmzXji2EyQqtm6SxBxzdMbe1BNY5GRALgGI2fSyra+VwjhUeOB/UJ8oZuxhqnywbF77lbZgUYK/kOWHgCKGQxRsVZyytgK2CihOwPwzSp/CWUhBjlyjtDpUOMJXfc0USg05imR9LcwdW9o84uXGyI3XwHhqsA5szlu09Oxz+O//TMCHobb8o9b13N8Oxhdu9mgzynXCEo7TG4rwbmx2t7ymfM0TfEqfEsOOQ/A7iPJ4lxQ+FKGoKaqfITuZtUmzd4RaCK8zRVg/dYbXX2qF/RWRBKwIAfBLNLYYdFxleaBaNgGGyQw8TpNkm80u5ilmIDCrw79m0MqePZXcL4pdfRC9PBE2PO55tX/Podhk9HKovixvB4qxUj3Y45ORtSE2TO78W3Cs54JTQVNh4xz8Tzp67DWwNXN5XnwkVyvRugaCHV1gUuJWuJTUr6Bdoad9vid+GUKqNoBlTTgkjfc0/TDSuDFnAbnhdga4xFoFLnpTDpCaZrr1NWfhVCepGqY7I4qLcie/Bobpr6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BLhl2nBsoOii1OpoHRIZkr5JAX91ws9s/hxCvGYHm7txIVG7dfljYdK20=" # GITHUB_TOKEN
- GOPATH=$HOME/gopath
- PATH=$HOME/gopath/bin:$PATH

addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-4.8
- icnsutils
- graphicsmagick
- gcc-multilib
- g++-multilib

before_install:
- git --version
- git config --global user.name "Travis CI"
- git config --global user.email "[email protected]"
- go version
- go env
# https://github.com/aktau/github-release
- go get github.com/aktau/github-release
- github-release --version
#
# https://github.com/electron-userland/electron-builder/wiki/Multi-Platform-Build#os-x
#
# Use brew to install required packages.
#
# To build app in distributable format for Windows on OS X:
# $ brew install Caskroom/cask/xquartz wine mono
#
# To build app in distributable format for Linux on OS X:
# $ brew install ruby gnu-tar libicns graphicsmagick
#
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update; fi
- gem install fpm
# npm v3
- npm install -g npm

script:
- npm run build
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then npm run electron-builder:darwin-x64; fi
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then npm run electron-builder:linux-x64; fi

after_success:
- npm run coveralls
- npm run coverage-clean
- ./.travis/build-docker-image.sh
- if [[ "$TRAVIS_NODE_VERSION" != "5" ]]; then exit 0; fi
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then bash -c 'scripts/travis-release-darwin-x64.sh'; fi
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then bash -c 'scripts/travis-release-linux-x64.sh'; fi
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then bash -c 'scripts/travis-docker-build.sh'; fi
53 changes: 53 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# http:https://www.appveyor.com/docs/appveyor-yml

version: "{build}-{branch}"

cache:
- node_modules
- '%APPDATA%\npm-cache'
- '%USERPROFILE%\.electron'

init:
- git --version
- git config --global core.autocrlf false
- git config --global user.name "AppVeyor"
- git config --global user.email "[email protected]"
- go version
- go env

environment:
matrix:
- nodejs_version: "4"
- nodejs_version: "5"
GOROOT: c:\go
GOPATH: c:\gopath
GITHUB_TOKEN:
secure: 8GAPx69HrhLHtbsZyBG9KhOWHVnltZlWZuj2EQjRmAgG7t/vvzWxmTRsDM5uhwYx

platform:
- x64

matrix:
# Enable fast fail strategy
fast_finish: true

install:
- set PATH=%GOROOT%\bin;%GOPATH%\bin;%PATH%
- go get github.com/aktau/github-release
- github-release --version
- ps: Install-Product node $env:nodejs_version $env:platform
- npm install -g npm
- npm install

build_script:
- node --version
- npm --version
- npm run build
- npm run electron-packager:win32-x64
- cmd: cd output\current && 7z.exe -a cncjs-win32-x64.zip cncjs-win32-x64

deploy_script:
- ps: if($env:nodejs_version -eq '5') {
bash -c 'scripts/appveyor-release-win32-x64.sh'; }

test: off
53 changes: 4 additions & 49 deletions bin/cnc
Original file line number Diff line number Diff line change
@@ -1,53 +1,8 @@
#!/usr/bin/env node

var path = require('path');
var program = require('commander');
var pkg = require('../package.json');
var cnc = require('../dist/cncjs/cnc').default;

// Defaults to 'production'
process.env.NODE_ENV = process.env.NODE_ENV || 'production';

// Change working directory to 'dist/app'
process.chdir(path.resolve(__dirname, '../dist/app'));

function increaseVerbosityLevel(val, total) {
return total + 1;
}

function parseMountPoint(val) {
val = val || '';

if (val.indexOf(':') >= 0) {
var r = val.match(/(?:([^:]*)(?::(.*)))/);
return {
url: r[1] || '/static',
path: r[2]
};
}

return {
url: '/static',
path: val
};
}

program
.version(pkg.version)
.usage('[options]')
.option('-p, --port <port>', 'set listen port (default: 8000)', parseInt, 8000)
.option('-H, --host <host>', 'set listen address or hostname (default: 0.0.0.0)', '0.0.0.0')
.option('-b, --backlog <backlog>', 'set listen backlog (default: 511)', parseInt, 511)
.option('-c, --config <filename>', 'set config file (default: ~/.cncrc)')
.option('-v, --verbose', 'increase the verbosity level', increaseVerbosityLevel, 0)
.option('-m, --mount [<url>:]<path>', 'set the mount point for serving static files (default: /static:static)', parseMountPoint, { url: '/static', path: 'static' })
.parse(process.argv);

var app = require('../dist/app');
app.run({
port: program.port,
host: program.host,
backlog: program.backlog,
config: program.config,
verbose: program.verbose,
mount: program.mount
cnc(function(server) {
const address = server.address();
console.log('Started the server at http:https://%s:%d/.', address.address, address.port);
});
Binary file added build/background.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added build/icon.icns
Binary file not shown.
Binary file added build/icon.ico
Binary file not shown.
6 changes: 3 additions & 3 deletions gulp/tasks/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const webpackProductionConfig = {
]
},
output: {
path: path.join(__dirname, '../../dist/app'),
path: path.join(__dirname, '../../dist/cncjs/app'),
filename: '[name].js',
libraryTarget: 'commonjs2'
},
Expand Down Expand Up @@ -74,7 +74,7 @@ const distConfig = {
src: [
'src/app/{i18n,views}/**/*'
],
dest: 'dist/app'
dest: 'dist/cncjs/app'
};

export default (options) => {
Expand All @@ -90,7 +90,7 @@ export default (options) => {
];
return gulp.src(src)
.pipe(babel())
.pipe(gulp.dest('dist/app'));
.pipe(gulp.dest('dist/cncjs/app'));
});

gulp.task('app:build-prod', (callback) => {
Expand Down
34 changes: 34 additions & 0 deletions gulp/tasks/bootstrap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import fs from 'fs';
import path from 'path';
import gulp from 'gulp';
import babel from 'gulp-babel';
import pkg from '../../package.json';

export default (options) => {
gulp.task('bootstrap:babel', (callback) => {
const src = [
'src/*.js'
];
return gulp.src(src)
.pipe(babel())
.pipe(gulp.dest('dist/cncjs'));
});
gulp.task('bootstrap:pkg', (callback) => {
// Copy necessary properties from 'package.json' to 'src/package.json'
const _pkg = require('../../src/package.json');

_pkg.name = pkg.name;
_pkg.version = pkg.version;
_pkg.description = pkg.description;
_pkg.homepage = pkg.homepage;
_pkg.author = pkg.author;
_pkg.license = pkg.license;
_pkg.dependencies = pkg.dependencies;

fs.writeFileSync(path.resolve(__dirname, '../../src/package.json'), JSON.stringify(_pkg, null, 2), 'utf8');

return gulp.src('src/package.json')
.pipe(gulp.dest('dist/cncjs'));
});
gulp.task('bootstrap', ['bootstrap:babel', 'bootstrap:pkg']);
};
2 changes: 1 addition & 1 deletion gulp/tasks/web.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const distConfig = {
'src/web/vendor/**/*',
'src/web/i18n/**/*'
],
dest: 'dist/web'
dest: 'dist/cncjs/web'
};

export default (options) => {
Expand Down
2 changes: 2 additions & 0 deletions gulpfile.babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ gulp.task('development', (callback) => {

runSequence(
'clean',
'bootstrap',
['app:build-dev', 'web:build-dev'],
['app:i18n', 'web:i18n'],
['app:dist', 'web:dist'],
Expand All @@ -45,6 +46,7 @@ gulp.task('production', (callback) => {

runSequence(
'clean',
'bootstrap',
['app:build-prod', 'web:build-prod'],
['app:i18n', 'web:i18n'],
['app:dist', 'web:dist'],
Expand Down
Loading

0 comments on commit 0d6a934

Please sign in to comment.