Selaa lähdekoodia

grunt-amberc: remove directory changing hack

For one this was ugly and it was discouraged by grunt.js
Manfred Kroehnert 11 vuotta sitten
vanhempi
commit
300fcf758a
2 muutettua tiedostoa jossa 24 lisäystä ja 67 poistoa
  1. 20 27
      Gruntfile.js
  2. 4 40
      grunt/tasks/grunt-amberc.js

+ 20 - 27
Gruntfile.js

@@ -33,73 +33,66 @@ module.exports = function(grunt) {
         closure_jar: ''
       },
       all: {
-        working_dir: 'st',
         target_dir : 'js',
-        src: ['Kernel-Objects.st', 'Kernel-Classes.st', 'Kernel-Methods.st', 'Kernel-Collections.st',
-              'Kernel-Exceptions.st', 'Kernel-Transcript.st', 'Kernel-Announcements.st',
-              'Importer-Exporter.st', 'Compiler-Exceptions.st', 'Compiler-Core.st', 'Compiler-AST.st',
-              'Compiler-IR.st', 'Compiler-Inlining.st', 'Compiler-Semantic.st',
-              'Canvas.st', 'SUnit.st', 'IDE.st',
-              'Kernel-Tests.st', 'Compiler-Tests.st', 'SUnit-Tests.st'
+        src: ['st/Kernel-Objects.st', 'st/Kernel-Classes.st', 'st/Kernel-Methods.st', 'st/Kernel-Collections.st',
+              'st/Kernel-Exceptions.st', 'st/Kernel-Transcript.st', 'st/Kernel-Announcements.st',
+              'st/Importer-Exporter.st', 'st/Compiler-Exceptions.st', 'st/Compiler-Core.st', 'st/Compiler-AST.st',
+              'st/Compiler-IR.st', 'st/Compiler-Inlining.st', 'st/Compiler-Semantic.st',
+              'st/Canvas.st', 'st/SUnit.st', 'st/IDE.st',
+              'st/Kernel-Tests.st', 'st/Compiler-Tests.st', 'st/SUnit-Tests.st'
               ],
         deploy: true
       },
       amber_kernel: {
-        working_dir: 'st',
         target_dir : 'js',
-        src: ['Kernel-Objects.st', 'Kernel-Classes.st', 'Kernel-Methods.st', 'Kernel-Collections.st',
-              'Kernel-Exceptions.st', 'Kernel-Transcript.st', 'Kernel-Announcements.st'],
+        src: ['st/Kernel-Objects.st', 'st/Kernel-Classes.st', 'st/Kernel-Methods.st', 'st/Kernel-Collections.st',
+              'st/Kernel-Exceptions.st', 'st/Kernel-Transcript.st', 'st/Kernel-Announcements.st'],
         deploy: true
       },
       amber_compiler: {
-        working_dir: 'st',
         target_dir : 'js',
-        src: ['Importer-Exporter.st', 'Compiler-Exceptions.st', 'Compiler-Core.st', 'Compiler-AST.st',
-              'Compiler-IR.st', 'Compiler-Inlining.st', 'Compiler-Semantic.st'],
+        src: ['st/Importer-Exporter.st', 'st/Compiler-Exceptions.st', 'st/Compiler-Core.st', 'st/Compiler-AST.st',
+              'st/Compiler-IR.st', 'st/Compiler-Inlining.st', 'st/Compiler-Semantic.st'],
         output_name: 'Compiler',
         deploy: true
       },
       amber_canvas: {
-        working_dir: 'st',
         target_dir : 'js',
-        src: ['Canvas.st', 'SUnit.st'],
-        deploy: true
+        src: ['st/Canvas.st', 'st/SUnit.st'],
+        deploy: true,
+        verbose: true
       },
       amber_IDE: {
-        working_dir: 'st',
         target_dir : 'js',
-        src: ['IDE.st'],
+        src: ['st/IDE.st'],
         libraries: ['Canvas'],
         deploy: true
       },
       amber_tests: {
-        working_dir: 'st',
         target_dir : 'js',
-        src: ['Kernel-Tests.st', 'Compiler-Tests.st', 'SUnit-Tests.st'],
+        src: ['st/Kernel-Tests.st', 'st/Compiler-Tests.st', 'st/SUnit-Tests.st'],
         libraries: ['SUnit']
       },
       amber_test_runner: {
-        working_dir: 'test',
-        src: ['Test.st'],
+        src: ['test/Test.st'],
         libraries: [
         'Compiler-Exceptions', 'Compiler-Core', 'Compiler-AST',
         'Compiler-IR', 'Compiler-Inlining', 'Compiler-Semantic', 'Compiler-Interpreter', 'parser',
         'SUnit',
         'Kernel-Tests', 'Compiler-Tests', 'SUnit-Tests'],
-        output_name: 'amber_test_runner'
+        output_name: 'test/amber_test_runner'
       },
       amber_dev: {
-        working_dir: 'js',
         src: [
               'Compiler-Exceptions.js', 'Compiler-Core.js', 'Compiler-AST.js',
               'Compiler-IR.js', 'Compiler-Inlining.js', 'Compiler-Semantic.js',
               'Canvas.js', 'IDE.js', 'SUnit.js',
               'Kernel-Tests.js', 'Compiler-Tests.js', 'SUnit-Tests.js'],
-        output_name: 'amber_dev'
+        output_name: 'js/amber_dev'
       },
       amber_cli: {
-        working_dir: 'cli/js',
-        src: ['../st/AmberCli.st'],
+        target_dir: 'cli/js',
+        src: ['cli/st/AmberCli.st'],
         main_class: 'AmberCli',
         output_name: 'amber-cli'
       }

+ 4 - 40
grunt/tasks/grunt-amberc.js

@@ -12,8 +12,7 @@ module.exports = function(grunt) {
          closure_jar: ''               // optional
        },
        helloWorld: {
-         src: ['HelloWorld.st'],                // REQUIRED
-         working_dir: 'projects/HelloWorld/st', // optional
+         src: ['projects/HelloWorld/st/HelloWorld.st'], // REQUIRED
          target_dir: 'projects/HelloWorld/js',  // optional
          main_class: 'HelloWorld',              // optional
          output_name: 'helloWorld',            // optional
@@ -33,13 +32,6 @@ module.exports = function(grunt) {
     this.requiresConfig('amberc._config.amber_dir');
     this.requiresConfig(['amberc', this.target, 'src']);
 
-    // change working directory if the working_dir property is set on the target
-    var current_dir = process.cwd();
-    var working_dir = this.data.working_dir;
-    if (undefined !== working_dir) {
-      grunt.file.setBase(working_dir);
-    }
-
     // mark task as async task
     var done = this.async();
 
@@ -53,18 +45,6 @@ module.exports = function(grunt) {
     // change back to the old working directory and call the async callback once finished
     var self = this;
     compiler.main(configuration, function(){
-      if (undefined !== self.data.target_dir) {
-        var absolute_target_dir = path.join(current_dir, self.data.target_dir);
-        replaceFileSuffix_moveToTargetDir(self.data.src, absolute_target_dir);
-        // if deploy is set also copy the deploy files
-        if (self.data.deploy) {
-          var suffix = self.data.output_suffix || 'deploy';
-          suffix = '.' + suffix + '.js';
-          replaceFileSuffix_moveToTargetDir(self.data.src, absolute_target_dir, suffix);
-        }
-      }
-      // reset working directory
-      grunt.file.setBase(current_dir);
       // signal that task has finished
       done();
     });
@@ -122,28 +102,12 @@ module.exports = function(grunt) {
     if (undefined !== outputName) {
       configuration.program = outputName;
     }
+    if (undefined !== data.target_dir) {
+    	configuration.output_dir = data.target_dir;
+    }
     if (true === data.verbose) {
     	configuration.verbose = true;
     }
     return configuration;
   }
-
-
-  /**
-   * Replace '.st' suffix of \p files with '.js' or with \p replace_suffix if this parameter is given.
-   * Afterwards move the files with replaced suffix to \p target_dir if the files exist.
-   */
-  function replaceFileSuffix_moveToTargetDir(files, target_dir, replace_suffix) {
-    var suffix = replace_suffix || '.js';
-    var compiledFiles = files.map(function(item) {
-      return item.replace(/.st$/g, suffix);
-    });
-
-    compiledFiles.forEach(function(file) {
-      if (fs.existsSync(file)) {
-        console.log('Move: ' + file + ' -> ' + path.join(target_dir, file));
-        fs.renameSync(file, path.join(target_dir, file));
-      }
-    });
-  }
 };