@stjoseph/prumo 0.5.0 → 0.6.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/.prumo-templates/api/auth.md +1 -1
- package/.prumo-templates/core/testing.md +14 -4
- package/.prumo-templates/mcp/server.md +1 -1
- package/.prumo-templates/monorepo/layout.md +5 -1
- package/.prumo-templates/monorepo/tasks.md +5 -3
- package/.prumo-templates/social/sign-in.md +2 -1
- package/README.md +15 -2
- package/dist/add.js +219 -0
- package/dist/apps.js +205 -0
- package/dist/asker.js +37 -0
- package/dist/clean.js +3 -3
- package/dist/cli.js +51 -2
- package/dist/commands.js +10 -0
- package/dist/compose.js +86 -28
- package/dist/context.js +32 -5
- package/dist/database.js +3 -4
- package/dist/generate.js +26 -24
- package/dist/names.js +15 -2
- package/dist/next-steps.js +4 -3
- package/dist/pnpm-extended.js +159 -0
- package/dist/questions.js +22 -3
- package/dist/workspace-yaml.js +91 -0
- package/package.json +4 -1
- package/templates/api/.env.example +1 -0
- package/templates/api/README.md +2 -1
- package/templates/api/scripts/ports.mjs +60 -45
- package/templates/api/src/infra/config/env.ts +8 -1
- package/templates/api/src/infra/http/controllers/oauth.controller.ts +2 -2
- package/templates/api/src/infra/http/controllers/social.controller.ts +29 -13
- package/templates/api/src/infra/http/hooks/origin.hook.ts +4 -4
- package/templates/api/src/infra/social/openid-identity-providers.adapter.ts +1 -1
- package/templates/api/test/infra/config/env.spec.ts +26 -0
- package/templates/api/test/infra/http/controllers/auth.controller.spec.ts +24 -0
- package/templates/api/test/infra/http/controllers/social.controller.spec.ts +23 -1
- package/templates/api/test/support/setup.ts +1 -1
- package/templates/mobile/scripts/ports.mjs +60 -45
- package/templates/mobile/src/api-contract/auth.ts +15 -3
- package/templates/mobile/test/features/auth/authenticated-layout.spec.tsx +3 -2
- package/templates/mobile/test/features/auth/email-flows.spec.tsx +3 -2
- package/templates/mobile/test/features/auth/sign-in-form.spec.tsx +3 -2
- package/templates/mobile/test/features/auth/sign-out-button.spec.tsx +3 -2
- package/templates/mobile/test/features/auth/social-buttons.spec.tsx +3 -2
- package/templates/mobile/test/features/profile/profile-form.spec.tsx +3 -4
- package/templates/mobile/test/support/query-client.ts +14 -0
- package/templates/site/scripts/ports.mjs +60 -45
- package/templates/web/scripts/ports.mjs +60 -45
- package/templates/web/src/api-contract/auth.ts +15 -3
- package/templates/web/src/features/auth/social-buttons.tsx +2 -2
- package/templates/web/test/features/auth/social-buttons.spec.tsx +1 -0
- package/templates/web/test/features/oauth/consent-form.spec.tsx +3 -2
- package/templates/web/test/features/profile/profile-form.spec.tsx +3 -2
- package/templates/web/test/support/query-client.ts +14 -0
- package/templates/web/test/support/render-app.tsx +2 -2
- package/templates/web/vite.config.ts +10 -3
- package/templates/workspace/README.md +2 -2
- package/templates/workspace/scripts/ports.mjs +60 -45
|
@@ -14,22 +14,23 @@ import { basename, dirname, join, resolve } from 'node:path'
|
|
|
14
14
|
import { createInterface } from 'node:readline/promises'
|
|
15
15
|
import { parseArgs } from 'node:util'
|
|
16
16
|
|
|
17
|
-
// Where
|
|
18
|
-
const
|
|
17
|
+
// Where an app of each type keeps its port, what it falls back to, and how its dev command is told about it.
|
|
18
|
+
const TYPES = {
|
|
19
19
|
api: { key: 'PORT', fallback: 3000, flag: [] },
|
|
20
20
|
web: { key: 'WEB_PORT', fallback: 5173, flag: ['--port', '--strictPort'] },
|
|
21
21
|
site: { key: 'SITE_PORT', fallback: 3200, flag: ['--port'] },
|
|
22
22
|
mobile: { key: 'METRO_PORT', fallback: 8081, flag: ['--port'] },
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
// A port that moves takes these with it: the key to write, in
|
|
25
|
+
// A port that moves takes these with it: the key to write, in every app of which type. A list holds one URL per app,
|
|
26
|
+
// so only the moving app's entry changes.
|
|
26
27
|
const FOLLOWERS = {
|
|
27
28
|
api: [
|
|
28
|
-
{
|
|
29
|
-
{
|
|
30
|
-
{
|
|
29
|
+
{ type: 'api', key: 'API_URL' },
|
|
30
|
+
{ type: 'web', key: 'VITE_API_URL' },
|
|
31
|
+
{ type: 'mobile', key: 'EXPO_PUBLIC_API_URL' },
|
|
31
32
|
],
|
|
32
|
-
web: [{
|
|
33
|
+
web: [{ type: 'api', key: 'WEB_ORIGIN', list: true }],
|
|
33
34
|
site: [],
|
|
34
35
|
mobile: [],
|
|
35
36
|
}
|
|
@@ -117,36 +118,43 @@ function projectRoot() {
|
|
|
117
118
|
const root = projectRoot()
|
|
118
119
|
const workspace = existsSync(join(root, 'apps'))
|
|
119
120
|
|
|
120
|
-
function
|
|
121
|
-
|
|
121
|
+
function readConfig() {
|
|
122
|
+
const path = join(root, '.prumo', 'config.json')
|
|
123
|
+
|
|
124
|
+
return existsSync(path) ? JSON.parse(readFileSync(path, 'utf8')) : {}
|
|
122
125
|
}
|
|
123
126
|
|
|
124
|
-
|
|
125
|
-
|
|
127
|
+
// Every app of the project, as { name, type, directory }. A workspace lists its apps in .prumo/config.json; one written
|
|
128
|
+
// before apps had names holds one per type, named after it. An alone project is its one app, named after its type.
|
|
129
|
+
function projectApps() {
|
|
130
|
+
const config = readConfig()
|
|
131
|
+
|
|
132
|
+
if (!workspace) {
|
|
133
|
+
// A project is named by its author, so only .prumo/config.json says what it is.
|
|
134
|
+
const type = TYPES[basename(root)] !== undefined ? basename(root) : config.types?.[0]
|
|
126
135
|
|
|
127
|
-
|
|
128
|
-
return name
|
|
136
|
+
return type === undefined ? [] : [{ name: type, type, directory: root }]
|
|
129
137
|
}
|
|
130
138
|
|
|
131
|
-
|
|
132
|
-
const config = join(root, '.prumo', 'config.json')
|
|
133
|
-
const types = existsSync(config) ? JSON.parse(readFileSync(config, 'utf8')).types : []
|
|
139
|
+
const listed = config.apps ?? (config.types ?? []).map((type) => ({ name: type, type }))
|
|
134
140
|
|
|
135
|
-
return
|
|
141
|
+
return listed
|
|
142
|
+
.map((app) => ({ ...app, directory: join(root, 'apps', app.name) }))
|
|
143
|
+
.filter(
|
|
144
|
+
(app) => TYPES[app.type] !== undefined && existsSync(join(app.directory, 'package.json')),
|
|
145
|
+
)
|
|
136
146
|
}
|
|
137
147
|
|
|
138
|
-
|
|
139
|
-
if (!values.all) {
|
|
140
|
-
return [typeOf(here)]
|
|
141
|
-
}
|
|
148
|
+
const apps = projectApps()
|
|
142
149
|
|
|
143
|
-
|
|
150
|
+
function appsToCheck() {
|
|
151
|
+
return values.all ? apps : apps.filter((app) => app.directory === here)
|
|
144
152
|
}
|
|
145
153
|
|
|
146
|
-
function portOf(
|
|
147
|
-
const
|
|
154
|
+
function portOf(app) {
|
|
155
|
+
const { key, fallback } = TYPES[app.type]
|
|
148
156
|
|
|
149
|
-
return Number(envValue(readEnv(
|
|
157
|
+
return Number(envValue(readEnv(app.directory), key) ?? fallback)
|
|
150
158
|
}
|
|
151
159
|
|
|
152
160
|
function listening(host, port) {
|
|
@@ -269,22 +277,31 @@ async function nextFree(from) {
|
|
|
269
277
|
throw new Failure('port_busy', `No free port between ${from + 1} and ${from + PORTS_TRIED - 1}.`)
|
|
270
278
|
}
|
|
271
279
|
|
|
272
|
-
function movePort(
|
|
273
|
-
const
|
|
280
|
+
function movePort(app, from, port) {
|
|
281
|
+
const before = `http://localhost:${from}`
|
|
282
|
+
const after = `http://localhost:${port}`
|
|
274
283
|
|
|
275
|
-
writeEnvValue(
|
|
284
|
+
writeEnvValue(app.directory, TYPES[app.type].key, port)
|
|
276
285
|
|
|
277
|
-
for (const follower of FOLLOWERS[type]) {
|
|
278
|
-
const
|
|
286
|
+
for (const follower of FOLLOWERS[app.type]) {
|
|
287
|
+
for (const other of apps.filter((each) => each.type === follower.type)) {
|
|
288
|
+
const current = envValue(readEnv(other.directory), follower.key)
|
|
289
|
+
const entries = (current ?? '').split(',').map((entry) => entry.trim())
|
|
290
|
+
const value =
|
|
291
|
+
follower.list && current !== undefined
|
|
292
|
+
? (entries.includes(before)
|
|
293
|
+
? entries.map((entry) => (entry === before ? after : entry))
|
|
294
|
+
: [...entries, after]
|
|
295
|
+
).join(',')
|
|
296
|
+
: after
|
|
279
297
|
|
|
280
|
-
|
|
281
|
-
writeEnvValue(directory, follower.key, `http://localhost:${port}`)
|
|
298
|
+
writeEnvValue(other.directory, follower.key, value)
|
|
282
299
|
}
|
|
283
300
|
}
|
|
284
301
|
}
|
|
285
302
|
|
|
286
|
-
async function settle(
|
|
287
|
-
const port = portOf(
|
|
303
|
+
async function settle(app) {
|
|
304
|
+
const port = portOf(app)
|
|
288
305
|
|
|
289
306
|
if (!(await taken(port))) {
|
|
290
307
|
return port
|
|
@@ -292,12 +309,12 @@ async function settle(type) {
|
|
|
292
309
|
|
|
293
310
|
const found = holders(port)
|
|
294
311
|
|
|
295
|
-
say(`${
|
|
312
|
+
say(`${app.name} wants port ${port}, held by ${describe(found)}.`)
|
|
296
313
|
|
|
297
314
|
const moved = async () => {
|
|
298
315
|
const free = await nextFree(port)
|
|
299
|
-
movePort(
|
|
300
|
-
say(`${
|
|
316
|
+
movePort(app, port, free)
|
|
317
|
+
say(`${app.name} moved to port ${free}, written to .env.`)
|
|
301
318
|
return free
|
|
302
319
|
}
|
|
303
320
|
|
|
@@ -311,7 +328,7 @@ async function settle(type) {
|
|
|
311
328
|
if (!interactive) {
|
|
312
329
|
throw new Failure(
|
|
313
330
|
'port_busy',
|
|
314
|
-
`Port ${port} is in use by ${describe(found)}. Pass --kill to stop it, or --change to move ${
|
|
331
|
+
`Port ${port} is in use by ${describe(found)}. Pass --kill to stop it, or --change to move ${app.name} to the next free port.`,
|
|
315
332
|
)
|
|
316
333
|
}
|
|
317
334
|
|
|
@@ -669,10 +686,8 @@ async function main() {
|
|
|
669
686
|
const starting = command === undefined ? undefined : startJob()
|
|
670
687
|
|
|
671
688
|
try {
|
|
672
|
-
for (const
|
|
673
|
-
|
|
674
|
-
ports[type] = await settle(type)
|
|
675
|
-
}
|
|
689
|
+
for (const app of appsToCheck()) {
|
|
690
|
+
ports[app.name] = await settle(app)
|
|
676
691
|
}
|
|
677
692
|
} catch (error) {
|
|
678
693
|
;(await starting)?.close()
|
|
@@ -685,10 +700,10 @@ async function main() {
|
|
|
685
700
|
|
|
686
701
|
// Only an app tells its command which port to use. A workspace root wraps `pnpm`, which would pass a stray
|
|
687
702
|
// `--port` on to every app it runs.
|
|
688
|
-
const [
|
|
689
|
-
const flag =
|
|
703
|
+
const [app] = values.all ? [] : appsToCheck()
|
|
704
|
+
const flag = app === undefined ? [] : TYPES[app.type].flag
|
|
690
705
|
const withPort = flag.flatMap((entry) =>
|
|
691
|
-
entry === '--port' ? ['--port', String(ports[
|
|
706
|
+
entry === '--port' ? ['--port', String(ports[app.name])] : [entry],
|
|
692
707
|
)
|
|
693
708
|
// Before the command starts, so that it and everything it starts are members from their first instant.
|
|
694
709
|
const job = await starting
|