Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added docs/commands/create.md
Empty file.
33 changes: 33 additions & 0 deletions docs/intro.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Intro

cli-notes is a tool for managing your markdown notes. It has a couple of basic
assumptions that it makes about the sort of notes you make;

1. You like writing your notes in markdown
2. They are either plain notes, meeting notes, or todo lists
3. You keep your notes in a nested folder structure
4. Creating a new note, and putting it in the right place is the most painful part of the note taking life-cycle

If you find yourself agreeing with this list of issues, then this project is for you.

## Installing

Run:

```
npm install -g cli-notes
```

or:

```
yarn global add cli-notes
```

## Commands

The following commands are available to you:

- Help
- [Create](./commands/create.md)

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@
"@oclif/config": "^1",
"@oclif/plugin-help": "^3",
"fs": "^0.0.1-security",
"inquirer": "^8.2.0",
"tslib": "^1"
},
"devDependencies": {
"@oclif/dev-cli": "^1",
"@oclif/test": "^1",
"@types/chai": "^4",
"@types/inquirer": "^8.1.3",
"@types/mocha": "^5",
"@types/node": "^10",
"@typescript-eslint/eslint-plugin": "^4.26.0",
Expand Down
57 changes: 44 additions & 13 deletions src/commands/create.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { Command, flags } from '@oclif/command';
import * as inquirer from 'inquirer';
import Note from '../services/Note';
import Today from '../services/Today';
import Collection from '../services/Collection';
import Project from '../services/Project';

export default class Create extends Command {
static availableTypes = {
Expand All @@ -15,7 +18,7 @@ export default class Create extends Command {
];

static flags = {
project: flags.boolean({char: 'p'}),
project: flags.string({ char: 'p' }),
}

static description = 'Creates a new note';
Expand All @@ -28,10 +31,37 @@ new file created!

async run(): Promise<void> {
const { args, flags } = this.parse(Create);
const project = flags.project;
let project = flags.project;
const type = args.type;
const title = args.title ? args.title : this.defaultNoteTitle(type);


const tree = Collection.getTree();

console.log(tree);
let foundDir;

let targetDir = tree;

if (!project) {
while (!foundDir) {
const responses: any = await inquirer.prompt([{
name: 'project',
message: 'select a Project',
type: 'list',
choices: [{ ...targetDir, name: `${targetDir.name}`, currentDir: true }, ...targetDir.projects],
}]);

if (responses.project === targetDir.name) {
project = responses.project;
foundDir = true;
} else {
foundDir = targetDir.projects.find((p) => p.name === responses.project );
targetDir = foundDir !== undefined ? foundDir : targetDir;
}
}
}

switch (type) {
case Create.availableTypes.meeting:
return this.meeting(project, title);
Expand All @@ -42,9 +72,9 @@ new file created!
}
}

meeting(project: boolean, title: string): void {
meeting(project: string|undefined, title: string): void {
const today = new Today();
const content = `# Meeting on ${today.date({separator: '/'})} at ${today.time()}
const content = `# Meeting on ${today.date({ separator: '/' })} at ${today.time()}

## Attendees

Expand All @@ -54,41 +84,42 @@ new file created!

-`;

const formattedTitle = `${today.date({separator: '-'})}_meeting-${title}`;
const formattedTitle = `${today.date({ separator: '-' })}_meeting-${title}`;

const note = new Note({
fileName: formattedTitle, extension: 'md', content: content
fileName: formattedTitle, extension: 'md', content: content, filePath: project
});

note.write();

this.log(`New meeting note created: ${note.fullName()}`);
// this.log(`New meeting note created: ${note.fullName()}`);
// this.log()
}

todo(project: boolean, title: string): void {
todo(project: string|undefined, title: string): void {
const today = new Today();
const formattedTitle = `${today.date({separator: '-'})}_todo-${title}`;
const formattedTitle = `${today.date({ separator: '-' })}_todo-${title}`;
const content = `# TODO

-
`;

const note = new Note({
fileName: formattedTitle, extension: 'md', content: content
fileName: formattedTitle, extension: 'md', content: content, filePath: project
});

note.write();

this.log(`New todo note created: ${note.fullName()}`);
}

default(project: boolean, title: string): void {
default(project: string|undefined, title: string): void {
const today = new Today();
const formattedTitle = `${today.date({separator: '-'})}_${title}`;
const formattedTitle = `${today.date({ separator: '-' })}_${title}`;
const content = `# ${title}`;

const note = new Note({
fileName: formattedTitle, extension: 'md', content: content
fileName: formattedTitle, extension: 'md', content: content, filePath: project
});

note.write();
Expand Down
17 changes: 11 additions & 6 deletions src/services/Note.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import * as fs from 'fs';
import Config from './Config';

type Arguments = {
fileName: string;
extension: string;
content?: string;
filePath: string|undefined;
}

/**
Expand All @@ -14,25 +14,30 @@ export default class Note {
fileName: string;
extension: string;
content?: string;
filePath: string | undefined;

constructor(args: Arguments) {
this.fileName = args.fileName;
this.filePath = args.filePath;
this.extension = args.extension;
this.content = args.content;
}

write(): void {
fs.writeFileSync(this.filePath(), this.content);

if (this.fileName && this.filePath) {
fs.writeFileSync(this.fullPath(), this.content);
}
}

fullName(): string {
return `${this.fileName}.${this.extension}`;
}

private filePath(): string {
const config = new Config;
const settings = config.getSettings();
private fullPath(): string {
// const config = new Config;
// const settings = config.getSettings();

return `${settings.collectionLocation}/${this.fullName()}`;
return `${this.filePath}/${this.fullName()}`;
}
}
1 change: 1 addition & 0 deletions src/services/Project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export default class Project {
projects: Array<Project>;

constructor(args: {path: string, projects: Array<Project>}) {
this.name = args.path;
this.path = args.path;
this.projects = args.projects;
}
Expand Down
2 changes: 1 addition & 1 deletion test/commands/create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe("create", () => {

test
.stdout()
.command(["create", "meeting", "test"])
.command(["create", "meeting", "test", "--project", "development"])
.it("creates a meeting note", (ctx) => {
expect(ctx.stdout).to.contain("New meeting note created");
});
Expand Down
2 changes: 1 addition & 1 deletion test/services/Note.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe("Note", () => {
process.env.HOME = './test-dir';
});

const note = new Note({ fileName: 'test-file', extension: 'txt', content: 'Test' });
const note = new Note({ fileName: 'test-file', extension: 'txt', content: 'Test', filePath: './test-dir/' });
note.write();
expect(fs.existsSync('./test-dir/test-file.txt')).to.eq(true);
});
Expand Down
Loading