Skip to content

Commit 6cdc213

Browse files
committed
just need to test windows
and we’re all good.
1 parent 77f2485 commit 6cdc213

File tree

6 files changed

+214
-163
lines changed

6 files changed

+214
-163
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ Explore your MongoDB.
3737
</dd>
3838
</dl>
3939

40+
## Building Releases
41+
42+
To compile electron + the app and the installer for your current platform:
43+
44+
```bash
45+
npm run release
46+
```
47+
4048
[setup-osx]: https://github.com/mongodb-js/mongodb-js/blob/master/docs/setup.md#osx-setup
4149
[setup-windows]: https://github.com/mongodb-js/mongodb-js/blob/master/docs/setup.md#windows-setup
4250
[setup-linux]: https://github.com/mongodb-js/mongodb-js/blob/master/docs/setup.md#linux-setup

gulpfile.js

Lines changed: 105 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -19,72 +19,102 @@ var notify = require('./tasks/notify');
1919
var pkg = require('./package.json');
2020

2121
// Platform specific tasks
22-
require(path.join(__dirname, 'tasks', process.platform)).tasks(gulp);
22+
var platform = require(path.join(__dirname, 'tasks', process.platform));
23+
gulp.task('build:electron', platform.build);
24+
gulp.task('build:electron-installer', ['build:electron'], platform.installer);
25+
26+
// @todo: debugging...
27+
var tar = require('gulp-tar');
28+
var gzip = require('gulp-gzip');
29+
30+
gulp.task('package:electron', function() {
31+
return gulp.src(['dist/MongoDB\ Enterprise\ Scout-darwin-x64/*', 'dist/MongoDB\ Enterprise\ Scout-darwin-x64/**/*'])
32+
.pipe(tar('MongoDB Enterprise Scout-v0.2.0.tar'))
33+
.pipe(gzip())
34+
.pipe(gulp.dest('dist/'));
35+
});
36+
37+
var BUILD = 'build/';
2338

2439
// `npm start` calls this.
25-
gulp.task('default', ['build', 'start electron', 'watch']);
26-
27-
var spinner = new clui.Spinner('Watching for changes...');
28-
29-
/**
30-
* Gulp's [fast browserify builds recipe](http://git.io/iiCk-A)
31-
*/
32-
var bundler = watchify(browserify('./src/index.js', {
33-
cache: {},
34-
packageCache: {},
35-
fullPaths: true,
36-
debug: false
37-
}))
38-
.transform('jadeify')
39-
.on('update', rebundle);
40-
41-
function rebundle(changed) {
42-
var start = process.hrtime();
43-
if (changed) {
44-
spinner.stop();
45-
gutil.log('Changed', '\'' + gutil.colors.cyan(changed[1]) + '\'');
46-
gutil.log('Starting', '\'' + gutil.colors.cyan('rebundle') + '\'...');
47-
}
48-
return bundler.bundle()
49-
.on('error', notify('js'))
50-
.pipe(source('index.js'))
51-
.pipe(gulp.dest('build/'))
52-
.on('end', function() {
53-
var time = prettyTime(process.hrtime(start));
54-
gutil.log('Finished', '\'' + gutil.colors.cyan('rebundle') + '\'',
55-
'after', gutil.colors.magenta(time));
56-
if (changed) {
57-
spinner.start();
58-
}
59-
});
60-
}
61-
62-
gulp.task('build', [
63-
'pages',
64-
'less',
65-
'js',
66-
'copy'
67-
]);
40+
gulp.task('start', ['build:app', 'build:electron', 'hack:app'], function() {
41+
platform.start();
42+
return gulp.start('watch');
43+
});
44+
gulp.task('hack:app', function() {
45+
return del(platform.BUILD);
46+
});
47+
48+
gulp.task('build:release', function() {
49+
BUILD = platform.BUILD;
50+
return gulp.start('build:app-release');
51+
});
6852

