modpack-lock 0.6.0 → 0.6.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "modpack-lock",
3
- "version": "0.6.0",
3
+ "version": "0.6.2",
4
4
  "description": "Creates a modpack lockfile for files hosted on Modrinth (mods, resource packs, shaders and datapacks)",
5
5
  "bugs": {
6
6
  "url": "https://github.com/nickesc/modpack-lock/issues"
@@ -39,13 +39,16 @@
39
39
  "src/**/*.js"
40
40
  ],
41
41
  "dependencies": {
42
- "commander": "^14.0.2",
42
+ "commander": "^14.0.3",
43
43
  "prompts": "^2.4.2",
44
44
  "slugify": "^1.6.6"
45
45
  },
46
46
  "devDependencies": {
47
- "@vitest/coverage-v8": "^4.0.16",
48
- "typedoc": "^0.28.16",
47
+ "@eslint/js": "^10.0.1",
48
+ "@vitest/coverage-v8": "^4.0.18",
49
+ "eslint": "^10.0.0",
50
+ "globals": "^17.3.0",
51
+ "typedoc": "^0.28.17",
49
52
  "typedoc-github-theme": "^0.3.1",
50
53
  "unzipper": "^0.12.3",
51
54
  "vitest": "^4.0.16"
package/src/cli.js CHANGED
@@ -68,7 +68,9 @@ modpackLock
68
68
  } else {
69
69
  // Warn if license option is passed but no modpack.json exists
70
70
  if (options.licenseFile) {
71
- logm.warn(`License generation requires a ${config.MODPACK_JSON_NAME} file. Skipping license generation.`);
71
+ logm.warn(
72
+ `License generation requires a ${config.MODPACK_JSON_NAME} file. Skipping license generation.`,
73
+ );
72
74
  }
73
75
 
74
76
  // Generate lockfile
@@ -98,7 +100,9 @@ modpackLock
98
100
 
99
101
  modpackLock
100
102
  .command("init")
101
- .description(`Initialize a modpack with a ${config.MODPACK_JSON_NAME} file and a ${config.MODPACK_LOCKFILE_NAME} lockfile.`)
103
+ .description(
104
+ `Initialize a modpack with a ${config.MODPACK_JSON_NAME} file and a ${config.MODPACK_LOCKFILE_NAME} lockfile.`,
105
+ )
102
106
  .optionsGroup(config.headings.options)
103
107
  .option("-f, --folder <path>", "Path to the modpack directory")
104
108
  .option("-n, --noninteractive", "Non-interactive mode - must provide options for required fields")
@@ -169,16 +173,28 @@ modpackLock
169
173
  } else {
170
174
  logm.info(logm.label("modpack-lock"), styleText(["bold", "italic", "blueBright"], "init"));
171
175
  logm.newline();
172
- logm.info(styleText(["dim"], "This utility will walk you through creating a"),
173
- config.MODPACK_JSON_NAME,
176
+ logm.info(
177
+ styleText(["dim"], "This utility will walk you through creating a"),
178
+ config.MODPACK_JSON_NAME,
174
179
  styleText(["dim"], "file and a"),
175
180
  config.MODPACK_LOCKFILE_NAME,
176
- styleText(["dim"], "lockfile. It only covers the most common items, and tries to guess sensible defaults."),
181
+ styleText(
182
+ ["dim"],
183
+ "lockfile. It only covers the most common items, and tries to guess sensible defaults.",
184
+ ),
177
185
  );
178
186
  logm.newline();
179
- logm.info(styleText(["dim"], "See"), styleText(["white", "bgGray", "italic"], "modpack-lock init --help"), styleText(["dim"], "for definitive documentation on these fields and exactly what they do."));
187
+ logm.info(
188
+ styleText(["dim"], "See"),
189
+ styleText(["white", "bgGray", "italic"], "modpack-lock init --help"),
190
+ styleText(["dim"], "for definitive documentation on these fields and exactly what they do."),
191
+ );
180
192
  logm.newline();
181
- logm.info(styleText(["dim"], "Press"), styleText(["yellow"], "^C"), styleText(["dim"], "at any time to quit."));
193
+ logm.info(
194
+ styleText(["dim"], "Press"),
195
+ styleText(["yellow"], "^C"),
196
+ styleText(["dim"], "at any time to quit."),
197
+ );
182
198
  logm.newline();
183
199
  try {
184
200
  const defaults = {
@@ -194,9 +210,13 @@ modpackLock
194
210
  targetModloaderVersion: undefined,
195
211
  targetMinecraftVersion: undefined,
196
212
  };
213
+ const mergedDefaults = mergeModpackInfo(existingInfo, options, defaults);
197
214
 
198
215
  // prompt user for modpack information
199
- const modpackInfo = await promptUserForInfo(mergeModpackInfo(existingInfo, options, defaults));
216
+ const userAnswers = await promptUserForInfo(mergedDefaults);
217
+
218
+ // Preserve extra fields (e.g. scripts) from existing modpack.json
219
+ const modpackInfo = {...mergedDefaults, ...userAnswers};
200
220
 
201
221
  // prompt user if they want to add the license text
202
222
  const optionalFiles = await promptUserAboutOptionalFiles(modpackInfo, options);
@@ -92,7 +92,7 @@ async function getJsonFile(directoryPath, filename) {
92
92
  return JSON.parse(fileContent);
93
93
  } catch (error) {
94
94
  if (error.code !== "ENOENT") {
95
- throw new Error(`Error: Could not read file ${jsonPath}: ${error.message}`);
95
+ throw new Error(`Error: Could not read file ${jsonPath}: ${error.message}`, {cause: error});
96
96
  } else {
97
97
  return null;
98
98
  }
@@ -1,7 +1,7 @@
1
1
  import fs from "fs/promises";
2
2
  import path from "path";
3
3
  import * as config from "./config/index.js";
4
- import {logm, styleText} from "./logger.js";
4
+ import {logm} from "./logger.js";
5
5
 
6
6
  /**
7
7
  * @typedef {import('./config/types.js').Options} Options
@@ -28,7 +28,7 @@ export async function generateGitignoreRules(lockfile, workingDir, options = {})
28
28
  rules.push(`*/**/*.disabled`);
29
29
 
30
30
  // Find files not hosted on Modrinth
31
- for (const [category, entries] of Object.entries(lockfile.dependencies)) {
31
+ for (const [, entries] of Object.entries(lockfile.dependencies)) {
32
32
  for (const entry of entries) {
33
33
  if (entry.version === null) {
34
34
  exceptions.push(`!${entry.path}`);
@@ -61,7 +61,7 @@ export async function generateGitignoreRules(lockfile, workingDir, options = {})
61
61
  const startMarkerIndex = existingContent.indexOf(config.GITIGNORE_START_MARKER);
62
62
  const endMarkerIndex = existingContent.indexOf(config.GITIGNORE_END_MARKER);
63
63
 
64
- let newContent = "";
64
+ let newContent;
65
65
 
66
66
  if (startMarkerIndex !== -1 && endMarkerIndex !== -1 && endMarkerIndex > startMarkerIndex) {
67
67
  // Both markers exist, replace content between them
@@ -47,7 +47,7 @@ export default async function generateLicense(modpackInfo, workingDir, options =
47
47
  await writeLicense(licenseText, workingDir);
48
48
  }
49
49
  return licenseText;
50
- } catch (error) {
50
+ } catch {
51
51
  logm.warn(`Unable to generate license for: ${modpackInfo.license}`);
52
52
  return null;
53
53
  }
@@ -35,11 +35,11 @@ function generateCategoryReadme(category, entries, projectsMap, usersMap) {
35
35
 
36
36
  for (const entry of entries) {
37
37
  const version = entry.version;
38
- let nameCell = "";
39
- let authorCell = "";
40
- let versionCell = "";
41
- let dependenciesCell = "";
42
- let dependantsCell = "";
38
+ let nameCell;
39
+ let authorCell;
40
+ let versionCell;
41
+ let dependenciesCell;
42
+ let dependantsCell;
43
43
 
44
44
  if (version && version.project_id) {
45
45
  const project = projectsMap[version.project_id];
@@ -162,7 +162,7 @@ export async function generateReadmeFiles(lockfile, workingDir, options = {}) {
162
162
  const projectIds = new Set();
163
163
  const authorIds = new Set();
164
164
 
165
- for (const [category, entries] of Object.entries(lockfile.dependencies)) {
165
+ for (const [, entries] of Object.entries(lockfile.dependencies)) {
166
166
  for (const entry of entries) {
167
167
  if (entry.version && entry.version.project_id) {
168
168
  projectIds.add(entry.version.project_id);
@@ -35,7 +35,7 @@ export async function getLicenseList(featured = false) {
35
35
  }
36
36
 
37
37
  return licenseSpdxIds;
38
- } catch (error) {
38
+ } catch {
39
39
  logm.warn(`Could not fetch license list. Using fallbacks.`);
40
40
  const licenses = config.FALLBACK_LICENSES.push(config.ALL_RIGHTS_RESERVED_LICENSE);
41
41
  licenses.push(config.OTHER_OPTION);
@@ -71,8 +71,7 @@ export async function getLicenseText(spdxId) {
71
71
  } else {
72
72
  throw new Error();
73
73
  }
74
- return null;
75
- } catch (error) {
74
+ } catch {
76
75
  logm.warn(`Could not find license text for: ${spdxId}`);
77
76
  return null;
78
77
  }
@@ -147,9 +147,8 @@ export async function getMinecraftVersions() {
147
147
  } else {
148
148
  throw new Error();
149
149
  }
150
- return null;
151
- } catch (error) {
152
- logm.warn(`Could not fetch Minecraft versions. Using fallbacks.`, error);
150
+ } catch {
151
+ logm.warn(`Could not fetch Minecraft versions. Using fallbacks.`);
153
152
  return config.FALLBACK_TARGET_MINECRAFT_VERSIONS;
154
153
  }
155
154
  }
@@ -177,9 +176,8 @@ export async function getModloaders() {
177
176
  } else {
178
177
  throw new Error();
179
178
  }
180
- return null;
181
- } catch (error) {
182
- logm.warn(`Could not fetch Modloaders. Using fallbacks.`, error);
179
+ } catch {
180
+ logm.warn(`Could not fetch Modloaders. Using fallbacks.`);
183
181
  return config.FALLBACK_MODLOADERS;
184
182
  }
185
183
  }