From ffb8b40f79ec7e41449a97b5c48197dd577cde7f Mon Sep 17 00:00:00 2001 From: brian-learningpool Date: Wed, 29 Apr 2015 09:57:31 +0100 Subject: [PATCH 01/21] Added 'chalk' package to project --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 0f1d9aead3..3f2ae29e97 100644 --- a/package.json +++ b/package.json @@ -42,6 +42,7 @@ "bcrypt-nodejs": "0.0.3", "bower": "1.3", "casperjs": "1.1.0-beta3", + "chalk": "^1.0.0", "colors": "1.0.3", "connect-mongo": "0.4.x", "consolidate": "0.10.0", @@ -65,9 +66,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": { From 481b583d1331906580e7713e29a952fb32a2b1f3 Mon Sep 17 00:00:00 2001 From: brian-learningpool Date: Thu, 30 Apr 2015 15:33:51 +0100 Subject: [PATCH 02/21] Work in progress (do not use) --- lib/application.js | 205 ++++++++++++++++++++++++++++++++------------- version.json | 4 + 2 files changed, 149 insertions(+), 60 deletions(-) create mode 100644 version.json diff --git a/lib/application.js b/lib/application.js index 08a5c98a49..b6ae35b65d 100644 --- a/lib/application.js +++ b/lib/application.js @@ -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'); /** * Some defaults */ @@ -308,85 +311,167 @@ Origin.prototype.startServer = function () { serverOptions.minimal = true; } - // Check the NodeJS version - if (process.version !== 'v0.10.33') { - logger.log('warn', 'Incorrect version of NodeJS required -- this code requires v0.10.33 to run correctly.'); - } - 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 project is up to date + 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 framework is up to date + 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) { + if (installedBuilderVersion == latestBuilderTag) { + console.log(chalk.green('Adapt Builder %s'), installedBuilderVersion); + } else { + console.log(chalk.bgYellow('You are currently running Adapt Builder %s - %s is now available'), installedBuilderVersion, latestBuilderTag); + } - // handle different server states - if (serverOptions.minimal) { - app.emit("minimalServerStarted", app.server); + if (installedFrameworkVersion == latestFrameworkTag) { + console.log(chalk.green('Adapt Framework %s'), installedFrameworkVersion); } else { - app.emit("serverStarted", app.server); + console.log(chalk.bgYellow('The Adapt Framework being used is %s - %s is now available'), installedFrameworkVersion, latestFrameworkTag); } - 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); - } + callback(); + }, + function(callback) { + app.createServer(serverOptions, function (error, server) { + if (error) { + logger.log('fatal', 'error creating server', error); + return process.exit(1); + } - return callback(null); - }); + // 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 () { diff --git a/version.json b/version.json new file mode 100644 index 0000000000..fb064357f1 --- /dev/null +++ b/version.json @@ -0,0 +1,4 @@ +{ + "adapt_authoring": "v0.1.0", + "adapt_framework": "v1.1.1" +} \ No newline at end of file From 02dbba2d86fcca2dcf35edb59b89fc13b358f8fd Mon Sep 17 00:00:00 2001 From: brian-learningpool Date: Tue, 12 May 2015 15:37:06 +0100 Subject: [PATCH 03/21] Work in progress --- lib/application.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/application.js b/lib/application.js index b6ae35b65d..5e1e084338 100644 --- a/lib/application.js +++ b/lib/application.js @@ -339,7 +339,7 @@ Origin.prototype.startServer = function () { callback(); }, function(callback) { - // Check the project is up to date + // 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' @@ -359,7 +359,7 @@ Origin.prototype.startServer = function () { }); }, function(callback) { - // Check the framework is up to date + // 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' @@ -379,16 +379,25 @@ Origin.prototype.startServer = function () { }); }, function(callback) { + var isUpdateAvailable = false; + if (installedBuilderVersion == latestBuilderTag) { console.log(chalk.green('Adapt Builder %s'), installedBuilderVersion); } else { - console.log(chalk.bgYellow('You are currently running Adapt Builder %s - %s is now available'), installedBuilderVersion, latestBuilderTag); + console.log(chalk.yellow('You are currently running Adapt Builder %s - %s is now available'), installedBuilderVersion, latestBuilderTag); + isUpdateAvailable = true; } if (installedFrameworkVersion == latestFrameworkTag) { console.log(chalk.green('Adapt Framework %s'), installedFrameworkVersion); } else { - console.log(chalk.bgYellow('The Adapt Framework being used is %s - %s is now available'), installedFrameworkVersion, latestFrameworkTag); + console.log(chalk.yellow('The Adapt Framework being used is %s - %s is now available'), installedFrameworkVersion, latestFrameworkTag); + isUpdateAvailable = true; + } + + if (isUpdateAvailable) { + console.log("Run " + chalk.bgRed("node update.js") + " to upgrade"); + console.log(); } callback(); From 2c20bddc424c4d9fb9472a9436c8e9e6db1bed7f Mon Sep 17 00:00:00 2001 From: brian-learningpool Date: Wed, 13 May 2015 17:34:38 +0100 Subject: [PATCH 04/21] Work in progress --- upgrade.js | 138 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 138 insertions(+) create mode 100644 upgrade.js diff --git a/upgrade.js b/upgrade.js new file mode 100644 index 0000000000..17433ec25d --- /dev/null +++ b/upgrade.js @@ -0,0 +1,138 @@ +var prompt = require('prompt'); +var fs = require('fs'); +var request = require('request'); +var async = require('async'); + +// GLOBALS +var installedBuilderVersion = ''; +var latestBuilderTag = ''; +var installedFrameworkVersion = ''; +var latestFrameworkTag = ''; + +async.series([ + function(callback) { + var versionFile = JSON.parse(fs.readFileSync('version.json'), {encoding: 'utf8'}); + + if (versionFile) { + installedBuilderVersion = versionFile.adapt_authoring; + installedFrameworkVersion = versionFile.adapt_framework; + } +console.log('readFileSync'); + // 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) { + console.log('tag data' + body); + 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) { + if (latestBuilderTag == installedBuilderVersion && latestFrameworkTag == installedFrameworkVersion) { + console.log('No updates available at this time'); + process.exit(0); + } + + callback(); + } +], function(err, results) { + +}); + + +console.log('Latest ' + latestBuilderTag); +console.log(installedBuilderVersion + latestBuilderTag); +console.log(installedFrameworkVersion + latestFrameworkTag); + +prompt.message = '> '; +prompt.delimiter = ''; + +prompt.start(); + +// Prompt the user to begin the install +console.log('This will update the Adapt builder to the latest version. Would you like to continue?'); +prompt.get({ name: 'Y/n', type: 'string', default: 'Y' }, function (err, result) { + if (!/(Y|y)[es]*$/.test(result['Y/n'])) { + return exitInstall(); + } + + return exitInstall(1, 'whateva'); + + // run steps + async.series(steps, function (err, results) { + if (err) { + console.log('ERROR: ', err); + return exitInstall(1, 'Install was unsuccessful. Please check the console output.'); + } + + exitInstall(); + }); +}); + +/** + * Exits the install with some cleanup, should there be an error + * + * @param {int} code + * @param {string} msg + */ + +function exitInstall (code, msg) { + code = code || 0; + msg = msg || 'Bye!'; + console.log(msg); + + // handle borked tenant, users, in case of a non-zero exit + // if (0 !== code) { + // if (app && app.db) { + // if (masterTenant) { + // return app.db.destroy('tenant', { _id: masterTenant._id }, function (err) { + // if (superUser) { + // return app.db.destroy('user', { _id: superUser._id }, function (err) { + // return process.exit(code); + // }); + // } + + // return process.exit(code); + // }); + // } + // } + // } + + process.exit(code); +} \ No newline at end of file From f0870ecf19f6f87f46290999b37a7bd557d80a80 Mon Sep 17 00:00:00 2001 From: Daryl Hedley Date: Thu, 14 May 2015 15:48:42 +0100 Subject: [PATCH 05/21] Added ability to check upgrades for both tools & pull the builder updates --- lib/application.js | 2 +- plugins/content/course/index.js | 1 + upgrade.js | 161 +++++++++++++++++++++++++------- version.json | 2 +- 4 files changed, 130 insertions(+), 36 deletions(-) diff --git a/lib/application.js b/lib/application.js index 5e1e084338..455275901d 100644 --- a/lib/application.js +++ b/lib/application.js @@ -396,7 +396,7 @@ Origin.prototype.startServer = function () { } if (isUpdateAvailable) { - console.log("Run " + chalk.bgRed("node update.js") + " to upgrade"); + console.log("Run " + chalk.bgRed('"node upgrade.js"') + " to update to the latest version"); console.log(); } diff --git a/plugins/content/course/index.js b/plugins/content/course/index.js index 4024ca86d9..948d75ae8e 100644 --- a/plugins/content/course/index.js +++ b/plugins/content/course/index.js @@ -47,6 +47,7 @@ function initialize () { var options = _.keys(req.body).length ? req.body : req.query; + options = JSON.stringify(options); var search = options.search || {}; var self = this; var orList = []; diff --git a/upgrade.js b/upgrade.js index 17433ec25d..177f3fedb3 100644 --- a/upgrade.js +++ b/upgrade.js @@ -2,25 +2,30 @@ var prompt = require('prompt'); var fs = require('fs'); var request = require('request'); var async = require('async'); +var exec = require('child_process').exec; // GLOBALS var installedBuilderVersion = ''; var latestBuilderTag = ''; var installedFrameworkVersion = ''; var latestFrameworkTag = ''; +var shouldUpdateBuilder = false; +var shouldUpdateFramework = false; +var versionFile = JSON.parse(fs.readFileSync('version.json'), {encoding: 'utf8'}); -async.series([ +var steps = [ function(callback) { - var versionFile = JSON.parse(fs.readFileSync('version.json'), {encoding: 'utf8'}); + console.log('Checking versions'); if (versionFile) { installedBuilderVersion = versionFile.adapt_authoring; installedFrameworkVersion = versionFile.adapt_framework; } -console.log('readFileSync'); - // callback(); + console.log('Currently installed versions. Builder: ' + installedBuilderVersion + ', Framework: ' + installedFrameworkVersion); + callback(); }, function(callback) { + console.log('Checking available Builder upgrades'); // Check the latest version of the project request({ headers: { @@ -30,20 +35,18 @@ console.log('readFileSync'); method: 'GET' }, function (error, response, body) { if (!error && response.statusCode == 200) { - console.log('tag data' + body); - var tagInfo = JSON.parse(body); - - if (tagInfo) { - latestBuilderTag = tagInfo[0].name; - } - - // callback(); - } + var tagInfo = JSON.parse(body); + if (tagInfo) { + latestBuilderTag = tagInfo[0].name; + } + callback(); + } }); }, function(callback) { + console.log('Checking available Framework upgrades'); // Check the latest version of the framework request({ headers: { @@ -53,35 +56,74 @@ console.log('readFileSync'); method: 'GET' }, function (error, response, body) { if (!error && response.statusCode == 200) { - var tagInfo = JSON.parse(body); - - if (tagInfo) { - latestFrameworkTag = tagInfo[0].name; - } - - callback(); - } + var tagInfo = JSON.parse(body); + if (tagInfo) { + // For now - we should only worry about v1 tags of the framework + async.detectSeries(tagInfo, function(tag, callback) { + if (tag.name.split('.')[0] == 'v1') { + callback(tag); + } + }, function(latestVersion) { + + latestFrameworkTag = latestVersion.name; + callback(); + + }); + } + + } }); }, function(callback) { - if (latestBuilderTag == installedBuilderVersion && latestFrameworkTag == installedFrameworkVersion) { + // Check what needs upgrading + if (latestBuilderTag != installedBuilderVersion) { + shouldUpdateBuilder = true; + console.log('Update for Builder is available: ' + latestBuilderTag); + } + + if (latestFrameworkTag != installedFrameworkVersion) { + shouldUpdateFramework = true; + console.log('Update for Framework is available: ' + latestFrameworkTag); + } + + // If neither of the Builder or Framework need updating then quit the upgrading process + if (!shouldUpdateFramework && !shouldUpdateBuilder) { console.log('No updates available at this time'); process.exit(0); } callback(); - } -], function(err, results) { + }, function(callback) { + // Upgrade Builder if we need to + if (shouldUpdateBuilder) { + + upgradeBuilder(latestBuilderTag, function(err) { + if (err) { + return callback(err); + } + callback(); + }); + + } else { + callback(); + } -}); + }, function(callback) { + // Upgrade Framework if we need to + if (shouldUpdateFramework) { + console.log('Upgrading Framework'); + } else { + callback(); + } + }] -console.log('Latest ' + latestBuilderTag); +/*console.log('Latest ' + latestBuilderTag); console.log(installedBuilderVersion + latestBuilderTag); -console.log(installedFrameworkVersion + latestFrameworkTag); +console.log(installedFrameworkVersion + latestFrameworkTag);*/ -prompt.message = '> '; -prompt.delimiter = ''; +/*prompt.message = '> '; +prompt.delimiter = '';*/ prompt.start(); @@ -89,22 +131,73 @@ prompt.start(); console.log('This will update the Adapt builder to the latest version. Would you like to continue?'); prompt.get({ name: 'Y/n', type: 'string', default: 'Y' }, function (err, result) { if (!/(Y|y)[es]*$/.test(result['Y/n'])) { - return exitInstall(); + return exitUpgrade(); } - return exitInstall(1, 'whateva'); + //return exitUpgrade(1, 'whateva'); // run steps async.series(steps, function (err, results) { if (err) { console.log('ERROR: ', err); - return exitInstall(1, 'Install was unsuccessful. Please check the console output.'); + return exitUpgrade(1, 'Upgrade was unsuccessful. Please check the console output.'); } - exitInstall(); + exitUpgrade(); }); }); +// This upgrades the Framework +function upgradeFramework(tagName, callback) { + +} + +// This upgrades the Builder +function upgradeBuilder(tagName, callback) { + console.log('Upgrading...please hold on!') + var child = exec('git fetch', { + stdio: [0, 'pipe', 'pipe'] + }); + + child.stdout.on('data', function(err) { + console.log(err); + }); + child.stderr.on('data', function(err) { + console.log(err); + }); + + child.on('exit', function (error, stdout, stderr) { + if (error) { + console.log('ERROR: ' + error); + return next(error); + } + + console.log("Fetch from github was successful.\n"); + console.log("Pulling latest changes"); + var secondChild = exec('git checkout ' + tagName + ' && git pull', { + stdio: [0, 'pipe', 'pipe'] + }); + + secondChild.stdout.on('data', function(err) { + console.log(err); + }); + secondChild.stderr.on('data', function(err) { + console.log(err); + }); + + secondChild.on('exit', function (error, stdout, stderr) { + if (error) { + console.log('ERROR: ' + error); + return next(error); + } + + console.log("Pulled the big one.\n"); + //return installFramework(next); + }); + //return installFramework(next); + }); +} + /** * Exits the install with some cleanup, should there be an error * @@ -112,7 +205,7 @@ prompt.get({ name: 'Y/n', type: 'string', default: 'Y' }, function (err, result) * @param {string} msg */ -function exitInstall (code, msg) { +function exitUpgrade (code, msg) { code = code || 0; msg = msg || 'Bye!'; console.log(msg); diff --git a/version.json b/version.json index fb064357f1..c52a5759d5 100644 --- a/version.json +++ b/version.json @@ -1,4 +1,4 @@ { - "adapt_authoring": "v0.1.0", + "adapt_authoring": "v0.0.9", "adapt_framework": "v1.1.1" } \ No newline at end of file From 67145abc98d9b4f337ed481bc1d4461419e46ca0 Mon Sep 17 00:00:00 2001 From: Daryl Hedley Date: Thu, 14 May 2015 15:58:50 +0100 Subject: [PATCH 06/21] Fixed git pull command not being needed --- upgrade.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/upgrade.js b/upgrade.js index 177f3fedb3..49ea1833f9 100644 --- a/upgrade.js +++ b/upgrade.js @@ -155,7 +155,7 @@ function upgradeFramework(tagName, callback) { // This upgrades the Builder function upgradeBuilder(tagName, callback) { console.log('Upgrading...please hold on!') - var child = exec('git fetch', { + var child = exec('git fetch origin', { stdio: [0, 'pipe', 'pipe'] }); @@ -174,7 +174,7 @@ function upgradeBuilder(tagName, callback) { console.log("Fetch from github was successful.\n"); console.log("Pulling latest changes"); - var secondChild = exec('git checkout ' + tagName + ' && git pull', { + var secondChild = exec('git checkout ' + tagName, { stdio: [0, 'pipe', 'pipe'] }); From d7d843ce15ae730d63bb2e71466a602f8be6176c Mon Sep 17 00:00:00 2001 From: Daryl Hedley Date: Tue, 19 May 2015 13:48:41 +0100 Subject: [PATCH 07/21] updated upgrade script --- upgrade.js | 231 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 231 insertions(+) create mode 100644 upgrade.js diff --git a/upgrade.js b/upgrade.js new file mode 100644 index 0000000000..413f290d6f --- /dev/null +++ b/upgrade.js @@ -0,0 +1,231 @@ +var prompt = require('prompt'); +var fs = require('fs'); +var request = require('request'); +var async = require('async'); +var exec = require('child_process').exec; + +// GLOBALS +var installedBuilderVersion = ''; +var latestBuilderTag = ''; +var installedFrameworkVersion = ''; +var latestFrameworkTag = ''; +var shouldUpdateBuilder = false; +var shouldUpdateFramework = false; +var versionFile = JSON.parse(fs.readFileSync('version.json'), {encoding: 'utf8'}); + +var steps = [ + function(callback) { + console.log('Checking versions'); + + if (versionFile) { + installedBuilderVersion = versionFile.adapt_authoring; + installedFrameworkVersion = versionFile.adapt_framework; + } + console.log('Currently installed versions. Builder: ' + installedBuilderVersion + ', Framework: ' + installedFrameworkVersion); + callback(); + }, + function(callback) { + console.log('Checking available Builder upgrades'); + // 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) { + console.log('Checking available Framework upgrades'); + // 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) { + // For now - we should only worry about v1 tags of the framework + async.detectSeries(tagInfo, function(tag, callback) { + if (tag.name.split('.')[0] == 'v1') { + callback(tag); + } + }, function(latestVersion) { + + latestFrameworkTag = latestVersion.name; + callback(); + + }); + } + + } + }); + }, + function(callback) { + // Check what needs upgrading + if (latestBuilderTag != installedBuilderVersion) { + shouldUpdateBuilder = true; + console.log('Update for Builder is available: ' + latestBuilderTag); + } + + if (latestFrameworkTag != installedFrameworkVersion) { + shouldUpdateFramework = true; + console.log('Update for Framework is available: ' + latestFrameworkTag); + } + + // If neither of the Builder or Framework need updating then quit the upgrading process + if (!shouldUpdateFramework && !shouldUpdateBuilder) { + console.log('No updates available at this time'); + process.exit(0); + } + + callback(); + }, function(callback) { + // Upgrade Builder if we need to + if (shouldUpdateBuilder) { + + upgradeBuilder(latestBuilderTag, function(err) { + if (err) { + return callback(err); + } + callback(); + }); + + } else { + callback(); + } + + }, function(callback) { + // Upgrade Framework if we need to + if (shouldUpdateFramework) { + console.log('Upgrading Framework'); + } else { + callback(); + } + }] + + +/*console.log('Latest ' + latestBuilderTag); +console.log(installedBuilderVersion + latestBuilderTag); +console.log(installedFrameworkVersion + latestFrameworkTag);*/ + +/*prompt.message = '> '; +prompt.delimiter = '';*/ + +prompt.start(); + +// Prompt the user to begin the install +console.log('This will update the Adapt builder to the latest version. Would you like to continue?'); +prompt.get({ name: 'Y/n', type: 'string', default: 'Y' }, function (err, result) { + if (!/(Y|y)[es]*$/.test(result['Y/n'])) { + return exitUpgrade(); + } + + //return exitUpgrade(1, 'whateva'); + + // run steps + async.series(steps, function (err, results) { + if (err) { + console.log('ERROR: ', err); + return exitUpgrade(1, 'Upgrade was unsuccessful. Please check the console output.'); + } + + exitUpgrade(); + }); +}); + +// This upgrades the Framework +function upgradeFramework(tagName, callback) { + +} + +// This upgrades the Builder +function upgradeBuilder(tagName, callback) { + console.log('Upgrading...please hold on!') + var child = exec('git fetch origin', { + stdio: [0, 'pipe', 'pipe'] + }); + + child.stdout.on('data', function(err) { + console.log(err); + }); + child.stderr.on('data', function(err) { + console.log(err); + }); + + child.on('exit', function (error, stdout, stderr) { + if (error) { + console.log('ERROR: ' + error); + return next(error); + } + + console.log("Fetch from github was successful.\n"); + console.log("Pulling latest changes"); + var secondChild = exec('git reset --hard ' + tagName, { + stdio: [0, 'pipe', 'pipe'] + }); + + secondChild.stdout.on('data', function(err) { + console.log(err); + }); + secondChild.stderr.on('data', function(err) { + console.log(err); + }); + + secondChild.on('exit', function (error, stdout, stderr) { + if (error) { + console.log('ERROR: ' + error); + return next(error); + } + + console.log("Pulled the big one.\n"); + //return installFramework(next); + }); + //return installFramework(next); + }); +} + +/** + * Exits the install with some cleanup, should there be an error + * + * @param {int} code + * @param {string} msg + */ + +function exitUpgrade (code, msg) { + code = code || 0; + msg = msg || 'Bye!'; + console.log(msg); + + // handle borked tenant, users, in case of a non-zero exit + // if (0 !== code) { + // if (app && app.db) { + // if (masterTenant) { + // return app.db.destroy('tenant', { _id: masterTenant._id }, function (err) { + // if (superUser) { + // return app.db.destroy('user', { _id: superUser._id }, function (err) { + // return process.exit(code); + // }); + // } + + // return process.exit(code); + // }); + // } + // } + // } + + process.exit(code); +} \ No newline at end of file From 70e24ed24f3e244c6983eeb9606d44f4e1db8781 Mon Sep 17 00:00:00 2001 From: Daryl Hedley Date: Tue, 19 May 2015 14:01:57 +0100 Subject: [PATCH 08/21] Updates to upgrade --- upgrade.js | 231 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 231 insertions(+) create mode 100644 upgrade.js diff --git a/upgrade.js b/upgrade.js new file mode 100644 index 0000000000..3ebbc97fab --- /dev/null +++ b/upgrade.js @@ -0,0 +1,231 @@ +var prompt = require('prompt'); +var fs = require('fs'); +var request = require('request'); +var async = require('async'); +var exec = require('child_process').exec; + +// GLOBALS +var installedBuilderVersion = ''; +var latestBuilderTag = ''; +var installedFrameworkVersion = ''; +var latestFrameworkTag = ''; +var shouldUpdateBuilder = false; +var shouldUpdateFramework = false; +var versionFile = JSON.parse(fs.readFileSync('version.json'), {encoding: 'utf8'}); + +var steps = [ + function(callback) { + console.log('Checking versions'); + + if (versionFile) { + installedBuilderVersion = versionFile.adapt_authoring; + installedFrameworkVersion = versionFile.adapt_framework; + } + console.log('Currently installed versions. Builder: ' + installedBuilderVersion + ', Framework: ' + installedFrameworkVersion); + callback(); + }, + function(callback) { + console.log('Checking available Builder upgrades'); + // 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) { + console.log('Checking available Framework upgrades'); + // 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) { + // For now - we should only worry about v1 tags of the framework + async.detectSeries(tagInfo, function(tag, callback) { + if (tag.name.split('.')[0] == 'v1') { + callback(tag); + } + }, function(latestVersion) { + + latestFrameworkTag = latestVersion.name; + callback(); + + }); + } + + } + }); + }, + function(callback) { + // Check what needs upgrading + if (latestBuilderTag != installedBuilderVersion) { + shouldUpdateBuilder = true; + console.log('Update for Builder is available: ' + latestBuilderTag); + } + + if (latestFrameworkTag != installedFrameworkVersion) { + shouldUpdateFramework = true; + console.log('Update for Framework is available: ' + latestFrameworkTag); + } + + // If neither of the Builder or Framework need updating then quit the upgrading process + if (!shouldUpdateFramework && !shouldUpdateBuilder) { + console.log('No updates available at this time'); + process.exit(0); + } + + callback(); + }, function(callback) { + // Upgrade Builder if we need to + if (shouldUpdateBuilder) { + + upgradeBuilder(latestBuilderTag, function(err) { + if (err) { + return callback(err); + } + callback(); + }); + + } else { + callback(); + } + + }, function(callback) { + // Upgrade Framework if we need to + if (shouldUpdateFramework) { + console.log('Upgrading Framework'); + } else { + callback(); + } + }] + + +/*console.log('Latest ' + latestBuilderTag); +console.log(installedBuilderVersion + latestBuilderTag); +console.log(installedFrameworkVersion + latestFrameworkTag);*/ + +/*prompt.message = '> '; +prompt.delimiter = '';*/ + +prompt.start(); + +// Prompt the user to begin the install +console.log('This will update the Adapt builder to the latest version. Would you like to continue?'); +prompt.get({ name: 'Y/n', type: 'string', default: 'Y' }, function (err, result) { + if (!/(Y|y)[es]*$/.test(result['Y/n'])) { + return exitUpgrade(); + } + + //return exitUpgrade(1, 'whateva'); + + // run steps + async.series(steps, function (err, results) { + if (err) { + console.log('ERROR: ', err); + return exitUpgrade(1, 'Upgrade was unsuccessful. Please check the console output.'); + } + + exitUpgrade(); + }); +}); + +// This upgrades the Framework +function upgradeFramework(tagName, callback) { + +} + +// This upgrades the Builder +function upgradeBuilder(tagName, callback) { + console.log('Upgrading...please hold on!') + var child = exec('git fetch origin', { + stdio: [0, 'pipe', 'pipe'] + }); + + child.stdout.on('data', function(err) { + console.log(err); + }); + child.stderr.on('data', function(err) { + console.log(err); + }); + + child.on('exit', function (error, stdout, stderr) { + if (error) { + return console.log('ERROR: ' + error); + + } + + console.log("Fetch from github was successful.\n"); + console.log("Pulling latest changes"); + var secondChild = exec('git reset --hard ' + tagName, { + stdio: [0, 'pipe', 'pipe'] + }); + + secondChild.stdout.on('data', function(err) { + console.log(err); + }); + secondChild.stderr.on('data', function(err) { + console.log(err); + }); + + secondChild.on('exit', function (error, stdout, stderr) { + if (error) { + return console.log('ERROR: ' + error); + } + + callback(); + console.log("Pulled the big one.\n"); + + }); + + }); +} + +/** + * Exits the install with some cleanup, should there be an error + * + * @param {int} code + * @param {string} msg + */ + +function exitUpgrade (code, msg) { + code = code || 0; + msg = msg || 'Bye!'; + console.log(msg); + + // handle borked tenant, users, in case of a non-zero exit + // if (0 !== code) { + // if (app && app.db) { + // if (masterTenant) { + // return app.db.destroy('tenant', { _id: masterTenant._id }, function (err) { + // if (superUser) { + // return app.db.destroy('user', { _id: superUser._id }, function (err) { + // return process.exit(code); + // }); + // } + + // return process.exit(code); + // }); + // } + // } + // } + + process.exit(code); +} \ No newline at end of file From 82550a82bb713bc9db0df64a12aaaf339baadf04 Mon Sep 17 00:00:00 2001 From: Daryl Hedley Date: Tue, 19 May 2015 14:13:26 +0100 Subject: [PATCH 09/21] Added framework upgrade --- upgrade.js | 69 ++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 49 insertions(+), 20 deletions(-) diff --git a/upgrade.js b/upgrade.js index 73fd0d2aa5..9919d606c9 100644 --- a/upgrade.js +++ b/upgrade.js @@ -12,6 +12,7 @@ var latestFrameworkTag = ''; var shouldUpdateBuilder = false; var shouldUpdateFramework = false; var versionFile = JSON.parse(fs.readFileSync('version.json'), {encoding: 'utf8'}); +var configFile = JSON.parse(fs.readFileSync('conf/config.json'), {encoding: 'utf8'}); var steps = [ function(callback) { @@ -111,7 +112,12 @@ var steps = [ }, function(callback) { // Upgrade Framework if we need to if (shouldUpdateFramework) { - console.log('Upgrading Framework'); + upgradeFramework(latestFrameworkTag, function(err) { + if (err) { + return callback(err); + } + callback(); + }); } else { callback(); } @@ -149,12 +155,53 @@ prompt.get({ name: 'Y/n', type: 'string', default: 'Y' }, function (err, result) // This upgrades the Framework function upgradeFramework(tagName, callback) { + console.log('Upgrading the Framework...please hold on!'); + var child = exec('git fetch origin', { + cwd: 'temp/' + configFile.masterTenantID + '/adapt_framework', + stdio: [0, 'pipe', 'pipe'] + }); + + child.stdout.on('data', function(err) { + console.log(err); + }); + child.stderr.on('data', function(err) { + console.log(err); + }); + + child.on('exit', function (error, stdout, stderr) { + if (error) { + return console.log('ERROR: ' + error); + } + + console.log("Fetch from github was successful.\n"); + console.log("Pulling latest changes"); + var secondChild = exec('git reset --hard ' + tagName, { + stdio: [0, 'pipe', 'pipe'] + }); + + secondChild.stdout.on('data', function(err) { + console.log(err); + }); + secondChild.stderr.on('data', function(err) { + console.log(err); + }); + + secondChild.on('exit', function (error, stdout, stderr) { + if (error) { + return console.log('ERROR: ' + error); + } + + callback(); + console.log("Pulled the big one.\n"); + }); + + }); } // This upgrades the Builder function upgradeBuilder(tagName, callback) { - console.log('Upgrading...please hold on!') + console.log('Upgrading the Builder...please hold on!'); var child = exec('git fetch origin', { stdio: [0, 'pipe', 'pipe'] }); @@ -208,23 +255,5 @@ function exitUpgrade (code, msg) { code = code || 0; msg = msg || 'Bye!'; console.log(msg); - - // handle borked tenant, users, in case of a non-zero exit - // if (0 !== code) { - // if (app && app.db) { - // if (masterTenant) { - // return app.db.destroy('tenant', { _id: masterTenant._id }, function (err) { - // if (superUser) { - // return app.db.destroy('user', { _id: superUser._id }, function (err) { - // return process.exit(code); - // }); - // } - - // return process.exit(code); - // }); - // } - // } - // } - process.exit(code); } \ No newline at end of file From a4eea49b49983e59cda6c90977ce4792db49d5f7 Mon Sep 17 00:00:00 2001 From: Daryl Hedley Date: Tue, 19 May 2015 14:21:29 +0100 Subject: [PATCH 10/21] moved version back a number --- version.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.json b/version.json index c52a5759d5..d3f9714b8f 100644 --- a/version.json +++ b/version.json @@ -1,4 +1,4 @@ { "adapt_authoring": "v0.0.9", - "adapt_framework": "v1.1.1" + "adapt_framework": "v1.1.0" } \ No newline at end of file From 46f461dcae8e9bf9fdc594622c1b2ee79954cbec Mon Sep 17 00:00:00 2001 From: Daryl Hedley Date: Tue, 19 May 2015 14:32:20 +0100 Subject: [PATCH 11/21] Fixes issue with cwd not being set --- upgrade.js | 1 + 1 file changed, 1 insertion(+) diff --git a/upgrade.js b/upgrade.js index 9919d606c9..137b307af2 100644 --- a/upgrade.js +++ b/upgrade.js @@ -176,6 +176,7 @@ function upgradeFramework(tagName, callback) { console.log("Fetch from github was successful.\n"); console.log("Pulling latest changes"); var secondChild = exec('git reset --hard ' + tagName, { + cwd: 'temp/' + configFile.masterTenantID + '/adapt_framework', stdio: [0, 'pipe', 'pipe'] }); From 7e29fe8ebd51729e246482fda48c961c6a3f2807 Mon Sep 17 00:00:00 2001 From: Daryl Hedley Date: Tue, 19 May 2015 14:44:07 +0100 Subject: [PATCH 12/21] Adds version.json file to be updated --- upgrade.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/upgrade.js b/upgrade.js index 137b307af2..73e4062085 100644 --- a/upgrade.js +++ b/upgrade.js @@ -102,6 +102,7 @@ var steps = [ if (err) { return callback(err); } + versionFile.adapt_authoring = latestBuilderTag; callback(); }); @@ -116,11 +117,22 @@ var steps = [ if (err) { return callback(err); } + versionFile.adapt_framework = latestFrameworkTag; callback(); }); } else { callback(); } + }, function(callback) { + // After upgrading let's update the version.json to the latest version + + fs.writeFile('version.json', JSON.stringify(versionFile, null, 4), function(err) { + if(err) { + console.log(err); + } else { + console.log("Version file updated"); + } + }); }]; From 8a13359d92a294d704f5381f1a9d89fabcd73677 Mon Sep 17 00:00:00 2001 From: Daryl Hedley Date: Tue, 19 May 2015 14:55:30 +0100 Subject: [PATCH 13/21] Sorted out spacing --- upgrade.js | 62 +++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 47 insertions(+), 15 deletions(-) diff --git a/upgrade.js b/upgrade.js index 73e4062085..8663d16d7a 100644 --- a/upgrade.js +++ b/upgrade.js @@ -16,16 +16,20 @@ var configFile = JSON.parse(fs.readFileSync('conf/config.json'), {encoding: 'utf var steps = [ function(callback) { + console.log('Checking versions'); if (versionFile) { installedBuilderVersion = versionFile.adapt_authoring; installedFrameworkVersion = versionFile.adapt_framework; } + console.log('Currently installed versions. Builder: ' + installedBuilderVersion + ', Framework: ' + installedFrameworkVersion); callback(); + }, function(callback) { + console.log('Checking available Builder upgrades'); // Check the latest version of the project request({ @@ -35,18 +39,22 @@ var steps = [ 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) { + console.log('Checking available Framework upgrades'); // Check the latest version of the framework request({ @@ -58,6 +66,7 @@ var steps = [ }, function (error, response, body) { if (!error && response.statusCode == 200) { var tagInfo = JSON.parse(body); + if (tagInfo) { // For now - we should only worry about v1 tags of the framework async.detectSeries(tagInfo, function(tag, callback) { @@ -74,6 +83,7 @@ var steps = [ } }); + }, function(callback) { // Check what needs upgrading @@ -94,6 +104,7 @@ var steps = [ } callback(); + }, function(callback) { // Upgrade Builder if we need to if (shouldUpdateBuilder) { @@ -102,8 +113,10 @@ var steps = [ if (err) { return callback(err); } + versionFile.adapt_authoring = latestBuilderTag; callback(); + }); } else { @@ -111,21 +124,27 @@ var steps = [ } }, function(callback) { + // Upgrade Framework if we need to if (shouldUpdateFramework) { + upgradeFramework(latestFrameworkTag, function(err) { if (err) { return callback(err); } + versionFile.adapt_framework = latestFrameworkTag; callback(); + }); + } else { callback(); } + }, function(callback) { - // After upgrading let's update the version.json to the latest version + // After upgrading let's update the version.json to the latest version fs.writeFile('version.json', JSON.stringify(versionFile, null, 4), function(err) { if(err) { console.log(err); @@ -133,6 +152,10 @@ var steps = [ console.log("Version file updated"); } }); + + }, function(callback) { + // Left empty for any upgrade scripts - just remember to call the callback when done. + callback(); }]; @@ -156,20 +179,22 @@ prompt.get({ name: 'Y/n', type: 'string', default: 'Y' }, function (err, result) // run steps async.series(steps, function (err, results) { + if (err) { console.log('ERROR: ', err); return exitUpgrade(1, 'Upgrade was unsuccessful. Please check the console output.'); } - exitUpgrade(); + exitUpgrade('Great work! Your builder is now updated.'); + }); }); -// This upgrades the Framework -function upgradeFramework(tagName, callback) { - console.log('Upgrading the Framework...please hold on!'); +// This upgrades the Builder +function upgradeBuilder(tagName, callback) { + + console.log('Upgrading the Builder...please hold on!'); var child = exec('git fetch origin', { - cwd: 'temp/' + configFile.masterTenantID + '/adapt_framework', stdio: [0, 'pipe', 'pipe'] }); @@ -186,15 +211,16 @@ function upgradeFramework(tagName, callback) { } console.log("Fetch from github was successful.\n"); - console.log("Pulling latest changes"); + console.log("Pulling latest changes..."); + var secondChild = exec('git reset --hard ' + tagName, { - cwd: 'temp/' + configFile.masterTenantID + '/adapt_framework', stdio: [0, 'pipe', 'pipe'] }); secondChild.stdout.on('data', function(err) { console.log(err); }); + secondChild.stderr.on('data', function(err) { console.log(err); }); @@ -204,24 +230,27 @@ function upgradeFramework(tagName, callback) { return console.log('ERROR: ' + error); } + console.log("Builder has been updated."); callback(); - console.log("Pulled the big one.\n"); }); }); } -// This upgrades the Builder -function upgradeBuilder(tagName, callback) { - console.log('Upgrading the Builder...please hold on!'); +// This upgrades the Framework +function upgradeFramework(tagName, callback) { + console.log('Upgrading the Framework...please hold on!'); + var child = exec('git fetch origin', { + cwd: 'temp/' + configFile.masterTenantID + '/adapt_framework', stdio: [0, 'pipe', 'pipe'] }); child.stdout.on('data', function(err) { console.log(err); }); + child.stderr.on('data', function(err) { console.log(err); }); @@ -232,14 +261,17 @@ function upgradeBuilder(tagName, callback) { } console.log("Fetch from github was successful.\n"); - console.log("Pulling latest changes"); + console.log("Pulling latest changes..."); + var secondChild = exec('git reset --hard ' + tagName, { + cwd: 'temp/' + configFile.masterTenantID + '/adapt_framework', stdio: [0, 'pipe', 'pipe'] }); secondChild.stdout.on('data', function(err) { console.log(err); }); + secondChild.stderr.on('data', function(err) { console.log(err); }); @@ -249,8 +281,8 @@ function upgradeBuilder(tagName, callback) { return console.log('ERROR: ' + error); } + console.log("Framework has been updated."); callback(); - console.log("Pulled the big one.\n"); }); From 2751fc1f1821c0413aadc88b79cc4028f476a447 Mon Sep 17 00:00:00 2001 From: Daryl Hedley Date: Tue, 19 May 2015 14:57:22 +0100 Subject: [PATCH 14/21] added new lines to consoles --- upgrade.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/upgrade.js b/upgrade.js index 8663d16d7a..6e4ed0274a 100644 --- a/upgrade.js +++ b/upgrade.js @@ -30,7 +30,7 @@ var steps = [ }, function(callback) { - console.log('Checking available Builder upgrades'); + console.log('Checking available Builder upgrades\n'); // Check the latest version of the project request({ headers: { @@ -55,7 +55,7 @@ var steps = [ }, function(callback) { - console.log('Checking available Framework upgrades'); + console.log('Checking available Framework upgrades\n'); // Check the latest version of the framework request({ headers: { @@ -99,7 +99,7 @@ var steps = [ // If neither of the Builder or Framework need updating then quit the upgrading process if (!shouldUpdateFramework && !shouldUpdateBuilder) { - console.log('No updates available at this time'); + console.log('No updates available at this time\n'); process.exit(0); } @@ -149,7 +149,7 @@ var steps = [ if(err) { console.log(err); } else { - console.log("Version file updated"); + console.log("Version file updated\n"); } }); @@ -210,7 +210,7 @@ function upgradeBuilder(tagName, callback) { return console.log('ERROR: ' + error); } - console.log("Fetch from github was successful.\n"); + console.log("Fetch from github was successful."); console.log("Pulling latest changes..."); var secondChild = exec('git reset --hard ' + tagName, { @@ -230,7 +230,7 @@ function upgradeBuilder(tagName, callback) { return console.log('ERROR: ' + error); } - console.log("Builder has been updated."); + console.log("Builder has been updated.\n"); callback(); }); @@ -260,7 +260,7 @@ function upgradeFramework(tagName, callback) { return console.log('ERROR: ' + error); } - console.log("Fetch from github was successful.\n"); + console.log("Fetch from github was successful."); console.log("Pulling latest changes..."); var secondChild = exec('git reset --hard ' + tagName, { @@ -281,7 +281,7 @@ function upgradeFramework(tagName, callback) { return console.log('ERROR: ' + error); } - console.log("Framework has been updated."); + console.log("Framework has been updated.\n"); callback(); }); From b6f94ef244a06cfb503fe349ffb6cc80269cf8a9 Mon Sep 17 00:00:00 2001 From: Daryl Hedley Date: Tue, 19 May 2015 15:07:57 +0100 Subject: [PATCH 15/21] Updated comments and static code --- upgrade.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/upgrade.js b/upgrade.js index 6e4ed0274a..555787ff18 100644 --- a/upgrade.js +++ b/upgrade.js @@ -30,7 +30,7 @@ var steps = [ }, function(callback) { - console.log('Checking available Builder upgrades\n'); + console.log('Checking available Builder upgrades.'); // Check the latest version of the project request({ headers: { @@ -55,7 +55,7 @@ var steps = [ }, function(callback) { - console.log('Checking available Framework upgrades\n'); + console.log('Checking available Framework upgrades.'); // Check the latest version of the framework request({ headers: { @@ -185,7 +185,7 @@ prompt.get({ name: 'Y/n', type: 'string', default: 'Y' }, function (err, result) return exitUpgrade(1, 'Upgrade was unsuccessful. Please check the console output.'); } - exitUpgrade('Great work! Your builder is now updated.'); + exitUpgrade(0, 'Great work! Your builder is now updated.'); }); }); From 799a614eae1cf9eaf4504860b4a4048332146c68 Mon Sep 17 00:00:00 2001 From: Daryl Hedley Date: Tue, 19 May 2015 15:11:03 +0100 Subject: [PATCH 16/21] Added missing callback --- upgrade.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/upgrade.js b/upgrade.js index 555787ff18..1589525f3c 100644 --- a/upgrade.js +++ b/upgrade.js @@ -147,9 +147,10 @@ var steps = [ // After upgrading let's update the version.json to the latest version fs.writeFile('version.json', JSON.stringify(versionFile, null, 4), function(err) { if(err) { - console.log(err); + callback(err); } else { console.log("Version file updated\n"); + callback(); } }); From 083603ac5b9e28416301798826ee69cbd16d56a3 Mon Sep 17 00:00:00 2001 From: Daryl Hedley Date: Tue, 19 May 2015 15:13:26 +0100 Subject: [PATCH 17/21] removed stringify --- plugins/content/course/index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/content/course/index.js b/plugins/content/course/index.js index 948d75ae8e..4024ca86d9 100644 --- a/plugins/content/course/index.js +++ b/plugins/content/course/index.js @@ -47,7 +47,6 @@ function initialize () { var options = _.keys(req.body).length ? req.body : req.query; - options = JSON.stringify(options); var search = options.search || {}; var self = this; var orList = []; From 0beb39cdedfcb469a6ecd486e987ad5f82cd29ce Mon Sep 17 00:00:00 2001 From: Daryl Hedley Date: Tue, 19 May 2015 15:23:21 +0100 Subject: [PATCH 18/21] updated the version.json back to the real release tags --- version.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/version.json b/version.json index d3f9714b8f..fb064357f1 100644 --- a/version.json +++ b/version.json @@ -1,4 +1,4 @@ { - "adapt_authoring": "v0.0.9", - "adapt_framework": "v1.1.0" + "adapt_authoring": "v0.1.0", + "adapt_framework": "v1.1.1" } \ No newline at end of file From 3ae623f656dad2a3c9420a4bc366991be55c9d82 Mon Sep 17 00:00:00 2001 From: Brian Quinn Date: Wed, 1 Jul 2015 16:43:13 +0100 Subject: [PATCH 19/21] Slight tidy-up of install/upgrade process - Removed 'colors' library in favour of 'chalk' - Added missing error logging -- the install process would hang if the mongod service was not running - Minor string changes --- install.js | 15 ++++++++------- lib/frameworkhelper.js | 1 - lib/tenantmanager.js | 5 +++++ package.json | 1 - upgrade.js | 43 ++++++++++++++++++------------------------ 5 files changed, 31 insertions(+), 34 deletions(-) diff --git a/install.js b/install.js index a3a8dd5816..127f5fbc48 100644 --- a/install.js +++ b/install.js @@ -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'), @@ -124,7 +123,8 @@ var configItems = [ { name: 'smtpUsername', type: 'string', - description: "SMTP username" + description: "SMTP username", + default: '' }, { name: 'smtpPassword', @@ -135,7 +135,8 @@ var configItems = [ { name: 'fromAddress', type: 'string', - description: "Sender email address" + description: "Sender email address", + default: '' }, { name: 'outputPlugin', @@ -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' }, @@ -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); @@ -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, @@ -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); diff --git a/lib/frameworkhelper.js b/lib/frameworkhelper.js index e151fbeaf3..e2e4596c34 100644 --- a/lib/frameworkhelper.js +++ b/lib/frameworkhelper.js @@ -2,7 +2,6 @@ var path = require('path'), fs = require('fs'), util = require('util'), - colors = require('colors'), exec = require('child_process').exec; // errors diff --git a/lib/tenantmanager.js b/lib/tenantmanager.js index 0bdaeb5ad4..f3fdc82b71 100644 --- a/lib/tenantmanager.js +++ b/lib/tenantmanager.js @@ -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')); diff --git a/package.json b/package.json index 3f2ae29e97..7161a9a8c5 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,6 @@ "bower": "1.3", "casperjs": "1.1.0-beta3", "chalk": "^1.0.0", - "colors": "1.0.3", "connect-mongo": "0.4.x", "consolidate": "0.10.0", "express": "3.4.0", diff --git a/upgrade.js b/upgrade.js index 1589525f3c..fa3464043d 100644 --- a/upgrade.js +++ b/upgrade.js @@ -4,6 +4,9 @@ var request = require('request'); var async = require('async'); var exec = require('child_process').exec; +// Constants +var DEFAULT_USER_AGENT = 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.118 Safari/537.36'; + // GLOBALS var installedBuilderVersion = ''; var latestBuilderTag = ''; @@ -24,17 +27,17 @@ var steps = [ installedFrameworkVersion = versionFile.adapt_framework; } - console.log('Currently installed versions. Builder: ' + installedBuilderVersion + ', Framework: ' + installedFrameworkVersion); + console.log('Currently installed versions:\n- Adapt Builder: ' + installedBuilderVersion + '\n- Adapt Framework: ' + installedFrameworkVersion); callback(); }, function(callback) { - console.log('Checking available Builder upgrades.'); + console.log('Checking for Adapt Builder upgrades...'); // 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' + 'User-Agent' : DEFAULT_USER_AGENT }, uri: 'https://api.github.com/repos/adaptlearning/adapt_authoring/tags', method: 'GET' @@ -55,11 +58,11 @@ var steps = [ }, function(callback) { - console.log('Checking available Framework upgrades.'); + console.log('Checking for Adapt Framework upgrades...'); // 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' + 'User-Agent' : DEFAULT_USER_AGENT }, uri: 'https://api.github.com/repos/adaptlearning/adapt_framework/tags', method: 'GET' @@ -89,12 +92,12 @@ var steps = [ // Check what needs upgrading if (latestBuilderTag != installedBuilderVersion) { shouldUpdateBuilder = true; - console.log('Update for Builder is available: ' + latestBuilderTag); + console.log('Update for Adapt Builder is available: ' + latestBuilderTag); } if (latestFrameworkTag != installedFrameworkVersion) { shouldUpdateFramework = true; - console.log('Update for Framework is available: ' + latestFrameworkTag); + console.log('Update for Adapt Framework is available: ' + latestFrameworkTag); } // If neither of the Builder or Framework need updating then quit the upgrading process @@ -157,26 +160,17 @@ var steps = [ }, function(callback) { // Left empty for any upgrade scripts - just remember to call the callback when done. callback(); - }]; - - -/*console.log('Latest ' + latestBuilderTag); -console.log(installedBuilderVersion + latestBuilderTag); -console.log(installedFrameworkVersion + latestFrameworkTag);*/ - -/*prompt.message = '> '; -prompt.delimiter = '';*/ + } +]; prompt.start(); // Prompt the user to begin the install -console.log('This will update the Adapt builder to the latest version. Would you like to continue?'); +console.log('This script will update the Adapt Builder (and/or Adapt Framework) to the latest released version. Would you like to continue?'); prompt.get({ name: 'Y/n', type: 'string', default: 'Y' }, function (err, result) { if (!/(Y|y)[es]*$/.test(result['Y/n'])) { return exitUpgrade(); } - - //return exitUpgrade(1, 'whateva'); // run steps async.series(steps, function (err, results) { @@ -186,15 +180,14 @@ prompt.get({ name: 'Y/n', type: 'string', default: 'Y' }, function (err, result) return exitUpgrade(1, 'Upgrade was unsuccessful. Please check the console output.'); } - exitUpgrade(0, 'Great work! Your builder is now updated.'); - + exitUpgrade(0, 'Great work! Your Adapt Builder is now updated.'); }); }); // This upgrades the Builder function upgradeBuilder(tagName, callback) { - console.log('Upgrading the Builder...please hold on!'); + console.log('Upgrading the Adapt Builder...please hold on!'); var child = exec('git fetch origin', { stdio: [0, 'pipe', 'pipe'] }); @@ -211,7 +204,7 @@ function upgradeBuilder(tagName, callback) { return console.log('ERROR: ' + error); } - console.log("Fetch from github was successful."); + console.log("Fetch from GitHub was successful."); console.log("Pulling latest changes..."); var secondChild = exec('git reset --hard ' + tagName, { @@ -241,7 +234,7 @@ function upgradeBuilder(tagName, callback) { // This upgrades the Framework function upgradeFramework(tagName, callback) { - console.log('Upgrading the Framework...please hold on!'); + console.log('Upgrading the Adapt Framework...please hold on!'); var child = exec('git fetch origin', { cwd: 'temp/' + configFile.masterTenantID + '/adapt_framework', @@ -261,7 +254,7 @@ function upgradeFramework(tagName, callback) { return console.log('ERROR: ' + error); } - console.log("Fetch from github was successful."); + console.log("Fetch from GitHub was successful."); console.log("Pulling latest changes..."); var secondChild = exec('git reset --hard ' + tagName, { From a1faaab6c357571db7b0ad2e3f9b43320547a97b Mon Sep 17 00:00:00 2001 From: Brian Quinn Date: Wed, 1 Jul 2015 17:06:49 +0100 Subject: [PATCH 20/21] Removed references to .grey This was using the old 'colors' library and missed from the previous commit. --- install.js | 2 +- lib/frameworkhelper.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/install.js b/install.js index 127f5fbc48..fc89b70f7a 100644 --- a/install.js +++ b/install.js @@ -317,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); }); }, diff --git a/lib/frameworkhelper.js b/lib/frameworkhelper.js index e2e4596c34..e15d9530a4 100644 --- a/lib/frameworkhelper.js +++ b/lib/frameworkhelper.js @@ -17,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) { From ece82978c6c311a8a219f764d6f21646e7e58d93 Mon Sep 17 00:00:00 2001 From: Brian Quinn Date: Wed, 1 Jul 2015 17:11:31 +0100 Subject: [PATCH 21/21] Removed another two instances of .grey A hangover from the 'colors' library. --- install.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/install.js b/install.js index fc89b70f7a..c3f54cc1de 100644 --- a/install.js +++ b/install.js @@ -373,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(); }