| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 | #!/usr/bin/env nodevar path = require('path');var amberc = require('amber-dev/lib/amberc');// get parameters passed to the command line script// discard the first two parameters which are the node binary and the script namevar parameters = process.argv.slice(2);// check if at least one parameter was passed to the scriptif (1 > parameters.length) {    print_usage_and_exit();}// Get Amber root directory from the location of this script so that// we can find the st and js directories etc.var amber_dir = path.normalize(path.join(__dirname, '..', 'node_modules', 'amber'));var configuration = handle_options(parameters);var compiler = new amberc.Compiler(amber_dir);compiler.main(configuration);/** * Process given program options and update defaults values. * Followed by check_for_closure_compiler() and then collect_files(). */function handle_options(optionsArray) {    var programName = [];    var currentItem = optionsArray.shift();    var defaults = amberc.createDefaultConfiguration();    while (currentItem != null) {        switch (currentItem) {            case '-C':                defaults.configFile = optionsArray.shift();                break;            case '-p':                optionsArray.shift.split(',').forEach(function (pairString) {                    var mapping = pairString.split(':');                    defaults.paths[mapping[0]] = mapping[1];                });                break;           case '-l':                defaults.load.push.apply(defaults.load, optionsArray.shift().split(','));                break;            case '-g':                defaults.jsGlobals.push.apply(defaults.jsGlobals, optionsArray.shift().split(','));                break;            case '-n':                defaults.amdNamespace = optionsArray.shift();                break;            case '-D':                defaults.outputDir = optionsArray.shift();                break;            case '-d':                amber_dir = path.normalize(optionsArray.shift());                break;            case '-v':                defaults.verbose = true;                break;            case '-h':            case '--help':            case '?':            case '-?':                print_usage_and_exit();                break;            default:                defaults.stFiles.push(currentItem);                break;        }        currentItem = optionsArray.shift();    }    if (1 < programName.length) {        throw new Error('More than one name for ProgramName given: ' + programName);    } else {        defaults.program = programName[0];    }    return defaults;}// print available flagsfunction print_usage_and_exit() {    var usage = [        '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.',        '   Files are compiled into .js files before concatenation.',        '   If not found we look in $AMBER/src/',        '',        '     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.',        '',        '  -l library1,library2',        '     Load the libraries specified as comma-separate AMD module names.',        '     Module names are not separated by spaces or end with .js.',        '',        '  -g jsGlobal1,jsGlobal2',        '     Comma separated list of JS global variable names.',        '     The names are added to a list containing "window", "document" and others.',        '',        '  -n amd_namespace',        '     Export packages with <amd_namespace> as the require.js namespace.',        '     Default value is "amber_core".',        '',        '  -v',        '     Produce a more verbose output.',        '',        '  -D',        '     Specifies the output directory for all generated .js files.',        '     The hierarchy of the input files is not maintaned.',        '     If this option is omitted all generated .js files are placed next to their input files',        '',        '  -d',        '     Specifies the alternate directory to look for Amber files.',        '     If not specified, the version embedded in CLI is used.',        '',        '     Example invocations:',        '',        '     Just compile Kernel-Objects.st to Kernel-Objects.js:',        '',        '        amberc Kernel-Objects.st',    ];    usage.forEach(function (line) {        console.log(line);    });    process.exit();}
 |