Skip to content
This repository has been archived by the owner on Dec 27, 2022. It is now read-only.

Commit

Permalink
Merge branch 'build-reorganisation'
Browse files Browse the repository at this point in the history
  • Loading branch information
szwacz committed Mar 4, 2016
2 parents 60bd286 + c3aaf47 commit 1795ac8
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 85 deletions.
4 changes: 2 additions & 2 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'use strict';

require('./tasks/build');
require('./tasks/release');
require('./tasks/build/build');
require('./tasks/release/release');
58 changes: 15 additions & 43 deletions tasks/build.js → tasks/build/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
var pathUtil = require('path');
var Q = require('q');
var gulp = require('gulp');
var rollup = require('rollup');
var less = require('gulp-less');
var jetpack = require('fs-jetpack');

var utils = require('./utils');
var generateSpecsImportFile = require('./generate_specs_import');
var bundle = require('./bundle');
var generateSpecImportsFile = require('./generate_spec_imports');
var utils = require('../utils');

var projectDir = jetpack;
var srcDir = projectDir.cwd('./app');
Expand All @@ -34,55 +34,27 @@ gulp.task('clean', function (callback) {

var copyTask = function () {
return projectDir.copyAsync('app', destDir.path(), {
overwrite: true,
matching: paths.copyFromAppDir
});
overwrite: true,
matching: paths.copyFromAppDir
});
};
gulp.task('copy', ['clean'], copyTask);
gulp.task('copy-watch', copyTask);


var bundle = function (src, dest) {
var deferred = Q.defer();

rollup.rollup({
entry: src,
}).then(function (bundle) {
var jsFile = pathUtil.basename(dest);
var result = bundle.generate({
format: 'cjs',
sourceMap: true,
sourceMapFile: jsFile,
});
// Wrap code in self invoking function so the variables don't
// pollute the global namespace.
var isolatedCode = '(function () {' + result.code + '\n}());';
return Q.all([
destDir.writeAsync(dest, isolatedCode + '\n//# sourceMappingURL=' + jsFile + '.map'),
destDir.writeAsync(dest + '.map', result.map.toString()),
]);
}).then(function () {
deferred.resolve();
}).catch(function (err) {
console.error('Build: Error during rollup', err.stack);
});

return deferred.promise;
};

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('background.js'), destDir.path('background.js')),
bundle(srcDir.path('app.js'), destDir.path('app.js')),
]);
};

var bundleSpecs = function () {
generateSpecsImportFile().then(function (specEntryPointPath) {
return generateSpecImportsFile().then(function (specEntryPointPath) {
return Q.all([
bundle(srcDir.path('background.js'), destDir.path('background.js')),
bundle(specEntryPointPath, destDir.path('spec.js')),
]);
bundle(srcDir.path('background.js'), destDir.path('background.js')),
bundle(specEntryPointPath, destDir.path('spec.js')),
]);
});
};

Expand All @@ -98,8 +70,8 @@ gulp.task('bundle-watch', bundleTask);

var lessTask = function () {
return gulp.src('app/stylesheets/main.less')
.pipe(less())
.pipe(gulp.dest(destDir.path('stylesheets')));
.pipe(less())
.pipe(gulp.dest(destDir.path('stylesheets')));
};
gulp.task('less', ['clean'], lessTask);
gulp.task('less-watch', lessTask);
Expand Down
52 changes: 52 additions & 0 deletions tasks/build/bundle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
'use strict';

var pathUtil = require('path');
var jetpack = require('fs-jetpack');
var rollup = require('rollup');
var Q = require('q');

var nodeBuiltInModules = ['assert', 'buffer', 'child_process', 'cluster',
'console', 'constants', 'crypto', 'dgram', 'dns', 'domain', 'events',
'fs', 'http', 'https', 'module', 'net', 'os', 'path', 'process', 'punycode',
'querystring', 'readline', 'repl', 'stream', 'string_decoder', 'timers',
'tls', 'tty', 'url', 'util', 'v8', 'vm', 'zlib'];

var electronBuiltInModules = ['electron'];

var npmModulesUsedInApp = function () {
var appManifest = require('../../app/package.json');
return Object.keys(appManifest.dependencies);
};

var generateExternalModulesList = function () {
return [].concat(nodeBuiltInModules, electronBuiltInModules, npmModulesUsedInApp());
};

