@ollie-shop/cli 0.3.0 → 0.3.3
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/.turbo/turbo-build.log +14 -2
- package/CHANGELOG.md +48 -0
- package/__tests__/mocks/core.ts +1 -1
- package/dist/index.d.ts +0 -2
- package/dist/index.js +40631 -75
- package/package.json +7 -6
- package/src/actions/component.actions.ts +148 -204
- package/src/actions/function.actions.ts +78 -171
- package/src/actions/project.actions.ts +16 -11
- package/src/commands/__tests__/component.test.ts +4 -7
- package/src/commands/__tests__/function.test.ts +1 -1
- package/src/commands/__tests__/store-version.test.ts +1 -4
- package/src/commands/component.ts +0 -10
- package/src/commands/function.ts +5 -56
- package/src/schemas/command.schema.ts +296 -6
- package/src/utils/__tests__/rich-progress.test.ts +22 -11
- package/src/utils/cli-progress-reporter.ts +2 -2
- package/src/utils/command-parser.ts +0 -5
- package/src/utils/console.ts +33 -4
- package/src/utils/constants.ts +32 -0
- package/src/utils/deploy-helpers.ts +357 -0
- package/src/utils/errors.ts +133 -2
- package/src/utils/interactive-builder.ts +61 -7
- package/src/utils/rich-progress.ts +25 -14
- package/src/utils/validation-helpers.ts +145 -12
- package/tsup.config.ts +15 -0
- package/dist/__tests__/helpers/cli-test-helper.d.ts +0 -89
- package/dist/__tests__/helpers/cli-test-helper.d.ts.map +0 -1
- package/dist/__tests__/helpers/cli-test-helper.js +0 -220
- package/dist/__tests__/mocks/index.d.ts +0 -69
- package/dist/__tests__/mocks/index.d.ts.map +0 -1
- package/dist/__tests__/mocks/index.js +0 -77
- package/dist/actions/component.actions.d.ts +0 -14
- package/dist/actions/component.actions.d.ts.map +0 -1
- package/dist/actions/component.actions.js +0 -273
- package/dist/actions/function.actions.d.ts +0 -15
- package/dist/actions/function.actions.d.ts.map +0 -1
- package/dist/actions/function.actions.js +0 -254
- package/dist/actions/project.actions.d.ts +0 -17
- package/dist/actions/project.actions.d.ts.map +0 -1
- package/dist/actions/project.actions.js +0 -97
- package/dist/actions/version.actions.d.ts +0 -19
- package/dist/actions/version.actions.d.ts.map +0 -1
- package/dist/actions/version.actions.js +0 -216
- package/dist/commands/component.d.ts +0 -3
- package/dist/commands/component.d.ts.map +0 -1
- package/dist/commands/component.js +0 -192
- package/dist/commands/docs.d.ts +0 -3
- package/dist/commands/docs.d.ts.map +0 -1
- package/dist/commands/docs.js +0 -16
- package/dist/commands/function.d.ts +0 -3
- package/dist/commands/function.d.ts.map +0 -1
- package/dist/commands/function.js +0 -243
- package/dist/commands/help.d.ts +0 -3
- package/dist/commands/help.d.ts.map +0 -1
- package/dist/commands/help.js +0 -20
- package/dist/commands/index.d.ts +0 -3
- package/dist/commands/index.d.ts.map +0 -1
- package/dist/commands/index.js +0 -26
- package/dist/commands/login.d.ts +0 -3
- package/dist/commands/login.d.ts.map +0 -1
- package/dist/commands/login.js +0 -175
- package/dist/commands/project.d.ts +0 -3
- package/dist/commands/project.d.ts.map +0 -1
- package/dist/commands/project.js +0 -78
- package/dist/commands/store-version.d.ts +0 -3
- package/dist/commands/store-version.d.ts.map +0 -1
- package/dist/commands/store-version.js +0 -241
- package/dist/commands/version.d.ts +0 -3
- package/dist/commands/version.d.ts.map +0 -1
- package/dist/commands/version.js +0 -46
- package/dist/commands/whoami.d.ts +0 -3
- package/dist/commands/whoami.d.ts.map +0 -1
- package/dist/commands/whoami.js +0 -41
- package/dist/index.d.ts.map +0 -1
- package/dist/prompts/component.prompts.d.ts +0 -14
- package/dist/prompts/component.prompts.d.ts.map +0 -1
- package/dist/prompts/component.prompts.js +0 -75
- package/dist/prompts/function.prompts.d.ts +0 -21
- package/dist/prompts/function.prompts.d.ts.map +0 -1
- package/dist/prompts/function.prompts.js +0 -127
- package/dist/schemas/command.schema.d.ts +0 -516
- package/dist/schemas/command.schema.d.ts.map +0 -1
- package/dist/schemas/command.schema.js +0 -267
- package/dist/types/index.d.ts +0 -147
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/index.js +0 -18
- package/dist/utils/auth.d.ts +0 -4
- package/dist/utils/auth.d.ts.map +0 -1
- package/dist/utils/auth.js +0 -26
- package/dist/utils/cli-progress-reporter.d.ts +0 -12
- package/dist/utils/cli-progress-reporter.d.ts.map +0 -1
- package/dist/utils/cli-progress-reporter.js +0 -77
- package/dist/utils/command-builder.d.ts +0 -22
- package/dist/utils/command-builder.d.ts.map +0 -1
- package/dist/utils/command-builder.js +0 -268
- package/dist/utils/command-helpers.d.ts +0 -19
- package/dist/utils/command-helpers.d.ts.map +0 -1
- package/dist/utils/command-helpers.js +0 -79
- package/dist/utils/command-parser.d.ts +0 -146
- package/dist/utils/command-parser.d.ts.map +0 -1
- package/dist/utils/command-parser.js +0 -179
- package/dist/utils/command-suggestions.d.ts +0 -35
- package/dist/utils/command-suggestions.d.ts.map +0 -1
- package/dist/utils/command-suggestions.js +0 -152
- package/dist/utils/console.d.ts +0 -44
- package/dist/utils/console.d.ts.map +0 -1
- package/dist/utils/console.js +0 -233
- package/dist/utils/constants.d.ts +0 -8
- package/dist/utils/constants.d.ts.map +0 -1
- package/dist/utils/constants.js +0 -10
- package/dist/utils/context-detector.d.ts +0 -12
- package/dist/utils/context-detector.d.ts.map +0 -1
- package/dist/utils/context-detector.js +0 -155
- package/dist/utils/enhanced-error-handler.d.ts +0 -47
- package/dist/utils/enhanced-error-handler.d.ts.map +0 -1
- package/dist/utils/enhanced-error-handler.js +0 -221
- package/dist/utils/error-handler.d.ts +0 -3
- package/dist/utils/error-handler.d.ts.map +0 -1
- package/dist/utils/error-handler.js +0 -55
- package/dist/utils/errors.d.ts +0 -44
- package/dist/utils/errors.d.ts.map +0 -1
- package/dist/utils/errors.js +0 -76
- package/dist/utils/interactive-builder.d.ts +0 -22
- package/dist/utils/interactive-builder.d.ts.map +0 -1
- package/dist/utils/interactive-builder.js +0 -246
- package/dist/utils/rich-progress.d.ts +0 -59
- package/dist/utils/rich-progress.d.ts.map +0 -1
- package/dist/utils/rich-progress.js +0 -234
- package/dist/utils/store.d.ts +0 -11
- package/dist/utils/store.d.ts.map +0 -1
- package/dist/utils/store.js +0 -19
- package/dist/utils/validation-error-formatter.d.ts +0 -25
- package/dist/utils/validation-error-formatter.d.ts.map +0 -1
- package/dist/utils/validation-error-formatter.js +0 -258
- package/dist/utils/validation-helpers.d.ts +0 -60
- package/dist/utils/validation-helpers.d.ts.map +0 -1
- package/dist/utils/validation-helpers.js +0 -152
- package/src/commands/__tests__/version.test.ts +0 -71
|
@@ -1,258 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.formatZodError = formatZodError;
|
|
4
|
-
exports.displayErrors = displayErrors;
|
|
5
|
-
exports.suggestCommand = suggestCommand;
|
|
6
|
-
const COMMON_EXAMPLES = {
|
|
7
|
-
component: [
|
|
8
|
-
{
|
|
9
|
-
description: "Create a header component",
|
|
10
|
-
command: "ollieshop component create --name header-nav --slot header",
|
|
11
|
-
},
|
|
12
|
-
{
|
|
13
|
-
description: "Create a product listing component",
|
|
14
|
-
command: "ollieshop component create --name product-list --slot main",
|
|
15
|
-
},
|
|
16
|
-
],
|
|
17
|
-
function: [
|
|
18
|
-
{
|
|
19
|
-
description: "Create a cart validation function",
|
|
20
|
-
command: "ollieshop function create --name validate-cart --event cart",
|
|
21
|
-
},
|
|
22
|
-
{
|
|
23
|
-
description: "Create an order processing function",
|
|
24
|
-
command: "ollieshop function create --name process-order --event order --timing after",
|
|
25
|
-
},
|
|
26
|
-
],
|
|
27
|
-
"store-version": [
|
|
28
|
-
{
|
|
29
|
-
description: "Create a new version",
|
|
30
|
-
command: "ollieshop store-version create --name summer-2024",
|
|
31
|
-
},
|
|
32
|
-
{
|
|
33
|
-
description: "Clone from existing version",
|
|
34
|
-
command: "ollieshop store-version clone --source v1 --name v2",
|
|
35
|
-
},
|
|
36
|
-
],
|
|
37
|
-
};
|
|
38
|
-
function formatIssue(issue, field) {
|
|
39
|
-
switch (issue.code) {
|
|
40
|
-
case "invalid_type": {
|
|
41
|
-
const invalidTypeIssue = issue;
|
|
42
|
-
if (invalidTypeIssue.received === "undefined") {
|
|
43
|
-
return {
|
|
44
|
-
message: `${humanizeFieldName(field)} is required`,
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
return {
|
|
48
|
-
message: `${humanizeFieldName(field)} must be ${issue.expected}`,
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
case "invalid_enum_value": {
|
|
52
|
-
const options = issue.options || [];
|
|
53
|
-
return {
|
|
54
|
-
message: `Invalid ${humanizeFieldName(field)}`,
|
|
55
|
-
suggestedValue: `Valid options: ${options.join(", ")}`,
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
case "too_small": {
|
|
59
|
-
const minimum = issue.minimum || 0;
|
|
60
|
-
return {
|
|
61
|
-
message: `${humanizeFieldName(field)} must be at least ${minimum} characters`,
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
case "invalid_string": {
|
|
65
|
-
const validation = issue
|
|
66
|
-
.validation;
|
|
67
|
-
if (!validation) {
|
|
68
|
-
return { message: humanizeMessage(issue.message, field) };
|
|
69
|
-
}
|
|
70
|
-
return formatStringValidation(validation, field);
|
|
71
|
-
}
|
|
72
|
-
default:
|
|
73
|
-
return { message: humanizeMessage(issue.message, field) };
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
function formatStringValidation(validation, field) {
|
|
77
|
-
const validationMessages = {
|
|
78
|
-
regex: getRegexMessage(field),
|
|
79
|
-
email: `${humanizeFieldName(field)} must be a valid email address`,
|
|
80
|
-
url: `${humanizeFieldName(field)} must be a valid URL`,
|
|
81
|
-
uuid: `${humanizeFieldName(field)} must be a valid UUID`,
|
|
82
|
-
};
|
|
83
|
-
return {
|
|
84
|
-
message: validationMessages[validation] ||
|
|
85
|
-
`Invalid ${humanizeFieldName(field)} format`,
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Format Zod errors into user-friendly validation errors
|
|
90
|
-
*/
|
|
91
|
-
function formatZodError(error, context) {
|
|
92
|
-
const errors = [];
|
|
93
|
-
for (const issue of error.issues) {
|
|
94
|
-
const field = issue.path.join(".");
|
|
95
|
-
const { message, suggestedValue } = formatIssue(issue, field);
|
|
96
|
-
const error = {
|
|
97
|
-
field,
|
|
98
|
-
message,
|
|
99
|
-
suggestedValue,
|
|
100
|
-
};
|
|
101
|
-
// Add examples based on context
|
|
102
|
-
if (context && COMMON_EXAMPLES[context]) {
|
|
103
|
-
error.examples = COMMON_EXAMPLES[context];
|
|
104
|
-
}
|
|
105
|
-
errors.push(error);
|
|
106
|
-
}
|
|
107
|
-
return errors;
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Display validation errors in a formatted way
|
|
111
|
-
*/
|
|
112
|
-
function displayErrors(console, errors, command) {
|
|
113
|
-
console.error("❌ Validation failed:");
|
|
114
|
-
console.log("");
|
|
115
|
-
for (const error of errors) {
|
|
116
|
-
console.error(` • ${error.field}: ${error.message}`);
|
|
117
|
-
if (error.suggestedValue) {
|
|
118
|
-
console.log(` 💡 ${error.suggestedValue}`);
|
|
119
|
-
}
|
|
120
|
-
if (error.examples && error.examples.length > 0) {
|
|
121
|
-
console.log("");
|
|
122
|
-
console.log(" 📝 Examples:");
|
|
123
|
-
for (const example of error.examples) {
|
|
124
|
-
console.log(` ${example.description}:`);
|
|
125
|
-
console.log(` $ ${example.command}`);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
if (command) {
|
|
130
|
-
console.log("");
|
|
131
|
-
console.info(`💡 For more help, run: ollieshop ${command} --help`);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* Suggest a command from available commands
|
|
136
|
-
*/
|
|
137
|
-
function suggestCommand(input, availableCommands) {
|
|
138
|
-
const normalizedInput = input.toLowerCase();
|
|
139
|
-
// Exact match
|
|
140
|
-
if (availableCommands.includes(normalizedInput)) {
|
|
141
|
-
return normalizedInput;
|
|
142
|
-
}
|
|
143
|
-
// Find commands that start with the input
|
|
144
|
-
const startsWithMatches = availableCommands.filter((cmd) => cmd.toLowerCase().startsWith(normalizedInput));
|
|
145
|
-
if (startsWithMatches.length === 1) {
|
|
146
|
-
return startsWithMatches[0];
|
|
147
|
-
}
|
|
148
|
-
// Find commands that contain the input
|
|
149
|
-
const containsMatches = availableCommands.filter((cmd) => cmd.toLowerCase().includes(normalizedInput));
|
|
150
|
-
if (containsMatches.length === 1) {
|
|
151
|
-
return containsMatches[0];
|
|
152
|
-
}
|
|
153
|
-
// Simple Levenshtein distance for close matches
|
|
154
|
-
const closeMatches = availableCommands
|
|
155
|
-
.map((cmd) => ({
|
|
156
|
-
command: cmd,
|
|
157
|
-
distance: levenshteinDistance(normalizedInput, cmd.toLowerCase()),
|
|
158
|
-
}))
|
|
159
|
-
.filter((match) => match.distance <= 2)
|
|
160
|
-
.sort((a, b) => a.distance - b.distance);
|
|
161
|
-
if (closeMatches.length > 0) {
|
|
162
|
-
const firstMatch = closeMatches[0];
|
|
163
|
-
return firstMatch ? firstMatch.command : undefined;
|
|
164
|
-
}
|
|
165
|
-
return undefined;
|
|
166
|
-
}
|
|
167
|
-
/**
|
|
168
|
-
* Transform field names to human-readable format
|
|
169
|
-
*/
|
|
170
|
-
function humanizeFieldName(field) {
|
|
171
|
-
if (!field)
|
|
172
|
-
return "Value";
|
|
173
|
-
return field
|
|
174
|
-
.split(/[._-]/)
|
|
175
|
-
.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
|
|
176
|
-
.join(" ");
|
|
177
|
-
}
|
|
178
|
-
/**
|
|
179
|
-
* Transform error messages to be more user-friendly
|
|
180
|
-
*/
|
|
181
|
-
function humanizeMessage(message, field) {
|
|
182
|
-
// Handle "Required" messages
|
|
183
|
-
if (message === "Required" || message.toLowerCase() === "required") {
|
|
184
|
-
return `${humanizeFieldName(field)} is required`;
|
|
185
|
-
}
|
|
186
|
-
// Handle regex validation messages
|
|
187
|
-
if (message.includes("Invalid input")) {
|
|
188
|
-
return getRegexMessage(field);
|
|
189
|
-
}
|
|
190
|
-
return message;
|
|
191
|
-
}
|
|
192
|
-
/**
|
|
193
|
-
* Get user-friendly message for regex validation
|
|
194
|
-
*/
|
|
195
|
-
function getRegexMessage(field) {
|
|
196
|
-
const regexMessages = {
|
|
197
|
-
name: "Must be lowercase with hyphens only (e.g., 'my-component', 'header-nav')",
|
|
198
|
-
version: "Must follow semantic versioning (e.g., '1.0.0', '2.1.3')",
|
|
199
|
-
slot: "Must be a valid slot name",
|
|
200
|
-
};
|
|
201
|
-
return regexMessages[field] || "Invalid format";
|
|
202
|
-
}
|
|
203
|
-
function initializeMatrix(a, b) {
|
|
204
|
-
const matrix = [];
|
|
205
|
-
// Initialize matrix with proper dimensions
|
|
206
|
-
for (let i = 0; i <= b.length; i++) {
|
|
207
|
-
const row = [];
|
|
208
|
-
matrix[i] = row;
|
|
209
|
-
for (let j = 0; j <= a.length; j++) {
|
|
210
|
-
if (i === 0) {
|
|
211
|
-
row[j] = j;
|
|
212
|
-
}
|
|
213
|
-
else if (j === 0) {
|
|
214
|
-
row[j] = i;
|
|
215
|
-
}
|
|
216
|
-
else {
|
|
217
|
-
row[j] = 0;
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
return matrix;
|
|
222
|
-
}
|
|
223
|
-
function computeDistance(a, b, i, j, matrix) {
|
|
224
|
-
if (b.charAt(i - 1) === a.charAt(j - 1)) {
|
|
225
|
-
const prevRow = matrix[i - 1];
|
|
226
|
-
return prevRow ? (prevRow[j - 1] ?? 0) : 0;
|
|
227
|
-
}
|
|
228
|
-
const currentRow = matrix[i];
|
|
229
|
-
const prevRow = matrix[i - 1];
|
|
230
|
-
const substitution = prevRow
|
|
231
|
-
? (prevRow[j - 1] ?? 0) + 1
|
|
232
|
-
: Number.MAX_SAFE_INTEGER;
|
|
233
|
-
const insertion = currentRow
|
|
234
|
-
? (currentRow[j - 1] ?? 0) + 1
|
|
235
|
-
: Number.MAX_SAFE_INTEGER;
|
|
236
|
-
const deletion = prevRow ? (prevRow[j] ?? 0) + 1 : Number.MAX_SAFE_INTEGER;
|
|
237
|
-
return Math.min(substitution, insertion, deletion);
|
|
238
|
-
}
|
|
239
|
-
/**
|
|
240
|
-
* Calculate Levenshtein distance between two strings
|
|
241
|
-
*/
|
|
242
|
-
function levenshteinDistance(a, b) {
|
|
243
|
-
if (a.length === 0)
|
|
244
|
-
return b.length;
|
|
245
|
-
if (b.length === 0)
|
|
246
|
-
return a.length;
|
|
247
|
-
const matrix = initializeMatrix(a, b);
|
|
248
|
-
for (let i = 1; i <= b.length; i++) {
|
|
249
|
-
const row = matrix[i];
|
|
250
|
-
if (!row)
|
|
251
|
-
continue;
|
|
252
|
-
for (let j = 1; j <= a.length; j++) {
|
|
253
|
-
row[j] = computeDistance(a, b, i, j, matrix);
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
const lastRow = matrix[b.length];
|
|
257
|
-
return lastRow ? (lastRow[a.length] ?? 0) : 0;
|
|
258
|
-
}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import type { CliConsole } from "./console";
|
|
2
|
-
export interface ValidationResult {
|
|
3
|
-
valid: boolean;
|
|
4
|
-
errors?: Array<{
|
|
5
|
-
message?: string;
|
|
6
|
-
} | string>;
|
|
7
|
-
warnings?: Array<{
|
|
8
|
-
message?: string;
|
|
9
|
-
} | string>;
|
|
10
|
-
}
|
|
11
|
-
export interface SpinnerManager {
|
|
12
|
-
succeed: (text: string) => void;
|
|
13
|
-
fail: (text: string) => void;
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Validate component name format using Zod schema
|
|
17
|
-
*/
|
|
18
|
-
export declare function validateComponentName(name: string): true | string;
|
|
19
|
-
/**
|
|
20
|
-
* Validate function name format using Zod schema
|
|
21
|
-
*/
|
|
22
|
-
export declare function validateFunctionName(name: string): true | string;
|
|
23
|
-
/**
|
|
24
|
-
* Validate store ID format using Zod schema
|
|
25
|
-
*/
|
|
26
|
-
export declare function validateStoreId(storeId: string): true | string;
|
|
27
|
-
/**
|
|
28
|
-
* Validate version name using Zod schema
|
|
29
|
-
*/
|
|
30
|
-
export declare function validateVersionName(name: string): true | string;
|
|
31
|
-
/**
|
|
32
|
-
* Validate priority value using Zod schema
|
|
33
|
-
*/
|
|
34
|
-
export declare function validatePriority(priority: number): true | string;
|
|
35
|
-
/**
|
|
36
|
-
* Validate URL or URL pattern using Zod schema
|
|
37
|
-
*/
|
|
38
|
-
export declare function validateUrl(url: string): true | string;
|
|
39
|
-
/**
|
|
40
|
-
* Validate semantic version using Zod schema
|
|
41
|
-
*/
|
|
42
|
-
export declare function validateSemver(version: string): true | string;
|
|
43
|
-
/**
|
|
44
|
-
* Process validation errors and display them to the user
|
|
45
|
-
*/
|
|
46
|
-
export declare function processValidationErrors(errors: Array<{
|
|
47
|
-
message?: string;
|
|
48
|
-
} | string>, cliConsole: CliConsole): void;
|
|
49
|
-
/**
|
|
50
|
-
* Process validation warnings and display them to the user
|
|
51
|
-
*/
|
|
52
|
-
export declare function processValidationWarnings(warnings: Array<{
|
|
53
|
-
message?: string;
|
|
54
|
-
} | string>, cliConsole: CliConsole): void;
|
|
55
|
-
/**
|
|
56
|
-
* Handle validation result with spinner and console output
|
|
57
|
-
*/
|
|
58
|
-
export declare function handleValidationResult(result: ValidationResult | unknown, spinner: SpinnerManager, cliConsole: CliConsole, entityType: string): void;
|
|
59
|
-
export declare function createMockSpinner(): SpinnerManager;
|
|
60
|
-
//# sourceMappingURL=validation-helpers.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"validation-helpers.d.ts","sourceRoot":"","sources":["../../src/utils/validation-helpers.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAE5C,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,CAAC,EAAE,KAAK,CAAC;QAAE,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,MAAM,CAAC,CAAC;IAC9C,QAAQ,CAAC,EAAE,KAAK,CAAC;QAAE,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,MAAM,CAAC,CAAC;CACjD;AAED,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAChC,IAAI,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;CAC9B;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,CAKjE;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,CAKhE;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,CAK9D;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,CAK/D;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,CAKhE;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,CAKtD;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,CAK7D;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,KAAK,CAAC;IAAE,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAAC,EAC5C,UAAU,EAAE,UAAU,GACrB,IAAI,CAMN;AAED;;GAEG;AACH,wBAAgB,yBAAyB,CACvC,QAAQ,EAAE,KAAK,CAAC;IAAE,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAAC,EAC9C,UAAU,EAAE,UAAU,GACrB,IAAI,CAON;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,gBAAgB,GAAG,OAAO,EAClC,OAAO,EAAE,cAAc,EACvB,UAAU,EAAE,UAAU,EACtB,UAAU,EAAE,MAAM,GACjB,IAAI,CAUN;AA2CD,wBAAgB,iBAAiB,IAAI,cAAc,CASlD"}
|
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.validateComponentName = validateComponentName;
|
|
4
|
-
exports.validateFunctionName = validateFunctionName;
|
|
5
|
-
exports.validateStoreId = validateStoreId;
|
|
6
|
-
exports.validateVersionName = validateVersionName;
|
|
7
|
-
exports.validatePriority = validatePriority;
|
|
8
|
-
exports.validateUrl = validateUrl;
|
|
9
|
-
exports.validateSemver = validateSemver;
|
|
10
|
-
exports.processValidationErrors = processValidationErrors;
|
|
11
|
-
exports.processValidationWarnings = processValidationWarnings;
|
|
12
|
-
exports.handleValidationResult = handleValidationResult;
|
|
13
|
-
exports.createMockSpinner = createMockSpinner;
|
|
14
|
-
const command_schema_1 = require("../schemas/command.schema");
|
|
15
|
-
/**
|
|
16
|
-
* Validate component name format using Zod schema
|
|
17
|
-
*/
|
|
18
|
-
function validateComponentName(name) {
|
|
19
|
-
const result = command_schema_1.ComponentNameSchema.safeParse(name);
|
|
20
|
-
return result.success
|
|
21
|
-
? true
|
|
22
|
-
: result.error.errors[0]?.message || "Invalid component name";
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Validate function name format using Zod schema
|
|
26
|
-
*/
|
|
27
|
-
function validateFunctionName(name) {
|
|
28
|
-
const result = command_schema_1.FunctionNameSchema.safeParse(name);
|
|
29
|
-
return result.success
|
|
30
|
-
? true
|
|
31
|
-
: result.error.errors[0]?.message || "Invalid function name";
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Validate store ID format using Zod schema
|
|
35
|
-
*/
|
|
36
|
-
function validateStoreId(storeId) {
|
|
37
|
-
const result = command_schema_1.StoreIdSchema.safeParse(storeId);
|
|
38
|
-
return result.success
|
|
39
|
-
? true
|
|
40
|
-
: result.error.errors[0]?.message || "Invalid store ID";
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Validate version name using Zod schema
|
|
44
|
-
*/
|
|
45
|
-
function validateVersionName(name) {
|
|
46
|
-
const result = command_schema_1.VersionNameSchema.safeParse(name);
|
|
47
|
-
return result.success
|
|
48
|
-
? true
|
|
49
|
-
: result.error.errors[0]?.message || "Invalid version name";
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Validate priority value using Zod schema
|
|
53
|
-
*/
|
|
54
|
-
function validatePriority(priority) {
|
|
55
|
-
const result = command_schema_1.PrioritySchema.safeParse(priority);
|
|
56
|
-
return result.success
|
|
57
|
-
? true
|
|
58
|
-
: result.error.errors[0]?.message || "Invalid priority";
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Validate URL or URL pattern using Zod schema
|
|
62
|
-
*/
|
|
63
|
-
function validateUrl(url) {
|
|
64
|
-
const result = command_schema_1.UrlSchema.safeParse(url);
|
|
65
|
-
return result.success
|
|
66
|
-
? true
|
|
67
|
-
: result.error.errors[0]?.message || "Invalid URL";
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Validate semantic version using Zod schema
|
|
71
|
-
*/
|
|
72
|
-
function validateSemver(version) {
|
|
73
|
-
const result = command_schema_1.SemverSchema.safeParse(version);
|
|
74
|
-
return result.success
|
|
75
|
-
? true
|
|
76
|
-
: result.error.errors[0]?.message || "Invalid semantic version";
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Process validation errors and display them to the user
|
|
80
|
-
*/
|
|
81
|
-
function processValidationErrors(errors, cliConsole) {
|
|
82
|
-
cliConsole.error("Errors:");
|
|
83
|
-
for (const error of errors) {
|
|
84
|
-
const message = typeof error === "string" ? error : error.message || error;
|
|
85
|
-
cliConsole.error(`• ${message}`);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Process validation warnings and display them to the user
|
|
90
|
-
*/
|
|
91
|
-
function processValidationWarnings(warnings, cliConsole) {
|
|
92
|
-
cliConsole.warn("Warnings:");
|
|
93
|
-
for (const warning of warnings) {
|
|
94
|
-
const message = typeof warning === "string" ? warning : warning.message || warning;
|
|
95
|
-
cliConsole.warn(`• ${message}`);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Handle validation result with spinner and console output
|
|
100
|
-
*/
|
|
101
|
-
function handleValidationResult(result, spinner, cliConsole, entityType) {
|
|
102
|
-
if (typeof result === "object" && result !== null && "valid" in result) {
|
|
103
|
-
const validationResult = result;
|
|
104
|
-
handleValidResult(validationResult, spinner, cliConsole, entityType);
|
|
105
|
-
handleValidationWarnings(validationResult, cliConsole);
|
|
106
|
-
handleValidationErrors(validationResult);
|
|
107
|
-
}
|
|
108
|
-
else {
|
|
109
|
-
spinner.succeed(`${entityType} validation completed`);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* Handle valid/invalid validation status
|
|
114
|
-
*/
|
|
115
|
-
function handleValidResult(result, spinner, cliConsole, entityType) {
|
|
116
|
-
if (result.valid) {
|
|
117
|
-
spinner.succeed(`${entityType} is valid!`);
|
|
118
|
-
}
|
|
119
|
-
else {
|
|
120
|
-
spinner.fail(`${entityType} validation failed`);
|
|
121
|
-
if (result.errors?.length) {
|
|
122
|
-
processValidationErrors(result.errors, cliConsole);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
/**
|
|
127
|
-
* Handle validation warnings display
|
|
128
|
-
*/
|
|
129
|
-
function handleValidationWarnings(result, cliConsole) {
|
|
130
|
-
if (result.warnings?.length) {
|
|
131
|
-
processValidationWarnings(result.warnings, cliConsole);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* Handle validation errors and throw if invalid
|
|
136
|
-
*/
|
|
137
|
-
function handleValidationErrors(result) {
|
|
138
|
-
if (!result.valid) {
|
|
139
|
-
throw new Error("Validation failed");
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
// Test helpers for mocking
|
|
143
|
-
function createMockSpinner() {
|
|
144
|
-
return {
|
|
145
|
-
succeed: () => {
|
|
146
|
-
// Mock spinner success - intentionally empty
|
|
147
|
-
},
|
|
148
|
-
fail: () => {
|
|
149
|
-
// Mock spinner failure - intentionally empty
|
|
150
|
-
},
|
|
151
|
-
};
|
|
152
|
-
}
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import type { Command } from "@commander-js/extra-typings";
|
|
2
|
-
import {
|
|
3
|
-
createTestProgram,
|
|
4
|
-
executeCLI,
|
|
5
|
-
resetCLIMocks,
|
|
6
|
-
} from "@tests/helpers/cli-test-helper";
|
|
7
|
-
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
8
|
-
import { configureVersionCommand } from "../version";
|
|
9
|
-
|
|
10
|
-
// Mock the package.json to provide a test version
|
|
11
|
-
vi.mock("../../package.json", () => ({
|
|
12
|
-
default: { version: "0.2.0" },
|
|
13
|
-
}));
|
|
14
|
-
|
|
15
|
-
// Mock the console utility
|
|
16
|
-
vi.mock("../../utils/console", () => ({
|
|
17
|
-
console: {
|
|
18
|
-
info: vi.fn(),
|
|
19
|
-
error: vi.fn(),
|
|
20
|
-
success: vi.fn(),
|
|
21
|
-
warn: vi.fn(),
|
|
22
|
-
log: vi.fn(),
|
|
23
|
-
},
|
|
24
|
-
}));
|
|
25
|
-
|
|
26
|
-
// Import the mocked console
|
|
27
|
-
import { console as mockConsole } from "../../utils/console";
|
|
28
|
-
|
|
29
|
-
describe("Version Command", () => {
|
|
30
|
-
let program: Command;
|
|
31
|
-
|
|
32
|
-
beforeEach(() => {
|
|
33
|
-
const testSetup = createTestProgram();
|
|
34
|
-
program = testSetup.program;
|
|
35
|
-
|
|
36
|
-
// Configure the version command
|
|
37
|
-
configureVersionCommand(program);
|
|
38
|
-
|
|
39
|
-
// Reset all mocks
|
|
40
|
-
vi.clearAllMocks();
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
afterEach(() => {
|
|
44
|
-
resetCLIMocks();
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
describe("version command", () => {
|
|
48
|
-
it("should display the CLI version", async () => {
|
|
49
|
-
// Act
|
|
50
|
-
const result = await executeCLI(program, ["version"]);
|
|
51
|
-
|
|
52
|
-
// Assert
|
|
53
|
-
expect(result.exitCode).toBe(0);
|
|
54
|
-
expect(mockConsole.info).toHaveBeenCalledWith(
|
|
55
|
-
"Ollie Shop CLI version: 0.2.0",
|
|
56
|
-
);
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
it("should call the version command action", async () => {
|
|
60
|
-
// Act
|
|
61
|
-
const result = await executeCLI(program, ["version"]);
|
|
62
|
-
|
|
63
|
-
// Assert
|
|
64
|
-
expect(result.exitCode).toBe(0);
|
|
65
|
-
expect(mockConsole.info).toHaveBeenCalledTimes(1);
|
|
66
|
-
expect(mockConsole.info).toHaveBeenCalledWith(
|
|
67
|
-
expect.stringContaining("Ollie Shop CLI version:"),
|
|
68
|
-
);
|
|
69
|
-
});
|
|
70
|
-
});
|
|
71
|
-
});
|