69-
gulp.task('js', function(cb) {
70-
bundler.bundle()
53+
gulp.task('build:app', ['pages', 'less', 'js', 'copy', 'build:npm-install'], function() {});
54+
gulp.task('build:app-release', ['pages', 'less', 'js', 'copy', 'build:npm-install-release'], function() {
55+
return gulp.start('build:electron-installer');
56+
});
57+
58+
// @todo: sourcemaps https://github.com/gulpjs/gulp/blob/master/docs/recipes/fast-browserify-builds-with-watchify.md
59+
gulp.task('js', function() {
60+
return browserify('./src/index.js', {
61+
cache: {},
62+
packageCache: {},
63+
fullPaths: true,
64+
debug: false
65+
})
66+
.transform('jadeify')
67+
.bundle()
7168
.on('error', notify('js'))
72-
.on('error', cb)
7369
.pipe(source('index.js'))
74-
.pipe(gulp.dest('build/'))
75-
.on('end', cb);
70+
.pipe(gulp.dest(BUILD));
7671
});
7772

78-
gulp.task('watch', function() {
73+
gulp.task('watch', ['build:app'], function() {
7974
gulp.watch(['src/{*,**/*}.less', 'styles/*.less'], ['less']);
8075
gulp.watch(['src/*.jade'], ['pages']);
8176
gulp.watch('images/{*,**/*}', ['copy images']);
8277
gulp.watch('fonts/*', ['copy fonts']);
83-
gulp.watch(['main.js', 'src/electron/*'], ['copy app electron files']);
84-
gulp.watch('package.json', ['install build']);
85-
86-
gulp.watch('build/*.js', ['copy build files to electron']);
87-
return rebundle(true);
78+
gulp.watch(['main.js', 'src/electron/*'], ['copy:electron']);
79+
gulp.watch('package.json', ['copy:electron', 'build:npm-install']);
80+
81+
var spinner = new clui.Spinner('Watching for changes...');
82+
83+
/**
84+
* Gulp's [fast browserify builds recipe](http://git.io/iiCk-A)
85+
*/
86+
var bundler = watchify(browserify('./src/index.js', {
87+
cache: {},
88+
packageCache: {},
89+
fullPaths: true,
90+
debug: false
91+
}))
92+
.transform('jadeify')
93+
.on('update', rebundle);
94+
var started = false;
95+
96+
function rebundle(changed) {
97+
var start = process.hrtime();
98+
if (changed) {
99+
spinner.stop();
100+
gutil.log('Changed', '\'' + gutil.colors.cyan(changed[1]) + '\'');
101+
gutil.log('Starting', '\'' + gutil.colors.cyan('rebundle') + '\'...');
102+
}
103+
return bundler.bundle()
104+
.on('error', notify('js'))
105+
.pipe(source('index.js'))
106+
.pipe(gulp.dest(BUILD))
107+
.on('end', function() {
108+
var time = prettyTime(process.hrtime(start));
109+
gutil.log('Finished', '\'' + gutil.colors.cyan('rebundle') + '\'',
110+
'after', gutil.colors.magenta(time));
111+
spinner.start();
112+
if (!started) {
113+
started = true;
114+
}
115+
});
116+
}
117+
return rebundle();
88118
});
89119

90120
// Compile LESS to CSS.
@@ -94,50 +124,49 @@ gulp.task('less', function() {
94124
.pipe(less(pkg.less))
95125
.on('error', notify('less'))
96126
.pipe(sourcemaps.write('./maps'))
97-
.pipe(gulp.dest('build'));
127+
.pipe(gulp.dest(BUILD));
98128
});
99129

100130
// Compile jade templates to HTML files.
101131
gulp.task('pages', function() {
102132
return gulp.src('src/index.jade')
103133
.pipe(jade())
104134
.on('error', notify('jade'))
105-
.pipe(gulp.dest('build'));
135+
.pipe(gulp.dest(BUILD));
106136
});
107137

108-
// Things that should be copied into `build/`.
138+
// Things that should be copied into `BUILD`.
109139
gulp.task('copy', [
110-
'copy fonts',
111-
'copy images',
112-
'copy app electron files'
140+
'copy:fonts',
141+
'copy:images',
142+
'copy:electron'
113143
]);
114144

115-
gulp.task('copy fonts', function() {
145+
gulp.task('copy:fonts', function() {
116146
return gulp.src(pkg.fonts)
117-
.pipe(gulp.dest('build/fonts'));
147+
.pipe(gulp.dest(path.join(BUILD, 'fonts')));
118148
});
119149

120-
gulp.task('copy fonts', function() {
121-
return gulp.src(pkg.fonts)
122-
.pipe(gulp.dest('build/fonts'));
123-
});
124-
125-
gulp.task('copy images', function() {
150+
gulp.task('copy:images', function() {
126151
return gulp.src('images/{*,**/*}')
127-
.pipe(gulp.dest('build/images'));
152+
.pipe(gulp.dest(path.join(BUILD, 'images')));
128153
});
129154

130-
gulp.task('copy app electron files', function() {
155+
gulp.task('copy:electron', function() {
131156
return merge(
132-
gulp.src(['main.js', 'package.json']).pipe(gulp.dest('build/')),
133-
gulp.src(['src/electron/*']).pipe(gulp.dest('build/src/electron'))
157+
gulp.src(['main.js', 'package.json']).pipe(gulp.dest(BUILD)),
158+
gulp.src(['src/electron/*']).pipe(gulp.dest(path.join(BUILD, 'src/electron')))
134159
);
135160
});
136161

137-
gulp.task('install build', ['copy'], shell.task('npm install', {
138-
cwd: 'build'
162+
gulp.task('build:npm-install', ['copy:electron'], shell.task('npm install', {
163+
cwd: BUILD
164+
}));
165+
166+
gulp.task('build:npm-install-release', ['copy:electron'], shell.task('npm install --production', {
167+
cwd: platform.BUILD
139168
}));
140169

141170
gulp.task('clean', function(done) {
142-
del(['dist/', 'build/', 'node_modules/'], done);
171+
del(['dist/', 'node_modules/'], done);
143172
});

main.js

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,35 @@
1+
var _ = require('lodash');
12
var server = require('scout-server');
23
var watch = require('watch');
34
var tinyLR = require('tiny-lr');
45

5-
var NODE_MODULES_REGEX = /node_modules/;
6-
var opts = {
7-
port: 35729,
8-
host: '127.0.0.1'
9-
};
10-
11-
var livereload = tinyLR();
12-
livereload.listen(opts.port, opts.host);
13-
14-
watch.watchTree(__dirname, {
15-
filter: function(filename) {
16-
return !NODE_MODULES_REGEX.test(filename);
17-
},
18-
ignoreDotFiles: true
19-
}, function(files) {
20-
console.log('File change detected! Sending reload message');
21-
livereload.changed({
22-
body: {
23-
files: files
24-
}
25-
});
26-
});
27-
286
server.start({
297
static: __dirname
308
});
319

10+
setTimeout(function() {
11+
var NODE_MODULES_REGEX = /node_modules/;
12+
var opts = {
13+
port: 35729,
14+
host: '127.0.0.1'
15+
};
16+
17+
var livereload = tinyLR();
18+
livereload.listen(opts.port, opts.host);
19+
console.log('Watching %s for changes', __dirname);
20+
watch.watchTree(__dirname, {
21+
filter: function(filename) {
22+
return !NODE_MODULES_REGEX.test(filename);
23+
},
24+
ignoreDotFiles: true
25+
}, _.debounce(function(files) {
26+
console.log('File change detected! Sending reload message');
27+
livereload.changed({
28+
body: {
29+
files: files
30+
}
31+
});
32+
}, 300));
33+
}, 500);
34+
3235
require('./src/electron');

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@
4141
]
4242
},
4343
"scripts": {
44-
"start": "gulp",
44+
"start": "gulp start",
45+
"release": "gulp build:release",
4546
"test": "mocha",
4647
"check": "mongodb-js-precommit"
4748
},
@@ -91,10 +92,12 @@
9192
"electron-packager": "^5.0.0",
9293
"eslint-config-mongodb-js": "^0.1.4",
9394
"gulp": "^3.9.0",
95+
"gulp-gzip": "^1.1.0",
9496
"gulp-jade": "^1.0.1",
9597
"gulp-less": "^3.0.3",
9698
"gulp-shell": "^0.4.2",
9799
"gulp-sourcemaps": "^1.5.2",
100+
"gulp-tar": "^1.4.0",
98101
"gulp-uglify": "^1.2.0",
99102
"gulp-util": "^3.0.6",
100103
"gulp-webserver": "^0.9.1",
@@ -105,7 +108,6 @@
105108
"mongodb-js-precommit": "^0.1.2",
106109
"nightmare": "^1.8.2",
107110
"node-notifier": "^4.2.3",
108-
"opn": "^3.0.2",
109111
"phantomjs": "^1.9.17",
110112
"pre-commit": "^1.0.10",
111113
"pretty-hrtime": "^1.0.0",

tasks/darwin.js

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,26 @@
11
var path = require('path');
22
var pkg = require(path.resolve(__dirname, '../package.json'));
33
var fs = require('fs');
4-
var opn = require('opn');
54

65
var debug = require('debug')('scout:tasks:darwin');
76

87
var NAME = pkg.electron.name;
9-
var APP_PATH = path.join('dist', NAME + '-darwin-x64', NAME + '.app');
8+
var PACKAGE = path.join('dist', NAME + '-darwin-x64');
9+
var APP_PATH = path.join(PACKAGE, NAME + '.app');
1010

1111
var packager = require('electron-packager');
1212
var createDMG = require('electron-installer-dmg');
1313

14-
var CONFIG = {
14+
var spawn = require('child_process').spawn;
15+
16+
var CONFIG = module.exports = {
1517
name: pkg.electron.name,
1618
dir: path.resolve(__dirname, '../build'),
1719
out: path.resolve(__dirname, '../dist'),
1820
appPath: APP_PATH,
21+
PACKAGE: PACKAGE,
22+
BUILD: path.join(APP_PATH, 'Contents', 'Resources', 'app'),
23+
ELECTRON: path.join(APP_PATH, 'Contents', 'MacOS', 'Electron'),
1924
platform: 'darwin',
2025
arch: 'x64',
2126
version: pkg.electron.version,
@@ -50,18 +55,9 @@ module.exports.installer = function(done) {
5055
createDMG(CONFIG, done);
5156
};
5257

53-
module.exports.start = function(done) {
54-
opn(APP_PATH, done);
55-
};
56-
57-
module.exports.tasks = function(gulp) {
58-
gulp.task('build electron app', ['install build'], module.exports.build);
5958

60-
gulp.task('build installer', ['build electron app'], module.exports.installer);
61-
gulp.task('start electron', ['build electron app'], module.exports.start);
62-
63-
gulp.task('copy build files to electron', function() {
64-
return gulp.src('../build/*.js')
65-
.pipe(gulp.dest(path.join(CONFIG.appPath, 'Contents', 'Resources', 'app')));
66-
});
59+
module.exports.start = function() {
60+
var child = spawn(path.resolve(CONFIG.ELECTRON), [path.resolve(CONFIG.dir)]);
61+
child.stderr.pipe(process.stderr);
62+
child.stdout.pipe(process.stdout);
6763
};

0 commit comments

Comments
 (0)