forked from lovell/sharp-libvips
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpopulate-npm-workspace.sh
More file actions
executable file
·82 lines (71 loc) · 2.14 KB
/
populate-npm-workspace.sh
File metadata and controls
executable file
·82 lines (71 loc) · 2.14 KB
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
77
78
79
80
81
82
#!/usr/bin/env bash
set -e
## Copyright 2017 Lovell Fuller and others.
## SPDX-License-Identifier: Apache-2.0
# Dependency version numbers
source ./versions.properties
# Common options for curl
CURL="curl --silent --location --retry 3 --retry-max-time 30"
extract() {
PLATFORM="$1"
case $1 in
*ppc64le)
PACKAGE="${1%??}" # package directory is named as npm/linux-ppc64
;;
*)
PACKAGE="${1%v[68]}" # remove ARM version
;;
esac
echo "$PLATFORM -> $PACKAGE"
rm -rf "npm/$PACKAGE/include" "npm/$PACKAGE/lib"
tar xzf sharp-libvips-$PLATFORM.tar.gz -C "npm/$PACKAGE"
}
download_cpp() {
$CURL \
--remote-name --output-dir "npm/dev/cplusplus" --create-dirs \
"https://raw.githubusercontent.com/libvips/libvips/v$VERSION_VIPS/cplusplus/$1.cpp"
}
generate_readme() {
PACKAGE="$1"
jq -r '("# `" + .name + "`\n\n" + .description + ".\n")' "npm/$PACKAGE/package.json" > "npm/$PACKAGE/README.md"
echo "## Licensing" >> "npm/$PACKAGE/README.md"
cat "npm/$PACKAGE/THIRD-PARTY-NOTICES.md" | tail -n +2 >> "npm/$PACKAGE/README.md"
}
generate_index() {
PACKAGE="$1"
for dir in include lib cplusplus; do
if [ -d "npm/$PACKAGE/$dir" ]; then
echo "module.exports = __dirname;" > "npm/$PACKAGE/$dir/index.js"
fi
done
}
remove_unused() {
PACKAGE="$1"
if [[ "$PACKAGE" != "dev"* ]]; then
rm -r "npm/$PACKAGE/include"
rm "npm/$PACKAGE/THIRD-PARTY-NOTICES.md"
fi
}
# Download and extract per-platform binaries
PLATFORMS=$(ls platforms --ignore=win32*)
for platform in $PLATFORMS; do
extract "$platform"
done
for platform in arm64v8 ia32 x64; do
extract "win32-$platform"
done
extract "dev-wasm32"
# Common header and source files
cp -r npm/linux-x64/{include,versions.json,THIRD-PARTY-NOTICES.md} npm/dev/
cp -r npm/win32-x64/include npm/dev/
find npm/dev/include/ -maxdepth 1 -type f -links +1 -delete
for source in VConnection VError VImage VInterpolate VRegion vips-operators; do
download_cpp "$source"
done;
# Generate README files
PACKAGES=$(jq -r '.workspaces[]' "npm/package.json")
for package in $PACKAGES; do
generate_readme "$package"
generate_index "$package"
remove_unused "$package"
done