create-wervt 0.2.1 → 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 CHANGED
@@ -12,6 +12,29 @@ import { installDependencies } from 'nypm'
12
12
  const BUNDLED_TEMPLATE = new URL('./template', import.meta.url).pathname
13
13
  const NAME_RE = /^[a-z0-9]+(?:-[a-z0-9]+)*$/
14
14
 
15
+ /**
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).
19
+ */
20
+ async function latest(name) {
21
+ const registry = (process.env.npm_config_registry ?? 'https://registry.npmjs.org').replace(
22
+ /\/$/,
23
+ '',
24
+ )
25
+ try {
26
+ const res = await fetch(`${registry}/${name}/latest`, { signal: AbortSignal.timeout(3000) })
27
+ if (res.ok) return (await res.json()).version
28
+ } catch {}
29
+ return undefined
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
+
15
38
  /** Root of the wervt repo when running inside it, so apps are created as workspace packages. */
16
39
  function findMonorepo(from) {
17
40
  for (let dir = resolve(from); ; dir = dirname(dir)) {
@@ -72,8 +95,22 @@ const main = defineCommand({
72
95
  if (monorepo) {
73
96
  // Inside the wervt repo: use the local module, root Vite+ config and lockfile.
74
97
  pkg.dependencies['@wervt/nuxt'] = 'workspace:*'
98
+ pkg.devDependencies['@wervt/cli'] = 'workspace:*'
75
99
  delete pkg.devDependencies['vite-plus']
76
100
  await rm(join(dir, 'vite.config.ts'), { force: true })
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}`
77
114
  }
78
115
  await writeFile(pkgPath, `${JSON.stringify(pkg, null, 2)}\n`)
79
116
  spinner.stop(`Created ${relative(process.cwd(), dir) || '.'}`)
@@ -91,6 +128,7 @@ const main = defineCommand({
91
128
  !args.install && 'pnpm install',
92
129
  'pnpm dev',
93
130
  monorepo && `pnpm app:deploy ${name} # from the repo root`,
131
+ !monorepo && 'pnpm exec wervt deploy # or from CI: .github/workflows/deploy.yml',
94
132
  ]
95
133
  .filter(Boolean)
96
134
  .join('\n'),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-wervt",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "description": "Create a new wervt app: Nuxt 5, Postgres with Drizzle, live data with Electric.",
5
5
  "homepage": "https://wervt.app",
6
6
  "license": "MIT",
@@ -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 }}
@@ -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.
@@ -15,6 +15,7 @@
15
15
  "valibot": "^1.5.0"
16
16
  },
17
17
  "devDependencies": {
18
+ "@wervt/cli": "^0.2.1",
18
19
  "drizzle-kit": "1.0.0-rc.4",
19
20
  "vite-plus": "^1.0.0"
20
21
  }