create-wervt 0.2.2 → 0.2.3
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/index.js +26 -7
- package/package.json +1 -1
- package/template/.github/workflows/deploy.yml +48 -0
- package/template/AGENTS.md +3 -0
- package/template/package.json +1 -0
package/index.js
CHANGED
|
@@ -13,21 +13,28 @@ const BUNDLED_TEMPLATE = new URL('./template', import.meta.url).pathname
|
|
|
13
13
|
const NAME_RE = /^[a-z0-9]+(?:-[a-z0-9]+)*$/
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
|
-
* The newest
|
|
17
|
-
* ask the registry instead of keeping the
|
|
16
|
+
* The newest version of a package on npm. Releases of @wervt/nuxt and @wervt/cli don't release
|
|
17
|
+
* this package, so new apps ask the registry instead of keeping the versions bundled at pack
|
|
18
|
+
* time (the fallback, offline).
|
|
18
19
|
*/
|
|
19
|
-
async function
|
|
20
|
+
async function latest(name) {
|
|
20
21
|
const registry = (process.env.npm_config_registry ?? 'https://registry.npmjs.org').replace(
|
|
21
22
|
/\/$/,
|
|
22
23
|
'',
|
|
23
24
|
)
|
|
24
25
|
try {
|
|
25
|
-
const res = await fetch(`${registry}
|
|
26
|
+
const res = await fetch(`${registry}/${name}/latest`, { signal: AbortSignal.timeout(3000) })
|
|
26
27
|
if (res.ok) return (await res.json()).version
|
|
27
28
|
} catch {}
|
|
28
29
|
return undefined
|
|
29
30
|
}
|
|
30
31
|
|
|
32
|
+
/** The pnpm running create-wervt (`pnpm create wervt`), else the newest one. */
|
|
33
|
+
async function pnpmVersion() {
|
|
34
|
+
const agent = process.env.npm_config_user_agent?.match(/^pnpm\/(\d+\.\d+\.\d+)/)
|
|
35
|
+
return agent?.[1] ?? (await latest('pnpm'))
|
|
36
|
+
}
|
|
37
|
+
|
|
31
38
|
/** Root of the wervt repo when running inside it, so apps are created as workspace packages. */
|
|
32
39
|
function findMonorepo(from) {
|
|
33
40
|
for (let dir = resolve(from); ; dir = dirname(dir)) {
|
|
@@ -88,11 +95,22 @@ const main = defineCommand({
|
|
|
88
95
|
if (monorepo) {
|
|
89
96
|
// Inside the wervt repo: use the local module, root Vite+ config and lockfile.
|
|
90
97
|
pkg.dependencies['@wervt/nuxt'] = 'workspace:*'
|
|
98
|
+
pkg.devDependencies['@wervt/cli'] = 'workspace:*'
|
|
91
99
|
delete pkg.devDependencies['vite-plus']
|
|
92
100
|
await rm(join(dir, 'vite.config.ts'), { force: true })
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
101
|
+
// Apps in the repo are deployed from the repo, not by their own workflow.
|
|
102
|
+
await rm(join(dir, '.github'), { recursive: true, force: true })
|
|
103
|
+
} else {
|
|
104
|
+
for (const [deps, name] of [
|
|
105
|
+
['dependencies', '@wervt/nuxt'],
|
|
106
|
+
['devDependencies', '@wervt/cli'],
|
|
107
|
+
]) {
|
|
108
|
+
const version = pkg[deps]?.[name] && (await latest(name))
|
|
109
|
+
if (version) pkg[deps][name] = `^${version}`
|
|
110
|
+
}
|
|
111
|
+
// The deploy workflow's pnpm/action-setup installs this version.
|
|
112
|
+
const pnpm = !pkg.packageManager && (await pnpmVersion())
|
|
113
|
+
if (pnpm) pkg.packageManager = `pnpm@${pnpm}`
|
|
96
114
|
}
|
|
97
115
|
await writeFile(pkgPath, `${JSON.stringify(pkg, null, 2)}\n`)
|
|
98
116
|
spinner.stop(`Created ${relative(process.cwd(), dir) || '.'}`)
|
|
@@ -110,6 +128,7 @@ const main = defineCommand({
|
|
|
110
128
|
!args.install && 'pnpm install',
|
|
111
129
|
'pnpm dev',
|
|
112
130
|
monorepo && `pnpm app:deploy ${name} # from the repo root`,
|
|
131
|
+
!monorepo && 'pnpm exec wervt deploy # or from CI: .github/workflows/deploy.yml',
|
|
113
132
|
]
|
|
114
133
|
.filter(Boolean)
|
|
115
134
|
.join('\n'),
|
package/package.json
CHANGED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
name: deploy
|
|
2
|
+
|
|
3
|
+
# Deploys the app to wervt on every push to main, with a deploy token that can deploy this app
|
|
4
|
+
# and nothing else. Setup (once):
|
|
5
|
+
# wervt tokens <app> --create github # or Deploy tokens in the dashboard
|
|
6
|
+
# then in the repository settings, Secrets and variables > Actions:
|
|
7
|
+
# secret WERVT_TOKEN the token
|
|
8
|
+
# variable WERVT_URL the control plane URL
|
|
9
|
+
# Each release records the commit, branch, actor and this run.
|
|
10
|
+
|
|
11
|
+
on:
|
|
12
|
+
push:
|
|
13
|
+
branches: [main]
|
|
14
|
+
workflow_dispatch:
|
|
15
|
+
|
|
16
|
+
# One deploy at a time; a newer push waits instead of racing the running one.
|
|
17
|
+
concurrency:
|
|
18
|
+
group: deploy
|
|
19
|
+
cancel-in-progress: false
|
|
20
|
+
|
|
21
|
+
permissions:
|
|
22
|
+
contents: read
|
|
23
|
+
|
|
24
|
+
jobs:
|
|
25
|
+
deploy:
|
|
26
|
+
runs-on: ubuntu-latest
|
|
27
|
+
environment:
|
|
28
|
+
name: production
|
|
29
|
+
url: ${{ steps.deploy.outputs.url }}
|
|
30
|
+
steps:
|
|
31
|
+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
|
32
|
+
|
|
33
|
+
# The pnpm version comes from packageManager in package.json.
|
|
34
|
+
- uses: pnpm/action-setup@ea17c68df8912ef543352723c149a84f56e3d413 # v6.1.0
|
|
35
|
+
|
|
36
|
+
- uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
|
|
37
|
+
with:
|
|
38
|
+
node-version: 24
|
|
39
|
+
cache: pnpm
|
|
40
|
+
|
|
41
|
+
- run: pnpm install --frozen-lockfile
|
|
42
|
+
|
|
43
|
+
# Builds, uploads, migrates the database and activates the release.
|
|
44
|
+
- id: deploy
|
|
45
|
+
run: pnpm exec wervt deploy
|
|
46
|
+
env:
|
|
47
|
+
WERVT_URL: ${{ vars.WERVT_URL }}
|
|
48
|
+
WERVT_TOKEN: ${{ secrets.WERVT_TOKEN }}
|
package/template/AGENTS.md
CHANGED
|
@@ -137,3 +137,6 @@ Queries are LogsQL. Logs may contain user data: quote only what's needed.
|
|
|
137
137
|
- `pnpm dev`: dev server against the local wervt stack (`docker compose up -d` in the wervt repo).
|
|
138
138
|
- `pnpm db:generate`: generate a migration from the schema.
|
|
139
139
|
- `pnpm exec vp check --fix`: format, lint and type check. Run it before finishing.
|
|
140
|
+
- Deploys: pushing to `main` deploys through `.github/workflows/deploy.yml`. `pnpm exec wervt
|
|
141
|
+
releases <app>` lists releases with their commits. Don't deploy, roll back or create tokens
|
|
142
|
+
unless asked.
|