MCPcopy Create free account
hub / github.com/SmartThingsCommunity/smartthings-cli / walkDir

Function walkDir

src/lib/command/util/edge-driver-package.ts:84–112  ·  view source on GitHub ↗
(fromDir: string, nested = 2)

Source from the content-addressed store, hash-verified

82 // The max depth is 10 but the main project directory and the src directory itself count,
83 // so we start at 2.
84 const walkDir = async (fromDir: string, nested = 2): Promise<void> => {
85 await Promise.all(readdirSync(fromDir).map(async filename => {
86 const fullFilename = `${fromDir}/${filename}`
87 if (await fileExists(fullFilename)) {
88 const isLink = await isSymbolicLink(fullFilename)
89 const resolvedFilename = isLink ? await realPathForSymbolicLink(fullFilename) : fullFilename
90 if (await isDir(resolvedFilename)) {
91 if (isLink) {
92 fatalIssue(`sym links to directories are not allowed (${fullFilename})`)
93 } else {
94 // maximum depth is defined by server
95 if (nested < 10) {
96 await walkDir(fullFilename, nested + 1)
97 } else {
98 fatalIssue(`drivers directory nested too deeply (at ${fullFilename}); max depth is 10`)
99 }
100 }
101 } else {
102 const filenameForTestMatch = fullFilename.substring(srcDir.length + 1)
103 if (!testFileMatchers.some(matcher => matcher(filenameForTestMatch))) {
104 const archiveName = `src${fullFilename.substring(srcDir.length)}`
105 zip.file(archiveName, createReadStream(fullFilename))
106 }
107 }
108 } else {
109 fatalIssue(`sym link ${fullFilename} points to non-existent file`)
110 }
111 }))
112 }
113
114 await walkDir(srcDir)
115 return successful

Callers 1

processSrcDirFunction · 0.85

Calls 5

fileExistsFunction · 0.85
isSymbolicLinkFunction · 0.85
realPathForSymbolicLinkFunction · 0.85
isDirFunction · 0.85
fatalIssueFunction · 0.85

Tested by

no test coverage detected