Browse Source

Merge pull request #435 from mkroehnert/grunt-0.4

Update to Grunt.js v0.4 and require Node.js v0.8
Nicolas Petton 11 năm trước cách đây
mục cha
commit
fb99845ff3
10 tập tin đã thay đổi với 317 bổ sung250 xóa
  1. 3 1
      .travis.yml
  2. 12 36
      Gruntfile.js
  3. 17 3
      README.md
  4. 8 8
      bin/amberc.js
  5. 1 1
      grunt/tasks/grunt-amberc.js
  6. 17 0
      grunt/tasks/grunt-css2js.js
  7. 29 0
      grunt/tasks/grunt-peg.js
  8. 5 1
      package.json
  9. 4 4
      server/FileServer.st
  10. 221 196
      server/server.js

+ 3 - 1
.travis.yml

@@ -1,3 +1,5 @@
 language: node_js
 node_js:
-  - 0.8
+  - 0.8
+before_script:
+  - npm install -g grunt-cli

+ 12 - 36
grunt.js → Gruntfile.js

@@ -2,25 +2,28 @@ module.exports = function(grunt) {
 
   grunt.loadTasks('./grunt/tasks');
 
-  grunt.loadNpmTasks('grunt-image-embed');
-  grunt.loadNpmTasks('grunt-contrib-mincss');
+  grunt.loadNpmTasks('grunt-contrib-jshint');
+//  grunt.loadNpmTasks('grunt-image-embed');
+//  grunt.loadNpmTasks('grunt-contrib-mincss');
 
-  grunt.registerTask('default', 'pegjs amberc:all');
+  grunt.registerTask('default', 'peg amberc:all');
 
   grunt.initConfig({
-    pkg: '<json:package.json>',
+    pkg: grunt.file.readJSON('package.json'),
 
     meta: {
       banner: '/*!\n <%= pkg.title || pkg.name %> - v<%= pkg.version %> - <%= grunt.template.today("yyyy-mm-dd") %> \n License: <%= pkg.license.type %> \n*/\n'
     },
 
-    pegjs: {
+    peg: {
       amber_parser: {
+        options: {
+          trackLineAndColumn: true,
+          cache: true,
+          export_var: 'smalltalk.parser'
+        },
         src: 'js/parser.pegjs',
         dest: 'js/parser.js',
-        trackLineAndColumn: true,
-        cache: true,
-        export_var: 'smalltalk.parser'
       }
     },
 
@@ -108,7 +111,7 @@ module.exports = function(grunt) {
       }
     },
 
-    lint: {
+    jshint: {
       amber: ['js/*.js'],
       server: ['server/*.js'],
       repl: ['repl/*.js'],
@@ -174,31 +177,4 @@ module.exports = function(grunt) {
     }
 */
   });
-
-  grunt.registerMultiTask('css2js', 'Embed CSS into JS', function() {
-    var cssContent = grunt.task.directive(grunt.file.expandFiles(this.data.src)[0], grunt.file.read);
-    var content =
-      'var css="' + cssContent + '";' +
-      'var cssTag = document.createElement("link");' +
-      'document.head = document.head || document.getElementsByTagName("head")[0];' +
-      'cssTag.href = "data:text/css,"+css;' +
-      'cssTag.rel = "stylesheet";' +
-      'document.head.appendChild(cssTag);';
-
-    grunt.file.write(this.data.dest, content);
-
-    grunt.log.writeln('File "' + this.data.dest + '" created.');
-  });
-
-  grunt.registerMultiTask('pegjs', 'Generate JavaScript parser from PEG.js description', function() {
-    var PEG = require('pegjs');
-    var pegOptions = {
-      cache: this.data.cache || false,
-      trackLineAndColumn: this.data.trackLineAndColumn || false
-    };
-    var export_var = this.data.export_var || 'module.exports';
-    var parser = PEG.buildParser(grunt.file.read(this.data.src), pegOptions);
-    var content = export_var + ' = ' + parser.toSource() + ';\n';
-    grunt.file.write(this.data.dest, content);
-  });
 };

+ 17 - 3
README.md

@@ -27,12 +27,26 @@ Amber is released under the MIT license. All contributions made for inclusion ar
 Building Amber
 --------------
 
-Since 0.10.0 Amber uses [Grunt.js](http://gruntjs.com/) as build system.
-To compile Amber on the commandline execute the following commands:
+Amber uses [Grunt.js](http://gruntjs.com/) as build system since version `0.10.0`.
 
+If you already have Grunt.js v0.3.x installed locally run the following (otherwise ignore these lines):
+
+    cd ${Amber_DIR}
+    npm uninstall grunt
+
+To install Grunt.js v0.4.x on the commandline execute the following commands:
+    
+    npm install -g grunt-cli grunt-init
     cd ${Amber_DIR}
     npm install
-    ./node_modules/grunt/bin/grunt
+
+And finally, compile Amber using the following command:
+
+    cd ${Amber_DIR}
+    grunt
+
+For Windows support check the [Grunt.js on Windows](http://gruntjs.com/frequently-asked-questions#does-grunt-work-on-windows) page.
+
 
 More infos
 ----------

+ 8 - 8
bin/amberc.js

@@ -183,7 +183,7 @@ AmberC.prototype.check_for_closure_compiler = function(callback) {
 				callback();
 				return;
 			}
-			path.exists(self.closure_jar, function(exists) {
+			fs.exists(self.closure_jar, function(exists) {
 				if (!exists) {
 					console.warn('Can not find Closure compiler at: ' + self.closure_jar);
 					defaults.closure = false;
@@ -214,11 +214,11 @@ AmberC.prototype.resolve_js = function(filename, callback) {
 	var jsFile = baseName + this.defaults.loadsuffix + '.js';
 	var amberJsFile = path.join(this.amber_dir, 'js', jsFile);
 	console.log('Resolving: ' + jsFile);
-	path.exists(jsFile, function(exists) {
+	fs.exists(jsFile, function(exists) {
 		if (exists) {
 			callback(jsFile);
 		} else {
-			path.exists(amberJsFile, function(exists) {
+			fs.exists(amberJsFile, function(exists) {
 				if (exists) {
 					callback(amberJsFile);
 				} else {
@@ -273,11 +273,11 @@ AmberC.prototype.collect_st_files = function(stFiles, callback) {
 		console.log('Checking: ' + stFile);
 		var category = path.basename(stFile, '.st');
 		var amberStFile = path.join(self.amber_dir, 'st', stFile);
-		path.exists(stFile, function(exists) {
+		fs.exists(stFile, function(exists) {
 			if (exists) {
 				_callback(stFile, category);
 			} else {
-				path.exists(amberStFile, function(exists) {
+				fs.exists(amberStFile, function(exists) {
 					if (exists) {
 						_callback(amberStFile, category);
 					} else {
@@ -491,7 +491,7 @@ AmberC.prototype.verify = function() {
 	console.log('Verifying if all .st files were compiled');
 	var self = this;
 	async_map(this.defaults.compiled, function(file, callback) {
-			path.exists(file, function(exists) {
+			fs.exists(file, function(exists) {
 				if (exists)
 					callback(null, null);
 				else
@@ -545,7 +545,7 @@ AmberC.prototype.compose_js_files = function() {
 	});
 
 	program_files.forEach(function(file) {
-		if(path.existsSync(file)) {
+		if(fs.existsSync(file)) {
 			console.log('Adding : ' + file);
 			fileStream.write(fs.readFileSync(file));
 		} else {
@@ -558,7 +558,7 @@ AmberC.prototype.compose_js_files = function() {
 		fileStream.write('smalltalk.' + defaults.main + '._main()');
 	}
 
-	if (undefined !== defaults.mainfile && path.existsSync(defaults.mainfile)) {
+	if (undefined !== defaults.mainfile && fs.existsSync(defaults.mainfile)) {
 		console.log('Adding main file: ' + defaults.mainfile);
 		fileStream.write(fs.readFileSync(defaults.mainfile));
 	}

+ 1 - 1
grunt/tasks/amberc-grunt.js → grunt/tasks/grunt-amberc.js

@@ -136,7 +136,7 @@ module.exports = function(grunt) {
     });
 
     compiledFiles.forEach(function(file) {
-      if (path.existsSync(file)) {
+      if (fs.existsSync(file)) {
         console.log('Move: ' + file + ' -> ' + path.join(target_dir, file));
         fs.renameSync(file, path.join(target_dir, file));
       }

+ 17 - 0
grunt/tasks/grunt-css2js.js

@@ -0,0 +1,17 @@
+module.exports = function(grunt) {
+  grunt.registerMultiTask('css2js', 'Embed CSS into JS', function() {
+    var cssContent = grunt.task.directive(grunt.file.expandFiles(this.data.src)[0], grunt.file.read);
+    var content =
+      'var css="' + cssContent + '";' +
+      'var cssTag = document.createElement("link");' +
+      'document.head = document.head || document.getElementsByTagName("head")[0];' +
+      'cssTag.href = "data:text/css,"+css;' +
+      'cssTag.rel = "stylesheet";' +
+      'document.head.appendChild(cssTag);';
+
+    grunt.file.write(this.data.dest, content);
+
+    grunt.log.writeln('File "' + this.data.dest + '" created.');
+  });
+
+};

+ 29 - 0
grunt/tasks/grunt-peg.js

@@ -0,0 +1,29 @@
+module.exports = function(grunt) {
+
+  var PEG = require('pegjs');
+
+  /**
+    Full config looks like this:
+    pegjs: {
+       my_parser: {
+         options: {                       // optional
+           trackLineAndColumn: true,      // default: false
+           cache: true,                   // default: false
+           export_var: 'smalltalk.parser' // default: module.exports
+         },
+         src: 'parser.pegjs',
+         dest: 'parser.js',
+       }
+     },
+   */
+  grunt.registerMultiTask('peg', 'Generate JavaScript parser from PEG.js grammar description', function() {
+    var options = this.options({
+      cache: false,
+      trackLineAndColumn: false,
+      export_var: 'module.exports'
+    });
+    var parser = PEG.buildParser(grunt.file.read(this.data.src), options);
+    var content = options.export_var + ' = ' + parser.toSource() + ';\n';
+    grunt.file.write(this.data.dest, content);
+  });
+};

+ 5 - 1
package.json

@@ -16,6 +16,9 @@
         "type": "git",
         "url": "git://github.com/amber-smalltalk/amber.git#0.10.0"
     },
+    "engines": {
+        "node": "0.8.x"
+    },
     "bin": {
         "amber": "./bin/amber",
         "amberc": "./bin/amberc",
@@ -26,7 +29,8 @@
     },
     "devDependencies": {
         "pegjs": "~0.7.0",
-        "grunt": "~0.3.17",
+        "grunt": "~0.4.0",
+        "grunt-contrib-jshint": "~0.3.0",
         "grunt-image-embed": "~0.1.3",
         "grunt-contrib-mincss": "~0.3.2"
     }

+ 4 - 4
server/FileServer.st

@@ -48,11 +48,11 @@ initialize
 !
 
 checkDirectoryLayout
-	(path existsSync: self basePath, 'index.html') ifFalse: [
+	(fs existsSync: self basePath, 'index.html') ifFalse: [
 		console warn: 'Warning: project directory does not contain index.html'].
-	(path existsSync: self basePath, 'st') ifFalse: [
+	(fs existsSync: self basePath, 'st') ifFalse: [
 		console warn: 'Warning: project directory is missing an "st" directory'].
-	(path existsSync: self basePath, 'js') ifFalse: [
+	(fs existsSync: self basePath, 'js') ifFalse: [
 		console warn: 'Warning: project directory is missing a "js" directory'].
 ! !
 
@@ -111,7 +111,7 @@ handleGETRequest: aRequest respondTo: aResponse
 	| uri filename |
 	uri := (url parse: aRequest url) pathname.
 	filename := path join: self basePath with: uri.
-	path exists: filename do: [:aBoolean |
+	fs exists: filename do: [:aBoolean |
 		aBoolean
 			ifFalse: [self respondNotFoundTo: aResponse]
 			ifTrue: [self respondFileNamed: filename to: aResponse]]

Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 221 - 196
server/server.js


Một số tệp đã không được hiển thị bởi vì quá nhiều tập tin thay đổi trong này khác