刘光辉
12 小时以前 0dfe84494048ce27ba8449831782128412d3eb13
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env sh
set -eu
 
SCRIPT_DIR=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
PLUGIN_DIR=$(CDPATH= cd -- "$SCRIPT_DIR/.." && pwd)
CONTRACT="$SCRIPT_DIR/production-contract.mjs"
DIST_DIR=${ONLYOFFICE_PLUGIN_DIST_DIR:-"$PLUGIN_DIR/dist"}
case "$DIST_DIR" in
  /*) ;;
  *) DIST_DIR=$(CDPATH= cd -- "$DIST_DIR" && pwd) ;;
esac
PACKAGE="$DIST_DIR/eln-template-annotator.plugin"
TEMP_PACKAGE="$DIST_DIR/.eln-template-annotator.$$.plugin"
 
cleanup() {
  rm -f "$TEMP_PACKAGE"
}
 
trap cleanup EXIT
trap 'exit 1' HUP INT TERM
 
command -v jq >/dev/null 2>&1 || {
  printf '%s\n' 'jq is required to package the plugin' >&2
  exit 1
}
command -v zip >/dev/null 2>&1 || {
  printf '%s\n' 'zip is required to package the plugin' >&2
  exit 1
}
command -v unzip >/dev/null 2>&1 || {
  printf '%s\n' 'unzip is required to verify the plugin' >&2
  exit 1
}
command -v node >/dev/null 2>&1 || {
  printf '%s\n' 'Node.js is required to validate the production package' >&2
  exit 1
}
 
for required_file in \
  "$DIST_DIR/config.json" \
  "$DIST_DIR/index.html" \
  "$DIST_DIR/resources/icon.png" \
  "$DIST_DIR/resources/icon@2x.png" \
  "$DIST_DIR/translations/langs.json"; do
  if [ ! -f "$required_file" ]; then
    printf '%s\n' "Missing production build file: $required_file" >&2
    exit 1
  fi
done
 
jq -e \
  '.version == "0.1.0" and
   .guid == "asc.{2D6D6CB6-F6FC-45B7-8EC7-0CC1940F1A6F}" and
   .variations[0].url == "index.html?v=0.1.0"' \
  "$DIST_DIR/config.json" >/dev/null
 
node "$CONTRACT" validate-dist "$DIST_DIR"
 
cd "$DIST_DIR"
set -- \
  config.json \
  index.html \
  assets/ \
  resources/ \
  resources/icon.png \
  resources/icon@2x.png \
  translations/ \
  translations/langs.json
for asset in assets/*; do
  set -- "$@" "$asset"
done
zip -q "$TEMP_PACKAGE" "$@"
unzip -tq "$TEMP_PACKAGE" >/dev/null
mv -f "$TEMP_PACKAGE" "$PACKAGE"
 
printf '%s\n' "$PACKAGE"