Pārlūkot izejas kodu

tech(typescript): its looking good

Torkel Ödegaard 10 gadi atpakaļ
vecāks
revīzija
abac8bccc6
54 mainītis faili ar 133 papildinājumiem un 66 dzēšanām
  1. 1 1
      .gitignore
  2. 1 0
      Gruntfile.js
  3. 1 0
      package.json
  4. 1 1
      public/app/app.js
  5. 1 1
      public/app/components/require.config.js
  6. 1 0
      public/app/controllers/errorCtrl.js
  7. 1 4
      public/app/controllers/grafanaCtrl.js
  8. 6 0
      public/app/core/core.ts
  9. 7 0
      public/app/core/directives/cool_dir.ts
  10. 19 0
      public/app/core/routes/module_loader.ts
  11. 6 0
      public/app/core/time_series.ts
  12. 0 1
      public/app/features/all.js
  13. 9 1
      public/app/routes/all.js
  14. 0 0
      public/less/admin.less
  15. 0 0
      public/less/bootstrap-tagsinput.less
  16. 0 0
      public/less/bootstrap.dark.less
  17. 0 0
      public/less/bootstrap.light.less
  18. 0 0
      public/less/bootswatch.dark.less
  19. 0 0
      public/less/bootswatch.light.less
  20. 0 0
      public/less/dashlist.less
  21. 0 0
      public/less/fonts.less
  22. 0 0
      public/less/forms.less
  23. 0 0
      public/less/gfbox.less
  24. 0 0
      public/less/grafana-responsive.less
  25. 0 0
      public/less/grafana.less
  26. 0 0
      public/less/graph.less
  27. 0 0
      public/less/login.less
  28. 0 0
      public/less/navbar.less
  29. 0 0
      public/less/overrides.less
  30. 0 0
      public/less/panel.less
  31. 0 0
      public/less/search.less
  32. 0 0
      public/less/sidemenu.less
  33. 0 0
      public/less/singlestat.less
  34. 0 0
      public/less/submenu.less
  35. 0 0
      public/less/tables_lists.less
  36. 0 0
      public/less/tabs.less
  37. 0 0
      public/less/tightform.less
  38. 0 0
      public/less/type.less
  39. 0 0
      public/less/validation.less
  40. 0 0
      public/less/variables.dark.less
  41. 0 0
      public/less/variables.light.less
  42. 1 1
      public/test/karma.conf.js
  43. 1 1
      public/test/test-main.js
  44. 1 1
      public/views/index.html
  45. 4 5
      tasks/build_task.js
  46. 12 2
      tasks/default_task.js
  47. 4 1
      tasks/options/clean.js
  48. 14 14
      tasks/options/concat.js
  49. 4 4
      tasks/options/copy.js
  50. 7 16
      tasks/options/less.js
  51. 9 5
      tasks/options/requirejs.js
  52. 13 2
      tasks/options/typescript.js
  53. 4 4
      tasks/options/watch.js
  54. 5 1
      tsconfig.json

+ 1 - 1
.gitignore

@@ -4,7 +4,7 @@ coverage/
 awsconfig
 /dist
 /emails/dist
-/public/.app_gen
+/public_gen
 /tmp
 
 docs/AWS_S3_BUCKET

+ 1 - 0
Gruntfile.js

