pagezero 0.3.0 → 0.4.1
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/bin/pagezero.ts +2 -117
- package/package.json +9 -8
- package/src/commands/init.ts +51 -0
- package/src/commands/upgrade.ts +58 -0
- package/src/utils.ts +15 -0
package/bin/pagezero.ts
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
|
|
3
|
-
import { confirm, input } from "@inquirer/prompts"
|
|
4
|
-
import boxen from "boxen"
|
|
5
|
-
import { $, file, write } from "bun"
|
|
6
|
-
import chalk from "chalk"
|
|
7
3
|
import { program } from "commander"
|
|
8
|
-
import
|
|
9
|
-
import
|
|
4
|
+
import { init } from "../src/commands/init"
|
|
5
|
+
import { upgrade } from "../src/commands/upgrade"
|
|
10
6
|
|
|
11
7
|
program
|
|
12
8
|
.description("PageZERO CLI")
|
|
@@ -17,114 +13,3 @@ program.command("init").description("initialize a new project").action(init)
|
|
|
17
13
|
program.command("upgrade").description("upgrade pagezero stack").action(upgrade)
|
|
18
14
|
|
|
19
15
|
program.parse()
|
|
20
|
-
|
|
21
|
-
async function init() {
|
|
22
|
-
// Welcome
|
|
23
|
-
console.log(chalk.green("👋 Welcome to PageZERO CLI"))
|
|
24
|
-
console.log(chalk.green("🚀 Let's get you started with your project!"))
|
|
25
|
-
|
|
26
|
-
// Bootstrap the project
|
|
27
|
-
const projectName = await input({
|
|
28
|
-
message: "What is the name of your project?",
|
|
29
|
-
})
|
|
30
|
-
const creatingProjectSpinner = ora(
|
|
31
|
-
`Running: bun create pagezero-dev/pagezero --no-install ${projectName}`,
|
|
32
|
-
).start()
|
|
33
|
-
await $`bun create pagezero-dev/pagezero --no-install ${projectName}`.quiet()
|
|
34
|
-
creatingProjectSpinner.succeed()
|
|
35
|
-
|
|
36
|
-
// Install dependencies
|
|
37
|
-
const installingDependenciesSpinner = ora(`Running: bun install`).start()
|
|
38
|
-
await $`bun install`.quiet().cwd(projectName)
|
|
39
|
-
installingDependenciesSpinner.succeed()
|
|
40
|
-
|
|
41
|
-
// Run setup script
|
|
42
|
-
const runningSetupScriptSpinner = ora(`Running: bun run setup`).start()
|
|
43
|
-
await $`bun run setup`.quiet().cwd(projectName)
|
|
44
|
-
runningSetupScriptSpinner.succeed()
|
|
45
|
-
|
|
46
|
-
// Update wrangler.json
|
|
47
|
-
const updatingWranglerJsonSpinner = ora(`Updating wrangler.json`).start()
|
|
48
|
-
try {
|
|
49
|
-
const wranglerJson = await file(`${projectName}/wrangler.json`).json()
|
|
50
|
-
wranglerJson.name = projectName
|
|
51
|
-
wranglerJson.d1_databases[0].database_name = `${projectName}-development`
|
|
52
|
-
wranglerJson.env.production.d1_databases[0].database_name = `${projectName}-production`
|
|
53
|
-
wranglerJson.env.preview.d1_databases[0].database_name = `${projectName}-preview`
|
|
54
|
-
wranglerJson.env.test.d1_databases[0].database_name = `${projectName}-test`
|
|
55
|
-
wranglerJson.env.production.d1_databases[0].database_id = "<DATABASE_ID>"
|
|
56
|
-
wranglerJson.env.preview.d1_databases[0].database_id = "<DATABASE_ID>"
|
|
57
|
-
await write(
|
|
58
|
-
`${projectName}/wrangler.json`,
|
|
59
|
-
JSON.stringify(wranglerJson, null, 2),
|
|
60
|
-
)
|
|
61
|
-
updatingWranglerJsonSpinner.succeed()
|
|
62
|
-
} catch (error) {
|
|
63
|
-
updatingWranglerJsonSpinner.warn()
|
|
64
|
-
console.error(chalk.yellow("Issue with updating wrangler.json"))
|
|
65
|
-
if (error instanceof Error) {
|
|
66
|
-
console.error(chalk.yellow(error.message))
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// Done
|
|
71
|
-
console.log(chalk.green("🎉 Done! Your project is ready to go."))
|
|
72
|
-
console.log(chalk.green.bold(`cd ${projectName}`))
|
|
73
|
-
console.log(chalk.green.bold("bun run dev"))
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
async function upgrade() {
|
|
77
|
-
console.log(
|
|
78
|
-
chalk.yellow(
|
|
79
|
-
boxen(
|
|
80
|
-
"Ugrade command is primitive. It will overwrite your existing \nproject files with the latest version of the PageZERO stack. \nAfterwards please review the changes through a git diff.",
|
|
81
|
-
{ padding: 1, title: "WARNING", titleAlignment: "center" },
|
|
82
|
-
),
|
|
83
|
-
),
|
|
84
|
-
)
|
|
85
|
-
|
|
86
|
-
const shouldProceed = await confirm({
|
|
87
|
-
message: "Do you want to proceed?",
|
|
88
|
-
})
|
|
89
|
-
|
|
90
|
-
if (!shouldProceed) {
|
|
91
|
-
return
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
const rsync = await $`command -v rsync`.quiet()
|
|
95
|
-
if (rsync.stdout) {
|
|
96
|
-
console.log(`${logSymbols.success} rsync is installed`)
|
|
97
|
-
} else {
|
|
98
|
-
console.log(
|
|
99
|
-
`${logSymbols.error} rsync is not installed and is required for the upgrade command: please install it and try again`,
|
|
100
|
-
)
|
|
101
|
-
return
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
const wranglerFile = file(`wrangler.json`)
|
|
105
|
-
if (await wranglerFile.exists()) {
|
|
106
|
-
console.log(`${logSymbols.success} wrangler.json file found`)
|
|
107
|
-
} else {
|
|
108
|
-
console.log(
|
|
109
|
-
`${logSymbols.error} wrangler.json file not found: please run command within PageZERO project directory`,
|
|
110
|
-
)
|
|
111
|
-
return
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
const clonePagezeroSpinner = ora(`downloading latest PageZERO stack`).start()
|
|
115
|
-
await $`git clone --depth 1 https://github.com/pagezero-dev/pagezero.git pagezero-latest`.quiet()
|
|
116
|
-
clonePagezeroSpinner.succeed()
|
|
117
|
-
|
|
118
|
-
const copyPagezeroSpinner = ora(
|
|
119
|
-
`copying PageZERO stack to project directory`,
|
|
120
|
-
).start()
|
|
121
|
-
await $`rsync -a --exclude=".git" ./pagezero-latest/ ./`.quiet()
|
|
122
|
-
copyPagezeroSpinner.succeed()
|
|
123
|
-
|
|
124
|
-
const cleanupSpinner = ora(`cleaning up`).start()
|
|
125
|
-
await $`rm -rf pagezero-latest`.quiet()
|
|
126
|
-
cleanupSpinner.succeed()
|
|
127
|
-
|
|
128
|
-
console.log(chalk.green("PageZERO stack upgraded successfully"))
|
|
129
|
-
console.log(chalk.green.bold("Please review the changes through a git diff"))
|
|
130
|
-
}
|
package/package.json
CHANGED
|
@@ -6,10 +6,11 @@
|
|
|
6
6
|
"pagezero": "./bin/pagezero.ts"
|
|
7
7
|
},
|
|
8
8
|
"files": [
|
|
9
|
-
"bin/"
|
|
9
|
+
"bin/",
|
|
10
|
+
"src/"
|
|
10
11
|
],
|
|
11
12
|
"engines": {
|
|
12
|
-
"bun": ">=1.
|
|
13
|
+
"bun": ">=1.3.1"
|
|
13
14
|
},
|
|
14
15
|
"keywords": [
|
|
15
16
|
"cli",
|
|
@@ -32,19 +33,19 @@
|
|
|
32
33
|
"check:types": "tsc"
|
|
33
34
|
},
|
|
34
35
|
"devDependencies": {
|
|
35
|
-
"@biomejs/biome": "2.
|
|
36
|
-
"@types/bun": "1.
|
|
36
|
+
"@biomejs/biome": "2.3.3",
|
|
37
|
+
"@types/bun": "1.3.1"
|
|
37
38
|
},
|
|
38
39
|
"peerDependencies": {
|
|
39
|
-
"typescript": "^5"
|
|
40
|
+
"typescript": "^5.9.3"
|
|
40
41
|
},
|
|
41
42
|
"dependencies": {
|
|
42
|
-
"@inquirer/prompts": "7.
|
|
43
|
+
"@inquirer/prompts": "7.9.0",
|
|
43
44
|
"boxen": "8.0.1",
|
|
44
45
|
"chalk": "5.6.2",
|
|
45
|
-
"commander": "14.0.
|
|
46
|
+
"commander": "14.0.2",
|
|
46
47
|
"log-symbols": "7.0.1",
|
|
47
48
|
"ora": "9.0.0"
|
|
48
49
|
},
|
|
49
|
-
"version": "0.
|
|
50
|
+
"version": "0.4.1"
|
|
50
51
|
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { input } from "@inquirer/prompts"
|
|
2
|
+
import { $, file, write } from "bun"
|
|
3
|
+
import chalk from "chalk"
|
|
4
|
+
import { spinner } from "../utils"
|
|
5
|
+
|
|
6
|
+
export async function init() {
|
|
7
|
+
// Welcome
|
|
8
|
+
console.log(chalk.green("👋 Welcome to PageZERO CLI"))
|
|
9
|
+
console.log(chalk.green("🚀 Let's get you started with your project!"))
|
|
10
|
+
|
|
11
|
+
// Bootstrap the project
|
|
12
|
+
const projectName = await input({
|
|
13
|
+
message: "What is the name of your project?",
|
|
14
|
+
})
|
|
15
|
+
await spinner(
|
|
16
|
+
`Running: bun create pagezero-dev/pagezero --no-install ${projectName}`,
|
|
17
|
+
() =>
|
|
18
|
+
$`bun create pagezero-dev/pagezero --no-install ${projectName}`.quiet(),
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
// Install dependencies
|
|
22
|
+
await spinner(`Running: bun install`, () =>
|
|
23
|
+
$`bun install`.quiet().cwd(projectName),
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
// Run setup script
|
|
27
|
+
await spinner(`Running: bun run setup`, () =>
|
|
28
|
+
$`bun run setup`.quiet().cwd(projectName),
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
// Update wrangler.json
|
|
32
|
+
await spinner(`Updating wrangler.json`, async () => {
|
|
33
|
+
const wranglerJson = await file(`${projectName}/wrangler.json`).json()
|
|
34
|
+
wranglerJson.name = projectName
|
|
35
|
+
wranglerJson.d1_databases[0].database_name = `${projectName}-development`
|
|
36
|
+
wranglerJson.env.production.d1_databases[0].database_name = `${projectName}-production`
|
|
37
|
+
wranglerJson.env.preview.d1_databases[0].database_name = `${projectName}-preview`
|
|
38
|
+
wranglerJson.env.test.d1_databases[0].database_name = `${projectName}-test`
|
|
39
|
+
wranglerJson.env.production.d1_databases[0].database_id = "<DATABASE_ID>"
|
|
40
|
+
wranglerJson.env.preview.d1_databases[0].database_id = "<DATABASE_ID>"
|
|
41
|
+
await write(
|
|
42
|
+
`${projectName}/wrangler.json`,
|
|
43
|
+
JSON.stringify(wranglerJson, null, 2),
|
|
44
|
+
)
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
// Done
|
|
48
|
+
console.log(chalk.green("🎉 Done! Your project is ready to go."))
|
|
49
|
+
console.log(chalk.green.bold(`cd ${projectName}`))
|
|
50
|
+
console.log(chalk.green.bold("bun run dev"))
|
|
51
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { confirm } from "@inquirer/prompts"
|
|
2
|
+
import boxen from "boxen"
|
|
3
|
+
import { $, file } from "bun"
|
|
4
|
+
import chalk from "chalk"
|
|
5
|
+
import logSymbols from "log-symbols"
|
|
6
|
+
import { spinner } from "../utils"
|
|
7
|
+
|
|
8
|
+
export async function upgrade() {
|
|
9
|
+
console.log(
|
|
10
|
+
chalk.yellow(
|
|
11
|
+
boxen(
|
|
12
|
+
"Ugrade command is primitive. It will overwrite your existing \nproject files with the latest version of the PageZERO stack. \nAfterwards please review the changes through a git diff.",
|
|
13
|
+
{ padding: 1, title: "WARNING", titleAlignment: "center" },
|
|
14
|
+
),
|
|
15
|
+
),
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
const shouldProceed = await confirm({
|
|
19
|
+
message: "Do you want to proceed?",
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
if (!shouldProceed) {
|
|
23
|
+
return
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const rsync = await $`command -v rsync`.quiet()
|
|
27
|
+
if (rsync.stdout) {
|
|
28
|
+
console.log(`${logSymbols.success} rsync is installed`)
|
|
29
|
+
} else {
|
|
30
|
+
console.log(
|
|
31
|
+
`${logSymbols.error} rsync is not installed and is required for the upgrade command: please install it and try again`,
|
|
32
|
+
)
|
|
33
|
+
return
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const wranglerFile = file(`wrangler.json`)
|
|
37
|
+
if (await wranglerFile.exists()) {
|
|
38
|
+
console.log(`${logSymbols.success} wrangler.json file found`)
|
|
39
|
+
} else {
|
|
40
|
+
console.log(
|
|
41
|
+
`${logSymbols.error} wrangler.json file not found: please run command within PageZERO project directory`,
|
|
42
|
+
)
|
|
43
|
+
return
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
await spinner(`downloading latest PageZERO stack`, () =>
|
|
47
|
+
$`git clone --depth 1 https://github.com/pagezero-dev/pagezero.git pagezero-latest`.quiet(),
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
await spinner(`copying PageZERO stack to project directory`, () =>
|
|
51
|
+
$`rsync -a --exclude=".git" ./pagezero-latest/ ./`.quiet(),
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
await spinner(`cleaning up`, () => $`rm -rf pagezero-latest`.quiet())
|
|
55
|
+
|
|
56
|
+
console.log(chalk.green("PageZERO stack upgraded successfully"))
|
|
57
|
+
console.log(chalk.green.bold("Please review the changes through a git diff"))
|
|
58
|
+
}
|
package/src/utils.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import ora, { type Ora } from "ora"
|
|
2
|
+
|
|
3
|
+
export async function spinner(
|
|
4
|
+
message: string,
|
|
5
|
+
fn: (spinner: Ora) => Promise<unknown>,
|
|
6
|
+
) {
|
|
7
|
+
const spinner = ora(message).start()
|
|
8
|
+
try {
|
|
9
|
+
await fn(spinner)
|
|
10
|
+
spinner.succeed()
|
|
11
|
+
} catch (error) {
|
|
12
|
+
spinner.fail()
|
|
13
|
+
throw error
|
|
14
|
+
}
|
|
15
|
+
}
|