-
Notifications
You must be signed in to change notification settings - Fork 10
/
jsxt.js
190 lines (151 loc) · 4.79 KB
/
jsxt.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
//[requires[ js/Function.js ]]
//[requires[ js/Array.js ]]
//[requires[ js/Ajax.js ]]
//[requires[ js/eval.js ]]
//[requires[ js/win32/FileSystem.js ]]
//[requires[ js/win32/Enumerator.js ]]
//[requires[ jsxt/jsxt.tools.js ]]
//[requires[ jsxt/jsxt.tools.jsCode.js ]]
//[requires[ jsxt/jsxt.tools.js2xml.js ]]
//[requires[ jsxt/jsxt.tools.js2js.js ]]
//[requires[ jsxt/jsxt.tools.vbs2js.js ]]
//[requires[ jsxt/jsxt.tools.js2bat.js ]]
(function()
{
if ( WScript.Arguments.Unnamed.length == 0 || WScript.Arguments.Named.Exists('H') || WScript.Arguments.Named.Exists('HELP') ) {
jsxt.tools.help(arguments.callee.getOneResource());
jsxt.tools.quit();
}
/*![[JSXT Tools Installer
Copyright (C) 2009, 2010, 2011, 2020 Ildar Shaimordanov
Usage: jsxt FILES [/D:targetPath] [/O]
/D - defines the target path where processed files will be stored
/O - use this option to overwrite an original file
The following options affect on js-in-bat launch only:
/W - force usage of WSCRIPT as a scripting host',
/WOW - force usage in SysWOW64 environment',
This is not mandatory action. You can use all these tools "as is".
You do not need run this untility. Download archive and place it's
content to the appropriate directory.
This utility allows you to install JSXT tools to the comfortable
location. It makes two things:
-- embeds specified JS scripts into the tool;
-- squeezes embeded scripts to reduce the size of resulting files.
Reasonable question arises:
"Why I should make install if it works fine without this?"
This was made to provide easy way to make each tool independent of
many files. Once downlanded and installed into the single file the
tool can be used without emergency of lost some parts of tool.
]]*/
})();
/*
Default options
*/
var iniOptions = {
// fils to be included to processing
includePatterns: [
'*.pl',
'*.perl',
'*.pm',
'*.php',
'*.js',
'*.vbs',
'*.wsf',
'*.hta',
'*.bat'],
// files to be excluded from processing
excludePatterns: [
'Sandbox.js',
'jsxt-install.*',
'$$$*',
'jsxt.js.ini'],
// target directory
targetPath: WScript.Arguments.Named.item('D') || '',
useWScript: WScript.Arguments.Named.Exists('W'),
useSysWOW64: WScript.Arguments.Named.Exists('WOW'),
// overwrite an original file
overwrite: WScript.Arguments.Named.Exists('O'),
// minify options
minify: true,
level: 2,
0: 0
};
var includePatterns = FileSystem.wildcard2regexp(iniOptions.includePatterns);
var excludePatterns = FileSystem.wildcard2regexp(iniOptions.excludePatterns);
var processFiles = Enumerator.map(WScript.Arguments.Unnamed, function(v)
{
return v;
})
// expand filename patterns
.map(function(v)
{
var e;
try {
return FileSystem.glob(v);
} catch (e) {
jsxt.tools.alert(e.description);
}
})
// non-empty values only
.filter(function(v)
{
return v;
})
// flatten a possible multi-dimentional array
.flatten()
// stringify values
.map(function(v)
{
return String(v);
})
// remove duplicates
.unique()
// take in account the patterns includePatterns and excludePatterns
.filter(function(v)
{
return v.match(includePatterns) && ! v.match(excludePatterns);
})
;
if ( processFiles.length == 0 ) {
jsxt.tools.alert('Nothing to install. Exit');
jsxt.tools.quit();
}
var fso = new ActiveXObject('Scripting.FileSystemObject');
processFiles.forEach(function(iname)
{
iniOptions.vbsFile = !! iname.match(/\.vbs$/i);
iniOptions.jsFile = !! iname.match(/\.js$/i);
iniOptions.escaped = !! iname.match(/\.(pl|perl|pm|php)$/i);
iniOptions.wsfFile = !! iname.match(/\.wsf$/i);
iniOptions.batFile = !! iname.match(/\.bat$/i);
jsxt.tools.alert('Processing "' + iname + '"...');
var text = jsxt.tools.readFromFile(iname);
var oname = iname;
if ( iniOptions.targetPath ) {
oname = oname.replace(/.+\\/, iniOptions.targetPath + '\\');
}
if ( iniOptions.vbsFile ) {
jsxt.tools.alert('vbs-2-bat converting...');
text = jsxt.tools.vbs2js(text, iniOptions);
text = jsxt.tools.js2bat(text, {
useWScript: WScript.Arguments.Named.Exists('W'),
useSysWOW64: true
});
oname = oname.replace(/\.vbs$/i, '.bat');
} else if ( iniOptions.jsFile ) {
jsxt.tools.alert('js-2-bat converting...');
text = jsxt.tools.js2js(text, iniOptions);
text = jsxt.tools.js2bat(text, iniOptions);
oname = oname.replace(/\.js$/i, '.bat');
} else if ( iniOptions.batFile ) {
text = jsxt.tools.js2js(text, iniOptions);
} else {
text = jsxt.tools.js2xml(text, iniOptions);
}
if ( iname != fso.GetAbsolutePathName(oname) || iniOptions.overwrite ) {
jsxt.tools.writeToFile(oname, text);
} else {
jsxt.tools.alert('Cannot write to the same file. Use /O option.');
}
});
jsxt.tools.quit();