diff --git a/app/build/docker.go b/app/build/docker.go index 02d077c..592d4b7 100644 --- a/app/build/docker.go +++ b/app/build/docker.go @@ -8,7 +8,6 @@ import ( "regexp" "strings" - "github.com/sohaha/zlsgo/zenv" "github.com/sohaha/zlsgo/zshell" "github.com/sohaha/zlsgo/zutil" @@ -92,7 +91,7 @@ func CommadString(os []OSData, isVendor, isCGO bool, packageName, outDir string) commad = []string{cmd} if outDir != "" { name := packageName - commad = []string{cmd + " -o=" + outDir + zutil.IfVal(zenv.IsWin(), name+".exe", name).(string)} + commad = []string{cmd + " -o=" + outDir + zutil.IfVal(zutil.IsWin(), name+".exe", name).(string)} } } return diff --git a/app/more/install.go b/app/more/install.go index 75f4b0c..43c4b7a 100644 --- a/app/more/install.go +++ b/app/more/install.go @@ -1,8 +1,8 @@ package more import ( - "github.com/sohaha/zlsgo/zenv" "github.com/sohaha/zlsgo/zfile" + "github.com/sohaha/zlsgo/zutil" "github.com/sohaha/zzz/util" "io" "os" @@ -36,7 +36,7 @@ func (m *Methods) Install(vars []string) { } func copyMain(src, dest string) (data string, err error) { - if zenv.IsWin() { + if zutil.IsWin() { data, err = util.ExecCommand("cmd", "/C", "copy", src, dest) } else { data, err = util.ExecCommand("cp", src, dest) diff --git a/app/root/config.go b/app/root/config.go index d209219..35c8cfd 100644 --- a/app/root/config.go +++ b/app/root/config.go @@ -4,7 +4,7 @@ import ( "fmt" "time" - "github.com/sohaha/zlsgo/zenv" + "github.com/sohaha/zlsgo/zutil" ) var ExampleConfig = `# zzz 主配置 @@ -127,7 +127,7 @@ func GetExampleConfig(version string) string { func GetExampleWatchConfig(version string) string { name := "tmpApp" - if zenv.IsWin() { + if zutil.IsWin() { name = "tmpApp.exe" } return fmt.Sprintf(ExampleWatchConfig, version, name, name) diff --git a/app/stress/printer.go b/app/stress/printer.go index 2b221d5..c67e123 100644 --- a/app/stress/printer.go +++ b/app/stress/printer.go @@ -32,10 +32,10 @@ func CreateTextStressSummary(reqStatSummary RequestStatSummary) string { summary += fmt.Sprintf("Total time: %d ms\n", reqStatSummary.endTime.Sub(reqStatSummary.startTime).Nanoseconds()/1000000) summary += "\nData Transferred\n" - summary += fmt.Sprintf("Mean query: %s\n", zfile.FileSizeFormat(uint64(reqStatSummary.avgDataTransferred))) - summary += fmt.Sprintf("Largest query: %s\n", zfile.FileSizeFormat(uint64(reqStatSummary.maxDataTransferred))) - summary += fmt.Sprintf("Smallest query: %s\n", zfile.FileSizeFormat(uint64(reqStatSummary.minDataTransferred))) - summary += fmt.Sprintf("Total: %s\n", zfile.FileSizeFormat(uint64(reqStatSummary.totalDataTransferred))) + summary += fmt.Sprintf("Mean query: %s\n", zfile.SizeFormat(uint64(reqStatSummary.avgDataTransferred))) + summary += fmt.Sprintf("Largest query: %s\n", zfile.SizeFormat(uint64(reqStatSummary.maxDataTransferred))) + summary += fmt.Sprintf("Smallest query: %s\n", zfile.SizeFormat(uint64(reqStatSummary.minDataTransferred))) + summary += fmt.Sprintf("Total: %s\n", zfile.SizeFormat(uint64(reqStatSummary.totalDataTransferred))) summary = summary + "\nResponse Codes\n" //sort the status codes @@ -88,7 +88,7 @@ func (p *printer) printStat(stat RequestStat) { fmt.Fprintf(p.output, "%s %d\t%s \t%d ms\t-> %s %s\n", stat.Proto, stat.StatusCode, - zfile.FileSizeFormat(uint64(stat.DataTransferred)), + zfile.SizeFormat(uint64(stat.DataTransferred)), stat.Duration.Nanoseconds()/1000000, stat.Method, stat.URL) diff --git a/app/watch/http.go b/app/watch/http.go index 88104b7..9d1b4e7 100644 --- a/app/watch/http.go +++ b/app/watch/http.go @@ -19,8 +19,9 @@ import ( "github.com/sohaha/zlsgo/znet" "github.com/sohaha/zlsgo/zstring" "github.com/sohaha/zlsgo/ztype" - "github.com/sohaha/zzz/util" "gopkg.in/olahol/melody.v1" + + "github.com/sohaha/zzz/util" ) var ( @@ -63,6 +64,7 @@ func httpRun() { ws = melody.New() service := znet.New() + // service.SetMode(znet.DebugMode) service.Log.ResetFlags(0) service.Log.SetPrefix("") service.NotFoundHandler(func(c *znet.Context) { @@ -77,6 +79,8 @@ func httpRun() { } }) + service.POST("/___VueRunMinifyApi___/", util.MinifyHandle) + ws.HandleMessage(func(s *melody.Session, data []byte) { // msg := string(data[:]) // zlog.Println(msg) @@ -138,6 +142,8 @@ func httpEntrance(c *znet.Context) { } if err = proxy(pullPath, c.Writer, c.Request); err != nil { c.String(404, "file not found") + } else { + c.Abort(200) } } @@ -172,6 +178,7 @@ func injectingCode(file string) (data string) { html.WriteString(vueSpaJs) } else if httpType == "vue-run" { html.WriteString(vueHotReload) + // html.WriteString(vueRunExport) } html.WriteString("") data = html.String() @@ -179,7 +186,7 @@ func injectingCode(file string) (data string) { } func proxy(_ string, w http.ResponseWriter, r *http.Request) (err error) { - host, scheme := urlParse() + host, scheme := urlParse(httpProxy) if host == "" { err = errors.New("404") } else { @@ -196,7 +203,7 @@ func proxy(_ string, w http.ResponseWriter, r *http.Request) (err error) { return } -func urlParse() (string, string) { +func urlParse(httpProxy string) (string, string) { var host, scheme string p, err := url.Parse(httpProxy) if err != nil { diff --git a/app/watch/httpUtil.go b/app/watch/httpUtil.go index 7b11d9b..43986a1 100644 --- a/app/watch/httpUtil.go +++ b/app/watch/httpUtil.go @@ -13,4 +13,4 @@ a=function(n){for(var o in e)if(e.hasOwnProperty(o)&&e[o]===n)return void locati n){!0===n?n=SpaResource.mod[e]||[]:SpaResource.mod[e]=n,r.mod[e]=n;var o=r.sta,a={},i=!0,c=!1,f=void 0;try{for(var u,l=n[Symbol.iterator]();!(i=(u=l.next()).done);i=!0){var s=u.value;s=t(s);var d=o[s]||[];d.indexOf(e)>=0||(d.push(e),a[s]=d)}}catch(e){c=!0,f=e}finally{try{!i&&l.return&&l.return()}finally{if(c)throw f}}Object.assign(o,a),Object.assign(SpaResource.sta,a)},f=function(){(_SpaForChildren=function(e,n){for(var o=e.length,a=0;a-1&&(p="init"),u.compatible=s[0]>=2,u.compatible?void 0:void console.warn("[HMR] You are using a version of vue-hot-reload-api that is only compatible with Vue.js core ^2.0.0.")},u.install(window.Vue),u.createRecord=function(n,e){if(!l[n]){var t=null;"function"==typeof e&&(t=e,e=t.options),o(n,e),l[n]={Ctor:t,options:e,instances:[]}}},u.isRecorded=function(n){return void 0!==l[n]},u.rerender=r(function(n,e){var o=l[n];if(!e)return void o.instances.slice().forEach(function(n){n.$forceUpdate()});if("function"==typeof e&&(e=e.options),o.Ctor)o.Ctor.options.render=e.render,o.Ctor.options.staticRenderFns=e.staticRenderFns,o.instances.slice().forEach(function(n){n.$options.render=e.render,n.$options.staticRenderFns=e.staticRenderFns,n._staticTrees&&(n._staticTrees=[]),Array.isArray(o.Ctor.options.cached)&&(o.Ctor.options.cached=[]),Array.isArray(n.$options.cached)&&(n.$options.cached=[]);var t=c(n);n.$forceUpdate(),n.$nextTick(t)});else if(o.options.render=e.render,o.options.staticRenderFns=e.staticRenderFns,o.options.functional){if(Object.keys(e).length>2)i(o.options,e);else{var t=o.options._injectStyles;if(t){var r=e.render;o.options.render=function(n,e){return t.call(e),r(n,e)}}}o.options._Ctor=null,Array.isArray(o.options.cached)&&(o.options.cached=[]),o.instances.slice().forEach(function(n){n.$forceUpdate()})}}),u.reload=r(function(n,e){var t=l[n];if(e)if("function"==typeof e&&(e=e.options),o(n,e),t.Ctor){s[1]<2&&(t.Ctor.extendOptions=e);var r=t.Ctor.super.extend(e);r.options._Ctor=t.options._Ctor,t.Ctor.options=r.options,t.Ctor.cid=r.cid,t.Ctor.prototype=r.prototype,r.release&&r.release()}else i(t.options,e);t.instances.slice().forEach(function(n){n.$vnode&&n.$vnode.context?n.$vnode.context.$forceUpdate():console.warn("Root or manually mounted instance modified. Full reload required.")})})},e=setInterval(function(){window.Vue&&window.VueRun&&(clearInterval(e),n())},1e3)}();` +const vueHotReload = `!function(){var e=function(){function e(e){return e?(v.href=e,v.pathname):""}function n(e){var n=e.lastIndexOf(".");return-1!=n?e.substring(n+1,e.length).toLowerCase():""}function t(e,n){if(n.functional){var t=n.render;n.render=function(n,o){var r=l[e].instances;return o&&r.indexOf(o.parent)<0&&r.push(o.parent),t(n,o)}}else o(n,p,function(){var n=l[e];n.Ctor||(n.Ctor=this.constructor),n.instances.push(this)}),o(n,"beforeDestroy",function(){var n=l[e].instances;n.splice(n.indexOf(this),1)})}function o(e,n,t){var o=e[n];e[n]=o?Array.isArray(o)?o.concat(t):[o,t]:[t]}function r(e){return function(n,t){try{e(n,t)}catch(e){console.error(e),console.warn("Something went wrong during Vue component hot-reload. Full reload required.")}}}function i(e,n){for(var t in e)t in n||delete e[t];for(var o in n)e[o]=n[o]}function c(e){if(e._u){var n=e._u;return e._u=function(e){try{return n(e,!0)}catch(t){return n(e,null,!0)}},function(){e._u=n}}}var a,s,u={},l=Object.create(null);window.__VUE_HOT_MAP__=l;var d=!1,f=!1,p="beforeCreate";window.VueRun.debug=u;var h={},v=document.createElement("a"),y=function(){try{var t=location.host;zwatchWs=new WebSocket("ws://"+t+"/"),zwatchWs.onopen=function(e){},zwatchWs.onmessage=function(t){var o=JSON.parse(t.data);console.log(o);var r="/"+o.Name,i=n(r);switch(console.log("update:",r),i){case"vue":VueRun.hotReload(r),console.log("hotReload:",r);break;case"html":var c=location.pathname;"/"==c&&(c="/index.html"),r===c&&location.reload();break;case"css":if(h[r])return void(h[r].href=r+"?v="+ +new Date);document.querySelectorAll("link").forEach(function(e){var n=e.href;n&&(n=n.replace(location.origin,""))===r&&(e.href=n+"?v="+ +new Date,h[r]=e)});break;case"es6":case"js":for(var a in VueRun.staticState){e(VueRun.staticState[a])===r&&location.reload()}document.querySelectorAll("script").forEach(function(e){var n=e.src;if(n)return n=n.replace(location.origin,""),n===r?void location.reload():void 0})}},zwatchWs.onclose=function(e){console.warn("Disconnect from zwatch."),setTimeout(function(){y()},300)}}catch(e){}};if(y(),!window.Vue||!window.Vue.use)return void console.warn("[HMR] Vue not found");u.install=function(e,n){if(!d)return d=!0,a=e.__esModule?e.default:e,s=a.version.split(".").map(Number),f=n,a.config._lifecycleHooks.indexOf("init")>-1&&(p="init"),u.compatible=s[0]>=2,u.compatible?void 0:void console.warn("[HMR] You are using a version of vue-hot-reload-api that is only compatible with Vue.js core ^2.0.0.")},u.install(window.Vue),u.createRecord=function(e,n){if(!l[e]){var o=null;"function"==typeof n&&(o=n,n=o.options),t(e,n),l[e]={Ctor:o,options:n,instances:[]}}},u.isRecorded=function(e){return void 0!==l[e]},u.rerender=r(function(e,n){var t=l[e];if(!n)return void t.instances.slice().forEach(function(e){e.$forceUpdate()});if("function"==typeof n&&(n=n.options),t.Ctor)t.Ctor.options.render=n.render,t.Ctor.options.staticRenderFns=n.staticRenderFns,t.instances.slice().forEach(function(e){e.$options.render=n.render,e.$options.staticRenderFns=n.staticRenderFns,e._staticTrees&&(e._staticTrees=[]),Array.isArray(t.Ctor.options.cached)&&(t.Ctor.options.cached=[]),Array.isArray(e.$options.cached)&&(e.$options.cached=[]);var o=c(e);e.$forceUpdate(),e.$nextTick(o)});else if(t.options.render=n.render,t.options.staticRenderFns=n.staticRenderFns,t.options.functional){if(Object.keys(n).length>2)i(t.options,n);else{var o=t.options._injectStyles;if(o){var r=n.render;t.options.render=function(e,n){return o.call(n),r(e,n)}}}t.options._Ctor=null,Array.isArray(t.options.cached)&&(t.options.cached=[]),t.instances.slice().forEach(function(e){e.$forceUpdate()})}}),u.reload=r(function(e,n){var o=l[e];if(n)if("function"==typeof n&&(n=n.options),t(e,n),o.Ctor){s[1]<2&&(o.Ctor.extendOptions=n);var r=o.Ctor.super.extend(n);r.options._Ctor=o.options._Ctor,o.Ctor.options=r.options,o.Ctor.cid=r.cid,o.Ctor.prototype=r.prototype,r.release&&r.release()}else i(o.options,n);o.instances.slice().forEach(function(e){e.$vnode&&e.$vnode.context?e.$vnode.context.$forceUpdate():console.warn("Root or manually mounted instance modified. Full reload required.")})})},n=setInterval(function(){window.Vue&&window.VueRun&&(clearInterval(n),e())},1e3);!function(){function e(e){return 0===e?"h":1===e?"j":"c"}function n(n,t,o,r){var i="";switch(e(o)){case"h":t+="";break;case"c":i=r.styles[0].elt.hasAttribute("data-scopeid")?"scoped":"",t+="";break;case"j":t+="