-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathcli.ts
116 lines (100 loc) · 3.18 KB
/
cli.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/usr/bin/env ts-node
import * as fs from "fs";
import { program } from "commander";
import { generateConfigurations } from "./commands/generateConfigurations";
import log from "loglevel";
import { createMetadataFiles } from "./helpers/metadata";
import { createGenerativeArt } from "./commands/createArt";
const CACHE_PATH = './.cache';
program.version("0.0.2");
if (!fs.existsSync(CACHE_PATH)) {
fs.mkdirSync(CACHE_PATH);
}
log.setLevel(log.levels.INFO);
program
.command("generate_art_configurations")
.argument(
"<directory>",
"Directory containing traits named from 0-n",
(val) => fs.readdirSync(`${val}`)
)
.action(async (files: string[]) => {
log.info("creating traits configuration file");
const startMs = Date.now();
const successful = await generateConfigurations(files);
const endMs = Date.now();
const timeTaken = new Date(endMs - startMs).toISOString().substr(11, 8);
if (successful) {
log.info("traits-configuration.json has been created!");
log.info(
`ended at: ${new Date(endMs).toISOString()}. time taken: ${timeTaken}`
);
} else {
log.info("The art configuration file was not created");
}
});
program
.command("create_generative_art")
.option(
"-n, --number-of-images <string>",
"Number of images to be generated",
"100"
)
.option(
"-c, --config-location <string>",
"Location of the traits configuration file",
"./traits-configuration.json"
)
.option(
"-o, --output-location <string>",
"If you wish to do image generation elsewhere, skip it and dump randomized sets to file"
)
.option(
"-ta, --treat-attributes-as-file-names <string>",
"If your attributes are filenames, trim the .png off if set to true"
)
.action(async (directory, cmd) => {
const {
numberOfImages,
configLocation,
outputLocation,
treatAttributesAsFileNames,
} = cmd.opts();
log.info("Loaded configuration file");
// 1. generate the metadata json files
const randomSets = await createMetadataFiles(
numberOfImages,
configLocation,
treatAttributesAsFileNames == "true"
);
log.info("JSON files have been created within the assets directory");
// 2. piecemeal generate the images
if (!outputLocation) {
await createGenerativeArt(configLocation, randomSets);
log.info("Images have been created successfully!");
} else {
fs.writeFileSync(outputLocation, JSON.stringify(randomSets));
log.info("Traits written!");
}
});
function programCommand(name: string) {
return program
.command(name)
.option(
"-e, --env <string>",
"Solana cluster env name",
"devnet" //mainnet-beta, testnet, devnet
)
.requiredOption("-k, --keypair <path>", `Solana wallet location`)
.option("-l, --log-level <string>", "log level", setLogLevel)
.option("-c, --cache-name <string>", "Cache file name", "temp");
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
function setLogLevel(value:any, prev:any) {
if (value === undefined || value === null) {
return;
}
log.info("setting the log value to: " + value);
log.setLevel(value);
}
program.parse(process.argv);