she3ba-courses-manager 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/courses.json +0 -0
  2. package/index.js +76 -0
  3. package/package.json +18 -0
package/courses.json ADDED
File without changes
package/index.js ADDED
@@ -0,0 +1,76 @@
1
+ #!/usr/bin/env node
2
+
3
+
4
+ import { Command } from 'commander';
5
+ import fs from 'fs';
6
+
7
+ import inquirer from 'inquirer';
8
+
9
+ const program = new Command();
10
+
11
+ const questions = [
12
+ {
13
+ type: 'input',
14
+ name: 'title',
15
+ message: 'Please enter course title',
16
+ },
17
+ {
18
+ type: 'number',
19
+ name: 'price',
20
+ message: 'Please enter course price',
21
+ },
22
+ ]
23
+
24
+ const filePath = './courses.json';
25
+
26
+ program
27
+ .name('SHE3BA-courses-manager')
28
+ .description('CLI to make courses')
29
+ .version('1.0.0')
30
+
31
+ program
32
+ .command('add')
33
+ .alias('a')
34
+ .description('Add a course')
35
+
36
+ .action(() => {
37
+ inquirer
38
+ .prompt(questions)
39
+ .then(answers => {
40
+ console.log(answers);
41
+ if (fs.existsSync(filePath)) {
42
+ fs.readFile(filePath, 'utf8', (err, fileContent) => {
43
+ if (err) {
44
+ console.log("Error", err);
45
+ process.exit();
46
+ }
47
+ console.log("fileContent ->", fileContent);
48
+ const fileContentAsJson = JSON.parse(fileContent);
49
+ fileContentAsJson.push(answers);
50
+ fs.writeFile(filePath, JSON.stringify(fileContentAsJson), 'utf8', () => {
51
+ console.log('Add Course Done');
52
+ })
53
+ })
54
+ } else {
55
+ fs.writeFile(filePath, JSON.stringify([answers]), 'utf8', () => {
56
+ console.log('Add Course Done');
57
+ })
58
+ }
59
+ })
60
+ })
61
+
62
+ program
63
+ .command('list')
64
+ .alias('l')
65
+ .description('List all courses')
66
+ .action( () => {
67
+ fs.readFile(filePath, 'utf8', (err, content) => {
68
+ if(err) {
69
+ console.log("Error", err);
70
+ process.exit();
71
+ }
72
+ console.table(JSON.parse(content));
73
+ })
74
+ })
75
+
76
+ program.parse(process.argv);
package/package.json ADDED
@@ -0,0 +1,18 @@
1
+ {
2
+ "name": "she3ba-courses-manager",
3
+ "version": "1.0.0",
4
+ "description": "",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1"
8
+ },
9
+ "bin": "./index.js",
10
+ "keywords": [],
11
+ "author": "",
12
+ "license": "ISC",
13
+ "type": "module",
14
+ "dependencies": {
15
+ "commander": "^14.0.3",
16
+ "inquirer": "^13.2.4"
17
+ }
18
+ }