ai-hero-cli 0.2.7 → 0.2.8

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/bin.cjs +76 -61
  2. package/package.json +1 -1
package/bin.cjs CHANGED
@@ -83427,10 +83427,8 @@ var cherryPick = Command_exports2.make(
83427
83427
  });
83428
83428
  },
83429
83429
  PromptCancelledError: () => {
83430
- return Effect_exports.gen(function* () {
83431
- yield* Console_exports.log("Operation cancelled");
83432
- process.exitCode = 0;
83433
- });
83430
+ process.exitCode = 0;
83431
+ return Effect_exports.succeed(void 0);
83434
83432
  }
83435
83433
  }),
83436
83434
  Effect_exports.catchAll((error4) => {
@@ -83770,61 +83768,68 @@ var runLesson = Effect_exports.fn("runLesson")(function* (opts) {
83770
83768
  subfolder
83771
83769
  });
83772
83770
  yield* Console_exports.clear;
83773
- yield* Console_exports.log(
83774
- util.styleText(
83775
- "bold",
83776
- `Running ${foundLesson.num} ${subfolder}...`
83777
- )
83778
- );
83779
- yield* Console_exports.log(
83780
- util.styleText(
83781
- "dim",
83782
- " Press n + enter to go to the next exercise"
83783
- )
83784
- );
83785
- yield* Console_exports.log(
83786
- util.styleText("dim", " Press h + enter for more shortcuts\n")
83787
- );
83788
- if (readmeFile) {
83789
- yield* logReadmeFile({ readmeFile });
83790
- }
83791
- const result = yield* Effect_exports.try({
83792
- try: () => ChildProcess.execSync(
83793
- `pnpm tsx --env-file="${envFilePath}" "${mainFile}"`,
83794
- {
83795
- stdio: "inherit",
83796
- cwd
83797
- }
83798
- ),
83799
- catch: (error4) => new RunLessonSimpleError({ cause: error4 })
83800
- }).pipe(
83801
- Effect_exports.map(() => "success"),
83802
- Effect_exports.catchAll(() => Effect_exports.succeed("failed"))
83803
- );
83804
83771
  const isExplainer = yield* foundLesson.isExplainer();
83805
- if (isExplainer && readmeFile) {
83806
- yield* logReadmeFile({ readmeFile });
83772
+ let result;
83773
+ if (!mainFile && readmeFile) {
83774
+ yield* Console_exports.log(util.styleText(["bold"], `Read the readme:`));
83775
+ yield* Console_exports.log(
83776
+ util.styleText("dim", path5__namespace.relative(cwd, readmeFile))
83777
+ );
83778
+ yield* Console_exports.log("");
83779
+ result = "readme-only";
83780
+ } else if (mainFile) {
83781
+ yield* Console_exports.log(
83782
+ util.styleText(
83783
+ "bold",
83784
+ `Running ${foundLesson.num} ${subfolder}...`
83785
+ )
83786
+ );
83787
+ if (readmeFile) {
83788
+ yield* logReadmeFile({ readmeFile });
83789
+ }
83790
+ result = yield* Effect_exports.try({
83791
+ try: () => ChildProcess.execSync(
83792
+ `pnpm tsx --env-file="${envFilePath}" "${mainFile}"`,
83793
+ {
83794
+ stdio: "inherit",
83795
+ cwd
83796
+ }
83797
+ ),
83798
+ catch: (error4) => new RunLessonSimpleError({ cause: error4 })
83799
+ }).pipe(
83800
+ Effect_exports.map(() => "success"),
83801
+ Effect_exports.catchAll(() => Effect_exports.succeed("failed"))
83802
+ );
83803
+ if (isExplainer && readmeFile) {
83804
+ yield* logReadmeFile({ readmeFile });
83805
+ }
83806
+ } else {
83807
+ result = "failed";
83807
83808
  }
83808
83809
  const lessonNoun = isExplainer ? {
83809
83810
  successMessage: `Explainer executed! Once you've read the readme and understand the code, you can go to the next exercise.`,
83810
83811
  failureMessage: `Looks like the explainer errored! Want to try again?`,
83811
- lowercase: "explainer"
83812
+ lowercase: "explainer",
83813
+ readmeMessage: `Once you've read the readme, you can go to the next exercise.`
83812
83814
  } : {
83813
83815
  successMessage: "Exercise complete! What's next?",
83814
83816
  failureMessage: `Looks like the exercise errored! Want to try again?`,
83815
- lowercase: "exercise"
83817
+ lowercase: "exercise",
83818
+ readmeMessage: "Once you've read the readme, you can go to the next exercise."
83816
83819
  };
83817
83820
  const { choice: choice6 } = yield* runPrompt(
83818
83821
  () => (0, import_prompts2.default)([
83819
83822
  {
83820
83823
  type: "select",
83821
83824
  name: "choice",
83822
- message: result === "success" ? lessonNoun.successMessage : lessonNoun.failureMessage,
83825
+ message: result === "success" ? lessonNoun.successMessage : result === "readme-only" ? lessonNoun.readmeMessage : lessonNoun.failureMessage,
83823
83826
  choices: [
83824
- {
83825
- title: result === "failed" ? `\u{1F504} Run the ${lessonNoun.lowercase} again` : `\u{1F504} Try the ${lessonNoun.lowercase} again`,
83826
- value: "run-again"
83827
- },
83827
+ ...result === "readme-only" ? [] : [
83828
+ {
83829
+ title: result === "failed" ? `\u{1F504} Run the ${lessonNoun.lowercase} again` : `\u{1F504} Try the ${lessonNoun.lowercase} again`,
83830
+ value: "run-again"
83831
+ }
83832
+ ],
83828
83833
  ...nextExerciseToRun ? [
83829
83834
  {
83830
83835
  title: `\u27A1\uFE0F Run the next exercise: ${nextExerciseToRun?.lessonNumber}-${nextExerciseToRun?.lessonName} ${nextExerciseToRun?.subfolder}`,
@@ -83938,10 +83943,8 @@ var chooseLessonAndRunIt = (opts) => Effect_exports.gen(function* () {
83938
83943
  }).pipe(
83939
83944
  Effect_exports.catchTags({
83940
83945
  PromptCancelledError: () => {
83941
- return Effect_exports.gen(function* () {
83942
- yield* Console_exports.log("Operation cancelled");
83943
- process.exitCode = 0;
83944
- });
83946
+ process.exitCode = 0;
83947
+ return Effect_exports.succeed(void 0);
83945
83948
  }
83946
83949
  }),
83947
83950
  Effect_exports.catchAll(Console_exports.log)
@@ -84041,12 +84044,6 @@ var getMainAndReadmeFiles = Effect_exports.fn("getMainAndReadmeFiles")(
84041
84044
  )
84042
84045
  )
84043
84046
  );
84044
- if (!mainFile) {
84045
- return yield* new LessonEntrypointNotFoundError({
84046
- lesson: opts.lesson.num,
84047
- message: `main.ts file for exercise ${opts.subfolder} not found`
84048
- });
84049
- }
84050
84047
  const readmeFile = yield* opts.lesson.allFiles().pipe(
84051
84048
  Effect_exports.map(
84052
84049
  (files) => files.find(
@@ -84054,7 +84051,16 @@ var getMainAndReadmeFiles = Effect_exports.fn("getMainAndReadmeFiles")(
84054
84051
  )
84055
84052
  )
84056
84053
  );
84057
- return { mainFile, readmeFile };
84054
+ if (!mainFile && !readmeFile) {
84055
+ return yield* new LessonEntrypointNotFoundError({
84056
+ lesson: opts.lesson.num,
84057
+ message: `main.ts file for exercise ${opts.subfolder} not found`
84058
+ });
84059
+ }
84060
+ return {
84061
+ mainFile: mainFile ?? null,
84062
+ readmeFile: readmeFile ?? null
84063
+ };
84058
84064
  }
84059
84065
  );
84060
84066
  var RunLessonSimpleError = class extends Data_exports.TaggedError(
@@ -84366,18 +84372,27 @@ var lint = Command_exports2.make(
84366
84372
  mainFilePath
84367
84373
  );
84368
84374
  if (!mainFileExists) {
84369
- errorTracker.addError(
84370
- lesson,
84371
- `main.ts file not found in the ${subfolder} folder.`
84375
+ const readmeInSubfolderPath = path5__namespace.join(
84376
+ lesson.absolutePath(),
84377
+ subfolder,
84378
+ "readme.md"
84372
84379
  );
84380
+ const readmeInSubfolderExists = yield* existsCache.get(readmeInSubfolderPath);
84381
+ if (!readmeInSubfolderExists) {
84382
+ errorTracker.addError(
84383
+ lesson,
84384
+ `main.ts file not found in the ${subfolder} folder.`
84385
+ );
84386
+ }
84373
84387
  } else {
84374
84388
  const mainFileContent = yield* fs.readFileString(
84375
84389
  mainFilePath
84376
84390
  );
84377
- if (mainFileContent.trim().length === 0) {
84391
+ const lineCount = mainFileContent.trim().split("\n").length;
84392
+ if (lineCount === 1) {
84378
84393
  errorTracker.addError(
84379
84394
  lesson,
84380
- `main.ts file is empty in the ${subfolder} folder.`
84395
+ `main.ts file in the ${subfolder} folder is too short (${lineCount} lines). Please use a readme-only exercise instead if you only need to show instructions.`
84381
84396
  );
84382
84397
  }
84383
84398
  }
@@ -85865,8 +85880,8 @@ var reset2 = Command_exports2.make(
85865
85880
  },
85866
85881
  PromptCancelledError: () => {
85867
85882
  return Effect_exports.gen(function* () {
85868
- yield* Console_exports.log("Operation cancelled");
85869
85883
  process.exitCode = 0;
85884
+ return Effect_exports.succeed(void 0);
85870
85885
  });
85871
85886
  },
85872
85887
  InvalidBranchOperationError: (error4) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai-hero-cli",
3
- "version": "0.2.7",
3
+ "version": "0.2.8",
4
4
  "type": "module",
5
5
  "description": "The CLI used to run exercises for the AI Hero course",
6
6
  "bin": "bin.cjs",