create-snappy 0.0.11 → 0.0.13
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/dist/index.js +115 -71
- 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
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
|
-
|
|
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,102 @@ async function main() {
|
|
|
68
77
|
initial: 0
|
|
69
78
|
}
|
|
70
79
|
]);
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
message: `Directory ${response.projectName} already exists. Wipe and overwrite?`,
|
|
81
|
-
initial: false
|
|
82
|
-
});
|
|
83
|
-
if (!overwrite) {
|
|
84
|
-
console.log(kleur.red("Aborted."));
|
|
85
|
-
process.exit(0);
|
|
86
|
-
}
|
|
87
|
-
fs.rmSync(targetDir, { recursive: true, force: true });
|
|
88
|
-
}
|
|
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
89
|
console.log(kleur.blue(`
|
|
90
|
-
\u{1F4E6} Cloning [${
|
|
90
|
+
\u{1F4E6} Cloning [${template}] template...`));
|
|
91
91
|
try {
|
|
92
|
-
const cloneUrl = `https://${
|
|
93
|
-
execSync(`git clone --depth 1 -b ${
|
|
92
|
+
const cloneUrl = `https://${githubToken}@${SNAPPY_TEMPLATE_REPO}`;
|
|
93
|
+
execSync(`git clone --depth 1 -b ${template} ${cloneUrl} "${targetDir}"`, { stdio: "inherit" });
|
|
94
94
|
fs.rmSync(path.join(targetDir, ".git"), { recursive: true, force: true });
|
|
95
|
-
const npmrcContent = `//npm.pkg.github.com/:_authToken=${
|
|
95
|
+
const npmrcContent = `//npm.pkg.github.com/:_authToken=${githubToken}
|
|
96
96
|
@snappy:registry=https://npm.pkg.github.com`;
|
|
97
97
|
fs.writeFileSync(path.join(targetDir, ".npmrc"), npmrcContent);
|
|
98
98
|
const pkgPath = path.join(targetDir, "package.json");
|
|
99
99
|
if (fs.existsSync(pkgPath)) {
|
|
100
100
|
const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
|
|
101
|
-
pkg.name =
|
|
101
|
+
pkg.name = projectName.toLowerCase().replace(/\s+/g, "-");
|
|
102
102
|
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2));
|
|
103
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));
|
|
104
118
|
} catch (err) {
|
|
105
|
-
|
|
106
|
-
process.exit(1);
|
|
119
|
+
throw new Error(`Failed to setup project: ${err.message}`);
|
|
107
120
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
const
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
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();
|
|
129
|
+
if (!response.projectName) {
|
|
130
|
+
console.log(kleur2.yellow("Installation cancelled."));
|
|
131
|
+
setTimeout(() => process.exit(0), 100);
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
console.log(kleur2.blue("\u{1F50D} Validating SNAPPY_TOKEN..."));
|
|
135
|
+
try {
|
|
136
|
+
const heartbeat = await validateToken(response.token);
|
|
137
|
+
console.log(kleur2.green(`\u2705 Token valid [Project: ${heartbeat.projectSlug || "Unknown"}]`));
|
|
138
|
+
} catch (err) {
|
|
139
|
+
console.error(kleur2.red(`\u274C Invalid SNAPPY_TOKEN: ${err.message}`));
|
|
140
|
+
setTimeout(() => process.exit(1), 100);
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
const targetDir = path2.resolve(process.cwd(), response.projectName);
|
|
144
|
+
if (fs2.existsSync(targetDir)) {
|
|
145
|
+
const { overwrite } = await prompts2({
|
|
146
|
+
type: "confirm",
|
|
147
|
+
name: "overwrite",
|
|
148
|
+
message: `Directory ${response.projectName} already exists. Wipe and overwrite?`,
|
|
149
|
+
initial: false
|
|
150
|
+
});
|
|
151
|
+
if (!overwrite) {
|
|
152
|
+
console.log(kleur2.red("Aborted."));
|
|
153
|
+
setTimeout(() => process.exit(0), 100);
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
fs2.rmSync(targetDir, { recursive: true, force: true });
|
|
157
|
+
}
|
|
158
|
+
try {
|
|
159
|
+
runSetup(targetDir, response);
|
|
160
|
+
console.log(kleur2.green("\n\u2705 Project initialized successfully!"));
|
|
161
|
+
console.log(`
|
|
124
162
|
Next steps:`);
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
163
|
+
console.log(kleur2.cyan(` cd ${response.projectName}`));
|
|
164
|
+
console.log(kleur2.cyan(` pnpm install`));
|
|
165
|
+
console.log(kleur2.cyan(` pnpm dev`));
|
|
166
|
+
console.log("\n");
|
|
167
|
+
} catch (err) {
|
|
168
|
+
console.error(kleur2.red(`
|
|
169
|
+
\u274C Installation failed: ${err.message}`));
|
|
170
|
+
setTimeout(() => process.exit(1), 100);
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
129
173
|
}
|
|
130
174
|
main().catch((err) => {
|
|
131
|
-
console.error(
|
|
132
|
-
\u274C
|
|
133
|
-
process.exit(1);
|
|
175
|
+
console.error(kleur2.red(`
|
|
176
|
+
\u274C Critical error: ${err.message}`));
|
|
177
|
+
setTimeout(() => process.exit(1), 100);
|
|
134
178
|
});
|