0.0.25 • Published 2 months ago

ecforce-theme-cli v0.0.25

Weekly downloads
-
License
ISC
Repository
-
Last release
2 months ago

Getting started

Installation

npm i -D ecforce-theme-cli

Configuration

Put ecforce.config.json to project root.

{
  "basicAuthUsername": "BASIC_AUTH_USERNAME",
  "basicAuthPassword": "BASIC_AUTH_PASSWORD",
  "username": "USERNAME",
  "password": "PASSWORD",
  "baseUrl": "https://HOSTNAME/",
  "themeId": "THEME_ID"
}

Commands

Sync

npx ecforce-theme-cli sync

Options

  • -w, --watch
    watch files

Pull

npx ecforce-theme-cli pull [theme id]

Preview

npx ecforce-theme-cli preview [theme id]

Auto reload script

For theme

{% if theme_preview_mode %}
  <script>
    const connectWSServer = () => {
      const ws = new WebSocket('ws://localhost:8080')
      ws.addEventListener('message', message => {
        const data = JSON.parse(message.data)
        if(data.type === 'update'){
          location.reload()
        }
      })
    }

    let localHosted = null
    new MutationObserver((mutations) => {
      for(const mutation of mutations){
        for(const node of mutation.addedNodes){
          if(node.nodeName !== 'SCRIPT') break
          if(node.src.includes('/ec_force/assets/')){
            if(localHosted === null){
              const xhr = new XMLHttpRequest()
              xhr.open('HEAD', 'http://localhost:8088/', false)
              try {
                xhr.send()
                if(xhr.readyState === 4){
                  localHosted = true
                  connectWSServer()
                } else {
                  throw new Error()
                }
              } catch(err) {
                localHosted = false
              }
            }
            if(localHosted){
              node.src = node.src.replace(/.*\/ec_force\/assets\//, 'http://localhost:8088/')
            }
          }
          return
        }
      }
    }).observe(document, {childList: true, subtree: true})
    document.addEventListener('DOMContentLoaded', () => {
      document.querySelectorAll('link').forEach(link => {
        if(localHosted === true && link.rel === 'stylesheet' && link.href.includes('/ec_force/assets/')){
          if(localHosted){
            link.href = link.href.replace(/.*\/ec_force\/assets\//, 'http://localhost:8088/')
          }
        }
      })
    })
  </script>
{% endif %}

For LP

{%%}
<script>
  const connectWSServer = () => {
    const ws = new WebSocket('ws://localhost:8080')
    ws.addEventListener('message', message => {
      const data = JSON.parse(message.data)
      if(data.type === 'update'){
        location.reload()
      }
    })
  }
</script>
0.0.25

2 months ago

0.0.23

3 months ago

0.0.24

3 months ago

0.0.20

4 months ago

0.0.21

4 months ago

0.0.22

4 months ago

0.0.17

4 months ago

0.0.18

4 months ago

0.0.19

4 months ago

0.0.16

4 months ago

0.0.15

4 months ago

0.0.14

6 months ago

0.0.13

6 months ago

0.0.12

6 months ago

0.0.11

6 months ago

0.0.10

6 months ago

0.0.9

6 months ago

0.0.8

6 months ago

0.0.7

6 months ago

0.0.6

6 months ago

0.0.5

6 months ago

0.0.4

6 months ago

0.0.3

6 months ago

0.0.2

6 months ago

0.0.1

6 months ago