setupcomfyuimodels 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1189,8 +1189,8 @@ var require_command = __commonJS({
1189
1189
  "node_modules/commander/lib/command.js"(exports2) {
1190
1190
  var EventEmitter = require("node:events").EventEmitter;
1191
1191
  var childProcess = require("node:child_process");
1192
- var path2 = require("node:path");
1193
- var fs2 = require("node:fs");
1192
+ var path3 = require("node:path");
1193
+ var fs3 = require("node:fs");
1194
1194
  var process3 = require("node:process");
1195
1195
  var { Argument: Argument2, humanReadableArgName } = require_argument();
1196
1196
  var { CommanderError: CommanderError2 } = require_error();
@@ -2184,7 +2184,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
2184
2184
  * @param {string} subcommandName
2185
2185
  */
2186
2186
  _checkForMissingExecutable(executableFile, executableDir, subcommandName) {
2187
- if (fs2.existsSync(executableFile)) return;
2187
+ if (fs3.existsSync(executableFile)) return;
2188
2188
  const executableDirMessage = executableDir ? `searched for local subcommand relative to directory '${executableDir}'` : "no directory for search for local subcommand, use .executableDir() to supply a custom directory";
2189
2189
  const executableMissing = `'${executableFile}' does not exist
2190
2190
  - if '${subcommandName}' is not meant to be an executable command, remove description parameter from '.command()' and use '.description()' instead
@@ -2202,11 +2202,11 @@ Expecting one of '${allowedValues.join("', '")}'`);
2202
2202
  let launchWithNode = false;
2203
2203
  const sourceExt = [".js", ".ts", ".tsx", ".mjs", ".cjs"];
2204
2204
  function findFile(baseDir, baseName) {
2205
- const localBin = path2.resolve(baseDir, baseName);
2206
- if (fs2.existsSync(localBin)) return localBin;
2207
- if (sourceExt.includes(path2.extname(baseName))) return void 0;
2205
+ const localBin = path3.resolve(baseDir, baseName);
2206
+ if (fs3.existsSync(localBin)) return localBin;
2207
+ if (sourceExt.includes(path3.extname(baseName))) return void 0;
2208
2208
  const foundExt = sourceExt.find(
2209
- (ext) => fs2.existsSync(`${localBin}${ext}`)
2209
+ (ext) => fs3.existsSync(`${localBin}${ext}`)
2210
2210
  );
2211
2211
  if (foundExt) return `${localBin}${foundExt}`;
2212
2212
  return void 0;
@@ -2218,21 +2218,21 @@ Expecting one of '${allowedValues.join("', '")}'`);
2218
2218
  if (this._scriptPath) {
2219
2219
  let resolvedScriptPath;
2220
2220
  try {
2221
- resolvedScriptPath = fs2.realpathSync(this._scriptPath);
2221
+ resolvedScriptPath = fs3.realpathSync(this._scriptPath);
2222
2222
  } catch {
2223
2223
  resolvedScriptPath = this._scriptPath;
2224
2224
  }
2225
- executableDir = path2.resolve(
2226
- path2.dirname(resolvedScriptPath),
2225
+ executableDir = path3.resolve(
2226
+ path3.dirname(resolvedScriptPath),
2227
2227
  executableDir
2228
2228
  );
2229
2229
  }
2230
2230
  if (executableDir) {
2231
2231
  let localFile = findFile(executableDir, executableFile);
2232
2232
  if (!localFile && !subcommand._executableFile && this._scriptPath) {
2233
- const legacyName = path2.basename(
2233
+ const legacyName = path3.basename(
2234
2234
  this._scriptPath,
2235
- path2.extname(this._scriptPath)
2235
+ path3.extname(this._scriptPath)
2236
2236
  );
2237
2237
  if (legacyName !== this._name) {
2238
2238
  localFile = findFile(
@@ -2243,7 +2243,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
2243
2243
  }
2244
2244
  executableFile = localFile || executableFile;
2245
2245
  }
2246
- launchWithNode = sourceExt.includes(path2.extname(executableFile));
2246
+ launchWithNode = sourceExt.includes(path3.extname(executableFile));
2247
2247
  let proc;
2248
2248
  if (process3.platform !== "win32") {
2249
2249
  if (launchWithNode) {
@@ -3158,7 +3158,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
3158
3158
  * @return {Command}
3159
3159
  */
3160
3160
  nameFromFilename(filename) {
3161
- this._name = path2.basename(filename, path2.extname(filename));
3161
+ this._name = path3.basename(filename, path3.extname(filename));
3162
3162
  return this;
3163
3163
  }
3164
3164
  /**
@@ -3172,9 +3172,9 @@ Expecting one of '${allowedValues.join("', '")}'`);
3172
3172
  * @param {string} [path]
3173
3173
  * @return {(string|null|Command)}
3174
3174
  */
3175
- executableDir(path3) {
3176
- if (path3 === void 0) return this._executableDir;
3177
- this._executableDir = path3;
3175
+ executableDir(path4) {
3176
+ if (path4 === void 0) return this._executableDir;
3177
+ this._executableDir = path4;
3178
3178
  return this;
3179
3179
  }
3180
3180
  /**
@@ -12079,10 +12079,10 @@ var require_stringify = __commonJS({
12079
12079
  replacer = null;
12080
12080
  indent = EMPTY;
12081
12081
  };
12082
- var join = (one, two, gap) => one ? two ? one + two.trim() + LF + gap : one.trimRight() + LF + gap : two ? two.trimRight() + LF + gap : EMPTY;
12082
+ var join2 = (one, two, gap) => one ? two ? one + two.trim() + LF + gap : one.trimRight() + LF + gap : two ? two.trimRight() + LF + gap : EMPTY;
12083
12083
  var join_content = (inside, value, gap) => {
12084
12084
  const comment = process_comments(value, PREFIX_BEFORE, gap + indent, true);
12085
- return join(comment, inside, gap);
12085
+ return join2(comment, inside, gap);
12086
12086
  };
12087
12087
  var array_stringify = (value, gap) => {
12088
12088
  const deeper_gap = gap + indent;
@@ -12093,7 +12093,7 @@ var require_stringify = __commonJS({
12093
12093
  if (i !== 0) {
12094
12094
  inside += COMMA;
12095
12095
  }
12096
- const before = join(
12096
+ const before = join2(
12097
12097
  after_comma,
12098
12098
  process_comments(value, BEFORE(i), deeper_gap),
12099
12099
  deeper_gap
@@ -12103,7 +12103,7 @@ var require_stringify = __commonJS({
12103
12103
  inside += process_comments(value, AFTER_VALUE(i), deeper_gap);
12104
12104
  after_comma = process_comments(value, AFTER(i), deeper_gap);
12105
12105
  }
12106
- inside += join(
12106
+ inside += join2(
12107
12107
  after_comma,
12108
12108
  process_comments(value, PREFIX_AFTER, deeper_gap),
12109
12109
  deeper_gap
@@ -12128,7 +12128,7 @@ var require_stringify = __commonJS({
12128
12128
  inside += COMMA;
12129
12129
  }
12130
12130
  first = false;
12131
- const before = join(
12131
+ const before = join2(
12132
12132
  after_comma,
12133
12133
  process_comments(value, BEFORE(key), deeper_gap),
12134
12134
  deeper_gap
@@ -12138,7 +12138,7 @@ var require_stringify = __commonJS({
12138
12138
  after_comma = process_comments(value, AFTER(key), deeper_gap);
12139
12139
  };
12140
12140
  keys.forEach(iteratee);
12141
- inside += join(
12141
+ inside += join2(
12142
12142
  after_comma,
12143
12143
  process_comments(value, PREFIX_AFTER, deeper_gap),
12144
12144
  deeper_gap
@@ -12494,14 +12494,6 @@ var stopProgressBar = () => {
12494
12494
  multibar.stop();
12495
12495
  };
12496
12496
 
12497
- // src/getConfig.ts
12498
- var import_fs = require("fs");
12499
- var import_comment_json = __toESM(require_src2());
12500
- var getConfig = async (configLocation) => {
12501
- const fileContent = (0, import_fs.readFileSync)(configLocation, "utf-8");
12502
- return (0, import_comment_json.parse)(fileContent);
12503
- };
12504
-
12505
12497
  // node_modules/chalk/source/vendor/ansi-styles/index.js
12506
12498
  var ANSI_BACKGROUND_OFFSET = 10;
12507
12499
  var wrapAnsi16 = (offset = 0) => (code) => `\x1B[${code + offset}m`;
@@ -13001,15 +12993,26 @@ var source_default = chalk;
13001
12993
  var { CIVITAI_TOKEN, HF_TOKEN } = process.env;
13002
12994
  var MAX_CONCURRENT_DOWNLOADS = 8;
13003
12995
  var concurrentDownloads = 0;
13004
- var downloadAssets = async (configLocation, targetFolder) => {
13005
- const config = await getConfig(configLocation);
12996
+ var downloadAssets = async (config, targetFolder) => {
12997
+ const filesConfigs = [
12998
+ config.files,
12999
+ ...Object.entries(config.groups).filter(([groupName]) => config.groupsEnabled[groupName]).map(([_, f]) => f.files)
13000
+ ];
13001
+ const foldersConfigs = [
13002
+ config.folders,
13003
+ ...Object.entries(config.groups).filter(([groupName]) => config.groupsEnabled[groupName]).map(([_, f]) => f.folders)
13004
+ ];
13006
13005
  const filePromises = [
13007
- ...Object.entries(config.files).map(([targetLocation, url]) => {
13008
- const fileName = import_path.default.basename(targetLocation), dir = import_path.default.dirname(targetLocation);
13009
- return scheduleDownload(targetFolder, dir, fileName, url);
13010
- }),
13011
- ...Object.entries(config.folders).flatMap(
13012
- ([folder, urls]) => urls.map((url) => scheduleDownload(targetFolder, folder, null, url))
13006
+ ...filesConfigs.flatMap(
13007
+ (config2) => Object.entries(config2.files).map(([targetLocation, url]) => {
13008
+ const fileName = import_path.default.basename(targetLocation), dir = import_path.default.dirname(targetLocation);
13009
+ return scheduleDownload(targetFolder, dir, fileName, url);
13010
+ })
13011
+ ),
13012
+ ...foldersConfigs.flatMap(
13013
+ (config2) => Object.entries(config2).flatMap(
13014
+ ([folder, urls]) => urls.map((url) => scheduleDownload(targetFolder, folder, null, url))
13015
+ )
13013
13016
  )
13014
13017
  ];
13015
13018
  setTotalProgress(0, filePromises.length);
@@ -13033,6 +13036,17 @@ var downloadAssets = async (configLocation, targetFolder) => {
13033
13036
  var scheduledDownloads = [];
13034
13037
  var results = [];
13035
13038
  var scheduleDownload = async (globalTargetLocation, targetLocation, targetFileName, url) => {
13039
+ const matchingJob = scheduledDownloads.find(
13040
+ (d) => d.targetLocation === targetLocation && d.targetFileName === targetFileName
13041
+ );
13042
+ if (matchingJob) {
13043
+ if (matchingJob.url !== url) {
13044
+ throw new Error(
13045
+ `Conflicting download jobs for ${targetLocation}/${targetFileName || ""}: ${matchingJob.url} and ${url}`
13046
+ );
13047
+ }
13048
+ return;
13049
+ }
13036
13050
  scheduledDownloads.push({ targetLocation, url, targetFileName });
13037
13051
  if (concurrentDownloads < MAX_CONCURRENT_DOWNLOADS) {
13038
13052
  while (scheduledDownloads.length > 0) {
@@ -13133,11 +13147,54 @@ var downloadFile = async (globalTargetLocation, targetLocation, targetFileName,
13133
13147
  }
13134
13148
  };
13135
13149
 
13150
+ // src/replacements.ts
13151
+ var fs2 = __toESM(require("fs"));
13152
+ var path2 = __toESM(require("path"));
13153
+ var replaceInFiles = (config, targetFolder) => {
13154
+ const replacements = config.replacements || [];
13155
+ for (const replacement of replacements) {
13156
+ const filePath = path2.join(targetFolder, replacement.file);
13157
+ if (fs2.existsSync(filePath)) {
13158
+ let fileContent = fs2.readFileSync(filePath, "utf-8");
13159
+ if (fileContent.includes(replacement.original)) {
13160
+ const lines = fileContent.split("\n");
13161
+ if (lines.length >= replacement.line && lines[replacement.line - 1].includes(replacement.original)) {
13162
+ lines[replacement.line - 1] = lines[replacement.line - 1].replace(
13163
+ replacement.original,
13164
+ replacement.replacement
13165
+ );
13166
+ fileContent = lines.join("\n");
13167
+ } else {
13168
+ console.warn(
13169
+ `Line number mismatch in ${replacement.file}. Expected line ${replacement.line} to contain the original code.`
13170
+ );
13171
+ }
13172
+ fs2.writeFileSync(filePath, fileContent, "utf-8");
13173
+ console.log(`Patched ${replacement.file} at line ${replacement.line}`);
13174
+ } else {
13175
+ console.warn(`Original code not found in ${replacement.file}`);
13176
+ }
13177
+ } else {
13178
+ console.warn(`File not found: ${replacement.file}`);
13179
+ }
13180
+ }
13181
+ };
13182
+
13183
+ // src/getConfig.ts
13184
+ var import_fs = require("fs");
13185
+ var import_comment_json = __toESM(require_src2());
13186
+ var getConfig = async (configLocation) => {
13187
+ const fileContent = (0, import_fs.readFileSync)(configLocation, "utf-8");
13188
+ return (0, import_comment_json.parse)(fileContent);
13189
+ };
13190
+
13136
13191
  // src/index.ts
13137
13192
  var program2 = new Command();
13138
13193
  program2.name("Setup ComfyUi Models");
13139
13194
  program2.command("download").argument("<config>", "JSON config file location").option("-l, --location <path>", "Target download location").action(async (configLocation, options) => {
13140
- await downloadAssets(configLocation, options.location || "./");
13195
+ const config = await getConfig(configLocation);
13196
+ await downloadAssets(config, options.location || "./");
13197
+ replaceInFiles(config, options.location || "./");
13141
13198
  });
13142
13199
  program2.parse();
13143
13200
  //# sourceMappingURL=index.js.map