hamdi-project1 0.0.0-stage → 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.
- package/courses.json +1 -0
- package/index.js +89 -0
- package/package.json +44 -4
- package/README.md +0 -3
package/courses.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
[{"progrem":"javascript","price":900},{"progrem":"java","price":900}]
|
package/index.js
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
#!usr/bin/env node
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
// command project use commander js
|
|
5
|
+
import fs from "fs";
|
|
6
|
+
import {Command} from "commander";
|
|
7
|
+
import inquirer from 'inquirer';
|
|
8
|
+
import { type } from "node:os";
|
|
9
|
+
const program = new Command();
|
|
10
|
+
// const fs = require('node:fs');
|
|
11
|
+
|
|
12
|
+
const question = [
|
|
13
|
+
{
|
|
14
|
+
type:"input",
|
|
15
|
+
name:"progrem",
|
|
16
|
+
message:"what is the favourite language"
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
type:"number",
|
|
20
|
+
name:"price",
|
|
21
|
+
message:"what is needed price"
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
]
|
|
25
|
+
|
|
26
|
+
// program
|
|
27
|
+
// .name("codezone")
|
|
28
|
+
// .command('print')
|
|
29
|
+
// .argument('<file>')
|
|
30
|
+
// .option('--double-sided')
|
|
31
|
+
const path = './courses.json' ;
|
|
32
|
+
|
|
33
|
+
program
|
|
34
|
+
.command("add")
|
|
35
|
+
.alias("A")
|
|
36
|
+
.action(() => {
|
|
37
|
+
inquirer
|
|
38
|
+
.prompt(question)
|
|
39
|
+
.then((answers) => {
|
|
40
|
+
|
|
41
|
+
// حل مشكله override
|
|
42
|
+
if(fs.existsSync(path))
|
|
43
|
+
{
|
|
44
|
+
fs.readFile(path , "utf8" , (err , data) => {
|
|
45
|
+
if(err)
|
|
46
|
+
{
|
|
47
|
+
console.log("error" , err)
|
|
48
|
+
process.exit();
|
|
49
|
+
}
|
|
50
|
+
const filecontantjson = JSON.parse(data);
|
|
51
|
+
filecontantjson.push(answers)
|
|
52
|
+
fs.writeFile(path , JSON.stringify(filecontantjson),"utf8" , (err , data) => {
|
|
53
|
+
console.log("add courses done")
|
|
54
|
+
})
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
}
|
|
58
|
+
else
|
|
59
|
+
{
|
|
60
|
+
fs.writeFile(path , JSON.stringify([answers]),"utf8" , (err , data) => {
|
|
61
|
+
console.log("add courses done")
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
// .command("list")
|
|
82
|
+
// .alias("l")
|
|
83
|
+
// .action(() => {
|
|
84
|
+
|
|
85
|
+
// console.log("courses")
|
|
86
|
+
|
|
87
|
+
// })
|
|
88
|
+
|
|
89
|
+
program.parse();
|
package/package.json
CHANGED
|
@@ -1,6 +1,46 @@
|
|
|
1
1
|
{
|
|
2
|
+
|
|
2
3
|
"name": "hamdi-project1",
|
|
3
|
-
|
|
4
|
-
"
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
|
|
5
|
+
"version": "1.0.0",
|
|
6
|
+
|
|
7
|
+
"description": "",
|
|
8
|
+
|
|
9
|
+
"main": "index.js",
|
|
10
|
+
"type" :"module",
|
|
11
|
+
|
|
12
|
+
"devDependencies": {
|
|
13
|
+
|
|
14
|
+
"nodemon": "^3.1.14"
|
|
15
|
+
|
|
16
|
+
},
|
|
17
|
+
|
|
18
|
+
"bin" : "./index.js",
|
|
19
|
+
"scripts": {
|
|
20
|
+
|
|
21
|
+
"run": " nodemon index.js",
|
|
22
|
+
|
|
23
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
24
|
+
|
|
25
|
+
},
|
|
26
|
+
|
|
27
|
+
"keywords": [],
|
|
28
|
+
|
|
29
|
+
"author": "",
|
|
30
|
+
|
|
31
|
+
"license": "ISC",
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
"dependencies": {
|
|
36
|
+
|
|
37
|
+
"@commander-js/extra-typings": "^15.1.0",
|
|
38
|
+
|
|
39
|
+
"inquirer": "^14.3.1",
|
|
40
|
+
|
|
41
|
+
"lodash": "^4.18.1"
|
|
42
|
+
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
}
|
|
46
|
+
|
package/README.md
DELETED