diff --git a/tasks/build.js b/tasks/build.js index ee5fff32..08d7d94d 100644 --- a/tasks/build.js +++ b/tasks/build.js @@ -25,8 +25,7 @@ var paths = { './images/**', './vendor/**', './**/*.html', - './**/*.+(jpg|png|svg)', - '!./server/boot.js' + './**/*.+(jpg|png|svg)' ], } @@ -81,7 +80,6 @@ var bundleApplication = function () { return Q.all([ bundle(srcDir.path('background.js'), destDir.path('background.js')), bundle(srcDir.path('app.js'), destDir.path('app.js')), - bundle(srcDir.path('server', 'boot.js'), destDir.path('server', 'boot.js')), ]); }; diff --git a/tasks/mocha-test.js b/tasks/mocha-test.js index e2b23381..75b96e67 100644 --- a/tasks/mocha-test.js +++ b/tasks/mocha-test.js @@ -1,49 +1,11 @@ 'use strict' var gulp = require('gulp'); -var gutils = require('gulp-util'); var pathUtil = require('path'); var jscs = require('gulp-jscs'); var jshint = require('gulp-jshint'); var stylish = require('gulp-jscs-stylish'); var childProcess = require('child_process'); -var babel = require('gulp-babel'); -var fse = require('fs-extra') -var path = require('path'); -var os = require('os'); -var exec = require('child_process').exec; -var gulpMocha = require('gulp-electron-mocha'); -var shell = require('gulp-shell'); -var install = require("gulp-install"); -var exec = require('gulp-exec'); - -var destDir = path.resolve('testApp'); -var ffiName = null; - -if (os.platform() === 'darwin') { - ffiName = 'libsafe_core.dylib'; -} else if(os.platform() === 'linux') { - ffiName = 'libsafe_core.so'; -} else { - ffiName = 'safe_core.dll'; -} -var apiPaths = [ - './app/api/**', - '!./app/api/ffi/' + ffiName -]; - -var serverPaths = [ - './app/server/**', -]; - -var loggerPaths = [ - './app/logger/**', -]; - -var rootPaths = [ - './app/env.js' -]; - var gulpPath = pathUtil.resolve('./node_modules/.bin/electron-mocha'); if (process.platform === 'win32') { @@ -52,107 +14,32 @@ if (process.platform === 'win32') { process.env['mocha-unfunk-style'] = 'plain'; -// var runMochaTests = function(cb) { -// childProcess.spawn(gulpPath, [ -// '--renderder', -// '--compilers', -// 'js:babel-core/register', -// '--timeout', -// '50000', -// '-R', -// 'mocha-unfunk-reporter', -// './tests/*' -// ], { -// stdio: 'inherit' -// }).on('exit', function() { -// cb(); -// }); -// } - -gulp.task('babelApi', function() { - gulp.src(apiPaths) - .pipe(babel()) - .pipe(gulp.dest(path.resolve(destDir, 'api'))); -}); - -gulp.task('babelServer', function() { - gulp.src(serverPaths) - .pipe(babel()) - .pipe(gulp.dest(path.resolve(destDir, 'server'))); -}); - -gulp.task('babelLogger', function() { - gulp.src(loggerPaths) - .pipe(babel()) - .pipe(gulp.dest(path.resolve(destDir, 'logger'))); -}); - -gulp.task('babelRoot', function() { - gulp.src(rootPaths) - .pipe(babel()) - .pipe(gulp.dest(path.resolve('.', destDir))); -}); - -gulp.task('clean', function() { - fse.removeSync('./testApp/api'); - fse.removeSync('./testApp/server'); - fse.removeSync('./testApp/*.js'); - fse.removeSync('./testApp/*.json'); -}); - -gulp.task('copy', function() { - fse.copySync(path.resolve('./app/api/ffi', ffiName), path.resolve(destDir, 'api', 'ffi', ffiName)); - fse.copySync('./app/package.json', path.resolve(destDir, 'package.json')); -}); - -gulp.task('finalize', function() { - var manifest = fse.readJsonSync(path.resolve(destDir, 'package.json')); - manifest.env = fse.readJsonSync(path.resolve('.', 'config', 'env_test.json')); - fse.writeJsonSync(path.resolve(destDir, 'package.json'), manifest); -}); - -gulp.task('installPackages', function() { - return gulp.src('./testApp/package.json') - .pipe(gulp.dest('./testApp')) - .pipe(install()); -}); +var runMochaTests = function() { + childProcess.spawn(gulpPath, [ + '--renderder', + '--compilers', + 'js:babel-core/register', + '--timeout', + '30000', + '-R', + 'mocha-unfunk-reporter', + './tests/*' + ], { + stdio: 'inherit' + }); +} -gulp.task('test_msvc_rebuild', [ 'installPackages' ], function() { - var options = { - continueOnError: false, // default = false, true means don't emit error event - pipeStdout: false, // default = false, true means stdout is written to file.contents - customTemplatingThing: "test" // content passed to gutil.template() - }; - var reportOptions = { - err: true, // default = true, false means don't write err - stderr: true, // default = true, false means don't write stderr - stdout: true // default = true, false means don't write stdout - } - return gulp.src(path.resolve(__dirname, '..')) - .pipe(exec('cd <%= file.path %> && gulp msvc_rebuild --env=test')) - .pipe(exec.reporter(reportOptions)); -}); +var executeTest = function() { -gulp.task('mocha', [ 'test_msvc_rebuild' ], function() { - return gulp.src('./tests', {read: false}) - .pipe(gulpMocha.default({ - electronMocha: { - renderer: true, - 'timeout': 50000, - compilers: 'js:babel-core/register', - R: 'mocha-unfunk-reporter', - } - })) -}); + gulp.src(['./app/*.js', './app/api/**/**/*.js', './app/scripts/**/*js']) + .pipe(jshint({ + esnext: true + })) // hint (optional) + .pipe(jscs()) // enforce style guide + .pipe(stylish.combineWithHintResults()) // combine with jshint results + .pipe(jshint.reporter('jshint-stylish')); -// var executeTest = function(cb) { -// gulp.src(['./app/*.js', './app/api/**/**/*.js', './app/scripts/**/*js']) -// .pipe(jshint({ -// esnext: true -// })) // hint (optional) -// .pipe(jscs()) // enforce style guide -// .pipe(stylish.combineWithHintResults()) // combine with jshint results -// .pipe(jshint.reporter('jshint-stylish')); -// }; + // runMochaTests(); +}; -gulp.task('test', [ 'clean', 'babelApi', 'babelServer', 'babelLogger', 'babelRoot', 'copy', 'finalize', 'mocha' ]); +gulp.task('test', executeTest); diff --git a/tasks/msvc_rebuild.js b/tasks/msvc_rebuild.js index 9dbb4883..2f2823c2 100644 --- a/tasks/msvc_rebuild.js +++ b/tasks/msvc_rebuild.js @@ -6,31 +6,22 @@ var childProcess = require('child_process'); var path = require('path'); var os = require('os'); var electronVersion = require(path.resolve('./node_modules/electron-prebuilt/package.json')).version; -var shell = require('gulp-shell'); -var exec = require('gulp-exec'); -gulp.task('msvc_rebuild', function() { - if (process.platform !== 'win32') { - return gutil.log('msvc_rebuild is supported only on Windows'); - } - var options = { - continueOnError: false, // default = false, true means don't emit error event - pipeStdout: false, // default = false, true means stdout is written to file.contents - customTemplatingThing: "test" // content passed to gutil.template() - }; - var reportOptions = { - err: true, // default = true, false means don't write err - stderr: true, // default = true, false means don't write stderr - stdout: true // default = true, false means don't write stdout - } - console.log(process.argv); - var rootFolder = gutil.env.env === 'test' ? 'testApp' : 'app'; - var packages = ['ref', 'ffi']; - var targetPath = path.resolve(rootFolder, 'node_modules'); - return gulp.src('./') - .pipe(exec('cd ' + path.resolve(targetPath, packages[0]) + ' && node-gyp rebuild --target=' + - electronVersion + ' --arch=' + os.arch() + ' --dist-url=https://atom.io/download/atom-shell && cd .. && cd ' + - packages[1] + ' && node-gyp rebuild --target=' + - electronVersion + ' --arch=' + os.arch() + ' --dist-url=https://atom.io/download/atom-shell', options)) - .pipe(exec.reporter(reportOptions)); -}); +if (process.platform !== 'win32') { + return new gutil.PluginError('msvc_rebuild', 'msvc_rebuild is supported only on Windows'); +} + +var executeMsvcRebuild = function() { + var targetPaths = [ './app/node_modules/ref', './app/node_modules/ffi' ]; + targetPaths.forEach(function(target) { + var childp = childProcess.exec('cd ' + path.resolve(target) + ' && node-gyp rebuild --target=' + + electronVersion + ' --arch=' + os.arch() + ' --dist-url=https://atom.io/download/atom-shell', function(err, stdout) { + if (err) { + return gutil.log(err); + } + gutil.log(stdout); + }); + }); +}; + +gulp.task('msvc_rebuild', executeMsvcRebuild); diff --git a/tasks/package.js b/tasks/package.js index cfe105ab..fbf112d1 100644 --- a/tasks/package.js +++ b/tasks/package.js @@ -8,10 +8,8 @@ var os = require('os'); var childProcess = require('child_process'); var pathUtil = require('path'); var electronVersion = require(pathUtil.resolve('./node_modules/electron-prebuilt/package.json')).version; -var exec = require('gulp-exec'); -var packageJson = require('../app/package.json'); -var BINARY_NAME = 'safe_launcher-v' + packageJson.version; +var BINARY_NAME = 'safe_launcher'; var OUT_FOLDER = 'app_dist'; var packagerPath = pathUtil.resolve('./node_modules/.bin/electron-packager'); @@ -37,13 +35,16 @@ var packageForOs = { } }; -var onPackageCompleted = function() { +var onPackageCompleted = function(code) { + if (code !== 0) { + return; + } var packagePath = pathUtil.resolve('.', OUT_FOLDER, BINARY_NAME + '-' + os.platform() + '-' + os.arch()); var versionFileName = 'version'; var filesToRemove = [ 'LICENSE', 'LICENSES.chromium.html' ]; var appVersion = require(pathUtil.resolve('./app/package.json')).version; - var versionFilePath = pathUtil.resolve(packagePath, versionFileName); + var versionFilePath = pathUtil.resolve(packagePath, versionFileName); filesToRemove.forEach(function(fileName) { fileName = pathUtil.resolve(packagePath, fileName); @@ -63,32 +64,21 @@ var onPackageCompleted = function() { var packageApp = function() { var config = packageForOs[utils.os()]; - var reportOptions = { - err: true, // default = true, false means don't write err - stderr: true, // default = true, false means don't write stderr - stdout: true // default = true, false means don't write stdout - } - return gulp.src('./') - .pipe(exec(packagerPath + ' build ' + BINARY_NAME + ' --icon=' + config.icon + ' --platform=' + config.platform + - ' --asar --asar-unpack=' + config.unpack + ' --out=' + OUT_FOLDER + ' --arch=' + os.arch() + ' --version=' + electronVersion + - ' --overwrite')) - .pipe(exec.reporter(reportOptions)); - // childProcess.spawn(packagerPath, [ - // 'build', - // BINARY_NAME, - // '--icon=' + config.icon, - // '--platform=' + config.platform, - // '--prune', - // '--asar', - // '--asar-unpack=' + config.unpack, - // '--out=' + OUT_FOLDER, - // '--arch=' + os.arch(), - // '--version=' + electronVersion, - // '--overwrite' - // ], { - // stdio: 'inherit' - // }).on('exit', onPackageCompleted); + childProcess.spawn(packagerPath, [ + 'build', + BINARY_NAME, + '--icon=' + config.icon, + '--platform=' + config.platform, + '--prune', + '--asar', + '--asar-unpack=' + config.unpack, + '--out=' + OUT_FOLDER, + '--arch=' + os.arch(), + '--version=' + electronVersion, + '--overwrite' + ], { + stdio: 'inherit' + }).on('exit', onPackageCompleted); }; -gulp.task('packageApp', ['build'], packageApp); -gulp.task('package', ['packageApp'], onPackageCompleted); +gulp.task('package', ['build'], packageApp);