atmn 0.0.6 → 0.0.7

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 (3) hide show
  1. package/dist/cli.cjs +77 -28
  2. package/dist/cli.js +76 -27
  3. package/package.json +2 -2
package/dist/cli.cjs CHANGED
@@ -2,18 +2,19 @@
2
2
  'use strict';
3
3
 
4
4
  var commander = require('commander');
5
- var chalk6 = require('chalk');
5
+ var chalk7 = require('chalk');
6
6
  var axios = require('axios');
7
7
  var fs = require('fs');
8
8
  var path = require('path');
9
9
  var createJiti = require('jiti');
10
10
  var url = require('url');
11
- var open = require('open');
11
+ var child_process = require('child_process');
12
12
  var prompts = require('@inquirer/prompts');
13
+ var open = require('open');
13
14
 
14
15
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
15
16
 
16
- var chalk6__default = /*#__PURE__*/_interopDefault(chalk6);
17
+ var chalk7__default = /*#__PURE__*/_interopDefault(chalk7);
17
18
  var axios__default = /*#__PURE__*/_interopDefault(axios);
18
19
  var fs__default = /*#__PURE__*/_interopDefault(fs);
19
20
  var path__default = /*#__PURE__*/_interopDefault(path);
@@ -93,10 +94,10 @@ AUTUMN_SECRET_KEY=${sandboxKey}
93
94
  `;
94
95
  if (fs__default.default.existsSync(envPath)) {
95
96
  fs__default.default.appendFileSync(envPath, envVars);
96
- console.log(chalk6__default.default.green(".env file found. Appended keys."));
97
+ console.log(chalk7__default.default.green(".env file found. Appended keys."));
97
98
  } else {
98
99
  fs__default.default.writeFileSync(envPath, envVars);
99
- console.log(chalk6__default.default.green(".env file not found. Created new .env file and wrote keys."));
100
+ console.log(chalk7__default.default.green(".env file not found. Created new .env file and wrote keys."));
100
101
  }
101
102
  }
102
103
  function readFromEnv() {
@@ -139,8 +140,8 @@ async function request({
139
140
  throw error;
140
141
  }
141
142
  console.error(
142
- chalk6__default.default.red("Error occured when making API request:"),
143
- chalk6__default.default.red(error.response.data.message || error.response.data.error)
143
+ chalk7__default.default.red("Error occured when making API request:"),
144
+ chalk7__default.default.red(error.response.data.message || error.response.data.error)
144
145
  );
145
146
  process.exit(1);
146
147
  }
@@ -307,10 +308,58 @@ export const ${idToVar(feature.id)} = feature({
307
308
  })`;
308
309
  return snippet;
309
310
  }
