TeaWeb/scripts/build_declarations.sh

57 lines
1.6 KiB
Bash
Raw Normal View History

2018-10-28 23:01:09 +01:00
#!/usr/bin/env bash
2018-10-28 23:59:15 +01:00
BASEDIR=$(dirname "$0")
source "${BASEDIR}/resolve_commands.sh"
2018-12-26 14:17:12 +01:00
cd "$BASEDIR/../"
2018-10-28 23:59:15 +01:00
2018-10-28 23:01:09 +01:00
function generate_link() {
2019-02-11 20:12:37 +01:00
if [[ ! -L $2 ]] || [[ "${BASH_ARGV[0]}" == "force" ]]; then
if [[ -e $2 ]] || [[ -L $2 ]]; then
2018-10-28 23:01:09 +01:00
rm $2
fi
ln -rs $1 $2
fi
}
2018-11-26 21:30:08 +01:00
function replace_tribble() {
#${1} => file name
echo "$(cat ${1} | sed -E 's/\/\/\/[ ]+<reference [a-zA-Z.-=_ ]+\/>.*/\n/')" > ${1}
}
2018-12-26 14:17:12 +01:00
2018-10-28 23:01:09 +01:00
2018-12-04 19:02:45 +01:00
#Building the generator
2018-12-26 14:17:12 +01:00
./tools/build_dtsgen.sh
2018-12-04 19:02:45 +01:00
if [ $? -ne 0 ]; then
echo "Failed to build typescript declaration generator"
exit 1
fi
2018-10-28 23:01:09 +01:00
#Easy going: Each "module" has it's exports and imports
#So lets first build the exports and ignore any errors
#Note: For the client we have to use the given file
#Web
2018-12-04 18:48:35 +01:00
npm run dtsgen -- --config web/tsconfig/dtsconfig.json -v
2018-11-26 21:30:08 +01:00
replace_tribble web/declarations/exports.d.ts
2018-10-28 23:01:09 +01:00
echo "Generated web declarations"
#Shared
2018-12-04 18:48:35 +01:00
npm run dtsgen -- --config shared/tsconfig/dtsconfig.json -v
2018-11-26 21:30:08 +01:00
replace_tribble shared/declarations/exports.d.ts
2018-10-28 23:01:09 +01:00
echo "Generated shared declarations"
#Now build the merged declaration for the shared project
#Link the declaration files (All interface declarations should be equal!)
2019-02-11 20:12:37 +01:00
if [[ ! -d shared/declarations ]]; then
2018-10-28 23:01:09 +01:00
mkdir shared/declarations
2019-02-11 20:12:37 +01:00
if [[ $? -ne 0 ]]; then
2018-10-28 23:01:09 +01:00
echo "Failed to create directory shared/declarations"
exit 1
fi
fi
generate_link client/declarations/exports.d.ts shared/declarations/imports_client.d.ts
generate_link web/declarations/exports.d.ts shared/declarations/imports_web.d.ts
#Last but not least the client imports
generate_link shared/declarations/exports.d.ts web/declarations/imports_shared.d.ts