-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlib.js
104 lines (67 loc) · 1.97 KB
/
lib.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
var _ = require('lodash'),
fs = require('fs'),
exec = require('child_process').exec
module.exports = helpers = {
capitalize: function(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
},
creators: {
nameAndPath: function(type) {
var name = helpers.slugify(this.name),
pathType = type;
if(type == 'collection') {
pathType = 'model';
}
if(type == 'collectionview') {
pathType = 'view';
}
if(this.path) {
if(type == 'template') {
this.copy('index.hbs', 'app/templates/' + this.path + '/' + name + '.hbs')
}
else {
this.template('_' + type + '.coffee', 'app/' + pathType + 's/' + this.path + '/' + name + '.coffee');
}
}
else {
if(type == 'template') {
this.copy('index.hbs', 'app/templates/' + name + '.hbs')
}
else {
this.template('_' + type + '.coffee', 'app/' + pathType + 's/' + name + '.coffee');
}
}
}
},
generators: {
nameAndPath: function() {
if(this.name.indexOf('/') > -1) {
var s = this.name.lastIndexOf('/'),
p = this.name.substring(0, s),
n = this.name.split('/').pop()
this.name = n;
this.path = p;
}
else {
this.path = null;
}
}
},
deleteCurrentFolder: function() {
var currentFolder = process.cwd().split('/').pop()
exec('rm -rf ' + process.cwd() + '/*')
},
slugify: function (str) {
str = str.replace(/^\s+|\s+$/g, ''); // trim
str = str.toLowerCase();
var from = "àáäâèéëêìíïîòóöôùúüûñç·/_,:;";
var to = "aaaaeeeeiiiioooouuuunc------";
for (var i=0, l=from.length ; i<l ; i++) {
str = str.replace(new RegExp(from.charAt(i), 'g'), to.charAt(i));
}
str = str.replace(/[^a-z0-9 -]/g, '')
.replace(/\s+/g, '-')
.replace(/-+/g, '-');
return str;
}
}