@ollie-shop/cli 0.2.0 → 0.3.0
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 +2 -11
- package/CHANGELOG.md +13 -7
- package/CLAUDE_CLI.md +265 -0
- package/README.md +704 -8
- package/__tests__/mocks/console.ts +22 -0
- package/__tests__/mocks/core.ts +137 -0
- package/__tests__/mocks/index.ts +4 -0
- package/__tests__/mocks/inquirer.ts +16 -0
- package/__tests__/mocks/progress.ts +19 -0
- package/dist/__tests__/helpers/cli-test-helper.d.ts +89 -0
- package/dist/__tests__/helpers/cli-test-helper.d.ts.map +1 -0
- package/dist/__tests__/helpers/cli-test-helper.js +220 -0
- package/dist/__tests__/mocks/index.d.ts +69 -0
- package/dist/__tests__/mocks/index.d.ts.map +1 -0
- package/dist/__tests__/mocks/index.js +77 -0
- package/dist/actions/component.actions.d.ts +14 -0
- package/dist/actions/component.actions.d.ts.map +1 -0
- package/dist/actions/component.actions.js +273 -0
- package/dist/actions/function.actions.d.ts +15 -0
- package/dist/actions/function.actions.d.ts.map +1 -0
- package/dist/actions/function.actions.js +254 -0
- package/dist/actions/project.actions.d.ts +17 -0
- package/dist/actions/project.actions.d.ts.map +1 -0
- package/dist/actions/project.actions.js +97 -0
- package/dist/actions/version.actions.d.ts +19 -0
- package/dist/actions/version.actions.d.ts.map +1 -0
- package/dist/actions/version.actions.js +216 -0
- package/dist/commands/component.d.ts +3 -0
- package/dist/commands/component.d.ts.map +1 -0
- package/dist/commands/component.js +192 -0
- package/dist/commands/docs.d.ts +3 -0
- package/dist/commands/docs.d.ts.map +1 -0
- package/dist/commands/docs.js +16 -0
- package/dist/commands/function.d.ts +3 -0
- package/dist/commands/function.d.ts.map +1 -0
- package/dist/commands/function.js +243 -0
- package/dist/commands/help.d.ts +3 -0
- package/dist/commands/help.d.ts.map +1 -0
- package/dist/commands/help.js +20 -0
- package/dist/commands/index.d.ts +3 -0
- package/dist/commands/index.d.ts.map +1 -0
- package/dist/commands/index.js +26 -0
- package/dist/commands/login.d.ts +3 -0
- package/dist/commands/login.d.ts.map +1 -0
- package/dist/commands/login.js +175 -0
- package/dist/commands/project.d.ts +3 -0
- package/dist/commands/project.d.ts.map +1 -0
- package/dist/commands/project.js +78 -0
- package/dist/commands/store-version.d.ts +3 -0
- package/dist/commands/store-version.d.ts.map +1 -0
- package/dist/commands/store-version.js +241 -0
- package/dist/commands/version.d.ts +3 -0
- package/dist/commands/version.d.ts.map +1 -0
- package/dist/commands/version.js +46 -0
- package/dist/commands/whoami.d.ts +3 -0
- package/dist/commands/whoami.d.ts.map +1 -0
- package/dist/commands/whoami.js +41 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +88 -478
- package/dist/prompts/component.prompts.d.ts +14 -0
- package/dist/prompts/component.prompts.d.ts.map +1 -0
- package/dist/prompts/component.prompts.js +75 -0
- package/dist/prompts/function.prompts.d.ts +21 -0
- package/dist/prompts/function.prompts.d.ts.map +1 -0
- package/dist/prompts/function.prompts.js +127 -0
- package/dist/schemas/command.schema.d.ts +516 -0
- package/dist/schemas/command.schema.d.ts.map +1 -0
- package/dist/schemas/command.schema.js +267 -0
- package/dist/types/index.d.ts +147 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +18 -0
- package/dist/utils/auth.d.ts +4 -0
- package/dist/utils/auth.d.ts.map +1 -0
- package/dist/utils/auth.js +26 -0
- package/dist/utils/cli-progress-reporter.d.ts +12 -0
- package/dist/utils/cli-progress-reporter.d.ts.map +1 -0
- package/dist/utils/cli-progress-reporter.js +77 -0
- package/dist/utils/command-builder.d.ts +22 -0
- package/dist/utils/command-builder.d.ts.map +1 -0
- package/dist/utils/command-builder.js +268 -0
- package/dist/utils/command-helpers.d.ts +19 -0
- package/dist/utils/command-helpers.d.ts.map +1 -0
- package/dist/utils/command-helpers.js +79 -0
- package/dist/utils/command-parser.d.ts +146 -0
- package/dist/utils/command-parser.d.ts.map +1 -0
- package/dist/utils/command-parser.js +179 -0
- package/dist/utils/command-suggestions.d.ts +35 -0
- package/dist/utils/command-suggestions.d.ts.map +1 -0
- package/dist/utils/command-suggestions.js +152 -0
- package/dist/utils/console.d.ts +44 -0
- package/dist/utils/console.d.ts.map +1 -0
- package/dist/utils/console.js +233 -0
- package/dist/utils/constants.d.ts +8 -0
- package/dist/utils/constants.d.ts.map +1 -0
- package/dist/utils/constants.js +10 -0
- package/dist/utils/context-detector.d.ts +12 -0
- package/dist/utils/context-detector.d.ts.map +1 -0
- package/dist/utils/context-detector.js +155 -0
- package/dist/utils/enhanced-error-handler.d.ts +47 -0
- package/dist/utils/enhanced-error-handler.d.ts.map +1 -0
- package/dist/utils/enhanced-error-handler.js +221 -0
- package/dist/utils/error-handler.d.ts +3 -0
- package/dist/utils/error-handler.d.ts.map +1 -0
- package/dist/utils/error-handler.js +55 -0
- package/dist/utils/errors.d.ts +44 -0
- package/dist/utils/errors.d.ts.map +1 -0
- package/dist/utils/errors.js +76 -0
- package/dist/utils/interactive-builder.d.ts +22 -0
- package/dist/utils/interactive-builder.d.ts.map +1 -0
- package/dist/utils/interactive-builder.js +246 -0
- package/dist/utils/rich-progress.d.ts +59 -0
- package/dist/utils/rich-progress.d.ts.map +1 -0
- package/dist/utils/rich-progress.js +234 -0
- package/dist/utils/store.d.ts +11 -0
- package/dist/utils/store.d.ts.map +1 -0
- package/dist/utils/store.js +19 -0
- package/dist/utils/validation-error-formatter.d.ts +25 -0
- package/dist/utils/validation-error-formatter.d.ts.map +1 -0
- package/dist/utils/validation-error-formatter.js +258 -0
- package/dist/utils/validation-helpers.d.ts +60 -0
- package/dist/utils/validation-helpers.d.ts.map +1 -0
- package/dist/utils/validation-helpers.js +152 -0
- package/package.json +43 -11
- package/src/__tests__/helpers/cli-test-helper.ts +281 -0
- package/src/__tests__/mocks/index.ts +142 -0
- package/src/actions/component.actions.ts +334 -0
- package/src/actions/function.actions.ts +313 -0
- package/src/actions/project.actions.ts +126 -0
- package/src/actions/version.actions.ts +233 -0
- package/src/commands/__tests__/component-validation.test.ts +250 -0
- package/src/commands/__tests__/component.test.ts +321 -0
- package/src/commands/__tests__/function-validation.test.ts +220 -0
- package/src/commands/__tests__/function.test.ts +286 -0
- package/src/commands/__tests__/store-version-validation.test.ts +414 -0
- package/src/commands/__tests__/store-version.test.ts +405 -0
- package/src/commands/__tests__/version.test.ts +71 -0
- package/src/commands/component.ts +188 -0
- package/src/commands/docs.ts +11 -11
- package/src/commands/function.ts +252 -0
- package/src/commands/help.ts +8 -18
- package/src/commands/index.ts +14 -7
- package/src/commands/login.ts +19 -79
- package/src/commands/project.ts +107 -0
- package/src/commands/store-version.ts +242 -0
- package/src/commands/version.ts +45 -8
- package/src/commands/whoami.ts +8 -13
- package/src/index.ts +108 -34
- package/src/prompts/component.prompts.ts +94 -0
- package/src/prompts/function.prompts.ts +168 -0
- package/src/schemas/command.schema.ts +354 -0
- package/src/types/index.ts +183 -0
- package/src/utils/__tests__/command-parser.test.ts +159 -0
- package/src/utils/__tests__/command-suggestions.test.ts +185 -0
- package/src/utils/__tests__/console.test.ts +192 -0
- package/src/utils/__tests__/context-detector.test.ts +258 -0
- package/src/utils/__tests__/enhanced-error-handler.test.ts +137 -0
- package/src/utils/__tests__/error-handler.test.ts +107 -0
- package/src/utils/__tests__/rich-progress.test.ts +170 -0
- package/src/utils/__tests__/validation-error-formatter.test.ts +175 -0
- package/src/utils/__tests__/validation-helpers.test.ts +125 -0
- package/src/utils/auth.ts +0 -1
- package/src/utils/cli-progress-reporter.ts +84 -0
- package/src/utils/command-builder.ts +390 -0
- package/src/utils/command-helpers.ts +83 -0
- package/src/utils/command-parser.ts +250 -0
- package/src/utils/command-suggestions.ts +176 -0
- package/src/utils/console.ts +291 -0
- package/src/utils/context-detector.ts +177 -0
- package/src/utils/enhanced-error-handler.ts +264 -0
- package/src/utils/error-handler.ts +60 -0
- package/src/utils/errors.ts +125 -0
- package/src/utils/interactive-builder.ts +271 -0
- package/src/utils/rich-progress.ts +320 -0
- package/src/utils/validation-error-formatter.ts +337 -0
- package/src/utils/validation-helpers.ts +192 -0
- package/tsconfig.json +13 -7
- package/vitest.config.ts +28 -0
- package/vitest.setup.ts +29 -0
- package/src/commands/validate.ts +0 -62
- package/src/utils/core.ts +0 -105
- package/tsup.config.ts +0 -15
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ComponentNameSchema,
|
|
3
|
+
FunctionNameSchema,
|
|
4
|
+
PrioritySchema,
|
|
5
|
+
SemverSchema,
|
|
6
|
+
StoreIdSchema,
|
|
7
|
+
UrlSchema,
|
|
8
|
+
VersionNameSchema,
|
|
9
|
+
} from "../schemas/command.schema";
|
|
10
|
+
import type { CliConsole } from "./console";
|
|
11
|
+
|
|
12
|
+
export interface ValidationResult {
|
|
13
|
+
valid: boolean;
|
|
14
|
+
errors?: Array<{ message?: string } | string>;
|
|
15
|
+
warnings?: Array<{ message?: string } | string>;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface SpinnerManager {
|
|
19
|
+
succeed: (text: string) => void;
|
|
20
|
+
fail: (text: string) => void;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Validate component name format using Zod schema
|
|
25
|
+
*/
|
|
26
|
+
export function validateComponentName(name: string): true | string {
|
|
27
|
+
const result = ComponentNameSchema.safeParse(name);
|
|
28
|
+
return result.success
|
|
29
|
+
? true
|
|
30
|
+
: result.error.errors[0]?.message || "Invalid component name";
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Validate function name format using Zod schema
|
|
35
|
+
*/
|
|
36
|
+
export function validateFunctionName(name: string): true | string {
|
|
37
|
+
const result = FunctionNameSchema.safeParse(name);
|
|
38
|
+
return result.success
|
|
39
|
+
? true
|
|
40
|
+
: result.error.errors[0]?.message || "Invalid function name";
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Validate store ID format using Zod schema
|
|
45
|
+
*/
|
|
46
|
+
export function validateStoreId(storeId: string): true | string {
|
|
47
|
+
const result = StoreIdSchema.safeParse(storeId);
|
|
48
|
+
return result.success
|
|
49
|
+
? true
|
|
50
|
+
: result.error.errors[0]?.message || "Invalid store ID";
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Validate version name using Zod schema
|
|
55
|
+
*/
|
|
56
|
+
export function validateVersionName(name: string): true | string {
|
|
57
|
+
const result = VersionNameSchema.safeParse(name);
|
|
58
|
+
return result.success
|
|
59
|
+
? true
|
|
60
|
+
: result.error.errors[0]?.message || "Invalid version name";
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Validate priority value using Zod schema
|
|
65
|
+
*/
|
|
66
|
+
export function validatePriority(priority: number): true | string {
|
|
67
|
+
const result = PrioritySchema.safeParse(priority);
|
|
68
|
+
return result.success
|
|
69
|
+
? true
|
|
70
|
+
: result.error.errors[0]?.message || "Invalid priority";
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Validate URL or URL pattern using Zod schema
|
|
75
|
+
*/
|
|
76
|
+
export function validateUrl(url: string): true | string {
|
|
77
|
+
const result = UrlSchema.safeParse(url);
|
|
78
|
+
return result.success
|
|
79
|
+
? true
|
|
80
|
+
: result.error.errors[0]?.message || "Invalid URL";
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Validate semantic version using Zod schema
|
|
85
|
+
*/
|
|
86
|
+
export function validateSemver(version: string): true | string {
|
|
87
|
+
const result = SemverSchema.safeParse(version);
|
|
88
|
+
return result.success
|
|
89
|
+
? true
|
|
90
|
+
: result.error.errors[0]?.message || "Invalid semantic version";
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Process validation errors and display them to the user
|
|
95
|
+
*/
|
|
96
|
+
export function processValidationErrors(
|
|
97
|
+
errors: Array<{ message?: string } | string>,
|
|
98
|
+
cliConsole: CliConsole,
|
|
99
|
+
): void {
|
|
100
|
+
cliConsole.error("Errors:");
|
|
101
|
+
for (const error of errors) {
|
|
102
|
+
const message = typeof error === "string" ? error : error.message || error;
|
|
103
|
+
cliConsole.error(`• ${message}`);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Process validation warnings and display them to the user
|
|
109
|
+
*/
|
|
110
|
+
export function processValidationWarnings(
|
|
111
|
+
warnings: Array<{ message?: string } | string>,
|
|
112
|
+
cliConsole: CliConsole,
|
|
113
|
+
): void {
|
|
114
|
+
cliConsole.warn("Warnings:");
|
|
115
|
+
for (const warning of warnings) {
|
|
116
|
+
const message =
|
|
117
|
+
typeof warning === "string" ? warning : warning.message || warning;
|
|
118
|
+
cliConsole.warn(`• ${message}`);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Handle validation result with spinner and console output
|
|
124
|
+
*/
|
|
125
|
+
export function handleValidationResult(
|
|
126
|
+
result: ValidationResult | unknown,
|
|
127
|
+
spinner: SpinnerManager,
|
|
128
|
+
cliConsole: CliConsole,
|
|
129
|
+
entityType: string,
|
|
130
|
+
): void {
|
|
131
|
+
if (typeof result === "object" && result !== null && "valid" in result) {
|
|
132
|
+
const validationResult = result as ValidationResult;
|
|
133
|
+
|
|
134
|
+
handleValidResult(validationResult, spinner, cliConsole, entityType);
|
|
135
|
+
handleValidationWarnings(validationResult, cliConsole);
|
|
136
|
+
handleValidationErrors(validationResult);
|
|
137
|
+
} else {
|
|
138
|
+
spinner.succeed(`${entityType} validation completed`);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Handle valid/invalid validation status
|
|
144
|
+
*/
|
|
145
|
+
function handleValidResult(
|
|
146
|
+
result: ValidationResult,
|
|
147
|
+
spinner: SpinnerManager,
|
|
148
|
+
cliConsole: CliConsole,
|
|
149
|
+
entityType: string,
|
|
150
|
+
): void {
|
|
151
|
+
if (result.valid) {
|
|
152
|
+
spinner.succeed(`${entityType} is valid!`);
|
|
153
|
+
} else {
|
|
154
|
+
spinner.fail(`${entityType} validation failed`);
|
|
155
|
+
if (result.errors?.length) {
|
|
156
|
+
processValidationErrors(result.errors, cliConsole);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Handle validation warnings display
|
|
163
|
+
*/
|
|
164
|
+
function handleValidationWarnings(
|
|
165
|
+
result: ValidationResult,
|
|
166
|
+
cliConsole: CliConsole,
|
|
167
|
+
): void {
|
|
168
|
+
if (result.warnings?.length) {
|
|
169
|
+
processValidationWarnings(result.warnings, cliConsole);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Handle validation errors and throw if invalid
|
|
175
|
+
*/
|
|
176
|
+
function handleValidationErrors(result: ValidationResult): void {
|
|
177
|
+
if (!result.valid) {
|
|
178
|
+
throw new Error("Validation failed");
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// Test helpers for mocking
|
|
183
|
+
export function createMockSpinner(): SpinnerManager {
|
|
184
|
+
return {
|
|
185
|
+
succeed: () => {
|
|
186
|
+
// Mock spinner success - intentionally empty
|
|
187
|
+
},
|
|
188
|
+
fail: () => {
|
|
189
|
+
// Mock spinner failure - intentionally empty
|
|
190
|
+
},
|
|
191
|
+
};
|
|
192
|
+
}
|
package/tsconfig.json
CHANGED
|
@@ -1,20 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"compilerOptions": {
|
|
3
|
-
"lib": ["ESNext"
|
|
4
|
-
"module": "
|
|
5
|
-
"target": "
|
|
6
|
-
"moduleResolution": "
|
|
3
|
+
"lib": ["ESNext"],
|
|
4
|
+
"module": "Node16",
|
|
5
|
+
"target": "ES2020",
|
|
6
|
+
"moduleResolution": "Node16",
|
|
7
7
|
"jsx": "react-jsx",
|
|
8
8
|
"strict": true,
|
|
9
9
|
"declaration": true,
|
|
10
|
+
"declarationMap": true,
|
|
10
11
|
"noUncheckedIndexedAccess": true,
|
|
11
12
|
"skipLibCheck": true,
|
|
12
13
|
"esModuleInterop": true,
|
|
14
|
+
"allowSyntheticDefaultImports": true,
|
|
13
15
|
"resolveJsonModule": true,
|
|
14
|
-
"
|
|
16
|
+
"outDir": "dist",
|
|
17
|
+
"rootDir": "src",
|
|
18
|
+
"isolatedModules": true,
|
|
15
19
|
"paths": {
|
|
16
|
-
"@/*": ["./src/*"]
|
|
20
|
+
"@/*": ["./src/*"],
|
|
21
|
+
"@tests/*": ["./src/__tests__/*"]
|
|
17
22
|
}
|
|
18
23
|
},
|
|
19
|
-
"
|
|
24
|
+
"include": ["src/**/*"],
|
|
25
|
+
"exclude": ["node_modules", "dist", "**/*.test.ts"]
|
|
20
26
|
}
|
package/vitest.config.ts
CHANGED
|
@@ -1,7 +1,35 @@
|
|
|
1
|
+
import path from "node:path";
|
|
1
2
|
import { defineConfig } from "vitest/config";
|
|
2
3
|
|
|
3
4
|
export default defineConfig({
|
|
4
5
|
test: {
|
|
5
6
|
globals: true,
|
|
7
|
+
environment: "node",
|
|
8
|
+
exclude: ["**/node_modules/**", "**/dist/**", "**/components/**"],
|
|
9
|
+
include: ["src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}"],
|
|
10
|
+
coverage: {
|
|
11
|
+
provider: "v8",
|
|
12
|
+
reporter: ["text", "json", "html"],
|
|
13
|
+
exclude: [
|
|
14
|
+
"node_modules/",
|
|
15
|
+
"dist/",
|
|
16
|
+
"**/*.d.ts",
|
|
17
|
+
"**/*.config.ts",
|
|
18
|
+
"**/__tests__/**",
|
|
19
|
+
],
|
|
20
|
+
thresholds: {
|
|
21
|
+
lines: 80,
|
|
22
|
+
functions: 80,
|
|
23
|
+
branches: 80,
|
|
24
|
+
statements: 80,
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
setupFiles: ["./vitest.setup.ts"],
|
|
28
|
+
},
|
|
29
|
+
resolve: {
|
|
30
|
+
alias: {
|
|
31
|
+
"@": path.resolve(__dirname, "./src"),
|
|
32
|
+
"@tests": path.resolve(__dirname, "./src/__tests__"),
|
|
33
|
+
},
|
|
6
34
|
},
|
|
7
35
|
});
|
package/vitest.setup.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { vi } from "vitest";
|
|
2
|
+
|
|
3
|
+
// Mock console methods
|
|
4
|
+
global.console = {
|
|
5
|
+
...console,
|
|
6
|
+
log: vi.fn(),
|
|
7
|
+
debug: vi.fn(),
|
|
8
|
+
info: vi.fn(),
|
|
9
|
+
warn: vi.fn(),
|
|
10
|
+
error: vi.fn(),
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
// Mock process.exit
|
|
14
|
+
vi.spyOn(process, "exit").mockImplementation((code?: string | number) => {
|
|
15
|
+
throw new Error(`process.exit called with code ${code}`);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
// Set test environment
|
|
19
|
+
process.env.NODE_ENV = "test";
|
|
20
|
+
process.env.OLLIE_SHOP_CONFIG_DIR = "/tmp/ollie-shop-test";
|
|
21
|
+
|
|
22
|
+
// Global test utilities
|
|
23
|
+
beforeEach(() => {
|
|
24
|
+
vi.clearAllMocks();
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
afterEach(() => {
|
|
28
|
+
vi.restoreAllMocks();
|
|
29
|
+
});
|
package/src/commands/validate.ts
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import fs from "node:fs/promises";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
import chalk from "chalk";
|
|
4
|
-
import type { Command } from "commander";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Register the `validate` command
|
|
8
|
-
*/
|
|
9
|
-
export function configureValidateCommand(program: Command): void {
|
|
10
|
-
program
|
|
11
|
-
// Make componentPath optional here to suppress Commander error
|
|
12
|
-
.command("validate [componentPath]")
|
|
13
|
-
.description("Validate the structure of your custom component")
|
|
14
|
-
.action(async (componentPath: string | undefined) => {
|
|
15
|
-
if (!componentPath) {
|
|
16
|
-
console.error(
|
|
17
|
-
`${chalk.red("❌ Missing required argument:")} component path\n\n` +
|
|
18
|
-
`Example usage:\n ${chalk.cyan("ollieshop validate")} ./path/to/your/component\n`,
|
|
19
|
-
);
|
|
20
|
-
process.exit(1);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const resolvedPath = path.resolve(componentPath);
|
|
24
|
-
const requiredFiles = ["index.tsx", "package.json", "meta.json"];
|
|
25
|
-
const optionalFile = "styles.module.css";
|
|
26
|
-
|
|
27
|
-
let isValid = true;
|
|
28
|
-
|
|
29
|
-
// Track missing required files
|
|
30
|
-
const missingFiles: string[] = [];
|
|
31
|
-
|
|
32
|
-
// Check required files
|
|
33
|
-
for (const file of requiredFiles) {
|
|
34
|
-
try {
|
|
35
|
-
await fs.access(path.join(resolvedPath, file));
|
|
36
|
-
console.log(`${chalk.green("✔")} Found: ${chalk.cyan(file)}`);
|
|
37
|
-
} catch {
|
|
38
|
-
console.log(`${chalk.red("✖")} Missing: ${chalk.cyan(file)}`);
|
|
39
|
-
missingFiles.push(file);
|
|
40
|
-
isValid = false;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// Check optional file presence
|
|
45
|
-
try {
|
|
46
|
-
await fs.access(path.join(resolvedPath, optionalFile));
|
|
47
|
-
console.log(
|
|
48
|
-
`${chalk.yellow("ℹ")} Optional file found: ${chalk.cyan(optionalFile)}`,
|
|
49
|
-
);
|
|
50
|
-
} catch {
|
|
51
|
-
console.log(
|
|
52
|
-
`${chalk.dim("ℹ")} Optional file not found: ${chalk.cyan(optionalFile)}`,
|
|
53
|
-
);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
if (isValid) {
|
|
57
|
-
console.log(`\n${chalk.green("✔")} Component structure looks valid!`);
|
|
58
|
-
} else {
|
|
59
|
-
process.exit(1);
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
}
|
package/src/utils/core.ts
DELETED
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import fs from "node:fs";
|
|
2
|
-
import { createRequire } from "node:module";
|
|
3
|
-
import path from "node:path";
|
|
4
|
-
import chalk from "chalk";
|
|
5
|
-
import latestVersion from "latest-version";
|
|
6
|
-
|
|
7
|
-
const require = createRequire(import.meta.url);
|
|
8
|
-
export const pkg = require("../package.json");
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Checks if there is a newer version of the CLI available
|
|
12
|
-
* and notifies the user to update if so.
|
|
13
|
-
*/
|
|
14
|
-
export async function checkForUpdates() {
|
|
15
|
-
try {
|
|
16
|
-
const latest = await latestVersion(pkg.name);
|
|
17
|
-
if (latest !== pkg.version) {
|
|
18
|
-
console.log(
|
|
19
|
-
chalk.yellow(
|
|
20
|
-
`\n⚠️ A new version ${chalk.bold(latest)} is available!\n Update now: ${chalk.bold(
|
|
21
|
-
"npm install -g @ollie-shop/cli",
|
|
22
|
-
)}\n`,
|
|
23
|
-
),
|
|
24
|
-
);
|
|
25
|
-
}
|
|
26
|
-
} catch {
|
|
27
|
-
// Silently ignore errors if offline or failed
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Displays a custom welcome message when no arguments are passed
|
|
33
|
-
*/
|
|
34
|
-
export function showWelcomeMessage() {
|
|
35
|
-
console.log(
|
|
36
|
-
chalk.cyanBright.bold(
|
|
37
|
-
`\n✨ Welcome to the Ollie Shop CLI - ${pkg.version} ✨\n`,
|
|
38
|
-
),
|
|
39
|
-
);
|
|
40
|
-
console.log("Build, customize and deploy your e-commerce with ease.\n");
|
|
41
|
-
|
|
42
|
-
console.log("Usage:");
|
|
43
|
-
console.log(" ollieshop <command> [options]\n");
|
|
44
|
-
|
|
45
|
-
console.log("Available commands:");
|
|
46
|
-
|
|
47
|
-
// Stable commands
|
|
48
|
-
const stableCommands = [
|
|
49
|
-
{ cmd: "login", desc: "Log in to your Ollie Shop account" },
|
|
50
|
-
{ cmd: "validate", desc: "Validate your component files" },
|
|
51
|
-
{ cmd: "whoami", desc: "Show logged-in user and current store" },
|
|
52
|
-
];
|
|
53
|
-
|
|
54
|
-
for (const { cmd, desc } of stableCommands) {
|
|
55
|
-
console.log(` ${chalk.green(cmd.padEnd(20))} ${desc}`);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
console.log("\nComing soon:");
|
|
59
|
-
|
|
60
|
-
// Coming soon
|
|
61
|
-
const comingSoonCommands = [
|
|
62
|
-
{ cmd: "build", desc: "Compile components for deployment" },
|
|
63
|
-
{ cmd: "deploy", desc: "Deploy a component or function" },
|
|
64
|
-
{ cmd: "dev", desc: "Start local preview server" },
|
|
65
|
-
{ cmd: "status", desc: "Show store status" },
|
|
66
|
-
];
|
|
67
|
-
|
|
68
|
-
for (const { cmd, desc } of comingSoonCommands) {
|
|
69
|
-
console.log(` ${chalk.yellow(cmd.padEnd(20))} ${desc}`);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
console.log(
|
|
73
|
-
`\nFor a full list of commands, run: ${chalk.yellow.bold("ollieshop help")}\n`,
|
|
74
|
-
);
|
|
75
|
-
|
|
76
|
-
console.log(
|
|
77
|
-
"Documentation:",
|
|
78
|
-
chalk.underline.blue("https://docs.ollie.shop/ollie-shop"),
|
|
79
|
-
);
|
|
80
|
-
console.log();
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Ensures the current working directory is a valid Ollie Shop project.
|
|
85
|
-
* If not, it shows an error and exits the process.
|
|
86
|
-
*/
|
|
87
|
-
export function validateProjectLocation() {
|
|
88
|
-
const command = process.argv[2] ?? "";
|
|
89
|
-
|
|
90
|
-
// Commands allowed outside a valid Ollie Shop project
|
|
91
|
-
const allowedOutside = ["help", "docs", "version"];
|
|
92
|
-
|
|
93
|
-
if (allowedOutside.includes(command)) return;
|
|
94
|
-
|
|
95
|
-
const configPath = path.join(process.cwd(), "ollie.json");
|
|
96
|
-
const isValidProject = fs.existsSync(configPath);
|
|
97
|
-
|
|
98
|
-
if (!isValidProject) {
|
|
99
|
-
console.log(`
|
|
100
|
-
${chalk.red("❌")} This command must be run inside an ${chalk.bold("Ollie Shop project")}.
|
|
101
|
-
Please navigate to your project directory and try again.\n`);
|
|
102
|
-
|
|
103
|
-
process.exit(1);
|
|
104
|
-
}
|
|
105
|
-
}
|
package/tsup.config.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { defineConfig } from "tsup";
|
|
2
|
-
|
|
3
|
-
export default defineConfig({
|
|
4
|
-
entry: ["./src/index.ts"],
|
|
5
|
-
bundle: true,
|
|
6
|
-
splitting: false,
|
|
7
|
-
minify: false,
|
|
8
|
-
sourcemap: false,
|
|
9
|
-
platform: "node",
|
|
10
|
-
format: "cjs",
|
|
11
|
-
clean: true,
|
|
12
|
-
treeshake: true,
|
|
13
|
-
dts: false,
|
|
14
|
-
banner: { js: "#!/usr/bin/env node" },
|
|
15
|
-
});
|