FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
nodegit/generate/scripts/utils.js at master · panjiang/nodegit · GitHub
panjiang
nodegit
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
nodegit
/
generate
/
scripts
/
utils.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
155 lines (130 loc) · 3.76 KB
Breadcrumbs
nodegit
/
generate
/
scripts
/
utils.js
Copy path
File metadata and controls
155 lines (130 loc) · 3.76 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
const
fse
=
require
(
"fs-extra"
)
;
const
walk
=
require
(
"walk"
)
;
const
_
=
require
(
'lodash'
)
;
const
fs
=
require
(
"fs"
)
;
const
path
=
require
(
"path"
)
;
// Make a locally bound path joiner, (bound to generate).
var
local
=
path
.
join
.
bind
(
null
,
__dirname
,
"../"
)
;
var
util
=
{
arrayTypeRegex
:
/
\s
\[
\d
+
\]
\s
*
/
,
pointerRegex
:
/
\s
*
\*
\s
*
/
,
doublePointerRegex
:
/
\s
*
\*
\*
\s
*
/
,
readLocalFile
:
function
(
filePath
)
{
return
util
.
readFile
(
local
(
filePath
)
)
;
}
,
readFile
:
function
(
filePath
)
{
try
{
return
fs
.
readFileSync
(
filePath
)
.
toString
(
)
;
}
catch
(
unhandledException
)
{
return
""
;
}
}
,
writeLocalFile
:
function
(
filePath
,
content
,
header
)
{
return
util
.
writeFile
(
local
(
filePath
)
,
content
,
header
)
;
}
,
writeFile
:
function
(
filePath
,
content
,
header
)
{
try
{
if
(
typeof
content
==
"object"
)
{
content
=
JSON
.
stringify
(
content
,
null
,
2
)
}
if
(
header
)
{
var
commentPrefix
=
~
header
.
indexOf
(
'.gyp'
)
?
'#'
:
'//'
content
=
commentPrefix
+
" This is a generated file, modify: generate/templates/templates/"
+
header
+
"\n\n"
+
content
;
}
fse
.
ensureFileSync
(
filePath
)
;
fse
.
writeFileSync
(
filePath
,
content
)
;
return
true
;
}
catch
(
exception
)
{
return
false
;
}
}
,
titleCase
:
function
(
str
)
{
return
str
.
split
(
/
_
|
\/
/
)
.
map
(
function
(
val
,
index
)
{
if
(
val
.
length
)
{
return
val
[
0
]
.
toUpperCase
(
)
+
val
.
slice
(
1
)
;
}
return
val
;
}
)
.
join
(
""
)
;
}
,
camelCase
:
_
.
camelCase
,
getFilePathsRelativeToDir
:
function
(
dir
)
{
const
files
=
[
]
;
const
walker
=
walk
.
walk
(
dir
,
{
followLinks
:
false
}
)
;
if
(
!
util
.
isDirectory
(
dir
)
)
{
return
Promise
.
resolve
(
[
]
)
;
}
return
new
Promise
(
function
(
resolve
,
reject
)
{
walker
.
on
(
'file'
,
function
(
root
,
stat
,
next
)
{
files
.
push
(
path
.
relative
(
dir
,
path
.
join
(
root
,
stat
.
name
)
)
)
;
next
(
)
;
}
)
;
walker
.
on
(
'end'
,
function
(
)
{
resolve
(
files
)
;
}
)
;
walker
.
on
(
'errors'
,
function
(
)
{
reject
(
)
;
}
)
;
}
)
;
}
,
isFile
:
function
(
path
)
{
var
isFile
;
try
{
isFile
=
fse
.
statSync
(
path
)
.
isFile
(
)
;
}
catch
(
e
)
{
isFile
=
false
;
}
return
isFile
;
}
,
isDirectory
:
function
(
path
)
{
var
isDirectory
;
try
{
isDirectory
=
fse
.
statSync
(
path
)
.
isDirectory
(
)
;
}
catch
(
e
)
{
isDirectory
=
false
;
}
return
isDirectory
;
}
,
isPointer
:
function
(
type
)
{
return
util
.
pointerRegex
.
test
(
type
)
||
util
.
doublePointerRegex
.
test
(
type
)
;
}
,
isDoublePointer
:
function
(
type
)
{
return
util
.
doublePointerRegex
.
test
(
type
)
;
}
,
syncDirs
:
function
(
fromDir
,
toDir
)
{
let
toFilePaths
;
let
fromFilePaths
;
return
Promise
.
all
(
[
util
.
getFilePathsRelativeToDir
(
toDir
)
,
util
.
getFilePathsRelativeToDir
(
fromDir
)
]
)
.
then
(
function
(
filePaths
)
{
toFilePaths
=
filePaths
[
0
]
;
fromFilePaths
=
filePaths
[
1
]
;
// Delete files that aren't in fromDir
return
Promise
.
all
(
toFilePaths
.
map
(
function
(
filePath
)
{
if
(
!
util
.
isFile
(
path
.
join
(
fromDir
,
filePath
)
)
)
{
return
fse
.
remove
(
path
.
join
(
toDir
,
filePath
)
)
;
}
return
Promise
.
resolve
(
)
;
}
)
)
;
}
)
.
then
(
function
(
)
{
// Copy files that don't exist in toDir or have different contents
return
Promise
.
all
(
fromFilePaths
.
map
(
function
(
filePath
)
{
const
toFilePath
=
path
.
join
(
toDir
,
filePath
)
;
const
fromFilePath
=
path
.
join
(
fromDir
,
filePath
)
;
if
(
!
util
.
isFile
(
toFilePath
)
||
util
.
readFile
(
toFilePath
)
!==
util
.
readFile
(
fromFilePath
)
)
{
return
fse
.
copy
(
fromFilePath
,
toFilePath
)
;
}
return
Promise
.
resolve
(
)
;
}
)
)
;
}
)
;
}
}
;
module
.
exports
=
util
;
Back
|
FazBrowse Home
|
New Git URL