|
@@ -1,6 +1,7 @@
|
|
|
module.exports = function(grunt) {
|
|
|
|
|
|
var path = require('path');
|
|
|
+ var fs = require('fs');
|
|
|
var amberc = require('../../bin/amberc.js');
|
|
|
|
|
|
|
|
@@ -11,16 +12,17 @@ module.exports = function(grunt) {
|
|
|
closure_jar: ''
|
|
|
},
|
|
|
helloWorld: {
|
|
|
- src: ['HelloWorld.st'],
|
|
|
- working_dir: 'projects/HelloWorld',
|
|
|
- main_class: 'HelloWorld',
|
|
|
- output_name: 'helloWorld',
|
|
|
- libraries: 'Canvas',
|
|
|
- init: 'myInit',
|
|
|
- main_file: 'myMain.js',
|
|
|
- deploy: true,
|
|
|
- output_suffix: 'mySuffix',
|
|
|
- library_suffix: '-0.9',
|
|
|
+ src: ['HelloWorld.st'],
|
|
|
+ working_dir: 'projects/HelloWorld/st',
|
|
|
+ target_dir: 'projects/HelloWorld/js',
|
|
|
+ main_class: 'HelloWorld',
|
|
|
+ output_name: 'helloWorld',
|
|
|
+ libraries: 'Canvas',
|
|
|
+ init: 'myInit',
|
|
|
+ main_file: 'myMain.js',
|
|
|
+ deploy: true,
|
|
|
+ output_suffix: 'mySuffix',
|
|
|
+ library_suffix: '-0.9',
|
|
|
},
|
|
|
},
|
|
|
|
|
@@ -48,8 +50,21 @@ module.exports = function(grunt) {
|
|
|
|
|
|
|
|
|
|
|
|
+ var self = this;
|
|
|
compiler.main(parameters, 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 (self.data.deploy) {
|
|
|
+ var suffix = self.data.output_suffix || 'deploy';
|
|
|
+ suffix = '.' + suffix + '.js';
|
|
|
+ replaceFileSuffix_moveToTargetDir(self.data.src, absolute_target_dir, suffix);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
grunt.file.setBase(current_dir);
|
|
|
+
|
|
|
done();
|
|
|
});
|
|
|
});
|
|
@@ -102,4 +117,21 @@ module.exports = function(grunt) {
|
|
|
return parameters;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+ * 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 (path.existsSync(file)) {
|
|
|
+ fs.renameSync(file, path.join(target_dir, file));
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
};
|