forked from Aylur/ags
-
Notifications
You must be signed in to change notification settings - Fork 0
/
post_install.sh
73 lines (56 loc) · 1.58 KB
/
post_install.sh
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
#!/usr/bin/env bash
DATA_DIR="$DESTDIR/$1"
PKGDATA_DIR="$DESTDIR/$2"
BIN_DIR="$DESTDIR/$3"
APP_ID=$4
mkdir -p $BIN_DIR
BIN_SRC="$PKGDATA_DIR/$APP_ID"
BIN_DEST="$BIN_DIR/ags"
ln -s -f $BIN_SRC $BIN_DEST
if [[ "$5" == "false" ]]; then
exit 0
fi
SRC=$6
TYPES="$PKGDATA_DIR/types"
mkdir -p $TYPES
tsc -p $SRC/tsconfig.json -d --declarationDir $TYPES --emitDeclarationOnly
function fixPaths {
sed -i 's/node_modules/types/g' $1
sed -i 's/import("@girs/import("types\/@girs/g' $1
}
export -f fixPaths
find $TYPES -type f | xargs -I % bash -c "fixPaths %"
cp -r "$SRC/node_modules/@girs" "$TYPES/@girs"
# gen ags.d.ts
function mod {
echo "declare module '$1' {
const exports: typeof import('$2')
export = exports
}"
}
function resource {
mod "resource:https:///com/github/Aylur/ags/$1.js" "./$1"
}
dts="$TYPES/ags.d.ts"
echo "declare function print(...args: any[]): void;
declare const Widget: typeof import('./widget').default
declare const Service: typeof import('./service').default
declare const Variable: typeof import('./variable').default
declare const Utils: typeof import('./utils').default
declare const App: typeof import('./app').default
" >$dts
for file in $SRC/src/*.ts; do
f=$(basename -s .ts $file)
if [[ "$f" != "main" && "$f" != "client" ]]; then
resource "$(basename -s .ts $file)" >>$dts
fi
done
for file in $SRC/src/service/*.ts; do
resource "service/$(basename -s .ts $file)" >>$dts
done
for file in $SRC/src/widgets/*.ts; do
resource "widgets/$(basename -s .ts $file)" >>$dts
done
for file in $SRC/src/utils/*.ts; do
resource "utils/$(basename -s .ts $file)" >>$dts
done