FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
atom/script/lib/backup-node-modules.js at master · feicc/atom · GitHub
feicc
/
atom
Public
forked from
atom/atom
Notifications
You must be signed in to change notification settings
Fork
1
Star
0
Code
Pull requests
53
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
atom
/
script
/
lib
/
backup-node-modules.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
41 lines (32 loc) · 1.35 KB
Breadcrumbs
atom
/
script
/
lib
/
backup-node-modules.js
Copy path
File metadata and controls
41 lines (32 loc) · 1.35 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
const
fs
=
require
(
'fs-extra'
)
const
path
=
require
(
'path'
)
module
.
exports
=
function
(
packagePath
)
{
const
nodeModulesPath
=
path
.
join
(
packagePath
,
'node_modules'
)
const
nodeModulesBackupPath
=
path
.
join
(
packagePath
,
'node_modules.bak'
)
if
(
fs
.
existsSync
(
nodeModulesBackupPath
)
)
{
throw
new
Error
(
'Cannot back up '
+
nodeModulesPath
+
'; '
+
nodeModulesBackupPath
+
' already exists'
)
}
// some packages may have no node_modules after deduping, but we still want
// to "back-up" and later restore that fact
if
(
!
fs
.
existsSync
(
nodeModulesPath
)
)
{
const
msg
=
'Skipping backing up '
+
nodeModulesPath
+
' as it does not exist'
console
.
log
(
msg
.
gray
)
const
restore
=
function
stubRestoreNodeModules
(
)
{
if
(
fs
.
existsSync
(
nodeModulesPath
)
)
{
fs
.
removeSync
(
nodeModulesPath
)
}
}
return
{
restore
,
nodeModulesPath
,
nodeModulesBackupPath
}
}
fs
.
copySync
(
nodeModulesPath
,
nodeModulesBackupPath
)
const
restore
=
function
restoreNodeModules
(
)
{
if
(
!
fs
.
existsSync
(
nodeModulesBackupPath
)
)
{
throw
new
Error
(
'Cannot restore '
+
nodeModulesPath
+
'; '
+
nodeModulesBackupPath
+
' does not exist'
)
}
if
(
fs
.
existsSync
(
nodeModulesPath
)
)
{
fs
.
removeSync
(
nodeModulesPath
)
}
fs
.
renameSync
(
nodeModulesBackupPath
,
nodeModulesPath
)
}
return
{
restore
,
nodeModulesPath
,
nodeModulesBackupPath
}
}
Back
|
FazBrowse Home
|
New Git URL