-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelper.js
89 lines (74 loc) · 2 KB
/
helper.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
'use strict';
const readLine = require('readline');
const fs = require('fs');
module.exports.createFolder = function createFolder(name) {
return new Promise((resolve, reject) => {
if (fs.existsSync(name)) {
reject('Already exist');
}
fs.mkdir(name, (err) => {
if (err) {
console.log(err);
reject(err);
}
resolve();
});
})
};
module.exports.createFile = function createFile(name, content) {
return new Promise((resolve, reject) => {
fs.writeFile(name, content, (err) => {
if (err) {
console.error(err);
reject(err);
}
resolve(name);
})
});
};
module.exports.toDash = function toDash(str) {
return str.replace(/([A-Z])/g, function ($1) {
return "-" + $1.toLowerCase();
});
};
module.exports.toCamel = function toCamel(str) {
return str.replace(/(\-[a-z])/g, function ($1) {
return $1.toUpperCase().replace('-', '');
});
};
module.exports.capitalize = function capitalize(str) {
return str.charAt(0).toUpperCase() + str.slice(1);
};
module.exports.ask = function ask(question) {
return new Promise((resolve) => {
let rl = readLine.createInterface({
input: process.stdin,
output: process.stdout
});
rl.question(question + ': ', (answer) => {
rl.close();
resolve(answer);
});
});
};
module.exports.js = function js(name) {
return `
class ${module.exports.capitalize(module.exports.toCamel(name))}Controller {
constructor() {
}
}
export default {
controller: ${module.exports.capitalize(module.exports.toCamel(name))}Controller,
template: require('./${module.exports.toDash(name)}.html'),
bindings: {
}
};
`.trim();
};
module.exports.html = function html() {
return `<div></div>`;
};
module.exports.scss = function scss(name) {
return `${name} {
}`;
};