-
Notifications
You must be signed in to change notification settings - Fork 2
/
Justfile
executable file
·209 lines (190 loc) · 10 KB
/
Justfile
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
#!/usr/bin/env just --justfile
# Documentation: https://just.systems/man/en/
set shell := ["nu", "-c"]
# Integration with nodejs package.json scripts, see https://just.systems/man/en/chapter_65.html
export PATH := './node_modules/.bin:' + env_var('PATH')
export DIST_DIR := "dist"
export BUILD_DIR := ".build"
# Print this help
help:
@just -l
# Install dependencies
deps:
yarn
# Format Justfile
format:
@just --fmt --unstable
# Install git commit hooks
githooks:
#!/usr/bin/env nu
$env.config = { use_ansi_coloring: false, error_style: "plain" }
let hooks_folder = '.githooks'
if (git config core.hooksPath) != $hooks_folder {
print 'Installing git commit hooks'
git config core.hooksPath $hooks_folder
# npm install -g @commitlint/config-conventional
}
if not ($hooks_folder | path exists) {
mkdir $hooks_folder
"#!/usr/bin/env -S sh\nset -eu\njust test" | save $"($hooks_folder)/pre-commit"
chmod 755 $"($hooks_folder)/pre-commit"
"#!/usr/bin/env -S sh\nset -eu\n\nMSG_FILE=\"$1\"\nPATTERN='^(fix|feat|docs|style|chore|test|refactor|ci|build)(\\([a-z0-9/-]+\\))?!?: [a-z].+$'\n\nif ! head -n 1 \"${MSG_FILE}\" | grep -qE \"${PATTERN}\"; then\n\techo \"Your commit message:\" 1>&2\n\tcat \"${MSG_FILE}\" 1>&2\n\techo 1>&2\n\techo \"The commit message must conform to this pattern: ${PATTERN}\" 1>&2\n\techo \"Contents:\" 1>&2\n\techo \"- follow the conventional commits style (https://www.conventionalcommits.org/)\" 1>&2\n\techo 1>&2\n\techo \"Example:\" 1>&2\n\techo \"feat: add super awesome feature\" 1>&2\n\texit 1\nfi"| save $"($hooks_folder)/commit-msg"
chmod 755 $"($hooks_folder)/commit-msg"
# if not (".commitlintrc.yaml" | path exists) {
# "extends:\n - '@commitlint/config-conventional'" | save ".commitlintrc.yaml"
# }
# git add $hooks_folder ".commitlintrc.yaml"
git add $hooks_folder
}
# Lint extension - only the firefox extension is linted at the moment
lint: build-prod
web-ext lint --source-dir=.build_firefox
# Build extension
_build BROWSER="all":
#!/usr/bin/env nu
# workaround for vite's build process that triggers the wrong code path for sanctuary modules
# This issue has been fixed in currently unrelease sanctuary versions
sed -i -e 's/util\.inspect\.custom/util?.inspect?.custom/g' node_modules/sanctuary*/*.js
# workaround the not yet existing support of package.json/browser in rollup - webpack supports it but uses eval which breaks browser plugins
# See: https://docs.npmjs.com/cli/v6/configuring-npm/package-json#browser
# See: https://github.com/rollup/rollup/issues/185
# See: https://github.com/webpack/webpack/issues/5627
let platform_bak = './node_modules/jsonld/lib/platform.js.bak'
let platform = './node_modules/jsonld/lib/platform.js'
let platform_browser = './node_modules/jsonld/lib/platform-browser.js'
if ($platform_browser | path exists) {
mv $platform $platform_bak
mv $platform_browser $platform
}
## build manifest
let package = (open package.json)
let manifest_shared = (open manifest/manifest_shared.json | upsert version $package.version)
## compile code
let build_dir = $env.BUILD_DIR
rm -rpf $build_dir
mkdir $build_dir
[rollup frontend] | par-each {|type|
if $type == "rollup" {
## backend build
yarn run rollup -c
mv .build_background.js .build/background.js
# ls *.js | par-each {|it| yarn run rollup -i $it.name --file $"($build_dir)/($it.name | path basename)" --format iife --inlineDynamicImports -p @rollup/plugin-commonjs -p rollup-plugin-polyfill-node -p @rollup/plugin-node-resolve}
} else {
## frontend build
yarn build
^cp -r ./.output/public/* $build_dir # solid-start always builds everything in the dist directory
rm -rvpf $"($build_dir)/assets"
^find $build_dir -name '*.gz' -exec rm -v {} +
^find $build_dir -name '*.br' -exec rm -v {} +
^find $build_dir -name '*.wasm' -exec rm -v {} +
^find $build_dir -name '*.json' -exec rm -v {} +
# INFO: workaround for https://github.com/solidjs/solid-start/issues/1263
htmlq -f $"($build_dir)/index.html" -o $"($build_dir)/manifest.js" --text 'body > script:first-of-type'
htmlq -f $"($build_dir)/index.html" -r 'body > script:first-of-type' | sed -e 's#</div>#</div><script src="/manifest.js"></script>#' | save -f $"($build_dir)/index.html.new"
mv -f $"($build_dir)/index.html.new" $"($build_dir)/index.html"
}
}
## prepare additional files
let dist_dir = $env.DIST_DIR
rm -rpf $dist_dir
mkdir $dist_dir
cp LICENSE $build_dir
## package plugin
if "{{ BROWSER }}" == "all" {[firefox chrome source]} else {"{{ BROWSER }}" | split words} | par-each {|browser|
let build_dir_browser = $"($env.BUILD_DIR)_($browser)"
rm -rpf $build_dir_browser
cp -r $build_dir $build_dir_browser
if ($"manifest/manifest_($browser).json" | path exists) {$manifest_shared | merge (open $"manifest/manifest_($browser).json") | save -f $"($build_dir_browser)/manifest.json"}
if $browser == "firefox" {
let res = (do {web-ext build --overwrite-dest -s $build_dir_browser -a $dist_dir} | complete)
if $res.exit_code != 0 {
print $res
exit $res.exit_code
}
mv $"($dist_dir)/($manifest_shared.name)-($manifest_shared.version).zip" $"($dist_dir)/($manifest_shared.name)-($manifest_shared.version)_($browser).zip"
} else if $browser == "chrome" {
## build chrome extension
$manifest_shared | merge (open manifest/manifest_chrome.json) | save -f $"($build_dir_browser)/manifest.json"
# See https://peter.sh/experiments/chromium-command-line-switches/
chromium $"--pack-extension=($build_dir_browser)" --pack-extension-key=./identinet-plugin.pem
mv $"($build_dir_browser).crx" $"($dist_dir)/($manifest_shared.name)-($manifest_shared.version)_($browser).crx"
cd $build_dir_browser
^zip -q -r -0 $"../($dist_dir)/($manifest_shared.name)-($manifest_shared.version)_($browser).zip" *
} else if $browser == "source" {
git archive --format=zip HEAD -o $"($dist_dir)/($manifest_shared.name)-($manifest_shared.version)_($browser).zip"
} else {
print -e $"Unknown browser, only source, firefox, chrome and all are supported: ($browser)"
}
print $"($browser) package ready: ($dist_dir)/($manifest_shared.name)-($manifest_shared.version)_($browser).zip"
$"($dist_dir)/($manifest_shared.name)-($manifest_shared.version)_($browser).zip"
}
print "done."
# Build extension for development
build-dev BROWSER="all":
NODE_ENV=development just _build {{ BROWSER }}
# Build extension for production
build-prod BROWSER="all":
NODE_ENV=production just _build {{ BROWSER }}
_build-notify BROWSER="all":
#!/usr/bin/env nu
let start = (date now)
NODE_ENV=development just _build {{ BROWSER }}
notify-send -a identinet-plugin $"(date now | format date "%H:%M") - built, duration: ((date now) - $start)"
# Watch changes and rebuild appliaction
build-watch BROWSER="all":
# FIXME: this isn't optimal - not all files are being watched,
# ./background.js and ./public are missing. Furthermore, it would be great
# to perform the build when the task is started
# watch src {|| let start = (date now); just build; notify-send -a identinet-plugin $"(date now | format date "%H:%M:%S") - build complete - it took ((date now) - $start)"}
watchexec -r -w src -w ./Justfile -w ./src-background -w ./public -w ./package.json -w ./vite.config.js -w ./rollup.config.js -w ./uno.config.ts -w ./manifest just _build-notify {{ BROWSER }}
# Run local test websites
run-websites:
#!/usr/bin/env nu
let directory = "./test/website-certificates"
mkdir $directory
let domains = ["id-broken.localhost", "id-plus.localhost", "id-did-configuration.localhost", "id-web.localhost", "no-id.localhost"]
$domains | each {|domain|
if not ($"($directory)/($domain).pem" | path exists) {
mkcert -cert-file $"($directory)/($domain).pem" -key-file $"($directory)/($domain).pem" $domain
}
}
print "Test websites are up and running. Visit:"
$domains | each {|it| print $"- https://($it):8443"}
print ""
caddy run
# Runt tests
test:
yarn run vitest run --dir .
# Start preview server
run-preview:
yarn run dev
# Create a new release of this module. LEVEL can be one of: major, minor, patch, premajor, preminor, prepatch, or prerelease.
release LEVEL="patch" NEW_VERSION="":
#!/usr/bin/env nu
if (git rev-parse --abbrev-ref HEAD) != "main" {
print -e "ERROR: A new release can only be created on the main branch."
exit 1
}
if (git status --porcelain | wc -l) != "0" {
print -e "ERROR: Repository contains uncommited changes."
exit 1
}
# str replace -r "-.*" "" - strips git's automatic prerelease version
let package = (open package.json)
# let current_version = (git describe | str replace -r "-.*" "" | deno run npm:semver $in)
let current_version = ($package.version | deno run npm:semver $in)
let new_version = if "{{ NEW_VERSION }}" == "" {$current_version | deno run npm:semver -i "{{ LEVEL }}" $in | lines | get 0} else {"{{ NEW_VERSION }}"}
print "\nChangelog:\n"
git cliff --strip all -u -t $"v($new_version)"
input -s $"Version will be bumped from ($current_version) to ($new_version)\nPress enter to confirm.\n"
open package.json | upsert version $new_version | save -f package.json; git add package.json
git cliff -t $"v($new_version)" -o CHANGELOG.md; git add CHANGELOG.md
git commit -n -m $"Bump version to ($new_version)"
just build-prod
git tag -s -m $"v($new_version)" $"v($new_version)"
git push --atomic origin refs/heads/main $"refs/tags/v($new_version)"
git cliff --strip all --current | gh release create -F - $"v($new_version)" dist/*.zip dist/*.crx
# Cleanup everything
clean:
rm -rpf $env.DIST_DIR $env.BUILD_DIR
glob $"($env.BUILD_DIR)_*" | each {|it| rm -rpf $it}