Jelajahi Sumber

devkit: -C / configFile in amberc. Fix #1183.

Herbert Vojčík 8 tahun lalu
induk
melakukan
020fcf842b

+ 9 - 1
external/amber-cli/support/amberc-cli.js

@@ -35,6 +35,9 @@ function handle_options(optionsArray) {
 
     while (currentItem != null) {
         switch (currentItem) {
+            case '-C':
+                defaults.configFile = optionsArray.shift();
+                break;
             case '-p':
                 optionsArray.shift.split(',').forEach(function (pairString) {
                     var mapping = pairString.split(':');
@@ -84,7 +87,7 @@ function handle_options(optionsArray) {
 // print available flags
 function print_usage_and_exit() {
     var usage = [
-        'Usage: amberc [-m mapping1,mapping2...] [-l lib1,lib2...] [-g jsGlobal1,jsGlobal2]',
+        'Usage: amberc [-C configFile | -p mapping1,mapping2...] [-l lib1,lib2...] [-g jsGlobal1,jsGlobal2]',
         '          [-n namespace] [-D output_dir] [-v] file1 file2 ...',
         '',
         '   amberc compiles Amber files.',
@@ -94,6 +97,11 @@ function print_usage_and_exit() {
         '     NOTE: Each .st file is currently considered to be a fileout of a single class',
         '     category of the same name as the file!',
         '',
+        '  -C configFile',
+        '     Set the file with amd config. Normally, you just use config.js here.',
+        '     If used, -p options are ignored and -d is only used if configfile does not',
+        '     contain mappings for amber and/or amber_core.',
+        '',
         '  -p amdpath1:realpath1,amdpath2:realpath2',
         '     Set the amd paths mapping as comma-separate amd:realpath pairs.',
         '     Mapping elements are not separated by spaces or end with .js.',

+ 27 - 9
external/amber-dev/lib/amberc.js

@@ -42,6 +42,7 @@ function AmberCompiler(amber_dir) {
 var createDefaultConfiguration = function () {
     return {
         paths: {},
+        configFile: null,
         load: [],
         stFiles: [],
         jsGlobals: [],
@@ -79,15 +80,32 @@ AmberCompiler.prototype.main = function (configuration, finished_callback) {
     configuration.compiler_libraries = this.compiler_libraries;
     configuration.amber_dir = this.amber_dir;
 
-    configuration.paths['text'] = require.resolve('requirejs-text').replace(/\.js$/, "");
-    configuration.paths['amber/without-imports'] = path.join(__dirname, 'without-imports');
-    if (!configuration.paths.amber) configuration.paths.amber = path.join(this.amber_dir, 'support');
-    if (!configuration.paths.amber_core) configuration.paths.amber_core = path.join(this.amber_dir, 'src');
-    configuration.requirejs = requirejs.config({
-        context: "amberc",
-        nodeRequire: require,
-        paths: configuration.paths
-    });
+    var rjsConfig;
+    if (configuration.configFile) {
+        var configSrc = fs.readFileSync(configuration.configFile, "utf8");
+        rjsConfig = (function () {
+            var require, requirejs;
+            requirejs = require = {
+                config: function (x) {
+                    requirejs = require = x;
+                }
+            };
+            eval(configSrc);
+            return require;
+        })();
+    } else {
+        rjsConfig = {
+            paths: configuration.paths
+        };
+    }
+
+    if (!rjsConfig.paths.amber) rjsConfig.paths.amber = path.join(this.amber_dir, 'support');
+    if (!rjsConfig.paths.amber_core) rjsConfig.paths.amber_core = path.join(this.amber_dir, 'src');
+    rjsConfig.paths['text'] = require.resolve('requirejs-text').replace(/\.js$/, "");
+    rjsConfig.paths['amber/without-imports'] = path.join(__dirname, 'without-imports');
+    rjsConfig.nodeRequire = require;
+    rjsConfig.context = "amberc";
+    configuration.requirejs = requirejs.config(rjsConfig);
 
     check_configuration(configuration)
         .then(collect_st_files)

+ 5 - 0
external/amber-dev/tasks/grunt-amberc.js

@@ -37,10 +37,12 @@ module.exports = function (grunt) {
 
         var options = this.options({
             amber_dir: undefined,
+            configFile: null,
             paths: {},
             verbose: grunt.option('verbose') || false
         });
         this.data.verbose = options.verbose;
+        this.data.configFile = options.configFile;
         this.data.paths = options.paths;
 
         // mark required properties
@@ -71,6 +73,9 @@ module.exports = function (grunt) {
         if (data.libraries != null) {
             configuration.load = data.libraries;
         }
+        if (data.configFile != null) {
+            configuration.configFile = data.configFile;
+        }
         if (data.paths != null) {
             configuration.paths = data.paths;
         }