-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.js
executable file
·76 lines (60 loc) · 1.55 KB
/
cli.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
var express = require('express');
var cliProto = FidalgoCLI.prototype;
var Site = require('./site');
var utils = require('./utils');
var fs = require('fs');
var path = require('path');
module.exports = FidalgoCLI;
function FidalgoCLI () {
if(!(this instanceof FidalgoCLI)) return new FidalgoCLI();
var cli = this, site, app;
Object.defineProperty(cli,'site',{
get : function () {
if(!site) {
site = Site()
.CWD( process.cwd() )
.loadConfig();
}
return site;
}
});
Object.defineProperty(cli,'app',{
get : function () {
app || (app = express());
return app;
}
});
}
cliProto.exec = function (args) {
if(!(args) || args.length == 0) {
this.generate();
this.serve();
return
}
this[args[0]]();
}
cliProto.generate = function () {
this.site.generate();
}
cliProto.serve = function () {
this.app.use(express.static(process.cwd() + '/site'));
this.app.listen(4000);
}
cliProto.init = function () {
var src = path.resolve('src');
var cfg = path.resolve('fidalgo.config.js');
var src_src = path.join(__dirname, 'init', 'src');
var cfg_src = path.join(__dirname, 'init', 'fidalgo.config.js');
if(! fs.existsSync(cfg) ) {
fs.writeFileSync(cfg, fs.readFileSync(cfg_src));
} else {
console.warn('Ya Existe un fidalgo.config, se usará');
}
if(fs.existsSync(src)) {
console.error('El directorio existe :'.concat(src));
console.error('Borrelo por su cuenta, después de respaldar');
return;
}
utils.copyRecursiveSync(src_src, src);
console.log('Archivos Copiados Exitosamente');
}