Skip to content

Commit

Permalink
Merge pull request #1 from georg-stone/version-1.1
Browse files Browse the repository at this point in the history
Version 1.1
  • Loading branch information
georg-stone authored Jul 27, 2024
2 parents 9df46d4 + 5ee0ed3 commit d809f78
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 4 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Deploy to NPM

on:
push:
branches:
- main # This triggers the workflow on pushes to the main branch

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '18' # Specify the Node.js version you want to use

- name: Install dependencies
run: npm install

- name: Publish to NPM
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.github/workflows/
41 changes: 39 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#!/usr/bin/env node

import { Command } from 'commander';
import fs from 'fs';
import path from 'path';
import chalk from 'chalk';
import readline from 'readline';
import { profileEnd } from 'console';

// Initialize the CLI program
const program = new Command();
Expand All @@ -15,6 +14,11 @@ const rl = readline.createInterface({
output: process.stdout
});

const findBestMatch = (input, items) => {
const results = fuzzy.filter(input, items);
return results[0] ? results[0].string : null;
};

// Function to prompt user for file path
const promptFilePath = () => {
return new Promise((resolve) => {
Expand Down Expand Up @@ -66,6 +70,34 @@ const addTodo = async (todo, dueDate) => {
process.exit(0);
};

const deleteTodo = async (todo) => {
const filePath = await getTodoFilePath();

let todos = [];
if (fs.existsSync(filePath)) {
todos = JSON.parse(fs.readFileSync(filePath, 'utf-8'));
}

if (!Array.isArray(todos)) {
console.log(chalk.red('JSON file must be in array format.'));
}
let amountOfTasksRemoved = 0;
todos.forEach((item, index) => {
if (item.name.toLowerCase() === todo.toLowerCase()) {
amountOfTasksRemoved++;
todos.splice(index, 1);
}
});
if (amountOfTasksRemoved === 0) {
console.log(chalk.red(`Didn't match any tasks named "${todo}".`));
process.exit(1);
} else {
fs.writeFileSync(filePath, JSON.stringify(todos, null, 2));
console.log(chalk.red(`Successfully removed 1 task${amountOfTasksRemoved - 1 > 0 ? ` and ${amountOfTasksRemoved} duplicate(s)` : ''} from your todo list.`));
process.exit(0);
}
};

// Function to list the contents of the JSON file
const listTodos = async () => {
const filePath = await getTodoFilePath();
Expand Down Expand Up @@ -95,4 +127,9 @@ program
.description('List the contents of the JSON file')
.action(listTodos);

program
.command('delete <todoName>')
.description('Delete a task from the todo list')
.action(deleteTodo);

program.parse(process.argv);
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d809f78

Please sign in to comment.