afform_html - Use package.json to download Monaco
authorTim Otten <totten@civicrm.org>
Sat, 4 May 2019 03:52:12 +0000 (20:52 -0700)
committerCiviCRM <info@civicrm.org>
Wed, 16 Sep 2020 02:13:18 +0000 (19:13 -0700)
ext/afform/html/bin/add-zip-regex.php [new file with mode: 0755]
ext/afform/html/bin/setup.sh [new file with mode: 0755]
ext/afform/html/package-lock.json [new file with mode: 0644]
ext/afform/html/package.json [new file with mode: 0644]

diff --git a/ext/afform/html/bin/add-zip-regex.php b/ext/afform/html/bin/add-zip-regex.php
new file mode 100755 (executable)
index 0000000..3ec29eb
--- /dev/null
@@ -0,0 +1,37 @@
+#!/usr/bin/php
+<?php
+
+## This script allows you to add to a ZIP file -- while filtering the filename.
+## For example, suppose you want to inject a prefix to put everything in a subdir;
+## match the start of the name (^) and put in the new sub dir:
+##
+## find -type f | add-zip-regex.php myfile.zip :^: 'the-new-sub-dir/'
+
+if (PHP_SAPI !== 'cli') {
+  die("This tool can only be run from command line.");
+}
+
+if (empty($argv[1]) || empty($argv[2])) {
+  die(sprintf("usage: cat files.txt | %s <zipfile> <old-prefix> <new-prefix>\n", $argv[0]));
+}
+
+$zip = new ZipArchive();
+$zip->open($argv[1], ZipArchive::CREATE);
+$zip->addEmptyDir($argv[3]);
+
+$files = explode("\n", file_get_contents('php://stdin'));
+foreach ($files as $file) {
+  if (empty($file)) {
+    continue;
+  }
+  $file = preg_replace(':^\./:', '', $file);
+  $internalName = preg_replace($argv[2], $argv[3], $file);
+  if (file_exists($file) && is_dir($file)) {
+    $zip->addEmptyDir($internalName);
+  }
+  else {
+    $zip->addFile($file, $internalName);
+  }
+}
+
+$zip->close();
diff --git a/ext/afform/html/bin/setup.sh b/ext/afform/html/bin/setup.sh
new file mode 100755 (executable)
index 0000000..ed1e89b
--- /dev/null
@@ -0,0 +1,105 @@
+#!/usr/bin/env bash
+set -e
+
+EXTROOT=$(cd `dirname $0`/..; pwd)
+EXTKEY="org.civicrm.afform-html"
+
+##############################
+function do_help() {
+  echo "usage: $0 [options]"
+  echo "example: $0"
+  echo "  -h     (Help)           Show this help screen"
+  echo "  -D     (Download)       Download dependencies"
+  echo "  -z     (Zip)            Build installable ZIP file"
+}
+
+##############################
+function use_civiroot() {
+  if [ -z "$CIVIROOT" ]; then
+    CIVIROOT=$(cv ev 'echo $GLOBALS["civicrm_root"];')
+    if [ -z "$CIVIROOT" -o ! -d "$CIVIROOT" ]; then
+      do_help
+      echo ""
+      echo "ERROR: invalid civicrm-dir: [$CIVIROOT]"
+      exit
+    fi
+  fi
+}
+
+##############################
+function cleanup() {
+  use_civiroot
+  ## No DAOs or XML build to cleanup
+}
+
+##############################
+function do_download() {
+  pushd "$EXTROOT" >> /dev/null
+    npm install
+  popd >> /dev/null
+}
+
+##############################
+## Build installable ZIP file
+function do_zipfile() {
+  local canary="$EXTROOT/node_modules/monaco-editor/package.json"
+  if [ ! -f "$canary" ]; then
+    echo "Error: File $canary missing. Are you sure the build is ready?"
+    exit 1
+  fi
+
+  local zipfile="$EXTROOT/build/$EXTKEY.zip"
+  [ -f "$zipfile" ] && rm -f "$zipfile"
+  [ ! -d "$EXTROOT/build" ] && mkdir "$EXTROOT/build"
+  pushd "$EXTROOT" >> /dev/null
+    ## Build a list of files to include.
+    ## Put the files into the *.zip, using a $EXTKEY as a prefix.
+    {
+       ## Get any files in the project root, except for dotfiles.
+       find . -mindepth 1 -maxdepth 1 -type f -o -type d | grep -v '^\./\.'
+       ## Get any files in the main subfolders.
+       #find CRM/ ang/ api/ bin/ css/ js/ sql/ sass/ settings/ templates/ tests/ xml/ -type f -o -type d
+       find bin/ xml/ -type f -o -type d
+       ## Get the distributable files for Monaco.
+       find node_modules/monaco-editor/LICENSE node_modules/monaco-editor/min -type f -o -type d
+    } \
+      | grep -v '~$' \
+      | php bin/add-zip-regex.php "$zipfile" ":^:" "$EXTKEY/"
+  popd >> /dev/null
+  echo "Created: $zipfile"
+}
+
+##############################
+## Main
+HAS_ACTION=
+
+while getopts "aDghz" opt; do
+  case $opt in
+    h)
+      do_help
+      HAS_ACTION=1
+      ;;
+    D)
+      do_download
+      HAS_ACTION=1
+      ;;
+    z)
+      do_zipfile
+      HAS_ACTION=1
+      ;;
+    \?)
+      do_help
+      echo "Invalid option: -$OPTARG" >&2
+      exit 1
+      ;;
+    :)
+      echo "Option -$OPTARG requires an argument." >&2
+      exit 1
+      ;;
+  esac
+done
+
+if [ -z "$HAS_ACTION" ]; then
+  do_help
+  exit 2
+fi
diff --git a/ext/afform/html/package-lock.json b/ext/afform/html/package-lock.json
new file mode 100644 (file)
index 0000000..167253f
--- /dev/null
@@ -0,0 +1,13 @@
+{
+  "name": "afform_html",
+  "version": "0.0.1",
+  "lockfileVersion": 1,
+  "requires": true,
+  "dependencies": {
+    "monaco-editor": {
+      "version": "0.14.3",
+      "resolved": "https://registry.npmjs.org/monaco-editor/-/monaco-editor-0.14.3.tgz",
+      "integrity": "sha512-RhaO4xXmWn/p0WrkEOXe4PoZj6xOcvDYjoAh0e1kGUrQnP1IOpc0m86Ceuaa2CLEMDINqKijBSmqhvBQnsPLHQ=="
+    }
+  }
+}
diff --git a/ext/afform/html/package.json b/ext/afform/html/package.json
new file mode 100644 (file)
index 0000000..4305b46
--- /dev/null
@@ -0,0 +1,15 @@
+{
+  "name": "afform_html",
+  "version": "0.0.1",
+  "description": "![Screenshot](/images/screenshot.png)",
+  "main": "index.js",
+  "scripts": {
+    "test": "echo \"Error: no test specified\" && exit 1"
+  },
+  "author": "",
+  "repository": "https://github.com/totten/afform",
+  "license": "AGPL-3.0",
+  "dependencies": {
+    "monaco-editor": "^0.14.3"
+  }
+}