FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
leanjs/scripts/prepare-tests.mjs at main · leanjs/leanjs · GitHub
leanjs
leanjs
Repository navigation
Code
Issues
1
(1)
Pull requests
10
(10)
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
leanjs
/
scripts
/
prepare-tests.mjs
Copy path
More file actions
More file actions
Latest commit
History
History
History
54 lines (44 loc) · 1.82 KB
Breadcrumbs
leanjs
/
scripts
/
prepare-tests.mjs
Copy path
File metadata and controls
54 lines (44 loc) · 1.82 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
import
{
readdir
}
from
"fs/promises"
;
import
path
from
"path"
;
import
{
fileURLToPath
}
from
"url"
;
import
fs
from
"fs-extra"
;
copyLocalPackagesToTestNodeModulesToAllowMultipleVersions
(
)
;
async
function
getDirectories
(
source
)
{
return
(
await
readdir
(
source
,
{
withFileTypes
:
true
}
)
)
.
filter
(
(
dirent
)
=>
dirent
.
isDirectory
(
)
)
.
map
(
(
{
name
}
)
=>
name
)
;
}
function
clearNodeModules
(
{
nodeModulesDir
,
scope
}
)
{
if
(
!
fs
.
existsSync
(
nodeModulesDir
)
)
{
fs
.
mkdirSync
(
nodeModulesDir
)
;
}
const
scopedNodeModulesDir
=
`
${
nodeModulesDir
}
/
${
scope
}
`
;
if
(
fs
.
existsSync
(
scopedNodeModulesDir
)
)
{
fs
.
removeSync
(
scopedNodeModulesDir
)
;
}
fs
.
mkdirSync
(
scopedNodeModulesDir
)
;
}
async
function
copyLocalPackagesToTestNodeModulesToAllowMultipleVersions
(
)
{
console
.
log
(
`Preparing tests...`
)
;
const
__dirname
=
path
.
dirname
(
fileURLToPath
(
import
.
meta
.
url
)
)
;
const
packageNamesToCopy
=
new
Set
(
[
"core"
,
"next"
,
"react"
,
"react-router"
]
)
;
const
packagesSource
=
path
.
join
(
__dirname
,
".."
,
"packages"
)
;
const
testSource
=
path
.
join
(
__dirname
,
".."
,
"tests"
)
;
const
packageDirectories
=
(
await
getDirectories
(
packagesSource
)
)
.
filter
(
(
name
)
=>
packageNamesToCopy
.
has
(
name
)
)
;
const
targetDirectories
=
await
getDirectories
(
testSource
)
;
targetDirectories
.
forEach
(
async
(
directory
)
=>
{
console
.
log
(
`Copying
${
directory
}
`
)
;
const
nodeModulesDir
=
`
${
testSource
}
/
${
directory
}
/node_modules`
;
clearNodeModules
(
{
nodeModulesDir
,
scope
:
"@leanjs"
}
)
;
packageDirectories
.
forEach
(
(
packageName
)
=>
{
const
src
=
`
${
packagesSource
}
/
${
packageName
}
/`
;
const
dest
=
`
${
nodeModulesDir
}
/@leanjs/
${
packageName
}
/`
;
fs
.
cp
(
src
,
dest
,
{
recursive
:
true
}
,
(
error
)
=>
{
if
(
error
)
return
console
.
error
(
"🔥"
,
error
)
;
console
.
log
(
`✅
${
packageName
}
copied to
${
directory
}
`
)
;
}
)
;
}
)
;
}
)
;
}
Back
|
FazBrowse Home
|
New Git URL