module.exports = function (src, dest) {
var deferred = Q.defer();

rollup.rollup({
entry: src,
external: generateExternalModulesList(),
}).then(function (bundle) {
var jsFile = pathUtil.basename(dest);
var result = bundle.generate({
format: 'cjs',
sourceMap: true,
sourceMapFile: jsFile,
});
// Wrap code in self invoking function so the variables don't
// pollute the global namespace.
var isolatedCode = '(function () {' + result.code + '\n}());';
return Q.all([
jetpack.writeAsync(dest, isolatedCode + '\n//# sourceMappingURL=' + jsFile + '.map'),
jetpack.writeAsync(dest + '.map', result.map.toString()),
]);
}).then(function () {
deferred.resolve();
}).catch(function (err) {
console.error('Build: Error during rollup', err.stack);
});

return deferred.promise;
};
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ var whatToInclude = [

module.exports = function () {
return srcDir.findAsync('.', { matching: whatToInclude }, 'relativePath')
.then(function (specPaths) {
var fileContent = specPaths.map(function (path) {
return 'import "' + path + '";';
}).join('\n');
return srcDir.writeAsync(fileName, fileBanner + fileContent);
})
.then(function () {
return srcDir.path(fileName);
});
.then(function (specPaths) {
var fileContent = specPaths.map(function (path) {
return 'import "' + path + '";';
}).join('\n');
return srcDir.writeAsync(fileName, fileBanner + fileContent);
})
.then(function () {
return srcDir.path(fileName);
});
};
16 changes: 8 additions & 8 deletions tasks/release_linux.js → tasks/release/linux.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var gulpUtil = require('gulp-util');
var childProcess = require('child_process');
var jetpack = require('fs-jetpack');
var asar = require('asar');
var utils = require('./utils');
var utils = require('../utils');

var projectDir;
var releasesDir;
Expand Down Expand Up @@ -107,11 +107,11 @@ var cleanClutter = function () {

module.exports = function () {
return init()
.then(copyRuntime)
.then(packageBuiltApp)
.then(finalize)
.then(renameApp)
.then(packToDebFile)
.then(cleanClutter)
.catch(console.error);
.then(copyRuntime)
.then(packageBuiltApp)
.then(finalize)
.then(renameApp)
.then(packToDebFile)
.then(cleanClutter)
.catch(console.error);
};
20 changes: 10 additions & 10 deletions tasks/release_osx.js → tasks/release/osx.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var Q = require('q');
var gulpUtil = require('gulp-util');
var jetpack = require('fs-jetpack');
var asar = require('asar');
var utils = require('./utils');
var utils = require('../utils');
var child_process = require('child_process');

var projectDir;
Expand Down Expand Up @@ -135,13 +135,13 @@ var cleanClutter = function () {

module.exports = function () {
return init()
.then(copyRuntime)
.then(cleanupRuntime)
.then(packageBuiltApp)
.then(finalize)
.then(renameApp)
.then(signApp)
.then(packToDmgFile)
.then(cleanClutter)
.catch(console.error);
.then(copyRuntime)
.then(cleanupRuntime)
.then(packageBuiltApp)
.then(finalize)
.then(renameApp)
.then(signApp)
.then(packToDmgFile)
.then(cleanClutter)
.catch(console.error);
};
8 changes: 4 additions & 4 deletions tasks/release.js → tasks/release/release.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
'use strict';

var gulp = require('gulp');
var utils = require('./utils');
var utils = require('../utils');

var releaseForOs = {
osx: require('./release_osx'),
linux: require('./release_linux'),
windows: require('./release_windows'),
osx: require('./osx'),
linux: require('./linux'),
windows: require('./windows'),
};

gulp.task('release', ['build'], function () {
Expand Down
18 changes: 9 additions & 9 deletions tasks/release_windows.js → tasks/release/windows.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var gulpUtil = require('gulp-util');
var childProcess = require('child_process');
var jetpack = require('fs-jetpack');
var asar = require('asar');
var utils = require('./utils');
var utils = require('../utils');

var projectDir;
var tmpDir;
Expand Down Expand Up @@ -123,12 +123,12 @@ var cleanClutter = function () {

module.exports = function () {
return init()
.then(copyRuntime)
.then(cleanupRuntime)
.then(packageBuiltApp)
.then(finalize)
.then(renameApp)
.then(createInstaller)
.then(cleanClutter)
.catch(console.error);
.then(copyRuntime)
.then(cleanupRuntime)
.then(packageBuiltApp)
.then(finalize)
.then(renameApp)
.then(createInstaller)
.then(cleanClutter)
.catch(console.error);
};

0 comments on commit 1795ac8

Please sign in to comment.