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

Add support for adapt_framework -> grunt server-build:dev #857

Merged
merged 35 commits into from
Nov 25, 2015
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
c727bd7
Adds ifUserIsMe and fixes inverse not being passed back
darylhedley Apr 15, 2015
d850fc8
Fixes #620
brian-learningpool Apr 15, 2015
9586a0b
Merge pull request #642 from adaptlearning/hotfix-620
brian-learningpool Apr 16, 2015
35b2da8
Merge pull request #641 from adaptlearning/issue/#639
brian-learningpool Apr 16, 2015
526cf16
Merge pull request #638 from adaptlearning/switch-ckeditor-to-cdn
brian-learningpool Apr 16, 2015
de1f2f2
Update README.md
brian-learningpool Apr 21, 2015
ac5047a
Merge branch 'develop'
brian-learningpool Jul 13, 2015
783b7bc
Update version.json
brian-learningpool Jul 13, 2015
f61f9bf
Merge pull request #751 from adaptlearning/release/0.1.1
brian-learningpool Jul 13, 2015
04b0c83
Update README.md
brian-learningpool Jul 13, 2015
4f37b42
Added Gitter badge
gitter-badger Jul 21, 2015
78689d1
Merge pull request #755 from gitter-badger/gitter-badge
brian-learningpool Jul 22, 2015
1185118
Add support for new server-build
taylortom Sep 22, 2015
53cf817
Whitespace amends
taylortom Sep 22, 2015
9aa2d85
Merge branch 'develop'
brian-learningpool Sep 30, 2015
fe07051
Update package.json
brian-learningpool Sep 30, 2015
fc3c5d8
Add source map toggle to config schema
taylortom Sep 30, 2015
3ae042c
Update adapt output plugin for sourcemapping
taylortom Sep 30, 2015
80d30cd
Fixes #881 - bug in isAssetExternal()
brian-learningpool Oct 6, 2015
ff6cff9
Merge pull request #882 from adaptlearning/issue/881
brian-learningpool Oct 7, 2015
526ec3e
Merge branch 'develop'
brian-learningpool Oct 21, 2015
ce20d09
Update version.json
brian-learningpool Oct 21, 2015
30a854c
Merge pull request #902 from adaptlearning/develop
brian-learningpool Oct 21, 2015
0cf5872
Merge pull request #904 from adaptlearning/develop
brian-learningpool Oct 22, 2015
aba99d8
Renamed function to isMasterPreviewAccessible()
brian-learningpool Oct 22, 2015
1f135b1
Corrected z-index issue with asset-management-modal-tags
brian-learningpool Oct 22, 2015
105b043
Merge pull request #915 from adaptlearning/develop
brian-learningpool Oct 27, 2015
43c4256
Remove DB query for course config
taylortom Nov 18, 2015
e43124c
Merge branch 'issue/811' of https://github.com/adaptlearning/adapt_au…
brian-learningpool Nov 23, 2015
a962af2
Remove trailing comma
taylortom Nov 24, 2015
233b7c2
Set config updates to PATCH
taylortom Nov 24, 2015
23a7776
Merge branch 'issue/811' of https://github.com/adaptlearning/adapt_au…
brian-learningpool Nov 24, 2015
a7871d1
Define usermanager
taylortom Nov 25, 2015
d81ac64
Tidied up PATCH request for config update
brian-learningpool Nov 25, 2015
f395520
Merge branches 'issue/811' and 'issue/811' of https://github.com/adap…
brian-learningpool Nov 25, 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: 15 additions & 6 deletions plugins/content/config/model.schema
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@
"required": true,
"default": "easeOutQuart",
"title": "Hide Easing",
"inputType": {
"type": "Select",
"inputType": {
"type": "Select",
"options": [
"easeInSine",
"easeInSine",
"easeOutSine",
"easeInOutSine",
"easeInQuad",
Expand Down Expand Up @@ -89,10 +89,10 @@
"required": true,
"default": "easeInQuart",
"title": "Hide Easing",
"inputType": {
"type": "Select",
"inputType": {
"type": "Select",
"options": [
"easeInSine",
"easeInSine",
"easeOutSine",
"easeInOutSine",
"easeInQuad",
Expand Down Expand Up @@ -135,6 +135,15 @@
"validators": ["required", "number"]
}
}
},
"_generateSourcemap": {
"type": "bool",
"default": "false",
"isSetting": true,
"inputType": {"type": "Boolean", "options": [true, false]},
"validators": [],
"title": "Generate sourcemap",
"help": "Creates a JavaScript sourcemap for the output code - useful for debugging (in browsers that support it)."
}
}
}
113 changes: 58 additions & 55 deletions plugins/output/adapt/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,35 +24,35 @@ var OutputPlugin = require('../../../lib/outputmanager').OutputPlugin,
version = require('../../../version'),
logger = require('../../../lib/logger');

function AdaptOutput () {
function AdaptOutput() {
}

util.inherits(AdaptOutput, OutputPlugin);

AdaptOutput.prototype.publish = function (courseId, isPreview, request, response, next) {
var self = this;
var user = usermanager.getCurrentUser(),
tenantId = user.tenant._id,
outputJson = {},
isRebuildRequired = false,
themeName = Constants.Defaults.ThemeName;
menuName = Constants.Defaults.MenuName;
AdaptOutput.prototype.publish = function(courseId, isPreview, request, response, next) {
var self = this;
var user = usermanager.getCurrentUser(),
tenantId = user.tenant._id,
outputJson = {},
isRebuildRequired = false,
themeName = Constants.Defaults.ThemeName;
menuName = Constants.Defaults.MenuName;

var resultObject = {};
var resultObject = {};

var FRAMEWORK_ROOT_FOLDER = path.join(configuration.tempDir, configuration.getConfig('masterTenantID'), Constants.Folders.Framework);
var FRAMEWORK_ROOT_FOLDER = path.join(configuration.tempDir, configuration.getConfig('masterTenantID'), Constants.Folders.Framework);

async.series([
async.series([
function(callback) {
self.getCourseJSON(tenantId, courseId, function(err, data) {
if (err) {
return callback(err);
}
if (err) {
return callback(err);
}

// Store off the retrieved collections
outputJson = data;
// Store off the retrieved collections
outputJson = data;

callback(null);
callback(null);
});
},
function(callback) {
Expand Down Expand Up @@ -119,7 +119,7 @@ AdaptOutput.prototype.publish = function (courseId, isPreview, request, response
});
},
function(callback) {
var assetsFolder = path.join(FRAMEWORK_ROOT_FOLDER, Constants.Folders.AllCourses, tenantId, courseId,
var assetsFolder = path.join(FRAMEWORK_ROOT_FOLDER, Constants.Folders.AllCourses, tenantId, courseId,
Constants.Folders.Build, Constants.Folders.Course, outputJson['config']._defaultLanguage, Constants.Folders.Assets);

self.writeCourseAssets(tenantId, courseId, assetsFolder, outputJson, function(err, modifiedJson) {
Expand All @@ -143,51 +143,54 @@ AdaptOutput.prototype.publish = function (courseId, isPreview, request, response
});
},
function(callback) {
fs.exists(path.join(FRAMEWORK_ROOT_FOLDER, Constants.Folders.AllCourses, tenantId, courseId, Constants.Folders.Build, Constants.Filenames.Main), function (exists) {
fs.exists(path.join(FRAMEWORK_ROOT_FOLDER, Constants.Folders.AllCourses, tenantId, courseId, Constants.Folders.Build, Constants.Filenames.Main), function(exists) {
if (!exists || isRebuildRequired) {
logger.log('info', '3.1. Ensuring framework build exists');

var args = [];
var outputFolder = path.join(Constants.Folders.AllCourses, tenantId, courseId);

// Append the 'build' folder to later versions of the framework
if (semver.gte(semver.clean(version.adapt_framework), semver.clean('2.0.0'))) {
outputFolder = path.join(outputFolder, Constants.Folders.Build);
}

args.push('--outputdir=' + outputFolder);
args.push('--theme=' + themeName);
args.push('--menu=' + menuName);

logger.log('info', '3.2. Using theme: ' + themeName);
logger.log('info', '3.3. Using menu: ' + menuName);

logger.log('info', 'grunt server-build ' + args.join(' '));

child = exec('grunt server-build ' + args.join(' '), {cwd: path.join(FRAMEWORK_ROOT_FOLDER)},
function (error, stdout, stderr) {
if (error !== null) {
logger.log('error', 'exec error: ' + error);
logger.log('error', 'stdout error: ' + stdout);
resultObject.success = true;
return callback(error, 'Error building framework');
}

if (stdout.length != 0) {
logger.log('info', 'stdout: ' + stdout);
resultObject.success = true;
return callback(null, 'Framework built OK');
}

if (stderr.length != 0) {
logger.log('error', 'stderr: ' + stderr);
resultObject.success = false;
return callback(stderr, 'Error (stderr) building framework!');
}

resultObject.success = true;
return callback(null, 'Framework built');
});
var generateSourcemap = outputJson.config._generateSourcemap;
var buildMode = generateSourcemap === true ? 'dev' : 'prod';

logger.log('info', 'grunt server-build:' + buildMode + ' ' + args.join(' '));

child = exec('grunt server-build:' + buildMode + ' ' + args.join(' '), {cwd: path.join(FRAMEWORK_ROOT_FOLDER)},
function(error, stdout, stderr) {
if (error !== null) {
logger.log('error', 'exec error: ' + error);
logger.log('error', 'stdout error: ' + stdout);
resultObject.success = true;
return callback(error, 'Error building framework');
}

if (stdout.length != 0) {
logger.log('info', 'stdout: ' + stdout);
resultObject.success = true;
return callback(null, 'Framework built OK');
}

if (stderr.length != 0) {
logger.log('error', 'stderr: ' + stderr);
resultObject.success = false;
return callback(stderr, 'Error (stderr) building framework!');
}

resultObject.success = true;
return callback(null, 'Framework built');
});
} else {
resultObject.success = true;
callback(null, 'Framework already built, nothing to do')
Expand Down Expand Up @@ -215,29 +218,29 @@ AdaptOutput.prototype.publish = function (courseId, isPreview, request, response
archive.pipe(output);

archive.bulk([
{ expand: true, cwd: path.join(FRAMEWORK_ROOT_FOLDER, Constants.Folders.AllCourses, tenantId, courseId, Constants.Folders.Build), src: ['**/*'] }
]).finalize();
{ expand: true, cwd: path.join(FRAMEWORK_ROOT_FOLDER, Constants.Folders.AllCourses, tenantId, courseId, Constants.Folders.Build), src: ['**/*'] },
]).finalize();

} else {
// No download required -- skip this step
callback();
}
}
}
},

Choose a reason for hiding this comment

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

usually wary of trailing commas in a JS array like this - is it ok?

Copy link
Member Author

Choose a reason for hiding this comment

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

Think I ran the jscs grunt task at some point which may have added this.

], function(err) {

if (err) {
logger.log('error', err);
return next(err);
}


return next(null, resultObject);
});
});

};
/**
* Module exports
*
*/

exports = module.exports = AdaptOutput;
exports = module.exports = AdaptOutput;