| 
 | 1 | +const child_process = require('child_process');  | 
 | 2 | +const fs = require('fs');  | 
 | 3 | + | 
 | 4 | +console.log("Start build .....");  | 
 | 5 | +console.log();  | 
 | 6 | + | 
 | 7 | +fs.existsSync("log") || fs.mkdirSync("log");  | 
 | 8 | + | 
 | 9 | +let flag_str = "";  | 
 | 10 | + | 
 | 11 | +var options = (function(argv){  | 
 | 12 | + | 
 | 13 | +    const arr = {};  | 
 | 14 | +    let count = 0;  | 
 | 15 | + | 
 | 16 | +    argv.forEach(function(val, index) {  | 
 | 17 | + | 
 | 18 | +        if(++count > 2){  | 
 | 19 | + | 
 | 20 | +            index = val.split('=');  | 
 | 21 | +            val = index[1];  | 
 | 22 | +            index = index[0].toUpperCase();  | 
 | 23 | + | 
 | 24 | +            flag_str += " --define='" + index + "=" + val + "'";  | 
 | 25 | +            arr[index] = val;  | 
 | 26 | + | 
 | 27 | +            if(count > 3) console.log(index + ': ' + val);  | 
 | 28 | +        }  | 
 | 29 | +    });  | 
 | 30 | + | 
 | 31 | +    console.log('RELEASE: ' + (arr['RELEASE'] || 'custom'));  | 
 | 32 | + | 
 | 33 | +    return arr;  | 
 | 34 | + | 
 | 35 | +})(process.argv);  | 
 | 36 | + | 
 | 37 | +const parameter = (function(opt){  | 
 | 38 | + | 
 | 39 | +    let parameter = '';  | 
 | 40 | + | 
 | 41 | +    for(let index in opt){  | 
 | 42 | + | 
 | 43 | +        if(opt.hasOwnProperty(index)){  | 
 | 44 | + | 
 | 45 | +            parameter += ' --' + index + '=' + opt[index];  | 
 | 46 | +        }  | 
 | 47 | +    }  | 
 | 48 | + | 
 | 49 | +    return parameter;  | 
 | 50 | +})({  | 
 | 51 | + | 
 | 52 | +    compilation_level: "ADVANCED_OPTIMIZATIONS", //"WHITESPACE"  | 
 | 53 | +    use_types_for_optimization: true,  | 
 | 54 | +    //new_type_inf: true,  | 
 | 55 | +    jscomp_warning: "newCheckTypes",  | 
 | 56 | +    //jscomp_error: "strictCheckTypes",  | 
 | 57 | +    jscomp_error: "newCheckTypesExtraChecks",  | 
 | 58 | +    generate_exports: true,  | 
 | 59 | +    export_local_property_definitions: true,  | 
 | 60 | +    language_in: "ECMASCRIPT6_STRICT",  | 
 | 61 | +    language_out: "ECMASCRIPT6_STRICT",  | 
 | 62 | +    process_closure_primitives: true,  | 
 | 63 | +    summary_detail_level: 3,  | 
 | 64 | +    warning_level: "VERBOSE",  | 
 | 65 | +    emit_use_strict: true,  | 
 | 66 | + | 
 | 67 | +    output_manifest: "log/manifest.log",  | 
 | 68 | +    output_module_dependencies: "log/module_dependencies.log",  | 
 | 69 | +    property_renaming_report: "log/property_renaming.log",  | 
 | 70 | +    create_source_map: "log/source_map.log",  | 
 | 71 | +    variable_renaming_report: "log/variable_renaming.log",  | 
 | 72 | +    strict_mode_input: true,  | 
 | 73 | +    assume_function_wrapper: true,  | 
 | 74 | + | 
 | 75 | +    transform_amd_modules: true,  | 
 | 76 | +    process_common_js_modules: true,  | 
 | 77 | +    module_resolution: "BROWSER",  | 
 | 78 | +    //dependency_mode: "SORT_ONLY",  | 
 | 79 | +    //js_module_root: "./",  | 
 | 80 | +    entry_point: "./src/main.js",  | 
 | 81 | +    //manage_closure_dependencies: true,  | 
 | 82 | +    dependency_mode: "PRUNE_LEGACY",  | 
 | 83 | +    rewrite_polyfills: false,  | 
 | 84 | + | 
 | 85 | +    isolation_mode: "IIFE"  | 
 | 86 | +    //output_wrapper: "(function(){%output%}());"  | 
 | 87 | + | 
 | 88 | +    //formatting: "PRETTY_PRINT"  | 
 | 89 | +});  | 
 | 90 | + | 
 | 91 | +exec("java -jar node_modules/google-closure-compiler-java/compiler.jar" + parameter + " --js='src/*.js' --js='src/template/*.es6.js' --js='node_modules/mikado/src/*.js'" + flag_str + " --js_output_file='dist/main.js' && exit 0", function(){  | 
 | 92 | + | 
 | 93 | +    console.log("Build Complete.");  | 
 | 94 | +});  | 
 | 95 | + | 
 | 96 | +function exec(prompt, callback){  | 
 | 97 | + | 
 | 98 | +    const child = child_process.exec(prompt, function(err, stdout, stderr){  | 
 | 99 | + | 
 | 100 | +        if(err){  | 
 | 101 | + | 
 | 102 | +            console.error(err);  | 
 | 103 | +        }  | 
 | 104 | +        else{  | 
 | 105 | + | 
 | 106 | +            if(callback){  | 
 | 107 | + | 
 | 108 | +                callback();  | 
 | 109 | +            }  | 
 | 110 | +        }  | 
 | 111 | +    });  | 
 | 112 | + | 
 | 113 | +    child.stdout.pipe(process.stdout);  | 
 | 114 | +    child.stderr.pipe(process.stderr);  | 
 | 115 | +}  | 
0 commit comments