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 +97 -40
- package/dist/index.js.map +4 -4
- package/package.json +1 -1
- package/src/downloadAssets.ts +40 -13
- package/src/downloadAssets.ts~ +11 -9
- package/src/getConfig.ts +17 -4
- package/src/getConfig.ts~ +11 -0
- package/src/index.ts +5 -1
- package/src/index.ts~ +3 -2
- package/src/replacements.ts +37 -0
- package/src/replacements.ts~ +0 -0
package/package.json
CHANGED
package/src/downloadAssets.ts
CHANGED
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
stopProgressBar,
|
|
10
10
|
updateKey,
|
|
11
11
|
} from "./progressbar";
|
|
12
|
-
import {
|
|
12
|
+
import { Config } from "./getConfig";
|
|
13
13
|
import chalk from "chalk";
|
|
14
14
|
|
|
15
15
|
const { CIVITAI_TOKEN, HF_TOKEN } = process.env;
|
|
@@ -17,19 +17,32 @@ const { CIVITAI_TOKEN, HF_TOKEN } = process.env;
|
|
|
17
17
|
const MAX_CONCURRENT_DOWNLOADS = 8;
|
|
18
18
|
let concurrentDownloads = 0;
|
|
19
19
|
|
|
20
|
-
export const downloadAssets = async (
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
)
|
|
24
|
-
|
|
20
|
+
export const downloadAssets = async (config: Config, targetFolder: string) => {
|
|
21
|
+
const filesConfigs = [
|
|
22
|
+
config.files,
|
|
23
|
+
...Object.entries(config.groups)
|
|
24
|
+
.filter(([groupName]) => config.groupsEnabled[groupName])
|
|
25
|
+
.map(([_, f]) => f.files),
|
|
26
|
+
];
|
|
27
|
+
const foldersConfigs = [
|
|
28
|
+
config.folders,
|
|
29
|
+
...Object.entries(config.groups)
|
|
30
|
+
.filter(([groupName]) => config.groupsEnabled[groupName])
|
|
31
|
+
.map(([_, f]) => f.folders),
|
|
32
|
+
];
|
|
33
|
+
|
|
25
34
|
const filePromises = [
|
|
26
|
-
...
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
35
|
+
...filesConfigs.flatMap((config) =>
|
|
36
|
+
Object.entries(config.files).map(([targetLocation, url]) => {
|
|
37
|
+
const fileName = path.basename(targetLocation),
|
|
38
|
+
dir = path.dirname(targetLocation);
|
|
39
|
+
return scheduleDownload(targetFolder, dir, fileName, url);
|
|
40
|
+
}),
|
|
41
|
+
),
|
|
42
|
+
...foldersConfigs.flatMap((config) =>
|
|
43
|
+
Object.entries(config).flatMap(([folder, urls]) =>
|
|
44
|
+
urls.map((url) => scheduleDownload(targetFolder, folder, null, url)),
|
|
45
|
+
),
|
|
33
46
|
),
|
|
34
47
|
];
|
|
35
48
|
setTotalProgress(0, filePromises.length);
|
|
@@ -80,6 +93,20 @@ const scheduleDownload = async (
|
|
|
80
93
|
targetFileName: string | null,
|
|
81
94
|
url: string,
|
|
82
95
|
) => {
|
|
96
|
+
const matchingJob = scheduledDownloads.find(
|
|
97
|
+
(d) =>
|
|
98
|
+
d.targetLocation === targetLocation &&
|
|
99
|
+
d.targetFileName === targetFileName,
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
if (matchingJob) {
|
|
103
|
+
if (matchingJob.url !== url) {
|
|
104
|
+
throw new Error(
|
|
105
|
+
`Conflicting download jobs for ${targetLocation}/${targetFileName || ""}: ${matchingJob.url} and ${url}`,
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
83
110
|
scheduledDownloads.push({ targetLocation, url, targetFileName });
|
|
84
111
|
if (concurrentDownloads < MAX_CONCURRENT_DOWNLOADS) {
|
|
85
112
|
while (scheduledDownloads.length > 0) {
|
package/src/downloadAssets.ts~
CHANGED
|
@@ -12,25 +12,24 @@ import {
|
|
|
12
12
|
import { getConfig } from "./getConfig";
|
|
13
13
|
import chalk from "chalk";
|
|
14
14
|
|
|
15
|
-
const {
|
|
16
|
-
|
|
17
|
-
if (!WORKSPACE) {
|
|
18
|
-
throw new Error("WORKSPACE environment variable is not set.");
|
|
19
|
-
}
|
|
15
|
+
const { CIVITAI_TOKEN, HF_TOKEN } = process.env;
|
|
20
16
|
|
|
21
17
|
const MAX_CONCURRENT_DOWNLOADS = 8;
|
|
22
18
|
let concurrentDownloads = 0;
|
|
23
19
|
|
|
24
|
-
export const downloadAssets = async (
|
|
20
|
+
export const downloadAssets = async (
|
|
21
|
+
configLocation: string,
|
|
22
|
+
targetFolder: string,
|
|
23
|
+
) => {
|
|
25
24
|
const config = await getConfig(configLocation);
|
|
26
25
|
const filePromises = [
|
|
27
26
|
...Object.entries(config.files).map(([targetLocation, url]) => {
|
|
28
27
|
const fileName = path.basename(targetLocation),
|
|
29
28
|
dir = path.dirname(targetLocation);
|
|
30
|
-
return scheduleDownload(dir, fileName, url);
|
|
29
|
+
return scheduleDownload(targetFolder, dir, fileName, url);
|
|
31
30
|
}),
|
|
32
31
|
...Object.entries(config.folders).flatMap(([folder, urls]) =>
|
|
33
|
-
urls.map((url) => scheduleDownload(folder, null, url)),
|
|
32
|
+
urls.map((url) => scheduleDownload(targetFolder, folder, null, url)),
|
|
34
33
|
),
|
|
35
34
|
];
|
|
36
35
|
setTotalProgress(0, filePromises.length);
|
|
@@ -76,6 +75,7 @@ const results = [] as {
|
|
|
76
75
|
error?: string;
|
|
77
76
|
}[];
|
|
78
77
|
const scheduleDownload = async (
|
|
78
|
+
globalTargetLocation: string,
|
|
79
79
|
targetLocation: string,
|
|
80
80
|
targetFileName: string | null,
|
|
81
81
|
url: string,
|
|
@@ -88,6 +88,7 @@ const scheduleDownload = async (
|
|
|
88
88
|
concurrentDownloads++;
|
|
89
89
|
try {
|
|
90
90
|
const skipped = await downloadFile(
|
|
91
|
+
globalTargetLocation,
|
|
91
92
|
nextDownload.targetLocation,
|
|
92
93
|
nextDownload.targetFileName,
|
|
93
94
|
nextDownload.url,
|
|
@@ -111,6 +112,7 @@ const scheduleDownload = async (
|
|
|
111
112
|
};
|
|
112
113
|
|
|
113
114
|
const downloadFile = async (
|
|
115
|
+
globalTargetLocation: string,
|
|
114
116
|
targetLocation: string,
|
|
115
117
|
targetFileName: string | null,
|
|
116
118
|
url: string,
|
|
@@ -118,7 +120,7 @@ const downloadFile = async (
|
|
|
118
120
|
const getTargetId = () => path.join(targetLocation, targetFileName || "");
|
|
119
121
|
try {
|
|
120
122
|
const targetDir = path.normalize(
|
|
121
|
-
`${
|
|
123
|
+
`${globalTargetLocation}/${targetLocation}`,
|
|
122
124
|
);
|
|
123
125
|
|
|
124
126
|
fs.mkdirSync(targetDir, { recursive: true });
|
package/src/getConfig.ts
CHANGED
|
@@ -1,11 +1,24 @@
|
|
|
1
1
|
import { readFileSync } from "fs";
|
|
2
2
|
import { parse } from "comment-json";
|
|
3
3
|
|
|
4
|
+
type FilesAndFolders = {
|
|
5
|
+
files: Record<string, string>;
|
|
6
|
+
folders: Record<string, string[]>;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export type Config = {
|
|
10
|
+
groupsEnabled: Record<string, boolean>;
|
|
11
|
+
groups: Record<string, FilesAndFolders>;
|
|
12
|
+
replacements?: {
|
|
13
|
+
file: string;
|
|
14
|
+
original: string;
|
|
15
|
+
replacement: string;
|
|
16
|
+
line: number;
|
|
17
|
+
}[];
|
|
18
|
+
} & FilesAndFolders;
|
|
19
|
+
|
|
4
20
|
export const getConfig = async (configLocation: string) => {
|
|
5
21
|
const fileContent = readFileSync(configLocation, "utf-8");
|
|
6
22
|
|
|
7
|
-
return parse(fileContent) as unknown as
|
|
8
|
-
files: Record<string, string>;
|
|
9
|
-
folders: Record<string, string[]>;
|
|
10
|
-
};
|
|
23
|
+
return parse(fileContent) as unknown as Config;
|
|
11
24
|
};
|
package/src/getConfig.ts~
CHANGED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { readFileSync } from "fs";
|
|
2
|
+
import { parse } from "comment-json";
|
|
3
|
+
|
|
4
|
+
export const getConfig = async (configLocation: string) => {
|
|
5
|
+
const fileContent = readFileSync(configLocation, "utf-8");
|
|
6
|
+
|
|
7
|
+
return parse(fileContent) as unknown as {
|
|
8
|
+
files: Record<string, string>;
|
|
9
|
+
folders: Record<string, string[]>;
|
|
10
|
+
};
|
|
11
|
+
};
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { Command } from "@commander-js/extra-typings";
|
|
3
3
|
import { downloadAssets } from "./downloadAssets";
|
|
4
|
+
import { replaceInFiles } from "./replacements";
|
|
5
|
+
import { getConfig } from "./getConfig";
|
|
4
6
|
|
|
5
7
|
const program = new Command();
|
|
6
8
|
program.name("Setup ComfyUi Models");
|
|
@@ -9,6 +11,8 @@ program
|
|
|
9
11
|
.argument("<config>", "JSON config file location")
|
|
10
12
|
.option("-l, --location <path>", "Target download location")
|
|
11
13
|
.action(async (configLocation: string, options) => {
|
|
12
|
-
await
|
|
14
|
+
const config = await getConfig(configLocation);
|
|
15
|
+
await downloadAssets(config, options.location || "./");
|
|
16
|
+
replaceInFiles(config, options.location || "./");
|
|
13
17
|
});
|
|
14
18
|
program.parse();
|
package/src/index.ts~
CHANGED
|
@@ -7,7 +7,8 @@ program.name("Setup ComfyUi Models");
|
|
|
7
7
|
program
|
|
8
8
|
.command("download")
|
|
9
9
|
.argument("<config>", "JSON config file location")
|
|
10
|
-
.
|
|
11
|
-
|
|
10
|
+
.option("-l, --location <path>", "Target download location")
|
|
11
|
+
.action(async (configLocation: string, options) => {
|
|
12
|
+
await downloadAssets(configLocation, options.location || "./");
|
|
12
13
|
});
|
|
13
14
|
program.parse();
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import * as fs from "fs";
|
|
2
|
+
import * as path from "path";
|
|
3
|
+
import { Config } from "./getConfig";
|
|
4
|
+
|
|
5
|
+
export const replaceInFiles = (config: Config, targetFolder: string) => {
|
|
6
|
+
const replacements = config.replacements || [];
|
|
7
|
+
for (const replacement of replacements) {
|
|
8
|
+
const filePath = path.join(targetFolder, replacement.file);
|
|
9
|
+
if (fs.existsSync(filePath)) {
|
|
10
|
+
let fileContent = fs.readFileSync(filePath, "utf-8");
|
|
11
|
+
if (fileContent.includes(replacement.original)) {
|
|
12
|
+
const lines = fileContent.split("\n");
|
|
13
|
+
if (
|
|
14
|
+
lines.length >= replacement.line &&
|
|
15
|
+
lines[replacement.line - 1].includes(replacement.original)
|
|
16
|
+
) {
|
|
17
|
+
lines[replacement.line - 1] = lines[replacement.line - 1].replace(
|
|
18
|
+
replacement.original,
|
|
19
|
+
replacement.replacement,
|
|
20
|
+
);
|
|
21
|
+
fileContent = lines.join("\n");
|
|
22
|
+
} else {
|
|
23
|
+
console.warn(
|
|
24
|
+
`Line number mismatch in ${replacement.file}. Expected line ${replacement.line} to contain the original code.`,
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
fs.writeFileSync(filePath, fileContent, "utf-8");
|
|
29
|
+
console.log(`Patched ${replacement.file} at line ${replacement.line}`);
|
|
30
|
+
} else {
|
|
31
|
+
console.warn(`Original code not found in ${replacement.file}`);
|
|
32
|
+
}
|
|
33
|
+
} else {
|
|
34
|
+
console.warn(`File not found: ${replacement.file}`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
};
|
|
File without changes
|