From 614aafeec93b095cda34b5afa6f60365b3cc509f Mon Sep 17 00:00:00 2001 From: Richard Marston Date: Wed, 8 Jul 2020 12:55:38 +0200 Subject: [PATCH] Github release workflow --- .github/workflows/release.yaml | 69 ++++++++++++++++++++++++++++++++ .gitignore | 2 + {css => cimmenu/css}/colours.css | 0 {css => cimmenu/css}/layout.css | 0 cimmenu/package-lock.json | 8 ++++ cimmenu/package.json | 1 + cimmenu/rollup.config.js | 4 ++ cimmenu/src/cimmenu.js | 25 ++++++++++++ cimsvg/src/cimsvg.js | 10 ++--- index.html | 43 ++++++++++++++------ index.js | 40 ------------------ package.json | 5 ++- 12 files changed, 147 insertions(+), 60 deletions(-) create mode 100644 .github/workflows/release.yaml rename {css => cimmenu/css}/colours.css (100%) rename {css => cimmenu/css}/layout.css (100%) delete mode 100644 index.js diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..5ed85db --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,69 @@ +name: package build workflow +# https://www.patriksvensson.se/2020/03/creating-release-artifacts-with-github-actions/ +# https://github.community/t5/GitHub-Actions/Using-on-push-tags-ignore-and-paths-ignore-together/td-p/38559 +# https://github.com/softprops/action-gh-release +# https://github.com/actions/download-artifact + +on: + push: + tags: + - 'release-v*' + +jobs: + package: + strategy: + matrix: + node-version: [14.x] + runs-on: ubuntu-latest + name: A job to build the packages + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: NPM + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} + - run: npm install + - run: npm run release --if-present + # TODO: tests need to be rewritten + # since the component files were + # deleted from grid-data + #- run: npm test + - name: UploadIndex + uses: actions/upload-artifact@v2 + with: + name: index + path: ${{ github.workspace }}/index.html + - name: UploadCimsvg + uses: actions/upload-artifact@v2 + with: + name: cimsvglib + path: ${{ github.workspace }}/dist/libcimsvg.js + - name: UploadCimmenu + uses: actions/upload-artifact@v2 + with: + name: cimmenulib + path: ${{ github.workspace }}/dist/libcimmenu.js + - name: UploadRelease + uses: actions/upload-artifact@v2 + with: + name: bundle + path: ${{ github.workspace }}/dist/release.tgz + release: + needs: package + runs-on: ubuntu-latest + steps: + - name: GetArtifact + uses: actions/download-artifact@v2 + - name: Display structure of downloaded files + run: ls -l /home/runner/work/pintura/pintura + - name: Release + uses: softprops/action-gh-release@v1 + with: + files: | + bundle/release.tgz + index/index.html + cimsvglib/* + cimmenulib/* + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.gitignore b/.gitignore index f1256aa..8eae643 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,7 @@ cimmenu/lib/* cimsvg/lib/* +cimmenu/css/bundle.css +cimmenu/cgmes/cgmesIndex.js cimmenu/templates/generated cimmenu/templates/index.js cimmenu/templates/cgmesIndex.js diff --git a/css/colours.css b/cimmenu/css/colours.css similarity index 100% rename from css/colours.css rename to cimmenu/css/colours.css diff --git a/css/layout.css b/cimmenu/css/layout.css similarity index 100% rename from css/layout.css rename to cimmenu/css/layout.css diff --git a/cimmenu/package-lock.json b/cimmenu/package-lock.json index 0380c25..60e10a4 100644 --- a/cimmenu/package-lock.json +++ b/cimmenu/package-lock.json @@ -355,6 +355,14 @@ "rollup-pluginutils": "^2.5.0" } }, + "rollup-plugin-string": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/rollup-plugin-string/-/rollup-plugin-string-3.0.0.tgz", + "integrity": "sha512-vqyzgn9QefAgeKi+Y4A7jETeIAU1zQmS6VotH6bzm/zmUQEnYkpIGRaOBPY41oiWYV4JyBoGAaBjYMYuv+6wVw==", + "requires": { + "rollup-pluginutils": "^2.4.1" + } + }, "rollup-pluginutils": { "version": "2.8.2", "resolved": "https://registry.npmjs.org/rollup-pluginutils/-/rollup-pluginutils-2.8.2.tgz", diff --git a/cimmenu/package.json b/cimmenu/package.json index ee86206..3cf2cf2 100644 --- a/cimmenu/package.json +++ b/cimmenu/package.json @@ -25,6 +25,7 @@ "rollup": "^2.18.0", "rollup-plugin-handlebars-plus": "^0.2.5", "rollup-plugin-json": "^4.0.0", + "rollup-plugin-string": "^3.0.0", "xml2js": "^0.4.23" } } diff --git a/cimmenu/rollup.config.js b/cimmenu/rollup.config.js index 27fcb64..0bd8e0a 100644 --- a/cimmenu/rollup.config.js +++ b/cimmenu/rollup.config.js @@ -1,6 +1,7 @@ import babel from "@rollup/plugin-babel"; import json from "rollup-plugin-json"; import handlebars from "rollup-plugin-handlebars-plus"; +import { string } from "rollup-plugin-string"; import replace from "@rollup/plugin-replace"; const global = { @@ -54,6 +55,9 @@ export default { exclude: 'node_modules/**', "logIfDebug": logIfDebugFunction }), + string({ + include: [ "css/*.css" ], + }), json() ] }; diff --git a/cimmenu/src/cimmenu.js b/cimmenu/src/cimmenu.js index 36ee447..0a8a6a1 100644 --- a/cimmenu/src/cimmenu.js +++ b/cimmenu/src/cimmenu.js @@ -22,6 +22,7 @@ import contextmenu from "./contextmenu.js"; import Menu from "./react-menu.js"; const e = React.createElement; import cgmes from '../cgmes/cgmesIndex.js'; +import css from "../css/bundle.css"; class cimmenu { @@ -41,6 +42,30 @@ class cimmenu { cimmenu.setCimmenu(this); this.cimsvg = false; this.contextMenu = new contextmenu(this.menuNode.querySelector("#context-menu"), "context-menu"); + this.addCss(leftnode, css); + } + + addCss(htmlNode, css) { + let docu = svg.ownerDocument; + let pinturaStyleTags = docu.querySelectorAll("style.pintura"); + + if (pinturaStyleTags.length < 1) { + this.style = docu.createElement("style"); + this.style.type = "text/css"; + this.style.classList.add("pintura"); + this.style.setAttribute("title", "cimsvg-style"); + + let head = docu.head; + if(head === undefined) { + console.error("Failed to get head from document."); + } + docu.head.appendChild(this.style); + if (this.style.styleSheet) { + this.style.styleSheet.cssText = css; + } else { + this.style.appendChild(docu.createTextNode(css)); + } + } } cimsvgFunction(func) { diff --git a/cimsvg/src/cimsvg.js b/cimsvg/src/cimsvg.js index bf74d5d..23425bd 100644 --- a/cimsvg/src/cimsvg.js +++ b/cimsvg/src/cimsvg.js @@ -196,12 +196,12 @@ class cimsvg { addPinturaStyle(svg, css) { let docu = svg.ownerDocument; let pinturaStyleTags = docu.querySelectorAll("style.pintura"); - this.style = docu.createElement("style"); - this.style.type = "text/css"; - this.style.classList.add("pintura"); - this.style.setAttribute("title", "cimsvg-style"); - if (pinturaStyleTags.length < 1) { + this.style = docu.createElement("style"); + this.style.type = "text/css"; + this.style.classList.add("pintura"); + this.style.setAttribute("title", "cimsvg-style"); + let head = docu.head; if(head === undefined) { console.error("Failed to get head from document."); diff --git a/index.html b/index.html index 5f31655..2f4b3c1 100644 --- a/index.html +++ b/index.html @@ -20,8 +20,6 @@ Pintura - - @@ -88,16 +86,35 @@ - + var currentCimmenu = libcimmenu.currentCimmenu; + var currentCimsvg = libcimsvg.currentCimsvg; + var cimmenuInstance = new libcimmenu.cimmenu(document.getElementById('left-panel'), document.getElementById('right-panel')); + var cimsvg = libcimsvg.cimsvg; + var cimsvgInstance = new cimsvg( + document.getElementById("svg"), + ); + cimsvgInstance.setCimmenu(cimmenuInstance); + cimmenuInstance.setCimsvg(cimsvgInstance); + + let urlTokens = window.location.href.split("?"); + let pairs = urlTokens.slice(1); + let params = {}; + for (let index in pairs) { + let pair = pairs[index]; + let param = pair.split("="); + if (param.length === 2){ + params[param[0]] = param[1]; + } + } + if ("uri" in params){ + let uri=params["uri"]; + cimsvgInstance.downloadUri(uri); + } + let body = document.querySelector("body"); + if (body !== undefined) { + cimsvgInstance.addEventListeners(body); + cimmenuInstance.addEventListeners(document); + } + diff --git a/index.js b/index.js deleted file mode 100644 index 5b138e9..0000000 --- a/index.js +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright © 2016-2017, RWTH Aachen University - * Authors: Richard Marston - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * A copy of the GNU General Public License is in the LICENSE file - * in the top level directory of this source tree. - */ - -let urlTokens = window.location.href.split("?"); -let pairs = urlTokens.slice(1); -let params = {}; -for (let index in pairs) { - let pair = pairs[index]; - let param = pair.split("="); - if (param.length === 2){ - params[param[0]] = param[1]; - } -} -if ("uri" in params){ - let uri=params["uri"]; - currentCimsvg().downloadUri(uri); -} - -let body = document.querySelector("body"); -if (body !== undefined) { - currentCimsvg().addEventListeners(body); - currentCimmenu().addEventListeners(document); -} - - diff --git a/package.json b/package.json index f820af6..274620f 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "cimmenu": "cd cimmenu && npm install && npm run build", "libs": "npm run cimsvg && npm run cimmenu", "makeDist": "cp -a cimmenu/lib/*.js cimsvg/lib/*.js dist", - "build-tasks": "npm run makeDirs && npm run libs && npm run makeDist", + "build-tasks": "cat cimmenu/css/layout.css cimmenu/css/colours.css cimsvg/css/svg.css > cimmenu/css/bundle.css && npm run makeDirs && npm run libs && npm run makeDist", "build": "npm config set mode production && npm run build-tasks", "build-dev": "export ROLLUP_FLAGS=' --sourcemap inline --environment BUILD:development'; export ESLINT_FLAGS=' --rule no-console:off '; npm config set mode development && npm run build-tasks", "initializeTests": "node node_modules/jasmine/bin/jasmine init", @@ -22,7 +22,8 @@ "lintfix": "eslint --fix index.js cimsvg/*.js cimsvg/src/*.js cimmenu/*.js cimmenu/src/*.js ${ESLINT_FLAGS}", "ctlint": "cd cimmenu/templates && eslint -c .eslintrc.js *.js ${ESLINT_FLAGS} && cd ../..", "lint": "eslint index.js cimsvg/*.js cimsvg/src/*.js cimmenu/*.js cimmenu/src/*.js ${ESLINT_FLAGS}", - "mockNpmInstall": "./npm/mockInstall.sh" + "mockNpmInstall": "./npm/mockInstall.sh", + "release": "npm run build && tar zcvf dist/release.tgz index.html dist/libcimsvg.js dist/libcimmenu.js" }, "dependencies": { "@babel/core": "^7.10.3",