@webship.co/workspace-filament 0.0.0-stage → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +271 -2
- package/ai/agents/filament-site-builder.md +108 -0
- package/ai/agents/filament-tester.md +131 -0
- package/ai/commands/filament-test.md +95 -0
- package/ai/prompts/filament-build-and-test.md +25 -0
- package/ai/prompts/filament-scenarios-for-a-resource.md +32 -0
- package/ai/skills/filament-scenarios/SKILL.md +127 -0
- package/ai/skills/filament-scenarios/examples/form-and-modal.feature +23 -0
- package/ai/skills/filament-scenarios/examples/session-and-navigation.feature +22 -0
- package/ai/skills/filament-scenarios/examples/table.feature +28 -0
- package/commands/cmd-filament-project.sh +38 -0
- package/dist/src/index.d.ts +34 -0
- package/dist/src/index.js +57 -0
- package/dist/src/index.js.map +1 -0
- package/features/filament-runtimes.feature +53 -0
- package/features/filament.feature +43 -0
- package/package.json +96 -4
- package/scripts/args/arg-filament.sh +39 -0
- package/scripts/functions/fun-filament.sh +478 -0
- package/testing/panel.feature +34 -0
|
@@ -0,0 +1,478 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
|
|
3
|
+
# Filament for the Webship Workspace: build a Laravel app with an admin panel (a new app with the
|
|
4
|
+
# panel installed, or the panel's official demo app), add its default accounts, and wire its step
|
|
5
|
+
# pack into the testing setup, next to the Laravel step pack it extends.
|
|
6
|
+
#
|
|
7
|
+
# Placed by `plugins.sh --install filament` in core/scripts/plugins/filament/functions/, where
|
|
8
|
+
# bootstrap sources it with the core's own functions and the Laravel plugin's: this plugin needs
|
|
9
|
+
# @webship.co/workspace-laravel. A new app starts from that plugin's laravel_build (the official
|
|
10
|
+
# installer and a starter kit), and the accounts are written with its laravel_write_accounts.
|
|
11
|
+
# Everything runs in the project's container (DDEV by default: `ddev artisan …`, `ddev composer …`),
|
|
12
|
+
# never on the host. On DDEV the container tool writes the database settings of the app into its .env.
|
|
13
|
+
#
|
|
14
|
+
# The runtimes: an app is built on DDEV, or with --runtime on Docker Compose, Podman, Kubernetes, Lando
|
|
15
|
+
# or Docksal. The commands are the same on each: `ddev <verb>` is DDEV itself on a DDEV project, and on
|
|
16
|
+
# another runtime the core's layer (fun-runtime.sh) gives the verb its meaning there. What differs comes
|
|
17
|
+
# from the Laravel plugin: Artisan and `.env` (laravel_artisan and laravel_dotenv_set: DDEV has verbs of
|
|
18
|
+
# its own for them, the layer has none), the .env DDEV writes on start (laravel_runtime_config: the
|
|
19
|
+
# address, the database of the project's own stack and its mail catcher), and a new app's build. The
|
|
20
|
+
# address is the runtime's (filament_url), and npm runs in the tests container there.
|
|
21
|
+
#
|
|
22
|
+
# The panel's CLI is Artisan, through the Laravel plugin's tool:
|
|
23
|
+
# bash cmd-tools-laravel-artisan.sh <app> --run "make:filament-resource Post --generate"
|
|
24
|
+
#
|
|
25
|
+
# Four names are the ones the core's tools look for:
|
|
26
|
+
# set_filament_users the default accounts (cmd-tools-add-users.sh <project> filament)
|
|
27
|
+
# add_filament_users create them through the app (the same tool, and --add-users of the builder)
|
|
28
|
+
# cancel_filament_users delete them (cmd-tools-cancel-users.sh <project> filament)
|
|
29
|
+
# testing_configure_filament the step pack in the testing stack (cmd-tools-testing.sh <project>)
|
|
30
|
+
# An app with a panel is a project of the DDEV type `laravel`: the row's Users menu hands the tools the
|
|
31
|
+
# Laravel plugin's list. The panel's own accounts come with the builder's --add-users, with the testing
|
|
32
|
+
# setup, and with `cmd-tools-add-users.sh <project> filament`. On another runtime the builder claims the
|
|
33
|
+
# project (the core's rt_claim: `platform: filament` in the x-webship block, beside the type laravel),
|
|
34
|
+
# so the dashboard knows an app with a panel from a plain Laravel app, and its row hands the panel's list.
|
|
35
|
+
|
|
36
|
+
# The step pack a panel is tested with, and the release line it is required at. It brings the Laravel
|
|
37
|
+
# step pack along; the Laravel plugin's hook adds that one too.
|
|
38
|
+
readonly FILAMENT_STEPS_PACKAGE='@webship-js/filament-steps';
|
|
39
|
+
readonly FILAMENT_STEPS_VERSION='^2.0.0';
|
|
40
|
+
|
|
41
|
+
# The release line of the panel the builder installs, and the branch of the demo app of that line.
|
|
42
|
+
readonly FILAMENT_LINE='5';
|
|
43
|
+
|
|
44
|
+
# The default accounts, the ones a scenario logs in as. A panel has no roles of its own: what the
|
|
45
|
+
# panel decides is whether an account may use it, so that is the "role" here. Accounts are
|
|
46
|
+
# configuration, created once on the app; a test suite never creates or deletes one.
|
|
47
|
+
# administrator a verified address: the panel lets it in
|
|
48
|
+
# unverified no verified address: the panel refuses it (its login form, and the 403 page)
|
|
49
|
+
function set_filament_users() {
|
|
50
|
+
users=(administrator unverified);
|
|
51
|
+
local user ;
|
|
52
|
+
for user in "${users[@]}" ; do
|
|
53
|
+
printf -v "user_${user}_name" '%s' "${user}" ;
|
|
54
|
+
printf -v "user_${user}_mail" '%s' "${user}@example.com" ;
|
|
55
|
+
printf -v "user_${user}_password" '%s' 'dD.123123ddd' ;
|
|
56
|
+
done
|
|
57
|
+
user_administrator_role='verified' ;
|
|
58
|
+
user_unverified_role='unverified' ;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
# The runtime of the project in this folder, or of a new build (--runtime, else the workspace's
|
|
62
|
+
# setting, else DDEV). A core without the runtime layer has DDEV only.
|
|
63
|
+
function filament_runtime() {
|
|
64
|
+
if declare -f runtime_of > /dev/null ; then runtime_of ; else echo 'ddev' ; fi
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
# The address of the app in this folder: https://<name>.ddev.site on DDEV, http://127.0.0.1:<port> on
|
|
68
|
+
# Docker Compose, Podman and Lando, the node's address and a port on Kubernetes, http://<name>.docksal.site
|
|
69
|
+
# on Docksal. Asked after `ddev config`.
|
|
70
|
+
function filament_url() {
|
|
71
|
+
if declare -f rt_url > /dev/null ; then rt_url ; else echo "https://${PROJECT_NAME}.ddev.site" ; fi
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
# Artisan in the app of this folder, through the Laravel plugin on every runtime; DDEV's own
|
|
75
|
+
# `ddev artisan` with a Laravel plugin from before the runtimes.
|
|
76
|
+
function filament_artisan() {
|
|
77
|
+
if declare -f laravel_artisan > /dev/null ; then laravel_artisan "$@" ; else ddev artisan "$@" ; fi
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
# Set keys of a .env file, through the Laravel plugin on every runtime; DDEV's own `ddev dotenv set`
|
|
81
|
+
# with a Laravel plugin from before the runtimes.
|
|
82
|
+
function filament_dotenv_set() {
|
|
83
|
+
if declare -f laravel_dotenv_set > /dev/null ; then laravel_dotenv_set "$@" ; else ddev dotenv set "$@" ; fi
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
# Is this folder an app with a panel? A Laravel project (its project type: on DDEV in .ddev/config.yaml,
|
|
87
|
+
# on another runtime in the x-webship block, both read by the core's rt_is_platform) with the panel in
|
|
88
|
+
# its Composer packages.
|
|
89
|
+
function filament_is_project() {
|
|
90
|
+
local project_path="$1";
|
|
91
|
+
if declare -f rt_is_platform > /dev/null ; then
|
|
92
|
+
rt_is_platform "${project_path}" laravel || return 1 ;
|
|
93
|
+
else
|
|
94
|
+
grep -qE '^type:[[:space:]]*"?laravel"?[[:space:]]*$' "${project_path}/.ddev/config.yaml" 2>/dev/null || return 1 ;
|
|
95
|
+
fi
|
|
96
|
+
grep -q '"filament/filament"' "${project_path}/composer.json" 2>/dev/null ;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
# Go to the project a tool was asked about, or say why not.
|
|
100
|
+
function filament_enter_project() {
|
|
101
|
+
local project_path="${WORKSPACE_ROOT}/${doc_name}/${PROJECT_NAME}";
|
|
102
|
+
if [ ! -d "${project_path}" ] ; then
|
|
103
|
+
echo "No project ${PROJECT_NAME} in ${WORKSPACE_ROOT}/${doc_name}." ;
|
|
104
|
+
return 1 ;
|
|
105
|
+
fi
|
|
106
|
+
if ! filament_is_project "${project_path}" ; then
|
|
107
|
+
echo "${doc_name}/${PROJECT_NAME} is not an app with a panel: a Laravel project (project type laravel) with filament/filament in its composer.json." ;
|
|
108
|
+
return 1 ;
|
|
109
|
+
fi
|
|
110
|
+
cd "${project_path}" || return 1 ;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
# The path of the admin panel of an app: "/" when its panel provider gives none (the demo app), else
|
|
114
|
+
# the one it gives ("/admin" for a new panel).
|
|
115
|
+
function filament_panel_path() {
|
|
116
|
+
local project_path="$1" provider path ;
|
|
117
|
+
provider="${project_path}/app/Providers/Filament/AdminPanelProvider.php" ;
|
|
118
|
+
path="$(grep -oE "\->path\('[^']*'\)" "${provider}" 2>/dev/null | head -1 | sed -E "s/->path\('([^']*)'\)/\1/")" ;
|
|
119
|
+
printf '/%s' "${path#/}" ;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
# The changes a panel needs to run as a live app runs, as the panel's documentation describes them,
|
|
123
|
+
# in the project folder: the User model says which accounts the panel lets in (an address verified),
|
|
124
|
+
# and the panel checks it on every page (its own middleware); a new panel offers the password reset.
|
|
125
|
+
# Each change is marked "Webship Workspace" where it is made.
|
|
126
|
+
function filament_set_up_panel() {
|
|
127
|
+
python3 - <<'PYEOF' || return 1
|
|
128
|
+
import re
|
|
129
|
+
path = 'app/Models/User.php'
|
|
130
|
+
src = open(path).read()
|
|
131
|
+
count = 0
|
|
132
|
+
if 'Webship Workspace' in src:
|
|
133
|
+
# Changed by an earlier build.
|
|
134
|
+
count = 1
|
|
135
|
+
elif 'canAccessPanel' in src:
|
|
136
|
+
# The demo app lets every account in: an address verified for its admin panel.
|
|
137
|
+
src, count = re.subn(r"(public function canAccessPanel\(Panel \$panel\): bool\s*\{)\s*return true;",
|
|
138
|
+
r"\1\n // Changed by the Webship Workspace: the admin panel lets in an account whose address is\n // verified, and refuses the others.\n return $panel->getId() !== 'admin' || $this->hasVerifiedEmail();", src, count=1)
|
|
139
|
+
else:
|
|
140
|
+
src = src.replace("use Illuminate\\Foundation\\Auth\\User as Authenticatable;", "use Filament\\Models\\Contracts\\FilamentUser;\nuse Filament\\Panel;\nuse Illuminate\\Foundation\\Auth\\User as Authenticatable;", 1)
|
|
141
|
+
src, count = re.subn(r"class User extends Authenticatable\b(?! implements)", "class User extends Authenticatable implements FilamentUser", src, count=1)
|
|
142
|
+
src, n = re.subn(r"(class User extends Authenticatable implements )(?!FilamentUser)", r"\1FilamentUser, ", src, count=1) if count == 0 else (src, 0)
|
|
143
|
+
count = count or n
|
|
144
|
+
src = src.rstrip()
|
|
145
|
+
if count and src.endswith('}'):
|
|
146
|
+
src = src[:-1].rstrip() + """
|
|
147
|
+
|
|
148
|
+
// Added by the Webship Workspace: the panel lets in an account whose address is verified, and
|
|
149
|
+
// refuses the others.
|
|
150
|
+
public function canAccessPanel(Panel $panel): bool
|
|
151
|
+
{
|
|
152
|
+
return $this->hasVerifiedEmail();
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
"""
|
|
156
|
+
if not count:
|
|
157
|
+
raise SystemExit(path + ': the User model is not one the Webship Workspace knows; add canAccessPanel by hand.')
|
|
158
|
+
open(path, 'w').write(src)
|
|
159
|
+
path = 'app/Providers/Filament/AdminPanelProvider.php'
|
|
160
|
+
src = open(path).read()
|
|
161
|
+
if 'use App\\Http\\Middleware\\Authenticate;' in src:
|
|
162
|
+
src = src.replace('use App\\Http\\Middleware\\Authenticate;', "// Changed by the Webship Workspace: the panel's own middleware, which checks canAccessPanel.\nuse Filament\\Http\\Middleware\\Authenticate;")
|
|
163
|
+
if '->passwordReset()' not in src and "->path('admin')" in src:
|
|
164
|
+
src = re.sub(r"->login\(\)", "->login()\n // Added by the Webship Workspace.\n ->passwordReset()", src, count=1)
|
|
165
|
+
open(path, 'w').write(src)
|
|
166
|
+
PYEOF
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
# The official demo app of the panel, at the head of the branch of its release line, as its README
|
|
170
|
+
# installs it, in the project folder: its packages (the panel at the newest release of the line), its
|
|
171
|
+
# key, its database with its own seed, its storage link and its theme.
|
|
172
|
+
function filament_get_demo() {
|
|
173
|
+
local tmp ;
|
|
174
|
+
tmp="$(mktemp -d)" ;
|
|
175
|
+
git clone --quiet --depth 1 --branch "${FILAMENT_LINE}.x" https://github.com/filamentphp/demo.git "${tmp}/demo" \
|
|
176
|
+
|| { echo "The demo app could not be downloaded." ; rm -rf "${tmp}" ; return 1 ; } ;
|
|
177
|
+
(cd "${tmp}/demo" && git log -1 --format=' the demo app at %h (%ad)' --date=short) ;
|
|
178
|
+
rm -rf "${tmp}/demo/.git" ;
|
|
179
|
+
cp -a "${tmp}/demo/." ./ && rm -rf "${tmp}" ;
|
|
180
|
+
[ -f .env ] || cp .env.example .env ;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
# The demo app ships an .npmrc that holds back every npm package younger than seven days (`min-release-age=…`).
|
|
184
|
+
# The testing setup installs step packs younger than that, which npm then cannot find ("ENOVERSIONS"), on every
|
|
185
|
+
# runtime. Only that line is taken out of the app's .npmrc, and the builder says so; the rest of the file stays as
|
|
186
|
+
# it is, and an app with no .npmrc gets none.
|
|
187
|
+
function filament_npmrc_release_age() {
|
|
188
|
+
local file="${1:-.npmrc}" ;
|
|
189
|
+
[ -f "${file}" ] || return 0 ;
|
|
190
|
+
grep -qE '^[[:space:]]*min-release-age[[:space:]]*=' "${file}" || return 0 ;
|
|
191
|
+
sed -i -E '/^[[:space:]]*min-release-age[[:space:]]*=/d' "${file}" || return 1 ;
|
|
192
|
+
echo " .npmrc: the min-release-age line taken out of the app's .npmrc: the testing setup installs step packs younger than seven days." ;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
# Build an app with a panel from nothing. With --demo, the panel's official demo app; without it, a new
|
|
196
|
+
# app made by the Laravel plugin's builder (the official installer and a starter kit) with the panel
|
|
197
|
+
# installed the documented way. With --install the database is migrated and the workspace account is
|
|
198
|
+
# the panel's first account; with --add-users the default accounts.
|
|
199
|
+
function filament_build() {
|
|
200
|
+
trim_project_name ;
|
|
201
|
+
local base_url runtime ;
|
|
202
|
+
local php_version="${PHP_VERSION:-${site_php_version:-8.4}}" ;
|
|
203
|
+
local add_users="${ADD_USERS}" launch="${LAUNCH}" production="${PRODUCTION}" ;
|
|
204
|
+
|
|
205
|
+
if ! declare -f laravel_build > /dev/null || ! declare -f laravel_write_accounts > /dev/null ; then
|
|
206
|
+
echo "The Filament plugin builds on the Laravel plugin, which is not installed here:" ;
|
|
207
|
+
echo " bash core/scripts/plugins.sh --install laravel" ;
|
|
208
|
+
exit 1 ;
|
|
209
|
+
fi
|
|
210
|
+
runtime="$(filament_runtime)" ;
|
|
211
|
+
if [ "${RUNTIME:-_none_}" != '_none_' ] && [ "${RUNTIME}" != "${runtime}" ] ; then
|
|
212
|
+
echo "--runtime ${RUNTIME} needs a Webship Workspace with the container runtimes (webship/workspace#694): update the workspace, or build on DDEV." ;
|
|
213
|
+
exit 1 ;
|
|
214
|
+
fi
|
|
215
|
+
# On another runtime the app's .env is written by the Laravel plugin, as DDEV writes it on DDEV: one
|
|
216
|
+
# from before the runtimes would leave the app with no database.
|
|
217
|
+
if [ "${runtime}" != 'ddev' ] && ! declare -f laravel_runtime_config > /dev/null ; then
|
|
218
|
+
echo "--runtime ${runtime} needs the Laravel plugin 1.0.2 or later, which builds on the container runtimes: update it, or build on DDEV." ;
|
|
219
|
+
exit 1 ;
|
|
220
|
+
fi
|
|
221
|
+
|
|
222
|
+
if [ "${DEMO}" == 'yes' ] ; then
|
|
223
|
+
cd ${WORKSPACE_ROOT}/${doc_name} || exit 1 ;
|
|
224
|
+
drop_database ;
|
|
225
|
+
rm -rf "${PROJECT_NAME}" ;
|
|
226
|
+
mkdir -p "${PROJECT_NAME}" ;
|
|
227
|
+
cd ${WORKSPACE_ROOT}/${doc_name}/${PROJECT_NAME} || exit 1 ;
|
|
228
|
+
# PHP 8.4: the demo's lock file holds packages that need it.
|
|
229
|
+
ddev config --project-type=laravel --docroot=public --project-name=${PROJECT_NAME} \
|
|
230
|
+
--nodejs-version=$(ddev_nodejs_version) --php-version=${php_version} --auto || exit 1 ;
|
|
231
|
+
# On another runtime than DDEV the plugin claims the project: its type is the Laravel plugin's.
|
|
232
|
+
if [ "${runtime}" != 'ddev' ] ; then
|
|
233
|
+
rt_claim filament || exit 1 ;
|
|
234
|
+
fi
|
|
235
|
+
# The address is the runtime's to say, once the project is configured: never a written ddev.site.
|
|
236
|
+
base_url="$(filament_url)" ;
|
|
237
|
+
filament_get_demo || exit 1 ;
|
|
238
|
+
filament_npmrc_release_age .npmrc || exit 1 ;
|
|
239
|
+
# The restart writes the database and the mail settings of the container into .env.
|
|
240
|
+
ddev_up start -y || exit 1 ;
|
|
241
|
+
if [ "${runtime}" != 'ddev' ] ; then
|
|
242
|
+
# What DDEV's start writes into .env: the address, the database and the mail of the container.
|
|
243
|
+
laravel_runtime_config "${base_url}" || { echo "The .env of the app could not be written." ; exit 1 ; } ;
|
|
244
|
+
fi
|
|
245
|
+
ddev composer install --no-interaction --no-progress || { echo "composer install failed." ; exit 1 ; } ;
|
|
246
|
+
ddev composer update 'filament/*' --with-dependencies --no-interaction --no-progress || exit 1 ;
|
|
247
|
+
filament_artisan key:generate --ansi > /dev/null || exit 1 ;
|
|
248
|
+
filament_dotenv_set .env --mail-from-address=webship@example.com > /dev/null ;
|
|
249
|
+
if [ "${INSTALL}" == 'yes' ] ; then
|
|
250
|
+
filament_artisan migrate --force --seed --no-interaction || { echo "The migrations and the demo's seed failed." ; exit 1 ; } ;
|
|
251
|
+
filament_artisan storage:link > /dev/null ;
|
|
252
|
+
fi
|
|
253
|
+
ddev npm ci --no-audit --no-fund || exit 1 ;
|
|
254
|
+
ddev npm run build || exit 1 ;
|
|
255
|
+
else
|
|
256
|
+
# A new app by the Laravel plugin's builder: its accounts and its browser come after the panel.
|
|
257
|
+
ADD_USERS='no' ; LAUNCH='no' ; PRODUCTION='no' ;
|
|
258
|
+
PHP_VERSION="${php_version}" ;
|
|
259
|
+
( laravel_build ) || exit 1 ;
|
|
260
|
+
ADD_USERS="${add_users}" ; LAUNCH="${launch}" ; PRODUCTION="${production}" ;
|
|
261
|
+
cd ${WORKSPACE_ROOT}/${doc_name}/${PROJECT_NAME} || exit 1 ;
|
|
262
|
+
# On another runtime than DDEV the plugin claims the project the Laravel plugin's builder made.
|
|
263
|
+
if [ "${runtime}" != 'ddev' ] ; then
|
|
264
|
+
rt_claim filament || exit 1 ;
|
|
265
|
+
fi
|
|
266
|
+
base_url="$(filament_url)" ;
|
|
267
|
+
ddev composer require "filament/filament:^${FILAMENT_LINE}.0" --with-all-dependencies --no-interaction --no-progress \
|
|
268
|
+
|| { echo "The panel could not be required." ; exit 1 ; } ;
|
|
269
|
+
filament_artisan filament:install --panels --no-interaction || { echo "The panel could not be installed." ; exit 1 ; } ;
|
|
270
|
+
filament_dotenv_set .env --mail-from-address=webship@example.com > /dev/null ;
|
|
271
|
+
# The panel's mail (the password reset) is a queued notification, and a new app queues in its
|
|
272
|
+
# database: a local app runs no queue worker, so its queue runs in the request, as the demo's does.
|
|
273
|
+
filament_dotenv_set .env --queue-connection=sync > /dev/null ;
|
|
274
|
+
fi
|
|
275
|
+
|
|
276
|
+
filament_set_up_panel || exit 1 ;
|
|
277
|
+
filament_artisan optimize:clear > /dev/null 2>&1 ;
|
|
278
|
+
|
|
279
|
+
if [ "${INSTALL}" == 'yes' ] ; then
|
|
280
|
+
# The workspace account is the panel's first account, its address verified.
|
|
281
|
+
printf '%s|%s|%s|verified\n' "${account_name}" "${account_mail}" "${account_pass}" | laravel_write_accounts save > /dev/null \
|
|
282
|
+
|| { echo "The workspace account could not be written." ; exit 1 ; } ;
|
|
283
|
+
if [ "${ADD_USERS}" == 'yes' ] ; then
|
|
284
|
+
set_filament_users ;
|
|
285
|
+
add_filament_users ;
|
|
286
|
+
cd ${WORKSPACE_ROOT}/${doc_name}/${PROJECT_NAME} || exit 1 ;
|
|
287
|
+
fi
|
|
288
|
+
if [ "${PRODUCTION}" == 'yes' ] ; then
|
|
289
|
+
filament_dotenv_set .env --app-env=production --app-debug=false > /dev/null ;
|
|
290
|
+
fi
|
|
291
|
+
local panel_path ;
|
|
292
|
+
panel_path="$(filament_panel_path "$(pwd)")" ;
|
|
293
|
+
echo "${doc_name} ${PROJECT_NAME} has been installed: $(filament_artisan --version 2>/dev/null), panel $(ddev composer show filament/filament 2>/dev/null | awk '$1 == "versions" {print $NF}')$( [ "${DEMO}" == 'yes' ] && echo ', the demo app').";
|
|
294
|
+
echo "Go to ${base_url}${panel_path%/}/login and log in as ${account_mail}";
|
|
295
|
+
else
|
|
296
|
+
[ "${ADD_USERS}" == 'yes' ] && echo "--add-users needs --install: there is no database to add accounts to yet." ;
|
|
297
|
+
echo "${doc_name} ${PROJECT_NAME} is ready: migrate its database with bash cmd-tools-laravel-artisan.sh ${PROJECT_NAME} --run \"migrate\"";
|
|
298
|
+
echo "Go to ${base_url}";
|
|
299
|
+
fi
|
|
300
|
+
|
|
301
|
+
if [ "${LAUNCH}" == 'yes' ] ; then
|
|
302
|
+
ddev launch "$(filament_panel_path "$(pwd)")" ;
|
|
303
|
+
fi
|
|
304
|
+
|
|
305
|
+
cd ${WORKSPACE_ROOT}/${doc_name};
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
# Create the default accounts through the app, with the Laravel plugin's writer (the password hashed
|
|
309
|
+
# with the app's own hasher). An account that is already there gets its name, password and state back.
|
|
310
|
+
# The list is loaded by the caller (set_filament_users): the core's add_users, the builder, the testing
|
|
311
|
+
# setup.
|
|
312
|
+
function add_filament_users() {
|
|
313
|
+
filament_enter_project || return 1 ;
|
|
314
|
+
local user user_name user_mail user_password user_role lines="" ;
|
|
315
|
+
for user in "${users[@]}" ; do
|
|
316
|
+
user_name="user_${user}_name"; user_mail="user_${user}_mail";
|
|
317
|
+
user_password="user_${user}_password"; user_role="user_${user}_role";
|
|
318
|
+
|
|
319
|
+
echo " ---------------------------------------------------------------- ";
|
|
320
|
+
echo " User name: ${!user_name}";
|
|
321
|
+
echo " User mail: ${!user_mail}";
|
|
322
|
+
echo " User password: ${!user_password}";
|
|
323
|
+
echo " User state: ${!user_role:-verified}";
|
|
324
|
+
echo " ================================================================= ";
|
|
325
|
+
|
|
326
|
+
lines="${lines}${!user_name}|${!user_mail}|${!user_password}|${!user_role:-verified}"$'\n' ;
|
|
327
|
+
done
|
|
328
|
+
printf '%s' "${lines}" | laravel_write_accounts save ;
|
|
329
|
+
cd ${WORKSPACE_ROOT}/${doc_name};
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
# Delete the default accounts.
|
|
333
|
+
function cancel_filament_users() {
|
|
334
|
+
filament_enter_project || return 1 ;
|
|
335
|
+
local user user_name user_mail lines="" ;
|
|
336
|
+
for user in "${users[@]}" ; do
|
|
337
|
+
user_name="user_${user}_name"; user_mail="user_${user}_mail";
|
|
338
|
+
echo " ---------------------------------------------------------------- ";
|
|
339
|
+
echo " User name: ${!user_name}";
|
|
340
|
+
echo " ================================================================= ";
|
|
341
|
+
lines="${lines}${!user_name}|${!user_mail}||"$'\n' ;
|
|
342
|
+
done
|
|
343
|
+
printf '%s' "${lines}" | laravel_write_accounts delete ;
|
|
344
|
+
cd ${WORKSPACE_ROOT}/${doc_name};
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
# The step pack in the testing stack of an app with a panel. The core's testing_configure calls this
|
|
348
|
+
# in the project folder once webship-js is scaffolded and before the dependencies are installed; for a
|
|
349
|
+
# project that is not one it changes nothing.
|
|
350
|
+
#
|
|
351
|
+
# The panel's pack extends the Laravel pack, and both go in the same profile. This hook runs before the
|
|
352
|
+
# Laravel plugin's (the core calls them in the order of their names) and writes what that one would
|
|
353
|
+
# write for a starter-kit app: the users registry of the panel's accounts, the panel's home and login
|
|
354
|
+
# page, the mailbox, the tags and a first feature for the panel; the Laravel hook then finds them there
|
|
355
|
+
# and adds its own pack beside this one. Every part is skipped when it is already there, so a second run
|
|
356
|
+
# adds what the first missed and never resets a suite.
|
|
357
|
+
function testing_configure_filament() {
|
|
358
|
+
local project_path="$1";
|
|
359
|
+
filament_is_project "${project_path}" || return 0 ;
|
|
360
|
+
if [ ! -f "${project_path}/cucumber.js" ] || [ ! -f "${project_path}/package.json" ] ; then
|
|
361
|
+
echo " Filament: cucumber.js is not here yet — run the testing setup again once webship-js is scaffolded." ;
|
|
362
|
+
return 1 ;
|
|
363
|
+
fi
|
|
364
|
+
|
|
365
|
+
echo "Adding the Filament step pack (${FILAMENT_STEPS_PACKAGE} ${FILAMENT_STEPS_VERSION}).";
|
|
366
|
+
set_filament_users ;
|
|
367
|
+
local registry="" user user_name user_mail user_password panel_path ;
|
|
368
|
+
for user in "${users[@]}" ; do
|
|
369
|
+
user_name="user_${user}_name"; user_mail="user_${user}_mail"; user_password="user_${user}_password";
|
|
370
|
+
registry="${registry}${user}|${!user_mail}|${!user_password}|${!user_name}"$'\n' ;
|
|
371
|
+
done
|
|
372
|
+
panel_path="$(filament_panel_path "${project_path}")" ;
|
|
373
|
+
|
|
374
|
+
python3 - "${project_path}" "${FILAMENT_STEPS_PACKAGE}" "${FILAMENT_STEPS_VERSION}" 'FILAMENT' "${registry}" "${panel_path}" <<'PYEOF' || return 1
|
|
375
|
+
import json, re, sys
|
|
376
|
+
|
|
377
|
+
project, pack, version, prefix, registry, panel = sys.argv[1:7]
|
|
378
|
+
|
|
379
|
+
# package.json: the pack as a dev dependency, at the release line this plugin was proven on.
|
|
380
|
+
pkg_file = project + '/package.json'
|
|
381
|
+
pkg = json.load(open(pkg_file))
|
|
382
|
+
if pack not in pkg.get('dependencies', {}) and pack not in pkg.get('devDependencies', {}):
|
|
383
|
+
pkg.setdefault('devDependencies', {})[pack] = version
|
|
384
|
+
open(pkg_file, 'w').write(json.dumps(pkg, indent=4) + '\n')
|
|
385
|
+
print(' package.json: %s %s' % (pack, version))
|
|
386
|
+
|
|
387
|
+
cucumber_file = project + '/cucumber.js'
|
|
388
|
+
src = open(cucumber_file).read()
|
|
389
|
+
before = src
|
|
390
|
+
|
|
391
|
+
# The pack's step definitions, after webship-js's own. The pack loads the Laravel pack's itself.
|
|
392
|
+
if ('node_modules/%s/' % pack) not in src:
|
|
393
|
+
line = "'node_modules/%s/tests/step-definitions/**/*.js'," % pack
|
|
394
|
+
anchor = re.search(r"^([ \t]*)'node_modules/webship-js/tests/step-definitions/[^']*',.*$", src, re.M)
|
|
395
|
+
opening = re.search(r"^([ \t]*)require:[ \t]*\[[ \t]*$", src, re.M)
|
|
396
|
+
if anchor:
|
|
397
|
+
src = src[:anchor.end()] + '\n' + anchor.group(1) + line + src[anchor.end():]
|
|
398
|
+
elif opening:
|
|
399
|
+
src = src[:opening.end()] + '\n' + opening.group(1) + ' ' + line + src[opening.end():]
|
|
400
|
+
else:
|
|
401
|
+
sys.exit(" cucumber.js has no require list this can add to. Add this line to it:\n " + line)
|
|
402
|
+
print(' cucumber.js: the step definitions of %s' % pack)
|
|
403
|
+
|
|
404
|
+
# The pack's assertions that must fail, and the Laravel pack's lanes, are no part of a normal run.
|
|
405
|
+
if not re.search(r"^[ \t]*tags:", src, re.M):
|
|
406
|
+
default = re.search(r"^([ \t]*)default:[ \t]*\{[ \t]*$", src, re.M)
|
|
407
|
+
if default:
|
|
408
|
+
pad = default.group(1) + ' '
|
|
409
|
+
src = src[:default.end()] + '\n' + pad + "// Work in progress, the assertions that must fail and the Laravel pack's lanes (@maintenance, @debug-page) stay out of a normal run.\n" \
|
|
410
|
+
+ pad + "tags: process.env.CUCUMBER_TAGS || 'not @wip and not @must-fail and not @maintenance and not @debug-page'," + src[default.end():]
|
|
411
|
+
print(' cucumber.js: the tags that keep the assertions that must fail out of a normal run')
|
|
412
|
+
|
|
413
|
+
world = re.search(r"^([ \t]*)worldParameters:[ \t]*\{[ \t]*$", src, re.M)
|
|
414
|
+
if not world:
|
|
415
|
+
sys.exit(" cucumber.js has no worldParameters block to add the users registry to.")
|
|
416
|
+
pad = world.group(1) + ' '
|
|
417
|
+
additions = []
|
|
418
|
+
if not re.search(r"^[ \t]*homePath:", src, re.M):
|
|
419
|
+
login = (panel.rstrip('/') or '') + '/login'
|
|
420
|
+
additions += [
|
|
421
|
+
pad + "// The panel's home and its login page (the login steps of the Laravel pack read them).",
|
|
422
|
+
pad + "homePath: '%s'," % panel,
|
|
423
|
+
pad + "loginPath: '%s'," % login,
|
|
424
|
+
]
|
|
425
|
+
if not re.search(r"^[ \t]*mailUrl:", src, re.M):
|
|
426
|
+
additions += [
|
|
427
|
+
pad + "// The mailbox that catches the mail of the app (the password reset steps read it).",
|
|
428
|
+
pad + "mailUrl: process.env.MAIL_URL || (process.env.LAUNCH_URL || '').replace(/\\/+$/, '') + ':8026',",
|
|
429
|
+
]
|
|
430
|
+
if not re.search(r"^[ \t]*users:[ \t]*\{", src, re.M):
|
|
431
|
+
rows = [r.split('|') for r in registry.splitlines() if r.strip()]
|
|
432
|
+
additions += [
|
|
433
|
+
pad + "// The users registry: a handle a scenario reads, mapped to an account of this app (the default",
|
|
434
|
+
pad + "// accounts: cmd-tools-add-users.sh <project> filament). Override one with %s_<HANDLE>_EMAIL and %s_<HANDLE>_PASSWORD." % (prefix, prefix),
|
|
435
|
+
pad + "users: {",
|
|
436
|
+
]
|
|
437
|
+
for handle, email, password, name in rows:
|
|
438
|
+
env = '%s_%s' % (prefix, handle.upper())
|
|
439
|
+
additions.append(pad + " %s: { email: process.env.%s_EMAIL || '%s', password: process.env.%s_PASSWORD || '%s', name: '%s' }," % (handle, env, email, env, password, name))
|
|
440
|
+
additions.append(pad + "},")
|
|
441
|
+
print(' cucumber.js: the users registry (%s)' % ', '.join(r[0] for r in rows))
|
|
442
|
+
if additions:
|
|
443
|
+
src = src[:world.end()] + '\n' + '\n'.join(additions) + src[world.end():]
|
|
444
|
+
|
|
445
|
+
# An app's package.json says "type": "module" (Vite's convention): cucumber.js becomes an ES module
|
|
446
|
+
# that exports the same default profile, and tests/ gets a package.json that keeps it CommonJS (the
|
|
447
|
+
# Laravel plugin's hook does the same; whichever runs first does it).
|
|
448
|
+
if pkg.get('type') == 'module':
|
|
449
|
+
if re.search(r"^module\.exports\s*=\s*\{", src, re.M) and not re.search(r"^export default ", src, re.M):
|
|
450
|
+
src = re.sub(r"^module\.exports\s*=\s*\{", "// The app's package.json says \"type\": \"module\": this file is an ES module, the profiles stay as they were.\nconst config = {", src, count=1, flags=re.M)
|
|
451
|
+
src = src.rstrip() + '\n\nexport default config.default;\n'
|
|
452
|
+
print(' cucumber.js: an ES module (the package.json of the app says "type": "module")')
|
|
453
|
+
import os
|
|
454
|
+
tests_pkg = project + '/tests/package.json'
|
|
455
|
+
if not os.path.exists(tests_pkg):
|
|
456
|
+
os.makedirs(project + '/tests', exist_ok=True)
|
|
457
|
+
open(tests_pkg, 'w').write(json.dumps({'type': 'commonjs'}, indent=2) + '\n')
|
|
458
|
+
print(' tests/package.json: the step definitions under tests/ stay CommonJS')
|
|
459
|
+
|
|
460
|
+
if src != before:
|
|
461
|
+
open(cucumber_file, 'w').write(src)
|
|
462
|
+
PYEOF
|
|
463
|
+
|
|
464
|
+
# A first feature for the panel, as the project's site.feature when it has none: the Laravel plugin's
|
|
465
|
+
# hook then keeps it, and places no starter-kit feature in a panel's project.
|
|
466
|
+
local feature="${WORKSPACE_SCRIPTS}/plugins/filament/panel.feature" login_path ;
|
|
467
|
+
login_path="${panel_path%/}/login" ;
|
|
468
|
+
if [ -f "${feature}" ] && [ ! -f "${project_path}/tests/features/site.feature" ] ; then
|
|
469
|
+
mkdir -p "${project_path}/tests/features" \
|
|
470
|
+
&& sed -e "s#__PANEL_PATH__#${panel_path}#g" -e "s#__LOGIN_PATH__#${login_path}#g" "${feature}" > "${project_path}/tests/features/site.feature" \
|
|
471
|
+
&& echo " tests/features/site.feature: a first feature for the panel" ;
|
|
472
|
+
fi
|
|
473
|
+
|
|
474
|
+
# The scenarios log in as the default accounts: make sure a migrated app has them.
|
|
475
|
+
if filament_artisan migrate:status > /dev/null 2>&1 ; then
|
|
476
|
+
( add_filament_users > /dev/null ) && echo " the panel's default accounts are on the app (${users[*]})" ;
|
|
477
|
+
fi
|
|
478
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
Feature: The panel answers and its accounts work
|
|
2
|
+
As the owner of the app
|
|
3
|
+
I want the panel's login page, its dashboard and each default account to work
|
|
4
|
+
So that a build that came out broken is caught before anything else is tested
|
|
5
|
+
|
|
6
|
+
# Placed by the workspace's testing setup as a starting point: it is yours to change.
|
|
7
|
+
# The accounts are the default ones (cmd-tools-add-users.sh <project> filament); a scenario logs in by
|
|
8
|
+
# a handle of the users registry in cucumber.js, so no password is written here.
|
|
9
|
+
|
|
10
|
+
@critical
|
|
11
|
+
Scenario: A visitor is sent to the login form of the panel
|
|
12
|
+
Given I am an anonymous user
|
|
13
|
+
When I go to "__PANEL_PATH__"
|
|
14
|
+
Then I should see the login form
|
|
15
|
+
|
|
16
|
+
@critical
|
|
17
|
+
Scenario: The administrator logs in, and the panel names it
|
|
18
|
+
Given I am a logged in user with the "administrator" user
|
|
19
|
+
Then I should be logged in as "administrator"
|
|
20
|
+
And the user menu should offer "Sign out"
|
|
21
|
+
|
|
22
|
+
@js-off
|
|
23
|
+
Scenario: The panel refuses the account whose address is not verified
|
|
24
|
+
Given I am an anonymous user
|
|
25
|
+
When I go to "__LOGIN_PATH__"
|
|
26
|
+
And I fill in "Email address" with the email of "unverified"
|
|
27
|
+
And I fill in "Password" with the password of "unverified"
|
|
28
|
+
And I press "Sign in"
|
|
29
|
+
Then the "Email address" field should have the error "These credentials do not match our records."
|
|
30
|
+
|
|
31
|
+
Scenario: The health route answers that the app is up
|
|
32
|
+
Given I am an anonymous user
|
|
33
|
+
When I go to "/up"
|
|
34
|
+
Then the response status code should be 200
|