pagezero 0.4.0 → 0.5.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/bin/pagezero.ts CHANGED
@@ -8,8 +8,16 @@ program
8
8
  .description("PageZERO CLI")
9
9
  .option("-h, --help", "output usage information")
10
10
 
11
- program.command("init").description("initialize a new project").action(init)
11
+ program
12
+ .command("init")
13
+ .description("initialize a new project")
14
+ .option("-p, --powerup", "use PowerUP edition")
15
+ .action(init)
12
16
 
13
- program.command("upgrade").description("upgrade pagezero stack").action(upgrade)
17
+ program
18
+ .command("upgrade")
19
+ .description("upgrade pagezero stack")
20
+ .option("-p, --powerup", "use PowerUP edition")
21
+ .action(upgrade)
14
22
 
15
23
  program.parse()
package/package.json CHANGED
@@ -6,7 +6,8 @@
6
6
  "pagezero": "./bin/pagezero.ts"
7
7
  },
8
8
  "files": [
9
- "bin/"
9
+ "bin/",
10
+ "src/"
10
11
  ],
11
12
  "engines": {
12
13
  "bun": ">=1.3.1"
@@ -29,7 +30,8 @@
29
30
  "scripts": {
30
31
  "check": "biome check",
31
32
  "check:fix": "biome check --write",
32
- "check:types": "tsc"
33
+ "check:types": "tsc",
34
+ "git:clean": "git branch -l | grep -v 'main' | xargs git branch -D"
33
35
  },
34
36
  "devDependencies": {
35
37
  "@biomejs/biome": "2.3.3",
@@ -46,5 +48,5 @@
46
48
  "log-symbols": "7.0.1",
47
49
  "ora": "9.0.0"
48
50
  },
49
- "version": "0.4.0"
51
+ "version": "0.5.0"
50
52
  }
@@ -0,0 +1,64 @@
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({ powerup }: { powerup?: boolean }) {
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
+ if (powerup) {
16
+ await spinner("downloading pagezero powerup edition", async () => {
17
+ await $`git clone --depth 1 https://github.com/pagezero-dev/powerup.git ${projectName}`.quiet()
18
+ })
19
+ } else {
20
+ await spinner("downloading pagezero", async () => {
21
+ await $`git clone --depth 1 https://github.com/pagezero-dev/pagezero.git ${projectName}`.quiet()
22
+ })
23
+ }
24
+
25
+ // Install dependencies
26
+ await spinner(`running: bun install`, () =>
27
+ $`bun install`.quiet().cwd(projectName),
28
+ )
29
+
30
+ // Run setup script
31
+ await spinner(`running: bun run setup`, () =>
32
+ $`bun run setup`.quiet().cwd(projectName),
33
+ )
34
+
35
+ // Update wrangler.json
36
+ await spinner(`updating wrangler.json`, async () => {
37
+ const wranglerJson = await file(`${projectName}/wrangler.json`).json()
38
+ wranglerJson.name = projectName
39
+ wranglerJson.d1_databases[0].database_name = `${projectName}-development`
40
+ wranglerJson.env.production.d1_databases[0].database_name = `${projectName}-production`
41
+ wranglerJson.env.preview.d1_databases[0].database_name = `${projectName}-preview`
42
+ wranglerJson.env.test.d1_databases[0].database_name = `${projectName}-test`
43
+ wranglerJson.env.production.d1_databases[0].database_id = "<DATABASE_ID>"
44
+ wranglerJson.env.preview.d1_databases[0].database_id = "<DATABASE_ID>"
45
+ await write(
46
+ `${projectName}/wrangler.json`,
47
+ JSON.stringify(wranglerJson, null, 2),
48
+ )
49
+ })
50
+
51
+ // Initialize git repository
52
+ await spinner("initializing fresh git repository", async () => {
53
+ await $`rm -rf .git`.quiet().cwd(projectName)
54
+ await $`git init`.quiet().cwd(projectName)
55
+ await $`git add .`.quiet().cwd(projectName)
56
+ await $`git commit -m "Initial commit"`.quiet().cwd(projectName)
57
+ await $`git branch -m master main`.quiet().cwd(projectName)
58
+ })
59
+
60
+ // Done
61
+ console.log(chalk.green("🎉 Done! Your project is ready to go."))
62
+ console.log(chalk.green.bold(`cd ${projectName}`))
63
+ console.log(chalk.green.bold("bun dev"))
64
+ }
@@ -0,0 +1,64 @@
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({ powerup }: { powerup?: boolean }) {
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
+ if (powerup) {
47
+ await spinner(`downloading latest PageZERO PowerUP edition`, () =>
48
+ $`git clone --depth 1 https://github.com/pagezero-dev/powerup.git pagezero-latest`.quiet(),
49
+ )
50
+ } else {
51
+ await spinner(`downloading latest PageZERO stack`, () =>
52
+ $`git clone --depth 1 https://github.com/pagezero-dev/pagezero.git pagezero-latest`.quiet(),
53
+ )
54
+ }
55
+
56
+ await spinner(`copying PageZERO stack to project directory`, () =>
57
+ $`rsync -a --exclude=".git" ./pagezero-latest/ ./`.quiet(),
58
+ )
59
+
60
+ await spinner(`cleaning up`, () => $`rm -rf pagezero-latest`.quiet())
61
+
62
+ console.log(chalk.green("PageZERO stack upgraded successfully"))
63
+ console.log(chalk.green.bold("Please review the changes through a git diff"))
64
+ }
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
+ }