Browse Source

devkit/cli: -m / mappings to add mappings to find libs

Herbert Vojčík 8 years ago
parent
commit
9f8f0870ac

+ 12 - 2
external/amber-cli/support/amberc-cli.js

@@ -35,7 +35,13 @@ function handle_options(optionsArray) {
 
     while (currentItem != null) {
         switch (currentItem) {
-            case '-l':
+            case '-m':
+                optionsArray.shift.split(',').forEach(function (pairString) {
+                    var mapping = pairString.split(':');
+                    defaults.mappings[mapping[0]] = mapping[1];
+                });
+                break;
+           case '-l':
                 defaults.load.push.apply(defaults.load, optionsArray.shift().split(','));
                 break;
             case '-g':
@@ -78,7 +84,7 @@ function handle_options(optionsArray) {
 // print available flags
 function print_usage_and_exit() {
     var usage = [
-        'Usage: amberc [-l lib1,lib2...] [-g jsGlobal1,jsGlobal2]',
+        'Usage: amberc [-m mapping1,mapping2...] [-l lib1,lib2...] [-g jsGlobal1,jsGlobal2]',
         '          [-n namespace] [-D output_dir] [-v] file1 file2 ...',
         '',
         '   amberc compiles Amber files.',
@@ -88,6 +94,10 @@ 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!',
         '',
+        '  -m amdpath1:realpath1,amdpath2:realpath2',
+        '     Set the amd mappings as comma-separate amd:realpath pairs.',
+        '     Mappings are not separated by spaces or end with .js.',
+        '',
         '  -l library1,library2',
         '     Load the libraries specified as comma-separate AMD module names.',
         '     Module names are not separated by spaces or end with .js.',

+ 11 - 11
external/amber-dev/lib/amberc.js

@@ -23,16 +23,6 @@ function AmberCompiler(amber_dir) {
     }
 
     this.amber_dir = amber_dir;
-    this.requirejs = requirejs.config({
-        context: "amberc",
-        nodeRequire: require,
-        paths: {
-            'amber': path.join(amber_dir, 'support'),
-            'amber_core': path.join(amber_dir, 'src'),
-            'text': require.resolve('requirejs-text').replace(/\.js$/, ""),
-            'amber/without-imports': path.join(__dirname, 'without-imports')
-        }
-    });
     // Important: in next list, boot MUST be first
     this.kernel_libraries = ['amber/boot',
         'amber_core/Kernel-Objects', 'amber_core/Kernel-Classes', 'amber_core/Kernel-Methods',
@@ -51,6 +41,7 @@ function AmberCompiler(amber_dir) {
  */
 var createDefaultConfiguration = function () {
     return {
+        mappings: {},
         load: [],
         stFiles: [],
         jsGlobals: [],
@@ -87,7 +78,16 @@ AmberCompiler.prototype.main = function (configuration, finished_callback) {
     configuration.globals = {};
     configuration.compiler_libraries = this.compiler_libraries;
     configuration.amber_dir = this.amber_dir;
-    configuration.requirejs = this.requirejs;
+
+    configuration.mappings['text'] = require.resolve('requirejs-text').replace(/\.js$/, "");
+    configuration.mappings['amber/without-imports'] = path.join(__dirname, 'without-imports');
+    if (!configuration.mappings.amber) configuration.mappings.amber = path.join(this.amber_dir, 'support');
+    if (!configuration.mappings.amber_core) configuration.mappings.amber_core = path.join(this.amber_dir, 'src');
+    configuration.requirejs = requirejs.config({
+        context: "amberc",
+        nodeRequire: require,
+        paths: configuration.mappings
+    });
 
     check_configuration(configuration)
         .then(collect_st_files)

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

@@ -37,9 +37,11 @@ module.exports = function (grunt) {
 
         var options = this.options({
             amber_dir: undefined,
+            mappings: {},
             verbose: grunt.option('verbose') || false
         });
         this.data.verbose = options.verbose;
+        this.data.mappings = options.mappings;
 
         // mark required properties
         this.requiresConfig('amberc.options.amber_dir');
@@ -69,6 +71,9 @@ module.exports = function (grunt) {
         if (data.libraries != null) {
             configuration.load = data.libraries;
         }
+        if (data.mappings != null) {
+            configuration.mappings = data.mappings;
+        }
         if (sourceFiles != null) {
             configuration.stFiles = sourceFiles;
         }