Skip to content
This repository has been archived by the owner on Jan 6, 2020. It is now read-only.

Commit

Permalink
reverted gulp scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
hitman401 committed Jun 14, 2016
1 parent 191df1c commit fc093a8
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 200 deletions.
4 changes: 1 addition & 3 deletions tasks/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ var paths = {
'./images/**',
'./vendor/**',
'./**/*.html',
'./**/*.+(jpg|png|svg)',
'!./server/boot.js'
'./**/*.+(jpg|png|svg)'
],
}

Expand Down Expand Up @@ -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')),
]);
};

Expand Down
163 changes: 25 additions & 138 deletions tasks/mocha-test.js
Original file line number Diff line number Diff line change
@@ -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') {
Expand All @@ -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);
45 changes: 18 additions & 27 deletions tasks/msvc_rebuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
54 changes: 22 additions & 32 deletions tasks/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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);
Expand All @@ -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);

0 comments on commit fc093a8

Please sign in to comment.