Best JavaScript code snippet using jest
ui.js
Source:ui.js
12var UI = {34 //#region å
Œ
±56 // å½å页é¢ã7 currentStep: 1,89 // å½åå¨ç¼è¾çæå
æ¹æ¡æ件ã10 currentBuildFile: null,1112 // æ¯å¦ä½¿ç¨ xfly è¿è¡æä½ï¼èä¸æ¯å¨å®¢æ·ç«¯å¤çã13 usingXFly: true,1415 // 模åæ示ç¨çæ°æ®ã16 _suggestData: null,1718 // åå§åå
¨é¨é»è¾ã19 init: function () {2021 // åªæ¾ç¤ºç¬¬ä¸ä¸ªé¢æ¿ã22 Dom.query('.panel').hide();23 Dom.show(Dom.get('step' + UI.currentStep));24 UI.step(1);2526 ModuleBuilder.moduleBasePath = Demo.baseUrl + Demo.Configs.src;2728 },2930 // åæ¢å°ä¸åç页é¢ã31 step: function (value) {3233 var me = this;3435 // æ ¹æ®ä¸åçæ¥éª¤è¿è¡åå§åã36 switch (value) {37 case 1:3839 // å¦æä½¿ç¨ xfly, å
æµè¯æ¯å¦å¯ä»¥æ£å¸¸å°è¿æ¥å°æå¡å¨ã40 if (UI.usingXFly) {4142 // çå¾
æå¡å¨æ£å¸¸åè°åï¼è®¾ç½®å¼ä¸º trueã43 UI.usingXFly = false;44 Ajax.jsonp(Demo.Configs.serverBaseUrl + Demo.Configs.apps + "/node/modulebuilder/server/api.njs?action=recentbuildfiles", function (data) {45 UI.usingXFly = true;46 me._showBuildFileListHtml('step1_buildfilelist', 'å·²ä¿åçæå
æ¹æ¡', data);47 });48 }4950 break;5152 case 2:5354 // æ¾ç¤ºæå¼åå²ã55 var data = window.localStorage && localStorage.moduleBuilderOpenList;5657 me._showBuildFileListHtml('step2_buildfilelist', 'æè¿çæå
æ¹æ¡', data && data.split(';'), true);5859 break;6061 case 3:62 UI._showBuildFile();6364 // åå§å UI çé¢ã65 if (!UI._suggestData) {6667 var r = UI._suggestData = {};6869 for (var key in ModuleList.src) {7071 var type = ModuleList.src[key];7273 if (type === ".js") {74 key = key.substr(0, key.length - 3);75 } else if (type === ".css") {76 key = key.substr(0, key.length - 4);77 } else {78 continue;79 }8081 if (r[key]) {82 r[key] = ".js+.css";83 } else {84 r[key] = type;85 }86 }8788 var suggest = new Suggest(Dom.get('step3_module'));8990 suggest.getSuggestItems = function (text) {91 var r = [];9293 if (!text) {94 for (var key in UI._suggestData) {95 if (UI.currentBuildFile.includes.indexOf(key) < 0 && UI.currentBuildFile.excludes.indexOf(key)) {96 r.push(key);97 }98 }99 } else if (/\.$/.test(text)) {100 r.push(text.substr(0, text.length - 1), text + "js", text + "css");101 } else {102 for (var key in UI._suggestData) {103 if (UI.currentBuildFile.includes.indexOf(key) < 0 && UI.currentBuildFile.excludes.indexOf(key)) {104 if (key.indexOf(text) === 0) {105 r.push("<strong>" + text + "</strong>" + key.substr(text.length));106 } else if (key.indexOf("/" + text) >= 0) {107 r.push(key.replace("/" + text, "/<strong>" + text + "</strong>"));108 }109 }110 }111 }112113 return r;114 };115116117 Dom.keyNav(Dom.get('step3_module'), {118 enter: function () {119 if (suggest.isDropDownHidden()) {120 UI.addModule();121 }122 }123 });124125 }126127 break;128129 }130131 // ä»å·¦å°å³æ¸åã132 if (UI.currentStep < value) {133 Dom.show(Dom.get('step' + value));134 Dom.animate(Dom.get('container'), { marginLeft: '0--' + Dom.get('step' + UI.currentStep).offsetWidth }, -1, function () {135 Dom.get('container').style.marginLeft = 0;136 Dom.hide(Dom.get('step' + UI.currentStep));137 UI.currentStep = value;138 });139 } else if (UI.currentStep > value) {140 Dom.show(Dom.get('step' + value));141 Dom.animate(Dom.get('container'), { marginLeft: '-' + Dom.get('step' + UI.currentStep).offsetWidth + '-0' }, -1, function () {142 Dom.hide(Dom.get('step' + UI.currentStep));143 UI.currentStep = value;144 });145 }146 },147148 // æ ¹æ®æ¨¡åå表çæ HTML 模æ¿ã149 _showBuildFileListHtml: function (id, title, data, fromOpenList) {150151 id = Dom.get(id);152153 if (data && data.length) {154155 id.style.display = 'block';156157 var r = ['<div class="hint">' + title + ' ââââââââââââââââââââââââââââââââââââââââââââ</div>'];158159 for (var i = 0; i < data.length; i++) {160161 var path = data[i],162 name = path;163164 if (!fromOpenList) {165 path = Demo.baseUrl + path;166 name = Path.basename(name, ".js");167 }168169 path = path.replace(/\\/g, "/");170171172 r.push('<div class="line" onmouseover="this.className += \' line-hover\'" onmouseout="this.className = this.className.replace(\' line-hover\', \'\');"><nav class="demo demo-toolbar"><a href="javascript://æå¼æ¤æå
æ¹æ¡" onclick="UI.openBuildFile(\'' + path + '\',' + fromOpenList + ');return false;">æå¼</a> | <a class="demo-viewsource-toggle" href="javascript://å é¤æ¤æå
æ¹æ¡" onclick="UI.deleteBuildFile(\'' + path + '\',' + fromOpenList + '); return false;">å é¤</a> | <a href="javascript://å¤å¶æ¤æå
æ¹æ¡" onclick="UI.copyBuildFile(\'' + path + '\',' + fromOpenList + ');return false;">å¤å¶</a> | <a class="demo-viewsource-toggle" href="javascript://æ ¹æ®æ¤æå
æ¹æ¡éæ°çæ" onclick="UI.buildBuildFile(\'' + path + '\',' + fromOpenList + '); return false;">çæ</a></nav><a class="link" href="javascript://æå¼æ¤æå
æ¹æ¡" onclick="UI.openBuildFile(\'' + path + '\',' + fromOpenList + ');return false;">' + name + '</a></div>');173 }174175 id.innerHTML = r.join('');176 } else {177 id.style.display = 'none';178179 }180181 },182183 //#endregion184185 //#region 第ä¸äºæ¥186187 // å建æ°çæå
æ¹æ¡ã188 createNewBuildFile: function () {189190 // å¦æä¹åå·²ç»æ°å»ºè¿ï¼åä¸åæ°å»ºã191 if (UI.currentBuildFile && UI.currentBuildFile.isNew) {192 UI.step(3);193 return;194 }195196 // å建æ°çæå
æ¹æ¡ã197 UI.currentBuildFile = new BuildFile();198 UI.currentBuildFile.isNew = true;199 UI.step(3);200 },201202 // æå¼å
¶ä»æå
æ¹æ¡ã203 openOtherBuildFile: function () {204 UI.step(2);205 },206207 // æå¼æå®çæå
æ¹æ¡ã208 openBuildFile: function (buildFilePath) {209 UI._loadBuildFile(buildFilePath, function (buildFile) {210 UI.currentBuildFile = buildFile;211 UI.step(3);212 });213 },214215 // å é¤æå®çæå
æ¹æ¡ã216 deleteBuildFile: function (buildFilePath, fromOpenList) {217218 if (fromOpenList) {219220221222 var data = window.localStorage && localStorage.moduleBuilderOpenList;223 if (data = data && data.split(';')) {224 var p = data.indexOf(buildFilePath);225 if (p >= 0) {226 data.splice(p, 1);227 }228229 localStorage.moduleBuilderOpenList = data.join(';');230 UI.step(2);231 }232 } else {233234 if (!confirm("确认å é¤æå
æ¹æ¡æ件 " + buildFilePath + " å?"))235 return;236237 UI._jsonpNode('deletebuildfile', {238 path: buildFilePath,239 }, function () {240 UI.step(1);241 });242 }243 },244245 _loadBuildFile: function (buildFilePath, callback) {246247 // ç»å¯¹è·¯å¾ï¼åºäºæå¡å¨æå¼ã248 if (buildFilePath.indexOf(':') >= 0 && buildFilePath.indexOf(location.protocol + '//' + location.host + '/') !== 0) {249250 if (!UI.usingXFly) {251 UI._alertOpenXFlyError();252 } else {253 UI._jsonpNode('read', {254 path: buildFilePath255 }, function (content) {256257 var buildFile = new BuildFile();258 buildFile.load(content);259260 buildFile.path = buildFilePath;261 callback(buildFile);262263 });264 }265266 } else {267 ModuleBuilder.load(buildFilePath, callback);268 }269270 },271272 // å¤å¶æå®çæå
æ¹æ¡ã273 copyBuildFile: function (buildFilePath) {274 UI._loadBuildFile(buildFilePath, function (buildFile) {275 UI.currentBuildFile = buildFile;276277 buildFile.js = buildFile.css = buildFile.assets = buildFile.path = "";278279 UI.step(3);280 });281 },282283 // ç¼è¯æå®çæå
æ¹æ¡ã284 buildBuildFile: function (buildFilePath) {285 UI._loadBuildFile(buildFilePath, function (buildFile) {286 UI.currentBuildFile = buildFile;287 UI._buildInternal();288 });289 },290291 _alertOpenXFlyError: function () {292 if (navigator.userAgent.indexOf("Windows") >= 0) {293 alert("é误: éè¦å
å¯å¨æ¬å°ä»£çæå¡å¨æè½è¯»åæ¬å°æ件ã\r\nå¯å¨æ¹æ³: åå»æå¼\"[åºæ ¹ç®å½]/apps/startserver.cmd\", 并ä¸è¦å
³éçªå£ã");294 } else {295 alert("é误: éè¦å
å¯å¨æ¬å°ä»£çæå¡å¨æè½è¯»åæ¬å°æ件ã\r\nå¯å¨æ¹æ³: 请å
å®è£
nodejs, ç¶åå¯å¨\"[åºæ ¹ç®å½]/apps/startserverã\"");296 }297 },298299 _jsonpNode: function (action, data, callback) {300 Ajax.jsonp(Demo.Configs.serverBaseUrl + Demo.Configs.apps + "/node/modulebuilder/server/api.njs?action=" + action, data, callback, UI._alertOpenXFlyError);301 },302303 // æå¼æ°è¾å
¥çæå
æ¹æ¡ã304 openBuildFileOf: function () {305 UI._openOrBuildBuildFileOf(UI.openBuildFile);306 },307308 // ç¼è¯æ°è¾å
¥çæå
æ¹æ¡ã309 buildBuildFileOf: function () {310 UI._openOrBuildBuildFileOf(UI.buildBuildFile);311 },312313 _openOrBuildBuildFileOf: function (callback) {314 UI._checkValue('step2_url', function (buildFilePath) {315316 if (/^\w+\//.test(buildFilePath)) {317 buildFilePath = "/" + buildFilePath;318 }319320 if (window.localStorage) {321 var data = (localStorage.moduleBuilderOpenList || "").split(';');322 if (data.indexOf(buildFilePath) < 0) {323 data.push(buildFilePath);324 localStorage.moduleBuilderOpenList = data.join(';');325 }326 }327328 callback(buildFilePath);329 });330 },331332 _checkValue: function (id, callback) {333 id = Dom.get(id);334 335 var value = id.value.trim();336337 if (value) {338 Dom.removeClass(id, 'x-textbox-error');339 callback(value);340 } else {341 Dom.addClass(Dom.get(id), 'x-textbox-error');342 }343 },344345 //#endregion346347 //#region 第ä¸æ¥348349 _showBuildFile: function () {350351 UI._showModuleList();352353 var buildFile = UI.currentBuildFile;354 buildFile.path = buildFile.path.replace(Demo.baseUrl, "");355356 Dom.get('step3_compress').checked = buildFile.compress;357 Dom.get('step3_addAssert').checked = buildFile.addAssert;358359 Dom.get('step3_buildfile').value = buildFile.path;360 Dom.get('step3_js').value = buildFile.js;361 Dom.get('step3_css').value = buildFile.css;362 Dom.get('step3_assets').value = buildFile.assets;363 Dom.get('step3_dependencySyntax').value = buildFile.dependencySyntax;364 Dom.get('step3_uniqueBuildFiles').value = buildFile.uniqueBuildFiles;365 Dom.get('step3_parseMacro').checked = buildFile.parseMacro;366 Dom.get('step3_defines').value = buildFile.defines;367 Dom.get('step3_prependComments').value = buildFile.prependComments;368 Dom.get('step3_prependModuleComments').value = buildFile.prependModuleComments;369370 },371372 _showModuleList: function () {373 var buildFile = UI.currentBuildFile;374 var html = '';375376 add("includes", "", "");377 add("excludes", "<del>", "</del>");378379 Dom.get('step3_modulelist').innerHTML = html;380 Dom.get('step_clearModules').style.display = html ? '' : 'none';381382 function add(includeOrExclude, prefix, postfix) {383384 for (var i = 0, all = buildFile[includeOrExclude]; i < all.length; i++) {385 html += '<div class="line" onmouseover="this.className += \' line-hover\'" onmouseout="this.className = this.className.replace(\' line-hover\', \'\');"><nav class="demo demo-toolbar"><a onclick="UI.viewSource(this, \'' + all[i] + '\');return false;" href="javascript://æ¥çå½å模å对åºçæºæ件">æºæ件</a> | <a onclick="UI.viewRequires(this, \'' + all[i] + '\');return false;" href="javascript://æ¥çå½å模åä¾èµç模å">æ¥çä¾èµ</a>';386387 if (i > 0)388 html += ' | <a href="javascript://ä¸ç§»çæçä½ç½®" onclick="UI.moveModule(\'' + includeOrExclude + '\', ' + i + ', false); return false;">ä¸ç§»</a>';389390 if (i < all.length - 1)391 html += ' | <a href="javascript://ä¸ç§»çæçä½ç½®" onclick="UI.moveModule(\'' + includeOrExclude + '\', ' + i + ', true);">ä¸ç§»</a>';392393394 html += ' | <a onclick="UI.deleteModule(\'' + includeOrExclude + '\', ' + i + '); return false;" href="javascript://å é¤æ¤è¡">å é¤</a></nav>';395 html += '<a class="link link-url" href="' + UI._getModuleExampleUrl(all[i]) + '" target="_blank">' + prefix + all[i] + postfix + '</a></div>';396 }397398 }399400 },401402 _updateBuildFile: function () {403 var buildFile = UI.currentBuildFile;404405 buildFile.compress = Dom.get('step3_compress').checked;406 buildFile.addAssert = Dom.get('step3_addAssert').checked;407408 buildFile.path = Dom.get('step3_buildfile').value;409 buildFile.js = Dom.get('step3_js').value;410 buildFile.css = Dom.get('step3_css').value;411 buildFile.assets = Dom.get('step3_assets').value;412 buildFile.dependencySyntax = Dom.get('step3_dependencySyntax').value;413 buildFile.uniqueBuildFiles = Dom.get('step3_uniqueBuildFiles').value;414 buildFile.parseMacro = Dom.get('step3_parseMacro').checked;415 buildFile.defines = Dom.get('step3_defines').value;416 buildFile.prependComments = Dom.get('step3_prependComments').value;417 buildFile.prependModuleComments = Dom.get('step3_prependModuleComments').value;418 },419420 _getModuleExampleUrl: function (module) {421 return Demo.baseUrl + Demo.Configs.examples + "/" + module.replace(/\.\w+$/, "") + ".html";422 },423424 addModule: function (showErrorMessage) {425 UI._checkValue('step3_module', function (value) {426 if (UI.currentBuildFile.includes.indexOf(value) >= 0) {427 if (confirm('模å ' + value + ' å·²å¨å表ä¸ï¼æ¯å¦éå¤æ·»å ?') === false) {428 return;429 }430 }431432 if (UI.currentBuildFile.excludes.indexOf(value) >= 0) {433 if (confirm('模å ' + value + ' 已被æé¤ï¼æ¯å¦åæ¶æé¤å¹¶æ·»å ?') === false) {434 return;435 }436437 UI.currentBuildFile.excludes.remove(value);438 }439440 UI.currentBuildFile.includes.push(value);441 UI._showModuleList();442443 Dom.get('step3_module').value = '';444 });445 },446447 removeModule: function (showErrorMessage) {448 UI._checkValue('step3_module', function (value) {449450 if (UI.currentBuildFile.includes.indexOf(value) >= 0) {451 if (confirm('模å ' + value + ' å·²å¨å表ä¸ï¼æ¯å¦æé¤?') === false) {452 return;453 }454 }455456 if (UI.currentBuildFile.excludes.indexOf(value) >= 0) {457 alert('模å ' + value + ' 已被æé¤');458 return;459 }460461 UI.currentBuildFile.excludes.push(value);462 UI._showModuleList();463464 Dom.get('step3_module').value = '';465466 });467 },468469 clearModules: function () {470 if (confirm('ç¡®å®æ¸
空å表å?')) {471 UI.currentBuildFile.includes.length = UI.currentBuildFile.excludes.length = 0;472 UI._showModuleList();473 }474 },475476 moveModule: function (includeOrExclude, id, down) {477 var oldId = down ? (id + 1) : (id - 1);478 if (oldId < 0 || oldId >= UI.currentBuildFile[includeOrExclude].length) {479 return;480 }481 var old = UI.currentBuildFile[includeOrExclude][oldId];482 UI.currentBuildFile[includeOrExclude][oldId] = UI.currentBuildFile[includeOrExclude][id];483 UI.currentBuildFile[includeOrExclude][id] = old;484485 UI._showModuleList();486 },487488 deleteModule: function (includeOrExclude, id) {489 UI.currentBuildFile[includeOrExclude].splice(id, 1);490491 UI._showModuleList();492 },493494 viewSource: function (node, module) {495 var div = node.parentNode.parentNode;496497 if (div.nextSibling && Dom.hasClass(div.nextSibling, 'source')) {498 Dom.toggle(div.nextSibling);499 return;500 }501502 if (div.nextSibling && div.nextSibling.tagName === 'UL' && div.nextSibling.nextSibling && Dom.hasClass(div.nextSibling.nextSibling, 'source')) {503 Dom.toggle(div.nextSibling.nextSibling);504 return;505 }506507 UI._getSource(module, function (data) {508 div = Dom.after(div, '<ul class="source x-bubble"></ul>');509 var html = '';510 for (var path in data) {511 html += '<li><a href="' + Demo.baseUrl + Demo.Configs.src + '/' + path + '" class="x-hint" target="_blank">' + Demo.Utils.encodeHTML(data[path]) + '</a></li>';512 }513 div.innerHTML = html || '<li>(æ æºç )</li>';514 });515 },516517 viewRequires: function (node, module) {518 var div = node.parentNode.parentNode;519520 if (div.nextSibling && Dom.hasClass(div.nextSibling, 'refs')) {521 Dom.toggle(div.nextSibling);522 return;523 }524525 if (div.nextSibling && div.nextSibling.tagName === 'UL' && div.nextSibling.nextSibling && Dom.hasClass(div.nextSibling.nextSibling, 'refs')) {526 Dom.toggle(div.nextSibling.nextSibling);527 return;528 }529530 UI._getRequires(module, function (data) {531 div = Dom.after(div, '<ul class="refs"></ul>');532 var html = '';533 for (var path in data) {534 html += '<li><div class="line" onmouseover="this.className += \' line-hover\'" onmouseout="this.className = this.className.replace(\' line-hover\', \'\');"><span class="demo demo-toolbar"><a class="demo" href="javascript://æ¥çå
³èçæºæ件" onclick="UI.viewSource(this, \'' + path + '\');return false;">æºæ件</a> | <a class="demo" href="javascript://æ¥çå½å模åä¾èµç项" onclick="UI.viewRequires(this, \'' + path + '\');return false;">æ¥çä¾èµ</a></span><a class="link" href="' + UI._getModuleExampleUrl(path) + '">' + path + '</a></div></li>';535 }536 div.innerHTML = html || '<li>(æ ä¾èµ)</li>';537 });538539 },540541 toggleMore: function () {542 var more = Dom.get('step3_advance');543544 if (Dom.isHidden(more)) {545 Dom.show(more);546 Dom.get('step3_toggleMore').innerHTML = '<span class="toggle-arrow">â¾</span> æå æ´å¤é项';547 } else {548 Dom.hide(more);549 Dom.get('step3_toggleMore').innerHTML = '<span class="toggle-arrow">â¸</span> å±å¼æ´å¤é项';550 }551 },552553 // è·åæ个ç模åæºç ã554 _getSource: function (modulePath, callback) {555 UI._updateBuildFile();556557 var file = UI.currentBuildFile;558559 var r = {};560 var type = ModuleBuilder.getModuleType(modulePath);561 if (type) {562 checkFile(modulePath, function () {563 callback(r);564 });565 } else {566 checkFile(modulePath + ".js", function () {567 checkFile(modulePath + ".css", function () {568 callback(r);569 });570 });571 }572573 function checkFile(modulePath, callback) {574 var fullPath = ModuleBuilder.getFullPath(modulePath, file.path, file.moduleBasePath);575 ModuleBuilder.loadContent(fullPath, function (error, content) {576 if (!error) {577 r[modulePath] = fullPath;578 }579580 callback();581 });582 }583584 },585586 // è·åæ个ç模åå¼ç¨é¡¹ã587 _getRequires: function (modulePath, callback) {588 UI._updateBuildFile();589590 var file = UI.currentBuildFile;591 var r = {};592 var type = ModuleBuilder.getModuleType(modulePath);593 if (type) {594 checkFile(modulePath, function () {595 callback(r);596 });597 } else {598 checkFile(modulePath + ".js", function () {599 checkFile(modulePath + ".css", function () {600 callback(r);601 });602 });603 }604605 function checkFile(modulePath, callback) {606 var fullPath = ModuleBuilder.getFullPath(modulePath, file.path, file.moduleBasePath);607 ModuleBuilder.loadContent(fullPath, function (error, content) {608 if (!error) {609 var type = ModuleBuilder.getModuleType(modulePath);610 var rq;611612 if (type == ".js") {613 rq = ModuleBuilder.resolveJsRequires(content, file).includes;614 } else if (type == ".css") {615 rq = ModuleBuilder.resolveCssRequires(content, modulePath, fullPath, {}, file).imports;616 }617618619 if (rq) {620 rq.each(function (item) {621 r[item] = modulePath;622 });623 }624625 }626627 callback();628 });629 }630631 },632633 //#endregion634635 //#region 第åæ¥636637 build: function () {638639 // 帮å©ç¨æ·ç¹å»æ·»å ã640 if (Dom.get('step3_module').value) {641 UI.addModule();642 }643644 if (!UI.currentBuildFile.includes.length) {645 alert("请å
æ·»å éè¦æå
ç模å");646 return;647 }648649 UI._updateBuildFile();650 UI._buildInternal();651652 },653654 preview: function () {655656 // 帮å©ç¨æ·ç¹å»æ·»å ã657 if (Dom.get('step3_module').value) {658 UI.addModule();659 }660661 if (!UI.currentBuildFile.includes.length) {662 alert("请å
æ·»å éè¦æå
ç模å");663 return;664 }665666 UI._updateBuildFile();667668 UI.step(4);669670 var form = Dom.get('step4_result');671 Dom.hide(Dom.get('step4_done'));672 Dom.hide(Dom.get('step4_form'));673 Dom.show(form);674675 ModuleBuilder.build({676677 file: UI.currentBuildFile,678679 log: function (info) {680 // console.info(info);681 Dom.get('step4_tip').innerHTML = Demo.Utils.encodeHTML(info);682 },683684 error: function (error) {685 Dom.get('step4_error').innerHTML += Demo.Utils.encodeHTML(error);686 },687688 complete: function (result) {689690 result.log("æ£å¨å并代ç ...");691692 Dom.show(Dom.get('step4_done'));693 694 var r = [];695 696 for(var key in result.css) {697 r.push('<link rel="stylesheet" type="text/css" href="' + Demo.baseUrl + Demo.Configs.src + '/' + result.css[key].path + '">');698 }699 700 for(var key in result.js) {701 r.push('<script type="text/javascript" src="' + Demo.baseUrl + Demo.Configs.src + '/' + result.js[key].path + '"></script>');702 }703704 UI._showResultForm('step4_js', '');705 UI._showResultForm('step4_css', '');706 UI._showResultForm('step4_assets', '');707 UI._showResultForm('step4_html', r.join('\r\n')); 708709 result.log("åæä¾èµå®æ!"); 710 711 }712713 });714715716 },717 718 save: function (){719 720 UI._updateBuildFile();721 UI.step(4);722723 if (!UI.usingXFly) {724 UI._alertOpenXFlyError();725 } else {726 UI._postNode('save');727 }728 729 },730 731 _postNode: function (action, data){732 733 var form = Dom.get('step4_form');734 Dom.hide(Dom.get('step4_result'));735 Dom.show(form);736737 form.innerHTML = '<iframe src="about:blank" frameborder="0" style="width:100%" height="200px"></iframe>';738739 form = form.firstChild;740741 var doc = form.contentDocument;742743 doc.open();744 doc.write('<form id="form" method="post" action="' + Demo.Configs.serverBaseUrl + Demo.Configs.apps + '/node/modulebuilder/server/api.njs?action=' + action + '" style="visibility:hidden;"><textarea id="data" name="data"></textarea></form>');745 doc.close();746747 doc.getElementById('data').value = JSON.stringify(UI.currentBuildFile);748 doc.getElementById('form').submit();749 750 },751752 // å¼å§æå
ã753 _buildInternal: function () {754 755 UI.step(4);756757 var needXFly = UI.currentBuildFile.js || UI.currentBuildFile.css || UI.currentBuildFile.assets || UI.currentBuildFile.path;758759 if (needXFly && !UI.usingXFly) {760 UI._alertOpenXFlyError();761 needXFly = false;762 }763764 // åºäºæå¡å¨çæã765 if (needXFly) {766 UI._postNode('build');767 } else {768769 var form = Dom.get('step4_result');770 Dom.hide(Dom.get('step4_done'));771 Dom.hide(Dom.get('step4_form'));772 Dom.show(form);773774 ModuleBuilder.build({775776 file: UI.currentBuildFile,777778 log: function (info) {779 // console.info(info);780 Dom.get('step4_tip').innerHTML = Demo.Utils.encodeHTML(info);781 },782783 error: function (error) {784 Dom.get('step4_error').innerHTML += Demo.Utils.encodeHTML(error);785 },786787 complete: function (result) {788789 result.log("æ£å¨å并代ç ...");790 UI._showResultForm('step4_html', '');791792 setTimeout(function () {793794 Dom.show(Dom.get('step4_done'));795796 var jsStream = new StringStream();797 var cssStream = new StringStream();798799 ModuleBuilder.writeJs(result, jsStream);800801 setTimeout(function () {802 jsStream.end();803 UI._showResultForm('step4_js', jsStream.toString());804805 ModuleBuilder.writeCss(result, cssStream);806 cssStream.end();807 UI._showResultForm('step4_css', cssStream.toString());808809 setTimeout(function () {810 var assets = [];811812 for (var images in result.assets) {813 assets.push(result.assets[images].relative);814 }815816 UI._showResultForm('step4_assets', assets.join('\r\n'));817818 result.log("æå
æå !");819820 }, 0);821822 }, 0);823824 }, 0);825826 }827828 });829830 }831832 },833834 _showResultForm: function (id, value) {835 Dom.get(id).value = value;836 Dom.get(id).style.display = Dom.prev(Dom.get(id)).style.display = value ? '' : 'none';837 }838839 //#endregion840841};842
...
register-file-types-test.mjs
Source:register-file-types-test.mjs
...26 });27 it('should use cache', () => {28 registerFallback(F);29 const i0 = getEntityId();30 const f0 = buildFile('/etc/config');31 const f1 = buildFile('/etc/config');32 expect(f1.id).toBe(f0.id);33 expect(f0.i_parent.initial.id).toBe(f1.i_parent.initial.id);34 const i1 = getEntityId() - 1;35 expect(i1 - i0).toBe(2);36 });37 it('should register and find it back', async () => {38 registerFileRegExp(glob2regExp('test.a'), A);39 expect(buildFile('test.a')).toEqual(jasmine.any(A));40 });41 it('should register an array and find it back', async () => {42 registerFileRegExp([43 glob2regExp('test.a'),44 glob2regExp('test.b')45 ], A);46 expect(buildFile('test.a')).toEqual(jasmine.any(A));47 expect(buildFile('test.b')).toEqual(jasmine.any(A));48 expect(buildFile('TEST.A')).toEqual(jasmine.any(A));49 });50 // it('should handle fallback and find it back', async () => {51 // registerFileRegExp(glob2regExp('test.a'), A);52 // registerFileRegExp(FallBackRegExp, B);53 // expect(buildFile('test.a')).toEqual(jasmine.any(A));54 // expect(buildFile('test.b')).toEqual(jasmine.any(B));55 // });56 it('should handle globs', async () => {57 registerFileRegExp(glob2regExp('a.*'), A);58 registerFileRegExp(glob2regExp('b.*'), B);59 expect(buildFile('a.test')).toEqual(jasmine.any(A));60 expect(buildFile('b.test')).toEqual(jasmine.any(B));61 });62 it('should handle . as a litteral', async () => {63 registerFileRegExp(glob2regExp('a.test'), A);64 registerFileRegExp(glob2regExp('a_test'), B);65 expect(buildFile('a.test')).toEqual(jasmine.any(A));66 expect(buildFile('a_test')).toEqual(jasmine.any(B));67 });68 it('should handle globs by size', async () => {69 registerFileRegExp(glob2regExp('test.*'), A);70 registerFileRegExp(glob2regExp('test.truc.*'), B);71 expect(buildFile('test.truc.bac')).toEqual(jasmine.any(B));72 expect(buildFile('test.somethingelse')).toEqual(jasmine.any(A));73 });...
build.js
Source:build.js
1234var buildFilePath = process.argv[2];56if (buildFilePath) {7 var ModuleBuilder = require('../assets/modulebuilder.js');8 var Demo = require('../../../demo/demo.js');9 ModuleBuilder.moduleBasePath = Demo.basePath + Demo.Configs.src;10 ModuleBuilder.load(buildFilePath, function (buildFile) {11 if (buildFile.js) {12 buildFile.js = ModuleBuilder.parseRelativePath(buildFilePath, buildFile.js);13 }14 if (buildFile.css) {15 buildFile.css = ModuleBuilder.parseRelativePath(buildFilePath, buildFile.css);16 }17 if (buildFile.assets) {18 buildFile.assets = ModuleBuilder.parseRelativePath(buildFilePath, buildFile.assets);19 }2021 ModuleBuilder.build({22 file: buildFile,23 complete: function (result) {24 var IO = require('utilskit/io');25 try {26 27 if (result.file.js && !isEmpty(result.js)) {28 var stream = IO.openWrite(result.file.js, {29 flags: 'w',30 encoding: Demo.Configs.encoding31 });32 ModuleBuilder.writeJs(result, stream);33 stream.end();34 result.log("çæ js æä»¶ï¼ " + result.file.js + "");35 }36 if (result.file.css && !isEmpty(result.css)) {37 var stream = IO.openWrite(result.file.css, {38 flags: 'w',39 encoding: Demo.Configs.encoding40 });41 ModuleBuilder.writeCss(result, stream);42 stream.end();43 result.log("çæ css æä»¶ï¼ " + result.file.css + "");44 }45 if (result.file.assets && !isEmpty(result.assets)) {46 result.log("æ£å¨å¤å¶èµæº...");47 for (var key in result.assets) {48 IO.copyFile(result.assets[key].from, result.assets[key].to);49 }50 result.log("çæå¾çæä»¶å¤¹ï¼ " + result.file.assets + "");51 }52 result.log("çæå®æ!");53 } catch (e) {54 result.error(e.message);55 }56 }5758 });5960 });6162} else {63 console.log("ç¨æ³: build path/to/buildfile.js");64}65function isEmpty(obj) {66 for (var key in obj) {67 return false;68 }69 return true;
...
coder.js
Source:coder.js
1// This must be ran from VS Code's root.2const gulp = require("gulp");3const path = require("path");4const _ = require("underscore");5const buildfile = require("./src/buildfile");6const common = require("./build/lib/optimize");7const util = require("./build/lib/util");8const vscodeEntryPoints = _.flatten([9 buildfile.entrypoint("vs/workbench/workbench.web.api"),10 buildfile.entrypoint("vs/server/entry"),11 buildfile.base,12 buildfile.workbenchWeb,13 buildfile.workerExtensionHost,14 buildfile.workerNotebook,15 buildfile.keyboardMaps,16 // See ./src/vs/workbench/buildfile.desktop.js17 buildfile.entrypoint("vs/platform/files/node/watcher/unix/watcherApp"),18 buildfile.entrypoint("vs/platform/files/node/watcher/nsfw/watcherApp"),19 buildfile.entrypoint('vs/platform/terminal/node/ptyHostMain'),20 buildfile.entrypoint("vs/workbench/services/extensions/node/extensionHostProcess"),21]);22// See ./build/gulpfile.vscode.js23const vscodeResources = [24 "out-build/vs/server/fork.js",25 "!out-build/vs/server/doc/**",26 "out-build/vs/workbench/services/extensions/worker/extensionHostWorkerMain.js",27 "out-build/bootstrap.js",28 "out-build/bootstrap-fork.js",29 "out-build/bootstrap-amd.js",30 'out-build/bootstrap-node.js',31 'out-build/vs/**/*.{svg,png,html,ttf,jpg}',32 "!out-build/vs/code/browser/workbench/*.html",33 '!out-build/vs/code/electron-browser/**',34 "out-build/vs/base/common/performance.js",35 "out-build/vs/base/node/languagePacks.js",36 'out-build/vs/base/browser/ui/codicons/codicon/**',37 'out-build/vs/base/node/userDataPath.js',38 "out-build/vs/workbench/browser/media/*-theme.css",39 "out-build/vs/workbench/contrib/debug/**/*.json",40 "out-build/vs/workbench/contrib/externalTerminal/**/*.scpt",41 "out-build/vs/workbench/contrib/webview/browser/pre/*.js",42 "out-build/vs/**/markdown.css",43 "out-build/vs/workbench/contrib/tasks/**/*.json",44 "out-build/vs/platform/files/**/*.md",45 "!**/test/**"46];47gulp.task("optimize", gulp.series(48 util.rimraf("out-vscode"),49 common.optimizeTask({50 src: "out-build",51 entryPoints: vscodeEntryPoints,52 resources: vscodeResources,53 loaderConfig: common.loaderConfig(),54 out: "out-vscode",55 inlineAmdImages: true,56 bundleInfo: undefined57 }),58));59gulp.task("minify", gulp.series(60 util.rimraf("out-vscode-min"),61 common.minifyTask("out-vscode")...
gulp-github1s.js
Source:gulp-github1s.js
1// This must be ran from VS Code's root.2const gulp = require('gulp');3const _ = require('underscore');4const buildfile = require('./src/buildfile');5const common = require('./build/lib/optimize');6const util = require('./build/lib/util');7const vscodeEntryPoints = _.flatten([8 buildfile.entrypoint('vs/workbench/workbench.web.api'),9 buildfile.base,10 buildfile.workbenchWeb,11 buildfile.workerExtensionHost,12 buildfile.workerNotebook,13 buildfile.keyboardMaps,14 buildfile.entrypoint('vs/platform/files/node/watcher/unix/watcherApp'),15 buildfile.entrypoint('vs/platform/files/node/watcher/nsfw/watcherApp'),16 buildfile.entrypoint(17 'vs/workbench/services/extensions/node/extensionHostProcess'18 ),19]);20const vscodeResources = [21 '!out-build/vs/server/doc/**',22 'out-build/vs/workbench/services/extensions/worker/extensionHostWorkerMain.js',23 'out-build/bootstrap.js',24 'out-build/bootstrap-fork.js',25 'out-build/bootstrap-amd.js',26 'out-build/bootstrap-node.js',27 'out-build/paths.js',28 'out-build/vs/**/*.{svg,png,html,ttf}',29 '!out-build/vs/code/browser/workbench/*.html',30 '!out-build/vs/code/electron-browser/**',31 'out-build/vs/base/common/performance.js',32 'out-build/vs/base/node/languagePacks.js',33 'out-build/vs/base/browser/ui/codicons/codicon/**',34 'out-build/vs/workbench/browser/media/*-theme.css',35 'out-build/vs/workbench/contrib/debug/**/*.json',36 'out-build/vs/workbench/contrib/externalTerminal/**/*.scpt',37 'out-build/vs/workbench/contrib/webview/browser/pre/*.js',38 'out-build/vs/**/markdown.css',39 'out-build/vs/workbench/contrib/tasks/**/*.json',40 'out-build/vs/platform/files/**/*.md',41 '!**/test/**',42];43gulp.task(44 'optimize',45 gulp.series(46 util.rimraf('out-vscode'),47 common.optimizeTask({48 src: 'out-build',49 entryPoints: vscodeEntryPoints,50 resources: vscodeResources,51 loaderConfig: common.loaderConfig(),52 out: 'out-vscode',53 inlineAmdImages: true,54 bundleInfo: undefined,55 })56 )57);58gulp.task(59 'minify',60 gulp.series(util.rimraf('out-vscode-min'), common.minifyTask('out-vscode'))...
gulp-githubsurf.js
Source:gulp-githubsurf.js
1// This must be ran from VS Code's root.2const gulp = require("gulp");3const _ = require("underscore");4const buildfile = require("./src/buildfile");5const common = require("./build/lib/optimize");6const util = require("./build/lib/util");7const vscodeEntryPoints = _.flatten([8 buildfile.entrypoint("vs/workbench/workbench.web.api"),9 buildfile.base,10 buildfile.workbenchWeb,11 buildfile.workerExtensionHost,12 buildfile.workerNotebook,13 buildfile.keyboardMaps,14 buildfile.entrypoint("vs/platform/files/node/watcher/unix/watcherApp"),15 buildfile.entrypoint("vs/platform/files/node/watcher/nsfw/watcherApp"),16 buildfile.entrypoint("vs/workbench/services/extensions/node/extensionHostProcess"),17]);18const vscodeResources = [19 "!out-build/vs/server/doc/**",20 "out-build/vs/workbench/services/extensions/worker/extensionHostWorkerMain.js",21 "out-build/bootstrap.js",22 "out-build/bootstrap-fork.js",23 "out-build/bootstrap-amd.js",24 'out-build/bootstrap-node.js',25 "out-build/paths.js",26 'out-build/vs/**/*.{svg,png,html,ttf}',27 "!out-build/vs/code/browser/workbench/*.html",28 '!out-build/vs/code/electron-browser/**',29 "out-build/vs/base/common/performance.js",30 "out-build/vs/base/node/languagePacks.js",31 'out-build/vs/base/browser/ui/codicons/codicon/**',32 "out-build/vs/workbench/browser/media/*-theme.css",33 "out-build/vs/workbench/contrib/debug/**/*.json",34 "out-build/vs/workbench/contrib/externalTerminal/**/*.scpt",35 "out-build/vs/workbench/contrib/webview/browser/pre/*.js",36 "out-build/vs/**/markdown.css",37 "out-build/vs/workbench/contrib/tasks/**/*.json",38 "out-build/vs/platform/files/**/*.md",39 "!**/test/**"40];41gulp.task("optimize", gulp.series(42 util.rimraf("out-vscode"),43 common.optimizeTask({44 src: "out-build",45 entryPoints: vscodeEntryPoints,46 resources: vscodeResources,47 loaderConfig: common.loaderConfig(),48 out: "out-vscode",49 inlineAmdImages: true,50 bundleInfo: undefined51 }),52));53gulp.task("minify", gulp.series(54 util.rimraf("out-vscode-min"),55 common.minifyTask("out-vscode")...
gulp-gogs1s.js
Source:gulp-gogs1s.js
1// This must be ran from VS Code's root.2const gulp = require("gulp");3const _ = require("underscore");4const buildfile = require("./src/buildfile");5const common = require("./build/lib/optimize");6const util = require("./build/lib/util");7const vscodeEntryPoints = _.flatten([8 buildfile.entrypoint("vs/workbench/workbench.web.api"),9 buildfile.base,10 buildfile.workbenchWeb,11 buildfile.workerExtensionHost,12 buildfile.workerNotebook,13 buildfile.keyboardMaps,14 buildfile.entrypoint("vs/platform/files/node/watcher/unix/watcherApp"),15 buildfile.entrypoint("vs/platform/files/node/watcher/nsfw/watcherApp"),16 buildfile.entrypoint("vs/workbench/services/extensions/node/extensionHostProcess"),17]);18const vscodeResources = [19 "!out-build/vs/server/doc/**",20 "out-build/vs/workbench/services/extensions/worker/extensionHostWorkerMain.js",21 "out-build/bootstrap.js",22 "out-build/bootstrap-fork.js",23 "out-build/bootstrap-amd.js",24 'out-build/bootstrap-node.js',25 "out-build/paths.js",26 'out-build/vs/**/*.{svg,png,html,ttf}',27 "!out-build/vs/code/browser/workbench/*.html",28 '!out-build/vs/code/electron-browser/**',29 "out-build/vs/base/common/performance.js",30 "out-build/vs/base/node/languagePacks.js",31 'out-build/vs/base/browser/ui/codicons/codicon/**',32 "out-build/vs/workbench/browser/media/*-theme.css",33 "out-build/vs/workbench/contrib/debug/**/*.json",34 "out-build/vs/workbench/contrib/externalTerminal/**/*.scpt",35 "out-build/vs/workbench/contrib/webview/browser/pre/*.js",36 "out-build/vs/**/markdown.css",37 "out-build/vs/workbench/contrib/tasks/**/*.json",38 "out-build/vs/platform/files/**/*.md",39 "!**/test/**"40];41gulp.task("optimize", gulp.series(42 util.rimraf("out-vscode"),43 common.optimizeTask({44 src: "out-build",45 entryPoints: vscodeEntryPoints,46 resources: vscodeResources,47 loaderConfig: common.loaderConfig(),48 out: "out-vscode",49 inlineAmdImages: true,50 bundleInfo: undefined51 }),52));53gulp.task("minify", gulp.series(54 util.rimraf("out-vscode-min"),55 common.minifyTask("out-vscode")...
cli.js
Source:cli.js
1#!/usr/bin/env node2/**3 * @app build4 * @app:npm @archivist/build5 * @app:git https://github.com/Archivist-Nerd/node-build6 * @app:Licence MIT7 * @app:Copyright Copyright (c) 2020 Archivist-Nerd8 *9 * @app:Example:10 * build [buildFile]11 *12 * @app:Example:13 * build ./src/.build14 */15'use strict';1617const pkg = require('./package.json') // package.json Contents18 , bargs = require("@archivistnerd/bargs") // Command Line Arguments19 , app = require('../.') // actual app code20 ;21process.on('uncaughtException', err => console.error('uncaughtException', err))22process.on('unhandledRejection', err => console.error('unhandledRejection', err))23bargs24 .scriptName( `${ pkg.name } \t ${ 'v'+pkg.version } \t ${ pkg.description }` )25 .usage(`build [buildfile]`)2627 .command('$ [buildfile]', 'use buildfile',28 (argv) => {29 if ( argv.buildFile == undefined ) return bargs.displayHelp()30 if (!app.build( argv.buildFile )) console.log(` error: file "${argv.buildFile}" does not exist`)31 }32 ,[33 { name: 'buildFile', type: 'string', describe: 'build filename' },34 ])3536 .help()
...
LambdaTest’s Jest Testing Tutorial covers step-by-step guides around Jest with code examples to help you be proficient with the Jest framework. The Jest tutorial has chapters to help you learn right from the basics of Jest framework to code-based tutorials around testing react apps with Jest, perform snapshot testing, import ES modules and more.
|<p>it('check_object_of_Car', () => {</p><p>
expect(newCar()).toBeInstanceOf(Car);</p><p>
});</p>|
| :- |
Get 100 minutes of automation test minutes FREE!!