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

Method iterate

tools/mcmanifest.js:2000–2056  ·  view source on GitHub ↗
(target, sourceIn, include, suffix, straight)

Source from the content-addressed store, hash-verified

1998 appendTarget(target) {
1999 }
2000 iterate(target, sourceIn, include, suffix, straight) {
2001 var tool = this.tool;
2002 var source = (typeof sourceIn == "string") ? sourceIn : sourceIn.source;
2003 var sourceParts = tool.splitPath(source);
2004 var directory = this.tool.resolveDirectoryPath(sourceParts.directory);
2005 if (directory) {
2006 this.count = 0;
2007 var star = sourceParts.name.lastIndexOf("*");
2008 var prefix = (star >= 0) ? sourceParts.name.slice(0, star) : sourceParts.name + sourceParts.extension;
2009 var names = tool.enumerateDirectory(directory);
2010 var c = names.length;
2011 for (var i = 0; i < c; i++) {
2012 var name = names[i];
2013 if (name[0] == ".")
2014 continue;
2015 var path = directory + tool.slash + name;
2016 var parts = tool.splitPath(path);
2017 if ((".ts" === parts.extension) && parts.name.endsWith(".d")) {
2018 parts.name = parts.name.slice(0, parts.name.length - 2);
2019 parts.extension = ".d.ts";
2020 }
2021 if (star >= 0) {
2022 if (prefix) {
2023 if (parts.name.startsWith(prefix))
2024 name = parts.name.slice(prefix.length);
2025 else
2026 continue;
2027 }
2028 else
2029 name = parts.name;
2030 }
2031 else {
2032 if (parts.name == prefix)
2033 name = prefix;
2034 else if (parts.name + parts.extension == prefix)
2035 name = sourceParts.name;
2036 else
2037 continue;
2038 }
2039 var kind = tool.isDirectoryOrFile(path);
2040 var query = (typeof sourceIn === "string") ? {} : {...sourceIn};
2041 if (straight)
2042 this.appendSource(target, path, include, suffix, parts, kind, query);
2043 else
2044 this.appendSource(target + name, path, include, suffix, parts, kind, query);
2045 }
2046 if (!this.count) {
2047 var trailingSlash = source.lastIndexOf("/");
2048 if (trailingSlash == source.length - 1)
2049 this.appendFolder(tool.cFolders, source);
2050 else
2051 this.noFilesMatch(source, star);
2052 }
2053 }
2054 else
2055 tool.reportError(null, 0, "directory not found: " + source);
2056 }
2057 noFilesMatch(target) {

Callers 1

processMethod · 0.95

Calls 4

appendSourceMethod · 0.95
appendFolderMethod · 0.95
noFilesMatchMethod · 0.95
sliceMethod · 0.65

Tested by

no test coverage detected