1 #!/usr/bin/env nix-shell
2 #! nix-shell -i bash -p nodejs yarn yarn2nix jq rsync common-updater-scripts moreutils
6 expr_dir
=$
(cd "$(dirname "$0")"; pwd)
7 tmp
=$
(mktemp
-dt update-meshcentral.XXXXXX
)
9 npm show
--json meshcentral
> "$tmp/npm.json"
10 version
=$
(<"$tmp/npm.json" jq
-r .version
)
11 tarball
=$
(<"$tmp/npm.json" jq
-r .dist.tarball
)
13 prefetch
=$
(nix-prefetch-url
--unpack --print-path "$tarball" |
tr '\n' ' ')
14 read -r hash storePath
<<<"$prefetch"
16 rsync
-r --chmod=u
=rwX
"$storePath/" package
/
19 # Very crude way of discovering optional dependencies. These are
20 # fetched at runtime by stock upstream, but we don't allow that kind
23 BEGIN { RS=\"[\n;]\" }
24 match(\$0, /(modules|passport) = (\[.*\])$/, a) { print a[2] }
25 match(\$0, /(modules|passport).push\(('[^']+')\)/, a) { print a[2] }
28 jq
--slurp '[if type == "array" then .[] else . end] | flatten' |
29 # And an equally crude way of adding them to package.json. We
30 # can't use yarn add here, because that will blow up on
31 # dependencies which don't support the current platform. Even with
33 jq
--slurpfile package package.json \
34 '(. | map(. | capture("(?<name>@?[^@]+)(@(?<version>.+))?") | { key: .name, value: (.version // "*")}) | from_entries) as $optionalDependencies | $package | .[] | .optionalDependencies |= . + $optionalDependencies' |
37 # Fetch all the optional dependencies, so we have them available in
39 yarn
install --ignore-scripts
41 cp package.json
"$expr_dir"
42 cp yarn.lock
"$expr_dir/yarn.lock"
43 yarn2nix
> "$expr_dir/yarn.nix"
45 cd "$expr_dir/../../../.."
46 update-source-version meshcentral
"$version" "$hash" "$tarball"
48 # Only clean up if everything worked