From 7da82b41ae2972b993157046059613882e9b3239 Mon Sep 17 00:00:00 2001 From: ChenYong Date: Wed, 19 Aug 2020 16:23:11 +0800 Subject: [PATCH] exposing more errors; alpha release --- .github/workflows/npm-publish.yaml | 21 ++++++++++++++ .github/workflows/upload.yaml | 45 ++++++++++++++++++++++++++++++ css/style.css | 1 + example/cirru/if.cirru | 2 +- package.json | 4 +-- src/abstract.coffee | 1 + src/expression/methods.coffee | 4 +++ src/main.coffee | 7 +++-- src/tag/common.coffee | 3 ++ yarn.lock | 8 +++--- 10 files changed, 87 insertions(+), 9 deletions(-) create mode 100644 .github/workflows/npm-publish.yaml create mode 100644 .github/workflows/upload.yaml diff --git a/.github/workflows/npm-publish.yaml b/.github/workflows/npm-publish.yaml new file mode 100644 index 0000000..7687181 --- /dev/null +++ b/.github/workflows/npm-publish.yaml @@ -0,0 +1,21 @@ +name: npm publish + +on: + release: + types: [created] + +jobs: + publish-npm: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v1 + with: + node-version: 12 + registry-url: https://registry.npmjs.org/ + + - run: yarn && yarn compile + + - run: npm publish + env: + NODE_AUTH_TOKEN: ${{secrets.npm_token}} diff --git a/.github/workflows/upload.yaml b/.github/workflows/upload.yaml new file mode 100644 index 0000000..e3c0d4b --- /dev/null +++ b/.github/workflows/upload.yaml @@ -0,0 +1,45 @@ +name: Upload Assets + +on: + pull_request: {} + push: + branches: + - master + +jobs: + upload-assets: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Use Node.js + uses: actions/setup-node@v1 + + - name: Get yarn cache + id: yarn-cache + run: echo "::set-output name=dir::$(yarn cache dir)" + + - uses: actions/cache@v1 + with: + path: ${{ steps.yarn-cache.outputs.dir }} + key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} + restore-keys: | + ${{ runner.os }}-yarn- + + - run: yarn && yarn release + name: Build web assets + + - name: Deploy to server + id: deploy + uses: Pendect/action-rsyncer@v1.1.0 + env: + DEPLOY_KEY: ${{secrets.rsync_private_key}} + with: + flags: "-avzr --progress" + options: "" + ssh_options: "" + src: "dist/*" + dest: "rsync-user@fe.jimu.io:/web-assets/repo/${{ github.repository }}" + + - name: Display status from deploy + run: echo "${{ steps.deploy.outputs.status }}" diff --git a/css/style.css b/css/style.css index 715ce9f..cfa16f0 100644 --- a/css/style.css +++ b/css/style.css @@ -81,6 +81,7 @@ body { margin: 0px 6px; border-radius: 3px; font-family: Source Code Pro, Menlo, Consolas, monospace; + white-space: pre; } .test .button { diff --git a/example/cirru/if.cirru b/example/cirru/if.cirru index 047fc5a..8a9856a 100644 --- a/example/cirru/if.cirru +++ b/example/cirru/if.cirru @@ -1,4 +1,4 @@ @if (@ switcher) div $ = right - div $ = wrong \ No newline at end of file + div $ = wrong diff --git a/package.json b/package.json index 38fca3c..3c3ef29 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cirru-html", - "version": "0.2.2", + "version": "0.2.3-a1", "description": "Template engine that converts Cirru to HTML", "main": "js/index.js", "scripts": { @@ -20,7 +20,7 @@ "author": "jiyinyiyong", "license": "MIT", "dependencies": { - "cirru-parser": "^0.10.7" + "cirru-parser": "^0.10.8-a1" }, "repository": { "type": "git", diff --git a/src/abstract.coffee b/src/abstract.coffee index a023c5d..3d65bd1 100644 --- a/src/abstract.coffee +++ b/src/abstract.coffee @@ -21,6 +21,7 @@ exports.makeAbstract = (syntaxTree) -> args = syntaxTree[1..] unless func? and func.length > 0 and typeof func is 'string' + console.error("evaluation tree:", JSON.stringify(syntaxTree)) throw new Error "(#{stringify func}) is not valid as func" if func[0] is '@' diff --git a/src/expression/methods.coffee b/src/expression/methods.coffee index 266de52..e3b29c3 100644 --- a/src/expression/methods.coffee +++ b/src/expression/methods.coffee @@ -1,6 +1,7 @@ exports.Expression = class constructor: (tree) -> + @tree = tree @func = tree[0][1..] @args = tree[1..] @@ -9,4 +10,7 @@ exports.Expression = class render: (data) -> list = @args.map (item) -> data[item] + if not data[@func]? + console.error "Evaludatiing tree", JSON.stringify(@tree) + throw new Error('Unknown method') data[@func] list... \ No newline at end of file diff --git a/src/main.coffee b/src/main.coffee index 292175a..eb695c2 100644 --- a/src/main.coffee +++ b/src/main.coffee @@ -13,8 +13,11 @@ document.body.onclick = (event) -> parent = event.target.parentElement file = parent.querySelector('.file').value data = parent.querySelector('.data').value - html = render file, (eval "(#{data})") - parent.querySelector('.result').value = html + try + html = render file, (eval "(#{data})") + parent.querySelector('.result').value = html + catch err + parent.querySelector('.result').value = err.stack buttons = document.querySelectorAll('.button') for button in buttons diff --git a/src/tag/common.coffee b/src/tag/common.coffee index 5a22c97..652c08e 100644 --- a/src/tag/common.coffee +++ b/src/tag/common.coffee @@ -45,6 +45,9 @@ exports.Tag = class CommonTag continue func = item[0] + if not func? + console.error 'args:', @args, 'func:', @func + throw new Error("Empty in args") matchAttr = func.match /^:([\w-]+)/ if matchAttr? prop = item[1..] diff --git a/yarn.lock b/yarn.lock index 0d9253e..fc322c0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -778,10 +778,10 @@ cipher-base@^1.0.0, cipher-base@^1.0.1, cipher-base@^1.0.3: inherits "^2.0.1" safe-buffer "^5.0.1" -cirru-parser@^0.10.7: - version "0.10.7" - resolved "https://registry.npmjs.org/cirru-parser/-/cirru-parser-0.10.7.tgz#0f6fe6f3e343b145fbd30c3505e1adb8be349e32" - integrity sha1-D2/m8+NDsUX70ww1BeGtuL40njI= +cirru-parser@^0.10.8-a1: + version "0.10.8-a1" + resolved "https://registry.npmjs.org/cirru-parser/-/cirru-parser-0.10.8-a1.tgz#238fc9d0d2d9254cfd25b198ffb29ab09b1e6ab0" + integrity sha512-x8lYYXK3Lvd8nXlsOpuW4Q8KNmlwuEw1JTIJFg6nucem/tD/b3eftVzudhEJke1Amav6b7xa86ZhHiDMXDMrPw== cirru-script-loader@0.5.5: version "0.5.5"