Skip to content

Commit

Permalink
stub projectfile, punchfile, and punch command
Browse files Browse the repository at this point in the history
  • Loading branch information
jkdmyrs committed Jun 8, 2024
1 parent 70d1fe2 commit 036dee3
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 22 deletions.
33 changes: 33 additions & 0 deletions src/_lib/shell.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
export async function executeShellCommandAsync(command: string, args: string[]): Promise<ShellOutput> {
const output = await new Deno.Command(command, { args: args }).output();
return new ShellOutput(output);
}

export class ShellOutput {
private _output: Deno.CommandOutput;

constructor(output: Deno.CommandOutput) {
this._output = output;
}

public get code(): number {
return this._output.code;
}

public get stderr(): string {
return new TextDecoder().decode(this._output.stderr);
}

public get stdout(): string {
return new TextDecoder().decode(this._output.stdout);
}

public verifyZeroReturnCode(): ShellOutput {
if (this._output.code !== 0) {
// todo - enhance error handling
console.log(this.stdout, this.stderr);
throw `non-zero RC: ${this._output.code}`;
}
return this;
}
}
File renamed without changes.
43 changes: 21 additions & 22 deletions src/app/timeclock.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { Configuration } from "../core/configuration.ts";
import { parseArgs } from "../_lib/cli-parser.ts"
import { PROJECTFILE as projectFile } from "../core/files/projectsfile.ts";
import { PUNCHFILE as punchFile } from "../core/files/punchfile.ts";

export class TimeClock {
constructor(private readonly _config: Configuration)
Expand All @@ -11,14 +13,27 @@ export class TimeClock {
const project = args.p;
const invoiceNumber = args.n;

const PROJECTFILE = await projectFile.readFileAsync();

if (! PROJECTFILE.projectExists(project)) {
await PROJECTFILE.addProjectAsync(project);
}
const projectId = PROJECTFILE.getProjectId(project);

switch(command) {
case "punch":
// check PUNCHFILE for existing punch
// if exists
// create a shift (in the project directory), delete PUNCHFILE
// else
// create a punch (in the project directory), create the PUNCHFILE
break;
{
const PUNCHFILE = await punchFile.readFileAsync();
if (PUNCHFILE) {
// create the shift
await PUNCHFILE.deleteAsync();
}
else {
const punchId = ""; // generate a GUID
await punchFile.createAsync(projectId, punchId, new Date(), this._config.rate)
}
break;
}
case "invoice":
{
const verb = args._[1];
Expand Down Expand Up @@ -47,21 +62,5 @@ export class TimeClock {
default:
break;
}

// punch -p <projectname>
// (create or end based on existence)
// (force punchout if punch in elsewhere) - keep a top level status indicator

// invoice create -p <projcetname>
// aggregate all punches into an invoice - calculate total $ based on rate in config

// invoice paid -p <projcetname> -n <invoice number>
// mark the invoice as paid

// invoice status
// get the invoice status for all projcets (unpaid invoices)

// invoice status -p <projectname>
// get the invoice status for a project (unpaid invoices)
}
}
Empty file added src/core/files/incomefile.ts
Empty file.
43 changes: 43 additions & 0 deletions src/core/files/projectsfile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
export class PROJECTFILE {
private constructor(public projects: Array<Project>)
{}

public static async readFileAsync() : Promise<PROJECTFILE> {
await PROJECTFILE.initAsync();
return new PROJECTFILE([]);
}

private static async initAsync() : Promise<void> {

}

private async writeFileAsync() : Promise<void> {

}

public projectExists(projectName: string) : boolean {
return true;
}

public async addProjectAsync(projcetName: string) : Promise<void> {
this.projects.push(new Project(projcetName))
await this.writeFileAsync();
}

public getProjectId(projectName: string) : string {
return "";
}
}

export class Project {
constructor(public name: string)
{}

public get id(): string {
return this.generateProjectId(this.name);
}

private generateProjectId(projectName: string) : string {
return "";
}
}
16 changes: 16 additions & 0 deletions src/core/files/punchfile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export class PUNCHFILE {
private constructor(public projectId: string, public punchId: string, public punchStart: Date, public shiftRate: number)
{}

public static async readFileAsync() : Promise<PUNCHFILE | null> {
return null;
}

public static async createAsync(projectId: string, punchId: string, punchStart: Date, shiftRate: number) : Promise<void> {

}

public async deleteAsync(): Promise<void> {

}
}

0 comments on commit 036dee3

Please sign in to comment.