Skip to content

Commit

Permalink
feat: config file manage add #3
Browse files Browse the repository at this point in the history
now you can create config file to manage the package
  • Loading branch information
evolvingkid committed Sep 27, 2021
1 parent fb7dc40 commit 6653a21
Show file tree
Hide file tree
Showing 6 changed files with 837 additions and 292 deletions.
36 changes: 28 additions & 8 deletions cli.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,35 @@
#!/usr/bin/env node
#!/usr/bin/env bash
":"; //# comment; exec /usr/bin/env node --input-type=module - "$@" < "$0"

const yargs = require("yargs/yargs");
const { hideBin } = require("yargs/helpers");
import yargs from "yargs";
import { hideBin } from "yargs/helpers";

const singleUser = require('./cli/singleUser/index')
import singleUser from "./cli/singleUser/index.js";

import acessConfigFile from "./config/acessConfigFile.js";

import taskListLog from "./services/tasklistLog.js";

const argv = yargs(hideBin(process.argv)).argv;

if (argv.userMail) {
singleUser();
return;
try {

if (argv.userMail) {
singleUser();
} else {
const configData = await acessConfigFile();

if (configData) {
if (configData.userEmail) {
taskListLog({ userEmail: configData.userEmail });
}
}
}


} catch (error) {

console.log('error Occured', error);

}

console.error("--usermail param is required");
40 changes: 6 additions & 34 deletions cli/singleUser/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const { exec } = require("child_process");
const moment = require("moment");
import yargs from 'yargs'
import { hideBin } from 'yargs/helpers'

import taskListLog from "../../services/tasklistLog.js";

const yargs = require("yargs/yargs");
const { hideBin } = require("yargs/helpers");

const singleUser = () => {
const argv = yargs(hideBin(process.argv)).argv;
Expand All @@ -11,36 +11,8 @@ const singleUser = () => {

console.log(`User email: ${argv.userMail}`);

let todayDate = new Date();

let startingDate = new Date();
startingDate.setDate(todayDate.getDate() - todayDate.getDay());

startingDate.setDate(startingDate.getDate() - 1);

let limitDate = new Date();
limitDate.setDate(startingDate.getDate() + 1);

console.log(todayDate, startingDate);

while (todayDate.getDate() !== startingDate.getDate()) {
const startingDateFormat = moment(startingDate).format("YYYY-M-D");
const limitDateFormat = moment(limitDate).format("YYYY-M-D");

console.log(`Task List ${startingDateFormat} \n`);

const gitCommand = `git log --pretty=format:'%s' --author="${userEmail}" --after="${startingDateFormat}" --before="${limitDateFormat}"`;

exec(gitCommand, (err, stdout, stderr) => {
const commitMsg = stdout.split(" ").slice(1).join(" ");

console.log(commitMsg);
});

startingDate.setDate(startingDate.getDate() + 1);
taskListLog({userEmail: userEmail})

limitDate.setDate(startingDate.getDate() + 1);
}
};

module.exports = singleUser;
export default singleUser;
23 changes: 23 additions & 0 deletions config/acessConfigFile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import path from "node:path";
import { findUp, pathExists } from "find-up";
import fs from "fs";

const acessConfigFile = async () => {
try {
const filedir = await findUp("weeklycommit.config.json");

if (!filedir) {
console.log("This is no data found");
return;
}

const data = JSON.parse(fs.readFileSync(filedir, "utf8"));

return data;

} catch (error) {
throw error;
}
};

export default acessConfigFile;
Loading

0 comments on commit 6653a21

Please sign in to comment.