@@ -6,6 +6,7 @@ module.exports = function (grunt) {
     pkg: grunt.file.readJSON('package.json'),
     baseDir: '.',
     srcDir: 'public',
+    genDir: 'public_gen',
     destDir: 'dist',
     tempDir: 'tmp',
     arch: os.arch(),

+ 1 - 0
package.json

@@ -61,6 +61,7 @@
   "license": "Apache-2.0",
   "dependencies": {
     "grunt-jscs": "~1.5.x",
+    "grunt-sync": "^0.4.1",
     "karma-sinon": "^1.0.3",
     "lodash": "^2.4.1",
     "sinon": "1.10.3"

+ 1 - 1
public/app/app.js

@@ -104,8 +104,8 @@ function (angular, $, _, appLevelRequire) {
               _.each(pre_boot_modules, function (module) {
                 _.extend(module, register_fns);
               });
-              pre_boot_modules = false;
 
+              pre_boot_modules = false;
               $rootScope.requireContext = appLevelRequire;
               $rootScope.require = function (deps, fn) {
                 var $scope = this;

+ 1 - 1
public/app/components/require.config.js

@@ -1,6 +1,6 @@
 require.config({
   urlArgs: 'bust=' + (new Date().getTime()),
-  baseUrl: 'public/.app_gen',
+  baseUrl: 'public/app',
 
   paths: {
     config:                   'components/config',

+ 1 - 0
public/app/controllers/errorCtrl.js

@@ -8,6 +8,7 @@ function (angular) {
 
   var module = angular.module('grafana.controllers');
 
+
   module.controller('ErrorCtrl', function($scope, contextSrv) {
 
     var showSideMenu = contextSrv.sidemenu;

+ 1 - 4
public/app/controllers/grafanaCtrl.js

@@ -4,13 +4,10 @@ define([
   'lodash',
   'jquery',
   'store',
-  './testCtrl',
 ],
-function (angular, config, _, $, store, TestCtrl) {
+function (angular, config, _, $, store) {
   "use strict";
 
-  console.log(new TestCtrl().getName());
-
   var module = angular.module('grafana.controllers');
 
   module.controller('GrafanaCtrl', function($scope, alertSrv, utilSrv, $rootScope, $controller, contextSrv) {

+ 6 - 0
public/app/core/core.ts

@@ -0,0 +1,6 @@
+
+export * from './time_series'
+export * from './directives/cool_dir'
+export * from './routes/module_loader'
+
+

+ 7 - 0
public/app/core/directives/cool_dir.ts

@@ -0,0 +1,7 @@
+
+export class CoolDir {
+  getName() : string {
+    return "CoolDir";
+  }
+}
+

+ 19 - 0
public/app/core/routes/module_loader.ts

@@ -0,0 +1,19 @@
+///<reference path="../../headers/require.d.ts" />
+
+export class ModuleLoader {
+  lazy: any
+
+  constructor(moduleName) {
+
+    this.lazy = ["$q", "$route", "$rootScope", function($q, $route, $rootScope) {
+      var defered = $q.defer();
+
+      require([moduleName], function () {
+        defered.resolve();
+      });
+
+      return defered.promise;
+    }];
+
+  }
+}

+ 6 - 0
public/app/core/time_series.ts

@@ -0,0 +1,6 @@
+export class TimeSeries {
+  getName() : string {
+    return "TimeSeries";
+  }
+}
+

+ 0 - 1
public/app/features/all.js

@@ -8,6 +8,5 @@ define([
   './profile/profileCtrl',
   './profile/changePasswordCtrl',
   './profile/selectOrgCtrl',
-  './org/all',
   './admin/all',
 ], function () {});

+ 9 - 1
public/app/routes/all.js

@@ -1,7 +1,8 @@
 define([
   'angular',
+  '../core/core',
   './dashLoadControllers',
-], function(angular) {
+], function(angular, core) {
   "use strict";
 
   var module = angular.module('grafana.routes');
@@ -41,30 +42,37 @@ define([
       .when('/datasources', {
         templateUrl: 'app/features/org/partials/datasources.html',
         controller : 'DataSourcesCtrl',
+        resolve: new core.ModuleLoader("features/org/all"),
       })
       .when('/datasources/edit/:id', {
         templateUrl: 'app/features/org/partials/datasourceEdit.html',
         controller : 'DataSourceEditCtrl',
+        resolve: new core.ModuleLoader("features/org/all"),
       })
       .when('/datasources/new', {
         templateUrl: 'app/features/org/partials/datasourceEdit.html',
         controller : 'DataSourceEditCtrl',
+        resolve: new core.ModuleLoader("features/org/all"),
       })
       .when('/org', {
         templateUrl: 'app/features/org/partials/orgDetails.html',
         controller : 'OrgDetailsCtrl',
+        resolve: new core.ModuleLoader("features/org/all"),
       })
       .when('/org/new', {
         templateUrl: 'app/features/org/partials/newOrg.html',
         controller : 'NewOrgCtrl',
+        resolve: new core.ModuleLoader("features/org/all"),
       })
       .when('/org/users', {
         templateUrl: 'app/features/org/partials/orgUsers.html',
         controller : 'OrgUsersCtrl',
+        resolve: new core.ModuleLoader("features/org/all"),
       })
       .when('/org/apikeys', {
         templateUrl: 'app/features/org/partials/orgApiKeys.html',
         controller : 'OrgApiKeysCtrl',
+        resolve: new core.ModuleLoader("features/org/all"),
       })
       .when('/profile', {
         templateUrl: 'app/features/profile/partials/profile.html',

+ 0 - 0
public/css/less/admin.less → public/less/admin.less


+ 0 - 0
public/css/less/bootstrap-tagsinput.less → public/less/bootstrap-tagsinput.less


+ 0 - 0
public/css/less/bootstrap.dark.less → public/less/bootstrap.dark.less


+ 0 - 0
public/css/less/bootstrap.light.less → public/less/bootstrap.light.less


+ 0 - 0
public/css/less/bootswatch.dark.less → public/less/bootswatch.dark.less


+ 0 - 0
public/css/less/bootswatch.light.less → public/less/bootswatch.light.less


+ 0 - 0
public/css/less/dashlist.less → public/less/dashlist.less


+ 0 - 0
public/css/less/fonts.less → public/less/fonts.less


+ 0 - 0
public/css/less/forms.less → public/less/forms.less


+ 0 - 0
public/css/less/gfbox.less → public/less/gfbox.less


+ 0 - 0
public/css/less/grafana-responsive.less → public/less/grafana-responsive.less


+ 0 - 0
public/css/less/grafana.less → public/less/grafana.less


+ 0 - 0
public/css/less/graph.less → public/less/graph.less


+ 0 - 0
public/css/less/login.less → public/less/login.less


+ 0 - 0
public/css/less/navbar.less → public/less/navbar.less


+ 0 - 0
public/css/less/overrides.less → public/less/overrides.less


+ 0 - 0
public/css/less/panel.less → public/less/panel.less


+ 0 - 0
public/css/less/search.less → public/less/search.less


+ 0 - 0
public/css/less/sidemenu.less → public/less/sidemenu.less


+ 0 - 0
public/css/less/singlestat.less → public/less/singlestat.less


+ 0 - 0
public/css/less/submenu.less → public/less/submenu.less


+ 0 - 0
public/css/less/tables_lists.less → public/less/tables_lists.less


+ 0 - 0
public/css/less/tabs.less → public/less/tabs.less


+ 0 - 0
public/css/less/tightform.less → public/less/tightform.less


+ 0 - 0
public/css/less/type.less → public/less/type.less


+ 0 - 0
public/css/less/validation.less → public/less/validation.less


+ 0 - 0
public/css/less/variables.dark.less → public/less/variables.dark.less


+ 0 - 0
public/css/less/variables.light.less → public/less/variables.light.less


+ 1 - 1
public/test/karma.conf.js

@@ -9,7 +9,7 @@ module.exports = function(config) {
     // list of files / patterns to load in the browser
     files: [
       'public/test/test-main.js',
-      {pattern: 'public/app/**/*.js', included: false},
+      {pattern: 'public/.app_gen/**/*.js', included: false},
       {pattern: 'public/vendor/**/*.js', included: false},
       {pattern: 'public/test/**/*.js', included: false},
       {pattern: 'public/**/*.js', included: false}

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

@@ -1,5 +1,5 @@
 require.config({
-  baseUrl: 'http://localhost:9876/base/public/app',
+  baseUrl: 'http://localhost:9876/base/public/app_gen',
 
   paths: {
     specs:                 '../test/specs',

+ 1 - 1
public/views/index.html

@@ -19,7 +19,7 @@
 
 		<!-- build:js [[.AppSubUrl]]/app/app.js -->
     <script src="[[.AppSubUrl]]/public/vendor/requirejs/require.js"></script>
-    <script src="[[.AppSubUrl]]/public/.app_gen/components/require.config.js"></script>
+    <script src="[[.AppSubUrl]]/public/app/components/require.config.js"></script>
     <!-- endbuild -->
   </head>
 

+ 4 - 5
tasks/build_task.js

@@ -6,11 +6,11 @@ module.exports = function(grunt) {
     'jshint:source',
     'jshint:tests',
     'jscs',
-    'karma:test',
     'clean:on_start',
-    'less:src',
-    'concat:cssDark',
-    'concat:cssLight',
+    'copy:app_gen_build',
+    'typescript:build',
+    'karma:test',
+    'css',
     'copy:everything_but_less_to_temp',
     'htmlmin:build',
     'ngtemplates',
@@ -25,7 +25,6 @@ module.exports = function(grunt) {
     'uglify:dest'
   ]);
 
-
   // task to add [[.AppSubUrl]] to reved path
   grunt.registerTask('remapFilerev', function(){
     var root = grunt.config().destDir;

+ 12 - 2
tasks/default_task.js

@@ -1,6 +1,16 @@
 // Lint and build CSS
 module.exports = function(grunt) {
-  grunt.registerTask('css', ['less:src', 'concat:cssDark', 'concat:cssLight']);
-  grunt.registerTask('default', ['jscs', 'jshint', 'css']);
+  'use strict';
+
+  grunt.registerTask('css', ['less', 'concat:cssDark', 'concat:cssLight']);
+  grunt.registerTask('default', [
+    'jscs',
+    'jshint',
+    'clean:gen',
+    'copy:everything_but_ts_and_less',
+    'css',
+    'typescript:build'
+  ]);
+
   grunt.registerTask('test', ['default', 'karma:test']);
 };

+ 4 - 1
tasks/options/clean.js

@@ -1,6 +1,9 @@
 module.exports = function(config) {
+  'use strict';
+
   return {
-    on_start: ['<%= destDir %>', '<%= tempDir %>'],
+    release: ['<%= destDir %>', '<%= tempDir %>', '<%= genDir %>'],
+    gen: ['<%= genDir %>'],
     temp: ['<%= tempDir %>']
   };
 };

+ 14 - 14
tasks/options/concat.js

@@ -4,25 +4,25 @@ module.exports = function(config) {
   return {
     cssDark: {
       src: [
-        '<%= srcDir %>/vendor/css/normalize.min.css',
-        '<%= srcDir %>/vendor/css/timepicker.css',
-        '<%= srcDir %>/vendor/css/spectrum.css',
-        '<%= srcDir %>/css/bootstrap.dark.min.css',
-        '<%= srcDir %>/css/bootstrap-responsive.min.css',
-        '<%= srcDir %>/vendor/css/font-awesome.min.css'
+        '<%= genDir %>/vendor/css/normalize.min.css',
+        '<%= genDir %>/vendor/css/timepicker.css',
+        '<%= genDir %>/vendor/css/spectrum.css',
+        '<%= genDir %>/css/bootstrap.dark.min.css',
+        '<%= genDir %>/css/bootstrap-responsive.min.css',
+        '<%= genDir %>/vendor/css/font-awesome.min.css'
       ],
-      dest: '<%= srcDir %>/css/grafana.dark.min.css'
+      dest: '<%= genDir %>/css/grafana.dark.min.css'
     },
     cssLight: {
       src: [
-        '<%= srcDir %>/vendor/css/normalize.min.css',
-        '<%= srcDir %>/vendor/css/timepicker.css',
-        '<%= srcDir %>/vendor/css/spectrum.css',
-        '<%= srcDir %>/css/bootstrap.light.min.css',
-        '<%= srcDir %>/css/bootstrap-responsive.min.css',
-        '<%= srcDir %>/vendor/css/font-awesome.min.css'
+        '<%= genDir %>/vendor/css/normalize.min.css',
+        '<%= genDir %>/vendor/css/timepicker.css',
+        '<%= genDir %>/vendor/css/spectrum.css',
+        '<%= genDir %>/css/bootstrap.light.min.css',
+        '<%= genDir %>/css/bootstrap-responsive.min.css',
+        '<%= genDir %>/vendor/css/font-awesome.min.css'
       ],
-      dest: '<%= srcDir %>/css/grafana.light.min.css'
+      dest: '<%= genDir %>/css/grafana.light.min.css'
     },
 
     js: {

+ 4 - 4
tasks/options/copy.js

@@ -8,11 +8,11 @@ module.exports = function(config) {
       dest: '<%= tempDir %>'
     },
 
-    app_gen_build: {
-      cwd: '<%= srcDir %>/app',
+    everything_but_less: {
+      cwd: '<%= srcDir %>',
       expand: true,
-      src: ['**/*.js', '**/*.html'],
-      dest: '<%= srcDir %>/.app_gen'
+      src: ['**/*', '!**/*.less'],
+      dest: '<%= genDir %>'
     }
 
   };

+ 7 - 16
tasks/options/less.js

@@ -1,25 +1,16 @@
 module.exports = function(config) {
+
   return {
-    // this is the only task, other than copy, that runs on the src directory, since we don't really need
-    // the less files in the dist. Everything else runs from on temp, and require copys everything
-    // from temp -> dist
-    dist:{
-      expand: true,
-      cwd:'<%= srcDir %>/vendor/bootstrap/less/',
-      src: ['bootstrap.dark.less', 'bootstrap.light.less'],
-      dest: '<%= tempDir %>/css/',
-    },
-    // Compile in place when not building
     src:{
       options: {
-        paths: ["<%= srcDir %>/vendor/bootstrap/less", "<%= srcDir %>/css/less"],
-        yuicompress:true
+        paths: ["<%= srcDir %>/vendor/bootstrap/less", "<%= srcDir %>/less"],
+        yuicompress: true
       },
       files: {
-        "<%= srcDir %>/css/bootstrap.dark.min.css": "<%= srcDir %>/css/less/bootstrap.dark.less",
-        "<%= srcDir %>/css/bootstrap.light.min.css": "<%= srcDir %>/css/less/bootstrap.light.less",
-        "<%= srcDir %>/css/bootstrap-responsive.min.css": "<%= srcDir %>/css/less/grafana-responsive.less"
+        "<%= genDir %>/css/bootstrap.dark.min.css": "<%= srcDir %>/less/bootstrap.dark.less",
+        "<%= genDir %>/css/bootstrap.light.min.css": "<%= srcDir %>/less/bootstrap.light.less",
+        "<%= genDir %>/css/bootstrap-responsive.min.css": "<%= srcDir %>/less/grafana-responsive.less"
       }
     }
   };
-};
+};

+ 9 - 5
tasks/options/requirejs.js

@@ -7,7 +7,7 @@ module.exports = function(config,grunt) {
       appDir: '<%= tempDir %>',
       dir:  '<%= destDir %>',
       mainConfigFile: '<%= tempDir %>/app/components/require.config.js',
-      baseUrl: './app',
+      baseUrl: 'app_gen',
       waitSeconds: 0,
 
       modules: [], // populated below,
@@ -37,9 +37,9 @@ module.exports = function(config,grunt) {
 
     // setup the modules require will build
     var requireModules = options.modules = [
-    {
-      // main/common module
-      name: 'app',
+      {
+        // main/common module
+        name: 'app',
         include: [
           'kbn',
           'text',
@@ -66,7 +66,11 @@ module.exports = function(config,grunt) {
           'plugins/datasource/graphite/datasource',
           'plugins/datasource/influxdb_08/datasource',
         ]
-      }
+      },
+      // {
+      //   name: 'features/org/all',
+      //   exclude: ['app'],
+      // }
     ];
 
     var fs = require('fs');

+ 13 - 2
tasks/options/typescript.js

@@ -4,7 +4,7 @@ module.exports = function() {
   return {
     build: {
       src: ['public/app/**/*.ts'],
-      dest: 'public/.app_gen',
+      dest: 'public_gen/app',
       options: {
         module: 'amd', //or commonjs
         target: 'es5', //or es3
@@ -14,9 +14,20 @@ module.exports = function() {
         generateTsConfig: true,
       }
     },
+
+    // build2: {
+    //   src: ['public/app/alerting#<{(||)}>#*.ts'],
+    //   dest: 'public/.app_gen/alerting/all.js',
+    //   options: {
+    //     target: 'es5', //or es3
+    //     declaration: true,
+    //     sourceMap: true,
+    //   }
+    // },
+
     watch: {
       src: ['public/app/**/*.ts'],
-      dest: 'public/.app_gen',
+      dest: 'public/app_gen',
       options: {
         module: 'amd', //or commonjs
         target: 'es5', //or es3

+ 4 - 4
tasks/options/watch.js

@@ -1,16 +1,16 @@
 module.exports = function(config) {
   return {
     css: {
-      files: [ '<%= srcDir %>/css/**/*.less' ],
+      files: [ '<%= srcDir %>/less/**/*.less' ],
       tasks: ['css'],
       options: {
         spawn: false
       }
     },
 
-    app_gen: {
-      files: ['<%= srcDir %>/app/**/*.js', '<%= srcDir %>/app/**/*.html'],
-      tasks: ['copy:app_gen_build'],
+    copy_to_gen: {
+      files: ['<%= srcDir %>/**/*', '!<%= srcDir %>/**/*.less'],
+      tasks: ['copy:everything_but_less'],
       options: {
         spawn: false
       }

+ 5 - 1
tsconfig.json

@@ -2,7 +2,7 @@
     "compilerOptions": {
         "sourceMap": true,
         "declaration": true,
-        "outDir": "public/.app_gen",
+        "outDir": "public_gen/app",
         "target": "ES5",
         "rootDir": "public/app",
         "module": "amd",
@@ -12,6 +12,10 @@
         "public/app/components/panelmeta.ts",
         "public/app/controllers/fileSearcher.ts",
         "public/app/controllers/testCtrl.ts",
+        "public/app/core/core.ts",
+        "public/app/core/directives/cool_dir.ts",
+        "public/app/core/routes/module_loader.ts",
+        "public/app/core/time_series.ts",
         "public/app/headers/require.d.ts"
     ]
 }