Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version checking on bootstrap #678

Merged
merged 24 commits into from
Jul 1, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
ffb8b40
Added 'chalk' package to project
brian-learningpool Apr 29, 2015
481b583
Work in progress (do not use)
brian-learningpool Apr 30, 2015
02dbba2
Work in progress
brian-learningpool May 12, 2015
2c20bdd
Work in progress
brian-learningpool May 13, 2015
f0870ec
Added ability to check upgrades for both tools & pull the builder upd…
darylhedley May 14, 2015
67145ab
Fixed git pull command not being needed
darylhedley May 14, 2015
d7d843c
updated upgrade script
darylhedley May 19, 2015
d4ad247
Merge remote-tracking branch 'origin/version-checking-on-bootstrap' i…
darylhedley May 19, 2015
70e24ed
Updates to upgrade
darylhedley May 19, 2015
58cebe3
More upgrade merges
darylhedley May 19, 2015
82550a8
Added framework upgrade
darylhedley May 19, 2015
a4eea49
moved version back a number
darylhedley May 19, 2015
46f461d
Fixes issue with cwd not being set
darylhedley May 19, 2015
7e29fe8
Adds version.json file to be updated
darylhedley May 19, 2015
8a13359
Sorted out spacing
darylhedley May 19, 2015
2751fc1
added new lines to consoles
darylhedley May 19, 2015
b6f94ef
Updated comments and static code
darylhedley May 19, 2015
799a614
Added missing callback
darylhedley May 19, 2015
083603a
removed stringify
darylhedley May 19, 2015
ffdd463
merge of develop
darylhedley May 19, 2015
0beb39c
updated the version.json back to the real release tags
darylhedley May 19, 2015
3ae623f
Slight tidy-up of install/upgrade process
brian-learningpool Jul 1, 2015
a1faaab
Removed references to .grey
brian-learningpool Jul 1, 2015
ece8297
Removed another two instances of .grey
brian-learningpool Jul 1, 2015
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions install.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ var prompt = require('prompt'),
async = require('async'),
fs = require('fs'),
path = require('path'),
colors = require('colors'),
rimraf = require('rimraf'),
exec = require('child_process').exec,
builder = require('./lib/application'),
Expand Down Expand Up @@ -124,7 +123,8 @@ var configItems = [
{
name: 'smtpUsername',
type: 'string',
description: "SMTP username"
description: "SMTP username",
default: ''
},
{
name: 'smtpPassword',
Expand All @@ -135,7 +135,8 @@ var configItems = [
{
name: 'fromAddress',
type: 'string',
description: "Sender email address"
description: "Sender email address",
default: ''
},
{
name: 'outputPlugin',
Expand All @@ -149,7 +150,7 @@ tenantConfig = [
{
name: 'name',
type: 'string',
description: "Set a unique name for your master tenant",
description: "Set a unique name for your tenant",
pattern: /^[A-Za-z0-9_-]+\W*$/,
default: 'master'
},
Expand Down Expand Up @@ -224,7 +225,7 @@ var steps = [
// run the app
app.run();
app.on('serverStarted', function () {
console.log("You will now be prompted to enter details for the master tenant.");
console.log("You will now be prompted to enter details for your tenant.");
prompt.get(tenantConfig, function (err, result) {
if (err) {
console.log('ERROR: ', err);
Expand All @@ -242,7 +243,7 @@ var steps = [

// create the tenant according to the user provided details
var _createTenant = function (cb) {
console.log("Creating master tenant file system for " + (tenantName).blue + ", please wait ...");
console.log("Creating file system for " + tenantName + ", please wait ...");
app.tenantmanager.createTenant({
name: tenantName,
displayName: tenantDisplayName,
Expand All @@ -262,7 +263,7 @@ var steps = [
}

masterTenant = tenant;
console.log("Master tenant " + (tenant.name).blue + " was created.");
console.log("Tenant " + tenant.name + " was created.");
// save master tenant name to config
configuration.setConfig('masterTenantName', tenant.name);
configuration.setConfig('masterTenantID', tenant._id);
Expand Down Expand Up @@ -316,7 +317,7 @@ var steps = [
return exitInstall(1, 'Plugin install was unsuccessful. Please check the console output.');
}

console.log((' installing ' + plugin.getPluginType() + ' plugins').grey);
console.log(' installing ' + plugin.getPluginType() + ' plugins');
plugin.updatePackages(plugin.bowerConfig, { tenantId: masterTenant._id.toString(), skipTenantCopy: true }, cb);
});
},
Expand Down Expand Up @@ -372,8 +373,8 @@ var steps = [
var proc = exec('grunt build:prod', { stdio: [0, 'pipe', 'pipe'] }, function (err) {
if (err) {
console.log('ERROR: ', err);
console.log('grunt build:prod command failed. Is the grunt-cli module installed? You can install using ' + 'npm install -g grunt grunt-cli'.grey);
console.log('Install will continue. Try running ' + 'grunt build:prod'.grey + ' after installation completes.');
console.log('grunt build:prod command failed. Is the grunt-cli module installed? You can install using ' + 'npm install -g grunt grunt-cli');
console.log('Install will continue. Try running ' + 'grunt build:prod' + ' after installation completes.');
return next();
}

Expand Down
209 changes: 154 additions & 55 deletions lib/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ var EventEmitter = require('events').EventEmitter,
Mailer = require('./mailer').Mailer,
configuration = require('./configuration');

var request = require('request');
var async = require('async');
var chalk = require('chalk');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The install.js uses 'colors' still. Chalk looks better. Can you update the install.js to swap out colors usage for chalk, and remove colors from the dependencies too?

pretty please :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've removed 'colors'.

/**
* Some defaults
*/
Expand Down Expand Up @@ -343,79 +346,175 @@ Origin.prototype.startServer = function () {
}

var app = this;
app.createServer(serverOptions, function (error, server) {
if (error) {
logger.log('fatal', 'error creating server', error);
return process.exit(1);
}

// use default port if configuration is not available
var port = app.configuration
? app.configuration.getConfig('serverPort')
: DEFAULT_SERVER_PORT;
var installedBuilderVersion = '', installedFrameworkVersion = '';
var latestBuilderTag = '';
var latestFrameworkTag = '';

app.server = server;
async.series([
function(callback) {
// Check for the expected NodeJS version
if (process.version !== 'v0.10.33') {
console.log(chalk.red('Incorrect version of NodeJS detected'));
logger.log('warn', 'Incorrect version of NodeJS detected -- this code requires v0.10.33 to run correctly.');
}

// Create a http server
var httpServer = require('http').createServer(server);

app._httpServer = httpServer.listen(port, function(){
// set up routes
app.router = router(app);
callback();
},
function(callback) {
// Read the current versions
var versionFile = JSON.parse(fs.readFileSync('version.json'), {encoding: 'utf8'});

if (versionFile) {
installedBuilderVersion = versionFile.adapt_authoring;
installedFrameworkVersion = versionFile.adapt_framework;
}

callback();
},
function(callback) {
// Check the latest version of the project
request({
headers: {
'User-Agent' : 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.118 Safari/537.36'
},
uri: 'https://api.github.com/repos/adaptlearning/adapt_authoring/tags',
method: 'GET'
}, function (error, response, body) {
if (!error && response.statusCode == 200) {
var tagInfo = JSON.parse(body);

if (tagInfo) {
latestBuilderTag = tagInfo[0].name;
}
}

callback();
});
},
function(callback) {
// Check the latest version of the framework
request({
headers: {
'User-Agent' : 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.118 Safari/537.36'
},
uri: 'https://api.github.com/repos/adaptlearning/adapt_framework/tags',
method: 'GET'
}, function (error, response, body) {
if (!error && response.statusCode == 200) {
var tagInfo = JSON.parse(body);

if (tagInfo) {
latestFrameworkTag = tagInfo[0].name;
}
}

callback();
});
},
function(callback) {
var isUpdateAvailable = false;

// handle different server states
if (serverOptions.minimal) {
app.emit("minimalServerStarted", app.server);
if (installedBuilderVersion == latestBuilderTag) {
console.log(chalk.green('Adapt Builder %s'), installedBuilderVersion);
} else {
app.emit("serverStarted", app.server);
console.log(chalk.yellow('You are currently running Adapt Builder %s - %s is now available'), installedBuilderVersion, latestBuilderTag);
isUpdateAvailable = true;
}

var writeRebuildFile = function(courseFolder, callback) {
var OutputConstants = require('./outputmanager').Constants;
var buildFolder = path.join(courseFolder, OutputConstants.Folders.Build);

fs.exists(buildFolder, function (exists) {
if (exists) {
// Write an empty lock file called .rebuild
logger.log('info', 'Writing build to ' + path.join(buildFolder, OutputConstants.Filenames.Rebuild));
fs.writeFile(path.join(buildFolder, OutputConstants.Filenames.Rebuild), '', function (err) {
if (err) {
return callback(err);
}
if (installedFrameworkVersion == latestFrameworkTag) {
console.log(chalk.green('Adapt Framework %s'), installedFrameworkVersion);
} else {
console.log(chalk.yellow('The Adapt Framework being used is %s - %s is now available'), installedFrameworkVersion, latestFrameworkTag);
isUpdateAvailable = true;
}

return callback(null);
});
if (isUpdateAvailable) {
console.log("Run " + chalk.bgRed('"node upgrade.js"') + " to update to the latest version");
console.log();
}

callback();
},
function(callback) {
app.createServer(serverOptions, function (error, server) {
if (error) {
logger.log('fatal', 'error creating server', error);
return process.exit(1);
}

// use default port if configuration is not available
var port = app.configuration
? app.configuration.getConfig('serverPort')
: DEFAULT_SERVER_PORT;

app.server = server;

// Create a http server
var httpServer = require('http').createServer(server);

app._httpServer = httpServer.listen(port, function(){
// set up routes
app.router = router(app);

// handle different server states
if (serverOptions.minimal) {
app.emit("minimalServerStarted", app.server);
} else {
return callback(null);
app.emit("serverStarted", app.server);
}
});
};

app.on("rebuildCourse", function(tenantId, courseId) {
logger.log('info', 'Event:rebuildCourse triggered for Tenant: ' + tenantId + ' Course: ' + courseId);
// Not ideal, but there is a timing issue which prevente d
var OutputConstants = require('./outputmanager').Constants;
var courseFolder = path.join(configuration.tempDir, configuration.getConfig('masterTenantID'), OutputConstants.Folders.Framework, OutputConstants.Folders.AllCourses, tenantId, courseId);

fs.exists(courseFolder, function(exists) {
if (exists) {
writeRebuildFile(courseFolder, function(err) {
if (err) {
logger.log('error', err);

var writeRebuildFile = function(courseFolder, callback) {
var OutputConstants = require('./outputmanager').Constants;
var buildFolder = path.join(courseFolder, OutputConstants.Folders.Build);

fs.exists(buildFolder, function (exists) {
if (exists) {
// Write an empty lock file called .rebuild
logger.log('info', 'Writing build to ' + path.join(buildFolder, OutputConstants.Filenames.Rebuild));
fs.writeFile(path.join(buildFolder, OutputConstants.Filenames.Rebuild), '', function (err) {
if (err) {
return callback(err);
}

return callback(null);
});
} else {
return callback(null);
}
});
};

app.on("rebuildCourse", function(tenantId, courseId) {
logger.log('info', 'Event:rebuildCourse triggered for Tenant: ' + tenantId + ' Course: ' + courseId);
// Not ideal, but there is a timing issue which prevente d
var OutputConstants = require('./outputmanager').Constants;
var courseFolder = path.join(configuration.tempDir, configuration.getConfig('masterTenantID'), OutputConstants.Folders.Framework, OutputConstants.Folders.AllCourses, tenantId, courseId);

fs.exists(courseFolder, function(exists) {
if (exists) {
writeRebuildFile(courseFolder, function(err) {
if (err) {
logger.log('error', err);
}

return;
});
}

return;
});
}
});

logger.log('info', 'Server started listening on port ' + port);

return;
callback();
});
});

logger.log('info', 'Server started listening on port ' + port);
});
}
]);

});

};

Origin.prototype.restartServer = function () {
Expand Down
3 changes: 1 addition & 2 deletions lib/frameworkhelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
var path = require('path'),
fs = require('fs'),
util = require('util'),
colors = require('colors'),
exec = require('child_process').exec;

// errors
Expand All @@ -18,7 +17,7 @@ var FRAMEWORK_DIR = 'adapt_framework',
GIT_FRAMEWORK_CLONE_URL = 'https://github.com/adaptlearning/adapt_framework.git';

function flog(msg) {
console.log((' ' + msg).grey);
console.log(' ' + msg);
}

function cloneFramework (next) {
Expand Down
5 changes: 5 additions & 0 deletions lib/tenantmanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,11 @@ exports = module.exports = {
}

database.getDatabase(function(err, db){
if (err) {
logger.log('error', err);
return;
}

// delegate to db retrieve method
db.retrieve('tenant', search, options, callback);
}, configuration.getConfig('dbName'));
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"bcrypt-nodejs": "0.0.3",
"bower": "1.3",
"casperjs": "1.1.0-beta3",
"colors": "1.0.3",
"chalk": "^1.0.0",
"connect-mongo": "0.4.x",
"consolidate": "0.10.0",
"express": "3.4.0",
Expand All @@ -65,9 +65,9 @@
"rimraf": "~2.2.5",
"semver": "^2.3.1",
"underscore": "~1.5.2",
"unzip": "0.1.8",
"validator": "3.3.0",
"winston": "0.7.2",
"unzip": "0.1.8"
"winston": "0.7.2"
},
"main": "index",
"engines": {
Expand Down
Loading