MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / iterate

Method iterate

tools/mcpack.js:1318–1368  ·  view source on GitHub ↗
(target, sourceIn, include, suffix, straight)

Source from the content-addressed store, hash-verified

1316 appendTarget(target) {
1317 }
1318 iterate(target, sourceIn, include, suffix, straight) {
1319 var tool = this.tool;
1320 var source = (typeof sourceIn == "string") ? sourceIn : sourceIn.source;
1321 var sourceParts = tool.splitPath(source);
1322 var slash = source.lastIndexOf(tool.slash);
1323 var directory = this.tool.resolveDirectoryPath(sourceParts.directory);
1324 if (directory) {
1325 this.count = 0;
1326 var star = sourceParts.name.lastIndexOf("*");
1327 var prefix = (star >= 0) ? sourceParts.name.slice(0, star) : sourceParts.name;
1328 var names = tool.enumerateDirectory(directory);
1329 var c = names.length;
1330 for (var i = 0; i < c; i++) {
1331 var name = names[i];
1332 if (name[0] == ".")
1333 continue;
1334 var path = directory + tool.slash + name;
1335 var parts = tool.splitPath(path);
1336 if ((".ts" === parts.extension) && parts.name.endsWith(".d")) {
1337 parts.name = parts.name.slice(0, parts.name.length - 2);
1338 parts.extension = ".d.ts";
1339 }
1340 if (star >= 0) {
1341 if (prefix) {
1342 if (parts.name.startsWith(prefix))
1343 name = parts.name.slice(prefix.length);
1344 else
1345 continue;
1346 }
1347 else
1348 name = parts.name;
1349 }
1350 else {
1351 if ((parts.name == prefix) && ((sourceParts.extension == "") || (sourceParts.extension == parts.extension)))
1352 name = prefix;
1353 else
1354 continue;
1355 }
1356 var kind = tool.isDirectoryOrFile(path);
1357 var query = (typeof sourceIn === "string") ? {} : {...sourceIn};
1358 if (straight)
1359 this.appendSource(target, path, include, suffix, parts, kind, query);
1360 else
1361 this.appendSource(target + name, path, include, suffix, parts, kind, query);
1362 }
1363 if (!this.count)
1364 this.noFilesMatch(source, star);
1365 }
1366 else
1367 tool.reportError(null, 0, "directory not found: " + source);
1368 }
1369 noFilesMatch(target) {
1370 }
1371 process(property) {

Callers 2

processMethod · 0.95
iterateZipDirectoryFunction · 0.45

Calls 3

appendSourceMethod · 0.95
noFilesMatchMethod · 0.95
sliceMethod · 0.65

Tested by

no test coverage detected