modpack-lock 0.5.1 → 0.6.1

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.
@@ -1,16 +1,16 @@
1
- import prompts from 'prompts';
2
- import slugify from 'slugify';
3
- import * as config from './config/index.js';
4
- import { getLicenseList, getLicenseText } from './github_interactions.js';
5
- import { getMinecraftVersions, getModloaders } from './modrinth_interactions.js';
1
+ import prompts from "prompts";
2
+ import slugify from "slugify";
3
+ import * as config from "./config/index.js";
4
+ import {getLicenseList, getLicenseText} from "./github_interactions.js";
5
+ import {getMinecraftVersions, getModloaders} from "./modrinth_interactions.js";
6
6
 
7
7
  /**
8
8
  * @typedef {import('./config/types.js').ModpackInfo} ModpackInfo
9
9
  */
10
10
 
11
11
  /**
12
- * Capitalizes a string
13
- */
12
+ * Capitalizes a string
13
+ */
14
14
  function capitalize(string) {
15
15
  return `${string.charAt(0).toUpperCase()}${string.slice(1)}`;
16
16
  }
@@ -26,30 +26,30 @@ function validateNotEmpty(value, field) {
26
26
  }
27
27
 
28
28
  /**
29
- * Returns a required text prompt
30
- */
29
+ * Returns a required text prompt
30
+ */
31
31
  function requiredText(name, message, initial) {
32
32
  return {
33
- type: 'text',
33
+ type: "text",
34
34
  name: name,
35
35
  message: `${capitalize(message)}`,
36
36
  initial: initial,
37
37
  validate: (value) => {
38
38
  return validateNotEmpty(value, name);
39
- }
40
- }
39
+ },
40
+ };
41
41
  }
42
42
 
43
43
  /**
44
- * Returns an optional text prompt
45
- */
44
+ * Returns an optional text prompt
45
+ */
46
46
  function optionalText(name, message, initial) {
47
47
  return {
48
- type: 'text',
48
+ type: "text",
49
49
  name: name,
50
50
  message: `${capitalize(message)}`,
51
51
  initial: initial,
52
- }
52
+ };
53
53
  }
54
54
 
55
55
  /**
@@ -59,29 +59,22 @@ async function getOtherAnswer(value, message, initial) {
59
59
  if (value && value !== config.OTHER_OPTION.value) {
60
60
  return value;
61
61
  }
62
- const question = await prompts(
63
- requiredText(
64
- 'other',
65
- message,
66
- initial
67
- ),
68
- config.PROMPTS_OPTIONS
69
- );
62
+ const question = await prompts(requiredText("other", message, initial), config.PROMPTS_OPTIONS);
70
63
 
71
64
  return question.other || config.OTHER_OPTION.value;
72
65
  }
73
66
 
74
67
  /**
75
- * Returns a required autocomplete prompt with a fallback to the other option
76
- */
68
+ * Returns a required autocomplete prompt with a fallback to the other option
69
+ */
77
70
  function requiredAutocomplete(name, message, initial, choices, defaultValue) {
78
71
  initial = initial || defaultValue || config.OTHER_OPTION.value;
79
- if (initial && !choices.some(choice => choice.value === initial)) {
80
- choices.push({ title: initial, value: initial });
72
+ if (initial && !choices.some((choice) => choice.value === initial)) {
73
+ choices.push({title: initial, value: initial});
81
74
  }
82
75
 
83
76
  return {
84
- type: 'autocomplete',
77
+ type: "autocomplete",
85
78
  name: name,
86
79
  message: `${capitalize(message)}`,
87
80
  initial: initial,
@@ -89,20 +82,20 @@ function requiredAutocomplete(name, message, initial, choices, defaultValue) {
89
82
  fallback: config.OTHER_OPTION.value,
90
83
  format: async (value) => {
91
84
  return await getOtherAnswer(value, ` └─𜰙 Other ${message}`, initial);
92
- }
93
- }
85
+ },
86
+ };
94
87
  }
95
88
 
96
89
  /**
97
- * Returns an confirmation prompt to generate an optional file
98
- */
90
+ * Returns an confirmation prompt to generate an optional file
91
+ */
99
92
  function fileGenerationConfirm(name, message, showPrompt) {
100
93
  return {
101
- type: showPrompt ? 'confirm' : null,
94
+ type: showPrompt ? "confirm" : null,
102
95
  name: name,
103
96
  message: `${capitalize(message)}`,
104
97
  initial: true,
105
- }
98
+ };
106
99
  }
