FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
javascript-node-workshop/scripts/postinstall.js at main · ReactTraining/javascript-node-workshop · GitHub
ReactTraining
javascript-node-workshop
Repository navigation
Code
Issues
Pull requests
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
javascript-node-workshop
/
scripts
/
postinstall.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
42 lines (35 loc) · 1.18 KB
Breadcrumbs
javascript-node-workshop
/
scripts
/
postinstall.js
Copy path
File metadata and controls
42 lines (35 loc) · 1.18 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
const
fs
=
require
(
'fs'
)
const
path
=
require
(
'path'
)
const
{
exec
}
=
require
(
'child_process'
)
// Define the main directory
const
mainDir
=
'./examples'
// Read the main directory
fs
.
readdir
(
mainDir
,
(
err
,
files
)
=>
{
if
(
err
)
{
return
console
.
error
(
`Unable to scan directory:
${
err
}
`
)
}
// Iterate through each file/folder in the main directory
files
.
forEach
(
(
file
)
=>
{
const
fullPath
=
path
.
join
(
mainDir
,
file
)
// Check if the file is a directory
if
(
fs
.
statSync
(
fullPath
)
.
isDirectory
(
)
)
{
const
packageJsonPath
=
path
.
join
(
fullPath
,
'package.json'
)
// Check if package.json exists in the directory
if
(
fs
.
existsSync
(
packageJsonPath
)
)
{
console
.
log
(
`Running npm install in
${
fullPath
}
`
)
// Execute npm install in the directory
exec
(
'npm install'
,
{
cwd
:
fullPath
}
,
(
error
,
stdout
,
stderr
)
=>
{
if
(
error
)
{
console
.
error
(
`Error installing dependencies in
${
fullPath
}
:
${
error
}
`
)
return
}
console
.
log
(
`npm install completed in
${
fullPath
}
`
)
console
.
log
(
stdout
)
if
(
stderr
)
{
console
.
error
(
stderr
)
}
}
)
}
}
}
)
}
)
Back
|
FazBrowse Home
|
New Git URL