Skip to content

Commit

Permalink
Integrate curl.press, Improve Error Reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
biocross committed Oct 27, 2019
1 parent 4a5ef43 commit 9cbe4ed
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
25 changes: 25 additions & 0 deletions analytics.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const https = require('https');

// These analytics ONLY send event names for understanding usage of the librarian.
// Absolutely NO system metadata or personal information is ever collected or sent.

///// Simple, Privary Aware Analytics: https://curl.press

const sendEvent = async (event) => {
if (event && event.length && event.length > 0) {
try {
const req = https.get(`https://curl.press/api/librarian/add?event=${event}`).on('error', function(err) {})
} catch (error) {}
}
}

const LibrarianEvents = {
SetupStarted: "setup.start",
SetupComplete: "setup.finish",
SetupError: "setup.error",
ServerStarted: "server.start",
ServerError: "server.error",
BuildSubmitted: "build.submit"
}

module.exports = { sendEvent, LibrarianEvents };
10 changes: 10 additions & 0 deletions librarian.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const gitP = require('simple-git/promise');
const git = gitP();
const { Extract } = require('app-metadata');
const { spawn } = require('child_process');
const { sendEvent, LibrarianEvents } = require('./analytics.js');
const { beginSetup, isSetup, shouldOverwriteConfiguration, purgeExistingInstallation, configurationKey } = require('./setup.js');
const { setWebConfiguration, addBuild } = require('./webBridge.js');
const storageOptions = {
Expand Down Expand Up @@ -69,6 +70,8 @@ program
fatalError('Librarian has not been setup yet! Run ' + chalk.yellow('librarian setup') + ' to begin')
}

sendEvent(LibrarianEvents.ServerStarted);

printHeader('Starting Librarian...');

const prefs = await preferences.getItem(configurationKey);
Expand All @@ -92,6 +95,8 @@ program
});

web.on('exit', function (code, signal) {
if(code != 0) { sendEvent(LibrarianEvents.ServerError); }
if(code == 1) { fatalError("Do you have another instance of Librarian running?") }
fatalError('The Jekyll Server has quit unexpectedly. Librarian is now exiting.');
});

Expand All @@ -115,6 +120,8 @@ program
});

asset_server.on('exit', function (code, signal) {
if(code == 1) { fatalError("Do you have another instance of Librarian running?") }
if(code != 0) { sendEvent(LibrarianEvents.ServerError); }
fatalError('The Assets Server has quit unexpectedly. Librarian is now exiting.');
});
}
Expand All @@ -137,6 +144,7 @@ program
tunnelURL = await ngrok.connect(options);

} catch (error) {
sendEvent(LibrarianEvents.ServerError);
log(JSON.stringify(error));
fatalError("\nFailed to start the ngrok tunnel.\nPlease make sure your ngRok token is valid.");
}
Expand Down Expand Up @@ -180,6 +188,8 @@ program
.option('-p, --public', 'Allow the build to be downloaded via the Internet using Librarian\'s HTTPS Tunnel')
.description('Submit a build to librarian')
.action(async (pathToFile, options) => {

sendEvent(LibrarianEvents.BuildSubmitted);

await preferences.init(storageOptions);

Expand Down
5 changes: 5 additions & 0 deletions setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const fs = require('fs-extra');
const git = require('simple-git/promise');
const home = os.homedir();
const { spawn } = require('child_process');
const { sendEvent, LibrarianEvents } = require('./analytics.js');

const configurationKey = 'librarian_config';
const librarianWebRepo = 'https://github.com/biocross/Librarian-Web.git';
Expand Down Expand Up @@ -85,6 +86,7 @@ const setupQuestions = [
];

const beginSetup = async (preferences) => {
sendEvent(LibrarianEvents.SetupStarted);
const configuration = await prompt(setupQuestions);

if (configuration.local_ip.indexOf('http') == -1) {
Expand Down Expand Up @@ -126,10 +128,12 @@ const beginSetup = async (preferences) => {
log(chalk.bold('\nAll set! Run Librarian using: ') + chalk.yellow.bold('librarian start'));
}
if (String(data).toLowerCase().indexOf('error') > -1) {
sendEvent(LibrarianEvents.SetupError);
log(String(data));
}
});
} else {
sendEvent(LibrarianEvents.SetupComplete);
log(chalk.green('Installation Complete!'));
log(chalk.bold('\nAll set! Run Librarian using: ') + chalk.yellow.bold('librarian start'));
}
Expand All @@ -140,6 +144,7 @@ const beginSetup = async (preferences) => {
});

bundler.on('exit', function (code, signal) {
if(code != 0) { sendEvent(LibrarianEvents.SetupError); }
if (code == 127) {
fatalError('Librarian requires bundler to work. Please install bundler by running ' + chalk.bold.yellow('gem install bundler') + ' and run librarian setup again.')
}
Expand Down

0 comments on commit 9cbe4ed

Please sign in to comment.