107
100
 
108
101
  /**
@@ -114,69 +107,58 @@ export async function promptUserForInfo(defaults = {}) {
114
107
  const licenseList = await getLicenseList();
115
108
  const minecraftVersions = await getMinecraftVersions();
116
109
  const modloaders = await getModloaders();
117
- let answers = await prompts([
118
- requiredText(
119
- 'name',
120
- config.infoFields.name.prompt,
121
- defaults.name
122
- ),
123
- requiredText(
124
- 'version',
125
- config.infoFields.version.prompt,
126
- defaults.version || config.DEFAULT_MODPACK_VERSION
127
- ),
128
- requiredText(
129
- 'id',
130
- config.infoFields.id.prompt,
131
- (prev, values) => slugify(defaults.id || values.name, config.SLUGIFY_OPTIONS)
132
- ),
133
- optionalText(
134
- 'description',
135
- config.infoFields.description.prompt,
136
- defaults.description
137
- ),
138
- requiredText(
139
- 'author',
140
- config.infoFields.author.prompt,
141
- defaults.author
142
- ),
143
- optionalText(
144
- 'projectUrl',
145
- config.infoFields.projectUrl.prompt,
146
- (prev, values) => defaults.projectUrl || config.DEFAULT_PROJECT_URL(values.id)
147
- ),
148
- optionalText(
149
- 'sourceUrl',
150
- config.infoFields.sourceUrl.prompt,
151
- (prev, values) => defaults.sourceUrl || config.DEFAULT_SOURCE_URL(values.id, values.author)
152
- ),
153
- requiredAutocomplete(
154
- 'license',
155
- config.infoFields.license.prompt,
156
- defaults.license,
157
- licenseList,
158
- config.DEFAULT_MODPACK_LICENSE
159
- ),
160
- requiredAutocomplete(
161
- 'modloader',
162
- config.infoFields.modloader.prompt,
163
- defaults.modloader,
164
- modloaders,
165
- config.FALLBACK_MODLOADERS[0].value
166
- ),
167
- optionalText(
168
- 'targetModloaderVersion',
169
- config.infoFields.targetModloaderVersion.prompt,
170
- defaults.targetModloaderVersion
171
- ),
172
- requiredAutocomplete(
173
- 'targetMinecraftVersion',
174
- config.infoFields.targetMinecraftVersion.prompt,
175
- defaults.targetMinecraftVersion,
176
- minecraftVersions,
177
- minecraftVersions[0].value
178
- )
179
- ], config.PROMPTS_OPTIONS);
110
+ let answers = await prompts(
111
+ [
112
+ requiredText("name", config.infoFields.name.prompt, defaults.name),
113
+ requiredText(
114
+ "version",
115
+ config.infoFields.version.prompt,
116
+ defaults.version || config.DEFAULT_MODPACK_VERSION,
117
+ ),
118
+ requiredText("id", config.infoFields.id.prompt, (prev, values) =>
119
+ slugify(defaults.id || values.name, config.SLUGIFY_OPTIONS),
120
+ ),
121
+ optionalText("description", config.infoFields.description.prompt, defaults.description),
122
+ requiredText("author", config.infoFields.author.prompt, defaults.author),
123
+ optionalText(
124
+ "projectUrl",
125
+ config.infoFields.projectUrl.prompt,
126
+ (prev, values) => defaults.projectUrl || config.DEFAULT_PROJECT_URL(values.id),
127
+ ),
128
+ optionalText(
129
+ "sourceUrl",
130
+ config.infoFields.sourceUrl.prompt,
131
+ (prev, values) => defaults.sourceUrl || config.DEFAULT_SOURCE_URL(values.id, values.author),
132
+ ),
133
+ requiredAutocomplete(
134
+ "license",
135
+ config.infoFields.license.prompt,
136
+ defaults.license,
137
+ licenseList,
138
+ config.DEFAULT_MODPACK_LICENSE,
139
+ ),
140
+ requiredAutocomplete(
141
+ "modloader",
142
+ config.infoFields.modloader.prompt,
143
+ defaults.modloader,
144
+ modloaders,
145
+ config.FALLBACK_MODLOADERS[0].value,
146
+ ),
147
+ optionalText(
148
+ "targetModloaderVersion",
149
+ config.infoFields.targetModloaderVersion.prompt,
150
+ defaults.targetModloaderVersion,
151
+ ),
152
+ requiredAutocomplete(
153
+ "targetMinecraftVersion",
154
+ config.infoFields.targetMinecraftVersion.prompt,
155
+ defaults.targetMinecraftVersion,
156
+ minecraftVersions,
157
+ minecraftVersions[0].value,
158
+ ),
159
+ ],
160
+ config.PROMPTS_OPTIONS,
161
+ );
180
162
 
181
163
  return answers;
182
164
  }
@@ -187,27 +169,30 @@ export async function promptUserForInfo(defaults = {}) {
187
169
  * @returns {Promise<Object>} The answers from the user
188
170
  */
