-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathutils.js
More file actions
116 lines (102 loc) · 2.78 KB
/
utils.js
File metadata and controls
116 lines (102 loc) · 2.78 KB
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
const chalk = require('chalk');
const notifier = require('node-notifier');
const process = require('process');
const basePath = __filename.split('/').slice(0, -1).join('/');
const projectPath = process.env.PWD;
const weeConfig = require('./config');
let projectSourcePath = `${projectPath}`;
projectSourcePath += weeConfig.paths ?
`/${weeConfig.paths.source}` :
'/source';
module.exports = {
/**
* Prep a string to become file/folder name
*
* @param {string} string
* @return {string}
*/
fileFormat(string) {
return string.split(/(?=[A-Z])/g).map((word) => word.toLowerCase())
.join('-');
},
/**
* Notify through a natively available notification option
*
* @param {object} options
* @param {string} [type=notice]
* @param {boolean} [log=true]
*/
notify(options, type, log) {
options.icon = __dirname + '/images/' + (type || 'notice') + '.png';
options.group = 1;
if (type == 'error' || type == 'fail') {
options.group = 2;
options.sound = true;
options.wait = true;
}
if (log !== false) {
console.log(options.message);
}
notifier.notify(options);
if (type == 'fail') {
process.exit(1);
}
},
/**
* Log an error to the console
*
* @param {string} message
* @param {string} [details]
*/
logError(message, details) {
console.log(
chalk.red.bold('error: ') +
message + ' ' + (details || '')
);
},
/**
* Log a success message to the console
*
* @param {string} message
*/
logSuccess(message) {
console.log(chalk.green(message));
},
logList(name, desc) {
console.log(
`\n${chalk.green.bgBlack.bold(name)} - ${chalk.white.bgBlack(desc)}`
);
},
paths: {
root: basePath,
styles: `${basePath}/styles`,
commands: `${basePath}/commands`,
project: {
root: projectPath,
source: projectSourcePath,
commands: `${projectSourcePath}/commands`,
styles: `${projectSourcePath}/styles`,
scripts: `${projectSourcePath}/scripts`,
components: `${projectSourcePath}/components`
},
tests: {
root: `${basePath}/tests`,
scripts: `${basePath}/tests/scripts`
}
},
/**
* Trim the right side of string
* @param {String} str
*/
trimRight(str) {
return str.replace(/\s+$/, '');
},
/**
* Remove stars from line
* @param {String} line
*/
stripStars(line) {
let re = /^(?:\s*[\*]{1,2}\s)/;
return this.trimRight(line.replace(re, ''));
}
};