-
Notifications
You must be signed in to change notification settings - Fork 10
/
js2bat.js
59 lines (48 loc) · 1.76 KB
/
js2bat.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
//
// js2bat
// Command line tool to embed js codes to batch scripts
//
// Copyright (c) 2010, 2011, Ildar Shaimordanov
//
//[requires[ js/Ajax.js ]]
//[requires[ js/eval.js ]]
//[requires[ tools/jsxt.tools.js ]]
//[requires[ tools/jsxt.tools.jsCode.js ]]
//[requires[ tools/jsxt.tools.js2bat.js ]]
///////////////////////////////////////////////////////////////////////////
// Display the minimal usage screen
if ( ! WScript.FullName.match(/cscript/i) || WScript.Arguments.Named.Exists('H') ) {
jsxt.tools.help(
WScript.ScriptName.replace(/\..+?$/, ''),
'Copyright (C) 2010, 2011 Ildar Shaimordanov',
'',
'H - this help',
'W - force usage of WSCRIPT as a scripting host',
'WOW - force usage in SysWOW64 environment',
'A:string - additional arguments for s scripting host');
jsxt.tools.quit();
}
var options = {
// Define the script host to be launched (WSCRIPT or CSCRIPT)
useWScript: WScript.Arguments.Named.Exists('W') ,
//Define whether we generate a script to be working in SysWOW64 environment
useSysWOW64: WScript.Arguments.Named.Exists('WOW'),
// Additional arguments for the script host
args: WScript.Arguments.Named('A')
? WScript.Arguments.Named.item('A')
: '//nologo'
};
if ( WScript.Arguments.Unnamed.length == 0 ) {
var lines = jsxt.tools.readFromConsole();
lines = jsxt.tools.js2bat(lines, options);
jsxt.tools.writeToConsole(lines);
jsxt.tools.quit();
}
for (var i = 0; i < WScript.Arguments.Unnamed.length; i++) {
var i_name = WScript.Arguments.Unnamed.item(i);
var lines = jsxt.tools.readFromFile(i_name);
lines = jsxt.tools.js2bat(lines, options);
var o_name = i_name.replace(/\.js/, '.bat');
jsxt.tools.writeToFile(o_name, lines);
}
jsxt.tools.quit();