pagezero 0.4.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/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"
@@ -46,5 +47,5 @@
46
47
  "log-symbols": "7.0.1",
47
48
  "ora": "9.0.0"
48
49
  },
49
- "version": "0.4.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
+ }