Browse Source

Adopt to ts and version bump

Joachim M. Giæver 3 years ago
parent
commit
bef017e6f9
3 changed files with 43 additions and 28 deletions
  1. 41 26
      snap/snapcraft.yaml
  2. 1 1
      src/helper/env-wrapper
  3. 1 1
      src/helper/functions

+ 41 - 26
snap/snapcraft.yaml

@@ -1,6 +1,6 @@
 name: zwavejs2mqtt
 name: zwavejs2mqtt
 base: core20
 base: core20
-version: 'v5.0.1'
+version: 'v5.0.2'
 summary: Fully configurable Zwave to MQTT Gateway and Control Panel. 
 summary: Fully configurable Zwave to MQTT Gateway and Control Panel. 
 description: |
 description: |
   - Configurable Zwave to Mqtt Gateway
   - Configurable Zwave to Mqtt Gateway
@@ -30,8 +30,9 @@ apps:
     restart-condition: always
     restart-condition: always
     environment:
     environment:
       STORE_DIR: $SNAP_DATA
       STORE_DIR: $SNAP_DATA
+      ZWAVEJS_EXTERNAL_CONFIG: $SNAP_DATA/.ext-config
       DAEMONIZED: 1
       DAEMONIZED: 1
-    command: usr/lib/zwavejs2mqtt/bin/www
+    command: lib/node_modules/yarn/bin/yarn run
     command-chain:
     command-chain:
       - helper/env-wrapper
       - helper/env-wrapper
     plugs:
     plugs:
@@ -43,7 +44,9 @@ apps:
   exec:
   exec:
     environment:
     environment:
       STORE_DIR: $SNAP_DATA
       STORE_DIR: $SNAP_DATA
-    command: usr/lib/zwavejs2mqtt/bin/www
+      ZWAVEJS_EXTERNAL_CONFIG: $SNAP_DATA/.ext-config
+      #command: lib/node_modules/zwavejs2mqtt/bin/www.ts
+    command: lib/node_modules/yarn/bin/yarn --cwd $SNAP/lib/node_modules/zwavejs2mqtt --global-folder $SNAP/lib/node_modules/npm/node_modules start
     command-chain:
     command-chain:
       - helper/env-wrapper
       - helper/env-wrapper
     plugs:
     plugs:
@@ -62,45 +65,54 @@ apps:
     command: bin/restart
     command: bin/restart
 
 
 layout:
 layout:
-  $SNAP/usr/lib/zwavejs2mqtt/node_modules/@zwave-js/config/config:
-    bind: $SNAP/usr/lib/zwavejs2mqtt/node_modules/@zwave-js/config/config
+  $SNAP/lib/node_modules/zwavejs2mqtt/node_modules/@zwave-js/config/config:
+    bind: $SNAP/lib/node_modules/zwavejs2mqtt/node_modules/@zwave-js/config/config
 
 
 parts:
 parts:
   zwavejs2mqtt:
   zwavejs2mqtt:
     after: [nodejs]
     after: [nodejs]
-    plugin: npm
+    plugin: dump
     source: https://github.com/zwave-js/zwavejs2mqtt.git
     source: https://github.com/zwave-js/zwavejs2mqtt.git
     #source-branch: "fix#1274"
     #source-branch: "fix#1274"
     source-tag: $SNAPCRAFT_PROJECT_VERSION
     source-tag: $SNAPCRAFT_PROJECT_VERSION
-    npm-node-version: '15.14.0'
     build-packages:
     build-packages:
       - gcc
       - gcc
       - build-essential
       - build-essential
-    stage-snaps:
-      - jq
-    stage-packages:
-      - git
-      - udev
-      - rsync
     override-build: |
     override-build: |
-      set -ex
+      set -x
       if [ -n "${http_proxy-}" ]; then
       if [ -n "${http_proxy-}" ]; then
         export GLOBAL_AGENT_HTTP_PROXY="${http_proxy}"
         export GLOBAL_AGENT_HTTP_PROXY="${http_proxy}"
         export GLOBAL_AGENT_HTTPS_PROXY="${http_proxy}"
         export GLOBAL_AGENT_HTTPS_PROXY="${http_proxy}"
       fi
       fi
