-
Notifications
You must be signed in to change notification settings - Fork 1
/
run.local
executable file
·116 lines (86 loc) · 2.42 KB
/
run.local
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
#!/usr/bin/env bash
function ci:build {
APP_ENV=prod nix develop --command ./run generate
}
function ci:install {
nix develop --command composer install
}
function ci:test {
nix develop --command ./run test --testdox --colors=always
}
function clean {
rm -fr output_*/ source/build/
}
# Create a new daily email.
function create-daily {
local date="${1}"
local title="${2}"
if [ "${date}" == "next" ]; then
next_date=$(ls -1 source/_daily_emails | tail -n 1 | tr -d '.md' | xargs -I {} date +%Y-%m-%d -d '{} +1 day')
else
next_date="${date}"
fi
filepath="source/_daily_emails/${next_date}.md"
shift 1
# Generate the title and slug.
title="${*}"
slug=$(echo "${title}" | \
tr '[:upper:]' '[:lower:]' | \
sed 's/[^a-z0-9]/-/g' | \
sed 's/\-\-+/-/g' | \
sed 's/^\-//;s/\-$//')
# Create the file.
cp -f --no-clobber resources/daily-email-stub.md "${filepath}"
date=$(date -d "${next_date}" +%Y-%m-%d)
day=$(date -d "${next_date}" +%d)
month=$(date -d "${next_date}" +%m)
year=$(date -d "${next_date}" +%Y)
# Replace the placeholders.
sed -i "s/{{ date }}/${date}/" "${filepath}"
sed -i "s/{{ title }}/${title}/" "${filepath}"
sed -i "s#{{ permalink }}#daily/${year}/${month}/${day}/${slug}#" "${filepath}"
# Create a commit with the appropriate date in the message
git add "${filepath}"
git commit --quiet -m "Add daily email for ${date}
${title}"
echo "${filepath}"
}
# Build CSS assets, this is meant to be run within the `assets` directory.
function npm:build:css {
local args=()
if [[ "${NODE_ENV:-}" == "production" ]]; then
args=(--minify)
else
args=(--watch)
fi
tailwindcss \
--config tailwind.config.ts \
--output ../source/build/tailwind.css "${args[@]}"
}
function setup {
git submodule update --recursive --init
git submodule update --recursive --remote || true
composer install
(cd assets && pnpm install)
(cd assets && NODE_ENV=production npm:build:css)
APP_ENV=prod generate
}
function publish {
git push
tag-release
git push --tags
git stash
clean
# Copy cached files, such as generated CSS files.
cp -r cache/* source
# export NODE_ENV=production
# (cd assets && npm:build:css)
APP_ENV=prod generate
rsync --archive --verbose --compress --update --delete \
output_prod/ ssh.oliverdavies.uk:/var/www/vhosts/www.oliverdavies.uk
git stash pop
}
function test {
phpunit "${@}"
}
# vim: ft=bash