@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
package/dist/index.js
CHANGED
|
@@ -1,489 +1,99 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
18
|
-
|
|
19
|
-
var chalk3__default = /*#__PURE__*/_interopDefault(chalk3);
|
|
20
|
-
var fs__default = /*#__PURE__*/_interopDefault(fs);
|
|
21
|
-
var path2__default = /*#__PURE__*/_interopDefault(path2);
|
|
22
|
-
var fs3__default = /*#__PURE__*/_interopDefault(fs3);
|
|
23
|
-
var latestVersion__default = /*#__PURE__*/_interopDefault(latestVersion);
|
|
24
|
-
|
|
25
|
-
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
26
|
-
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
27
|
-
}) : x)(function(x) {
|
|
28
|
-
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
29
|
-
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
30
|
-
});
|
|
31
|
-
function configureDocsCommand(program) {
|
|
32
|
-
program.command("docs").description("Show documentation links for Ollie Shop").action(() => {
|
|
33
|
-
console.log(chalk3__default.default.cyanBright("\nOllie Shop Documentation\n"));
|
|
34
|
-
console.log(
|
|
35
|
-
`${chalk3__default.default.green("Main Docs:".padEnd(20))} https://docs.ollie.shop/ollie-shop`
|
|
36
|
-
);
|
|
37
|
-
console.log(
|
|
38
|
-
`${chalk3__default.default.green("Components:".padEnd(20))} https://docs.ollie.shop/ollie-shop/concepts/component`
|
|
39
|
-
);
|
|
40
|
-
console.log(
|
|
41
|
-
`${chalk3__default.default.green("Functions:".padEnd(20))} https://docs.ollie.shop/ollie-shop/concepts/function`
|
|
42
|
-
);
|
|
43
|
-
console.log(
|
|
44
|
-
`${chalk3__default.default.green("Versions:".padEnd(20))} https://docs.ollie.shop/ollie-shop/concepts/version
|
|
45
|
-
`
|
|
46
|
-
);
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
function configureHelpCommand(program) {
|
|
50
|
-
program.command("help [command]").description("Display help for a specific command or list all commands").action((cmdName) => {
|
|
51
|
-
if (cmdName) {
|
|
52
|
-
const cmd = program.commands.find((c) => c.name() === cmdName);
|
|
53
|
-
if (cmd) {
|
|
54
|
-
cmd.help();
|
|
55
|
-
} else {
|
|
56
|
-
console.log(chalk3__default.default.red(`Command '${cmdName}' not found.`));
|
|
57
|
-
}
|
|
58
|
-
} else {
|
|
59
|
-
console.log(chalk3__default.default.cyanBright("\nAvailable commands:\n"));
|
|
60
|
-
for (const cmd of program.commands) {
|
|
61
|
-
console.log(
|
|
62
|
-
` ${chalk3__default.default.green(cmd.name().padEnd(20))} ${cmd.description()}`
|
|
63
|
-
);
|
|
64
|
-
}
|
|
65
|
-
console.log(
|
|
66
|
-
`
|
|
67
|
-
Use ${chalk3__default.default.yellow("ollieshop help <command>")} to get more info on a command.
|
|
68
|
-
`
|
|
69
|
-
);
|
|
2
|
+
"use strict";
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
const extra_typings_1 = require("@commander-js/extra-typings");
|
|
8
|
+
const package_json_1 = __importDefault(require("../package.json"));
|
|
9
|
+
const commands_1 = require("./commands");
|
|
10
|
+
const command_schema_1 = require("./schemas/command.schema");
|
|
11
|
+
const console_1 = require("./utils/console");
|
|
12
|
+
class OllieShopCLI {
|
|
13
|
+
constructor() {
|
|
14
|
+
this.program = new extra_typings_1.Command();
|
|
15
|
+
this.setupProgram();
|
|
16
|
+
this.registerCommands();
|
|
70
17
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
if (token) {
|
|
85
|
-
await saveCredentials(token);
|
|
86
|
-
console.log("\u2705 Successfully logged in!");
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
console.error("\u274C Authentication failed. Please try again.");
|
|
90
|
-
process.exit(1);
|
|
91
|
-
} catch (error) {
|
|
92
|
-
console.error(
|
|
93
|
-
`\u274C Login failed: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
94
|
-
);
|
|
95
|
-
process.exit(1);
|
|
18
|
+
setupProgram() {
|
|
19
|
+
this.program
|
|
20
|
+
.name("ollieshop")
|
|
21
|
+
.description("Ollie Shop CLI - Build and manage your e-commerce components and functions")
|
|
22
|
+
.version(package_json_1.default.version)
|
|
23
|
+
.option("-v, --verbose", "Enable verbose logging", false)
|
|
24
|
+
.option("-q, --quiet", "Suppress non-essential output", false)
|
|
25
|
+
.option("--no-color", "Disable colored output", false)
|
|
26
|
+
.option("-c, --config <path>", "Path to configuration file")
|
|
27
|
+
.option("--log-level <level>", "Set log level (error|warn|info|debug)", "info")
|
|
28
|
+
.hook("preAction", (thisCommand) => {
|
|
29
|
+
this.setupGlobalOptions(thisCommand);
|
|
30
|
+
});
|
|
96
31
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
sendErrorResponse(
|
|
109
|
-
res,
|
|
110
|
-
400,
|
|
111
|
-
"Invalid state parameter",
|
|
112
|
-
"Authentication failed. Please try again."
|
|
113
|
-
);
|
|
114
|
-
reject(new Error("Invalid state parameter"));
|
|
115
|
-
return;
|
|
116
|
-
}
|
|
117
|
-
let formData = "";
|
|
118
|
-
req.on("data", (chunk) => {
|
|
119
|
-
formData += chunk.toString();
|
|
120
|
-
});
|
|
121
|
-
await new Promise((formResolve) => {
|
|
122
|
-
req.on("end", () => {
|
|
123
|
-
formResolve();
|
|
124
|
-
});
|
|
125
|
-
});
|
|
126
|
-
const formParams = new URLSearchParams(formData);
|
|
127
|
-
const accessToken = formParams.get("access_token");
|
|
128
|
-
const refreshToken = formParams.get("refresh_token") || "";
|
|
129
|
-
const expiresAt = formParams.get("expires_at") || new Date(Date.now() + 36e5).toISOString();
|
|
130
|
-
if (!accessToken) {
|
|
131
|
-
sendErrorResponse(
|
|
132
|
-
res,
|
|
133
|
-
400,
|
|
134
|
-
"Missing authentication token",
|
|
135
|
-
"Authentication failed. Please try again."
|
|
136
|
-
);
|
|
137
|
-
reject(new Error("Missing authentication token"));
|
|
138
|
-
return;
|
|
139
|
-
}
|
|
140
|
-
try {
|
|
141
|
-
const token = {
|
|
142
|
-
accessToken,
|
|
143
|
-
refreshToken,
|
|
144
|
-
expiresAt
|
|
145
|
-
};
|
|
146
|
-
sendSuccessResponse(res);
|
|
147
|
-
resolve(token);
|
|
148
|
-
} catch (error) {
|
|
149
|
-
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
150
|
-
sendErrorResponse(
|
|
151
|
-
res,
|
|
152
|
-
500,
|
|
153
|
-
"Authentication failed",
|
|
154
|
-
`Error: ${errorMessage}`
|
|
155
|
-
);
|
|
156
|
-
reject(new Error(errorMessage));
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
function sendErrorResponse(res, statusCode, title, message) {
|
|
160
|
-
res.writeHead(statusCode, { "Content-Type": "text/html" });
|
|
161
|
-
res.end(`<h1>${title}</h1><p>${message}</p>`);
|
|
162
|
-
}
|
|
163
|
-
function sendSuccessResponse(res) {
|
|
164
|
-
res.writeHead(200, { "Content-Type": "text/html" });
|
|
165
|
-
res.end(
|
|
166
|
-
"<h1>Authentication successful!</h1><p>You can now close this window and return to the CLI.</p>"
|
|
167
|
-
);
|
|
168
|
-
}
|
|
169
|
-
function sendWaitingResponse(res) {
|
|
170
|
-
res.writeHead(200, { "Content-Type": "text/html" });
|
|
171
|
-
res.end(
|
|
172
|
-
"<h1>Ollie Shop CLI Authentication</h1><p>Waiting for authentication response...</p>"
|
|
173
|
-
);
|
|
174
|
-
}
|
|
175
|
-
async function startWebAuthFlow(options) {
|
|
176
|
-
const state = crypto.randomBytes(16).toString("hex");
|
|
177
|
-
const port = Number.parseInt(options.port, 10);
|
|
178
|
-
const baseUrl = options.authUrl;
|
|
179
|
-
return new Promise((resolve, reject) => {
|
|
180
|
-
const server = http.createServer(async (req, res) => {
|
|
181
|
-
try {
|
|
182
|
-
const url = new URL(req.url || "/", `http://localhost:${port}`);
|
|
183
|
-
if (url.pathname === "/callback") {
|
|
184
|
-
await handleAuthCallback(
|
|
185
|
-
req,
|
|
186
|
-
res,
|
|
187
|
-
state,
|
|
188
|
-
(token) => {
|
|
189
|
-
server.close(() => {
|
|
190
|
-
console.log("\u{1F510} Local authentication server closed");
|
|
191
|
-
resolve(token);
|
|
192
|
-
});
|
|
193
|
-
},
|
|
194
|
-
(error) => {
|
|
195
|
-
server.close(() => {
|
|
196
|
-
console.log("\u{1F510} Local authentication server closed");
|
|
197
|
-
reject(error);
|
|
198
|
-
});
|
|
32
|
+
setupGlobalOptions(thisCommand) {
|
|
33
|
+
try {
|
|
34
|
+
const options = thisCommand.opts();
|
|
35
|
+
const parsedOptions = this.validateGlobalOptions(options);
|
|
36
|
+
console_1.console.setOptions({
|
|
37
|
+
quiet: parsedOptions.quiet,
|
|
38
|
+
verbose: parsedOptions.verbose,
|
|
39
|
+
noColor: !parsedOptions.color, // --no-color sets color to false
|
|
40
|
+
});
|
|
41
|
+
if (parsedOptions.verbose) {
|
|
42
|
+
process.env.DEBUG = "ollieshop:*";
|
|
199
43
|
}
|
|
200
|
-
);
|
|
201
|
-
} else {
|
|
202
|
-
sendWaitingResponse(res);
|
|
203
44
|
}
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
});
|
|
213
|
-
server.listen(port, async () => {
|
|
214
|
-
const redirectUrl = `http://localhost:${port}/callback`;
|
|
215
|
-
const authUrl = new URL(baseUrl);
|
|
216
|
-
authUrl.searchParams.set("flow", "cli");
|
|
217
|
-
authUrl.searchParams.set("state", state);
|
|
218
|
-
authUrl.searchParams.set("redirect_to", redirectUrl);
|
|
219
|
-
console.log("\n\u{1F512} Please authenticate in your browser...\n");
|
|
220
|
-
console.log(`Opening: ${authUrl}
|
|
221
|
-
`);
|
|
222
|
-
const open = (await import('open')).default;
|
|
223
|
-
open(authUrl.toString());
|
|
224
|
-
});
|
|
225
|
-
server.on("error", (err) => {
|
|
226
|
-
if (err.code === "EADDRINUSE") {
|
|
227
|
-
reject(
|
|
228
|
-
new Error(
|
|
229
|
-
`Port ${port} is already in use. Please specify a different port using the --port option.`
|
|
230
|
-
)
|
|
231
|
-
);
|
|
232
|
-
} else {
|
|
233
|
-
reject(err);
|
|
234
|
-
}
|
|
235
|
-
server.close();
|
|
236
|
-
});
|
|
237
|
-
const timeoutId = setTimeout(
|
|
238
|
-
() => {
|
|
239
|
-
server.close(() => {
|
|
240
|
-
console.log("\u{1F510} Local authentication server closed due to timeout");
|
|
241
|
-
reject(new Error("Authentication timed out. Please try again."));
|
|
242
|
-
});
|
|
243
|
-
},
|
|
244
|
-
5 * 60 * 1e3
|
|
245
|
-
);
|
|
246
|
-
server.on("close", () => {
|
|
247
|
-
clearTimeout(timeoutId);
|
|
248
|
-
});
|
|
249
|
-
});
|
|
250
|
-
}
|
|
251
|
-
async function saveCredentials(token) {
|
|
252
|
-
console.log("Saving credentials...");
|
|
253
|
-
const configDir = path2__default.default.join(os.homedir(), ".ollie-shop");
|
|
254
|
-
const credentialsPath = path2__default.default.join(configDir, "credentials.json");
|
|
255
|
-
try {
|
|
256
|
-
await fs__default.default.mkdir(configDir, { recursive: true });
|
|
257
|
-
} catch (error) {
|
|
258
|
-
if (!(error instanceof Error && "code" in error && error.code === "EEXIST")) {
|
|
259
|
-
throw error;
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
await fs__default.default.writeFile(credentialsPath, JSON.stringify(token, null, 2));
|
|
263
|
-
return true;
|
|
264
|
-
}
|
|
265
|
-
function configureValidateCommand(program) {
|
|
266
|
-
program.command("validate [componentPath]").description("Validate the structure of your custom component").action(async (componentPath) => {
|
|
267
|
-
if (!componentPath) {
|
|
268
|
-
console.error(
|
|
269
|
-
`${chalk3__default.default.red("\u274C Missing required argument:")} component path
|
|
270
|
-
|
|
271
|
-
Example usage:
|
|
272
|
-
${chalk3__default.default.cyan("ollieshop validate")} ./path/to/your/component
|
|
273
|
-
`
|
|
274
|
-
);
|
|
275
|
-
process.exit(1);
|
|
276
|
-
}
|
|
277
|
-
const resolvedPath = path2__default.default.resolve(componentPath);
|
|
278
|
-
const requiredFiles = ["index.tsx", "package.json", "meta.json"];
|
|
279
|
-
const optionalFile = "styles.module.css";
|
|
280
|
-
let isValid = true;
|
|
281
|
-
for (const file of requiredFiles) {
|
|
282
|
-
try {
|
|
283
|
-
await fs__default.default.access(path2__default.default.join(resolvedPath, file));
|
|
284
|
-
console.log(`${chalk3__default.default.green("\u2714")} Found: ${chalk3__default.default.cyan(file)}`);
|
|
285
|
-
} catch {
|
|
286
|
-
console.log(`${chalk3__default.default.red("\u2716")} Missing: ${chalk3__default.default.cyan(file)}`);
|
|
287
|
-
isValid = false;
|
|
288
|
-
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
console_1.console.error("Invalid global options:");
|
|
47
|
+
if (error instanceof Error) {
|
|
48
|
+
console_1.console.error(error.message);
|
|
49
|
+
}
|
|
50
|
+
process.exit(1);
|
|
51
|
+
}
|
|
289
52
|
}
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
`${chalk3__default.default.dim("\u2139")} Optional file not found: ${chalk3__default.default.cyan(optionalFile)}`
|
|
298
|
-
);
|
|
53
|
+
validateGlobalOptions(options) {
|
|
54
|
+
const result = command_schema_1.GlobalOptionsSchema.safeParse(options);
|
|
55
|
+
if (!result.success) {
|
|
56
|
+
const errors = result.error.issues.map((issue) => `${issue.path.join(".")}: ${issue.message}`);
|
|
57
|
+
throw new Error(errors.join("\n"));
|
|
58
|
+
}
|
|
59
|
+
return result.data;
|
|
299
60
|
}
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
61
|
+
registerCommands() {
|
|
62
|
+
try {
|
|
63
|
+
(0, commands_1.registerCommands)(this.program);
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
console_1.console.error("Failed to register commands:");
|
|
67
|
+
if (error instanceof Error) {
|
|
68
|
+
console_1.console.error(error.message);
|
|
69
|
+
}
|
|
70
|
+
process.exit(1);
|
|
71
|
+
}
|
|
305
72
|
}
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
`
|
|
322
|
-
|
|
323
|
-
|
|
73
|
+
async run() {
|
|
74
|
+
try {
|
|
75
|
+
// Show command suggestions if no args provided
|
|
76
|
+
if (process.argv.length <= 2) {
|
|
77
|
+
const { showCommandSuggestions } = await import("./utils/command-suggestions.js");
|
|
78
|
+
showCommandSuggestions(console_1.console);
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
await this.program.parseAsync();
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
console_1.console.error("CLI execution failed:");
|
|
85
|
+
if (error instanceof Error) {
|
|
86
|
+
console_1.console.error(error.message);
|
|
87
|
+
if (process.env.DEBUG) {
|
|
88
|
+
console_1.console.info(`Stack trace: ${error.stack || ""}`);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
process.exit(1);
|
|
92
|
+
}
|
|
324
93
|
}
|
|
325
|
-
} catch {
|
|
326
|
-
}
|
|
327
94
|
}
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
`
|
|
332
|
-
\u2728 Welcome to the Ollie Shop CLI - ${pkg.version} \u2728
|
|
333
|
-
`
|
|
334
|
-
)
|
|
335
|
-
);
|
|
336
|
-
console.log("Build, customize and deploy your e-commerce with ease.\n");
|
|
337
|
-
console.log("Usage:");
|
|
338
|
-
console.log(" ollieshop <command> [options]\n");
|
|
339
|
-
console.log("Available commands:");
|
|
340
|
-
const stableCommands = [
|
|
341
|
-
{ cmd: "login", desc: "Log in to your Ollie Shop account" },
|
|
342
|
-
{ cmd: "validate", desc: "Validate your component files" },
|
|
343
|
-
{ cmd: "whoami", desc: "Show logged-in user and current store" }
|
|
344
|
-
];
|
|
345
|
-
for (const { cmd, desc } of stableCommands) {
|
|
346
|
-
console.log(` ${chalk3__default.default.green(cmd.padEnd(20))} ${desc}`);
|
|
347
|
-
}
|
|
348
|
-
console.log("\nComing soon:");
|
|
349
|
-
const comingSoonCommands = [
|
|
350
|
-
{ cmd: "build", desc: "Compile components for deployment" },
|
|
351
|
-
{ cmd: "deploy", desc: "Deploy a component or function" },
|
|
352
|
-
{ cmd: "dev", desc: "Start local preview server" },
|
|
353
|
-
{ cmd: "status", desc: "Show store status" }
|
|
354
|
-
];
|
|
355
|
-
for (const { cmd, desc } of comingSoonCommands) {
|
|
356
|
-
console.log(` ${chalk3__default.default.yellow(cmd.padEnd(20))} ${desc}`);
|
|
357
|
-
}
|
|
358
|
-
console.log(
|
|
359
|
-
`
|
|
360
|
-
For a full list of commands, run: ${chalk3__default.default.yellow.bold("ollieshop help")}
|
|
361
|
-
`
|
|
362
|
-
);
|
|
363
|
-
console.log(
|
|
364
|
-
"Documentation:",
|
|
365
|
-
chalk3__default.default.underline.blue("https://docs.ollie.shop/ollie-shop")
|
|
366
|
-
);
|
|
367
|
-
console.log();
|
|
368
|
-
}
|
|
369
|
-
function validateProjectLocation() {
|
|
370
|
-
const command = process.argv[2] ?? "";
|
|
371
|
-
const allowedOutside = ["help", "docs", "version"];
|
|
372
|
-
if (allowedOutside.includes(command)) return;
|
|
373
|
-
const configPath = path2__default.default.join(process.cwd(), "ollie.json");
|
|
374
|
-
const isValidProject = fs3__default.default.existsSync(configPath);
|
|
375
|
-
if (!isValidProject) {
|
|
376
|
-
console.log(`
|
|
377
|
-
${chalk3__default.default.red("\u274C")} This command must be run inside an ${chalk3__default.default.bold("Ollie Shop project")}.
|
|
378
|
-
Please navigate to your project directory and try again.
|
|
379
|
-
`);
|
|
95
|
+
const cli = new OllieShopCLI();
|
|
96
|
+
cli.run().catch((error) => {
|
|
97
|
+
console_1.console.error(`Unexpected error: ${error}`);
|
|
380
98
|
process.exit(1);
|
|
381
|
-
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
// src/commands/version.ts
|
|
385
|
-
function configureVersionCommand(program) {
|
|
386
|
-
program.command("version").description("Display the current CLI version").action(() => {
|
|
387
|
-
console.log(
|
|
388
|
-
`${chalk3__default.default.bold("Ollie Shop CLI version:")} ${chalk3__default.default.cyan(pkg.version)}
|
|
389
|
-
`
|
|
390
|
-
);
|
|
391
|
-
});
|
|
392
|
-
}
|
|
393
|
-
var CREDENTIALS_PATH = path2__default.default.join(
|
|
394
|
-
os.homedir(),
|
|
395
|
-
".ollie-shop",
|
|
396
|
-
"credentials.json"
|
|
397
|
-
);
|
|
398
|
-
async function getCurrentUser() {
|
|
399
|
-
try {
|
|
400
|
-
const raw = await fs__default.default.readFile(CREDENTIALS_PATH, "utf-8");
|
|
401
|
-
const token = JSON.parse(raw);
|
|
402
|
-
if (!token.accessToken) return null;
|
|
403
|
-
const decoded = jwtDecode.jwtDecode(token.accessToken);
|
|
404
|
-
return {
|
|
405
|
-
email: decoded.email
|
|
406
|
-
};
|
|
407
|
-
} catch {
|
|
408
|
-
return null;
|
|
409
|
-
}
|
|
410
|
-
}
|
|
411
|
-
async function getOllieConfig() {
|
|
412
|
-
try {
|
|
413
|
-
const configPath = path2__default.default.join(process.cwd(), "ollie.json");
|
|
414
|
-
const raw = await fs__default.default.readFile(configPath, "utf-8");
|
|
415
|
-
const data = JSON.parse(raw);
|
|
416
|
-
return data;
|
|
417
|
-
} catch {
|
|
418
|
-
return null;
|
|
419
|
-
}
|
|
420
|
-
}
|
|
421
|
-
|
|
422
|
-
// src/commands/whoami.ts
|
|
423
|
-
async function getUserInfo() {
|
|
424
|
-
try {
|
|
425
|
-
const user = await getCurrentUser();
|
|
426
|
-
const store = await getOllieConfig();
|
|
427
|
-
if (!user || !user.email) {
|
|
428
|
-
console.log("\u274C No user authenticated");
|
|
429
|
-
return {};
|
|
430
|
-
}
|
|
431
|
-
return {
|
|
432
|
-
email: user.email,
|
|
433
|
-
store: store ?? void 0
|
|
434
|
-
};
|
|
435
|
-
} catch {
|
|
436
|
-
return {};
|
|
437
|
-
}
|
|
438
|
-
}
|
|
439
|
-
function configureWhoamiCommand(program) {
|
|
440
|
-
program.command("whoami").description("Show logged-in user and current store").action(async () => {
|
|
441
|
-
const { email, store } = await getUserInfo();
|
|
442
|
-
if (!email) {
|
|
443
|
-
console.log(chalk3__default.default.red("You are not authenticated"));
|
|
444
|
-
return;
|
|
445
|
-
}
|
|
446
|
-
console.log();
|
|
447
|
-
console.log(
|
|
448
|
-
`${chalk3__default.default.bold("You are logged in as:")} ${chalk3__default.default.cyan(email)}`
|
|
449
|
-
);
|
|
450
|
-
if (store) {
|
|
451
|
-
console.log(
|
|
452
|
-
`${chalk3__default.default.bold("Current store:")} ${chalk3__default.default.cyan(store.platformStoreId ?? "unknown")}`
|
|
453
|
-
);
|
|
454
|
-
}
|
|
455
|
-
console.log();
|
|
456
|
-
});
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
// src/commands/index.ts
|
|
460
|
-
function registerCommands(program) {
|
|
461
|
-
configureDocsCommand(program);
|
|
462
|
-
configureHelpCommand(program);
|
|
463
|
-
configureLoginCommand(program);
|
|
464
|
-
configureWhoamiCommand(program);
|
|
465
|
-
configureValidateCommand(program);
|
|
466
|
-
configureVersionCommand(program);
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
// src/index.ts
|
|
470
|
-
function createProgram() {
|
|
471
|
-
const program = new commander.Command();
|
|
472
|
-
program.name("ollieshop").description("Ollie Shop CLI tools").version(pkg.version);
|
|
473
|
-
registerCommands(program);
|
|
474
|
-
return program;
|
|
475
|
-
}
|
|
476
|
-
if (__require.main === module) {
|
|
477
|
-
(async () => {
|
|
478
|
-
const program = createProgram();
|
|
479
|
-
if (process.argv.length <= 2) {
|
|
480
|
-
await checkForUpdates();
|
|
481
|
-
showWelcomeMessage();
|
|
482
|
-
process.exit(0);
|
|
483
|
-
}
|
|
484
|
-
validateProjectLocation();
|
|
485
|
-
program.parse();
|
|
486
|
-
})();
|
|
487
|
-
}
|
|
488
|
-
|
|
489
|
-
exports.createProgram = createProgram;
|
|
99
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type ComponentSlotType } from "@ollie-shop/core";
|
|
2
|
+
export interface ComponentCreationAnswers {
|
|
3
|
+
name: string;
|
|
4
|
+
slot: ComponentSlotType;
|
|
5
|
+
includeTests: boolean;
|
|
6
|
+
description?: string;
|
|
7
|
+
}
|
|
8
|
+
export interface ComponentDeploymentAnswers {
|
|
9
|
+
versionId: string;
|
|
10
|
+
confirm: boolean;
|
|
11
|
+
}
|
|
12
|
+
export declare function promptComponentCreation(name?: string, slot?: string): Promise<ComponentCreationAnswers>;
|
|
13
|
+
export declare function promptComponentDeployment(): Promise<ComponentDeploymentAnswers>;
|
|
14
|
+
//# sourceMappingURL=component.prompts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"component.prompts.d.ts","sourceRoot":"","sources":["../../src/prompts/component.prompts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,KAAK,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAIzE,MAAM,WAAW,wBAAwB;IACvC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,iBAAiB,CAAC;IACxB,YAAY,EAAE,OAAO,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,0BAA0B;IACzC,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,OAAO,CAAC;CAClB;AAQD,wBAAsB,uBAAuB,CAC3C,IAAI,CAAC,EAAE,MAAM,EACb,IAAI,CAAC,EAAE,MAAM,GACZ,OAAO,CAAC,wBAAwB,CAAC,CA8CnC;AAED,wBAAsB,yBAAyB,IAAI,OAAO,CAAC,0BAA0B,CAAC,CAoBrF"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.promptComponentCreation = promptComponentCreation;
|
|
7
|
+
exports.promptComponentDeployment = promptComponentDeployment;
|
|
8
|
+
const core_1 = require("@ollie-shop/core");
|
|
9
|
+
const inquirer_1 = __importDefault(require("inquirer"));
|
|
10
|
+
const validation_helpers_1 = require("../utils/validation-helpers");
|
|
11
|
+
// Generate component slot choices from core enum
|
|
12
|
+
const componentSlotChoices = core_1.ComponentSlot.options.map((slot) => ({
|
|
13
|
+
name: slot.charAt(0).toUpperCase() + slot.slice(1).replace(/-/g, " "),
|
|
14
|
+
value: slot,
|
|
15
|
+
}));
|
|
16
|
+
async function promptComponentCreation(name, slot) {
|
|
17
|
+
const questions = [];
|
|
18
|
+
if (!name) {
|
|
19
|
+
questions.push({
|
|
20
|
+
type: "input",
|
|
21
|
+
name: "name",
|
|
22
|
+
message: "What's the name of your component?",
|
|
23
|
+
validate: (input) => {
|
|
24
|
+
return (0, validation_helpers_1.validateComponentName)(input);
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
if (!slot) {
|
|
29
|
+
questions.push({
|
|
30
|
+
type: "list",
|
|
31
|
+
name: "slot",
|
|
32
|
+
message: "Which slot will this component occupy?",
|
|
33
|
+
choices: componentSlotChoices,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
questions.push({
|
|
37
|
+
type: "input",
|
|
38
|
+
name: "description",
|
|
39
|
+
message: "Enter a description (optional):",
|
|
40
|
+
default: "",
|
|
41
|
+
}, {
|
|
42
|
+
type: "confirm",
|
|
43
|
+
name: "includeTests",
|
|
44
|
+
message: "Include test files?",
|
|
45
|
+
default: true,
|
|
46
|
+
});
|
|
47
|
+
const answers = await inquirer_1.default.prompt(questions);
|
|
48
|
+
return {
|
|
49
|
+
name: name || answers.name,
|
|
50
|
+
slot: slot || answers.slot,
|
|
51
|
+
description: answers.description || undefined,
|
|
52
|
+
includeTests: answers.includeTests,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
async function promptComponentDeployment() {
|
|
56
|
+
const answers = await inquirer_1.default.prompt([
|
|
57
|
+
{
|
|
58
|
+
type: "input",
|
|
59
|
+
name: "versionId",
|
|
60
|
+
message: "Enter the version ID to deploy to:",
|
|
61
|
+
validate: (input) => {
|
|
62
|
+
if (!input.trim())
|
|
63
|
+
return "Version ID is required";
|
|
64
|
+
return true;
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
type: "confirm",
|
|
69
|
+
name: "confirm",
|
|
70
|
+
message: "Are you sure you want to deploy this component?",
|
|
71
|
+
default: false,
|
|
72
|
+
},
|
|
73
|
+
]);
|
|
74
|
+
return answers;
|
|
75
|
+
}
|