311
+ function checkAtmnInstalled() {
312
+ try {
313
+ const packageJsonPath = path__default.default.join(process.cwd(), "package.json");
314
+ if (fs__default.default.existsSync(packageJsonPath)) {
315
+ const packageJson = JSON.parse(fs__default.default.readFileSync(packageJsonPath, "utf-8"));
316
+ return !!(packageJson.dependencies?.atmn || packageJson.devDependencies?.atmn);
317
+ }
318
+ child_process.execSync(`node -e "require.resolve('atmn')"`, { stdio: "ignore" });
319
+ return true;
320
+ } catch {
321
+ return false;
322
+ }
323
+ }
324
+ async function installAtmn() {
325
+ const shouldInstall = await prompts.confirm({
326
+ message: "The atmn package is not installed. Would you like to install it now?",
327
+ default: true
328
+ });
329
+ if (!shouldInstall) {
330
+ console.log(chalk7__default.default.yellow("Skipping installation. You can install atmn manually with your preferred package manager."));
331
+ return false;
332
+ }
333
+ const packageManager = await prompts.select({
334
+ message: "Which package manager would you like to use?",
335
+ choices: [
336
+ { name: "npm", value: "npm" },
337
+ { name: "pnpm", value: "pnpm" },
338
+ { name: "bun", value: "bun" }
339
+ ],
340
+ default: "npm"
341
+ });
342
+ try {
343
+ console.log(chalk7__default.default.blue(`Installing atmn with ${packageManager}...`));
344
+ const installCommand = packageManager === "npm" ? "npm install atmn" : packageManager === "pnpm" ? "pnpm add atmn" : "bun add atmn";
345
+ child_process.execSync(installCommand, { stdio: "inherit" });
346
+ console.log(chalk7__default.default.green("atmn installed successfully!"));
347
+ return true;
348
+ } catch (error) {
349
+ console.error(chalk7__default.default.red("Failed to install atmn:"), error);
350
+ return false;
351
+ }
352
+ }
310
353
  async function loadAutumnConfigFile() {
311
354
  const configPath = path__default.default.join(process.cwd(), "autumn.config.ts");
312
355
  const absolutePath = path.resolve(configPath);
313
356
  const fileUrl = url.pathToFileURL(absolutePath).href;
357
+ if (!checkAtmnInstalled()) {
358
+ const installed = await installAtmn();
359
+ if (!installed) {
360
+ throw new Error("atmn package is required but not installed. Please install it manually.");
361
+ }
362
+ }
314
363
  const jiti = createJiti__default.default(importMetaUrl);
315
364
  const mod = await jiti.import(fileUrl);
316
365
  const def = mod.default || mod;
@@ -333,7 +382,7 @@ function writeConfig(config) {
333
382
 
334
383
  // source/commands/pull.ts
335
384
  async function Pull({ config }) {
336
- console.log(chalk6__default.default.green("Pulling products and features from Autumn..."));
385
+ console.log(chalk7__default.default.green("Pulling products and features from Autumn..."));
337
386
  const products = await getAllProducts();
338
387
  const features = await getFeatures();
339
388
  const productSnippets = products.map(
@@ -358,7 +407,7 @@ ${exportBuilder(
358
407
  )}
359
408
  `;
360
409
  writeConfig(autumnConfig);
361
- console.log(chalk6__default.default.green("Success! Config has been updated."));
410
+ console.log(chalk7__default.default.green("Success! Config has been updated."));
362
411
  }
363
412
 
364
413
  // source/core/auth.ts
@@ -374,14 +423,14 @@ async function getOTP(otp) {
374
423
  var passwordTheme = {
375
424
  style: {
376
425
  answer: (text) => {
377
- return chalk6__default.default.magenta("*".repeat(text.length));
426
+ return chalk7__default.default.magenta("*".repeat(text.length));
378
427
  }
379
428
  }
380
429
  };
381
430
  var inputTheme = {
382
431
  style: {
383
432
  answer: (text) => {
384
- return chalk6__default.default.magenta(text);
433
+ return chalk7__default.default.magenta(text);
385
434
  }
386
435
  }
387
436
  };
@@ -419,7 +468,7 @@ async function AuthCommand() {
419
468
  );
420
469
  } else {
421
470
  console.log(
422
- chalk6__default.default.yellow(
471
+ chalk7__default.default.yellow(
423
472
  "Okay, no worries. Go to the Autumn dashboard when you're ready!"
424
473
  )
425
474
  );
@@ -427,7 +476,7 @@ async function AuthCommand() {
427
476
  }
428
477
  storeToEnv(keyInfo.prodKey, keyInfo.sandboxKey);
429
478
  console.log(
430
- chalk6__default.default.green(
479
+ chalk7__default.default.green(
431
480
  "Success! Keys have been stored locally. You may now use the CLI."
432
481
  )
433
482
  );
@@ -437,19 +486,19 @@ async function AuthCommand() {
437
486
  async function Init({ config }) {
438
487
  let apiKey = readFromEnv();
439
488
  if (apiKey) {
440
- console.log(chalk6__default.default.green("API key found. Pulling latest config..."));
489
+ console.log(chalk7__default.default.green("API key found. Pulling latest config..."));
441
490
  await Pull({ config });
442
- console.log(chalk6__default.default.green("Project initialized and config pulled successfully!"));
491
+ console.log(chalk7__default.default.green("Project initialized and config pulled successfully!"));
443
492
  return;
444
493
  }
445
- console.log(chalk6__default.default.yellow("No API key found. Running authentication..."));
494
+ console.log(chalk7__default.default.yellow("No API key found. Running authentication..."));
446
495
  await AuthCommand();
447
496
  apiKey = readFromEnv();
448
497
  if (apiKey) {
449
498
  await Pull({ config });
450
- console.log(chalk6__default.default.green("Project initialized! You are now authenticated and config has been pulled."));
499
+ console.log(chalk7__default.default.green("Project initialized! You are now authenticated and config has been pulled."));
451
500
  } else {
452
- console.log(chalk6__default.default.red("Authentication did not yield an API key. Please check your setup."));
501
+ console.log(chalk7__default.default.red("Authentication did not yield an API key. Please check your setup."));
453
502
  }
454
503
  }
455
504
 
@@ -537,18 +586,18 @@ async function Push({
537
586
  });
538
587
  if (shouldDelete) {
539
588
  await deleteProduct(productId);
540
- console.log(chalk6__default.default.green(`Product [${productId}] deleted successfully!`));
589
+ console.log(chalk7__default.default.green(`Product [${productId}] deleted successfully!`));
541
590
  }
542
591
  }
543
592
  for (let feature of features) {
544
- console.log(chalk6__default.default.green(`Pushing feature [${feature.id}]`));
593
+ console.log(chalk7__default.default.green(`Pushing feature [${feature.id}]`));
545
594
  await upsertFeature(feature);
546
- console.log(chalk6__default.default.green(`Pushed feature [${feature.id}]`));
595
+ console.log(chalk7__default.default.green(`Pushed feature [${feature.id}]`));
547
596
  }
548
597
  for (let product of products) {
549
- console.log(chalk6__default.default.green(`Pushing product [${product.id}]`));
598
+ console.log(chalk7__default.default.green(`Pushing product [${product.id}]`));
550
599
  await upsertProduct(product);
551
- console.log(chalk6__default.default.green(`Pushed product [${product.id}]`));
600
+ console.log(chalk7__default.default.green(`Pushed product [${product.id}]`));
552
601
  }
553
602
  for (let featureId of featuresToDelete) {
554
603
  let shouldDelete = yes || await prompts.confirm({
@@ -556,22 +605,22 @@ async function Push({
556
605
  });
557
606
  if (shouldDelete) {
558
607
  await deleteFeature(featureId);
559
- console.log(chalk6__default.default.green(`Feature [${featureId}] deleted successfully!`));
608
+ console.log(chalk7__default.default.green(`Feature [${featureId}] deleted successfully!`));
560
609
  }
561
610
  }
562
611
  const env = prod ? "prod" : "sandbox";
563
612
  console.log(
564
- chalk6__default.default.magentaBright(`Success! Changes have been pushed to ${env}.`)
613
+ chalk7__default.default.magentaBright(`Success! Changes have been pushed to ${env}.`)
565
614
  );
566
615
  if (prod) {
567
616
  console.log(
568
- chalk6__default.default.magentaBright(
617
+ chalk7__default.default.magentaBright(
569
618
  `You can view the products at ${FRONTEND_URL}/products`
570
619
  )
571
620
  );
572
621
  } else {
573
622
  console.log(
574
- chalk6__default.default.magentaBright(
623
+ chalk7__default.default.magentaBright(
575
624
  `You can view the products at ${FRONTEND_URL}/sandbox/products`
576
625
  )
577
626
  );
@@ -598,6 +647,6 @@ commander.program.command("dashboard").description("Open the Autumn dashboard in
598
647
  open__default.default(`${FRONTEND_URL}`);
599
648
  });
600
649
  commander.program.command("version").description("Show the version of Autumn").action(() => {
601
- console.log(chalk6__default.default.green(`Autumn v${VERSION}`));
650
+ console.log(chalk7__default.default.green(`Autumn v${VERSION}`));
602
651
  });
603
652
  commander.program.parse();
package/dist/cli.js CHANGED
@@ -1,13 +1,14 @@
1
1
  #!/usr/bin/env node
2
2
  import { program } from 'commander';
3
- import chalk6 from 'chalk';
3
+ import chalk7 from 'chalk';
4
4
  import axios from 'axios';
5
5
  import fs from 'fs';
6
6
  import path, { resolve } from 'path';
7
7
  import createJiti from 'jiti';
8
8
  import { pathToFileURL } from 'url';
9
+ import { execSync } from 'child_process';
10
+ import { confirm, input, password, select } from '@inquirer/prompts';
9
11
  import open from 'open';
10
- import { confirm, input, password } from '@inquirer/prompts';
11
12
 
12
13
  // source/constants.ts
13
14
  var FRONTEND_URL = "http://app.useautumn.com";
@@ -78,10 +79,10 @@ AUTUMN_SECRET_KEY=${sandboxKey}
78
79
  `;
79
80
  if (fs.existsSync(envPath)) {
80
81
  fs.appendFileSync(envPath, envVars);
81
- console.log(chalk6.green(".env file found. Appended keys."));
82
+ console.log(chalk7.green(".env file found. Appended keys."));
82
83
  } else {
83
84
  fs.writeFileSync(envPath, envVars);
84
- console.log(chalk6.green(".env file not found. Created new .env file and wrote keys."));
85
+ console.log(chalk7.green(".env file not found. Created new .env file and wrote keys."));
85
86
  }
86
87
  }
87
88
  function readFromEnv() {
@@ -124,8 +125,8 @@ async function request({
124
125
  throw error;
125
126
  }
126
127
  console.error(
127
- chalk6.red("Error occured when making API request:"),
128
- chalk6.red(error.response.data.message || error.response.data.error)
128
+ chalk7.red("Error occured when making API request:"),
129
+ chalk7.red(error.response.data.message || error.response.data.error)
129
130
  );
130
131
  process.exit(1);
131
132
  }
@@ -292,10 +293,58 @@ export const ${idToVar(feature.id)} = feature({
292
293
  })`;
293
294
  return snippet;
294
295
  }
296
+ function checkAtmnInstalled() {
297
+ try {
298
+ const packageJsonPath = path.join(process.cwd(), "package.json");
299
+ if (fs.existsSync(packageJsonPath)) {
300
+ const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf-8"));
301
+ return !!(packageJson.dependencies?.atmn || packageJson.devDependencies?.atmn);
302
+ }
303
+ execSync(`node -e "require.resolve('atmn')"`, { stdio: "ignore" });
304
+ return true;
305
+ } catch {
306
+ return false;
307
+ }
308
+ }
309
+ async function installAtmn() {
310
+ const shouldInstall = await confirm({
311
+ message: "The atmn package is not installed. Would you like to install it now?",
312
+ default: true
313
+ });
314
+ if (!shouldInstall) {
315
+ console.log(chalk7.yellow("Skipping installation. You can install atmn manually with your preferred package manager."));
316
+ return false;
317
+ }
318
+ const packageManager = await select({
319
+ message: "Which package manager would you like to use?",
320
+ choices: [
321
+ { name: "npm", value: "npm" },
322
+ { name: "pnpm", value: "pnpm" },
323
+ { name: "bun", value: "bun" }
324
+ ],
325
+ default: "npm"
326
+ });
327
+ try {
328
+ console.log(chalk7.blue(`Installing atmn with ${packageManager}...`));
329
+ const installCommand = packageManager === "npm" ? "npm install atmn" : packageManager === "pnpm" ? "pnpm add atmn" : "bun add atmn";
330
+ execSync(installCommand, { stdio: "inherit" });
331
+ console.log(chalk7.green("atmn installed successfully!"));
332
+ return true;
333
+ } catch (error) {
334
+ console.error(chalk7.red("Failed to install atmn:"), error);
335
+ return false;
336
+ }
337
+ }
295
338
  async function loadAutumnConfigFile() {
296
339
  const configPath = path.join(process.cwd(), "autumn.config.ts");
297
340
  const absolutePath = resolve(configPath);
298
341
  const fileUrl = pathToFileURL(absolutePath).href;
342
+ if (!checkAtmnInstalled()) {
343
+ const installed = await installAtmn();
344
+ if (!installed) {
345
+ throw new Error("atmn package is required but not installed. Please install it manually.");
346
+ }
347
+ }
299
348
  const jiti = createJiti(import.meta.url);
300
349
  const mod = await jiti.import(fileUrl);
301
350
  const def = mod.default || mod;
@@ -318,7 +367,7 @@ function writeConfig(config) {
318
367
 
319
368
  // source/commands/pull.ts
320
369
  async function Pull({ config }) {
321
- console.log(chalk6.green("Pulling products and features from Autumn..."));
370
+ console.log(chalk7.green("Pulling products and features from Autumn..."));
322
371
  const products = await getAllProducts();
323
372
  const features = await getFeatures();
324
373
  const productSnippets = products.map(
@@ -343,7 +392,7 @@ ${exportBuilder(
343
392
  )}
344
393
  `;
345
394
  writeConfig(autumnConfig);
346
- console.log(chalk6.green("Success! Config has been updated."));
395
+ console.log(chalk7.green("Success! Config has been updated."));
347
396
  }
348
397
 
349
398
  // source/core/auth.ts
@@ -359,14 +408,14 @@ async function getOTP(otp) {
359
408
  var passwordTheme = {
360
409
  style: {
361
410
  answer: (text) => {
362
- return chalk6.magenta("*".repeat(text.length));
411
+ return chalk7.magenta("*".repeat(text.length));
363
412
  }
364
413
  }
365
414
  };
366
415
  var inputTheme = {
367
416
  style: {
368
417
  answer: (text) => {
369
- return chalk6.magenta(text);
418
+ return chalk7.magenta(text);
370
419
  }
371
420
  }
372
421
  };
@@ -404,7 +453,7 @@ async function AuthCommand() {
404
453
  );
405
454
  } else {
406
455
  console.log(
407
- chalk6.yellow(
456
+ chalk7.yellow(
408
457
  "Okay, no worries. Go to the Autumn dashboard when you're ready!"
409
458
  )
410
459
  );
@@ -412,7 +461,7 @@ async function AuthCommand() {
412
461
  }
413
462
  storeToEnv(keyInfo.prodKey, keyInfo.sandboxKey);
414
463
  console.log(
415
- chalk6.green(
464
+ chalk7.green(
416
465
  "Success! Keys have been stored locally. You may now use the CLI."
417
466
  )
418
467
  );
@@ -422,19 +471,19 @@ async function AuthCommand() {
422
471
  async function Init({ config }) {
423
472
  let apiKey = readFromEnv();
424
473
  if (apiKey) {
425
- console.log(chalk6.green("API key found. Pulling latest config..."));
474
+ console.log(chalk7.green("API key found. Pulling latest config..."));
426
475
  await Pull({ config });
427
- console.log(chalk6.green("Project initialized and config pulled successfully!"));
476
+ console.log(chalk7.green("Project initialized and config pulled successfully!"));
428
477
  return;
429
478
  }
430
- console.log(chalk6.yellow("No API key found. Running authentication..."));
479
+ console.log(chalk7.yellow("No API key found. Running authentication..."));
431
480
  await AuthCommand();
432
481
  apiKey = readFromEnv();
433
482
  if (apiKey) {
434
483
  await Pull({ config });
435
- console.log(chalk6.green("Project initialized! You are now authenticated and config has been pulled."));
484
+ console.log(chalk7.green("Project initialized! You are now authenticated and config has been pulled."));
436
485
  } else {
437
- console.log(chalk6.red("Authentication did not yield an API key. Please check your setup."));
486
+ console.log(chalk7.red("Authentication did not yield an API key. Please check your setup."));
438
487
  }
439
488
  }
440
489
 
@@ -522,18 +571,18 @@ async function Push({
522
571
  });
523
572
  if (shouldDelete) {
524
573
  await deleteProduct(productId);
525
- console.log(chalk6.green(`Product [${productId}] deleted successfully!`));
574
+ console.log(chalk7.green(`Product [${productId}] deleted successfully!`));
526
575
  }
527
576
  }
528
577
  for (let feature of features) {
529
- console.log(chalk6.green(`Pushing feature [${feature.id}]`));
578
+ console.log(chalk7.green(`Pushing feature [${feature.id}]`));
530
579
  await upsertFeature(feature);
531
- console.log(chalk6.green(`Pushed feature [${feature.id}]`));
580
+ console.log(chalk7.green(`Pushed feature [${feature.id}]`));
532
581
  }
533
582
  for (let product of products) {
534
- console.log(chalk6.green(`Pushing product [${product.id}]`));
583
+ console.log(chalk7.green(`Pushing product [${product.id}]`));
535
584
  await upsertProduct(product);
536
- console.log(chalk6.green(`Pushed product [${product.id}]`));
585
+ console.log(chalk7.green(`Pushed product [${product.id}]`));
537
586
  }
538
587
  for (let featureId of featuresToDelete) {
539
588
  let shouldDelete = yes || await confirm({
@@ -541,22 +590,22 @@ async function Push({
541
590
  });
542
591
  if (shouldDelete) {
543
592
  await deleteFeature(featureId);
544
- console.log(chalk6.green(`Feature [${featureId}] deleted successfully!`));
593
+ console.log(chalk7.green(`Feature [${featureId}] deleted successfully!`));
545
594
  }
546
595
  }
547
596
  const env = prod ? "prod" : "sandbox";
548
597
  console.log(
549
- chalk6.magentaBright(`Success! Changes have been pushed to ${env}.`)
598
+ chalk7.magentaBright(`Success! Changes have been pushed to ${env}.`)
550
599
  );
551
600
  if (prod) {
552
601
  console.log(
553
- chalk6.magentaBright(
602
+ chalk7.magentaBright(
554
603
  `You can view the products at ${FRONTEND_URL}/products`
555
604
  )
556
605
  );
557
606
  } else {
558
607
  console.log(
559
- chalk6.magentaBright(
608
+ chalk7.magentaBright(
560
609
  `You can view the products at ${FRONTEND_URL}/sandbox/products`
561
610
  )
562
611
  );
@@ -583,6 +632,6 @@ program.command("dashboard").description("Open the Autumn dashboard in your brow
583
632
  open(`${FRONTEND_URL}`);
584
633
  });
585
634
  program.command("version").description("Show the version of Autumn").action(() => {
586
- console.log(chalk6.green(`Autumn v${VERSION}`));
635
+ console.log(chalk7.green(`Autumn v${VERSION}`));
587
636
  });
588
637
  program.parse();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "atmn",
3
- "version": "0.0.6",
3
+ "version": "0.0.7",
4
4
  "license": "MIT",
5
5
  "bin": "dist/cli.js",
6
6
  "main": "dist/index.js",
@@ -23,6 +23,7 @@
23
23
  "dependencies": {
24
24
  "@inquirer/prompts": "^7.6.0",
25
25
  "axios": "^1.10.0",
26
+ "chalk": "^5.2.0",
26
27
  "commander": "^14.0.0",
27
28
  "dotenv": "^17.2.0",
28
29
  "inquirer": "^12.7.0",
@@ -35,7 +36,6 @@
35
36
  "@types/react": "^18.0.32",
36
37
  "@vdemedes/prettier-config": "^2.0.1",
37
38
  "ava": "^5.2.0",
38
- "chalk": "^5.2.0",
39
39
  "eslint-config-xo-react": "^0.27.0",
40
40
  "eslint-plugin-react": "^7.32.2",
41
41
  "eslint-plugin-react-hooks": "^4.6.0",