create-snappy 0.0.11 → 0.0.12

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/dist/index.js +107 -67
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1,23 +1,38 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  // src/index.ts
4
- import fs from "fs";
5
- import path from "path";
6
- import { execSync } from "child_process";
7
- import prompts from "prompts";
8
- import kleur from "kleur";
9
- async function main() {
10
- console.log(kleur.cyan("create-snappy v0.0.11 by Wicky.ID"));
11
- console.log(kleur.white("wicky.id/snappy \u2014 hi@wicky.id"));
12
- console.log("\u2500".repeat(44) + "\n");
13
- try {
14
- execSync("pnpm --version", { stdio: "ignore" });
15
- } catch (err) {
16
- console.error(kleur.red("\u274C Error: pnpm is required to use SNAPPY CMS."));
17
- console.log(kleur.white(" Please install it: npm i -g pnpm\n"));
18
- process.exit(1);
4
+ import fs2 from "fs";
5
+ import path2 from "path";
6
+ import kleur2 from "kleur";
7
+ import prompts2 from "prompts";
8
+
9
+ // src/constants.ts
10
+ var SNAPPY_API_URL = "https://core.wicky.id";
11
+ var SNAPPY_TEMPLATE_REPO = "github.com/Snappy-Stack/Snappy_Template";
12
+ var SNAPPY_VERSION = "0.0.12";
13
+ var TEMPLATES = [
14
+ { title: "Portfolio", value: "portfolio", description: "Personal branding & projects" },
15
+ { title: "Portfolio + Services", value: "portfolio-services", description: "Portfolio with lead capture" },
16
+ { title: "Institution", value: "institution", description: "Schools, NGOs, Organization" },
17
+ { title: "Store", value: "store", description: "Simple e-commerce primitives" },
18
+ { title: "Artist / Karya", value: "artist", description: "Musicians, singers, creatives" }
19
+ ];
20
+
21
+ // src/api.ts
22
+ async function validateToken(token) {
23
+ const res = await fetch(`${SNAPPY_API_URL}/v1/heartbeat`, {
24
+ headers: { Authorization: `Bearer ${token}` }
25
+ });
26
+ if (!res.ok) {
27
+ throw new Error("Invalid SNAPPY_TOKEN");
19
28
  }
20
- const response = await prompts([
29
+ return await res.json();
30
+ }
31
+
32
+ // src/prompts.ts
33
+ import prompts from "prompts";
34
+ async function askQuestions() {
35
+ return await prompts([
21
36
  {
22
37
  type: "text",
23
38
  name: "projectName",
@@ -29,13 +44,7 @@ async function main() {
29
44
  type: "select",
30
45
  name: "template",
31
46
  message: "Choose a starting template:",
32
- choices: [
33
- { title: "Artist / Karya", value: "artist", description: "Musicians, singers, creatives" },
34
- { title: "Portfolio", value: "portfolio", description: "Personal branding & projects" },
35
- { title: "Portfolio + Services", value: "portfolio-services", description: "Portfolio with lead capture" },
36
- { title: "Institution", value: "institution", description: "Schools, NGOs, Organization" },
37
- { title: "Store", value: "store", description: "Simple e-commerce primitives" }
38
- ],
47
+ choices: TEMPLATES,
39
48
  initial: 0
40
49
  },
41
50
  {
@@ -68,67 +77,98 @@ async function main() {
68
77
  initial: 0
69
78
  }
70
79
  ]);
80
+ }
81
+
82
+ // src/setup.ts
83
+ import fs from "fs";
84
+ import path from "path";
85
+ import { execSync } from "child_process";
86
+ import kleur from "kleur";
87
+ function runSetup(targetDir, options) {
88
+ const { projectName, template, token, domain, githubToken, locale } = options;
89
+ console.log(kleur.blue(`
90
+ \u{1F4E6} Cloning [${template}] template...`));
91
+ try {
92
+ const cloneUrl = `https://${githubToken}@${SNAPPY_TEMPLATE_REPO}`;
93
+ execSync(`git clone --depth 1 -b ${template} ${cloneUrl} "${targetDir}"`, { stdio: "inherit" });
94
+ fs.rmSync(path.join(targetDir, ".git"), { recursive: true, force: true });
95
+ const npmrcContent = `//npm.pkg.github.com/:_authToken=${githubToken}
96
+ @snappy:registry=https://npm.pkg.github.com`;
97
+ fs.writeFileSync(path.join(targetDir, ".npmrc"), npmrcContent);
98
+ const pkgPath = path.join(targetDir, "package.json");
99
+ if (fs.existsSync(pkgPath)) {
100
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
101
+ pkg.name = projectName.toLowerCase().replace(/\s+/g, "-");
102
+ fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2));
103
+ }
104
+ const envContent = `# SNAPPY CMS - Site Configuration
105
+ SNAPPY_TOKEN="${token}"
106
+ SNAPPY_URL="${SNAPPY_API_URL}"
107
+ PUBLIC_LOCALE="${locale}"
108
+ PRIMARY_DOMAIN="${domain}"
109
+ `;
110
+ fs.writeFileSync(path.join(targetDir, ".env"), envContent);
111
+ const metadata = {
112
+ projectName,
113
+ template,
114
+ installedAt: (/* @__PURE__ */ new Date()).toISOString(),
115
+ version: "2.0.0"
116
+ };
117
+ fs.writeFileSync(path.join(targetDir, "snappy.json"), JSON.stringify(metadata, null, 2));
118
+ } catch (err) {
119
+ throw new Error(`Failed to setup project: ${err.message}`);
120
+ }
121
+ }
122
+
123
+ // src/index.ts
124
+ async function main() {
125
+ console.log(kleur2.cyan(`create-snappy v${SNAPPY_VERSION} by Wicky.ID`));
126
+ console.log(kleur2.white("wicky.id/snappy \u2014 hi@wicky.id"));
127
+ console.log("\u2500".repeat(44) + "\n");
128
+ const response = await askQuestions();
71
129
  if (!response.projectName) {
72
- console.log(kleur.yellow("Installation cancelled."));
130
+ console.log(kleur2.yellow("Installation cancelled."));
73
131
  process.exit(0);
74
132
  }
75
- const targetDir = path.resolve(process.cwd(), response.projectName);
76
- if (fs.existsSync(targetDir)) {
77
- const { overwrite } = await prompts({
133
+ console.log(kleur2.blue("\u{1F50D} Validating SNAPPY_TOKEN..."));
134
+ try {
135
+ const heartbeat = await validateToken(response.token);
136
+ console.log(kleur2.green(`\u2705 Token valid [Project: ${heartbeat.projectSlug || "Unknown"}]`));
137
+ } catch (err) {
138
+ console.error(kleur2.red(`\u274C Invalid SNAPPY_TOKEN: ${err.message}`));
139
+ process.exit(1);
140
+ }
141
+ const targetDir = path2.resolve(process.cwd(), response.projectName);
142
+ if (fs2.existsSync(targetDir)) {
143
+ const { overwrite } = await prompts2({
78
144
  type: "confirm",
79
145
  name: "overwrite",
80
146
  message: `Directory ${response.projectName} already exists. Wipe and overwrite?`,
81
147
  initial: false
82
148
  });
83
149
  if (!overwrite) {
84
- console.log(kleur.red("Aborted."));
150
+ console.log(kleur2.red("Aborted."));
85
151
  process.exit(0);
86
152
  }
87
- fs.rmSync(targetDir, { recursive: true, force: true });
153
+ fs2.rmSync(targetDir, { recursive: true, force: true });
88
154
  }
89
- console.log(kleur.blue(`
90
- \u{1F4E6} Cloning [${response.template}] template...`));
91
155
  try {
92
- const cloneUrl = `https://${response.githubToken}@github.com/Snappy-Stack/Snappy_Template`;
93
- execSync(`git clone --depth 1 -b ${response.template} ${cloneUrl} "${targetDir}"`, { stdio: "inherit" });
94
- fs.rmSync(path.join(targetDir, ".git"), { recursive: true, force: true });
95
- const npmrcContent = `//npm.pkg.github.com/:_authToken=${response.githubToken}
96
- @snappy:registry=https://npm.pkg.github.com`;
97
- fs.writeFileSync(path.join(targetDir, ".npmrc"), npmrcContent);
98
- const pkgPath = path.join(targetDir, "package.json");
99
- if (fs.existsSync(pkgPath)) {
100
- const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
101
- pkg.name = response.projectName.toLowerCase().replace(/\s+/g, "-");
102
- fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2));
103
- }
156
+ runSetup(targetDir, response);
157
+ console.log(kleur2.green("\n\u2705 Project initialized successfully!"));
158
+ console.log(`
159
+ Next steps:`);
160
+ console.log(kleur2.cyan(` cd ${response.projectName}`));
161
+ console.log(kleur2.cyan(` pnpm install`));
162
+ console.log(kleur2.cyan(` pnpm dev`));
163
+ console.log("\n");
104
164
  } catch (err) {
105
- console.error(kleur.red(`\u274C Failed to clone template.`));
165
+ console.error(kleur2.red(`
166
+ \u274C Installation failed: ${err.message}`));
106
167
  process.exit(1);
107
168
  }
108
- const envContent = `# SNAPPY CMS - Site Configuration
109
- SNAPPY_TOKEN="${response.token}"
110
- SNAPPY_URL="https://core.wicky.id"
111
- PUBLIC_LOCALE="${response.locale}"
112
- PRIMARY_DOMAIN="${response.domain}"
113
- `;
114
- fs.writeFileSync(path.join(targetDir, ".env"), envContent);
115
- const metadata = {
116
- projectName: response.projectName,
117
- template: response.template,
118
- installedAt: (/* @__PURE__ */ new Date()).toISOString(),
119
- version: "2.0.0"
120
- };
121
- fs.writeFileSync(path.join(targetDir, "snappy.json"), JSON.stringify(metadata, null, 2));
122
- console.log(kleur.green("\n\u2705 Project initialized successfully!"));
123
- console.log(`
124
- Next steps:`);
125
- console.log(kleur.cyan(` cd ${response.projectName}`));
126
- console.log(kleur.cyan(` pnpm install`));
127
- console.log(kleur.cyan(` pnpm dev`));
128
- console.log("\n");
129
169
  }
130
170
  main().catch((err) => {
131
- console.error(kleur.red(`
132
- \u274C Installation failed: ${err.message}`));
171
+ console.error(kleur2.red(`
172
+ \u274C Critical error: ${err.message}`));
133
173
  process.exit(1);
134
174
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-snappy",
3
- "version": "0.0.11",
3
+ "version": "0.0.12",
4
4
  "description": "The official SNAPPY Stack CLI for project initialization.",
5
5
  "type": "module",
6
6
  "private": false,