serve extension css to the browser
authorSteve Hackbarth <stephenhackbarth@gmail.com>
Wed, 30 Jul 2014 16:44:52 +0000 (12:44 -0400)
committerSteve Hackbarth <stephenhackbarth@gmail.com>
Wed, 30 Jul 2014 16:44:52 +0000 (12:44 -0400)
node-datasource/routes/app.js
node-datasource/views/app.ejs
scripts/lib/build_client.js

index 6f639ba..e083ee8 100644 (file)
@@ -110,18 +110,25 @@ var async = require("async"),
               return ext1.name > ext2.name ? 1 : -1;
             }
           });
-          var uuids = _.map(extensions, function (ext) {
-            var sortedModels = _.sortBy(ext.codeInfo, function (codeInfo) {
-              return -1 * getVersionSize(codeInfo.version);
+          var getLatestUuid = function (extensions, language) {
+            var uuids = _.map(extensions, function (ext) {
+              var jsModels = _.filter(ext.codeInfo, function (codeInfo) {
+                return codeInfo.language === language;
+              });
+              var sortedModels = _.sortBy(jsModels, function (codeInfo) {
+                return -1 * getVersionSize(codeInfo.version);
+              });
+              if (sortedModels[0]) {
+                return sortedModels[0].uuid;
+              } else {
+                X.log("Could not find js uuid for extension " + ext.description);
+                return null;
+              }
             });
-            if (sortedModels[0]) {
-              return sortedModels[0].uuid;
-            } else {
-              X.log("Could not find uuid for extension " + ext.description);
-              return null;
-            }
-          });
-          uuids = _.compact(uuids); // eliminate any null values
+            return _.compact(uuids); // eliminate any null values
+          };
+          var extJsUuids = getLatestUuid(extensions, "js");
+          var extCssUuids = getLatestUuid(extensions, "css");
           var extensionPaths = _.compact(_.map(extensions, function (ext) {
             var locationName = ext.location.indexOf("/") === 0 ?
               path.join(ext.location, "source") :
@@ -142,7 +149,8 @@ var async = require("async"),
                 org: req.session.passport.user.organization,
                 coreJs: jsUuid,
                 coreCss: cssUuid,
-                extensions: uuids,
+                extensionJsArray: extJsUuids,
+                extensionCssArray: extCssUuids,
                 extensionPaths: extensionPaths
               });
             });
index c1ca279..c2a8df5 100644 (file)
     <!-- css -->
     <link href="/<%= org %>/client/lib/enyo-x/lib/nvd3/src/nv.d3.css" rel="stylesheet"/>
     <link href="/<%= org %>/client/build/client-code?uuid=<%= coreCss %>&language=css" rel="stylesheet"/>
+    <% for (var i = 0; i < extensionCssArray.length; i++) { %>
+      <link href="/<%= org %>/client/build/client-code?uuid=<%= extensionCssArray[i] %>&language=css" rel="stylesheet"/>
+    <% } %>
     <!-- js -->
     <script src="/<%= org %>/locale"></script>
     <script src="/socket.io/socket.io.js?1.3.10" type="text/javascript"></script>
     <script src="/<%= org %>/client/build/client-code?uuid=<%= coreJs %>&language=js"></script>
-    <% for (var i = 0; i < extensions.length; i++) { %>
-      <script src="/<%= org %>/client/build/client-code?uuid=<%= extensions[i] %>&language=js"></script>
+    <% for (var i = 0; i < extensionJsArray.length; i++) { %>
+      <script src="/<%= org %>/client/build/client-code?uuid=<%= extensionJsArray[i] %>&language=js"></script>
     <% } %>
   </head>
   <body class="enyo-unselectable">
index 8dab372..7953a61 100755 (executable)
@@ -10,9 +10,6 @@ var _ = require('underscore'),
   path = require('path'),
   rimraf = require('rimraf');
 
-  // TODO: relax the assumption that extension builds are js only (i.e. allow extension css)
-  // TODO: right now we just give the latest versions available in the db. This might possibly change.
-
 (function () {
   "use strict";
 
@@ -136,7 +133,9 @@ var _ = require('underscore'),
           // rename the file with the name of the extension so that we won't need to recreate it
           // in the case of multiple databases wanting the same client code
           fs.renameSync(path.join(__dirname, "build/app.js"), path.join(__dirname, "build", jsFilename));
-          fs.renameSync(path.join(__dirname, "build/app.css"), path.join(__dirname, "build", cssFilename));
+          if (fs.existsSync(path.join(__dirname, "build/app.css"))) {
+            fs.renameSync(path.join(__dirname, "build/app.css"), path.join(__dirname, "build", cssFilename));
+          }
           callback();
         }
       );