From 58d2a2460bde6eebea4cfc17257befa2941fa59e Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Mon, 21 Jun 2021 11:08:05 +0300 Subject: [PATCH] lib building --- Gruntfile.js | 151 ++++++++++++++++++------------------ client/lib/selectize.min.js | 3 - frontend/bundle-config.json | 43 ++++++++++ frontend/libs.json | 22 ++++++ 4 files changed, 139 insertions(+), 80 deletions(-) delete mode 100644 client/lib/selectize.min.js create mode 100644 frontend/bundle-config.json create mode 100644 frontend/libs.json diff --git a/Gruntfile.js b/Gruntfile.js index fbe4aa4c49..071ee7f75e 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -34,75 +34,11 @@ const path = require('path'); module.exports = grunt => { - let jsFilesToMinify = [ - 'node_modules/jquery/dist/jquery.js', - 'node_modules/underscore/underscore.js', - 'node_modules/es6-promise/dist/es6-promise.js', - 'node_modules/backbone/backbone.js', - 'node_modules/handlebars/dist/handlebars.js', - 'node_modules/bullbone/dist/bullbone.js', - 'node_modules/base-64/base64.js', - 'node_modules/moment/moment.js', - 'node_modules/moment-timezone/moment-timezone.js', - 'node_modules/timepicker/jquery.timepicker.js', - "node_modules/devbridge-autocomplete/dist/jquery.autocomplete.js", - "node_modules/jquery-textcomplete/dist/jquery.textcomplete.js", - 'node_modules/bootstrap/dist/js/bootstrap.js', - 'node_modules/bootstrap-datepicker/dist/js/bootstrap-datepicker.js', - 'node_modules/marked/lib/marked.js', - 'node_modules/gridstack/dist/gridstack.js', - 'node_modules/gridstack/dist/gridstack.jQueryUI.js', - - 'client/lib/jquery-ui.min.js', - 'client/lib/jquery.ui.touch-punch.min.js', - 'client/lib/moment-timezone-data.js', - 'client/lib/autobahn.js', - - 'client/src/namespace.js', - 'client/src/exceptions.js', - 'client/src/loader.js', - 'client/src/utils.js', - - 'client/src/acl.js', - 'client/src/model.js', - 'client/src/model-offline.js', - 'client/src/ajax.js', - 'client/src/controller.js', - - 'client/src/ui.js', - 'client/src/acl-manager.js', - 'client/src/cache.js', - 'client/src/storage.js', - 'client/src/models/settings.js', - 'client/src/language.js', - 'client/src/metadata.js', - 'client/src/field-manager.js', - 'client/src/models/user.js', - 'client/src/models/preferences.js', - 'client/src/model-factory.js', - 'client/src/collection-factory.js', - 'client/src/pre-loader.js', - 'client/src/controllers/base.js', - 'client/src/router.js', - 'client/src/date-time.js', - 'client/src/layout-manager.js', - 'client/src/theme-manager.js', - 'client/src/session-storage.js', - 'client/src/view-helper.js', - 'client/src/page-title.js', - - 'client/src/app.js' - ]; - - function camelCaseToHyphen (string){ - if (string === null) { - return string; - } - - return string.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase(); - } - const pkg = grunt.file.readJSON('package.json'); + const bundleConfig = require('./frontend/bundle-config.json'); + + let jsFilesToBundle = getBundleLibList().concat(bundleConfig.jsFiles); + let jsFilesToCopy = getCopyLibList(); let currentPath = path.dirname(fs.realpathSync(__filename)); @@ -137,8 +73,6 @@ module.exports = grunt => { lessData[theme] = o; }); - - grunt.initConfig({ pkg: pkg, @@ -171,8 +105,8 @@ module.exports = grunt => { cssmin: { themes: { - files: cssminFilesData - } + files: cssminFilesData, + }, }, uglify: { @@ -181,9 +115,7 @@ module.exports = grunt => { sourceMap: true, banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n', }, - 'build/tmp/client/espo.min.js': jsFilesToMinify.map(item => { - return '' + item; - }), + 'build/tmp/client/espo.min.js': jsFilesToBundle, }, copy: { options: { @@ -206,6 +138,12 @@ module.exports = grunt => { dest: 'build/tmp/client', }, frontendLib: { + expand: true, + flatten: true, + src: jsFilesToCopy, + dest: 'build/tmp/client/lib/', + }, + frontendCommitedLib: { expand: true, dot: true, cwd: 'client/lib', @@ -303,14 +241,14 @@ module.exports = grunt => { patterns: [ { match: 'version', - replacement: '<%= pkg.version %>' + replacement: '<%= pkg.version %>', } ] }, files: [ { src: 'build/tmp/application/Espo/Resources/defaults/config.php', - dest: 'build/tmp/application/Espo/Resources/defaults/config.php' + dest: 'build/tmp/application/Espo/Resources/defaults/config.php', } ], } @@ -401,6 +339,7 @@ module.exports = grunt => { 'uglify', 'copy:frontendFolders', 'copy:frontendLib', + 'copy:frontendCommitedLib', 'copy:backend', 'replace', 'clean:beforeFinal', @@ -451,3 +390,61 @@ module.exports = grunt => { 'offline', ]); }; + +function getBundleLibList() { + const libs = require('./frontend/libs.json'); + + let list = []; + + libs.forEach(item => { + if (typeof item === 'string') { + list.push(item); + + return; + } + + if (!item.bundle) { + return; + } + + if (!item.path) { + throw new Error("No lib path."); + } + + list.push(item.path); + }); + + return list.map(item => 'node_modules/' + item); +} + +function getCopyLibList() { + const libs = require('./frontend/libs.json'); + + let list = []; + + libs.forEach(item => { + if (typeof item === 'string') { + return; + } + + if (item.bundle) { + return; + } + + if (!item.path) { + throw new Error("No lib path."); + } + + list.push(item.path); + }); + + return list.map(item => 'node_modules/' + item); +} + +function camelCaseToHyphen (string){ + if (string === null) { + return string; + } + + return string.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase(); +} diff --git a/client/lib/selectize.min.js b/client/lib/selectize.min.js deleted file mode 100644 index 1bad526d2a..0000000000 --- a/client/lib/selectize.min.js +++ /dev/null @@ -1,3 +0,0 @@ -/*! selectize.js - v0.13.3 | https://github.com/selectize/selectize.js | Apache License (v2) */ - -!function(root,factory){"function"==typeof define&&define.amd?define("sifter",factory):"object"==typeof exports?module.exports=factory():root.Sifter=factory()}(this,function(){function Sifter(items,settings){this.items=items,this.settings=settings||{diacritics:!0}}Sifter.prototype.tokenize=function(query){if(!(query=trim(String(query||"").toLowerCase()))||!query.length)return[];for(var regex,letter,tokens=[],words=query.split(/ +/),i=0,n=words.length;i/g,">").replace(/"/g,""")}function debounce_events(self,types,fn){var type,trigger=self.trigger,event_args={};for(type in self.trigger=function(){var type=arguments[0];if(-1===types.indexOf(type))return trigger.apply(self,arguments);event_args[type]=arguments},fn.apply(self,[]),self.trigger=trigger,event_args)event_args.hasOwnProperty(type)&&trigger.apply(self,event_args[type])}function getSelection(input){var sel,selLen,result={};return void 0===input?console.warn("WARN getSelection cannot locate input control"):"selectionStart"in input?(result.start=input.selectionStart,result.length=input.selectionEnd-result.start):document.selection&&(input.focus(),sel=document.selection.createRange(),selLen=document.selection.createRange().text.length,sel.moveStart("character",-input.value.length),result.start=sel.text.length-selLen,result.length=selLen),result}function measureString(str,$parent){return str?(Selectize.$testInput||(Selectize.$testInput=$("").css({position:"absolute",width:"auto",padding:0,whiteSpace:"pre"}),$("
").css({position:"absolute",width:0,height:0,overflow:"hidden"}).append(Selectize.$testInput).appendTo("body")),Selectize.$testInput.text(str),function($from,$to,properties){var i,n,styles={};if(properties)for(i=0,n=properties.length;i").addClass(settings.wrapperClass).addClass(classes).addClass(event),$control=$("
").addClass(settings.inputClass).addClass("items").appendTo($wrapper),$control_input=$('').appendTo($control).attr("tabindex",$input.is(":disabled")?"-1":self.tabIndex),inputId=$(settings.dropdownParent||$wrapper),selector=$("
").addClass(settings.dropdownClass).addClass(event).hide().appendTo(inputId),event=$("
").addClass(settings.dropdownContentClass).attr("tabindex","-1").appendTo(selector);(inputId=$input.attr("id"))&&($control_input.attr("id",inputId+"-selectized"),$("label[for='"+inputId+"']").attr("for",inputId+"-selectized")),self.settings.copyClassesToDropdown&&selector.addClass(classes),$wrapper.css({width:$input[0].style.width}),self.plugins.names.length&&(delimiterEscaped="plugin-"+self.plugins.names.join(" plugin-"),$wrapper.addClass(delimiterEscaped),selector.addClass(delimiterEscaped)),(null===settings.maxItems||1[data-selectable]",function(e){e.stopImmediatePropagation()}),selector.on("mouseenter","[data-selectable]",function(){return self.onOptionHover.apply(self,arguments)}),selector.on("mousedown click","[data-selectable]",function(){return self.onOptionSelect.apply(self,arguments)}),event="mousedown",selector="*:not(input)",fn=function(){return self.onItemSelect.apply(self,arguments)},($parent=$control).on(event,selector,function(e){for(var child=e.target;child&&child.parentNode!==$parent[0];)child=child.parentNode;return e.currentTarget=child,fn.apply(this,[e])}),autoGrow($control_input),$control.on({mousedown:function(){return self.onMouseDown.apply(self,arguments)},click:function(){return self.onClick.apply(self,arguments)}}),$control_input.on({mousedown:function(e){e.stopPropagation()},keydown:function(){return self.onKeyDown.apply(self,arguments)},keyup:function(){return self.onKeyUp.apply(self,arguments)},keypress:function(){return self.onKeyPress.apply(self,arguments)},resize:function(){self.positionDropdown.apply(self,[])},blur:function(){return self.onBlur.apply(self,arguments)},focus:function(){return self.ignoreBlur=!1,self.onFocus.apply(self,arguments)},paste:function(){return self.onPaste.apply(self,arguments)}}),$document.on("keydown"+eventNS,function(e){self.isCmdDown=e[IS_MAC?"metaKey":"ctrlKey"],self.isCtrlDown=e[IS_MAC?"altKey":"ctrlKey"],self.isShiftDown=e.shiftKey}),$document.on("keyup"+eventNS,function(e){e.keyCode===KEY_CTRL&&(self.isCtrlDown=!1),16===e.keyCode&&(self.isShiftDown=!1),e.keyCode===KEY_CMD&&(self.isCmdDown=!1)}),$document.on("mousedown"+eventNS,function(e){if(self.isFocused){if(e.target===self.$dropdown[0]||e.target.parentNode===self.$dropdown[0])return!1;self.$control.has(e.target).length||e.target===self.$control[0]||self.blur(e.target)}}),$window.on(["scroll"+eventNS,"resize"+eventNS].join(" "),function(){self.isOpen&&self.positionDropdown.apply(self,arguments)}),$window.on("mousemove"+eventNS,function(){self.ignoreHover=!1}),this.revertSettings={$children:$input.children().detach(),tabindex:$input.attr("tabindex")},$input.attr("tabindex",-1).hide().after(self.$wrapper),$.isArray(settings.items)&&(self.lastValidValue=settings.items,self.setValue(settings.items),delete settings.items),SUPPORTS_VALIDITY_API&&$input.on("invalid"+eventNS,function(e){e.preventDefault(),self.isInvalid=!0,self.refreshState()}),self.updateOriginalInput(),self.refreshItems(),self.refreshState(),self.updatePlaceholder(),self.isSetup=!0,$input.is(":disabled")&&self.disable(),self.on("change",this.onChange),$input.data("selectize",self),$input.addClass("selectized"),self.trigger("initialize"),!0===settings.preload&&self.onSearchChange("")},setupTemplates:function(){var field_label=this.settings.labelField,field_optgroup=this.settings.optgroupLabelField,templates={optgroup:function(data){return'
'+data.html+"
"},optgroup_header:function(data,escape){return'
'+escape(data[field_optgroup])+"
"},option:function(data,escape){return'
'+escape(data[field_label])+"
"},item:function(data,escape){return'
'+escape(data[field_label])+"
"},option_create:function(data,escape){return'
Add '+escape(data.input)+"
"}};this.settings.render=$.extend({},templates,this.settings.render)},setupCallbacks:function(){var key,fn,callbacks={initialize:"onInitialize",change:"onChange",item_add:"onItemAdd",item_remove:"onItemRemove",clear:"onClear",option_add:"onOptionAdd",option_remove:"onOptionRemove",option_clear:"onOptionClear",optgroup_add:"onOptionGroupAdd",optgroup_remove:"onOptionGroupRemove",optgroup_clear:"onOptionGroupClear",dropdown_open:"onDropdownOpen",dropdown_close:"onDropdownClose",type:"onType",load:"onLoad",focus:"onFocus",blur:"onBlur",dropdown_item_activate:"onDropdownItemActivate",dropdown_item_deactivate:"onDropdownItemDeactivate"};for(key in callbacks)callbacks.hasOwnProperty(key)&&(fn=this.settings[callbacks[key]])&&this.on(key,fn)},onClick:function(e){this.isFocused&&this.isOpen||(this.focus(),e.preventDefault())},onMouseDown:function(e){var self=this,defaultPrevented=e.isDefaultPrevented();$(e.target);if(self.isFocused){if(e.target!==self.$control_input[0])return"single"===self.settings.mode?self.isOpen?self.close():self.open():defaultPrevented||self.setActiveItem(null),!1}else defaultPrevented||window.setTimeout(function(){self.focus()},0)},onChange:function(){""!==this.getValue()&&(this.lastValidValue=this.getValue()),this.$input.trigger("input"),this.$input.trigger("change")},onPaste:function(e){var self=this;self.isFull()||self.isInputHidden||self.isLocked?e.preventDefault():self.settings.splitOn&&setTimeout(function(){var pastedText=self.$control_input.val();if(pastedText.match(self.settings.splitOn))for(var splitInput=$.trim(pastedText).split(self.settings.splitOn),i=0,n=splitInput.length;i=this.settings.maxItems},updateOriginalInput:function(opts){var i,n,options,label;if(opts=opts||{},1===this.tagType){for(options=[],i=0,n=this.items.length;i'+escape_html(label)+"");options.length||this.$input.attr("multiple")||options.push(''),this.$input.html(options.join(""))}else this.$input.val(this.getValue()),this.$input.attr("value",this.$input.val());this.isSetup&&(opts.silent||this.trigger("change",this.$input.val()))},updatePlaceholder:function(){var $input;this.settings.placeholder&&($input=this.$control_input,this.items.length?$input.removeAttr("placeholder"):$input.attr("placeholder",this.settings.placeholder),$input.triggerHandler("update",{force:!0}))},open:function(){this.isLocked||this.isOpen||"multi"===this.settings.mode&&this.isFull()||(this.focus(),this.isOpen=!0,this.refreshState(),this.$dropdown.css({visibility:"hidden",display:"block"}),this.positionDropdown(),this.$dropdown.css({visibility:"visible"}),this.trigger("dropdown_open",this.$dropdown))},close:function(){var trigger=this.isOpen;"single"===this.settings.mode&&this.items.length&&(this.hideInput(),this.isBlurring&&this.$control_input.blur()),this.isOpen=!1,this.$dropdown.hide(),this.setActiveOption(null),this.refreshState(),trigger&&this.trigger("dropdown_close",this.$dropdown)},positionDropdown:function(){var $control=this.$control,offset="body"===this.settings.dropdownParent?$control.offset():$control.position();offset.top+=$control.outerHeight(!0),this.$dropdown.css({width:$control[0].getBoundingClientRect().width,top:offset.top,left:offset.left})},clear:function(silent){this.items.length&&(this.$control.children(":not(input)").remove(),this.items=[],this.lastQuery=null,this.setCaret(0),this.setActiveItem(null),this.updatePlaceholder(),this.updateOriginalInput({silent:silent}),this.refreshState(),this.showInput(),this.trigger("clear"))},insertAtCaret:function(target){var caret=Math.min(this.caretPos,this.items.length),el=target[0],target=this.buffer||this.$control[0];0===caret?target.insertBefore(el,target.firstChild):target.insertBefore(el,target.childNodes[caret]),this.setCaret(caret+1)},deleteSelection:function(e){var i,n,values,option_select,$option_select,caret,direction=e&&8===e.keyCode?-1:1,selection=getSelection(this.$control_input[0]);if(this.$activeOption&&!this.settings.hideSelected&&(option_select=this.getAdjacentOption(this.$activeOption,-1).attr("data-value")),values=[],this.$activeItems.length){for(caret=this.$control.children(".active:"+(0
'+data.title+'×
'}},options),self.setup=(original=self.setup,function(){original.apply(self,arguments),self.$dropdown_header=$(options.html(options)),self.$dropdown.prepend(self.$dropdown_header)})}),Selectize.define("optgroup_columns",function(options){var original,self=this;options=$.extend({equalizeWidth:!0,equalizeHeight:!0},options),this.getAdjacentOption=function($option,index){var $options=$option.closest("[data-group]").find("[data-selectable]"),index=$options.index($option)+index;return 0<=index&&index<$options.length?$options.eq(index):$()},this.onKeyDown=(original=self.onKeyDown,function(e){var $option,$options;return!this.isOpen||37!==e.keyCode&&39!==e.keyCode?original.apply(this,arguments):(self.ignoreHover=!0,$option=($options=this.$activeOption.closest("[data-group]")).find("[data-selectable]").index(this.$activeOption),void(($option=($options=($options=37===e.keyCode?$options.prev("[data-group]"):$options.next("[data-group]")).find("[data-selectable]")).eq(Math.min($options.length-1,$option))).length&&this.setActiveOption($option)))});function equalizeSizes(){var i,height_max,width_last,width_parent,$optgroups=$("[data-group]",self.$dropdown_content),n=$optgroups.length;if(n&&self.$dropdown_content.width()){if(options.equalizeHeight){for(i=height_max=0;i
',div=div.firstChild,doc.body.appendChild(div),width=getScrollbarWidth.width=div.offsetWidth-div.clientWidth,doc.body.removeChild(div)),width};(options.equalizeHeight||options.equalizeWidth)&&(hook.after(this,"positionDropdown",equalizeSizes),hook.after(this,"refreshOptions",equalizeSizes))}),Selectize.define("remove_button",function(options){options=$.extend({label:"×",title:"Remove",className:"remove",append:!0},options);("single"===this.settings.mode?function(thisRef,options){options.className="remove-single";var original,self=thisRef,html=''+options.label+"";thisRef.setup=(original=self.setup,function(){var id,render_item;options.append&&(id=$(self.$input.context).attr("id"),$("#"+id),render_item=self.settings.render.item,self.settings.render.item=function(data){return html_container=render_item.apply(thisRef,arguments),html_element=html,$("").append(html_container).append(html_element);var html_container,html_element}),original.apply(thisRef,arguments),thisRef.$control.on("click","."+options.className,function(e){e.preventDefault(),self.isLocked||self.clear()})})}:function(thisRef,options){var original,self=thisRef,html=''+options.label+"";thisRef.setup=(original=self.setup,function(){var render_item;options.append&&(render_item=self.settings.render.item,self.settings.render.item=function(data){return html_container=render_item.apply(thisRef,arguments),html_element=html,pos=html_container.search(/(<\/[^>]+>\s*)$/),html_container.substring(0,pos)+html_element+html_container.substring(pos);var html_container,html_element,pos}),original.apply(thisRef,arguments),thisRef.$control.on("click","."+options.className,function($item){if($item.preventDefault(),!self.isLocked){$item=$($item.currentTarget).parent();return self.setActiveItem($item),self.deleteSelection()&&self.setCaret(self.items.length),!1}})})})(this,options)}),Selectize.define("restore_on_backspace",function(options){var original,self=this;options.text=options.text||function(option){return option[this.settings.labelField]},this.onKeyDown=(original=self.onKeyDown,function(e){var option;return 8===e.keyCode&&""===this.$control_input.val()&&!this.$activeItems.length&&0<=(option=this.caretPos-1)&&option