Skip to content

Commit ca7e6bf

Browse files
committed
Merge pull request #147 from 10gen/dx-release-improvements
⚡ sourcemaps, a better `npm run release`, and an updated README.md
2 parents 1b2ceb8 + ccf9c42 commit ca7e6bf

File tree

4 files changed

+266
-52
lines changed

4 files changed

+266
-52
lines changed

README.md

Lines changed: 41 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,69 @@
1-
# compass
1+
# compass [![][travis_img]][travis_url]
22

3-
Explore your MongoDB.
3+
> Explore your MongoDB.
44
5-
## Developing
5+
## Development
66

77
1. Follow the setup instructions for [OSX][setup-osx], [Windows][setup-windows] or [Linux][setup-linux].
8-
2. Clone this repo
8+
2. Run `git clone [email protected]:10gen/compass.git ~/compass` to get the source code
99
3. Run `npm install` to install dependencies
10-
4. Run `npm start` to launch
10+
4. Run `npm start` to build the app and launch it
1111

12-
## Modules
12+
Already setup and prefer a simple copy and paste?
13+
14+
```bash
15+
git clone [email protected]:10gen/compass.git ~/compass;
16+
cd ~/compass;
17+
npm install;
18+
npm start;
19+
```
20+
21+
## Key Modules
1322

1423
<dl>
15-
<dt><a href="https://github.com/10gen/scout">Compass</a></dt>
24+
<dt><a href="https://magnum.travis-ci.com/10gen/compass"><img src="https://magnum.travis-ci.com/10gen/compass.svg?token=q2zsnxCbboarF6KYRYxM&branch=master" height="10" /></a>&nbsp;<a href="https://github.com/10gen/compass">compass</a> </dt>
1625
<dd>
1726
The default Ampersand.js single-page application people actually interact with.
18-
<a href="https://github.com/10gen/scout/blob/dev/src/models/scout-client-mixin.js">ScoutClientMixin</a>
19-
connects the <a href="https://github.com/10gen/scout/tree/dev/src/models">models</a> to
20-
<a href="https://github.com/mongodb-js/scout-client">scout-client</a>.
2127
</dd>
22-
<dt><a href="https://github.com/mongodb-js/scout-brain">scout-brain</a></dt>
28+
<dt><a href="https://magnum.travis-ci.com/10gen/scout-client"><img src="https://magnum.travis-ci.com/10gen/scout-client.svg?token=q2zsnxCbboarF6KYRYxM&branch=master" height="10" /></a>&nbsp;<a href="https://github.com/10gen/scout-client">scout-client</a></dt>
2329
<dd>
24-
Needs to be broken down into topic based models but for now, this is where
25-
all the business logic code lives we want to share between modules running
26-
in the browser, nodejs, or electron.
30+
Provides a clean API for `compass` to talk to `scout-server` that works in the browser, nodejs, or electron.
2731
</dd>
28-
<dt><a href="https://github.com/mongodb-js/scout-client">scout-client</a></dt>
32+
<dt><a href="https://magnum.travis-ci.com/10gen/scout-server"><img src="https://magnum.travis-ci.com/10gen/scout-server.svg?token=q2zsnxCbboarF6KYRYxM&branch=master" height="10" /></a>&nbsp;<a href="https://github.com/10gen/scout-server">scout-server</a></dt>
2933
<dd>
30-
Provides a clean API for <a href="https://github.com/mongodb-js/scout-server">scout-server</a>
31-
that works in the browser, nodejs, or electron.
34+
An express.js application which provides REST and socket.io endpoints
35+
to the mongodb node.js driver.
3236
</dd>
33-
<dt><a href="https://github.com/mongodb-js/scout-server">scout-server</a></dt>
37+
<dt><a href="https://travis-ci.org/mongodb-js/mongodb-connection-model"><img src="https://secure.travis-ci.org/mongodb-js/mongodb-connection-model.svg?branch=master" height="10" /></a>&nbsp;<a href="https://github.com/mongodb-js/mongodb-connection-model">mongodb-connection-model</a></dt>
3438
<dd>
35-
An express.js application which provides REST and socket.io connectivity
36-
to the mongodb node.js driver.
39+
A shared Ampersand.js model used by `compass`, `scout-client`, and `scout-server` that encapsulates
40+
all of the business logic for generating valid parameters to hand to the driver to connect to MongoDB.
41+
</dd>
42+
<dt><a href="https://travis-ci.org/mongodb-js/mongodb-collection-sample"><img src="https://secure.travis-ci.org/mongodb-js/mongodb-collection-sample.svg?branch=master" height="10" /></a>&nbsp;<a href="https://github.com/mongodb-js/mongodb-collection-sample">mongodb-collection-sample</a></dt>
43+
<dd>
44+
Provides a single interface for `scout-server` to request a sample of documents from a collection that automatically uses the `$sample` operator if available, falling back to a client-side reservoir sample.
45+
</dd>
46+
<dt><a href="https://travis-ci.org/mongodb-js/mongodb-schema"><img src="https://secure.travis-ci.org/mongodb-js/mongodb-schema.svg?branch=master" height="10" /></a>&nbsp;<a href="https://github.com/mongodb-js/mongodb-schema">mongodb-schema</a></dt>
47+
<dd>
48+
`compass` uses `scout-client` to get a sample of documents from `scout-server` via `mongodb-collection-sample` which is piped into `mongodb-schema` to create a probabilistic representation of what the schema for a given collection most likely is.
3749
</dd>
3850
</dl>
3951

