FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
JsObjects/JavaScript/UnitTests/src/temp.js at master · charliecalvert/JsObjects · GitHub
charliecalvert
/
JsObjects
Public
Notifications
You must be signed in to change notification settings
Fork
53
Star
22
Code
Issues
1
Pull requests
1
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
JsObjects
/
JavaScript
/
UnitTests
/
src
/
temp.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
106 lines (91 loc) · 3.74 KB
Breadcrumbs
JsObjects
/
JavaScript
/
UnitTests
/
src
/
temp.js
Copy path
File metadata and controls
106 lines (91 loc) · 3.74 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
#!/usr/bin/env node
// const { exec } = require('child_process');
const
{
log
}
=
require
(
'console'
)
;
const
fsp
=
require
(
'fs/promises'
)
;
// const { debugParams } = require('./src/debugParams');
// const { programStub } = require('./src/programStub');
// const { setupAuditCheck } = require('./src/audit-check/perform-audit-check');
// const { writeAuditDataReport } = require('./src/utils');
const
{
createAuditDataReport
,
writeAuditDataReport
}
=
require
(
'./src/create-audit-data-report'
)
;
/*
* This script searches for a file in a directory and its subdirectories.
* When the file is found, it executes a program with the file as an argument.
* The program is expected to parse the file and do something with it.
*/
const
useDebug
=
false
;
function
debugParams
(
dir
,
entries
)
{
log
(
`Searching in:
${
dir
}
`
)
;
log
(
`Entries:
${
entries
}
`
)
;
}
function
programStub
(
filePath
)
{
console
.
log
(
`programStub got:
${
filePath
}
`
)
;
}
// Error checking: log('Audit data reports length:', auditDataReports.length);
log
(
'Audit data reports type:'
,
typeof
auditDataReports
)
;
if
(
debugParams
===
undefined
)
{
throw
new
Error
(
'debugParams is not defined'
)
;
}
if
(
programStub
===
undefined
)
{
throw
new
Error
(
'programStub is not defined'
)
;
}
if
(
createAuditDataReport
===
undefined
)
{
throw
new
Error
(
'createAuditDataReport is not defined'
)
;
}
/*
* This function searches for instances of package.js
* in a directory and its subdirectories.
* When the file is found, it executes an audit on it.
* The program looks for errors recorded in the audit.
*/
async
function
setupCallToExecProgram
(
auditDataReports
)
{
if
(
auditDataReports
===
undefined
)
{
throw
new
Error
(
'auditDataReports is not defined in start'
)
;
}
async
function
readDirectory
(
directoryToSearch
)
{
// Find all subdirectories in the directoryToSearch
const
directoryEntries
=
await
fsp
.
readdir
(
directoryToSearch
,
{
withFileTypes
:
true
}
)
;
// Error handling. If no entries are found, log it.
if
(
directoryEntries
.
length
===
0
)
{
log
(
`No entries found in
${
directoryToSearch
}
`
)
;
}
else
{
log
(
`Entries found in
${
directoryToSearch
}
:
${
directoryEntries
.
length
}
`
)
;
}
if
(
useDebug
)
{
debugParams
(
directoryToSearch
,
directoryEntries
)
;
}
// Parameters to pass to execProgram
const
params
=
[
directoryEntries
,
directoryToSearch
,
auditDataReports
,
]
;
// Execute the programToRun on packageJson
// in directoryToSearch and its subdirectories.
await
createAuditDataReport
(
...
params
)
;
}
log
(
'home: '
,
'/home/ubuntu/Git/JsObjects/JavaScript/Design/src/'
)
;
const
directoryToSearch
=
'/home/ubuntu/Git/JsObjects/JavaScript/Design/src/'
;
// The directory we want to search
/* let programToRun;
if (useDebug) {
programToRun = 'programStub.js';
} else {
programToRun = setupAuditCheck;
} */
// log(`Searching in ${directoryToSearch}`);
await
readDirectory
(
directoryToSearch
)
.
then
(
(
)
=>
{
console
.
log
(
'call to searchFile completed successfully.'
)
;
}
)
.
catch
(
(
err
)
=>
console
.
error
(
`Error:
${
err
.
message
}
`
)
)
;
// log('after searcfFile Audit data reports length:', auditDataReports.length);
}
// setupCallToExecProgram
async
function
run
(
)
{
const
auditDataReports
=
[
]
;
await
setupCallToExecProgram
(
auditDataReports
)
;
log
(
'run Audit data reports length:'
,
auditDataReports
.
length
)
;
// convert the array to valid JSON
const
auditDataReportsJson
=
JSON
.
stringify
(
auditDataReports
)
;
writeAuditDataReport
(
auditDataReportsJson
)
;
log
(
'Audit data reports written to file'
)
;
}
// run
run
(
)
;
// log('Audit data reports length:', auditDataReports.length);
// End of file
Back
|
FazBrowse Home
|
New Git URL