-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·145 lines (118 loc) · 3.99 KB
/
index.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/usr/bin/env node
var jsonfile = require('jsonfile');
var path = require('path');
var exec = require('child_process').exec;
var inquirer = require('inquirer');
var program = require('commander');
var os = require('os');
var questions = require('./questions');
var util = require('./util');
var fs = require('fs');
var opn = require('opn');
var envEditor = require('env-editor');
var npm_settings = require('./package.json');
var setting_file = path.join(os.homedir(), '/.fatih.setting.json');
var args = process.argv.slice(2);
var fatih_data = util.readFatih();
var fatih_settings = util.readSettingsFatih();
var default_fatih_settings = {
index: {},
};
// indexi döner ve configi yerinde olmayan varsa indexten kaldırır
if (!fatih_settings) {
util.writeSettingsFatih(default_fatih_settings).then(function(){
fatih_settings = default_fatih_settings;
});
} else {
clearIndex();
}
program.version(npm_settings.version);
// INIT COMMAND
program
.command('init')
.description('Proje ekleyin')
.action(function(env, options){
questions.init[2].choices = envEditor.all();
inquirer.prompt(questions.init).then(function (answers) {
fatih_settings.index[answers.project_name] = process.cwd()
return Promise.all([
util.writeFatih({
name:answers.project_name,
config: {
github:answers.github_url,
editor:answers.editor,
},
commands : { }
}),
util.writeSettingsFatih(fatih_settings)
]);
}).then(function(){
console.log('Bilgilerini başarıyla kaydettik');
}).catch(function(err){
console.log('Birşeyler oldu...', err)
})
});
// GO COMMAND
program
.command('go')
.description('Proje gidin')
.action(function(env, options){
questions.go[0].choices = Object.keys(fatih_settings.index)
if (Object.keys(fatih_settings.index).length) {
inquirer.prompt(questions.go).then(function (answers) {
project_path = fatih_settings.index[answers.project];
opn(project_path);
}).then(function (answers) {
// dizin açılmış olmalı
})
} else {
console.log('Hiç projeniz yok');
}
});
program
.command('*')
.description('Proje komutunuz')
.action(function(env, options){
if (args[0] && fatih_data != null) {
switch (args[0]) {
case 'is':
opn(`${fatih_data.config.github}/issues`).then(function(){
})
break;
case 'code':
var editor = envEditor.get(fatih_data.config.editor);
if(editor.bin){
exec(`${editor.bin} ${process.cwd()}`);
}
break;
default:
try{
var selected_command = fatih_data.commands[args[0]];
if (selected_command) {
if(process.platform == 'win32'){
exec('start cmd /K "'+selected_command+'"');
} else {
exec(`${selected_command}`);
}
process.exit(1);
} else {
console.log('Herhangi bir komut bulamadık')
}
}catch(err){
console.log('Herhangi bir komut bulamadık')
}
break;
}
}
});
program.parse(process.argv);
function clearIndex() {
for (var key in fatih_settings.index) {
var path = fatih_settings.index[key];
if (!fs.existsSync(path+'/.fatih')) {
delete fatih_settings.index[key];
}
}
util.writeSettingsFatih(fatih_settings).then(function(){
});
}