@webship.co/workspace-ghost 0.0.0-stage → 1.0.7

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.
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env bash
2
+
3
+ argparse "$@" <<ARGEOF || exit 1
4
+ parser.add_argument('PROJECT_NAME',
5
+ help='The Ghost project in this workspace.')
6
+ parser.add_argument('-r', '--run',
7
+ default="_none_",
8
+ help='A Ghost-CLI command to run in the project, without the leading ghost. Example: --run "doctor"')
9
+ parser.add_argument('-u', '--update',
10
+ action='store_true',
11
+ default=False,
12
+ help='Update Ghost to the latest release and start it again.')
13
+ parser.add_argument('-s', '--restart',
14
+ action='store_true',
15
+ default=False,
16
+ help='Start Ghost again, and wait until it answers.')
17
+ parser.add_argument('-a', '--add-users',
18
+ action='store_true',
19
+ default=False,
20
+ help='Add the default staff accounts, one per role. An account that is already there is left as it is.')
21
+ parser.add_argument('-c', '--cancel-users',
22
+ action='store_true',
23
+ default=False,
24
+ help='Delete the default staff accounts and what they wrote.')
25
+ ARGEOF
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env bash
2
+
3
+ argparse "$@" <<ARGEOF || exit 1
4
+ parser.add_argument('PROJECT_NAME',
5
+ help='The name of the project: its folder, its DDEV project and its host name.')
6
+ parser.add_argument('-v', '--version',
7
+ default="${site_version}",
8
+ help='The Ghost release to install: latest, or a version number. Example: --version 6.77.0 [default %(default)s]')
9
+ parser.add_argument('-i', '--install',
10
+ action='store_true',
11
+ default=False,
12
+ help='Set the site up, with the workspace account as its owner.')
13
+ parser.add_argument('-a', '--add-users',
14
+ action='store_true',
15
+ default=False,
16
+ help='With --install, add the default staff accounts: one per role, the ones the test scenarios sign in as.')
17
+ parser.add_argument('-l', '--launch',
18
+ action='store_true',
19
+ default=False,
20
+ help='Open the site in a browser when it is ready.')
21
+ ARGEOF
@@ -0,0 +1,464 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # Ghost for the Webship Workspace: build a self-hosted site, run Ghost-CLI on it, add its default
4
+ # staff accounts, and wire its step pack into the testing setup.
5
+ #
6
+ # Placed by `plugins.sh --install ghost` in core/scripts/plugins/ghost/functions/, where bootstrap
7
+ # sources it after the core's own functions. Everything runs in the project's container (DDEV by
8
+ # default), never on the host: the web container runs Node.js and starts Ghost as an extra daemon,
9
+ # the router serves it at the project's address, MySQL 8 is the container tool's database, and the
10
+ # mail of the site goes to the mailbox of the container. No hosted service and no payment provider
11
+ # is connected.
12
+ #
13
+ # Ghost is not a PHP platform and DDEV has no project type for it, so a Ghost project is recognised
14
+ # by a file (.ddev/config.ghost.yaml, written by the builder), and four names are the ones the
15
+ # core's tools look for:
16
+ # set_ghost_users the default staff accounts (cmd-tools-add-users.sh <project> ghost)
17
+ # add_ghost_users create them through the Admin API (the same tool, and --add-users of the builder)
18
+ # cancel_ghost_users delete them (cmd-tools-cancel-users.sh <project> ghost)
19
+ # testing_configure_ghost the step pack in the testing stack (cmd-tools-testing.sh <project>)
20
+
21
+ # The step pack a Ghost project is tested with, and the release line it is required at.
22
+ readonly GHOST_STEPS_PACKAGE='@webship-js/ghost-steps';
23
+ readonly GHOST_STEPS_VERSION='^2.0.0';
24
+
25
+ # Ghost-CLI, the official installer and command line, run with npx in the container.
26
+ readonly GHOST_CLI_PACKAGE='ghost-cli@latest';
27
+
28
+ # Where Ghost lives in the web container, and the port it listens on.
29
+ readonly GHOST_DIR='/var/www/html/ghost';
30
+ readonly GHOST_PORT='2368';
31
+
32
+ # The default staff accounts: one per role, the ones a scenario signs in as. Accounts are
33
+ # configuration, created once on the site; a test suite never creates or deletes one. The owner of
34
+ # the site is the workspace account and is not in this list.
35
+ function set_ghost_users() {
36
+ users=(administrator editor author contributor);
37
+ local user ;
38
+ for user in "${users[@]}" ; do
39
+ printf -v "user_${user}_name" '%s' "${user}" ;
40
+ printf -v "user_${user}_mail" '%s' "${user}@example.com" ;
41
+ printf -v "user_${user}_password" '%s' 'dD.123123ddd' ;
42
+ # The roles of Ghost are written with a capital: Administrator, Editor, Author, Contributor.
43
+ printf -v "user_${user}_role" '%s' "${user^}" ;
44
+ done
45
+ }
46
+
47
+ # Is this folder a Ghost project? The builder leaves .ddev/config.ghost.yaml in it.
48
+ function ghost_is_project() {
49
+ local project_path="$1";
50
+ [ -f "${project_path}/.ddev/config.ghost.yaml" ] ;
51
+ }
52
+
53
+ # Go to the project a tool was asked about, or say why not.
54
+ function ghost_enter_project() {
55
+ local project_path="${WORKSPACE_ROOT}/${doc_name}/${PROJECT_NAME}";
56
+ if [ ! -d "${project_path}" ] ; then
57
+ echo "No project ${PROJECT_NAME} in ${WORKSPACE_ROOT}/${doc_name}." ;
58
+ return 1 ;
59
+ fi
60
+ if ! ghost_is_project "${project_path}" ; then
61
+ echo "${doc_name}/${PROJECT_NAME} is not a Ghost project (it has no .ddev/config.ghost.yaml)." ;
62
+ return 1 ;
63
+ fi
64
+ cd "${project_path}" || return 1 ;
65
+ }
66
+
67
+ # What the container tool is told about Ghost: the router sends the project's address to Ghost's
68
+ # port, and Ghost runs as a daemon of the web container once the build has finished.
69
+ function ghost_write_ddev_config() {
70
+ local project_path="$1";
71
+ mkdir -p "${project_path}/.ddev" || return 1 ;
72
+ cat > "${project_path}/.ddev/config.ghost.yaml" <<YAMLEOF
73
+ # Ghost in this project. Written by the Ghost builder of the workspace; build again rather than
74
+ # editing by hand. The web container serves no files of its own: the router sends ports 80 and 443
75
+ # of the project's address to Ghost, which the web container runs as a daemon.
76
+ web_extra_exposed_ports:
77
+ - name: ghost
78
+ container_port: ${GHOST_PORT}
79
+ http_port: 80
80
+ https_port: 443
81
+ web_extra_daemons:
82
+ - name: ghost
83
+ command: "bash -c 'while [ ! -f ${GHOST_DIR}/.ready ]; do sleep 2; done; cd ${GHOST_DIR} && NODE_ENV=production exec node current/index.js'"
84
+ directory: /var/www/html
85
+ YAMLEOF
86
+ }
87
+
88
+ # Node.js in the web image itself. The container tool installs the Node.js of the project when the
89
+ # container starts, after the daemons have started and within a short time limit: on a slow
90
+ # connection, or offline, Ghost would be started on the image's older Node.js and refuse to run.
91
+ # Baked into the image, the Node.js Ghost needs is there before anything starts, on every restart.
92
+ function ghost_write_web_build() {
93
+ local project_path="$1" nodejs_version="$2";
94
+ mkdir -p "${project_path}/.ddev/web-build" || return 1 ;
95
+ cat > "${project_path}/.ddev/web-build/Dockerfile.ghost" <<DOCKEREOF
96
+ # Node.js ${nodejs_version} in the web image, so Ghost has it before the container's daemons start.
97
+ # Written by the Ghost builder of the workspace; build again rather than editing by hand.
98
+ RUN N_PREFIX=/usr/local n install ${nodejs_version} && node --version
99
+ DOCKEREOF
100
+ }
101
+
102
+ # The configuration of the site: the container's own database (db/db/db), the mailbox of the
103
+ # container, no update check and no call to an outside service. Nothing personal is written.
104
+ function ghost_write_config() {
105
+ local project_path="$1" base_url="$2" title="$3";
106
+ cat > "${project_path}/ghost/config.production.json" <<JSONEOF
107
+ {
108
+ "url": "${base_url}",
109
+ "server": { "host": "0.0.0.0", "port": ${GHOST_PORT} },
110
+ "database": {
111
+ "client": "mysql",
112
+ "connection": { "host": "db", "port": 3306, "user": "db", "password": "db", "database": "db" }
113
+ },
114
+ "mail": {
115
+ "transport": "SMTP",
116
+ "from": "'${title}' <noreply@example.com>",
117
+ "options": { "host": "127.0.0.1", "port": 1025, "secure": false, "ignoreTLS": true }
118
+ },
119
+ "logging": { "transports": ["file", "stdout"] },
120
+ "process": "local",
121
+ "paths": { "contentPath": "${GHOST_DIR}/content" },
122
+ "privacy": { "useTinfoil": true },
123
+ "explore": { "update_url": "" },
124
+ "security": { "staffDeviceVerification": false },
125
+ "spam": {
126
+ "user_login": { "freeRetries": 100000 },
127
+ "staff_invite_block": { "freeRetries": 100000 },
128
+ "member_login": { "freeRetries": 100000 },
129
+ "global_block": { "freeRetries": 100000 },
130
+ "global_reset": { "freeRetries": 100000 },
131
+ "private_block": { "freeRetries": 100000 },
132
+ "content_api_key": { "freeRetries": 100000 },
133
+ "email_preview_block": { "freeRetries": 100000 },
134
+ "webmentions_block": { "freeRetries": 100000 }
135
+ }
136
+ }
137
+ JSONEOF
138
+ }
139
+
140
+ # Ghost-CLI in the container, in the folder of the site.
141
+ function ghost_cli() {
142
+ ddev exec -d "${GHOST_DIR}" "npx --yes ${GHOST_CLI_PACKAGE} $*" ;
143
+ }
144
+
145
+ # The release of Ghost the project runs.
146
+ function ghost_version() {
147
+ ddev exec "node -p \"require('${GHOST_DIR}/current/package.json').version\"" 2>/dev/null ;
148
+ }
149
+
150
+ # The address the site is configured with.
151
+ function ghost_site_url() {
152
+ sed -n 's/^ *"url": *"\([^"]*\)".*/\1/p' ghost/config.production.json 2>/dev/null | head -n 1 ;
153
+ }
154
+
155
+ # Wait until Ghost answers on its own port. It creates its tables on the first start, so the
156
+ # first wait is the long one.
157
+ function ghost_wait() {
158
+ local attempt ;
159
+ for attempt in $(seq 1 120) ; do
160
+ if ddev exec "curl -fsS -o /dev/null -H 'X-Forwarded-Proto: https' http://127.0.0.1:${GHOST_PORT}/ghost/api/admin/site/" > /dev/null 2>&1 ; then
161
+ return 0 ;
162
+ fi
163
+ sleep 5 ;
164
+ done
165
+ echo "Ghost did not start; the end of its log:" ;
166
+ ddev exec "tail -n 40 ${GHOST_DIR}/content/logs/*.log" 2>/dev/null ;
167
+ return 1 ;
168
+ }
169
+
170
+ # Start Ghost again (the daemon of the web container), and wait for it.
171
+ function ghost_restart() {
172
+ ddev exec "supervisorctl restart webextradaemons:ghost" || return 1 ;
173
+ ghost_wait ;
174
+ }
175
+
176
+ # Run a verb of ghost-accounts.js (installed, setup, add, cancel, list) in the container. The
177
+ # script is piped to node, and what it needs travels as base64 of a JSON object, so no password is
178
+ # written into a file of the project and no quoting can break a value.
179
+ function ghost_accounts() {
180
+ local verb="$1" script="${WORKSPACE_SCRIPTS}/plugins/ghost/ghost-accounts.js" rows="" user name mail password role payload ;
181
+ if [ ! -f "${script}" ] ; then
182
+ echo "ghost-accounts.js is not in ${WORKSPACE_SCRIPTS}/plugins/ghost: install the plugin (plugins.sh --install ghost)." ;
183
+ return 1 ;
184
+ fi
185
+ for user in "${users[@]}" ; do
186
+ name="user_${user}_name"; mail="user_${user}_mail"; password="user_${user}_password"; role="user_${user}_role";
187
+ rows="${rows}${!name}"$'\x1f'"${!mail}"$'\x1f'"${!password}"$'\x1f'"${!role}"$'\x1e' ;
188
+ done
189
+ payload="$(GHOST_SITE_URL="${ghost_url:-$(ghost_site_url)}" GHOST_SITE_TITLE="${ghost_title:-}" \
190
+ GHOST_OWNER_NAME="${account_name}" GHOST_OWNER_MAIL="${account_mail}" GHOST_OWNER_PASS="${account_pass}" \
191
+ GHOST_STAFF="${rows}" python3 -c '
192
+ import base64, json, os
193
+ staff = [dict(zip(("name", "email", "password", "role"), row.split("\x1f"))) for row in os.environ["GHOST_STAFF"].split("\x1e") if row]
194
+ print(base64.b64encode(json.dumps({
195
+ "url": os.environ["GHOST_SITE_URL"], "title": os.environ["GHOST_SITE_TITLE"],
196
+ "owner": {"name": os.environ["GHOST_OWNER_NAME"], "email": os.environ["GHOST_OWNER_MAIL"], "password": os.environ["GHOST_OWNER_PASS"]},
197
+ "staff": staff,
198
+ }).encode()).decode())')" || return 1 ;
199
+ ddev exec "GHOST_ACCOUNTS=${payload} node - ${verb}" < "${script}" ;
200
+ }
201
+
202
+ # Build a Ghost site from nothing: the container, the code, and with --install the site itself.
203
+ function ghost_build() {
204
+ trim_project_name ;
205
+ local base_url="https://${PROJECT_NAME}.ddev.site" ;
206
+ local version="${VERSION:-${site_version:-latest}}" ;
207
+ local project_path="${WORKSPACE_ROOT}/${doc_name}/${PROJECT_NAME}" ;
208
+ local title="${doc_name} ${PROJECT_NAME}" ;
209
+ [ "${version}" == 'latest' ] && version="" ;
210
+
211
+ cd ${WORKSPACE_ROOT}/${doc_name} || exit 1 ;
212
+
213
+ drop_database ;
214
+ rm -rf "${PROJECT_NAME}" ;
215
+ mkdir -p "${PROJECT_NAME}/ghost" ;
216
+ cd "${project_path}" || exit 1 ;
217
+
218
+ # A generic web server: no nginx and no PHP are started. Ghost needs MySQL 8.
219
+ ddev config --project-type=generic --webserver-type=generic --docroot="" --project-name=${PROJECT_NAME} \
220
+ --database=mysql:8.0 --nodejs-version=$(ddev_nodejs_version) || exit 1 ;
221
+ ghost_write_ddev_config "${project_path}" || exit 1 ;
222
+ ghost_write_web_build "${project_path}" "$(ddev_nodejs_version)" || exit 1 ;
223
+ ddev_up start -y || exit 1 ;
224
+
225
+ # The official install path: Ghost-CLI downloads the release and its dependencies. --no-setup:
226
+ # the configuration is written below instead of asked for.
227
+ echo "Installing Ghost ${version:-(the latest release)} with Ghost-CLI. This takes a few minutes." ;
228
+ ghost_cli install ${version} --no-setup --no-stack --no-start --no-prompt --dir "${GHOST_DIR}" \
229
+ || { echo "ghost install failed." ; exit 1 ; } ;
230
+
231
+ ghost_write_config "${project_path}" "${base_url}" "${title}" ;
232
+ touch "${project_path}/ghost/.ready" ;
233
+ echo "Starting Ghost. The first start creates the tables." ;
234
+ ghost_restart || exit 1 ;
235
+
236
+ if [ "${INSTALL}" == 'yes' ] ; then
237
+ # Ghost refuses a password under 10 characters, and the owner is the workspace account.
238
+ if [ "${#account_pass}" -lt 10 ] ; then
239
+ echo "Ghost asks for a password of 10 characters or more, and the workspace account's is shorter" ;
240
+ echo "(account: pass in core/config/settings.yml). The site is built; finish its setup at ${base_url}/ghost" ;
241
+ exit 1 ;
242
+ fi
243
+ ghost_url="${base_url}" ; ghost_title="${title}" ;
244
+ users=() ;
245
+ ghost_accounts setup || { echo "The setup of the site failed." ; exit 1 ; } ;
246
+
247
+ if [ "${ADD_USERS}" == 'yes' ] ; then
248
+ set_ghost_users ;
249
+ add_ghost_users ;
250
+ cd "${project_path}" || exit 1 ;
251
+ fi
252
+
253
+ echo "${doc_name} ${PROJECT_NAME} has been installed: Ghost $(ghost_version).";
254
+ echo "Go to ${base_url}/ghost and sign in as ${account_mail}";
255
+ else
256
+ [ "${ADD_USERS}" == 'yes' ] && echo "--add-users needs --install: there is no site to add accounts to yet." ;
257
+ echo "${doc_name} ${PROJECT_NAME} is ready to set up: Ghost $(ghost_version).";
258
+ echo "Go to ${base_url}/ghost";
259
+ fi
260
+
261
+ if [ "${LAUNCH}" == 'yes' ] ; then
262
+ ddev launch ;
263
+ fi
264
+
265
+ cd ${WORKSPACE_ROOT}/${doc_name};
266
+ }
267
+
268
+ # Create the default staff accounts through the Admin API: each is invited, and the invitation is
269
+ # accepted from the mailbox of the container. An account that is already there is left as it is.
270
+ # The list is loaded by the caller (set_ghost_users): the core's add_users, the builder, the CLI tool.
271
+ function add_ghost_users() {
272
+ ghost_enter_project || return 1 ;
273
+ local user user_name user_mail user_password user_role ;
274
+ for user in "${users[@]}" ; do
275
+ user_name="user_${user}_name"; user_mail="user_${user}_mail";
276
+ user_password="user_${user}_password"; user_role="user_${user}_role";
277
+
278
+ echo " ---------------------------------------------------------------- ";
279
+ echo " User name: ${!user_name}";
280
+ echo " User mail: ${!user_mail}";
281
+ echo " User password: ${!user_password}";
282
+ echo " User role: ${!user_role}";
283
+ echo " ================================================================= ";
284
+ done
285
+ ghost_accounts add ;
286
+ local status=$? ;
287
+ cd ${WORKSPACE_ROOT}/${doc_name};
288
+ return ${status} ;
289
+ }
290
+
291
+ # Delete the default staff accounts, and what they wrote.
292
+ function cancel_ghost_users() {
293
+ ghost_enter_project || return 1 ;
294
+ local user user_mail ;
295
+ for user in "${users[@]}" ; do
296
+ user_mail="user_${user}_mail";
297
+ echo " ---------------------------------------------------------------- ";
298
+ echo " User mail: ${!user_mail}";
299
+ echo " ================================================================= ";
300
+ done
301
+ ghost_accounts cancel ;
302
+ local status=$? ;
303
+ cd ${WORKSPACE_ROOT}/${doc_name};
304
+ return ${status} ;
305
+ }
306
+
307
+ # What cmd-tools-ghost-cli.sh does: the first of --run, --update, --restart, --add-users,
308
+ # --cancel-users that was asked for; with none of them, what the site is.
309
+ function ghost_cli_tool() {
310
+ trim_project_name ;
311
+ ghost_enter_project || exit 1 ;
312
+
313
+ if ! ddev describe -j 2>/dev/null | grep -q '"status":"running"' ; then
314
+ ddev start -y || exit 1 ;
315
+ fi
316
+
317
+ if [ ! "${RUN}" == '_none_' ] ; then
318
+ # Unquoted on purpose: --run "config get url" is a command and its arguments.
319
+ ghost_cli ${RUN} ;
320
+ exit $? ;
321
+ fi
322
+
323
+ if [ "${UPDATE}" == 'yes' ] ; then
324
+ echo "Ghost $(ghost_version) is installed." ;
325
+ # Ghost-CLI does not manage the process here (the web container does): update, then start again.
326
+ ghost_cli update --no-restart --no-prompt || exit 1 ;
327
+ ghost_restart || exit 1 ;
328
+ echo "Ghost $(ghost_version) is running." ;
329
+ elif [ "${RESTART}" == 'yes' ] ; then
330
+ ghost_restart || exit 1 ;
331
+ echo "Ghost $(ghost_version) is running." ;
332
+ elif [ "${ADD_USERS}" == 'yes' ] ; then
333
+ set_ghost_users ;
334
+ add_ghost_users ;
335
+ elif [ "${CANCEL_USERS}" == 'yes' ] ; then
336
+ set_ghost_users ;
337
+ cancel_ghost_users ;
338
+ else
339
+ echo "${doc_name}/${PROJECT_NAME}: Ghost $(ghost_version) at $(ghost_site_url)" ;
340
+ echo "" ; echo "Accounts:" ;
341
+ users=() ;
342
+ if ghost_accounts installed ; then
343
+ ghost_accounts list ;
344
+ else
345
+ echo " The site is not set up yet: finish its setup at $(ghost_site_url)/ghost" ;
346
+ fi
347
+ fi
348
+ cd ${WORKSPACE_ROOT}/${doc_name};
349
+ }
350
+
351
+ # The step pack in the testing stack of a Ghost project. The core's testing_configure calls this in
352
+ # the project folder once webship-js is scaffolded and before the dependencies are installed; for a
353
+ # project that is not Ghost it changes nothing.
354
+ #
355
+ # It adds the pack to package.json, lists its step definitions in cucumber.js after webship-js's
356
+ # own, gives cucumber.js the users registry of the default staff accounts (a handle a scenario
357
+ # reads, mapped to an account; never the workspace account), the address of the mailbox the
358
+ # membership steps read and the pack's setting for the JavaScript errors of the admin, and writes a first feature when the project has none of its own. Every
359
+ # part is skipped when it is already there, so a second run adds what the first missed and never
360
+ # resets a suite.
361
+ function testing_configure_ghost() {
362
+ local project_path="$1";
363
+ ghost_is_project "${project_path}" || return 0 ;
364
+ if [ ! -f "${project_path}/cucumber.js" ] || [ ! -f "${project_path}/package.json" ] ; then
365
+ echo " Ghost: cucumber.js is not here yet — run the testing setup again once webship-js is scaffolded." ;
366
+ return 1 ;
367
+ fi
368
+
369
+ echo "Adding the Ghost step pack (${GHOST_STEPS_PACKAGE} ${GHOST_STEPS_VERSION}).";
370
+ set_ghost_users ;
371
+ local registry="" user user_name user_mail user_password user_role ;
372
+ for user in "${users[@]}" ; do
373
+ user_name="user_${user}_name"; user_mail="user_${user}_mail";
374
+ user_password="user_${user}_password"; user_role="user_${user}_role";
375
+ registry="${registry}${user}|${!user_name}|${!user_role}|${!user_mail}|${!user_password}"$'\n' ;
376
+ done
377
+
378
+ python3 - "${project_path}" "${GHOST_STEPS_PACKAGE}" "${GHOST_STEPS_VERSION}" 'SITE' "${registry}" <<'PYEOF' || return 1
379
+ import json, re, sys
380
+
381
+ project, pack, version, prefix, registry = sys.argv[1:6]
382
+
383
+ # package.json: the pack as a dev dependency, at the release line this plugin was proven on.
384
+ pkg_file = project + '/package.json'
385
+ pkg = json.load(open(pkg_file))
386
+ if pack not in pkg.get('dependencies', {}) and pack not in pkg.get('devDependencies', {}):
387
+ pkg.setdefault('devDependencies', {})[pack] = version
388
+ open(pkg_file, 'w').write(json.dumps(pkg, indent=2) + '\n')
389
+ print(' package.json: %s %s' % (pack, version))
390
+
391
+ # cucumber.js: the pack's step definitions after webship-js's own, the users registry, the mailbox.
392
+ cucumber_file = project + '/cucumber.js'
393
+ src = open(cucumber_file).read()
394
+ before = src
395
+
396
+ if ('node_modules/%s/' % pack) not in src:
397
+ line = "'node_modules/%s/tests/step-definitions/**/*.js'," % pack
398
+ core = re.search(r"^([ \t]*)'node_modules/webship-js/tests/step-definitions/[^']*',.*$", src, re.M)
399
+ opening = re.search(r"^([ \t]*)require:[ \t]*\[[ \t]*$", src, re.M)
400
+ if core:
401
+ src = src[:core.end()] + '\n' + core.group(1) + line + src[core.end():]
402
+ elif opening:
403
+ src = src[:opening.end()] + '\n' + opening.group(1) + ' ' + line + src[opening.end():]
404
+ else:
405
+ sys.exit(" cucumber.js has no require list this can add to. Add this line to it:\n " + line)
406
+ print(' cucumber.js: the step definitions of %s' % pack)
407
+
408
+ world = re.search(r"^([ \t]*)worldParameters:[ \t]*\{[ \t]*$", src, re.M)
409
+ if not re.search(r"^[ \t]*users:[ \t]*\{", src, re.M):
410
+ if not world:
411
+ sys.exit(" cucumber.js has no worldParameters block to add the users registry to.")
412
+ pad = world.group(1) + ' '
413
+ rows = [r.split('|') for r in registry.splitlines() if r.strip()]
414
+ block = [
415
+ pad + "// The users registry: a handle a scenario reads, mapped to a staff account of this site (the default",
416
+ pad + "// accounts: cmd-tools-add-users.sh). Override one with %s_<HANDLE>_EMAIL and %s_<HANDLE>_PASSWORD." % (prefix, prefix),
417
+ pad + "users: {",
418
+ ]
419
+ for handle, name, role, mail, password in rows:
420
+ env = '%s_%s' % (prefix, handle.upper())
421
+ block.append(pad + " %s: { name: '%s', role: '%s', email: process.env.%s_EMAIL || '%s', password: process.env.%s_PASSWORD || '%s' }," % (handle, name, role, env, mail, env, password))
422
+ block.append(pad + "},")
423
+ src = src[:world.end()] + '\n' + '\n'.join(block) + src[world.end():]
424
+ print(' cucumber.js: the users registry (%s)' % ', '.join(r[0] for r in rows))
425
+
426
+ if world and not re.search(r"^[ \t]*mailUrl:", src, re.M):
427
+ world = re.search(r"^([ \t]*)worldParameters:[ \t]*\{[ \t]*$", src, re.M)
428
+ pad = world.group(1) + ' '
429
+ block = [
430
+ pad + "// The mailbox that catches the mail of the site (the one of the project's container): the membership",
431
+ pad + "// steps read the sign in link from it. No e-mail leaves the machine.",
432
+ pad + "mailUrl: process.env.MAIL_URL || (process.env.LAUNCH_URL || process.env.DDEV_PRIMARY_URL || '').replace(/\\/+$/, '') + ':8026',",
433
+ ]
434
+ src = src[:world.end()] + '\n' + '\n'.join(block) + src[world.end():]
435
+ print(' cucumber.js: the mailbox of the site (mailUrl)')
436
+
437
+ if world and not re.search(r"^[ \t]*javascript:", src, re.M):
438
+ world = re.search(r"^([ \t]*)worldParameters:[ \t]*\{[ \t]*$", src, re.M)
439
+ pad = world.group(1) + ' '
440
+ block = [
441
+ pad + "// JavaScript errors the page raises: 'warn' reports them, 'fail' fails the scenario, 'off' ignores them; @js-fail, @js-warn and @js-off per scenario.",
442
+ pad + "// Off by default here: the admin logs an error for every request a signed-out or restricted user is refused, which is what many scenarios are about.",
443
+ pad + "javascript: { mode: process.env.WEBSHIP_JS_ERROR_MODE || 'off', levels: ['error'], ignore: '', beforeScenario: false, afterScenario: true },",
444
+ ]
445
+ src = src[:world.end()] + '\n' + '\n'.join(block) + src[world.end():]
446
+ print(' cucumber.js: JavaScript errors of the admin are not reported (javascript.mode)')
447
+
448
+ if src != before:
449
+ open(cucumber_file, 'w').write(src)
450
+ PYEOF
451
+
452
+ # A first feature, when the project has none for the site yet: the front page, the sign in
453
+ # screen, each default account in its role.
454
+ local feature="${WORKSPACE_SCRIPTS}/plugins/ghost/site.feature" ;
455
+ if [ -f "${feature}" ] && [ ! -f "${project_path}/tests/features/site.feature" ] ; then
456
+ mkdir -p "${project_path}/tests/features" && cp "${feature}" "${project_path}/tests/features/site.feature" \
457
+ && echo " tests/features/site.feature: a first feature for the site" ;
458
+ fi
459
+
460
+ # The scenarios sign in as the default accounts: make sure a site that is set up has them.
461
+ if ghost_wait > /dev/null 2>&1 && ( users=() ; ghost_accounts installed ) > /dev/null 2>&1 ; then
462
+ ( add_ghost_users > /dev/null ) && echo " the default accounts are on the site (${users[*]})" ;
463
+ fi
464
+ }