瀏覽代碼

Added Xml.ts, Grunt config

Andrea Condoluci 9 年之前
父節點
當前提交
540a434a81
共有 3 個文件被更改,包括 144 次插入106 次删除
  1. 69 102
      Gruntfile.js
  2. 13 4
      package.json
  3. 62 0
      src/Common/FileIO/Xml.ts

+ 69 - 102
Gruntfile.js

@@ -1,4 +1,5 @@
 module.exports = function(grunt) {
+  'use strict';
   var L = grunt.log.writeln;
   var BANNER = '/**\n' +
                 ' * Open Sheet Music Display library <%= pkg.version %> built on <%= grunt.template.today("yyyy-mm-dd") %>.\n' +
@@ -6,130 +7,96 @@ module.exports = function(grunt) {
                 ' *\n' +
                 ' * https://github.com/opensheetmusicdisplay/opensheetmusicdisplay\n' +
                 ' */\n';
-  var BUILD_DIR = 'build';
-  var RELEASE_DIR = 'releases';
-  var TARGET_RAW = BUILD_DIR + '/osmd.js';
-  var TARGET_MIN = BUILD_DIR + '/osmd-min.js';
-
-  var SOURCES = [ "src/source.js",
-                  "src/*.js", "!src/header.js", "!src/container.js"];
 
   grunt.initConfig({
     pkg: grunt.file.readJSON('package.json'),
-    concat: {
-      options: {
-        banner: BANNER
-      },
-      build: {
-        src: SOURCES,
-        dest: TARGET_RAW
-      }
+    // Build output directories
+    outputDir: {
+        build: 'build',
+        dist: 'dist'
     },
-    uglify: {
-      options: {
-        banner: BANNER,
-        sourceMap: true
-      },
-      build: {
-        src: SOURCES,
-        dest: TARGET_MIN
-      }
+    // Browserify
+    browserify: {
+        dist: {
+            src: ['typings/browser.d.ts', 'src/**/*.ts'],
+            dest: '<%= outputDir.build %>/osmd.js'
+        },
+        debug: {
+            src: ['typings/browser.d.ts', 'src/**/*.ts', 'test/**/*.ts'],
+            dest: '<%= outputDir.build %>/osmd-debug.js',
+            options: {
+                browserifyOptions: {
+                    debug: true
+
+                }
+            }
+        },
+        options: {
+            plugin: ['tsify']
+        }
     },
-    jshint: {
-      files: SOURCES,
+    // Uglify
+    /*uglify: {
       options: {
-        eqnull: true,   // allow == and ~= for nulls
-        sub: true,      // don't enforce dot notation
-        trailing: true, // no more trailing spaces
-        globals: {
-          "Vex": false,
-          "Raphael": false
-         }
+        compress: {
+          drop_console: true
+        }
+      },
+      my_target: {
+        files: {
+          'build/osmd.js': ['src/input.js']
+        }
       }
-    },
-    watch: {
-      scripts: {
-        files: ['src/*', 'Gruntfile.js'],
-        tasks: ['concat', 'jshint'],
+    },*/
+    // TSLint setup
+    tslint: {
         options: {
-          interrupt: true
+            configuration: 'tslint.json'
+        },
+        all: {
+            src: ['<%= browserify.dist.src %>', '<%= browserify.debug.src %>']
         }
-      }
     },
-    copy: {
-      release: {
-        files: [
-          {
-            expand: true,
-            dest: RELEASE_DIR,
-            cwd: BUILD_DIR,
-            src    : ['*.js', 'docs/**', '*.map']
-          }
-        ]
-      }
+    // TypeScript type definitions
+    typings: {
+        install: {}
     },
     docco: {
-      src: SOURCES,
+      src: ['src/**/*.ts'],
       options: {
         layout: 'linear',
         output: 'build/docs'
       }
     },
-    gitcommit: {
-      releases: {
+    // Settings for clean task
+    clean: {
         options: {
-          message: "Committing release binaries for new version: <%= pkg.version %>",
-          verbose: true
+            force: true
         },
-        files: [
-          {
-            src: [RELEASE_DIR + "/*.js", RELEASE_DIR + "/*.map"],
-            expand: true
-          }
-        ]
-      }
-    },
-    bump: {
-      options: {
-        files: ['package.json', 'component.json'],
-        commitFiles: ['package.json', 'component.json'],
-        updateConfigs: ['pkg'],
-        createTag: false,
-        push: false
-      }
-    },
-    release: {
-      options: {
-        bump: false,
-        commit: false
-      }
+        all: {
+            src: [
+                '<%= outputDir.build %>',
+                '<%= outputDir.dist %>',
+                '.tscache'
+            ]
+        }
     },
-    clean: [BUILD_DIR, RELEASE_DIR],
   });
 
-  // Load the plugin that provides the "uglify" task.
-  grunt.loadNpmTasks('grunt-contrib-concat');
-  grunt.loadNpmTasks('grunt-contrib-uglify');
-  grunt.loadNpmTasks('grunt-contrib-jshint');
-  grunt.loadNpmTasks('grunt-contrib-watch');
-  grunt.loadNpmTasks('grunt-contrib-qunit');
-  grunt.loadNpmTasks('grunt-contrib-copy');
+  grunt.loadNpmTasks('grunt-browserify');
   grunt.loadNpmTasks('grunt-contrib-clean');
-  grunt.loadNpmTasks('grunt-docco');
-  grunt.loadNpmTasks('grunt-release');
-  grunt.loadNpmTasks('grunt-bump');
-  grunt.loadNpmTasks('grunt-git');
-
-  // Default task(s).
-  grunt.registerTask('default', ['jshint', 'concat', 'uglify', 'docco']);
-
-  grunt.registerTask('test', 'Run qunit tests.', function() {
-    grunt.task.run('qunit');
-  });
+  grunt.loadNpmTasks('grunt-contrib-watch');
+  //grunt.loadNpmTasks('grunt-jscs');
+  //grunt.loadNpmTasks('grunt-karma');
+  grunt.loadNpmTasks('grunt-tslint');
+  //grunt.loadNpmTasks('grunt-typings');
 
-  // Release current build.
-  grunt.registerTask('stage', 'Stage current binaries to releases/.', function() {
-    grunt.task.run('default');
-    grunt.task.run('copy:release');
-  });
+  grunt.registerTask('default', ['tslint', 'browserify'/*, 'karma:ci'*/]);
+  //grunt.registerTask('lint', ['tslint', 'jscs']);
+  grunt.registerTask('test', ['browserify:debug'/*, 'karma:ci'*/]);
+  //grunt.registerTask('test debug Firefox', ['browserify:debug', /*'karma:debugWithFirefox'*/]);
+  //grunt.registerTask('test debug Chrome', ['browserify:debug', /*'karma:debugWithChrome'*/]);
+  grunt.registerTask('rebuild', ['clean', 'default']);
+  grunt.registerTask('publish', ['clean', 'browserify:dist']);
+  grunt.registerTask('all', ['typings', 'default']);
 };

+ 13 - 4
package.json

@@ -5,7 +5,7 @@
   "main": "build.js",
   "directories": {
     "doc": "docs",
-    "test": "tests"
+    "test": "test"
   },
   "scripts": {
     "test": "echo \"Error: no test specified\" && exit 1"
@@ -27,8 +27,17 @@
   },
   "homepage": "http://opensheetmusicdisplay.org",
   "dependencies": {
-    "browserify": "^8.1.1",
-    "minimist": "^1.1.0",
-    "vexflow": "^1.2.27"
+    "browserify": "",
+    "tsify": "",
+    "tslint": "",
+
+    "grunt": "",
+    "grunt-browserify": "",
+    "grunt-contrib-clean": "",
+    "grunt-contrib-watch": "",
+    "grunt-tslint": "",
+    "grunt-contrib-uglify": "",
+
+    "vexflow": ""
   }
 }

+ 62 - 0
src/Common/FileIO/Xml.ts

@@ -0,0 +1,62 @@
+class XmlAttribute {
+  public Name: string;
+  public Value: string;
+
+  constructor(attr: Attr) {
+    this.Name = attr.name;
+    this.Value = attr.value;
+  };
+}
+
+class XmlElement {
+  public Name: string;
+  public Value: string;
+  public HasAttributes: boolean = false;
+  public FirstAttribute: XmlAttribute;
+  public HasElements: boolean;
+
+  private _attrs: XmlAttribute[];
+  private _elem: Element;
+
+  constructor(elem: Element) {
+    this._elem = elem;
+    if (elem.hasAttributes()) {
+      this.HasAttributes = true;
+      this.FirstAttribute = new XmlAttribute(elem.attributes[0]);
+      }
+    this.HasElements = elem.hasChildNodes();
+  }
+
+  public Attribute(attributeName: string): XmlAttribute {
+    return new XmlAttribute(this._elem.attributes.getNamedItem(attributeName));
+  }
+
+  public Attributes(): XmlAttribute[] {
+    if (typeof this._attrs === "undefined") {
+      let attributes: NamedNodeMap = this._elem.attributes;
+      let attrs: XmlAttribute[] = new Array();
+      for (let i: number = 0; i < attributes.length; i += 1) {
+        attrs.push(new XmlAttribute(attributes[i]));
+      }
+      this._attrs = attrs;
+    }
+    return this._attrs;
+  }
+
+  public Element(elementName: string): XmlElement {
+    return this.Elements(elementName)[0];
+  }
+
+  public Elements(nodeName: string): XmlElement[] {
+    let nodes: NodeList = this._elem.childNodes;
+    let ret: XmlElement[] = new Array();
+    let nameUnset: boolean = typeof nodeName === "undefined";
+    for (let i: number = 0; i < nodes.length; i += 1) {
+      let node: Node = nodes[i];
+      if (node.nodeType === 1 && (nameUnset || node.nodeName === nodeName)) {
+          ret.push(new XmlElement(<Element> node));
+        }
+    }
+    return ret;
+  }
+}