@shoplineos/cli 1.1.1 → 1.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"default",{enumerable:!0,get:()=>
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"default",{enumerable:!0,get:()=>q});const e=w(require("qs")),t=w(require("koa")),r=w(require("https")),i=w(require("pathe")),o=w(require("koa-send")),s=w(require("koa-body")),l=w(require("@koa/router")),d=w(require("form-data")),n=w(require("axios")),a=require("./sse"),u=w(require("../../utils/debug")),c=w(require("../../helpers/config")),h=require("../../utils/messages"),p=require("../../utils/const"),v=require("../theme/utils"),g=w(require("../../utils/get-real-referer")),m=require("../theme/3.0/theme"),y=w(require("../../utils/winston"));function f(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function w(e){return e&&e.__esModule?e:{default:e}}const _=["multipart/form-data","application/x-www-form-urlencoded"];class q extends u.default{async start(){let e=new t.default,d=new l.default,a=new r.default.Agent({rejectUnauthorized:!1}),u=n.default.create({httpsAgent:a});return d.get("/(.*).css",async e=>{await (0,o.default)(e,e.path,{root:this.cwd})}),d.get("/socket-client.js",async e=>{await (0,o.default)(e,e.path,{root:i.default.join(__dirname,"./web")})}),d.get("/hot-reload",e=>{e.req.socket.setKeepAlive(!0),e.req.socket.setNoDelay(!0),e.req.socket.setTimeout(0),e.set({"Content-Type":"text/event-stream; charset=utf-8","Cache-Control":"no-cache",Connection:"keep-alive"});let t=this.streams.create();e.status=200,e.body=t,t.write(":ok\n"),t.on("close",()=>{this.log("SSE lost connection")})}),d.all("/(.*)",(0,s.default)({multipart:!0}),async e=>{var t,r,i,o,s,l,d,n,a,c;let{method:v,query:m,path:f,request:w}=e,{body:b,headers:$}=q.getRequestBody((null===(t=e.request.headers)||void 0===t?void 0:t["content-type"])||"",e.request.body),S="l_spwd=1";try{let t={cookie:`${w.headers.cookie}; ${S}`||S,"user-agent":`${w.headers["user-agent"]} ${p.CLI_USER_AGENT}`,...$,referer:(0,g.default)(this.storeUrl,(null===(r=w.headers)||void 0===r?void 0:r.referer)||"/",this.previewQuery),Accept:(null===(i=e.request.headers)||void 0===i?void 0:i.accept)||"*/*"},s=await u({method:v,url:`${this.storeUrl}${f}`,maxRedirects:0,headers:t,params:{...m,...this.previewQuery,ignoreRedirect:!0,dev_mode:1},data:"get"===v.toLowerCase()?null:b});if(e.set(s.headers),f.endsWith(".ico")||["application/json",..._].some(e=>s.headers["content-type"].includes(e))){e.status=200,e.body=s.data;return}let l=`<script>
|
|
2
2
|
(() => {
|
|
3
3
|
window.__SHOPLINE_CLI_ENV__ = {
|
|
4
4
|
mode: '${this.mode}',
|
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
}
|
|
7
7
|
})();
|
|
8
8
|
</script>
|
|
9
|
-
<script src="/socket-client.js"></script>`,d=null==
|
|
9
|
+
<script src="/socket-client.js"></script>`,d=null==s?void 0:null===(o=s.data)||void 0===o?void 0:o.replace(/(<\/body>)/,`${l}$1`);e.status=200,e.body=d}catch(r){let t=null==r?void 0:null===(s=r.response)||void 0===s?void 0:s.status;if(!t){console.log(r),e.body=r;return}if(e.status=t,t.toString().startsWith(30)){let t=null==r?void 0:null===(d=r.response)||void 0===d?void 0:null===(n=d.headers)||void 0===n?void 0:n["set-cookie"];t&&e.set("set-cookie",t);let i=null==r?void 0:null===(a=r.response)||void 0===a?void 0:null===(c=a.headers)||void 0===c?void 0:c.location;if(i){let t=i.replace(this.storeUrl,this.localUrl);e.redirect(t);return}e.body=""}if(!t.toString().startsWith(20)){let e=`${this.storeUrl}${f}`,r={...m,...this.previewQuery,ignoreRedirect:!0,dev_mode:1};y.default.log(`request proxy error: ${t} ${e} ${JSON.stringify(r)}`),console.log((0,h.getMessage)("theme.serve.error.non_start_20_error",{errorCode:t,requestUrl:e,requestQuery:JSON.stringify(r,null,2)}))}e.body=null==r?void 0:null===(l=r.response)||void 0===l?void 0:l.data}}),e.use(d.routes()).use(d.allowedMethods()),e.listen(this.port,async()=>{let e=await (0,m.startThemeService)({mode:this.mode,cwd:this.cwd,sse:this.streams,includeFilter:this.includeFilter,ignoreFilter:this.ignoreFilter,editorSync:this.editorSync});this.previewQuery.themeId=null==e?void 0:e.themeId,this.printInfo()}),e}printInfo(){let{storeUrl:t}=this,{themeId:r}=this.previewQuery,i=`${t}/admin/theme-editor/editing/Home?themeId=${r}&dev_mode=1`,o=`${t}/?${e.default.stringify({...this.previewQuery,dev_mode:1})}`,{localUrl:s}=this,l=(0,v.getRelativePath)(this.cwd);console.log((0,h.getMessage)("theme.serve.serving",{path:l||"."})),console.log(),console.log((0,h.getMessage)("theme.serve.print_theme_id",{theme_id:r})),console.log(),console.log((0,h.getMessage)("core.context.open_url",{url:s})),console.log(),console.log((0,h.getMessage)("theme.serve.customize_or_preview",{editor_url:i,preview_url:o}))}static getRequestBody(t,r){if(t.includes("multipart/form-data")){let e=new d.default;for(let t in r)Object.prototype.hasOwnProperty.call(r,t)&&e.append(t,r[t]);return{body:e,headers:e.getHeaders()}}if(t.includes("application/x-www-form-urlencoded")){let t=e.default.stringify(r);return{body:t,headers:{"Content-Type":"application/x-www-form-urlencoded"}}}return{body:r,headers:{}}}get localUrl(){return`http://127.0.0.1:${this.port}`}constructor({port:e,liveReload:t,path:r,themeEditorSync:i},o){super("theme:serve"),f(this,"cwd",void 0),f(this,"port",void 0),f(this,"previewQuery",void 0),f(this,"storeUrl",void 0),f(this,"mode",void 0),f(this,"streams",void 0),f(this,"includeFilter",void 0),f(this,"ignoreFilter",void 0),f(this,"editorSync",void 0),this.cwd=r,this.port=e,this.storeUrl=c.default.currentStore,this.mode=t,this.streams=new a.SSEQueue,this.ignoreFilter=o.ignore,this.includeFilter=o.include,this.editorSync=i,this.previewQuery={preview:1,themeId:""},this.start()}}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shoplineos/cli",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.3",
|
|
4
4
|
"description": "A CLI tool to build for the Shopline platform",
|
|
5
5
|
"bin": {
|
|
6
6
|
"sl": "./bin/index.js"
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"archiver": "^5.3.1",
|
|
47
47
|
"axios": "^0.24.0",
|
|
48
48
|
"chalk": "^4.1.2",
|
|
49
|
-
"cheerio": "
|
|
49
|
+
"cheerio": "1.0.0-rc.10",
|
|
50
50
|
"chokidar": "^3.5.2",
|
|
51
51
|
"ci-info": "^4.0.0",
|
|
52
52
|
"cli-progress": "^3.9.1",
|