Quellcode durchsuchen

Fixed asset revving issue with css files

Torkel Ödegaard vor 10 Jahren
Ursprung
Commit
4b3224702c

+ 0 - 1
Gruntfile.js

@@ -8,7 +8,6 @@ module.exports = function (grunt) {
     srcDir: 'src',
     destDir: 'dist',
     tempDir: 'tmp',
-    docsDir: 'docs/',
     arch: grunt.option('arch') || 'x86_64',
   };
 

+ 1 - 1
src/app/components/config.js

@@ -4,7 +4,7 @@ define([
 function (Settings) {
   "use strict";
 
-  var bootData = window.grafanaBootData;
+  var bootData = window.grafanaBootData || { settings: {} };
   var options = bootData.settings;
 
   return new Settings(options);

+ 0 - 105
src/config.sample.js

@@ -1,105 +0,0 @@
-// == Configuration
-// config.js is where you will find the core Grafana configuration. This file contains parameter that
-// must be set before Grafana is run for the first time.
-
-define(['settings'], function(Settings) {
-  "use strict";
-
-  return new Settings({
-
-      /* Data sources
-      * ========================================================
-      * Datasources are used to fetch metrics, annotations, and serve as dashboard storage
-      *  - You can have multiple of the same type.
-      *  - grafanaDB: true    marks it for use for dashboard storage
-      *  - default: true      marks the datasource as the default metric source (if you have multiple)
-      *  - basic authentication: use url syntax http://username:password@domain:port
-      */
-
-      // InfluxDB example setup (the InfluxDB databases specified need to exist)
-      /*
-      datasources: {
-        influxdb: {
-          type: 'influxdb',
-          url: "http://my_influxdb_server:8086/db/database_name",
-          username: 'admin',
-          password: 'admin',
-        },
-        grafana: {
-          type: 'influxdb',
-          url: "http://my_influxdb_server:8086/db/grafana",
-          username: 'admin',
-          password: 'admin',
-          grafanaDB: true
-        },
-      },
-      */
-
-      // Graphite & Elasticsearch example setup
-      /*
-      datasources: {
-        graphite: {
-          type: 'graphite',
-          url: "http://my.graphite.server.com:8080",
-        },
-        elasticsearch: {
-          type: 'elasticsearch',
-          url: "http://my.elastic.server.com:9200",
-          index: 'grafana-dash',
-          grafanaDB: true,
-        }
-      },
-      */
-
-      // OpenTSDB & Elasticsearch example setup
-      /*
-      datasources: {
-        opentsdb: {
-          type: 'opentsdb',
-          url: "http://opentsdb.server:4242",
-        },
-        elasticsearch: {
-          type: 'elasticsearch',
-          url: "http://my.elastic.server.com:9200",
-          index: 'grafana-dash',
-          grafanaDB: true,
-        }
-      },
-      */
-
-      /* Global configuration options
-      * ========================================================
-      */
-
-      // specify the limit for dashboard search results
-      search: {
-        max_results: 100
-      },
-
-      // default home dashboard
-      default_route: 'dashboard/file/default.json',
-
-      // set to false to disable unsaved changes warning
-      unsaved_changes_warning: true,
-
-      // set the default timespan for the playlist feature
-      // Example: "1m", "1h"
-      playlist_timespan: "1m",
-
-      // Change window title prefix from 'Grafana - <dashboard title>'
-      window_title_prefix: 'Grafana - ',
-
-      // Add your own custom panels
-      plugins: {
-        // list of plugin panels
-        panels: [],
-        // requirejs modules in plugins folder that should be loaded
-        // for example custom datasources
-        dependencies: [],
-      }
-
-    });
-});
-
-
-

+ 0 - 51
src/index.html

@@ -1,51 +0,0 @@
-<!DOCTYPE html>
-  <!--[if IE 8]>         <html class="no-js lt-ie9" lang="en"> <![endif]-->
-  <!--[if gt IE 8]><!--> <html class="no-js" lang="en"> <!--<![endif]-->
-  <head>
-    <meta charset="utf-8">
-    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
-    <meta name="viewport" content="width=device-width">
-    <meta name="google" value="notranslate">
-
-    <title>Grafana</title>
-    <link rel="stylesheet" href="css/grafana.dark.min.css" title="Dark">
-    <link rel="icon" type="image/png" href="img/fav32.png">
-
-    <!-- build:js app/app.js -->
-    <script src="vendor/require/require.js"></script>
-    <script src="app/components/require.standalone.js"></script>
-    <!-- endbuild -->
-
-  </head>
-
-  <body ng-cloak ng-controller="GrafanaCtrl">
-
-    <link rel="stylesheet" href="css/grafana.light.min.css" ng-if="grafana.style === 'light'">
-
-		<div class="page-alert-list">
-			<div ng-repeat='alert in dashAlerts.list' class="alert-{{alert.severity}} alert">
-				<button type="button" class="alert-close" ng-click="dashAlerts.clear(alert)">
-					<i class="fa fa-times-circle"></i>
-				</button>
-				<div class="alert-title">{{alert.title}}</div>
-				<div ng-bind-html='alert.text'></div>
-			</div>
-		</div>
-
-		<div ng-view></div>
-
-	</body>
-
-	<script>
-		window.grafanaBackend = false;
-		window.grafanaBootData = {
-			user: {},
-			settings: {},
-		};
-
-    require(['app'], function (app) {
-	    app.boot();
-    })
-	</script>
-
-</html>

+ 1 - 1
src/test/test-main.js

@@ -5,7 +5,7 @@ require.config({
     specs:                 '../test/specs',
     mocks:                 '../test/mocks',
     helpers:               '../test/specs/helpers',
-    config:                ['../config', '../config.sample'],
+    config:                'components/config',
     kbn:                   'components/kbn',
     store:                 'components/store',
 

+ 1 - 1
src/views/index.html

@@ -20,7 +20,7 @@
 			window.grafanaBackend = true;
 		</script>
 
-		<!-- build:js app/app.js -->
+		<!-- build:js [[.AppSubUrl]]/app/app.js -->
     <script src="[[.AppSubUrl]]/public/vendor/require/require.js"></script>
     <script src="[[.AppSubUrl]]/public/app/components/require.config.js"></script>
     <!-- endbuild -->

+ 20 - 0
tasks/build_task.js

@@ -19,11 +19,31 @@ module.exports = function(grunt) {
     'requirejs:build',
     'concat:js',
     'filerev',
+    'remapFilerev',
     'usemin',
     'clean:temp',
     'uglify:dest'
   ]);
 
+
+  // task to add [[.AppSubUrl]] to reved path
+  grunt.registerTask('remapFilerev', function(){
+    var root = grunt.config().destDir;
+    var summary = grunt.filerev.summary;
+    var fixed = {};
+
+    for(var key in summary){
+      if(summary.hasOwnProperty(key)){
+
+        var orig = key.replace(root, root+'/[[.AppSubUrl]]');
+        var revved = summary[key].replace(root, root+'/[[.AppSubUrl]]');
+        fixed[orig] = revved;
+      }
+    }
+
+    grunt.filerev.summary = fixed;
+  });
+
   grunt.registerTask('build-post-process', function() {
     grunt.config('copy.dist_to_tmp', {
       expand: true,

+ 2 - 3
tasks/options/clean.js

@@ -1,7 +1,6 @@
 module.exports = function(config) {
   return {
     on_start: ['<%= destDir %>', '<%= tempDir %>'],
-    temp: ['<%= tempDir %>'],
-    docs: ['<%= docsDir %>']
+    temp: ['<%= tempDir %>']
   };
-};
+};

+ 21 - 3
tasks/options/usemin.js

@@ -1,11 +1,29 @@
-module.exports = function(config) {
+module.exports = function() {
+  'use strict';
+
   return {
     html: [
       '<%= destDir %>/views/index.html',
-      '<%= destDir %>/index.html',
     ],
     options: {
-      assetsDirs: ['<%= destDir %>']
+      assetsDirs: ['<%= destDir %>'],
+      patterns: {
+        css: [
+          [/(\.css)/, 'Replacing reference to image.png']
+        ]
+      }
+      // blockReplacements: {
+      //   css: function (block) {
+      //     console.log('aaaaaaaaaaaaa', block);
+      //     return '<link rel="stylesheet" href="aaaa' + block.dest + '">';
+      //   }
+      // }
+      // css: [
+      //   [/(grafana\.light\.min\.css)/, 'Replacing reference to light css', function(asd) {
+      //     console.log("Match", asd);
+      //     return 'css/grafana.light.min.css';
+      //   }]
+      // ]
     }
   };
 };

+ 0 - 1
tasks/options/useminPrepare.js

@@ -2,7 +2,6 @@ module.exports = function(config) {
   return {
     html: [
       'tmp/index.html',
-      'tmp/views/index.html',
     ]
   };
 };