forked from UIZE/UIZE-JavaScript-Framework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
_test-simpledoc.js
90 lines (79 loc) · 2.76 KB
/
_test-simpledoc.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
/*** boilerplate setup code for WSH build scripts ***/
var
_fileSystemObject = new ActiveXObject ('Scripting.FileSystemObject'),
_currentDirectory = _fileSystemObject.GetParentFolderName(_fileSystemObject.GetFile(WScript.ScriptFullName)) + '\\',
_setupFile = _fileSystemObject.OpenTextFile (
_currentDirectory + '_build-script-setup.js',
1
)
;
eval (_setupFile.ReadAll ()) ({pathToRoot:_currentDirectory});
_setupFile.Close ();
Uize.module ({
required:[
'Uize.Wsh',
'Uize.Doc.Sucker',
'Uize.Doc.Simple',
'Uize.Templates.SimpleDoc'
],
builder:function () {
if (WScript.Arguments.length && _fileSystemObject.FileExists(WScript.Arguments(0))) {
var
_fileExtensionRegExp = /\.[a-z]+$/i,
_file = _fileSystemObject.GetFile(WScript.Arguments(0)),
_fileName = _file.Name,
_fileNameSansExtension = _fileName.replace (_fileExtensionRegExp,''),
_fileIsJsFile = !/\.simple$/i.test (_fileName),
_tempFilePath = _fileSystemObject.GetParentFolderName(_file) + '\\' + _fileSystemObject.GetTempName() + '.html',
_tempFileLastModifiedTime = +new Date
;
WScript.Echo('Watching: ' + _fileName);
function _updateSimpleDocPreview() {
Uize.module ({
required:_fileIsJsFile ? _fileNameSansExtension : '',
builder:function () {
var
_fileText = Uize.Wsh.readFile ({path:_file}),
_simpleDoc = _fileIsJsFile
? Uize.Doc.Sucker.toDocument (_fileText,{result:'full',module:eval (_fileNameSansExtension)})
: Uize.Doc.Simple.toDocument (_fileText,{result:'full'})
;
Uize.Wsh.writeFile({
path:_tempFilePath,
text:Uize.Templates.SimpleDoc.process({
body:_simpleDoc.html,
title:_simpleDoc.metaData.title || _fileNameSansExtension
})
});
_tempFileLastModifiedTime = +new Date;
}
});
}
var
_globalScope = (function() { return this })(),
_browser = WScript.CreateObject('InternetExplorer.Application.1', 'TestSimpleDoc')
// http://msdn.microsoft.com/en-us/library/aa752084(v=vs.85).aspx
;
_globalScope.TestSimpleDocOnQuit = function() {
_fileSystemObject.DeleteFile(_tempFilePath);
WScript.Quit(0);
};
_updateSimpleDocPreview();
_browser.visible = true;
_browser.menuBar = _browser.statusBar = _browser.toolBar = false;
_browser.navigate(_tempFilePath); // go to the file
/*** focus and position the window ***/
var _window = _browser.document.parentWindow;
_window.moveTo ((_window.screen.width - 880) >> 1,0);
_window.resizeTo (880,_window.screen.height);
_window.focus ();
while (true) {
WScript.Sleep(1000); // polling time
if (+_file.DateLastModified > _tempFileLastModifiedTime) {
_updateSimpleDocPreview();
_browser.refresh2(3); // force refresh
}
}
}
}
});