Permalink
Browse files

Fix merge conflicts

  • Loading branch information...
2 parents 9083e21 + 0924896 commit 5fe60267d26a99c602b2e7354b17896586216f5c @richtera richtera committed Jan 5, 2013
View
@@ -13,10 +13,8 @@
*
*/
var sys;
-var zip;
try {
sys = require('util');
- zip = require('zipfile')
}
catch (e) {
sys = require('sys');
@@ -30,10 +28,10 @@ calipso = require(path.join(rootpath, 'lib/calipso')),
exec = require('child_process').exec,
colors = require('colors'),
util = require('util'),
- zip,
fs = require('fs'),
- rimraf = require('rimraf')
-semver = require('semver');
+ rimraf = require('rimraf'),
+ semver = require('semver'),
+ zip = require('adm-zip');
/**
=======
@@ -371,31 +369,31 @@ function unzipDownload(type, file, callback) {
tmpFolder,
tmpName;
- try {
- zf = new zip.ZipFile(file)
- }
- catch (ex) {
- return callback(ex);
- }
+ zf = new zip(file, 'r');
+ entries = zf.getEntries();
- zf.names.forEach(function (name) {
-
- // First result is the basefolder
- if (!baseFolder) {
- baseFolder = name; // Store
+ entries.forEach(function (entry) {
+ var name = entry.entryName;
+ if (entry.isDirectory) {
+ // First result is the basefolder
+ if (!baseFolder) {
+ baseFolder = name;
+ } // Store
+ return;
}
+
// Now, lets find the package.json
if (type === 'module' && name === (baseFolder + "package.json")) {
- var buffer = zf.readFileSync(name);
+ var buffer = entry.getData();
var packageJson = JSON.parse(buffer);
tmpName = packageJson.name;
tmpFolder = path.join(path.dirname(file), tmpName + "/"); // Extraction will go here
}
// Now, lets find the theme.json
if (type === 'theme' && name === (baseFolder + "theme.json")) {
- var buffer = zf.readFileSync(name);
+ var buffer = entry.getData();
var themeJson = JSON.parse(buffer);
tmpName = themeJson.name;
tmpFolder = path.join(path.dirname(file), tmpName + "/"); // Extraction will go here
@@ -413,8 +411,13 @@ function unzipDownload(type, file, callback) {
// First run through and create every directory synchronously
var folders = [];
- zf.names.forEach(function (name) {
- folders.push(name.replace(baseFolder, "").split("/"));
+ entries.forEach(function (entry) {
+ var name = entry.entryName;
+ var p = name.replace(baseFolder, "").split("/");
+ if (!entry.isDirectory) {
+ p.splice(-1, 1);
+ }
+ folders.push(p);
});
folders.forEach(function (folderList) {
@@ -429,55 +432,60 @@ function unzipDownload(type, file, callback) {
});
// Now, lets extract all the files
- var remaining = zf.names.length;
-
- zf.names.forEach(function (name) {
+ var remaining = entries.length;
+ entries.forEach(function (entry) {
+ var name = entry.entryName;
var dest = path.join(
tmpFolder,
name.replace(baseFolder, "")
);
// Skip directories, hiddens.
- var isDir = (!path.extname(name) || name[0] === '.' || name[name.length] === "/");
- if (isDir) {
+ if (entry.isDirectory) {
remaining--;
if (!remaining) {
return callback(null);
}
} else {
- zf.readFile(name, function (err, buff) {
- if (err) {
- return callback(err);
+ var buff;
+ try {
+ buff = entry.getData();
+ if (!buff) {
+ return callback(new Error('Unable to read content'));
}
- fs.open(dest, 'w', 0644, function (err, fd) {
- if (err) {
- if (err.code !== "EISDIR") {
- // fs.unlinkSync(file);
+ }
+ catch (err) {
+ return callback(err);
+ }
+ console.log('Downloaded ', name, buff.length);
+ fs.open(dest, 'w', 0644, function (err, fd) {
+ if (err) {
+ if (err.code !== "EISDIR") {
+ // fs.unlinkSync(file);
+ return callback(err);
+ } else {
+ remaining--;
+ }
+
+ } else {
+ fs.write(fd, buff, 0, buff.length, null, function (err) {
+ if (err) {
+ fs.unlinkSync(file);
return callback(err);
- } else {
- remaining--;
}
-
- } else {
- fs.write(fd, buff, 0, buff.length, null, function (err) {
+ fs.close(fd, function (err) {
if (err) {
- fs.unlinkSync(file);
return callback(err);
}
- fs.close(fd, function (err) {
- if (err) {
- return callback(err);
- }
- remaining--;
- if (!remaining) {
- fs.unlinkSync(file);
- callback(null, tmpName, tmpFolder);
- }
- });
+ remaining--;
+ if (!remaining) {
+ fs.unlinkSync(file);
+ callback(null, tmpName, tmpFolder);
+ }
});
- }
- });
+ });
+ }
});
}
});
View
@@ -370,38 +370,45 @@ function initModule(module, depends) {
var express = require('express');
calipso.app.use(express["static"](p, {maxAge:86400000}));
}
-
- // If the module has no dependencies, kick start it
- if (depends || !calipso.modules[module].fn.depends) {
-
- // Init start event
- calipso.modules[module].event.init_start();
-
- // Next run any init functions
- calipso.modules[module].fn.init(calipso.modules[module], calipso.app, function (err) {
-
- // Init finish event
- calipso.modules[module].inited = true;
- calipso.modules[module].event.init_finish();
-
- // Now, load any routes to go along with it
- if (calipso.modules[module].fn.routes && calipso.modules[module].fn.routes.length > 0) {
- calipso.lib.async.map(calipso.modules[module].fn.routes, function (options, next) {
- calipso.modules[module].router.addRoute(options, next);
- }, function (err, data) {
- if (err) {
- calipso.error(err);
- }
+ p = path.join(calipso.modules[module].router.modulePath, 'theme-extension.json');
+ if ((fs.existsSync || path.existsSync)(p)) {
+ var moduleThemeConfig = fs.readFileSync(p, 'utf8');
+ calipso.theme.cacheModuleTheme(JSON.parse(moduleThemeConfig), calipso.modules[module].router.modulePath, finish);
+ return;
+ }
+ finish();
+ function finish() {
+ // If the module has no dependencies, kick start it
+ if (depends || !calipso.modules[module].fn.depends) {
+
+ // Init start event
+ calipso.modules[module].event.init_start();
+
+ // Next run any init functions
+ calipso.modules[module].fn.init(calipso.modules[module], calipso.app, function (err) {
+
+ // Init finish event
+ calipso.modules[module].inited = true;
+ calipso.modules[module].event.init_finish();
+
+ // Now, load any routes to go along with it
+ if (calipso.modules[module].fn.routes && calipso.modules[module].fn.routes.length > 0) {
+ calipso.lib.async.map(calipso.modules[module].fn.routes, function (options, next) {
+ calipso.modules[module].router.addRoute(options, next);
+ }, function (err, data) {
+ if (err) {
+ calipso.error(err);
+ }
+ checkAllModulesInited();
+ });
+ } else {
checkAllModulesInited();
- });
- } else {
- checkAllModulesInited();
- }
+ }
- });
+ });
+ }
}
-
}
/**
@@ -799,9 +806,13 @@ function loadModuleTemplates(module, moduleTemplatePath) {
}
fs.readdirSync(moduleTemplatePath).forEach(function (name) {
-
// Template paths and functions
var templatePath = moduleTemplatePath + "/" + name;
+
+ if (fs.statSync(templatePath).isDirectory()) {
+ return;
+ }
+
var templateExtension = templatePath.match(/([^\.]+)$/)[0];
var template = fs.readFileSync(templatePath, 'utf8');
var templateName = name.replace(/\.([^\.]+)$/, '');
View
@@ -147,8 +147,56 @@ module.exports.Theme = function (theme, next) {
}
return layouts;
- }
+ },
+ cacheModuleTheme:function (moduleThemeConfig, moduleThemePath, next) {
+ var templates = [],
+ layout, layoutConfig, section, template, module, templateFiles, errorCodeTemplates;
+
+ // Scan through each layout
+ if (moduleThemeConfig) {
+
+ for (layout in moduleThemeConfig.layouts) {
+ // Scan through each layout
+ layoutConfig = moduleThemeConfig.layouts[layout].layout;
+
+ if (!this.config.layouts[layout]) {
+ theme.config.layouts[layout] = moduleThemeConfig.layouts[layout];
+ // Add the layout template
+ templates.push({
+ name:layout,
+ templatePath:calipso.lib.path.join("templates", layoutConfig.template)
+ });
+ }
+
+ // Add the templates
+ for (section in layoutConfig.sections) {
+ template = layoutConfig.sections[section].template;
+ if (template && !this.cache[layout + "." + section]) {
+ templates.push({
+ name:layout + "." + section,
+ templatePath:calipso.lib.path.join("templates", layout, template)
+ });
+ }
+ }
+
+ }
+ var self = this;
+ var templateIterator = function (templateName, cb) {
+ loadTemplate(self.cache, templateName, moduleThemePath, cb);
+ };
+
+ calipso.lib.async.map(templates, templateIterator, function (err, result) {
+ if (err) {
+ // May not be a problem as missing templates default to default
+ calipso.error("Error loading templates, msg: " + err.message + ", stack: " + err.stack);
+ next(err);
+ } else {
+ next(null);
+ }
+ });
+ }
+ }
};
next(null, theme);
@@ -422,6 +470,7 @@ function loadTheme(theme, themePath, next) {
});
}
+
/**
* Load all of the theme templates into the theme
* @param theme
@@ -194,7 +194,7 @@ function init(module, app, next) {
var s = asset.key.split('/');
bucket = s[0];
}
- var expat = require('node-expat');
+ var nodeXml = require('node-xml');
var knox = require('knox').createClient({
key:calipso.config.getModuleConfig("assets", "s3key"),
secret:calipso.config.getModuleConfig("assets", "s3secret"),
@@ -212,7 +212,6 @@ function init(module, app, next) {
}
knox.get((info && info.prefix) ? ('?prefix=' + info.prefix) : '').on('response',function (s3res) {
s3res.setEncoding('utf8');
- var parser = new expat.Parser();
var items = [];
var item = null;
var dirs = {};
@@ -274,11 +273,9 @@ function init(module, app, next) {
parser.addListener('text', function (s) {
if (property === 'code') {
code = s;
- }
- if (property === 'message') {
+ } else if (property === 'message') {
message = s;
- }
- if (property === 'author') {
+ } else if (property === 'author') {
owner = s;
}
if (property && item) {
@@ -638,8 +635,9 @@ function init(module, app, next) {
if (bucket !== '') {
list = assetsToDelete[bucket].splice(0, 1000); // Pop off the first 1000 assets for one of the buckets.
if (assetsToDelete[bucket].length == 0) {
+ // If we're done with the bucket then remove it from here.
delete assetsToDelete[bucket];
- } // If we're done with the bucket then remove it from here.
+ }
break;
}
}
@@ -2014,15 +2012,15 @@ function updateAsset(req, res, template, block, next) {
var errorMsg = '';
if (err.errors) {
- for (var error in
- err.errors) {
+ for (var error in err.errors) {
errorMessage = error + " " + err.errors[error] + '\r\n';
}
} else {
errorMessage = err.message;
}
req.flash('error', req.t('Could not update content because {msg}', {msg:errorMessage}));
- if (res.statusCode != 302) { // Don't redirect if we already are, multiple errors
+ if (res.statusCode != 302) {
+ // Don't redirect if we already are, multiple errors
res.redirect('back');
}
next();
Oops, something went wrong.

0 comments on commit 5fe6026

Please sign in to comment.