-      npm config set unsafe-perm true
-      npm install npm@latest detect-libc
-      npm run build
-      chmod +x $SNAPCRAFT_PART_BUILD/bin/www
-      cp -rf $SNAPCRAFT_PART_BUILD $SNAPCRAFT_PART_INSTALL/usr/lib/zwavejs2mqtt
-    stage:
-      - -usr/lib/zwavejs2mqtt/kubernetes
-      - -usr/lib/zwavejs2mqtt/kustomization.yaml
-      - -usr/lib/zwavejs2mqtt/docker
-      - -usr/lib/zwavejs2mqtt/.dockerignore
-      - -usr/lib/zwavejs2mqtt/.markdown*
+      yarn install
+      yarn run build \
+        && mkdir -p $SNAPCRAFT_PART_INSTALL/lib/node_modules \
+        && cp --archive --link --no-dereference $SNAPCRAFT_PART_BUILD \
+          $SNAPCRAFT_PART_INSTALL/lib/node_modules/zwavejs2mqtt \
     organize:
     organize:
-      usr/lib/zwavejs2mqtt/node_modules/@zwave-js/config/config: snap/zwave-js/config
+      lib/node_modules/zwavejs2mqtt/node_modules/@zwave-js/config/config: snap/zwave-js/config
+      lib/node_modules/zwavejs2mqtt/dist: lib/node_modules/zwavejs2mqtt/server/dist
+      lib/node_modules/zwavejs2mqtt/views: lib/node_modules/zwavejs2mqtt/server/views
+    filesets:
+      zwavejs2mqtt-include:
+        - lib/node_modules/zwavejs2mqtt/.git
+        - lib/node_modules/zwavejs2mqtt/LICENSE
+        - lib/node_modules/zwavejs2mqtt/*.md
+        - lib/node_modules/zwavejs2mqtt/node_modules
+        - lib/node_modules/zwavejs2mqtt/server
+        - lib/node_modules/zwavejs2mqtt/package.json
+        - lib/node_modules/zwavejs2mqtt/yarn.lock
+    stage:
+      - snap
+      - $zwavejs2mqtt-include
+  dependencies:
+    plugin: nil
+    stage-snaps:
+      - jq
+    stage-packages:
+      - git
+      - udev
+      - rsync
   nodejs:
   nodejs:
     plugin: dump
     plugin: dump
     source:
     source:
@@ -110,6 +122,9 @@ parts:
     stage-packages:
     stage-packages:
       - on armhf: 
       - on armhf: 
         - libatomic1
         - libatomic1
+    override-stage: |
+      npm install --global yarn
+      snapcraftctl stage
     organize:
     organize:
       '*.md' : nodejs/
       '*.md' : nodejs/
       LICENSE : nodejs/
       LICENSE : nodejs/

+ 1 - 1
src/helper/env-wrapper

@@ -81,7 +81,7 @@ export SERVER_SSL=$(snapctl get server.ssl)
 export SERVER_HOST=$(snapctl get server.host)
 export SERVER_HOST=$(snapctl get server.host)
 export SERVER_PORT=$(snapctl get server.port)
 export SERVER_PORT=$(snapctl get server.port)
 
 
-export GIT_DIR="${SNAP}/usr/lib/zwavejs2mqtt/.git"
+export GIT_DIR="${SNAP}/lib/node_modules/zwavejs2mqtt/.git"
 
 
 export HTTPS="${SERVER_SSL}"
 export HTTPS="${SERVER_SSL}"
 
 

+ 1 - 1
src/helper/functions

@@ -1,7 +1,7 @@
 #!/usr/bin/env bash
 #!/usr/bin/env bash
 
 
 function ensure_zwavejs_config {
 function ensure_zwavejs_config {
-    ZWAVE_JS_CONF="${SNAP}/usr/lib/zwavejs2mqtt/node_modules/@zwave-js/config/config"
+    ZWAVE_JS_CONF="${SNAP}/lib/node_modules/zwavejs2mqtt/node_modules/@zwave-js/config/config"
     if [ "$(find ${ZWAVE_JS_CONF} -maxdepth 0 -empty -exec echo empty \;)" == "empty" ]; then
     if [ "$(find ${ZWAVE_JS_CONF} -maxdepth 0 -empty -exec echo empty \;)" == "empty" ]; then
         logger "Config directory is empty, copying data from ${SNAP}/snap/zwave-js/config"
         logger "Config directory is empty, copying data from ${SNAP}/snap/zwave-js/config"
         rsync -raz "${SNAP}/snap/zwave-js/config" "${ZWAVE_JS_CONF}/.."
         rsync -raz "${SNAP}/snap/zwave-js/config" "${ZWAVE_JS_CONF}/.."