@yoamigo.com/cli 0.1.3 → 0.1.5

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.
Files changed (2) hide show
  1. package/dist/index.js +40 -30
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -56,22 +56,27 @@ async function saveCredentials(credentials) {
56
56
  var loginCommand = new Command("login").description("Authenticate with your API key").option("-k, --key <apiKey>", "API key (or enter interactively)").action(async (options) => {
57
57
  let apiKey = options.key;
58
58
  if (!apiKey) {
59
- apiKey = await input({
60
- message: "Enter your API key:",
61
- validate: (value) => {
62
- if (!value || value.trim().length === 0) {
63
- return "API key is required";
59
+ try {
60
+ apiKey = await input({
61
+ message: "Enter your API key:",
62
+ validate: (value) => {
63
+ if (!value || value.trim().length === 0) {
64
+ return "API key is required";
65
+ }
66
+ if (!value.startsWith("ya_dev_")) {
67
+ return "Invalid API key format. Keys should start with ya_dev_";
68
+ }
69
+ return true;
64
70
  }
65
- if (!value.startsWith("ya_dev_")) {
66
- return "Invalid API key format. Keys should start with ya_dev_";
67
- }
68
- return true;
69
- }
70
- });
71
+ });
72
+ } catch {
73
+ console.log();
74
+ process.exit(0);
75
+ }
71
76
  }
72
77
  const spinner = ora("Authenticating...").start();
73
78
  try {
74
- const response = await fetch(`${API_BASE_URL}/trpc/developer.validateApiKey?input=${encodeURIComponent(JSON.stringify({ apiKey }))}`, {
79
+ const response = await fetch(`${API_BASE_URL}/api/trpc/developer.validateApiKey?input=${encodeURIComponent(JSON.stringify({ apiKey }))}`, {
75
80
  method: "GET",
76
81
  headers: {
77
82
  "Content-Type": "application/json"
@@ -115,19 +120,24 @@ var TEMPLATES_DIR = path2.resolve(__dirname, "../../templates");
115
120
  var initCommand = new Command2("init").description("Create a new template project").argument("[name]", "Project name").option("-t, --template <template>", "Template to use", "starter").action(async (name, options) => {
116
121
  let projectName = name;
117
122
  if (!projectName) {
118
- projectName = await input2({
119
- message: "Project name:",
120
- default: "my-template",
121
- validate: (value) => {
122
- if (!value || value.trim().length === 0) {
123
- return "Project name is required";
123
+ try {
124
+ projectName = await input2({
125
+ message: "Project name:",
126
+ default: "my-template",
127
+ validate: (value) => {
128
+ if (!value || value.trim().length === 0) {
129
+ return "Project name is required";
130
+ }
131
+ if (!/^[a-z0-9-]+$/.test(value)) {
132
+ return "Project name must be lowercase letters, numbers, and hyphens only";
133
+ }
134
+ return true;
124
135
  }
125
- if (!/^[a-z0-9-]+$/.test(value)) {
126
- return "Project name must be lowercase letters, numbers, and hyphens only";
127
- }
128
- return true;
129
- }
130
- });
136
+ });
137
+ } catch {
138
+ console.log();
139
+ process.exit(0);
140
+ }
131
141
  }
132
142
  const targetDir = path2.resolve(process.cwd(), projectName);
133
143
  const templateDir = path2.join(TEMPLATES_DIR, options.template);
@@ -239,14 +249,14 @@ import path4 from "path";
239
249
  var API_BASE_URL2 = getApiBaseUrl();
240
250
  var APP_BASE_URL = getAppBaseUrl();
241
251
  var EXCLUDE_PATTERNS = ["node_modules", "dist", ".git", "vite.config.ts", "tsconfig.json", "*.log"];
242
- var deployCommand = new Command4("deploy").description("Upload template to YoAmigo").requiredOption("--version <semver>", "Template version (e.g., 1.0.0)").action(async (options) => {
252
+ var deployCommand = new Command4("deploy").description("Upload template to YoAmigo").argument("<version>", "Template version (e.g., 1.0.0)").action(async (version) => {
243
253
  const credentials = await getCredentials();
244
254
  if (!credentials) {
245
255
  console.error(chalk4.red("Error: Not logged in. Run `yoamigo login` first."));
246
256
  process.exit(1);
247
257
  }
248
258
  const versionRegex = /^\d+\.\d+\.\d+$/;
249
- if (!versionRegex.test(options.version)) {
259
+ if (!versionRegex.test(version)) {
250
260
  console.error(chalk4.red("Error: Version must be in semver format (e.g., 1.0.0)"));
251
261
  process.exit(1);
252
262
  }
@@ -265,7 +275,7 @@ var deployCommand = new Command4("deploy").description("Upload template to YoAmi
265
275
  throw new Error("No files found to upload");
266
276
  }
267
277
  spinner.text = `Uploading ${files.length} files...`;
268
- const templateResponse = await fetch(`${API_BASE_URL2}/trpc/developer.createOrUpdateTemplate`, {
278
+ const templateResponse = await fetch(`${API_BASE_URL2}/api/trpc/developer.createOrUpdateTemplate`, {
269
279
  method: "POST",
270
280
  headers: {
271
281
  "Content-Type": "application/json",
@@ -273,7 +283,7 @@ var deployCommand = new Command4("deploy").description("Upload template to YoAmi
273
283
  },
274
284
  body: JSON.stringify({
275
285
  name: templateName,
276
- version: options.version,
286
+ version,
277
287
  description: packageJson.description || ""
278
288
  })
279
289
  });
@@ -290,7 +300,7 @@ var deployCommand = new Command4("deploy").description("Upload template to YoAmi
290
300
  for (const file of files) {
291
301
  const relativePath = path4.relative(process.cwd(), file);
292
302
  const content = await fs4.readFile(file, "utf-8");
293
- const uploadResponse = await fetch(`${API_BASE_URL2}/trpc/developer.uploadTemplateFile`, {
303
+ const uploadResponse = await fetch(`${API_BASE_URL2}/api/trpc/developer.uploadTemplateFile`, {
294
304
  method: "POST",
295
305
  headers: {
296
306
  "Content-Type": "application/json",
@@ -306,7 +316,7 @@ var deployCommand = new Command4("deploy").description("Upload template to YoAmi
306
316
  console.warn(chalk4.yellow(`Warning: Failed to upload ${relativePath}`));
307
317
  }
308
318
  }
309
- spinner.succeed(`Template v${options.version} deployed successfully!`);
319
+ spinner.succeed(`Template v${version} deployed successfully!`);
310
320
  console.log();
311
321
  console.log(chalk4.green("Preview URL:"));
312
322
  console.log(chalk4.cyan(` ${APP_BASE_URL}/preview/${templateId}`));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yoamigo.com/cli",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "CLI for creating and managing YoAmigo templates",
5
5
  "type": "module",
6
6
  "license": "SEE LICENSE IN LICENSE",