-
Notifications
You must be signed in to change notification settings - Fork 1
/
sx.js
executable file
·112 lines (103 loc) · 3.71 KB
/
sx.js
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/usr/bin/env node
// Modules
const path = require("path");
const process = require('process');
// command imports form ./commands/exportFile.js
var {
init,
ls,
pwd,
open,
mkdir,
cat,
rm,
mkpro,
mv,
sxglobal,
sxcustom,
edit,
touch,
cp,
clone,
sync,
version,
help
} = require("./commands/exportFile.js");
// Config File
var sxconfig = require(path.join(__dirname, "sxconfig.json"))
// Arrays for keys of global, custom and editor commands
// 1) Globals
var globKeys = [];
sxconfig.Globals.forEach(obj => {
globKeys.push(Object.keys(obj)[0]);
});
// 2) Custom
var custKeys = [];
sxconfig.Custom.forEach(obj => {
custKeys.push(Object.keys(obj)[0]);
});
// Initializise command
passedArgs = process.argv.slice(2);
if (passedArgs.length == 2 && passedArgs[0].toLowerCase() == "init") {
init(passedArgs[1].toLowerCase());
process.exit(0);
}
// Check if SYNIX is initialized
// 1) Globals
sxconfig.Globals.forEach((obj) => {
if (Object.values(obj)[0] == "None") {
console.log("SYNIX is not initialized")
console.log('For details on init visit https://synix-docs.netlify.com/ccc/commands.html#init')
process.exit(0);
}
})
// 2) Text_editor
sxconfig.Text_editor.forEach((obj) => {
if (Object.values(obj)[0] == "None") {
console.log("SYNIX is not initialized")
console.log('For details on init visit https://synix-docs.netlify.com/ccc/commands.html#init')
process.exit(0);
}
})
// argument parsing
if (passedArgs.length == 0) {
console.error(`No arguments passed`);
console.log('For commands visit https://synix-docs.netlify.com/ccc/commands.html')
} else if (passedArgs.length == 1 && passedArgs[0].toLowerCase() == "ls") {
ls("./");
} else if (passedArgs.length == 1 && passedArgs[0].toLowerCase() == "pwd") {
pwd();
} else if (passedArgs.length >= 1 && passedArgs[0].toLowerCase() == "open") {
open(passedArgs);
} else if (passedArgs.length >= 1 && passedArgs[0].toLowerCase() == "mkdir") {
mkdir("./", passedArgs[1]);
} else if (passedArgs.length >= 1 && passedArgs[0].toLowerCase() == "cat") {
cat("./", passedArgs[1]);
} else if (passedArgs.length >= 1 && passedArgs[0].toLowerCase() == "rm") {
rm("./", passedArgs[1]);
} else if (passedArgs.length >= 1 && passedArgs[0].toLowerCase() == "mkpro") {
mkpro(passedArgs[1]);
} else if (passedArgs.length >= 1 && passedArgs[0].toLowerCase() == "mv") {
mv(passedArgs[1], passedArgs[2]);
} else if (passedArgs.length == 1 && globKeys.includes(passedArgs[0].toLowerCase())) {
sxglobal(globKeys.indexOf(passedArgs[0].toLowerCase()), passedArgs[0].toLowerCase())
} else if (passedArgs.length == 1 && custKeys.includes(passedArgs[0].toLowerCase())) {
sxcustom(custKeys.indexOf(passedArgs[0].toLowerCase()), passedArgs[0].toLowerCase())
} else if (passedArgs.length == 1 && passedArgs[0].toLowerCase() == "edit") {
edit();
} else if (passedArgs.length >= 1 && passedArgs[0].toLowerCase() == "touch") {
touch("./", passedArgs[1]);
} else if (passedArgs.length >= 1 && passedArgs[0].toLowerCase() == "cp") {
cp(passedArgs[1], passedArgs[2]);
} else if (passedArgs.length >= 1 && passedArgs[0].toLowerCase() == "clone") {
clone(passedArgs.slice(1))
} else if (passedArgs.length >= 1 && passedArgs[0].toLowerCase() == "sync") {
sync(passedArgs.slice(1));
} else if (passedArgs.length == 1 && (passedArgs[0].toLowerCase() == "version" || passedArgs[0].toLowerCase() == "v")) {
version();
} else if (passedArgs.length == 1 && passedArgs[0].toLowerCase() == "help") {
help();
} else {
console.error(`Argument(s) ${passedArgs} cannot be parsed`);
console.log('For commands visit https://synix-docs.netlify.com/ccc/commands.html');
}