-
Notifications
You must be signed in to change notification settings - Fork 3
/
browserRoller.html
192 lines (174 loc) · 5.73 KB
/
browserRoller.html
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
191
192
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8' />
<title>Browser Roller</title>
<style>
#container{
position: absolute;
right: 0;
left: 0;
top: 0;
bottom: 0;
margin: 5px 5px 5px 5px;
}
#inputPanel, #outputPanel{
position: absolute;
top: 30px;
bottom: 20px;
}
#inputPanel {
left: 0;
width: 50%;
}
#outputPanel{
width: 50%;
right: 0;
}
#editor, #otherOptions, #output, #preferredVersions, #statusMessage, #toolbar, #optionsSection, #editorPanel, #otherOptionsPanel, #versionsPanel, .panelHeader, .panelBody{
position: absolute;
left: 0;
right: 0;
}
#editorPanel{
top: 0px;
height: 50%;
}
.panelHeader {
font: 16px "Open Sans", sans-serif;
top: 0px;
height: 20px;
}
.panelBody{
top: 20px;
bottom: 0;
}
#optionsSection {
bottom: 0px;
height: 50%;
}
#versionsPanel{
top: 0px;
height: 50%;
}
#otherOptionsPanel{
bottom: 0px;
height: 50%;
}
#toolbar{
top: 0;
height: 30px;
}
#statusMessage{
font: 16px "Open Sans", sans-serif;
bottom: 0;
height: 20px;
}
</style>
</head>
<body>
<div id="container">
<div id="toolbar">
<input size="12" placeholder="moduleName" id="moduleName"></input>
<select id="exportType">
<option value="umd">UMD</option>
<option value="iife">Globals</option>
<option value="es">ES6</option>
<option value="amd">AMD</option>
<option value="cjs">CommonJS</option>
</select>
<button id="rollButton">Roll</button>
</div>
<div id="inputPanel">
<div id="editorPanel">
<div class="panelHeader">main.js</div>
<div class="panelBody" id="editor"></div>
</div>
<div id="optionsSection">
<div id="versionsPanel">
<div class="panelHeader">Preferred Versions:</div>
<div class="panelBody" id="preferredVersions"></div>
</div>
<div id="otherOptionsPanel">
<div class="panelHeader">Other Options:</div>
<div class="panelBody" id="otherOptions"></div>
</div>
</div>
</div>
<div id="outputPanel">
<div class="panelHeader">Output:</div>
<div class="panelBody" id="output"></div>
</div>
<div id="statusMessage"></div>
</div>
<script src="./libs/d3.v3.min.js"></script>
<script src="./libs/esprima.js"></script>
<script src="./libs/rollup.browser.js"></script>
<script src="./libs/semver.browser.js"></script>
<script src="./js/npmloader.js"></script>
<script src="./js/npmroller.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.2.3/ace.js"></script>
<script>
// browserRoller.html alpha; probably buggy
// Copyright (c) Steve Tung All Rights Reserved
var editor = ace.edit("editor");
var output = ace.edit("output");
var otherOptions = ace.edit("otherOptions");
var preferredVersions = ace.edit("preferredVersions");
var defaultModuleName = "myModule";
var defaultOtherOptions = '{\n}';
var statusMessage = document.getElementById("statusMessage");
var rollButton = document.getElementById("rollButton");
var exportType = document.getElementById("exportType");
var moduleName = document.getElementById("moduleName");
editor.getSession().setMode("ace/mode/javascript");
output.getSession().setMode("ace/mode/javascript");
preferredVersions.getSession().setMode("ace/mode/json");
otherOptions.getSession().setMode("ace/mode/json");
output.setReadOnly(true);
var restoreFromFragment = function(){
var restoredJSON = JSON.parse(decodeURIComponent(window.location.hash.replace("#", ""))||"{}");
editor.setValue(restoredJSON.mainjs || '', 1);
otherOptions.setValue(restoredJSON.otherOptions || '{\n}', -1),
preferredVersions.setValue(restoredJSON.preferredVersions || '{\n}', -1),
moduleName.value = (restoredJSON.moduleName || defaultModuleName);
exportType.value = (restoredJSON.exportType || 'umd');
};
var saveToFragment = function(){
window.location.hash = encodeURIComponent(JSON.stringify({
mainjs: editor.getValue(),
preferredVersions: preferredVersions.getValue(),
otherOptions: otherOptions.getValue(),
moduleName: moduleName.value,
exportType: exportType.value
}));
};
var messenger = function(message){
if(message.type === 'status') {
statusMessage.innerHTML = message.message;
}
};
rollButton.addEventListener("click", function(){
saveToFragment();
var options = JSON.parse(otherOptions.getValue().trim() || '{}');
var versions = JSON.parse(preferredVersions.getValue().trim() || '{}');
options.format = options.format || exportType.value;
options.moduleName = options.moduleName ||moduleName.value;
npmroller.roll({
configjs: editor.getValue(),
messenger: messenger,
preferredVersions: versions,
external: options.external
}).then(function(bundle){
messenger('Finished Rolling!');
var generated = bundle.generate(options);
output.setValue(generated.code);
}).catch(function(err){
messenger('Error: '+err.message);
console.warn(err);
});
});
restoreFromFragment();
</script>
</body>
</html>