-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathTypescript.build.js
98 lines (76 loc) · 2.74 KB
/
Typescript.build.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// IMPORT
var fs = require('fs'),
cmd = require('child_process').exec;
// VARS
var FILE_ENCODING = 'utf-8';
var EOL = '\n';
var config_file = process.argv[2];
var user_config_file = process.argv[3];
var filename = process.argv[4];
var commands_map = {
"output_dir_path":"--outDir ",
"concatenate_and_emit_output_file_path":"--out ",
"source_files_root_path":"--sourceRoot ",
"map_files_root_path":"--mapRoot ",
"module_kind":"--module ",
"allow_bool_synonym":"--allowbool",
"allow_import_module_synonym":"--allowimportmodule",
"generate_declaration":"--declaration",
"no_implicit_any_warning":"--noImplicitAny",
"skip_resolution_and_preprocessing":"--noResolve",
"remove_comments_from_output":"--removeComments",
"generate_source_map":"--sourcemap",
"ecmascript_target":"--target "
};
var default_values = {
"output_dir_path":"none",
"concatenate_and_emit_output_file_path":"none",
"source_files_root_path":"none",
"map_files_root_path":"none",
"module_kind":"none",
"allow_bool_synonym":false,
"allow_import_module_synonym":false,
"generate_declaration":false,
"no_implicit_any_warning":false,
"skip_resolution_and_preprocessing":false,
"remove_comments_from_output":false,
"generate_source_map":false,
"ecmascript_target":"ES3"
};
////////////////////////////////////////////////////////////////////////////////////////
if(fs.existsSync(user_config_file)) config_file = user_config_file;
var config = JSON.parse(fs.readFileSync(config_file, FILE_ENCODING))['build_parameters'];
function build_commands(){
var tsc = "";
var commands = [];
for (var option in config){
if(default_values[option] != config[option] && option!=='pre_processing_commands' && option!=='post_processing_commands') {
tsc += ' '+commands_map[option]+(default_values[option]!==false?config[option]:'');
}
}
var i,
pre_processing_commands = config['pre_processing_commands'],
post_processing_commands = config['post_processing_commands'];
for (i = 0; i < pre_processing_commands.length; i++) {
commands[commands.length] = pre_processing_commands[i];
}
commands[commands.length] = 'tsc '+'"'+filename+'"'+tsc;
for (i = 0; i < post_processing_commands.length; i++) {
commands[commands.length] =post_processing_commands[i];
}
return commands;
}
var commands = build_commands();
var num_commands = commands.length;
var index = 0;
function exec(index){
console.log('executing command : '+commands[index]);
cmd(commands[index],function(err,stdout,stderr){
if(stdout!==null && stdout!=='') console.log(stdout);
if(stderr!==null && stderr!=='') console.log(stderr);
if(index+1<num_commands) exec(index+1);
});
}
console.log('T3S building ... '+commands+'\n');
exec(0);
////////////////////////////////////////////////////////////////////////////////////////