-
Notifications
You must be signed in to change notification settings - Fork 0
/
Taskfile
161 lines (140 loc) · 4.5 KB
/
Taskfile
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#!/bin/bash
PATH="$PWD/node_modules/.bin":$PATH
set -e
make_layers() {
# mkdir src/resolvers
# basename $file
files=$(/usr/bin/find src -name *.resolver.ts)
for file in $files; do
# basename=$(basename $file)
ln -Pvf $file src/resolvers
# ln -rsv ./src/article/article.resolver.ts ./src/resolvers/article.resolver.ts
done
}
api_spec() {
export APIURL='localhost:3000/api'
sh test/run-api-tests.sh
}
build() {
set -x
rm -rf dist
mkdir dist
# Prepare sources
# cp -rf src dist
# cat tsconfig.json | jq 'del(.include, .compilerOptions.outDir)' >dist/tsconfig.json
# cp -fv README.md LICENSE package.json dist
# Build
nest build --path tsconfig.build.json
# Copy prisma schema and migrations
mkdir -p dist/prisma/migrations
if [ -d prisma/migrations ]; then
cp -r prisma/migrations dist/prisma
cp prisma/schema.prisma dist/prisma
fi
# Copy @prisma/client
mkdir -p dist/node_modules/@prisma/client
cp -r node_modules/@prisma/client/* dist/node_modules/@prisma/client
cd dist
# Remove spec
/usr/bin/find . -name '*.spec.ts' | xargs rm -rf
# Cleanup
rm -vf *.tsbuildinfo tsconfig.json tsconfig.build.json
/usr/bin/find . -name '*.ts' | xargs rm -rf
cd ..
set +x
}
# Deploy package for monorepo strategy
# Example: sh Taskfile deploy_package src/subpackage
# setup global for faster deployment several package:
# npm i -g semantic-release semantic-release-monorepo @semantic-release/changelog @semantic-release/commit-analyzer @semantic-release/git @semantic-release/github @semantic-release/npm @semantic-release/release-notes-generator remark-cli remark-license
# npm i --no-save remark-cli remark-license remark-toc
deploy_package() {
set -x
root=$(pwd)
build_package $1
cd $1
npx semantic-release -e semantic-release-monorepo
cd $root
set +x
}
# build sub package (monorepo)
build_package() {
echo Building package $1
# Prepare
root=$(pwd)
rootPackage=$(cat package.json)
rootTsConfig=$(cat tsconfig.json)
# Switching directory to package
cd "$root/$1"
# Clean
rm -rfv dist
mkdir dist
build_package_json
# Merge root and local tsconfig files
localTsConfig=$(cat tsconfig.json || echo {})
echo "$rootTsConfig" "$localTsConfig" |
jq -s '.[0] * .[1]' |
jq 'del(.include, .compilerOptions.outDir)' \
>dist/tsconfig.json
# Build
cp -rfv *.ts ./dist
cd dist
/usr/bin/find . -name '*.spec.ts' | xargs rm -rvf
tsc --incremental false --project .
rm -rvf tsconfig.json
cd ..
# Return to package directory
# Copy other files to dist
cp -vf README.md LICENSE package.json dist || true
cd $root
return 0
}
# Configure package.json for package
# $1 - path to subpackage root
# https://riptutorial.com/bash/example/19531/a-function-that-accepts-named-parameters
build_package_json() {
if [ -z "$root" ]; then
local root=$(git rev-parse --show-toplevel)
local rootPackage=$(cat $root/package.json)
fi
if [ -n "$1" ]; then
parentScope=$(pwd)
cd $1
fi
[ ! -f package.json ] && npm init -y 1>/dev/null
localPackage=$(cat package.json)
localPackage=$(echo "$localPackage" | jq '.license = "MIT"')
author=$(echo "$localPackage" | jq -r '.author | select (. != null)')
if [ -z "$author" ]; then
author=$(date +"%Y")
localPackage=$(echo "$localPackage" | jq --arg x "$author" '.author = $x')
fi
# Update homepage field
if [ -z $(echo "$localPackage" | jq -r '.homepage | select (. != null)') ]; then
rootHomepage=$(echo "$rootPackage" | jq -r '.homepage | select (. != null)' | sed s'/#readme//')
homepage="$rootHomepage/tree/master/$1"
localPackage=$(echo "$localPackage" | jq --arg x "$homepage" '.homepage = $x')
fi
echo "$localPackage" >package.json
[ -n "$1" ] && cd $parentScope
return 0
}
postbuild() {
# if we are on heroku
if [ "$STACK" = 'heroku-18' ]; then
npm run migrate:up
fi
}
preinstall() {
set -x
# This is hacky solution to deploy on heroku
# https://github.com/prisma/prisma-client-js/issues/184
if [ "$STACK" = 'heroku-18' ]; then
sed -i 's/provider = "sqlite"/provider = "postgresql"/' prisma/schema.prisma
if [ -d prisma/migrations ]; then
sed -i 's/provider = "sqlite"/provider = "postgresql"/' prisma/migrations/migration_lock.toml
fi
fi
set +x
}
"$@"