create-moncircle 1.0.0 → 1.0.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.
Files changed (2) hide show
  1. package/index.js +28 -6
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -1,18 +1,23 @@
1
1
  #!/usr/bin/env node
2
2
  /**
3
- * create-moncircle
3
+ * create-moncircle — Interactive setup wizard for @moncircle/sdk
4
4
  *
5
- * Usage: npx create-moncircle
5
+ * Usage:
6
+ * npx create-moncircle (standalone)
7
+ * npm install @moncircle/sdk (auto-triggered via postinstall)
6
8
  *
7
- * Walks devs through setting up @moncircle/sdk in their project.
8
- * Runs as a foreground process (visible output, interactive TTY).
9
+ * Supports:
10
+ * - NEW mode: creates .env from scratch
11
+ * - EDIT mode: updates existing .env without destroying it
9
12
  */
10
13
 
11
14
  const readline = require("readline")
12
15
  const fs = require("fs")
13
16
  const path = require("path")
17
+ const { execSync } = require("child_process")
14
18
 
15
- const ENV_PATH = path.join(process.cwd(), ".env")
19
+ const ENV_PATH = process.env.MON_LOYALTY_ENV_PATH || path.join(process.cwd(), ".env")
20
+ const PKG_PATH = path.join(process.cwd(), "package.json")
16
21
 
17
22
  const CYAN = "\x1b[36m"
18
23
  const GREEN = "\x1b[32m"
@@ -133,6 +138,13 @@ function writeFreshEnv(values) {
133
138
  fs.writeFileSync(ENV_PATH, lines.join("\n"), "utf-8")
134
139
  }
135
140
 
141
+ function sdkIsInstalled() {
142
+ try {
143
+ const pkg = JSON.parse(fs.readFileSync(PKG_PATH, "utf-8"))
144
+ return !!(pkg.dependencies?.["@moncircle/sdk"] || pkg.devDependencies?.["@moncircle/sdk"])
145
+ } catch { return false }
146
+ }
147
+
136
148
  async function main() {
137
149
  const existing = loadExistingEnv()
138
150
  const isEditMode = Object.keys(existing).length > 0
@@ -144,7 +156,6 @@ async function main() {
144
156
  if (isEditMode) {
145
157
  console.log(` ${GREEN}✓ Existing .env found.${RESET} ${DIM}Press Enter to keep current values.${RESET}\n`)
146
158
  } else {
147
- console.log(` ${DIM}No .env found — let's create one.${RESET}`)
148
159
  console.log(` ${DIM}Writing to: ${ENV_PATH}${RESET}\n`)
149
160
  }
150
161
 
@@ -180,6 +191,17 @@ async function main() {
180
191
  console.log(`${GREEN}${BOLD} ✅ .env created successfully!${RESET}\n`)
181
192
  }
182
193
 
194
+ // Auto-install @moncircle/sdk if not in package.json
195
+ if (!sdkIsInstalled() && fs.existsSync(PKG_PATH)) {
196
+ console.log(` ${YELLOW}Installing @moncircle/sdk...${RESET}`)
197
+ try {
198
+ execSync("npm install @moncircle/sdk --save", { stdio: "inherit", cwd: process.cwd() })
199
+ console.log(` ${GREEN}✓ @moncircle/sdk installed!${RESET}\n`)
200
+ } catch {
201
+ console.log(` ${YELLOW}⚠ Run ${CYAN}npm install @moncircle/sdk${RESET}${YELLOW} manually.${RESET}\n`)
202
+ }
203
+ }
204
+
183
205
  console.log(` Next steps:\n`)
184
206
  console.log(` ${CYAN}npx mon-loyalty-api start${RESET} — start the server`)
185
207
  console.log(` ${CYAN}npx create-moncircle${RESET} — reconfigure anytime\n`)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-moncircle",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Interactive setup wizard for @moncircle/sdk — run via npx create-moncircle",
5
5
  "bin": {
6
6
  "create-moncircle": "index.js"