lalph 0.3.13 → 0.3.14

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/dist/cli.mjs CHANGED
@@ -144155,16 +144155,49 @@ var LinearError = class extends ErrorClass("lalph/LinearError")({
144155
144155
  cause: Defect
144156
144156
  }) {};
144157
144157
  const selectedProjectId = new ProjectSetting("linear.selectedProjectId", String$1);
144158
- const selectProject$1 = gen(function* () {
144158
+ const createLinearProject = gen(function* () {
144159
144159
  const linear = yield* Linear;
144160
144160
  const projects = yield* runCollect(linear.projects);
144161
- const project = yield* autoComplete({
144162
- message: "Select a Linear project",
144163
- choices: projects.map((project) => ({
144164
- title: project.name,
144165
- value: project
144161
+ const projectName = yield* text$2({
144162
+ message: "Project name",
144163
+ validate(input) {
144164
+ const name = input.trim();
144165
+ if (name.length === 0) return fail$4("Project name cannot be empty");
144166
+ if (projects.some((project) => project.name.toLowerCase() === name.toLowerCase())) return fail$4("A project with this name already exists");
144167
+ return succeed$1(name);
144168
+ }
144169
+ });
144170
+ const teams = yield* linear.use((client) => client.teams()).pipe(map$8((teamConnection) => teamConnection.nodes));
144171
+ const teamId = yield* autoComplete({
144172
+ message: "Select a team for the new project",
144173
+ choices: teams.map((team) => ({
144174
+ title: team.name,
144175
+ value: team.id
144166
144176
  }))
144167
144177
  });
144178
+ const created = yield* linear.use((client) => client.createProject({
144179
+ name: projectName,
144180
+ teamIds: [teamId]
144181
+ }));
144182
+ return yield* linear.use(() => created.project);
144183
+ });
144184
+ const selectProject$1 = gen(function* () {
144185
+ const linear = yield* Linear;
144186
+ const choices = [{
144187
+ title: "Create new",
144188
+ value: { _tag: "create" }
144189
+ }, ...(yield* runCollect(linear.projects)).map((project) => ({
144190
+ title: project.name,
144191
+ value: {
144192
+ _tag: "existing",
144193
+ project
144194
+ }
144195
+ }))];
144196
+ const selected = yield* autoComplete({
144197
+ message: "Select a Linear project",
144198
+ choices
144199
+ });
144200
+ const project = selected._tag === "existing" ? selected.project : yield* createLinearProject;
144168
144201
  yield* Settings.setProject(selectedProjectId, some$2(project.id));
144169
144202
  return project;
144170
144203
  });
@@ -152323,7 +152356,7 @@ const commandSource = make$35("source").pipe(withDescription("Select the issue s
152323
152356
 
152324
152357
  //#endregion
152325
152358
  //#region package.json
152326
- var version = "0.3.13";
152359
+ var version = "0.3.14";
152327
152360
 
152328
152361
  //#endregion
152329
152362
  //#region src/commands/projects/ls.ts
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "lalph",
3
3
  "type": "module",
4
- "version": "0.3.13",
4
+ "version": "0.3.14",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
package/src/Linear.ts CHANGED
@@ -539,19 +539,81 @@ const selectedProjectId = new ProjectSetting(
539
539
  "linear.selectedProjectId",
540
540
  Schema.String,
541
541
  )
542
+ type ProjectSelection =
543
+ | {
544
+ readonly _tag: "create"
545
+ }
546
+ | {
547
+ readonly _tag: "existing"
548
+ readonly project: LinearProject
549
+ }
550
+ const createLinearProject = Effect.gen(function* () {
551
+ const linear = yield* Linear
552
+ const projects = yield* Stream.runCollect(linear.projects)
553
+ const projectName = yield* Prompt.text({
554
+ message: "Project name",
555
+ validate(input) {
556
+ const name = input.trim()
557
+ if (name.length === 0) {
558
+ return Effect.fail("Project name cannot be empty")
559
+ }
560
+ if (
561
+ projects.some(
562
+ (project) => project.name.toLowerCase() === name.toLowerCase(),
563
+ )
564
+ ) {
565
+ return Effect.fail("A project with this name already exists")
566
+ }
567
+ return Effect.succeed(name)
568
+ },
569
+ })
570
+ const teams = yield* linear
571
+ .use((client) => client.teams())
572
+ .pipe(Effect.map((teamConnection) => teamConnection.nodes))
573
+ const teamId = yield* Prompt.autoComplete({
574
+ message: "Select a team for the new project",
575
+ choices: teams.map((team) => ({
576
+ title: team.name,
577
+ value: team.id,
578
+ })),
579
+ })
580
+ const created = yield* linear.use((client) =>
581
+ client.createProject({
582
+ name: projectName,
583
+ teamIds: [teamId],
584
+ }),
585
+ )
586
+ return yield* linear.use(() => created.project!)
587
+ })
542
588
  const selectProject = Effect.gen(function* () {
543
589
  const linear = yield* Linear
544
590
 
545
591
  const projects = yield* Stream.runCollect(linear.projects)
546
-
547
- const project = yield* Prompt.autoComplete({
548
- message: "Select a Linear project",
549
- choices: projects.map((project) => ({
592
+ const choices: ReadonlyArray<{
593
+ readonly title: string
594
+ readonly value: ProjectSelection
595
+ }> = [
596
+ {
597
+ title: "Create new",
598
+ value: { _tag: "create" },
599
+ },
600
+ ...projects.map((project) => ({
550
601
  title: project.name,
551
- value: project,
602
+ value: {
603
+ _tag: "existing" as const,
604
+ project,
605
+ },
552
606
  })),
607
+ ]
608
+
609
+ const selected = yield* Prompt.autoComplete({
610
+ message: "Select a Linear project",
611
+ choices,
553
612
  })
554
613
 
614
+ const project =
615
+ selected._tag === "existing" ? selected.project : yield* createLinearProject
616
+
555
617
  yield* Settings.setProject(selectedProjectId, Option.some(project.id))
556
618
 
557
619
  return project