189
171
  export async function promptUserAboutOptionalFiles(modpackInfo, defaults = {}) {
190
-
191
172
  const licenseText = await getLicenseText(modpackInfo.license);
192
- const answers = await (prompts([
193
- fileGenerationConfirm(
194
- 'addLicense',
195
- `${config.fileFields.addLicense.prompt}?`,
196
- licenseText && defaults.addLicense === undefined
197
- ),
198
- fileGenerationConfirm(
199
- 'addReadme',
200
- `${config.fileFields.addReadme.prompt}?`,
201
- defaults.addReadme === undefined
202
- ),
203
- fileGenerationConfirm(
204
- 'addGitignore',
205
- `${config.fileFields.addGitignore.prompt}?`,
206
- defaults.addGitignore === undefined
207
- ),
208
- ], config.PROMPTS_OPTIONS));
173
+ const answers = await prompts(
174
+ [
175
+ fileGenerationConfirm(
176
+ "addLicense",
177
+ `${config.fileFields.addLicense.prompt}?`,
178
+ licenseText && defaults.addLicense === undefined,
179
+ ),
180
+ fileGenerationConfirm(
181
+ "addReadme",
182
+ `${config.fileFields.addReadme.prompt}?`,
183
+ defaults.addReadme === undefined,
184
+ ),
185
+ fileGenerationConfirm(
186
+ "addGitignore",
187
+ `${config.fileFields.addGitignore.prompt}?`,
188
+ defaults.addGitignore === undefined,
189
+ ),
190
+ ],
191
+ config.PROMPTS_OPTIONS,
192
+ );
209
193
 
210
- answers.addLicense = answers.addLicense === undefined ? (licenseText ? defaults.addLicense : false) : answers.addLicense;
194
+ answers.addLicense =
195
+ answers.addLicense === undefined ? (licenseText ? defaults.addLicense : false) : answers.addLicense;
211
196
  answers.addReadme = answers.addReadme === undefined ? defaults.addReadme : answers.addReadme;
212
197
  answers.addGitignore = answers.addGitignore === undefined ? defaults.addGitignore : answers.addGitignore;
213
198
 
@@ -1,4 +1,5 @@
1
- import * as config from './config/index.js';
1
+ import * as config from "./config/index.js";
2
+ import {logm} from "./logger.js";
2
3
 
3
4
  /**
4
5
  * Split an array into chunks of specified size
@@ -21,14 +22,14 @@ export async function getVersionsFromHashes(hashes) {
21
22
 
22
23
  try {
23
24
  const response = await fetch(config.MODRINTH_VERSION_FILES_ENDPOINT, {
24
- method: 'POST',
25
+ method: "POST",
25
26
  headers: {
26
- 'Content-Type': 'application/json',
27
- 'User-Agent': config.PACKAGE_USER_AGENT,
27
+ "Content-Type": "application/json",
28
+ "User-Agent": config.PACKAGE_USER_AGENT,
28
29
  },
29
30
  body: JSON.stringify({
30
31
  hashes: hashes,
31
- algorithm: 'sha1',
32
+ algorithm: "sha1",
32
33
  }),
33
34
  });
34
35
 
@@ -39,7 +40,7 @@ export async function getVersionsFromHashes(hashes) {
39
40
 
40
41
  return await response.json();
41
42
  } catch (error) {
42
- console.error(`Error fetching version information from hashes: ${error.message}`);
43
+ logm.error(`Error fetching version information from hashes: ${error.message}`);
43
44
  throw error;
44
45
  }
45
46
  }
@@ -60,7 +61,7 @@ export async function getProjects(projectIds) {
60
61
  const url = `${config.MODRINTH_PROJECTS_ENDPOINT}?ids=${encodeURIComponent(JSON.stringify(chunk))}`;
61
62
  const response = await fetch(url, {
62
63
  headers: {
63
- 'User-Agent': config.PACKAGE_USER_AGENT,
64
+ "User-Agent": config.PACKAGE_USER_AGENT,
64
65
  },
65
66
  });
66
67
 
@@ -72,7 +73,7 @@ export async function getProjects(projectIds) {
72
73
  const data = await response.json();
73
74
  results.push(...data);
74
75
  } catch (error) {
75
- console.error(`Error fetching projects: ${error.message}`);
76
+ logm.error(`Error fetching projects: ${error.message}`);
76
77
  throw error;
77
78
  }
78
79
  }
@@ -96,7 +97,7 @@ export async function getUsers(userIds) {
96
97
  const url = `${config.MODRINTH_USERS_ENDPOINT}?ids=${encodeURIComponent(JSON.stringify(chunk))}`;
97
98
  const response = await fetch(url, {
98
99
  headers: {
99
- 'User-Agent': config.PACKAGE_USER_AGENT,
100
+ "User-Agent": config.PACKAGE_USER_AGENT,
100
101
  },
101
102
  });
102
103
 
@@ -108,7 +109,7 @@ export async function getUsers(userIds) {
108
109
  const data = await response.json();
109
110
  results.push(...data);
110
111
  } catch (error) {
111
- console.error(`Error fetching users: ${error.message}`);
112
+ logm.error(`Error fetching users: ${error.message}`);
112
113
  throw error;
113
114
  }
114
115
  }
@@ -125,7 +126,7 @@ export async function getMinecraftVersions() {
125
126
  const url = config.MODRINTH_MINECRAFT_VERSIONS_ENDPOINT;
126
127
  const response = await fetch(url, {
127
128
  headers: {
128
- 'User-Agent': config.PACKAGE_USER_AGENT,
129
+ "User-Agent": config.PACKAGE_USER_AGENT,
129
130
  },
130
131
  });
131
132
  if (!response.ok) {
@@ -137,15 +138,18 @@ export async function getMinecraftVersions() {
137
138
  if (json) {
138
139
  //sort by version type (in the order of the MINECRAFT_VERSION_TYPES array)
139
140
  json.sort((a, b) => {
140
- return config.MINECRAFT_VERSION_TYPES.indexOf(a.version_type) - config.MINECRAFT_VERSION_TYPES.indexOf(b.version_type);
141
+ return (
142
+ config.MINECRAFT_VERSION_TYPES.indexOf(a.version_type) -
143
+ config.MINECRAFT_VERSION_TYPES.indexOf(b.version_type)
144
+ );
141
145
  });
142
- return json.map(version => ({ title: version.version, value: version.version }));
146
+ return json.map((version) => ({title: version.version, value: version.version}));
143
147
  } else {
144
148
  throw new Error();
145
149
  }
146
150
  return null;
147
151
  } catch (error) {
148
- console.warn(`Warning: could not fetch Minecraft versions. Using fallbacks.`, error);
152
+ logm.warn(`Could not fetch Minecraft versions. Using fallbacks.`, error);
149
153
  return config.FALLBACK_TARGET_MINECRAFT_VERSIONS;
150
154
  }
151
155
  }
@@ -159,7 +163,7 @@ export async function getModloaders() {
159
163
  const url = config.MODRINTH_MODLOADERS_ENDPOINT;
160
164
  const response = await fetch(url, {
161
165
  headers: {
162
- 'User-Agent': config.PACKAGE_USER_AGENT,
166
+ "User-Agent": config.PACKAGE_USER_AGENT,
163
167
  },
164
168
  });
165
169
  if (!response.ok) {
@@ -169,13 +173,13 @@ export async function getModloaders() {
169
173
 
170
174
  const json = await response.json();
171
175
  if (json) {
172
- return json.map(loader => ({ title: loader.name, value: loader.name }));
176
+ return json.map((loader) => ({title: loader.name, value: loader.name}));
173
177
  } else {
174
178
  throw new Error();
175
179
  }
176
180
  return null;
177
181
  } catch (error) {
178
- console.warn(`Warning: could not fetch Modloaders. Using fallbacks.`, error);
182
+ logm.warn(`Could not fetch Modloaders. Using fallbacks.`, error);
179
183
  return config.FALLBACK_MODLOADERS;
180
184
  }
181
185
  }