@sprawlify/cli 0.0.82

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.
@@ -0,0 +1 @@
1
+ export { };
package/dist/index.mjs ADDED
@@ -0,0 +1,200 @@
1
+ #!/usr/bin/env node
2
+ import { Command } from "commander";
3
+ import path from "path";
4
+ import fsExtra from "fs-extra";
5
+ import { cyan, green, red, yellow } from "kleur/colors";
6
+ import { z } from "zod";
7
+
8
+ //#region package.json
9
+ var version = "0.0.82";
10
+
11
+ //#endregion
12
+ //#region src/utils/file-helper.ts
13
+ const FILE_BACKUP_SUFFIX = ".bak";
14
+ function restoreFileBackup(filePath) {
15
+ const backupPath = `${filePath}${FILE_BACKUP_SUFFIX}`;
16
+ if (!fsExtra.existsSync(backupPath)) return false;
17
+ try {
18
+ fsExtra.renameSync(backupPath, filePath);
19
+ return true;
20
+ } catch (error) {
21
+ console.error(`Warning: Could not restore backup file ${backupPath}: ${error}`);
22
+ return false;
23
+ }
24
+ }
25
+ function deleteFileBackup(filePath) {
26
+ const backupPath = `${filePath}${FILE_BACKUP_SUFFIX}`;
27
+ if (!fsExtra.existsSync(backupPath)) return false;
28
+ try {
29
+ fsExtra.unlinkSync(backupPath);
30
+ return true;
31
+ } catch {
32
+ return false;
33
+ }
34
+ }
35
+
36
+ //#endregion
37
+ //#region src/utils/highlighter.ts
38
+ const highlighter = {
39
+ error: red,
40
+ warn: yellow,
41
+ info: cyan,
42
+ success: green
43
+ };
44
+
45
+ //#endregion
46
+ //#region src/utils/logger.ts
47
+ const logger = {
48
+ error(...args) {
49
+ console.log(highlighter.error(args.join(" ")));
50
+ },
51
+ warn(...args) {
52
+ console.log(highlighter.warn(args.join(" ")));
53
+ },
54
+ info(...args) {
55
+ console.log(highlighter.info(args.join(" ")));
56
+ },
57
+ success(...args) {
58
+ console.log(highlighter.success(args.join(" ")));
59
+ },
60
+ log(...args) {
61
+ console.log(args.join(" "));
62
+ },
63
+ break() {
64
+ console.log("");
65
+ }
66
+ };
67
+
68
+ //#endregion
69
+ //#region src/registry/errors.ts
70
+ const RegistryErrorCode = {
71
+ NETWORK_ERROR: "NETWORK_ERROR",
72
+ NOT_FOUND: "NOT_FOUND",
73
+ GONE: "GONE",
74
+ UNAUTHORIZED: "UNAUTHORIZED",
75
+ FORBIDDEN: "FORBIDDEN",
76
+ FETCH_ERROR: "FETCH_ERROR",
77
+ NOT_CONFIGURED: "NOT_CONFIGURED",
78
+ INVALID_CONFIG: "INVALID_CONFIG",
79
+ MISSING_ENV_VARS: "MISSING_ENV_VARS",
80
+ LOCAL_FILE_ERROR: "LOCAL_FILE_ERROR",
81
+ PARSE_ERROR: "PARSE_ERROR",
82
+ VALIDATION_ERROR: "VALIDATION_ERROR",
83
+ UNKNOWN_ERROR: "UNKNOWN_ERROR"
84
+ };
85
+ var RegistryError = class extends Error {
86
+ code;
87
+ statusCode;
88
+ context;
89
+ suggestion;
90
+ timestamp;
91
+ cause;
92
+ constructor(message, options = {}) {
93
+ super(message);
94
+ this.name = "RegistryError";
95
+ this.code = options.code || RegistryErrorCode.UNKNOWN_ERROR;
96
+ this.statusCode = options.statusCode;
97
+ this.cause = options.cause;
98
+ this.context = options.context;
99
+ this.suggestion = options.suggestion;
100
+ this.timestamp = /* @__PURE__ */ new Date();
101
+ if (Error.captureStackTrace) Error.captureStackTrace(this, this.constructor);
102
+ }
103
+ toJSON() {
104
+ return {
105
+ name: this.name,
106
+ message: this.message,
107
+ code: this.code,
108
+ statusCode: this.statusCode,
109
+ context: this.context,
110
+ suggestion: this.suggestion,
111
+ timestamp: this.timestamp,
112
+ stack: this.stack
113
+ };
114
+ }
115
+ };
116
+
117
+ //#endregion
118
+ //#region src/utils/handle-error.ts
119
+ function handleError(error) {
120
+ logger.break();
121
+ logger.error(`Something went wrong. Please check the error below for more details.`);
122
+ logger.error(`If the problem persists, please open an issue on GitHub.`);
123
+ logger.error("");
124
+ if (typeof error === "string") {
125
+ logger.error(error);
126
+ logger.break();
127
+ process.exit(1);
128
+ }
129
+ if (error instanceof RegistryError) {
130
+ if (error.message) {
131
+ logger.error(error.cause ? "Error:" : "Message:");
132
+ logger.error(error.message);
133
+ }
134
+ if (error.cause) {
135
+ logger.error("\nMessage:");
136
+ logger.error(error.cause);
137
+ }
138
+ if (error.suggestion) {
139
+ logger.error("\nSuggestion:");
140
+ logger.error(error.suggestion);
141
+ }
142
+ logger.break();
143
+ process.exit(1);
144
+ }
145
+ if (error instanceof z.ZodError) {
146
+ logger.error("Validation failed:");
147
+ for (const [key, value] of Object.entries(error.flatten().fieldErrors)) logger.error(`- ${highlighter.info(key)}: ${value}`);
148
+ logger.break();
149
+ process.exit(1);
150
+ }
151
+ if (error instanceof Error) {
152
+ logger.error(error.message);
153
+ logger.break();
154
+ process.exit(1);
155
+ }
156
+ logger.break();
157
+ process.exit(1);
158
+ }
159
+
160
+ //#endregion
161
+ //#region src/registry/context.ts
162
+ let context = { headers: {} };
163
+ function clearRegistryContext() {
164
+ context.headers = {};
165
+ }
166
+
167
+ //#endregion
168
+ //#region src/commands/init.ts
169
+ process.on("exit", (code) => {
170
+ const filePath = path.resolve(process.cwd(), "components.json");
171
+ if (code === 0) return deleteFileBackup(filePath);
172
+ return restoreFileBackup(filePath);
173
+ });
174
+ const init = new Command().name("init").description("initialize your project and install dependencies").argument("[components...]", "names, url or local path to component").option("-t, --theme <theme>", "the theme to use. (Monochrome, Clay)").option("-f, --framework <framework>", "the framework to use. (React, Solid, Svelte, Vue)").option("-m, --metaframework <metaframework>", "the metaframework to use. (Vanilla, Next.js, React Router, Remix)").option("-d, --defaults,", "use default configuration.", false).action(async (components, opts) => {
175
+ try {
176
+ if (opts.defaults) {
177
+ opts.template = opts.template || "react";
178
+ opts.baseColor = opts.baseColor || "neutral";
179
+ }
180
+ } catch (error) {
181
+ logger.break();
182
+ handleError(error);
183
+ } finally {
184
+ clearRegistryContext();
185
+ }
186
+ });
187
+
188
+ //#endregion
189
+ //#region src/index.ts
190
+ process.on("SIGINT", () => process.exit(0));
191
+ process.on("SIGTERM", () => process.exit(0));
192
+ async function main() {
193
+ const program = new Command().name("shadcn").description("add items from registries to your project").version(version || "1.0.0", "-v, --version", "display the version number");
194
+ program.addCommand(init);
195
+ program.parse();
196
+ }
197
+ main();
198
+
199
+ //#endregion
200
+ export { };
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "@sprawlify/cli",
3
+ "version": "0.0.82",
4
+ "type": "module",
5
+ "description": "A command-line interface for Sprawlify.",
6
+ "author": "sprawlify <npm@sprawlify.com>",
7
+ "bin": {
8
+ "scripts": "dist/index.mjs"
9
+ },
10
+ "types": "./dist/index.d.mts",
11
+ "exports": {
12
+ ".": "./dist/index.mjs",
13
+ "./package.json": "./package.json"
14
+ },
15
+ "publishConfig": {
16
+ "access": "public"
17
+ },
18
+ "files": [
19
+ "dist"
20
+ ],
21
+ "dependencies": {
22
+ "commander": "^14.0.3",
23
+ "fs-extra": "^11.3.4",
24
+ "kleur": "^4.1.5",
25
+ "zod": "^4.3.6"
26
+ },
27
+ "engines": {
28
+ "node": ">=24"
29
+ },
30
+ "license": "MIT",
31
+ "scripts": {
32
+ "build": "tsdown",
33
+ "typecheck": "tsc --noEmit",
34
+ "lint": "eslint src --fix"
35
+ }
36
+ }