@shoplineos/cli 1.3.0 → 1.3.2

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.
@@ -3,4 +3,4 @@ error message: ${null==e?void 0:null===(_=e.data)||void 0===_?void 0:_.message}
3
3
  trace id: ${L}`}throw new u.AbortError(`url: ${e.config.baseURL+e.config.url}`,t)}return null===(g=e.data)||void 0===g?void 0:g.data},e=>{if((0,p.reportBug)(e),e.response){var t,r,n,o;(0,p.reportHttpRes)(e.response);let{response:a}=e,s=a.config.url,i=(null==a?void 0:null===(t=a.data)||void 0===t?void 0:t.trace_id)||(null==a?void 0:null===(r=a.data)||void 0===r?void 0:r.traceid)||(null==a?void 0:null===(n=a.data)||void 0===n?void 0:n.traceId)||(null==a?void 0:null===(o=a.headers)||void 0===o?void 0:o["x-request-id"])||"";(0,l.renderFatalError)(Error(`url: ${s}
4
4
  status: ${a.status}
5
5
  traceId: ${i}
6
- ${e}`))}return Promise.reject(e)})}const L=o.default.create({baseURL:_(s.DEFAULT_EXTENSION_ENDPOINT),maxBodyLength:1/0,maxContentLength:1/0,headers:{"Content-Type":"application/json","User-Agent":E.CLI_USER_AGENT}}),R=o.default.create({baseURL:T(s.DEFAULT_EXTENSION_ENDPOINT),maxBodyLength:1/0,maxContentLength:1/0,headers:{"Content-Type":"application/json","User-Agent":E.CLI_USER_AGENT}});v(L),v(R);const m=o.default.create({baseURL:h(s.DEFAULT_EXTENSION_ENDPOINT),maxBodyLength:1/0,maxContentLength:1/0,headers:{"Content-Type":"application/json"}}),P=o.default.create({baseURL:O(s.DEFAULT_EXTENSION_ENDPOINT),maxBodyLength:1/0,maxContentLength:1/0,headers:{"Content-Type":"application/json"}});function U(e){let t=s.EXTENSION_ENDPOINTS[e];L.defaults.baseURL=_(t),m.defaults.baseURL=h(t),R.defaults.baseURL=T(t),P.defaults.baseURL=O(t)}v(m,{useThemeAuth:!0}),v(P,{useThemeAuth:!0}),function(e){e.CHECKOUT="CHECKOUT",e.THEME="THEME",e.PIXELS="WEB_PIXEL",e.SHOPPER="SHOPPER"}(e||(e={})),function(e){e.THEME_APP_BLOCK="THEME_APP_BLOCK",e.CHECKOUT_UI="CHECKOUT_UI",e.PIXELS="WEB_PIXEL_EXT",e.SHOPPER_CUSTOM_BLOCK="SHOPPER_CUSTOM_BLOCK",e.SHOPPER_CUSTOM_WEB_PAGE="SHOPPER_CUSTOM_WEB_PAGE"}(t||(t={})),function(e){e.DRAFT="DRAFT",e.WORKING_DRAFT="WORKING_DRAFT"}(r||(r={}));const C=e=>R.post("/register",JSON.stringify({...e})),N=e=>R.post("/push",e),S=e=>m.post("/auth/app/list",e),y=e=>P.post("/auth/app/ext/list",e),A=()=>m.get("/auth/partner/list");function I(e){return m.post("/auth/store/list",{partnerId:e})}function b(e){return m.post("/auth/generate/accessToken",e)}function H(e,t){return m.post("/auth/app/queryByAppKey",{partnerId:e,appKey:t})}function x(e,t){return m.post("/auth/store/queryByHandle",{partnerId:e,handle:t})}function q(){return P.post("/function/template/list")}function B(e){return P.post("/function/register",e)}function M(e){return P.post("/function/deploy",e)}
6
+ ${e}`))}return Promise.reject(e)})}const L=o.default.create({baseURL:_(s.DEFAULT_EXTENSION_ENDPOINT),maxBodyLength:1/0,maxContentLength:1/0,headers:{"Content-Type":"application/json","User-Agent":E.CLI_USER_AGENT}}),R=o.default.create({baseURL:T(s.DEFAULT_EXTENSION_ENDPOINT),maxBodyLength:1/0,maxContentLength:1/0,headers:{"Content-Type":"application/json","User-Agent":E.CLI_USER_AGENT}});v(L),v(R);const m=o.default.create({baseURL:h(s.DEFAULT_EXTENSION_ENDPOINT),maxBodyLength:1/0,maxContentLength:1/0,headers:{"Content-Type":"application/json"}}),P=o.default.create({baseURL:O(s.DEFAULT_EXTENSION_ENDPOINT),maxBodyLength:1/0,maxContentLength:1/0,headers:{"Content-Type":"application/json"}});function U(e){let t=s.EXTENSION_ENDPOINTS[e];L.defaults.baseURL=_(t),m.defaults.baseURL=h(t),R.defaults.baseURL=T(t),P.defaults.baseURL=O(t)}v(m,{useThemeAuth:!0}),v(P,{useThemeAuth:!0}),function(e){e.CHECKOUT="CHECKOUT",e.THEME="THEME",e.PIXELS="WEB_PIXEL",e.SHOPPER="SHOPPER"}(e||(e={})),function(e){e.THEME_APP_BLOCK="THEME_APP_BLOCK",e.CHECKOUT_UI="CHECKOUT_UI",e.PIXELS="WEB_PIXEL_EXT",e.SHOPPER_CUSTOM_BLOCK="SHOPPER_CUSTOM_BLOCK",e.SHOPPER_CUSTOM_WEB_PAGE="SHOPPER_CUSTOM_WEB_PAGE"}(t||(t={})),function(e){e.DRAFT="DRAFT",e.WORKING_DRAFT="WORKING_DRAFT"}(r||(r={}));const C=e=>R.post("/register",JSON.stringify({...e})),N=e=>R.post("/push",e),S=e=>P.post("/auth/app/list",e),y=e=>P.post("/auth/app/ext/list",e),A=()=>P.post("/auth/partner/list");function I(e){return P.post("/auth/store/list",{partnerId:e})}function b(e){return P.post("/auth/generate/accessToken",e)}function H(e,t){return P.post("/auth/app/queryByAppKey",{partnerId:e,appKey:t})}function x(e,t){return P.post("/auth/store/queryByHandle",{partnerId:e,handle:t})}function q(){return P.post("/function/template/list")}function B(e){return P.post("/function/register",e)}function M(e){return P.post("/function/deploy",e)}
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"default",{enumerable:!0,get:()=>r});const e=require("crypto"),t=function(e){return e&&e.__esModule?e:{default:e}}(require("mime")),i=require("../../utils/path"),s=require("../../utils/fs");function l(e,t,i){return t in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}class r{get fullPath(){return(0,i.joinPath)(this.cwd,this.filePath)}get extName(){return(0,i.extname)(this.filePath)}get isExist(){return(0,s.fileExistsSync)(this.fullPath)}get isConfigSchemaFile(){return"config/settings_schema.json"===this.fileName}get isConfigFile(){return["config/settings_schema.json","config/settings_data.json"].includes(this.fileName)}get mimeType(){return this.isExist?t.default.getType(this.filePath):""}get isImageType(){var e,t;return(null===(e=this.mimeType)||void 0===e?void 0:e.startsWith("image/"))&&!(null===(t=this.mimeType)||void 0===t?void 0:t.startsWith("image/svg"))}get fileName(){return this.filePath}get fileContent(){return this.isImageType?(0,s.readFileSync)(this.localeFullFilePath,{}):(0,s.readFileSync)(this.localeFullFilePath)}get localeFullFilePath(){let e=this.filePath.endsWith(".preview")?this.filePath.replace(".preview",""):this.filePath,t=(0,i.joinPath)(this.cwd,e);return t}get checksum(){return(0,e.createHash)("sha256").update(this.fileContent).digest("hex")}constructor(e,t){l(this,"cwd",(0,i.cwd)()),l(this,"filePath",void 0),this.filePath=e,this.cwd=t}}
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"default",{enumerable:!0,get:()=>r});const e=require("crypto"),t=function(e){return e&&e.__esModule?e:{default:e}}(require("mime")),i=require("../../utils/path"),s=require("../../utils/fs");function l(e,t,i){return t in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}class r{get fullPath(){return(0,i.joinPath)(this.cwd,this.filePath)}get extName(){return(0,i.extname)(this.filePath)}get isExist(){return(0,s.fileExistsSync)(this.fullPath)}get isConfigSchemaFile(){return"config/settings_schema.json"===this.fileName}get isConfigFile(){return["config/settings_schema.json","config/settings_data.json"].includes(this.fileName)}get mimeType(){return this.isExist?t.default.getType(this.filePath):""}get isImageType(){var e,t;return(null===(e=this.mimeType)||void 0===e?void 0:e.startsWith("image/"))&&!(null===(t=this.mimeType)||void 0===t?void 0:t.startsWith("image/svg"))}get fileName(){return this.filePath}get fileContent(){return this.filePath.startsWith("assets/")?(0,s.readFileSync)(this.localeFullFilePath,{}):(0,s.readFileSync)(this.localeFullFilePath)}get localeFullFilePath(){let e=this.filePath.endsWith(".preview")?this.filePath.replace(".preview",""):this.filePath,t=(0,i.joinPath)(this.cwd,e);return t}get checksum(){return(0,e.createHash)("sha256").update(this.fileContent).digest("hex")}constructor(e,t){l(this,"cwd",(0,i.cwd)()),l(this,"filePath",void 0),this.filePath=e,this.cwd=t}}
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"default",{enumerable:!0,get:()=>k});const e=F(require("fs-extra")),t=F(require("form-data")),l=F(require("../../helpers/config")),i=require("./api"),a=require("./utils"),s=require("./const"),r=F(require("../../utils/get-objects-diff")),o=require("./types"),u=F(require("../../utils/tiny-queue")),d=F(require("./index")),n=require("../../utils/messages"),f=require("./inquirer"),c=F(require("../../utils/debug")),h=F(require("./uploader")),m=require("../../utils/error"),p=F(require("./file")),g=F(require("./operation")),y=F(require("../../utils/winston"));function w(e,t,l){return t in e?Object.defineProperty(e,t,{value:l,enumerable:!0,configurable:!0,writable:!0}):e[t]=l,e}function F(e){return e&&e.__esModule?e:{default:e}}class k extends c.default{setUpdateQueue(e){this.updateQueue=e}setUpdateMode(e){this.updateMode=e}async syncTheme(){y.default.log("Ensure development theme..."),await this.ensureDevelopmentTheme(),this.printSyncMessage(),y.default.log(`Check theme (${this.themeId}) is uncompleted dev theme...`);let e=await d.default.isUncompletedDevTheme(this.themeId);y.default.log(`The theme ${this.themeId}) is uncompleted dev theme: ${e}`),e?(y.default.log("Upload theme files..."),await this.uploadThemeFiles()):(y.default.log("Sync theme files..."),await this.syncUpdate())}printSyncMessage(){console.log(`✨ Syncing theme #${this.themeId} on ${l.default.currentStore}`)}getFilterFileChecksums(e){let t=Object.keys(e).reduce((t,l)=>{let i=this.ignoreFilter.match(l),a=this.includeFilter.match(l);return!i&&a&&(t[l]=e[l]),t},{});return t}async getFileChecksums(){let{localeFileChecksums:e}=this.uploader,t=await (0,i.getThemeFileList)(this.themeId),l=t.files.reduce((e,t)=>(t.fileName.endsWith(".preview")||(e[t.fileName]=t.fileContentChecksum||""),e),Object.create(null)),a=this.getFilterFileChecksums(e),s=this.getFilterFileChecksums(l);return{local:a,remote:s}}async syncRemoteUpdate(){let{local:e,remote:t}=await this.getFileChecksums();if(this.editorSync){y.default.log("[Remote Watch] Get remote and local diffs...");let l=await (0,r.default)(t,e);y.default.log("[Remote Watch] Run remote diffs..."),await this.updateStrategy(l,!0)}}async syncUpdate(){y.default.log("Get local and remote files checksum...");let{local:e,remote:t}=await this.getFileChecksums();if(this.editorSync){y.default.log("Get remote and local diffs...");let l=await (0,r.default)(t,e);await this.updateStrategy(l)}else{y.default.log("Get local and remote diffs...");let l=await (0,r.default)(e,t);l.length&&(y.default.log(`Run local diffs ${JSON.stringify(l)}...`),await this.runAllLocalDiff(l))}}async updateStrategy(e,t){let{local:l,remote:i}=await k.prepareUpdateDiffs(e,t);this.log("local diffs: %O",l),this.log("remote diffs: %O",i),l.length&&(y.default.log(`Run local diffs ${JSON.stringify(l)}...`),await this.runAllLocalDiff(l,!0)),i.length&&(y.default.log(`Run remote diffs ${JSON.stringify(i)}...`),await this.runAllRemoteDiff(i))}static async prepareUpdateDiffs(e,t){let l={local:[],remote:[]},i=e.length,a=e=>"create"===e?"delete":"delete"===e?"create":"update",s=(e,t)=>{let i=t.filter(e=>{let t=e.key;return(t.startsWith("config/")||t.startsWith("templates/"))&&t.endsWith(".json")});"remote"===e?l.remote=l.remote.concat(i):l.local=l.local.concat(i.map(e=>({...e,type:a(e.type)})))};if(!i)return l;if(t)return s("remote",e),l;y.default.log("Update conflicts files...");let[{key:r},...o]=e,u=await k.promptUpdateStrategy(r);if(s(u,[e[0]]),1===i)return l;let d=await (0,f.askForApplyToAll)(o.length);for await(let e of(console.log(),o))if(d)y.default.log("Apply to all files to solve conflict files..."),s(u,o);else{let t=await k.promptUpdateStrategy(e.key);y.default.log(`Apply ${e.key} strategy to solve conflict files...`),console.log(),s(t,[e])}return l}static async promptUpdateStrategy(e){let t=(0,n.getMessage)("theme.serve.syncer.update_strategy.title_content",{file_name:e});console.log(t);let l=await (0,f.askForUpdateStrategy)();return l}async processRemoteDiffFile(t,l,i){var a;let{fullPath:s}=l;if("create"===t||"update"===t){y.default.log(`Get file (${l.fileName}) information: ${l.fileName}`);let t=await this.getFileInfo(s);y.default.log("Writing file content"),e.default.ensureFileSync(s),e.default.writeFileSync(s,t)}else"delete"===t&&(y.default.log(`Delete file (${l.fileName})`),e.default.unlinkSync(s));null===(a=this.updateQueue)||void 0===a||a.push({key:l.fileName,checksums:[i],type:t})}runAllLocalDiff(e,t){return new Promise((l,i)=>{let a=!1,s=new m.ErrorStash,r=async e=>{if(a){e();return}y.default.log("Set theme upload completed"),await h.default.setUploadCompleted(this.themeId,o.EThemeStatus.Development),a=!0,e()};this.queue.on("all-done",async()=>{y.default.log("All task queue is all done!"),s.printAll(),await r(()=>l())}),this.queue.on("error",async e=>{y.default.logError(e),e instanceof m.ValidatorError?(y.default.log("Occurred validation error"),s.concat(e.errors)):(s.printAll(),await r(()=>{i(e)}))}),this.queue.all(e.map(({type:e,key:l})=>async()=>{let i=new p.default(l,this.cwd);if(await this.processLocalDiffFile(e,i),!t){let t=this.editorSync&&"update"===e?"get":e,l=new g.default(t,i).asSyncMessage();console.log(l)}}))})}runAllRemoteDiff(e){return new Promise((t,l)=>{this.queue.on("all-done",()=>t()),this.queue.on("error",e=>l(e)),this.queue.all(e.map(({type:e,key:t,checksums:l})=>async()=>{let i=new p.default(t,this.cwd);if(await this.processRemoteDiffFile(e,i,l[0]),"polling"===this.updateMode){let t=this.editorSync&&"update"===e?"get":e,l=new g.default(t,i).asSyncMessage();console.log(l)}}))})}async processLocalDiffFile(e,t){"create"===e?(y.default.log(`Create file: ${t.fileName}`),await this.createFile(t)):"update"===e?(y.default.log(`Update file: ${t.fileName}`),await this.updateFile(t)):"delete"===e&&(y.default.log(`Delete file: ${t.fileName}`),await this.deleteFile(t))}async getFileInfo(e){let t=(0,a.parseFileName)(e,this.cwd),l=await (0,i.getThemeFileDetail)({themeId:this.themeId,fileName:t});return null==l?void 0:l.fileContent}async deleteFile(e){y.default.log(`Delete file: ${e.fileName}`),await (0,i.deleteFile)(this.themeId,{fileName:e.fileName,cliFirstCreateFile:!0}),this.uploader.checksums.has(e)&&(y.default.log(`Delete file (${e.fileName}) checksum`),this.uploader.checksums.delete(e))}async updateFile(l){let{fileName:r}=l,o=r.startsWith("assets/");if((0,a.checkTemplateFileName)(r),o&&!s.TEXT_TYPE_EXTNAMES.includes(l.extName)){let a=new t.default;a.append("file",e.default.createReadStream(l.fullPath)),a.append("fileName",r),a.append("cliFirstCreateFile","true"),y.default.log(`Upload asset file: ${r}`);let s=await (0,i.uploadFile)(this.themeId,a,{headers:a.getHeaders()});y.default.log(`Update file (${r}) checksum: ${s.fileContentChecksum}`),this.uploader.checksums.set(r,null==s?void 0:s.fileContentChecksum)}else{if(!(0,a.checkLayoutFile)(r,l.fileContent))throw new m.AbortError(s.ERRORS.LAYOUT_FILE_NOT_MATCH_TEMPLATE);y.default.log(`Update file: ${r}`);let e=await (0,i.updateFile)(this.themeId,{fileName:r,fileContent:l.fileContent,cliFirstCreateFile:!0});y.default.log(`Update file (${r}) checksum: ${e.fileContentChecksum}`),this.uploader.checksums.set(r,null==e?void 0:e.fileContentChecksum)}}async createFile(l){let{fileName:r}=l,o=r.startsWith("assets/");if(!(0,a.checkLayoutFile)(r,l.fileContent))throw new m.AbortError(s.ERRORS.LAYOUT_FILE_NOT_MATCH_TEMPLATE);if((0,a.checkTemplateFileName)(r),o&&!s.TEXT_TYPE_EXTNAMES.includes(l.extName)){let a=new t.default;a.append("file",e.default.createReadStream(l.fullPath)),a.append("fileName",r),a.append("cliFirstCreateFile","true"),y.default.log(`Upload asset file: ${r}`);let s=await (0,i.uploadFile)(this.themeId,a,{headers:a.getHeaders()});y.default.log(`Update file (${r}) checksum: ${s.fileContentChecksum}`),this.uploader.checksums.set(r,s.fileContentChecksum)}else{y.default.log(`Create file: ${r}`);let e=await (0,i.createFile)(this.themeId,{fileName:r,fileContent:l.fileContent,cliFirstCreateFile:!0});y.default.log(`Update file (${r}) checksum: ${e.fileContentChecksum}`),this.uploader.checksums.set(r,e.fileContentChecksum)}}async ensureDevelopmentTheme(){let{id:e,name:t}=await d.default.findOrCreate(this.themeId);if(e)this.themeId=e,l.default.developmentThemeId=e,l.default.developmentThemeName=t;else throw new m.AbortError(s.ERRORS.THEME_ID_NOT_EXIST)}async uploadThemeFiles(){await this.uploader.upload(this.themeId,o.EThemeStatus.Development)}constructor(e,t,i,a=process.cwd()){super("theme:serve:update"),w(this,"cwd",void 0),w(this,"themeId",void 0),w(this,"queue",void 0),w(this,"editorSync",void 0),w(this,"updateQueue",void 0),w(this,"updateMode","initialize"),w(this,"includeFilter",void 0),w(this,"ignoreFilter",void 0),w(this,"uploader",void 0),this.cwd=a,this.themeId=l.default.developmentThemeId,this.queue=new u.default({concurrency:4}),this.editorSync=e,this.updateQueue=null,this.includeFilter=t.include,this.ignoreFilter=t.ignore,this.uploader=i}}
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"default",{enumerable:!0,get:()=>k});const e=F(require("fs-extra")),t=F(require("form-data")),l=F(require("../../helpers/config")),i=require("./api"),a=require("./utils"),s=require("./const"),r=F(require("../../utils/get-objects-diff")),o=require("./types"),u=F(require("../../utils/tiny-queue")),d=F(require("./index")),n=require("../../utils/messages"),f=require("./inquirer"),c=F(require("../../utils/debug")),h=F(require("./uploader")),m=require("../../utils/error"),p=F(require("./file")),g=F(require("./operation")),y=F(require("../../utils/winston"));function w(e,t,l){return t in e?Object.defineProperty(e,t,{value:l,enumerable:!0,configurable:!0,writable:!0}):e[t]=l,e}function F(e){return e&&e.__esModule?e:{default:e}}class k extends c.default{setUpdateQueue(e){this.updateQueue=e}setUpdateMode(e){this.updateMode=e}async syncTheme(){y.default.log("Ensure development theme..."),await this.ensureDevelopmentTheme(),this.printSyncMessage(),y.default.log(`Check theme (${this.themeId}) is uncompleted dev theme...`);let e=await d.default.isUncompletedDevTheme(this.themeId);y.default.log(`The theme ${this.themeId}) is uncompleted dev theme: ${e}`),e?(y.default.log("Upload theme files..."),await this.uploadThemeFiles()):(y.default.log("Sync theme files..."),await this.syncUpdate())}printSyncMessage(){console.log(`✨ Syncing theme #${this.themeId} on ${l.default.currentStore}`)}getFilterFileChecksums(e){let t=Object.keys(e).reduce((t,l)=>{let i=this.ignoreFilter.match(l),a=this.includeFilter.match(l);return!i&&a&&(t[l]=e[l]),t},{});return t}async getFileChecksums(){let{localeFileChecksums:e}=this.uploader,t=await (0,i.getThemeFileList)(this.themeId),l=t.files.reduce((e,t)=>(t.fileName.endsWith(".preview")||(e[t.fileName]=t.fileContentChecksum||""),e),Object.create(null)),a=this.getFilterFileChecksums(e),s=this.getFilterFileChecksums(l);return{local:a,remote:s}}async syncRemoteUpdate(){let{local:e,remote:t}=await this.getFileChecksums();if(this.editorSync){y.default.log("[Remote Watch] Get remote and local diffs...");let l=await (0,r.default)(t,e);y.default.log("[Remote Watch] Run remote diffs..."),await this.updateStrategy(l,!0)}}async syncUpdate(){y.default.log("Get local and remote files checksum...");let{local:e,remote:t}=await this.getFileChecksums();if(this.editorSync){y.default.log("Get remote and local diffs...");let l=await (0,r.default)(t,e);await this.updateStrategy(l)}else{y.default.log("Get local and remote diffs...");let l=await (0,r.default)(e,t);l.length&&(y.default.log(`Run local diffs ${JSON.stringify(l)}...`),await this.runAllLocalDiff(l))}}async updateStrategy(e,t){let{local:l,remote:i}=await k.prepareUpdateDiffs(e,t);this.log("local diffs: %O",l),this.log("remote diffs: %O",i),l.length&&(y.default.log(`Run local diffs ${JSON.stringify(l)}...`),await this.runAllLocalDiff(l,!0)),i.length&&(y.default.log(`Run remote diffs ${JSON.stringify(i)}...`),await this.runAllRemoteDiff(i))}static async prepareUpdateDiffs(e,t){let l={local:[],remote:[]},i=e.length,a=e=>"create"===e?"delete":"delete"===e?"create":"update",s=(e,t)=>{let i=t.filter(e=>{let t=e.key;return(t.startsWith("config/")||t.startsWith("templates/"))&&t.endsWith(".json")});"remote"===e?l.remote=l.remote.concat(i):l.local=l.local.concat(i.map(e=>({...e,type:a(e.type)})))};if(!i)return l;if(t)return s("remote",e),l;y.default.log("Update conflicts files...");let[{key:r},...o]=e,u=await k.promptUpdateStrategy(r);if(s(u,[e[0]]),1===i)return l;let d=await (0,f.askForApplyToAll)(o.length);for await(let e of(console.log(),o))if(d)y.default.log("Apply to all files to solve conflict files..."),s(u,o);else{let t=await k.promptUpdateStrategy(e.key);y.default.log(`Apply ${e.key} strategy to solve conflict files...`),console.log(),s(t,[e])}return l}static async promptUpdateStrategy(e){let t=(0,n.getMessage)("theme.serve.syncer.update_strategy.title_content",{file_name:e});console.log(t);let l=await (0,f.askForUpdateStrategy)();return l}async processRemoteDiffFile(t,l,i){var a;let{fullPath:s}=l;if("create"===t||"update"===t){y.default.log(`Get file (${l.fileName}) information: ${l.fileName}`);let t=await this.getFileInfo(s);y.default.log("Writing file content"),e.default.ensureFileSync(s),e.default.writeFileSync(s,t)}else"delete"===t&&(y.default.log(`Delete file (${l.fileName})`),e.default.unlinkSync(s));null===(a=this.updateQueue)||void 0===a||a.push({key:l.fileName,checksums:[i],type:t})}runAllLocalDiff(e,t){return new Promise((l,i)=>{let a=!1,s=new m.ErrorStash,r=async e=>{if(a){e();return}y.default.log("Set theme upload completed"),await h.default.setUploadCompleted(this.themeId,o.EThemeStatus.Development),a=!0,e()};this.queue.on("all-done",async()=>{y.default.log("All task queue is all done!"),s.printAll(),await r(()=>l())}),this.queue.on("error",async e=>{y.default.logError(e),e instanceof m.ValidatorError?(y.default.log("Occurred validation error"),s.concat(e.errors)):(s.printAll(),await r(()=>{i(e)}))}),this.queue.all(e.map(({type:e,key:l})=>async()=>{let i=new p.default(l,this.cwd);if(await this.processLocalDiffFile(e,i),!t){let t=this.editorSync&&"update"===e?"get":e,l=new g.default(t,i).asSyncMessage();console.log(l)}}))})}runAllRemoteDiff(e){return new Promise((t,l)=>{this.queue.on("all-done",()=>t()),this.queue.on("error",e=>l(e)),this.queue.all(e.map(({type:e,key:t,checksums:l})=>async()=>{let i=new p.default(t,this.cwd);if(await this.processRemoteDiffFile(e,i,l[0]),"polling"===this.updateMode){let t=this.editorSync&&"update"===e?"get":e,l=new g.default(t,i).asSyncMessage();console.log(l)}}))})}async processLocalDiffFile(e,t){"create"===e?(y.default.log(`Create file: ${t.fileName}`),await this.createFile(t)):"update"===e?(y.default.log(`Update file: ${t.fileName}`),await this.updateFile(t)):"delete"===e&&(y.default.log(`Delete file: ${t.fileName}`),await this.deleteFile(t))}async getFileInfo(e){let t=(0,a.parseFileName)(e,this.cwd),l=await (0,i.getThemeFileDetail)({themeId:this.themeId,fileName:t});return null==l?void 0:l.fileContent}async deleteFile(e){y.default.log(`Delete file: ${e.fileName}`),await (0,i.deleteFile)(this.themeId,{fileName:e.fileName,cliFirstCreateFile:!0}),this.uploader.checksums.has(e)&&(y.default.log(`Delete file (${e.fileName}) checksum`),this.uploader.checksums.delete(e))}async updateFile(l){let{fileName:r}=l,o=r.startsWith("assets/");if((0,a.checkTemplateFileName)(r),o&&!s.TEXT_TYPE_EXTNAMES.includes(l.extName)){let a=new t.default;a.append("file",e.default.createReadStream(l.fullPath)),a.append("fileName",r),a.append("cliFirstCreateFile","true"),y.default.log(`Upload asset file: ${r}`);let s=await (0,i.uploadFile)(this.themeId,a,{headers:a.getHeaders()});y.default.log(`Update file (${r}) checksum: ${s.fileContentChecksum}`),this.uploader.checksums.set(r,null==s?void 0:s.fileContentChecksum)}else{if(!(0,a.checkLayoutFile)(r,l.fileContent))throw new m.AbortError(s.ERRORS.LAYOUT_FILE_NOT_MATCH_TEMPLATE);y.default.log(`Update file: ${r}`);let e=await (0,i.updateFile)(this.themeId,{fileName:r,fileContent:l.fileContent,cliFirstCreateFile:!0});y.default.log(`Update file (${r}) checksum: ${e.fileContentChecksum}`),this.uploader.checksums.set(r,null==e?void 0:e.fileContentChecksum)}}async createFile(l){let{fileName:r}=l,o=r.startsWith("assets/");if(!(0,a.checkLayoutFile)(r,l.fileContent))throw new m.AbortError(s.ERRORS.LAYOUT_FILE_NOT_MATCH_TEMPLATE);if((0,a.checkTemplateFileName)(r),o){let a=new t.default;a.append("file",e.default.createReadStream(l.fullPath)),a.append("fileName",r),a.append("cliFirstCreateFile","true"),y.default.log(`Upload asset file: ${r}`);let s=await (0,i.uploadFile)(this.themeId,a,{headers:a.getHeaders()});y.default.log(`Update file (${r}) checksum: ${s.fileContentChecksum}`),this.uploader.checksums.set(r,s.fileContentChecksum)}else{y.default.log(`Create file: ${r}`);let e=await (0,i.createFile)(this.themeId,{fileName:r,fileContent:l.fileContent,cliFirstCreateFile:!0});y.default.log(`Update file (${r}) checksum: ${e.fileContentChecksum}`),this.uploader.checksums.set(r,e.fileContentChecksum)}}async ensureDevelopmentTheme(){let{id:e,name:t}=await d.default.findOrCreate(this.themeId);if(e)this.themeId=e,l.default.developmentThemeId=e,l.default.developmentThemeName=t;else throw new m.AbortError(s.ERRORS.THEME_ID_NOT_EXIST)}async uploadThemeFiles(){await this.uploader.upload(this.themeId,o.EThemeStatus.Development)}constructor(e,t,i,a=process.cwd()){super("theme:serve:update"),w(this,"cwd",void 0),w(this,"themeId",void 0),w(this,"queue",void 0),w(this,"editorSync",void 0),w(this,"updateQueue",void 0),w(this,"updateMode","initialize"),w(this,"includeFilter",void 0),w(this,"ignoreFilter",void 0),w(this,"uploader",void 0),this.cwd=a,this.themeId=l.default.developmentThemeId,this.queue=new u.default({concurrency:4}),this.editorSync=e,this.updateQueue=null,this.includeFilter=t.include,this.ignoreFilter=t.ignore,this.uploader=i}}
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"default",{enumerable:!0,get:()=>p});const e=f(require("progress")),t=f(require("fast-glob")),i=f(require("fs-extra")),l=f(require("form-data")),s=require("./api"),a=require("../../utils/error"),r=f(require("../../utils/colors")),n=f(require("./file")),u=f(require("./checksum")),c=require("./types"),o=f(require("../../utils/tiny-queue")),h=require("./utils"),d=f(require("../../utils/winston"));function m(e,t,i){return t in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}function f(e){return e&&e.__esModule?e:{default:e}}class p{themeFiles(){let e=t.default.sync(["config/**/*","layout/**/*","locales/**/*","sections/**/*","snippets/**/*","templates/**/*","assets/**/*"],{cwd:this.cwd,onlyFiles:!0,unique:!0});return e.map(e=>new n.default(e,this.cwd))}staticAssetFiles(){let e=t.default.sync(["assets/**/*"],{cwd:this.cwd,onlyFiles:!0,unique:!0});return e.map(e=>new n.default(e,this.cwd))}diffThemeFiles(){return this.themeFiles().filter(e=>!this.checksums.has(e))}get localeFileChecksums(){return this.themeFiles().reduce((e,t)=>(e[t.fileName]=t.checksum,e),{})}upload(t,i=c.EThemeStatus.Development,l={progressFormat:r.default.cyan("[:bar] :percent")}){let s=new a.ErrorStash;return new Promise(async(n,u)=>{d.default.log("Fetching theme checksums..."),await this.fetchChecksums(t),await this.deleteFiles(t);let c=this.themeFiles(),o=!1,m=(()=>{if(l.silent)return;let t=l.progressFormat||r.default.cyan("[:bar] :percent");e.default.prototype.setTotal=function(e){this.total=e};let i=new e.default(t,{complete:"=",incomplete:" ",total:0,width:50,clear:!0,...l.progressBarOptions});return i})(),f=!1,F=async e=>{if(f||!o){e();return}d.default.log(`Set theme (${t}) upload completed...`),await p.setUploadCompleted(t,i),f=!0,e()};this.queue.on("all-done",async()=>{d.default.log("All task queue is all done!"),s.printAll(),await F(()=>n())}),this.queue.on("error",async e=>{if(d.default.logError(e),e instanceof a.ValidatorError)s.concat(e.errors);else{console.log(),null==m||m.terminate(),s.printAll();let t=e instanceof a.AbortError?e:new a.AbortError(e.message);await F(()=>{u(t),(0,h.handleError)(t)})}}),this.queue.on("success",()=>{o=!0,l.silent||null==m||m.tick()});let w=c.filter(e=>this.uploadable(e)).filter(e=>e.isConfigSchemaFile).map(e=>async()=>{await p.createFile(t,e)}),g=c.filter(e=>this.uploadable(e)).filter(e=>".html"===e.extName).map(e=>async()=>{await p.createFile(t,e)}),y=c.filter(e=>this.uploadable(e)).filter(e=>".json"===e.extName&&!e.isConfigFile).map(e=>async()=>{await p.createFile(t,e)}),q=c.filter(e=>this.uploadable(e)).filter(e=>e.isConfigFile&&!e.isConfigSchemaFile).map(e=>async()=>{await p.createFile(t,e)}),C=this.staticAssetFiles().filter(e=>this.uploadable(e)).map(e=>async()=>{await p.createFile(t,e)}),k=[...w,...g,...y,...q,...C];this.queue.addAll(k),0===k.length&&n(),null==m||m.setTotal(this.queue.size)})}uploadable(e){return!this.ignoreOperation(e.fileName)&&!!e.isExist&&this.checksums.fileHasChanged(e)}static async createFile(e,t){let a=t.fileName.startsWith("assets/");if((0,h.checkTemplateFileName)(t.fileName),a&&t.isImageType){let a=new l.default;a.append("file",i.default.createReadStream(t.fullPath)),a.append("fileName",t.fileName),a.append("cliFirstCreateFile","true"),await (0,s.uploadFile)(e,a,{headers:a.getHeaders()})}else await (0,s.createFile)(e,{fileName:t.fileName,fileContent:t.fileContent,cliFirstCreateFile:!0})}async fetchChecksums(e){try{let t=await (0,s.getThemeFileList)(e);t.files.forEach(e=>{e.fileContentChecksum&&this.checksums.set(e.fileName,e.fileContentChecksum)})}catch(e){}}async deleteFiles(e){if(!this.isDeleteFile)return;d.default.log("Deleting remote theme files...");let t=this.checksums.keys(),i=this.themeFiles().map(e=>e.fileName),l=t.map(e=>new n.default(e,this.cwd)).filter(e=>!i.includes(e.fileName)).filter(e=>!this.ignoreOperation(e.fileName));l.length>0&&await this.enqueueDeletes(l,e)}async enqueueDeletes(e,t){return new Promise((i,l)=>{this.queue.on("all-done",i),this.queue.on("error",l),this.queue.addAll(e.map(e=>async()=>{await this.del(e,t)}))})}ignoreOperation(e){return this.ignoreFilter.match(e)||!this.includeFilter.match(e)}async del(e,t){await (0,s.deleteFile)(t,{fileName:e.fileName,cliFirstCreateFile:!0}),this.checksums.has(e)&&this.checksums.delete(e)}static async createNewTheme(e){let t=await (0,s.createNewThemeOrCompleteUpload)({themeName:e});if(t.themeId)return t.themeId}static async setUploadCompleted(e,t){let i=await (0,s.createNewThemeOrCompleteUpload)({themeId:e,status:t,completed:!0});if(i.themeId)return i.themeId}constructor(e,t,i){m(this,"cwd",void 0),m(this,"queue",void 0),m(this,"checksums",void 0),m(this,"includeFilter",void 0),m(this,"ignoreFilter",void 0),m(this,"isDeleteFile",void 0),this.cwd=i,this.queue=new o.default({maxRetry:3,concurrency:4}),this.checksums=new u.default,this.includeFilter=e.include,this.ignoreFilter=e.ignore,this.isDeleteFile=t}}
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"default",{enumerable:!0,get:()=>p});const e=f(require("progress")),t=f(require("fast-glob")),i=f(require("fs-extra")),l=f(require("form-data")),s=require("./api"),a=require("../../utils/error"),r=f(require("../../utils/colors")),n=f(require("./file")),u=f(require("./checksum")),c=require("./types"),o=f(require("../../utils/tiny-queue")),h=require("./utils"),d=f(require("../../utils/winston"));function m(e,t,i){return t in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}function f(e){return e&&e.__esModule?e:{default:e}}class p{themeFiles(){let e=t.default.sync(["config/**/*","layout/**/*","locales/**/*","sections/**/*","snippets/**/*","templates/**/*","assets/**/*"],{cwd:this.cwd,onlyFiles:!0,unique:!0});return e.map(e=>new n.default(e,this.cwd))}staticAssetFiles(){let e=t.default.sync(["assets/**/*"],{cwd:this.cwd,onlyFiles:!0,unique:!0});return e.map(e=>new n.default(e,this.cwd))}diffThemeFiles(){return this.themeFiles().filter(e=>!this.checksums.has(e))}get localeFileChecksums(){return this.themeFiles().reduce((e,t)=>(e[t.fileName]=t.checksum,e),{})}upload(t,i=c.EThemeStatus.Development,l={progressFormat:r.default.cyan("[:bar] :percent")}){let s=new a.ErrorStash;return new Promise(async(n,u)=>{d.default.log("Fetching theme checksums..."),await this.fetchChecksums(t),await this.deleteFiles(t);let c=this.themeFiles(),o=!1,m=(()=>{if(l.silent)return;let t=l.progressFormat||r.default.cyan("[:bar] :percent");e.default.prototype.setTotal=function(e){this.total=e};let i=new e.default(t,{complete:"=",incomplete:" ",total:0,width:50,clear:!0,...l.progressBarOptions});return i})(),f=!1,F=async e=>{if(f||!o){e();return}d.default.log(`Set theme (${t}) upload completed...`),await p.setUploadCompleted(t,i),f=!0,e()};this.queue.on("all-done",async()=>{d.default.log("All task queue is all done!"),s.printAll(),await F(()=>n())}),this.queue.on("error",async e=>{if(d.default.logError(e),e instanceof a.ValidatorError)s.concat(e.errors);else{console.log(),null==m||m.terminate(),s.printAll();let t=e instanceof a.AbortError?e:new a.AbortError(e.message);await F(()=>{u(t),(0,h.handleError)(t)})}}),this.queue.on("success",()=>{o=!0,l.silent||null==m||m.tick()});let w=c.filter(e=>this.uploadable(e)).filter(e=>e.isConfigSchemaFile).map(e=>async()=>{await p.createFile(t,e)}),g=c.filter(e=>this.uploadable(e)).filter(e=>".html"===e.extName).map(e=>async()=>{await p.createFile(t,e)}),y=c.filter(e=>this.uploadable(e)).filter(e=>".json"===e.extName&&!e.isConfigFile).map(e=>async()=>{await p.createFile(t,e)}),q=c.filter(e=>this.uploadable(e)).filter(e=>e.isConfigFile&&!e.isConfigSchemaFile).map(e=>async()=>{await p.createFile(t,e)}),C=this.staticAssetFiles().filter(e=>this.uploadable(e)).map(e=>async()=>{await p.createFile(t,e)}),k=[...w,...g,...y,...q,...C];this.queue.addAll(k),0===k.length&&n(),null==m||m.setTotal(this.queue.size)})}uploadable(e){return!this.ignoreOperation(e.fileName)&&!!e.isExist&&this.checksums.fileHasChanged(e)}static async createFile(e,t){let a=t.fileName.startsWith("assets/");if((0,h.checkTemplateFileName)(t.fileName),a){let a=new l.default;a.append("file",i.default.createReadStream(t.fullPath)),a.append("fileName",t.fileName),a.append("cliFirstCreateFile","true"),await (0,s.uploadFile)(e,a,{headers:a.getHeaders()})}else await (0,s.createFile)(e,{fileName:t.fileName,fileContent:t.fileContent,cliFirstCreateFile:!0})}async fetchChecksums(e){try{let t=await (0,s.getThemeFileList)(e);t.files.forEach(e=>{e.fileContentChecksum&&this.checksums.set(e.fileName,e.fileContentChecksum)})}catch(e){}}async deleteFiles(e){if(!this.isDeleteFile)return;d.default.log("Deleting remote theme files...");let t=this.checksums.keys(),i=this.themeFiles().map(e=>e.fileName),l=t.map(e=>new n.default(e,this.cwd)).filter(e=>!i.includes(e.fileName)).filter(e=>!this.ignoreOperation(e.fileName));l.length>0&&await this.enqueueDeletes(l,e)}async enqueueDeletes(e,t){return new Promise((i,l)=>{this.queue.on("all-done",i),this.queue.on("error",l),this.queue.addAll(e.map(e=>async()=>{await this.del(e,t)}))})}ignoreOperation(e){return this.ignoreFilter.match(e)||!this.includeFilter.match(e)}async del(e,t){await (0,s.deleteFile)(t,{fileName:e.fileName,cliFirstCreateFile:!0}),this.checksums.has(e)&&this.checksums.delete(e)}static async createNewTheme(e){let t=await (0,s.createNewThemeOrCompleteUpload)({themeName:e});if(t.themeId)return t.themeId}static async setUploadCompleted(e,t){let i=await (0,s.createNewThemeOrCompleteUpload)({themeId:e,status:t,completed:!0});if(i.themeId)return i.themeId}constructor(e,t,i){m(this,"cwd",void 0),m(this,"queue",void 0),m(this,"checksums",void 0),m(this,"includeFilter",void 0),m(this,"ignoreFilter",void 0),m(this,"isDeleteFile",void 0),this.cwd=i,this.queue=new o.default({maxRetry:3,concurrency:4}),this.checksums=new u.default,this.includeFilter=e.include,this.ignoreFilter=e.ignore,this.isDeleteFile=t}}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shoplineos/cli",
3
- "version": "1.3.0",
3
+ "version": "1.3.2",
4
4
  "description": "A CLI tool to build for the Shopline platform",
5
5
  "bin": {
6
6
  "sl": "./bin/index.js"