-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
executable file
·51 lines (41 loc) · 1.33 KB
/
index.js
File metadata and controls
executable file
·51 lines (41 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env node
import readline from 'node:readline';
import { addToList } from './addToList.js';
import { menu } from './menu.js';
import { printContent } from './printContent.js';
import jsonFile from './list.json' with { type: 'json' };
import fs from 'node:fs';
import { addToJson } from './addToJson.js';
import { printJson } from './printJson.js';
// const linuxPath = '/home/oliver/repos/to-do-cli/list.txt';
// const windowsPath = '/Users/n/repos/to-do-cli/list.txt';
const windowsPath = '/Users/n/repos/to-do-cli/list.json';
const linuxPath = '/home/oliver/repos/to-do-cli/list.json';
const [,,input] = process.argv;
const joinedInput = process.argv.slice(2).join(' ');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
// console.log(joinedInput);
let path = '';
if (process.platform === 'win32') {
path = windowsPath;
} else if (process.platform === 'linux') {
path = linuxPath;
}
// printContent(path);
if (input === undefined) {
menu(rl, path);
} else {
let data = fs.readFileSync(path);
let myJsonList = JSON.parse(data);
myJsonList.list.push(joinedInput);
let updatedJson = JSON.stringify(myJsonList);
addToJson(path, updatedJson);
console.log(updatedJson);
process.exit();
// addToList(rl, path, joinedInput);
}
// File.list.splice(joinedInput,1);
printJson(path);