52+
4053
## Building Releases
4154

42-
To compile electron + the app and the installer for your current platform:
55+
After you've made some local changes, the next thing you'll probably want to do
56+
is create an artifact to share. There is only one command you need to run to compile the app,
57+
sign it if the signing certificate is available on your machine, and generate a single file
58+
installer for your current platform:
4359

4460
```bash
45-
npm run release
61+
cd ~/compass;
62+
npm run release;
4663
```
4764

4865
[setup-osx]: https://github.com/mongodb-js/mongodb-js/blob/master/docs/setup.md#osx-setup
4966
[setup-windows]: https://github.com/mongodb-js/mongodb-js/blob/master/docs/setup.md#windows-setup
5067
[setup-linux]: https://github.com/mongodb-js/mongodb-js/blob/master/docs/setup.md#linux-setup
68+
[travis_img]: https://magnum.travis-ci.com/10gen/compass.svg?token=q2zsnxCbboarF6KYRYxM&branch=master
69+
[travis_url]: https://magnum.travis-ci.com/10gen/compass

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"fonts/*"
4040
],
4141
"browserify": {
42+
"debug": true,
4243
"entries": [
4344
"./src/index.js"
4445
]
@@ -92,6 +93,7 @@
9293
"bootstrap": "https://github.com/twbs/bootstrap/archive/v3.3.5.tar.gz",
9394
"browserify": "^10.2.4",
9495
"bugsnag-js": "^2.4.8",
96+
"chalk": "^1.1.1",
9597
"d3": "^3.5.5",
9698
"del": "^1.2.0",
9799
"domready": "^1.0.8",
@@ -101,6 +103,7 @@
101103
"eslint": "^0.24.1",
102104
"eslint-config-mongodb-js": "^0.1.4",
103105
"event-stream": "^3.3.1",
106+
"figures": "^1.4.0",
104107
"font-awesome": "https://github.com/FortAwesome/Font-Awesome/archive/v4.3.0.tar.gz",
105108
"glob": "^5.0.14",
106109
"gulp": "^3.9.0",

tasks/darwin.js

Lines changed: 114 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
var path = require('path');
22
var pkg = require(path.resolve(__dirname, '../package.json'));
33
var fs = require('fs');
4-
var cp = require('child_process');
4+
var run = require('./run');
5+
var format = require('util').format;
6+
var chalk = require('chalk');
7+
var figures = require('figures');
58
var series = require('run-series');
69
var _ = require('lodash');
10+
var packager = require('electron-packager');
11+
var createDMG = require('electron-installer-dmg');
712

813
var debug = require('debug')('scout:tasks:darwin');
914

1015
var NAME = pkg.product_name;
1116
var PACKAGE = path.join('dist', NAME + '-darwin-x64');
1217
var APP_PATH = path.join(PACKAGE, NAME + '.app');
1318

14-
var packager = require('electron-packager');
15-
var createDMG = require('electron-installer-dmg');
16-
1719
module.exports.ELECTRON = path.join(APP_PATH, 'Contents', 'MacOS', 'Electron');
1820
module.exports.RESOURCES = path.join(APP_PATH, 'Contents', 'Resources');
1921

@@ -29,7 +31,6 @@ var PACKAGER_CONFIG = {
2931
prune: true,
3032
'app-bundle-id': 'com.mongodb.compass',
3133
'app-version': pkg.version,
32-
sign: '90E39AA7832E95369F0FC6DAF823A04DFBD9CF7A',
3334
protocols: [
3435
{
3536
name: 'MongoDB Prototcol',
@@ -38,11 +39,6 @@ var PACKAGER_CONFIG = {
3839
]
3940
};
4041

41-
// Adjust config via environment variables
42-
if (process.env.SCOUT_INSTALLER_UNSIGNED !== undefined) {
43-
PACKAGER_CONFIG.sign = null;
44-
}
45-
4642
// @todo (imlucas): Standardize `electron-installer-dmg`
4743
// options w/ `electron-installer-squirrel-windows`.
4844
var INSTALLER_CONFIG = {
@@ -69,39 +65,127 @@ var INSTALLER_CONFIG = {
6965
]
7066
};
7167

72-
module.exports.build = function(done) {
73-
fs.exists(APP_PATH, function(exists) {
74-
if (exists) {
75-
debug('.app already exists. skipping packager run.');
76-
return done();
68+
var CODESIGN_IDENTITY_COMMON_NAME = 'Developer ID Application: Matt Kangas (ZD3CL9MT3L)';
69+
var CODESIGN_IDENTITY_SHA1 = '90E39AA7832E95369F0FC6DAF823A04DFBD9CF7A';
70+
71+
/**
72+
* Checks if the current environment can actually sign builds.
73+
* If signing can be done, `electron-packager`'s config will
74+
* be updated to sign artifacts. If not, gracefully degrade
75+
*
76+
* @param {Function} fn - Callback.
77+
*/
78+
function addCodesignIdentityIfAvailable(fn) {
79+
run('certtool', ['y'], function(err, output) {
80+
if (err) {
81+
debug('Failed to list certificates. Build will not be signed.');
82+
fn();
83+
return;
7784
}
78-
debug('running packager to create electron binaries...');
79-
packager(PACKAGER_CONFIG, done);
85+
if (output.indexOf(CODESIGN_IDENTITY_COMMON_NAME) === -1) {
86+
debug('Signing identity `%s` not detected. Build will not be signed.',
87+
CODESIGN_IDENTITY_COMMON_NAME);
88+
fn();
89+
return;
90+
}
91+
92+
PACKAGER_CONFIG.sign = CODESIGN_IDENTITY_SHA1;
93+
debug('The signing identity `%s` is available! '
94+
+ 'This build will be signed!', CODESIGN_IDENTITY_COMMON_NAME);
95+
96+
console.log(chalk.green.bold(figures.tick),
97+
format(' This build will be signed using the `%s` signing identity',
98+
CODESIGN_IDENTITY_COMMON_NAME));
99+
fn();
80100
});
81-
};
101+
}
102+
103+
module.exports.build = function(done) {
104+
addCodesignIdentityIfAvailable(function(err) {
105+
if (err) return done(err);
82106

83-
var verify = function(done) {
84-
var cmd = 'codesign --verify "' + APP_PATH + '"';
85-
debug('Verifying `%s` has been signed...', APP_PATH);
86-
cp.exec(cmd, done);
107+
fs.exists(APP_PATH, function(exists) {
108+
if (exists && process.env.NODE_ENV !== 'production') {
109+
debug('.app already exists. skipping packager run.');
110+
return done();
111+
}
112+
debug('running electron-packager...');
113+
packager(PACKAGER_CONFIG, done);
114+
});
115+
});
87116
};
88117

89-
module.exports.installer = function(done) {
90-
debug('creating installer...');
118+
/**
119+
* If the app is supposed to be signed, verify that
120+
* the signing was actually completed correctly.
121+
* If signing is not available, print helpful details
122+
* on working with unsigned builds.
123+
*
124+
* @param {Function} done - Callback which receives `(err)`.
125+
*/
126+
function verify(done) {
127+
if (!PACKAGER_CONFIG.sign) {
128+
console.error(chalk.yellow.bold(figures.warning),
129+
' User confusion ahead!');
91130

92-
var tasks = [];
93-
if (PACKAGER_CONFIG.sign) {
94-
tasks.push(verify);
131+
console.error(chalk.gray(
132+
' The default preferences for OSX Gatekeeper will not',
133+
'allow users to run unsigned applications.'));
134+
135+
console.error(chalk.gray(
136+
' However, we\'re going to continue building',
137+
'the app and an installer because you\'re most likely'));
138+
139+
console.error(chalk.gray(
140+
' a developer trying to test',
141+
'the app\'s installation process.'));
142+
143+
console.error(chalk.gray(
144+
' For more information on OSX Gatekeeper and how to change your',
145+
'system preferences to run unsigned applications,'));
146+
console.error(chalk.gray(' please see',
147+
'https://support.apple.com/en-us/HT202491'));
148+
debug('Build is not signed. Skipping codesign verification.');
149+
process.nextTick(done);
150+
return;
95151
}
96152

97-
tasks.push(_.partial(createDMG, INSTALLER_CONFIG));
153+
debug('Verifying `%s` has been signed correctly...', APP_PATH);
154+
run('codesign', ['--verify', APP_PATH], function(err) {
155+
if (err) {
156+
err = new Error('App is not correctly signed');
157+
done(err);
158+
return;
159+
}
160+
debug('Verified that the app has been signed correctly!');
161+
done();
162+
});
163+
}
164+
165+
/**
166+
* Package the application as a single `.DMG` file which
167+
* is the OSX equivalent of a `Setup.exe` installer.
168+
*
169+
* @param {Function} done - Callback which receives `(err)`.
170+
*/
171+
module.exports.installer = function(done) {
172+
debug('creating installer...');
173+
174+
var tasks = [
175+
verify,
176+
_.partial(createDMG, INSTALLER_CONFIG)
177+
];
98178

99179
series(tasks, function(err) {
100180
if (err) {
101-
console.error(err.stack);
181+
console.error(chalk.red.bold(figures.cross),
182+
'Failed to create DMG installer:', err.message);
183+
console.error(chalk.gray(err.stack));
102184
return done(err);
103185
}
104-
console.log('Installer created!');
186+
console.log(chalk.green.bold(figures.tick),
187+
' DMG installer written to',
188+
path.join(INSTALLER_CONFIG.out, INSTALLER_CONFIG.name + '.dmg'));
105189
done();
106190
});
107191
};

0 commit comments

Comments
 (0)