refactor: js output
This commit is contained in:
parent
1aa28c2a34
commit
c6704c3a04
96 changed files with 3816 additions and 147 deletions
72
src/commands/CreateCommand.js
Normal file
72
src/commands/CreateCommand.js
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
import { CLICommand } from "../cli/CLICommand.js";
|
||||
import { parseTodoFile, writeTodoFile } from "../file.js";
|
||||
import { getCurrentBranch, commitFile } from "../git.js";
|
||||
export class CreateCommand extends CLICommand {
|
||||
name = "create";
|
||||
help = "Create a new issue";
|
||||
description = "Add an issue to the TODO file (must be on develop)";
|
||||
addArguments(yargs) {
|
||||
return yargs
|
||||
.option("type", {
|
||||
alias: "t",
|
||||
type: "string",
|
||||
choices: ["feature", "bugfix", "hotfix"],
|
||||
demandOption: true,
|
||||
})
|
||||
.option("title", {
|
||||
type: "string",
|
||||
demandOption: true,
|
||||
})
|
||||
.option("priority", {
|
||||
alias: "p",
|
||||
type: "string",
|
||||
choices: ["low", "medium", "high"],
|
||||
default: "medium",
|
||||
})
|
||||
.option("plan", {
|
||||
type: "string",
|
||||
demandOption: true,
|
||||
description: "Description of what needs to be done",
|
||||
})
|
||||
.option("module", {
|
||||
alias: "m",
|
||||
type: "string",
|
||||
});
|
||||
}
|
||||
async execute(args) {
|
||||
const branch = getCurrentBranch();
|
||||
if (branch !== "develop") {
|
||||
console.error(`Must be on develop to create issues (currently on ${branch})`);
|
||||
return 1;
|
||||
}
|
||||
const todo = await parseTodoFile();
|
||||
const mod = args.module;
|
||||
if (mod && todo.modules) {
|
||||
const valid = todo.modules.map(m => m.name);
|
||||
if (!valid.includes(mod)) {
|
||||
console.error(`Module "${mod}" not defined. Valid: ${valid.join(", ")}`);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
const nextId = todo.issues.length > 0
|
||||
? Math.max(...todo.issues.map(i => i.id)) + 1
|
||||
: 1;
|
||||
const today = new Date().toISOString().slice(0, 10);
|
||||
todo.issues.push({
|
||||
id: nextId,
|
||||
type: args.type,
|
||||
title: args.title,
|
||||
status: "open",
|
||||
priority: args.priority,
|
||||
created: today,
|
||||
module: mod,
|
||||
relationships: {},
|
||||
description: args.plan,
|
||||
body: "",
|
||||
});
|
||||
writeTodoFile(todo);
|
||||
commitFile("TODO", `todo(${nextId}): open`);
|
||||
console.log(`Created issue #${nextId}: ${args.title}`);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue