-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathslush-utils.js
More file actions
45 lines (38 loc) · 1.03 KB
/
slush-utils.js
File metadata and controls
45 lines (38 loc) · 1.03 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
const lodash = require('lodash')
const path = require('path')
const spawnSync = require('child_process').spawnSync
module.exports = {
format( string ){
string = string.toLowerCase()
return string.replace( /\s/g, '' )
},
getAppName(){
let appname
try {
appname = require( path.join( process.cwd(), 'bower.json' ) ).name
} catch (e) {
try {
appname = require( path.join( process.cwd(), 'package.json' ) ).name
} catch (e) {}
}
if( !appname )
appname = path.basename( process.cwd() )
return appname.replace( /[^\w\s]+?/g, ' ' )
},
camelize( str ){
str = str.replace( /[-_]+/g, ' ' )
return str.replace( /(?:^\w|[A-Z]|\b\w)/g, ( letter, index ) => {
return index == 0 ? letter.toLowerCase() : letter.toUpperCase()
}).replace( /\s+/g, '' )
},
getGithubUrl(){
let result = spawnSync( 'git', ['config', 'remote.origin.url'], {
encoding: 'utf8',
cwd: process.cwd()
})
// TODO: Make sure it's a github url..
if(!result.error)
return result.stdout.replace('.git','')
return ''
}
}