فهرست منبع

more experiments for mixing javascript and typescript

Torkel Ödegaard 10 سال پیش
والد
کامیت
a8197df1c1

+ 1 - 0
.gitignore

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

+ 0 - 7
public/app/components/panelmeta.d.ts

@@ -1,7 +0,0 @@
-/// <reference path="../headers/require.d.ts" />
-declare class Base {
-  constructor();
-  testFunc(): number
-  getName(): string
-}
-export = Base;

+ 18 - 19
public/app/components/panelmeta.js → public/app/components/panelmeta.ts

@@ -1,9 +1,13 @@
-define([
-],
-function () {
-  "use strict";
-
-  function PanelMeta(options) {
+class PanelMeta {
+  description: any
+  fullscreen: any
+  editIcon: any
+  panelName: any
+  menu: any
+  editorTabs: any
+  extendedMenu: any
+
+  constructor(options : any) {
     this.description = options.description;
     this.fullscreen = options.fullscreen;
     this.editIcon = options.editIcon;
@@ -29,22 +33,17 @@ function () {
     this.addExtendedMenuItem('Panel JSON', '', 'editPanelJson(); dismiss();');
   }
 
-  PanelMeta.prototype.addMenuItem = function(text, icon, click, role) {
+  addMenuItem (text, icon, click, role?) {
     this.menu.push({text: text, icon: icon, click: click, role: role});
-  };
-
-  PanelMeta.prototype.getName = function() {
-    return "javascript";
-  };
+  }
 
-  PanelMeta.prototype.addExtendedMenuItem = function(text, icon, click, role) {
+  addExtendedMenuItem (text, icon, click, role?) {
     this.extendedMenu.push({text: text, icon: icon, click: click, role: role});
-  };
+  }
 
-  PanelMeta.prototype.addEditorTab = function(title, src) {
+  addEditorTab (title, src) {
     this.editorTabs.push({title: title, src: src});
-  };
-
-  return PanelMeta;
+  }
+}
 
-});
+export = PanelMeta;

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

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

+ 0 - 6
public/app/controllers/fileSearcher.d.ts

@@ -1,6 +0,0 @@
-/// <reference path="../headers/require.d.ts" />
-declare class FileSearcher {
-    constructor();
-    getFiles(): string[];
-}
-export = FileSearcher;

+ 0 - 13
public/app/controllers/fileSearcher.js

@@ -1,13 +0,0 @@
-///<reference path="../headers/require.d.ts" />
-define(["require", "exports"], function (require, exports) {
-    var FileSearcher = (function () {
-        function FileSearcher() {
-        }
-        FileSearcher.prototype.getFiles = function () {
-            return ["asd"];
-        };
-        return FileSearcher;
-    })();
-    return FileSearcher;
-});
-//# sourceMappingURL=fileSearcher.js.map

+ 0 - 1
public/app/controllers/fileSearcher.js.map

@@ -1 +0,0 @@
-{"version":3,"file":"fileSearcher.js","sourceRoot":"","sources":["fileSearcher.ts"],"names":["FileSearcher","FileSearcher.constructor","FileSearcher.getFiles"],"mappings":"AAAA,+CAA+C;;IAE/C;QAEIA;QACAC,CAACA;QAEMD,+BAAQA,GAAfA;YACEE,MAAMA,CAACA,CAACA,KAAKA,CAACA,CAACA;QACjBA,CAACA;QACLF,mBAACA;IAADA,CAACA,AARD,IAQC;IAEqB,AAAtB,OAAS,YAAY,CAAC"}

+ 0 - 6
public/app/controllers/testCtrl.d.ts

@@ -1,6 +0,0 @@
-/// <reference path="../headers/require.d.ts" />
-declare class Base {
-    constructor();
-    getName(): string;
-}
-export = Base;

+ 0 - 15
public/app/controllers/testCtrl.js

@@ -1,15 +0,0 @@
-///<reference path="../headers/require.d.ts" />
-define(["require", "exports", './fileSearcher', "../components/panelmeta"], function (require, exports, FileSearcher) {
-    var Base = (function () {
-        function Base() {
-            var test = new FileSearcher();
-            test.getFiles();
-        }
-        Base.prototype.getName = function () {
-            return "asd";
-        };
-        return Base;
-    })();
-    return Base;
-});
-//# sourceMappingURL=testCtrl.js.map

+ 0 - 1
public/app/controllers/testCtrl.js.map

@@ -1 +0,0 @@
-{"version":3,"file":"testCtrl.js","sourceRoot":"","sources":["testCtrl.ts"],"names":["Base","Base.constructor","Base.getName"],"mappings":"AAAA,+CAA+C;;IAO/C;QAEIA;YACEC,IAAIA,IAAIA,GAAGA,IAAIA,YAAYA,EAAEA,CAACA;YAC9BA,IAAIA,CAACA,QAAQA,EAAEA,CAACA;QAClBA,CAACA;QAEMD,sBAAOA,GAAdA;YACEE,MAAMA,CAACA,KAAKA,CAACA;QACfA,CAACA;QACLF,WAACA;IAADA,CAACA,AAVD,IAUC;IAEa,AAAd,OAAS,IAAI,CAAC"}

+ 0 - 1
public/app/controllers/testCtrl.ts

@@ -2,7 +2,6 @@
 
 ///<amd-dependency path="../components/panelmeta" />
 
-import PanelMeta = require('../components/panelmeta');
 import FileSearcher = require('./fileSearcher');
 
 class Base {

+ 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/components/require.config.js"></script>
+    <script src="[[.AppSubUrl]]/public/app_gen/components/require.config.js"></script>
     <!-- endbuild -->
   </head>
 

+ 9 - 1
tasks/options/copy.js

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

+ 17 - 4
tasks/options/typescript.js

@@ -2,16 +2,29 @@ module.exports = function() {
   'use strict';
 
   return {
-    base: {
+    build: {
       src: ['public/app/**/*.ts'],
-      dest: '',
+      dest: 'public/app_gen',
       options: {
         module: 'amd', //or commonjs
         target: 'es5', //or es3
-        keepDirectoryHierarchy: true,
+        rootDir: 'public/app',
         declaration: true,
-        watch: true,
         sourceMap: true,
+        generateTsConfig: true,
+      }
+    },
+    watch: {
+      src: ['public/app/**/*.ts'],
+      dest: 'public/app_gen',
+      options: {
+        module: 'amd', //or commonjs
+        target: 'es5', //or es3
+        rootDir: 'public/app',
+        declaration: true,
+        sourceMap: true,
+        watch: true,
+        generateTsConfig: true,
       }
     }
   };

+ 17 - 0
tasks/options/watch.js

@@ -6,6 +6,23 @@ module.exports = function(config) {
       options: {
         spawn: false
       }
+    },
+
+    app_gen: {
+      files: ['<%= srcDir %>/app/**/*.js', '<%= srcDir %>/app/**/*.html'],
+      tasks: ['copy:app_gen_build'],
+      options: {
+        spawn: false
+      }
+    },
+
+    typescript: {
+      files: ['<%= srcDir %>/app/**/*.ts'],
+      tasks: ['typescript:build'],
+      options: {
+        spawn: false
+      }
     }
+
   };
 };

+ 17 - 0
tsconfig.json

@@ -0,0 +1,17 @@
+{
+    "compilerOptions": {
+        "sourceMap": true,
+        "declaration": true,
+        "outDir": "public/app_gen",
+        "target": "ES5",
+        "rootDir": "public/app",
+        "module": "amd",
+        "noEmitOnError": true
+    },
+    "files": [
+        "public/app/components/panelmeta.ts",
+        "public/app/controllers/fileSearcher.ts",
+        "public/app/controllers/testCtrl.ts",
+        "public/app/headers/require.d.ts"
+    ]
+}