@webship.co/workspace-express 0.0.0-stage → 1.0.0
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/LICENSE +15 -0
- package/README.md +190 -2
- package/ai/agents/express-builder.md +60 -0
- package/ai/agents/express-tester.md +55 -0
- package/ai/commands/express-test.md +29 -0
- package/ai/prompts/express-build-and-test.md +20 -0
- package/ai/prompts/express-scenarios-for-a-project.md +18 -0
- package/ai/skills/express-scenarios/SKILL.md +75 -0
- package/ai/skills/express-scenarios/examples/accounts.feature +24 -0
- package/ai/skills/express-scenarios/examples/answers.feature +26 -0
- package/ai/skills/express-scenarios/examples/session.feature +10 -0
- package/ai/skills/express-scenarios/examples/static.feature +11 -0
- package/commands/cmd-express-project.sh +34 -0
- package/demo/app.js +143 -0
- package/demo/public/app.css +6 -0
- package/dist/src/index.d.ts +29 -0
- package/dist/src/index.js +53 -0
- package/dist/src/index.js.map +1 -0
- package/features/express-runtimes.feature +51 -0
- package/features/express.feature +35 -0
- package/package.json +103 -4
- package/scripts/args/arg-express.sh +42 -0
- package/scripts/docker-compose.express.yaml +33 -0
- package/scripts/functions/fun-express.sh +371 -0
- package/testing/site.feature +22 -0
package/demo/app.js
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// The demo app of @webship-js/express-steps: a small Express app, this pack's own (MIT), that shows what Express itself
|
|
4
|
+
// does, on the line of Express the build installs (5.3.0 or 4.22.3). Run by .github/scripts/build-demo.sh.
|
|
5
|
+
//
|
|
6
|
+
// - accounts: register and sign in through forms (passwords hashed with scrypt, kept in memory while it runs), a
|
|
7
|
+
// session cookie (express-session) and a flash message carried by the session;
|
|
8
|
+
// - Express's own pages: its 404 ("Cannot GET /…"), its error handler (no stack trace in production), its redirects;
|
|
9
|
+
// - express.static: ETag, 304 on revalidation, Cache-Control max-age, dotfiles ignored;
|
|
10
|
+
// - the body parsers: 400 for malformed JSON, 413 for a body over its limit;
|
|
11
|
+
// - res.format: 406 for a type it does not offer.
|
|
12
|
+
//
|
|
13
|
+
// The session secret is read from the file SESSION_SECRET_FILE names (made at build time, 0600), never from the code.
|
|
14
|
+
|
|
15
|
+
const crypto = require('crypto');
|
|
16
|
+
const fs = require('fs');
|
|
17
|
+
const path = require('path');
|
|
18
|
+
const express = require('express');
|
|
19
|
+
const session = require('express-session');
|
|
20
|
+
|
|
21
|
+
const secretFile = process.env.SESSION_SECRET_FILE;
|
|
22
|
+
if (!secretFile || !fs.existsSync(secretFile)) {
|
|
23
|
+
console.error('Set SESSION_SECRET_FILE to the file of the session secret.');
|
|
24
|
+
process.exit(1);
|
|
25
|
+
}
|
|
26
|
+
const secret = fs.readFileSync(secretFile, 'utf8').trim();
|
|
27
|
+
|
|
28
|
+
const app = express();
|
|
29
|
+
const accounts = new Map();
|
|
30
|
+
|
|
31
|
+
// Behind a TLS proxy (a router, an ingress), the proxy's X-Forwarded-Proto says the request came over HTTPS: trusted
|
|
32
|
+
// from the one proxy in front, so the session cookie below is Secure there, and not on plain http.
|
|
33
|
+
app.set('trust proxy', 1);
|
|
34
|
+
|
|
35
|
+
const page = (title, body, who) => `<!doctype html>
|
|
36
|
+
<html lang="en"><head><meta charset="utf-8"><title>${title} - Webship demo</title>
|
|
37
|
+
<link rel="icon" href="data:,"><link rel="stylesheet" href="/app.css"></head>
|
|
38
|
+
<body><header><a href="/">Webship demo</a> ${who ? `<span class="who">Signed in as ${who}</span>
|
|
39
|
+
<form method="post" action="/logout"><button type="submit">Sign out</button></form>` : '<a href="/login">Sign in</a> <a href="/register">Register</a>'}</header>
|
|
40
|
+
<main>${body}</main></body></html>`;
|
|
41
|
+
|
|
42
|
+
const esc = (s) => String(s).replace(/[&<>"']/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[c]));
|
|
43
|
+
|
|
44
|
+
const hash = (password, salt = crypto.randomBytes(16).toString('hex')) => `${salt}:${crypto.scryptSync(password, salt, 32).toString('hex')}`;
|
|
45
|
+
const matches = (password, stored) => {
|
|
46
|
+
const [salt, digest] = stored.split(':');
|
|
47
|
+
return crypto.timingSafeEqual(Buffer.from(digest, 'hex'), crypto.scryptSync(password, salt, 32));
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
app.use(express.static(path.join(__dirname, 'public'), { maxAge: '1h', dotfiles: 'ignore' }));
|
|
51
|
+
app.use(session({
|
|
52
|
+
name: 'webship.sid',
|
|
53
|
+
secret,
|
|
54
|
+
resave: false,
|
|
55
|
+
saveUninitialized: false,
|
|
56
|
+
// secure: 'auto': Secure when the request came over HTTPS (req.secure, through trust proxy), not on plain http.
|
|
57
|
+
cookie: { httpOnly: true, sameSite: 'lax', secure: 'auto' },
|
|
58
|
+
}));
|
|
59
|
+
app.use(express.urlencoded({ extended: false, limit: '2kb' }));
|
|
60
|
+
|
|
61
|
+
// The flash message of the request before, said once.
|
|
62
|
+
app.use((req, res, next) => {
|
|
63
|
+
res.locals.flash = req.session && req.session.flash;
|
|
64
|
+
if (req.session && req.session.flash) delete req.session.flash;
|
|
65
|
+
next();
|
|
66
|
+
});
|
|
67
|
+
const flash = (req, text) => { req.session.flash = text; };
|
|
68
|
+
const said = (res) => (res.locals.flash ? `<p class="flash" role="status">${esc(res.locals.flash)}</p>` : '');
|
|
69
|
+
|
|
70
|
+
app.get('/', (req, res) => {
|
|
71
|
+
res.send(page('Home', `${said(res)}<h1>Webship demo</h1><p>${req.session.user ? `Welcome back, ${esc(req.session.user)}.` : 'Sign in to see your account.'}</p>`, req.session.user && esc(req.session.user)));
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
const form = (title, action, button) => `<h1>${title}</h1>
|
|
75
|
+
<form method="post" action="${action}">
|
|
76
|
+
<label for="username">User name</label><input id="username" name="username" autocomplete="username" required>
|
|
77
|
+
<label for="password">Password</label><input id="password" name="password" type="password" required>
|
|
78
|
+
<button type="submit">${button}</button></form>`;
|
|
79
|
+
|
|
80
|
+
app.get('/register', (req, res) => res.send(page('Register', said(res) + form('Register', '/register', 'Register'))));
|
|
81
|
+
app.post('/register', (req, res) => {
|
|
82
|
+
const { username = '', password = '' } = req.body || {};
|
|
83
|
+
if (!username.trim() || password.length < 8) { flash(req, 'A user name and a password of 8 characters or more, please.'); return res.redirect('/register'); }
|
|
84
|
+
if (accounts.has(username)) { flash(req, `The user name ${username} is taken.`); return res.redirect('/register'); }
|
|
85
|
+
accounts.set(username, hash(password));
|
|
86
|
+
flash(req, `Registered ${username}. Sign in now.`);
|
|
87
|
+
res.redirect('/login');
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
app.get('/login', (req, res) => res.send(page('Sign in', said(res) + form('Sign in', '/login', 'Sign in'))));
|
|
91
|
+
app.post('/login', (req, res, next) => {
|
|
92
|
+
const { username = '', password = '' } = req.body || {};
|
|
93
|
+
const stored = accounts.get(username);
|
|
94
|
+
if (!stored || !matches(password, stored)) { flash(req, 'Wrong user name or password.'); return res.redirect('/login'); }
|
|
95
|
+
req.session.regenerate((err) => {
|
|
96
|
+
if (err) return next(err);
|
|
97
|
+
req.session.user = username;
|
|
98
|
+
flash(req, `Signed in as ${username}.`);
|
|
99
|
+
res.redirect('/account');
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
app.post('/logout', (req, res, next) => {
|
|
103
|
+
req.session.destroy((err) => {
|
|
104
|
+
if (err) return next(err);
|
|
105
|
+
res.clearCookie('webship.sid');
|
|
106
|
+
res.redirect('/');
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
app.get('/account', (req, res) => {
|
|
111
|
+
if (!req.session.user) { flash(req, 'Sign in first.'); return res.redirect('/login'); }
|
|
112
|
+
res.send(page('Account', `${said(res)}<h1>Your account</h1><p>You are ${esc(req.session.user)}.</p>`, esc(req.session.user)));
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
// A page that fails: Express's own error handler answers it (no stack trace with NODE_ENV=production).
|
|
116
|
+
app.get('/boom', () => { throw new Error('Webship demo failure'); });
|
|
117
|
+
|
|
118
|
+
// JSON: express.json's refusals (400 malformed, 413 over the limit) go to Express's own error handler.
|
|
119
|
+
app.post('/api/echo', express.json({ limit: '1kb' }), (req, res) => res.json({ received: req.body }));
|
|
120
|
+
|
|
121
|
+
// Content negotiation: JSON or HTML; any other type is refused with 406.
|
|
122
|
+
app.get('/api/greeting', (req, res) => {
|
|
123
|
+
res.format({
|
|
124
|
+
'application/json': () => res.json({ greeting: 'Hello from the Webship demo' }),
|
|
125
|
+
'text/html': () => res.send(page('Greeting', '<h1>Hello from the Webship demo</h1>')),
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
const port = Number(process.env.PORT || 3000);
|
|
130
|
+
const server = app.listen(port, () => {
|
|
131
|
+
console.log(`The Webship demo (Express ${require('express/package.json').version}) listens on ${port}.`);
|
|
132
|
+
// Its accounts are kept in memory: every start begins with none.
|
|
133
|
+
console.log('No accounts yet (they are kept in memory, so every start begins with none): register them at /register.');
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
// A stop closes the server: what is being answered is finished, idle keep-alive connections are closed (they would
|
|
137
|
+
// hold the server open), then the process ends.
|
|
138
|
+
process.on('SIGTERM', () => {
|
|
139
|
+
console.log('SIGTERM: closing the server.');
|
|
140
|
+
server.close(() => process.exit(0));
|
|
141
|
+
server.closeIdleConnections();
|
|
142
|
+
setTimeout(() => process.exit(0), 5000).unref();
|
|
143
|
+
});
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/* The demo's own stylesheet, served by express.static (maxAge 1h). */
|
|
2
|
+
body { font-family: system-ui, sans-serif; margin: 2rem; max-width: 40rem; }
|
|
3
|
+
header { display: flex; gap: 1rem; align-items: center; margin-bottom: 1.5rem; }
|
|
4
|
+
header form { display: inline; }
|
|
5
|
+
label, input, button { display: block; margin: .25rem 0; }
|
|
6
|
+
.flash { padding: .5rem; background: #eef6ff; border: 1px solid #9cc4f0; }
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Express for Webship Workspace: a plugin for Express apps.
|
|
3
|
+
*
|
|
4
|
+
* What the package carries is placed by the installer from the manifest: the builder in the sites folders, its
|
|
5
|
+
* functions, argparse and machine files (the project's compose service on DDEV, the step pack's demo app, a first
|
|
6
|
+
* feature) under core/scripts/plugins/express/, its AI items (ai/) in the AI folders. The builder makes an Express app
|
|
7
|
+
* (the step pack's demo app at a line of Express, or an app from its repository) and serves it with Node.js in Node's
|
|
8
|
+
* own image, in production mode. The step pack (@webship-js/express-steps) goes into the testing setup of such an app
|
|
9
|
+
* with the core's `cmd-tools-testing.sh <project>`. What register() adds is what the assistant is told.
|
|
10
|
+
*
|
|
11
|
+
* Everything the dashboard is asked for goes through `api`; this package requires nothing from the dashboard's own
|
|
12
|
+
* files, so it can be installed from npm and removed without a trace.
|
|
13
|
+
*/
|
|
14
|
+
import type { PluginApi } from '@webship.co/workspace-plugin-api';
|
|
15
|
+
/** The plugin's name, which its functions are named after. */
|
|
16
|
+
export declare const PLATFORM = "express";
|
|
17
|
+
/** The commands the installer places in every sites folder. */
|
|
18
|
+
export declare const COMMANDS: string[];
|
|
19
|
+
/** The agents the installer places in the AI Agents folder. */
|
|
20
|
+
export declare const AGENTS: string[];
|
|
21
|
+
/** The skill the installer places in the AI Skills folder (a folder each, with its SKILL.md). */
|
|
22
|
+
export declare const SKILLS: string[];
|
|
23
|
+
/** The slash command the installer places in the AI Commands folder. */
|
|
24
|
+
export declare const AI_COMMANDS: string[];
|
|
25
|
+
/** The prompts the installer places in the AI Prompts folder: whole launch commands for a new session. */
|
|
26
|
+
export declare const PROMPTS: string[];
|
|
27
|
+
/** What the assistant is told about Express in this workspace. */
|
|
28
|
+
export declare function assistantContext(): string;
|
|
29
|
+
export declare function register(api: PluginApi): void;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Express for Webship Workspace: a plugin for Express apps.
|
|
4
|
+
*
|
|
5
|
+
* What the package carries is placed by the installer from the manifest: the builder in the sites folders, its
|
|
6
|
+
* functions, argparse and machine files (the project's compose service on DDEV, the step pack's demo app, a first
|
|
7
|
+
* feature) under core/scripts/plugins/express/, its AI items (ai/) in the AI folders. The builder makes an Express app
|
|
8
|
+
* (the step pack's demo app at a line of Express, or an app from its repository) and serves it with Node.js in Node's
|
|
9
|
+
* own image, in production mode. The step pack (@webship-js/express-steps) goes into the testing setup of such an app
|
|
10
|
+
* with the core's `cmd-tools-testing.sh <project>`. What register() adds is what the assistant is told.
|
|
11
|
+
*
|
|
12
|
+
* Everything the dashboard is asked for goes through `api`; this package requires nothing from the dashboard's own
|
|
13
|
+
* files, so it can be installed from npm and removed without a trace.
|
|
14
|
+
*/
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.PROMPTS = exports.AI_COMMANDS = exports.SKILLS = exports.AGENTS = exports.COMMANDS = exports.PLATFORM = void 0;
|
|
17
|
+
exports.assistantContext = assistantContext;
|
|
18
|
+
exports.register = register;
|
|
19
|
+
/** The plugin's name, which its functions are named after. */
|
|
20
|
+
exports.PLATFORM = 'express';
|
|
21
|
+
/** The commands the installer places in every sites folder. */
|
|
22
|
+
exports.COMMANDS = ['cmd-express-project.sh'];
|
|
23
|
+
/** The agents the installer places in the AI Agents folder. */
|
|
24
|
+
exports.AGENTS = ['express-builder', 'express-tester'];
|
|
25
|
+
/** The skill the installer places in the AI Skills folder (a folder each, with its SKILL.md). */
|
|
26
|
+
exports.SKILLS = ['express-scenarios'];
|
|
27
|
+
/** The slash command the installer places in the AI Commands folder. */
|
|
28
|
+
exports.AI_COMMANDS = ['express-test'];
|
|
29
|
+
/** The prompts the installer places in the AI Prompts folder: whole launch commands for a new session. */
|
|
30
|
+
exports.PROMPTS = ['express-build-and-test', 'express-scenarios-for-a-project'];
|
|
31
|
+
/** What the assistant is told about Express in this workspace. */
|
|
32
|
+
function assistantContext() {
|
|
33
|
+
return [
|
|
34
|
+
'Express (a plugin, @webship.co/workspace-express): its builder makes an Express app and serves it with Node.js in Node 24\'s own image,',
|
|
35
|
+
'with `bash cmd-express-project.sh <name> --install --add-users` from a sites folder (dev, test, sandboxes, demos), at https://<name>.ddev.site:',
|
|
36
|
+
'the step pack\'s demo app (accounts, Express\'s own refusal pages, static files, a session) at Express 5.3.0, or `--line 4.22.3`, or an app of',
|
|
37
|
+
'your own with --source, --ref, --path and --start (its start command; it listens on PORT, 3000). Its packages are installed in the app\'s folder',
|
|
38
|
+
'at the first start; Node.js runs in the app\'s container, never on the machine, in production mode. Express has no database of its own: the',
|
|
39
|
+
'row\'s Backup keeps the files. --add-users registers webship-tester and webship-other through the demo\'s form (kept in memory while it runs).',
|
|
40
|
+
'`--runtime docker`, `podman` or `kubernetes` builds it on Docker Compose, Podman or a Kubernetes cluster instead.',
|
|
41
|
+
'`bash cmd-tools-testing.sh <name>` sets up webship-js with the step pack @webship-js/express-steps on such an app: its steps sign in through',
|
|
42
|
+
'the app\'s forms, read its flash messages, Express\'s own answers (404, 500 with no stack trace, the body parsers\' 400 and 413, 406),',
|
|
43
|
+
'redirects, static files\' caching and 304, headers, and the session cookie\'s flags.',
|
|
44
|
+
`For building or fixing an Express app, hand over to the agent \`${exports.AGENTS[0]}\`; for testing one, to \`${exports.AGENTS[1]}\`.`,
|
|
45
|
+
`The plugin also places the skill ${exports.SKILLS.map((a) => `\`${a}\``).join(', ')} (the step pack's phrases) in ai-skills/,`,
|
|
46
|
+
`the command ${exports.AI_COMMANDS.map((a) => `\`/${a} <project>\``).join(', ')} in ai-commands/ and the prompts ${exports.PROMPTS.map((a) => `\`${a}\``).join(' and ')} in ai-prompts/.`,
|
|
47
|
+
'Never run node, npm or npx on the host for a project.',
|
|
48
|
+
].join(' ');
|
|
49
|
+
}
|
|
50
|
+
function register(api) {
|
|
51
|
+
api.addAssistantContext(assistantContext);
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;GAYG;;;AAuBH,4CAiBC;AAED,4BAEC;AAxCD,8DAA8D;AACjD,QAAA,QAAQ,GAAG,SAAS,CAAC;AAElC,+DAA+D;AAClD,QAAA,QAAQ,GAAG,CAAC,wBAAwB,CAAC,CAAC;AAEnD,+DAA+D;AAClD,QAAA,MAAM,GAAG,CAAC,iBAAiB,EAAE,gBAAgB,CAAC,CAAC;AAE5D,iGAAiG;AACpF,QAAA,MAAM,GAAG,CAAC,mBAAmB,CAAC,CAAC;AAE5C,wEAAwE;AAC3D,QAAA,WAAW,GAAG,CAAC,cAAc,CAAC,CAAC;AAE5C,0GAA0G;AAC7F,QAAA,OAAO,GAAG,CAAC,wBAAwB,EAAE,iCAAiC,CAAC,CAAC;AAErF,kEAAkE;AAClE,SAAgB,gBAAgB;IAC9B,OAAO;QACL,yIAAyI;QACzI,iJAAiJ;QACjJ,gJAAgJ;QAChJ,kJAAkJ;QAClJ,6IAA6I;QAC7I,gJAAgJ;QAChJ,mHAAmH;QACnH,8IAA8I;QAC9I,wIAAwI;QACxI,sFAAsF;QACtF,mEAAmE,cAAM,CAAC,CAAC,CAAC,6BAA6B,cAAM,CAAC,CAAC,CAAC,KAAK;QACvH,oCAAoC,cAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,2CAA2C;QACvH,eAAe,mBAAW,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,oCAAoC,eAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,kBAAkB;QACzK,uDAAuD;KACxD,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACd,CAAC;AAED,SAAgB,QAAQ,CAAC,GAAc;IACrC,GAAG,CAAC,mBAAmB,CAAC,gBAAgB,CAAC,CAAC;AAC5C,CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
Feature: An Express app on Docker Compose, Podman and Kubernetes
|
|
2
|
+
The builder builds on DDEV by default, and with --runtime on Docker Compose, Podman or a Kubernetes cluster. An app
|
|
3
|
+
built there has the row a DDEV project has: its state, its own address and the runtime's menu, and Node.js
|
|
4
|
+
serves it in Node's own image, its packages in the app's folder.
|
|
5
|
+
|
|
6
|
+
# Each scenario drives a real project of that runtime, built with cmd-express-project.sh --runtime: the first running
|
|
7
|
+
# one the workspace holds. Without one it is skipped, with the reason. In the plugin's CI the Docker Compose project is
|
|
8
|
+
# the one the manifest's featuresSite builds: ci-express.
|
|
9
|
+
|
|
10
|
+
@needs-runtime-docker @needs-platform-express
|
|
11
|
+
Scenario: An Express app built on Docker Compose runs at its own address, with the DOCKER menu
|
|
12
|
+
Given I am on the folder of the "docker" site
|
|
13
|
+
Then the row of the "docker" site should show "Running"
|
|
14
|
+
And the row of the "docker" site should link to the address of its runtime
|
|
15
|
+
And the address of the "docker" site should answer
|
|
16
|
+
And the row of the "docker" site should carry the "DOCKER" menu and no DDEV menu
|
|
17
|
+
|
|
18
|
+
# The demo app's own sign-in form, served by Node.js.
|
|
19
|
+
@needs-runtime-docker @needs-platform-express
|
|
20
|
+
Scenario: Express on Docker Compose serves the demo app
|
|
21
|
+
Given I am on the folder of the "docker" site
|
|
22
|
+
When I open "/login" on the "docker" site
|
|
23
|
+
Then "body" should contain text "Sign in" within 30 seconds
|
|
24
|
+
|
|
25
|
+
@needs-runtime-podman @needs-platform-express
|
|
26
|
+
Scenario: An Express app built on Podman runs at its own address, with the PODMAN menu
|
|
27
|
+
Given I am on the folder of the "podman" site
|
|
28
|
+
Then the row of the "podman" site should show "Running"
|
|
29
|
+
And the row of the "podman" site should link to the address of its runtime
|
|
30
|
+
And the address of the "podman" site should answer
|
|
31
|
+
And the row of the "podman" site should carry the "PODMAN" menu and no DDEV menu
|
|
32
|
+
|
|
33
|
+
@needs-runtime-podman @needs-platform-express
|
|
34
|
+
Scenario: Express on Podman serves the demo app
|
|
35
|
+
Given I am on the folder of the "podman" site
|
|
36
|
+
When I open "/login" on the "podman" site
|
|
37
|
+
Then "body" should contain text "Sign in" within 30 seconds
|
|
38
|
+
|
|
39
|
+
@needs-runtime-kubernetes @needs-platform-express
|
|
40
|
+
Scenario: An Express app built on Kubernetes runs at the address of its node, with the K8S menu
|
|
41
|
+
Given I am on the folder of the "kubernetes" site
|
|
42
|
+
Then the row of the "kubernetes" site should show "Running"
|
|
43
|
+
And the row of the "kubernetes" site should link to the address of its runtime
|
|
44
|
+
And the address of the "kubernetes" site should answer
|
|
45
|
+
And the row of the "kubernetes" site should carry the "K8S" menu and no DDEV menu
|
|
46
|
+
|
|
47
|
+
@needs-runtime-kubernetes @needs-platform-express
|
|
48
|
+
Scenario: Express on Kubernetes serves the demo app
|
|
49
|
+
Given I am on the folder of the "kubernetes" site
|
|
50
|
+
When I open "/login" on the "kubernetes" site
|
|
51
|
+
Then "body" should contain text "Sign in" within 30 seconds
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
Feature: The Express plugin on the dashboard
|
|
2
|
+
Once the plugin is activated and installed, the sites folders offer the Express builder, each AI folder
|
|
3
|
+
lists the items of its kind the plugin ships, and the Plugins page lists the plugin with what it ships.
|
|
4
|
+
|
|
5
|
+
# Settings lists every plugin that was added; the package and what the plugin ships are on its own page.
|
|
6
|
+
Scenario: Settings lists the plugin, and its own page names its package and what it ships
|
|
7
|
+
Given I am on "/settings"
|
|
8
|
+
Then I should see "Express"
|
|
9
|
+
When I go to "/settings/plugin/express"
|
|
10
|
+
Then I should see "@webship.co/workspace-express"
|
|
11
|
+
And I should see "cmd-express-project.sh"
|
|
12
|
+
And I should see "express-builder"
|
|
13
|
+
|
|
14
|
+
Scenario: A sites folder offers the Express builder
|
|
15
|
+
Given I am on "/dev"
|
|
16
|
+
Then "option[value='cmd-express-project.sh']" should be attached
|
|
17
|
+
|
|
18
|
+
# The AI folders are searched by name: with every plugin on, a folder lists more than one page of items.
|
|
19
|
+
Scenario: The AI Agents folder lists the agents the plugin ships
|
|
20
|
+
Given I am on "/ai-agents?q=express-"
|
|
21
|
+
Then I should see "express-builder"
|
|
22
|
+
And I should see "express-tester"
|
|
23
|
+
|
|
24
|
+
Scenario: The AI Skills folder lists the skill the plugin ships
|
|
25
|
+
Given I am on "/ai-skills?q=express-scenarios"
|
|
26
|
+
Then I should see "express-scenarios"
|
|
27
|
+
|
|
28
|
+
Scenario: The AI Commands folder lists the command the plugin ships
|
|
29
|
+
Given I am on "/ai-commands?q=express-test"
|
|
30
|
+
Then I should see "express-test"
|
|
31
|
+
|
|
32
|
+
Scenario: The AI Prompts folder lists the prompts the plugin ships
|
|
33
|
+
Given I am on "/ai-prompts?q=express-"
|
|
34
|
+
Then I should see "express-build-and-test"
|
|
35
|
+
And I should see "express-scenarios-for-a-project"
|
package/package.json
CHANGED
|
@@ -1,6 +1,105 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webship.co/workspace-express",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Express for Webship Workspace: the builder (`cmd-express-project.sh`) in every sites folder, which makes an Express app (the step pack's demo app at Express 5.3.0 or 4.22.3, or an app from its repository) and serves it with Node.js in Node 24's official image pinned by digest, in production mode, its packages installed in the app's folder (DDEV by default, or Docker Compose, Podman or Kubernetes with --runtime). The demo's accounts registered through its own form, the Express step pack wired into the testing setup of such an app, and its AI items in their folders: two agents, a skill, a command and two prompts for building and testing Express apps.",
|
|
5
|
+
"main": "dist/src/index.js",
|
|
6
|
+
"types": "dist/src/index.d.ts",
|
|
7
|
+
"license": "ISC",
|
|
8
|
+
"engines": {
|
|
9
|
+
"node": ">=24"
|
|
10
|
+
},
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "https://github.com/webship/workspace-express.git"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist/src",
|
|
17
|
+
"ai",
|
|
18
|
+
"commands",
|
|
19
|
+
"features",
|
|
20
|
+
"scripts",
|
|
21
|
+
"testing",
|
|
22
|
+
"README.md",
|
|
23
|
+
"demo"
|
|
24
|
+
],
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "tsc -p tsconfig.json",
|
|
27
|
+
"prepare": "npm run build",
|
|
28
|
+
"test": "npm run build && node --test dist/tests/*.test.js",
|
|
29
|
+
"lint": "tsc -p tsconfig.json --noEmit"
|
|
30
|
+
},
|
|
31
|
+
"workspacePlugin": {
|
|
32
|
+
"name": "express",
|
|
33
|
+
"label": "Express",
|
|
34
|
+
"needs": [
|
|
35
|
+
[
|
|
36
|
+
"dev",
|
|
37
|
+
"test",
|
|
38
|
+
"sandboxes",
|
|
39
|
+
"demos"
|
|
40
|
+
],
|
|
41
|
+
"ai-agents",
|
|
42
|
+
"ai-skills",
|
|
43
|
+
"ai-commands",
|
|
44
|
+
"ai-prompts"
|
|
45
|
+
],
|
|
46
|
+
"commands": {
|
|
47
|
+
"types": [
|
|
48
|
+
"sites"
|
|
49
|
+
],
|
|
50
|
+
"workspaces": [
|
|
51
|
+
"dev",
|
|
52
|
+
"test",
|
|
53
|
+
"sandboxes",
|
|
54
|
+
"demos"
|
|
55
|
+
],
|
|
56
|
+
"files": [
|
|
57
|
+
"commands/cmd-express-project.sh"
|
|
58
|
+
]
|
|
59
|
+
},
|
|
60
|
+
"scripts": {
|
|
61
|
+
"functions": [
|
|
62
|
+
"scripts/functions/fun-express.sh"
|
|
63
|
+
],
|
|
64
|
+
"args": [
|
|
65
|
+
"scripts/args/arg-express.sh"
|
|
66
|
+
],
|
|
67
|
+
"machine": [
|
|
68
|
+
"scripts/docker-compose.express.yaml",
|
|
69
|
+
"testing/site.feature",
|
|
70
|
+
"demo/app.js",
|
|
71
|
+
"demo/public/app.css"
|
|
72
|
+
]
|
|
73
|
+
},
|
|
74
|
+
"ai": {
|
|
75
|
+
"agents": [
|
|
76
|
+
"ai/agents/express-builder.md",
|
|
77
|
+
"ai/agents/express-tester.md"
|
|
78
|
+
],
|
|
79
|
+
"skills": [
|
|
80
|
+
"ai/skills/express-scenarios"
|
|
81
|
+
],
|
|
82
|
+
"commands": [
|
|
83
|
+
"ai/commands/express-test.md"
|
|
84
|
+
],
|
|
85
|
+
"prompts": [
|
|
86
|
+
"ai/prompts/express-build-and-test.md",
|
|
87
|
+
"ai/prompts/express-scenarios-for-a-project.md"
|
|
88
|
+
]
|
|
89
|
+
},
|
|
90
|
+
"features": [
|
|
91
|
+
"features/express.feature",
|
|
92
|
+
"features/express-runtimes.feature"
|
|
93
|
+
],
|
|
94
|
+
"featuresSite": "cmd-express-project.sh ci-express --install --add-users --runtime docker"
|
|
95
|
+
},
|
|
96
|
+
"devDependencies": {
|
|
97
|
+
"@types/node": "^24.0.0",
|
|
98
|
+
"@webship.co/workspace-plugin-api": "^1.0.13",
|
|
99
|
+
"typescript": "^5.9.0"
|
|
100
|
+
},
|
|
101
|
+
"publishConfig": {
|
|
102
|
+
"access": "public"
|
|
103
|
+
},
|
|
104
|
+
"keywords": []
|
|
105
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
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, and its project on the container runtime.')
|
|
6
|
+
parser.add_argument('--runtime',
|
|
7
|
+
dest='RUNTIME',
|
|
8
|
+
default="_none_",
|
|
9
|
+
choices=['ddev', 'docker', 'podman', 'kubernetes'],
|
|
10
|
+
help='The container runtime to build on: ddev (the default, or container.runtime of settings.yml), docker (Docker Compose), podman or kubernetes.')
|
|
11
|
+
parser.add_argument('--line',
|
|
12
|
+
dest='LINE',
|
|
13
|
+
default="5.3.0",
|
|
14
|
+
choices=['5.3.0', '4.22.3'],
|
|
15
|
+
help='The line of Express of the demo app: 5.3.0, the latest, or 4.22.3, the last of 4 (its exact packages). [default %(default)s]')
|
|
16
|
+
parser.add_argument('-s', '--source',
|
|
17
|
+
default="",
|
|
18
|
+
help="A git repository of an Express app to build instead of the demo app; empty means the demo app. [default %(default)s]")
|
|
19
|
+
parser.add_argument('-r', '--ref',
|
|
20
|
+
default="",
|
|
21
|
+
help='A branch or a tag of that repository; empty means its default branch. [default %(default)s]')
|
|
22
|
+
parser.add_argument('-p', '--path',
|
|
23
|
+
dest='APP_PATH',
|
|
24
|
+
default="",
|
|
25
|
+
help='The folder of the app in that repository (where its package.json is); empty means its root. [default %(default)s]')
|
|
26
|
+
parser.add_argument('--start',
|
|
27
|
+
dest='START',
|
|
28
|
+
default="",
|
|
29
|
+
help="The command that starts an app of your own, from its folder: for example 'node server.js'. It listens on PORT (3000). [default: the demo app's]")
|
|
30
|
+
parser.add_argument('-i', '--install',
|
|
31
|
+
action='store_true',
|
|
32
|
+
default=False,
|
|
33
|
+
help="Start the app (its packages installed at the first start) and check that it answers at its address.")
|
|
34
|
+
parser.add_argument('-a', '--add-users',
|
|
35
|
+
action='store_true',
|
|
36
|
+
default=False,
|
|
37
|
+
help="Register the default accounts too, through the demo app's own form: webship-tester and webship-other, with the workspace's password (kept in memory while the app runs).")
|
|
38
|
+
parser.add_argument('-l', '--launch',
|
|
39
|
+
action='store_true',
|
|
40
|
+
default=False,
|
|
41
|
+
help='Open the app in a browser when it is ready.')
|
|
42
|
+
ARGEOF
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# An Express app of this project: Node 24's official image (pinned by digest in .env), the project mounted, the app's
|
|
2
|
+
# packages installed in app/node_modules at the first start (npm ci with a lock file), then the app's start command
|
|
3
|
+
# (../.webship-express/start) as the main process under an init, so a stop reaches it; in production mode. It runs as
|
|
4
|
+
# the project's own user, so what it writes in the project is the project's. Written by the Express builder of the
|
|
5
|
+
# workspace (the plugin's docker-compose.express.yaml); build again rather than editing by hand.
|
|
6
|
+
services:
|
|
7
|
+
# The project's own web container steps aside from the project's address, which the router sends to the app.
|
|
8
|
+
web:
|
|
9
|
+
environment:
|
|
10
|
+
- HTTP_EXPOSE=8093:80,8025:8025
|
|
11
|
+
- HTTPS_EXPOSE=8457:80,8026:8025
|
|
12
|
+
express:
|
|
13
|
+
image: "${EXPRESS_NODE_IMAGE}"
|
|
14
|
+
container_name: ddev-${DDEV_SITENAME}-express
|
|
15
|
+
labels:
|
|
16
|
+
com.ddev.site-name: ${DDEV_SITENAME}
|
|
17
|
+
com.ddev.approot: ${DDEV_APPROOT}
|
|
18
|
+
restart: "no"
|
|
19
|
+
init: true
|
|
20
|
+
user: "${DDEV_UID}:${DDEV_GID}"
|
|
21
|
+
expose:
|
|
22
|
+
- "3000"
|
|
23
|
+
volumes:
|
|
24
|
+
- ${DDEV_APPROOT}:/var/www/html
|
|
25
|
+
working_dir: /var/www/html/app
|
|
26
|
+
command: ["sh", "-c", "export HOME=/tmp npm_config_cache=/tmp/.npm npm_config_update_notifier=false && { [ -d node_modules ] || { if [ -f package-lock.json ] ; then npm ci --omit=dev --no-audit --no-fund ; else npm install --omit=dev --no-audit --no-fund ; fi ; } ; } && exec $$(cat ../.webship-express/start)"]
|
|
27
|
+
environment:
|
|
28
|
+
NODE_ENV: production
|
|
29
|
+
PORT: "3000"
|
|
30
|
+
SESSION_SECRET_FILE: /var/www/html/.webship-express/session-secret
|
|
31
|
+
VIRTUAL_HOST: ${DDEV_HOSTNAME}
|
|
32
|
+
HTTP_EXPOSE: "80:3000"
|
|
33
|
+
HTTPS_EXPOSE: "443:3000"
|