create-pagescms 0.0.0-stage → 3.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 +21 -0
- package/README.md +4 -2
- package/cli.mjs +144 -0
- package/create.mjs +143 -0
- package/package.json +29 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright 2025 Ronan Berder
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Create Pages CMS
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Run `npm create pagescms@latest` for an interactive walkthrough. It can install dependencies, run the GitHub App helper and initialize the local database; each step is optional. The generated project's `npm run setup:github-app` and `npm run migrate` commands are also available separately.
|
|
4
|
+
|
|
5
|
+
For non-interactive creation, run `npm create pagescms@latest -- my-cms --target node`. The other targets are `cloudflare`, `netlify`, and `vercel`; Netlify and Vercel are experimental. Then follow the generated README and [self-hosting guide](https://pagescms.org/docs/self-hosting/).
|
package/cli.mjs
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import * as p from '@clack/prompts'
|
|
3
|
+
import { spawn } from 'node:child_process'
|
|
4
|
+
import { parseArgs } from 'node:util'
|
|
5
|
+
import { createProject } from './create.mjs'
|
|
6
|
+
|
|
7
|
+
function answer(value) {
|
|
8
|
+
if (p.isCancel(value)) {
|
|
9
|
+
p.cancel(
|
|
10
|
+
'Setup cancelled. You can continue using the commands in the project README.',
|
|
11
|
+
)
|
|
12
|
+
process.exit(0)
|
|
13
|
+
}
|
|
14
|
+
return value
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async function run(path, ...args) {
|
|
18
|
+
const command = process.platform === 'win32' ? 'npm.cmd' : 'npm'
|
|
19
|
+
const code = await new Promise((resolve, reject) => {
|
|
20
|
+
const child = spawn(command, args, { cwd: path, stdio: 'inherit' })
|
|
21
|
+
child.on('error', reject)
|
|
22
|
+
child.on('close', resolve)
|
|
23
|
+
})
|
|
24
|
+
if (code !== 0)
|
|
25
|
+
throw new Error(
|
|
26
|
+
`npm ${args.join(' ')} failed. Continue using the project README.`,
|
|
27
|
+
)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
try {
|
|
31
|
+
const { values, positionals } = parseArgs({
|
|
32
|
+
allowPositionals: true,
|
|
33
|
+
options: {
|
|
34
|
+
target: { type: 'string' },
|
|
35
|
+
help: { type: 'boolean', short: 'h' },
|
|
36
|
+
},
|
|
37
|
+
})
|
|
38
|
+
if (values.help) {
|
|
39
|
+
console.log(
|
|
40
|
+
'Usage: npm create pagescms@latest -- [directory] [--target node|cloudflare|netlify|vercel]',
|
|
41
|
+
)
|
|
42
|
+
process.exit(0)
|
|
43
|
+
}
|
|
44
|
+
if (positionals.length > 1) throw new Error('Provide one project directory')
|
|
45
|
+
const interactive = process.stdin.isTTY && process.stdout.isTTY
|
|
46
|
+
if (interactive) p.intro('Create Pages CMS')
|
|
47
|
+
const directory =
|
|
48
|
+
positionals[0] ??
|
|
49
|
+
(interactive
|
|
50
|
+
? answer(
|
|
51
|
+
await p.text({
|
|
52
|
+
message: 'Where should we create your project?',
|
|
53
|
+
placeholder: 'my-pagescms',
|
|
54
|
+
defaultValue: 'my-pagescms',
|
|
55
|
+
validate: (value) =>
|
|
56
|
+
value.trim() ? undefined : 'Enter a directory',
|
|
57
|
+
}),
|
|
58
|
+
)
|
|
59
|
+
: 'my-pagescms')
|
|
60
|
+
const target =
|
|
61
|
+
values.target ??
|
|
62
|
+
(interactive
|
|
63
|
+
? answer(
|
|
64
|
+
await p.select({
|
|
65
|
+
message: 'Where will you deploy?',
|
|
66
|
+
options: [
|
|
67
|
+
{
|
|
68
|
+
value: 'node',
|
|
69
|
+
label: 'Node.js',
|
|
70
|
+
hint: 'a server or container',
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
value: 'cloudflare',
|
|
74
|
+
label: 'Cloudflare Workers',
|
|
75
|
+
hint: 'with D1',
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
value: 'netlify',
|
|
79
|
+
label: 'Netlify',
|
|
80
|
+
hint: 'experimental, with remote libSQL',
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
value: 'vercel',
|
|
84
|
+
label: 'Vercel',
|
|
85
|
+
hint: 'experimental, with remote libSQL',
|
|
86
|
+
},
|
|
87
|
+
],
|
|
88
|
+
}),
|
|
89
|
+
)
|
|
90
|
+
: 'node')
|
|
91
|
+
const path = await createProject(directory, target)
|
|
92
|
+
if (!interactive) {
|
|
93
|
+
console.log(
|
|
94
|
+
`Created ${target} project at ${path}.\nRun npm install and follow README.md to configure and start it.`,
|
|
95
|
+
)
|
|
96
|
+
} else {
|
|
97
|
+
p.log.success(`Created ${target} project at ${path}`)
|
|
98
|
+
const guided = answer(
|
|
99
|
+
await p.confirm({
|
|
100
|
+
message: 'Install dependencies and continue with guided setup?',
|
|
101
|
+
initialValue: true,
|
|
102
|
+
}),
|
|
103
|
+
)
|
|
104
|
+
let githubReady = false
|
|
105
|
+
let databaseReady = false
|
|
106
|
+
if (guided) {
|
|
107
|
+
await run(path, 'install')
|
|
108
|
+
if (
|
|
109
|
+
answer(
|
|
110
|
+
await p.confirm({
|
|
111
|
+
message: 'Set up a GitHub App now?',
|
|
112
|
+
initialValue: true,
|
|
113
|
+
}),
|
|
114
|
+
)
|
|
115
|
+
) {
|
|
116
|
+
await run(path, 'run', 'setup:github-app')
|
|
117
|
+
githubReady = true
|
|
118
|
+
}
|
|
119
|
+
if (
|
|
120
|
+
answer(
|
|
121
|
+
await p.confirm({
|
|
122
|
+
message: 'Initialize the local database now?',
|
|
123
|
+
initialValue: true,
|
|
124
|
+
}),
|
|
125
|
+
)
|
|
126
|
+
) {
|
|
127
|
+
await run(path, 'run', 'migrate', '--', '--local')
|
|
128
|
+
databaseReady = true
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
const next = [
|
|
132
|
+
`cd '${path.replaceAll("'", "'\\''")}'`,
|
|
133
|
+
...(!guided ? ['npm install'] : []),
|
|
134
|
+
...(!githubReady ? ['npm run setup:github-app'] : []),
|
|
135
|
+
...(!databaseReady ? ['npm run migrate -- --local'] : []),
|
|
136
|
+
'npm run dev',
|
|
137
|
+
]
|
|
138
|
+
p.note(next.join('\n'), 'Next steps')
|
|
139
|
+
p.outro('See README.md for deployment commands.')
|
|
140
|
+
}
|
|
141
|
+
} catch (error) {
|
|
142
|
+
console.error(error instanceof Error ? error.message : String(error))
|
|
143
|
+
process.exitCode = 1
|
|
144
|
+
}
|
package/create.mjs
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { mkdir, readdir, writeFile } from 'node:fs/promises'
|
|
2
|
+
import { basename, resolve } from 'node:path'
|
|
3
|
+
import { randomBytes } from 'node:crypto'
|
|
4
|
+
|
|
5
|
+
export const VERSION = '3.0.0'
|
|
6
|
+
|
|
7
|
+
export async function createProject(directory, target) {
|
|
8
|
+
if (!['node', 'cloudflare', 'netlify', 'vercel'].includes(target))
|
|
9
|
+
throw new Error('Target must be node, cloudflare, netlify or vercel')
|
|
10
|
+
const runtime = target === 'cloudflare' ? 'cloudflare' : 'node'
|
|
11
|
+
const serverless = target === 'netlify' || target === 'vercel'
|
|
12
|
+
const root = resolve(directory)
|
|
13
|
+
await mkdir(root, { recursive: true })
|
|
14
|
+
if ((await readdir(root)).length)
|
|
15
|
+
throw new Error(`Directory is not empty: ${root}`)
|
|
16
|
+
const name =
|
|
17
|
+
basename(root)
|
|
18
|
+
.toLowerCase()
|
|
19
|
+
.replace(/[^a-z0-9._-]/g, '-')
|
|
20
|
+
.replace(/^[._-]+/, '') || 'pagescms-app'
|
|
21
|
+
const scripts = {
|
|
22
|
+
dev: 'pagescms dev',
|
|
23
|
+
build: 'pagescms build',
|
|
24
|
+
...(serverless
|
|
25
|
+
? { 'build:function': 'pagescms build --remote-libsql' }
|
|
26
|
+
: {}),
|
|
27
|
+
preview: 'pagescms preview',
|
|
28
|
+
migrate: 'pagescms migrate',
|
|
29
|
+
'setup:github-app': 'pagescms-setup-github-app',
|
|
30
|
+
'migrate:2x': 'pagescms-collaborators migrate-2x',
|
|
31
|
+
...(runtime === 'node'
|
|
32
|
+
? { start: 'pagescms start' }
|
|
33
|
+
: {
|
|
34
|
+
'migrate:remote': 'pagescms migrate --remote',
|
|
35
|
+
'deploy:dry-run': 'wrangler deploy --dry-run',
|
|
36
|
+
deploy: 'wrangler deploy',
|
|
37
|
+
}),
|
|
38
|
+
}
|
|
39
|
+
const overrides = {
|
|
40
|
+
'@tiptap/extension-bubble-menu': '3.31.3',
|
|
41
|
+
'@tiptap/extension-floating-menu': '3.31.3',
|
|
42
|
+
}
|
|
43
|
+
const manifest = {
|
|
44
|
+
name,
|
|
45
|
+
private: true,
|
|
46
|
+
type: 'module',
|
|
47
|
+
engines: { node: '>=22.19.0' },
|
|
48
|
+
scripts,
|
|
49
|
+
dependencies: {
|
|
50
|
+
pagescms: VERSION,
|
|
51
|
+
react: '19.3.1',
|
|
52
|
+
'react-dom': '19.3.1',
|
|
53
|
+
...(target === 'vercel' ? { '@vercel/functions': '3.11.3' } : {}),
|
|
54
|
+
},
|
|
55
|
+
overrides,
|
|
56
|
+
pnpm: { overrides },
|
|
57
|
+
...(target === 'cloudflare'
|
|
58
|
+
? { devDependencies: { wrangler: '4.162.0' } }
|
|
59
|
+
: {}),
|
|
60
|
+
}
|
|
61
|
+
const environment =
|
|
62
|
+
'BETTER_AUTH_URL="http://localhost:3000"\nDATABASE_URL="file:.data/pagescms.db"\nGITHUB_APP_NAME=""\nGITHUB_APP_CLIENT_ID=""\nGITHUB_APP_CLIENT_SECRET=""\nGITHUB_APP_ID=""\nGITHUB_APP_PRIVATE_KEY=""\nGITHUB_APP_WEBHOOK_SECRET=""\nCRYPTO_KEY=""\n'
|
|
63
|
+
const files = {
|
|
64
|
+
'package.json': `${JSON.stringify(manifest, null, 2)}\n`,
|
|
65
|
+
'pagescms.config.ts': `import { defineConfig } from 'pagescms'\n\nexport default defineConfig({ target: '${runtime}' })\n`,
|
|
66
|
+
'.gitignore':
|
|
67
|
+
'node_modules/\ndist/\n.pagescms/\n.wrangler/\n.data/\n.env*\n!.env.example\n.dev.vars*\n',
|
|
68
|
+
'.env.example': `BETTER_AUTH_SECRET=""\n${environment}`,
|
|
69
|
+
'.env.local': `BETTER_AUTH_SECRET="${randomBytes(32).toString('base64')}"\n${environment}`,
|
|
70
|
+
'README.md': `# Pages CMS\n\nSee the [self-hosting guide](https://pagescms.org/docs/self-hosting/) for GitHub App, database and deployment setup.\n\nThe generated \`.env.local\` contains your local authentication secret. Run \`npm install\`, then run \`npm run setup:github-app\`, \`npm run migrate -- --local\` and \`npm run dev\`.\n${target === 'cloudflare' ? '\nSet your D1 database ID in `wrangler.jsonc` before deploying. Run `npm run migrate:remote`, `npm run build`, then `npm run deploy`. Set deployed secrets in Cloudflare.\n' : serverless ? `\nSee the [${target} deployment guide](https://pagescms.org/docs/self-hosting/${target}/) for remote database and deployment setup.\n` : '\nRun `npm run build` and `npm start` to serve a production build.\n'}`,
|
|
71
|
+
}
|
|
72
|
+
if (target === 'vercel') {
|
|
73
|
+
files['.vercelignore'] =
|
|
74
|
+
'node_modules/\ndist/\n.pagescms/\n.wrangler/\n.data/\n.env*\n.dev.vars*\n'
|
|
75
|
+
files['vercel.json'] = `${JSON.stringify(
|
|
76
|
+
{
|
|
77
|
+
buildCommand: 'npm run build:function',
|
|
78
|
+
outputDirectory: 'dist/client',
|
|
79
|
+
headers: [
|
|
80
|
+
{
|
|
81
|
+
source: '/(.*)',
|
|
82
|
+
headers: [
|
|
83
|
+
{
|
|
84
|
+
key: 'Content-Security-Policy',
|
|
85
|
+
value: "frame-ancestors 'none'",
|
|
86
|
+
},
|
|
87
|
+
{ key: 'X-Frame-Options', value: 'DENY' },
|
|
88
|
+
],
|
|
89
|
+
},
|
|
90
|
+
],
|
|
91
|
+
rewrites: [
|
|
92
|
+
{ source: '/api/(.*)', destination: '/api' },
|
|
93
|
+
{
|
|
94
|
+
source: '/.well-known/((?!acme-challenge(?:/|$)).*)',
|
|
95
|
+
destination: '/api',
|
|
96
|
+
},
|
|
97
|
+
{ source: '/(.*)', destination: '/index.html' },
|
|
98
|
+
],
|
|
99
|
+
},
|
|
100
|
+
null,
|
|
101
|
+
2,
|
|
102
|
+
)}\n`
|
|
103
|
+
files['api/index.mjs'] =
|
|
104
|
+
`import { waitUntil } from '@vercel/functions'\nimport app from '../dist/server/server.js'\n\nexport default { fetch: (request) => app.fetch(request, waitUntil) }\n`
|
|
105
|
+
}
|
|
106
|
+
if (target === 'netlify') {
|
|
107
|
+
files['netlify.toml'] =
|
|
108
|
+
`[build]\n command = "npm run build:function"\n publish = "dist/client"\n functions = "netlify/functions"\n\n[[redirects]]\n from = "/*"\n to = "/index.html"\n status = 200\n`
|
|
109
|
+
files['netlify/functions/api.mjs'] =
|
|
110
|
+
`import app from '../../dist/server/server.js'\n\nexport default (request, context) => app.fetch(request, (promise) => context.waitUntil(promise))\nexport const config = { path: ['/api/*', '/.well-known/*'] }\n`
|
|
111
|
+
}
|
|
112
|
+
if (target === 'cloudflare') {
|
|
113
|
+
files['wrangler.jsonc'] = `${JSON.stringify(
|
|
114
|
+
{
|
|
115
|
+
name: 'pagescms',
|
|
116
|
+
main: 'pagescms/server-entry',
|
|
117
|
+
compatibility_date: '2026-08-20',
|
|
118
|
+
compatibility_flags: ['nodejs_compat'],
|
|
119
|
+
d1_databases: [
|
|
120
|
+
{
|
|
121
|
+
binding: 'DATABASE',
|
|
122
|
+
database_name: 'pagescms',
|
|
123
|
+
database_id: '00000000-0000-0000-0000-000000000001',
|
|
124
|
+
migrations_dir: 'node_modules/pagescms/drizzle',
|
|
125
|
+
migrations_table: '__pagescms_core_d1_migrations',
|
|
126
|
+
},
|
|
127
|
+
],
|
|
128
|
+
},
|
|
129
|
+
null,
|
|
130
|
+
2,
|
|
131
|
+
)}\n`
|
|
132
|
+
}
|
|
133
|
+
await Promise.all(
|
|
134
|
+
Object.entries(files).map(async ([file, content]) => {
|
|
135
|
+
await mkdir(resolve(root, file, '..'), { recursive: true })
|
|
136
|
+
await writeFile(resolve(root, file), content, {
|
|
137
|
+
flag: 'wx',
|
|
138
|
+
...(file === '.env.local' ? { mode: 0o600 } : {}),
|
|
139
|
+
})
|
|
140
|
+
}),
|
|
141
|
+
)
|
|
142
|
+
return root
|
|
143
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,32 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-pagescms",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "3.0.0",
|
|
4
|
+
"description": "Create a self-hosted Pages CMS project",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"publishConfig": {
|
|
8
|
+
"tag": "latest"
|
|
9
|
+
},
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "https://github.com/hunvreus/pagescms.git",
|
|
13
|
+
"directory": "packages/create-pagescms"
|
|
14
|
+
},
|
|
15
|
+
"bin": {
|
|
16
|
+
"create-pagescms": "./cli.mjs"
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"cli.mjs",
|
|
20
|
+
"create.mjs",
|
|
21
|
+
"README.md"
|
|
22
|
+
],
|
|
23
|
+
"engines": {
|
|
24
|
+
"node": ">=22.19.0"
|
|
25
|
+
},
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"@clack/prompts": "1.9.0"
|
|
28
|
+
},
|
|
29
|
+
"scripts": {
|
|
30
|
+
"test": "node --test create.check.mjs"
|
|
31
|
+
}
|
|
6
32
|
}
|