modpack-lock 0.3.0 → 0.3.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.3.0",
3
+ "version": "0.3.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"
package/src/cli.js CHANGED
@@ -4,7 +4,6 @@ import { Command } from 'commander';
4
4
  import path from 'path';
5
5
  import slugify from 'slugify';
6
6
  import {generateLockfile} from './generate_lockfile.js';
7
- import generateJson from './generate_json.js';
8
7
  import { generateModpackFiles } from './modpack-lock.js';
9
8
  import promptUserForInfo from './modpack_info.js';
10
9
  import { getModpackInfo } from './directory_scanning.js';
@@ -43,6 +42,17 @@ function restoreConsole() {
43
42
  console.error = originalLogs.error;
44
43
  }
45
44
 
45
+ /**
46
+ * Merge modpack info with priority: options > existingInfo > defaults
47
+ */
48
+ function mergeModpackInfo(existingInfo, options, defaults) {
49
+ const result = {};
50
+ for (const [key, defaultValue] of Object.entries(defaults)) {
51
+ result[key] = options[key] || existingInfo?.[key] || defaultValue;
52
+ }
53
+ return result;
54
+ }
55
+
46
56
  modpackLock
47
57
  .name(pkg.name)
48
58
  .description(pkg.description)
@@ -105,6 +115,8 @@ modpackLock.command('init')
105
115
  .action(async (options) => {
106
116
  const currDir = options.folder || process.cwd();
107
117
 
118
+ let existingInfo = await getModpackInfo(currDir);
119
+
108
120
  if (options.noninteractive) {
109
121
  quietConsole();
110
122
  if (!options.author || !options.modloader || !options.targetMinecraftVersion) {
@@ -112,19 +124,23 @@ modpackLock.command('init')
112
124
  process.exitCode = 1;
113
125
  return;
114
126
  } else {
115
- const modpackInfo = {
116
- name: options.name || path.basename(currDir),
117
- version: options.version || '1.0.0',
118
- id: slugify(options.id || options.name || path.basename(currDir), config.SLUGIFY_OPTIONS),
119
- description: options.description || '',
120
- author: options.author,
121
- projectUrl: options.projectUrl || '',
122
- sourceUrl: options.sourceUrl || '',
123
- license: options.license || '',
124
- modloader: options.modloader,
125
- targetModloaderVersion: options.targetModloaderVersion || '',
126
- targetMinecraftVersion: options.targetMinecraftVersion,
127
+ const defaultName = path.basename(currDir);
128
+ const defaults = {
129
+ name: defaultName,
130
+ version: config.DEFAULT_MODPACK_VERSION,
131
+ id: defaultName,
132
+ description: '',
133
+ author: options.author, // Required, no default
134
+ projectUrl: '',
135
+ sourceUrl: '',
136
+ license: '',
137
+ modloader: options.modloader, // Required, no default
138
+ targetModloaderVersion: '',
139
+ targetMinecraftVersion: options.targetMinecraftVersion, // Required, no default
127
140
  };
141
+
142
+ const modpackInfo = mergeModpackInfo(existingInfo, options, defaults);
143
+ modpackInfo.id = slugify(modpackInfo.id, config.SLUGIFY_OPTIONS);
128
144
  try {
129
145
  await generateModpackFiles(modpackInfo, currDir, { dryRun: false });
130
146
  } catch (error) {
@@ -137,19 +153,23 @@ modpackLock.command('init')
137
153
  console.log("\nSee `modpack-lock init --help` for definitive documentation on these fields and exactly what they do.\n");
138
154
  console.log("Press ^C at any time to quit.\n");
139
155
  try {
140
- const modpackInfo = await promptUserForInfo({
141
- name: options.name || path.basename(currDir),
142
- version: options.version,
143
- id: options.id,
144
- description: options.description,
145
- author: options.author,
146
- projectUrl: options.projectUrl,
147
- sourceUrl: options.sourceUrl,
148
- license: options.license,
149
- modloader: options.modloader,
150
- targetModloaderVersion: options.targetModloaderVersion,
151
- targetMinecraftVersion: options.targetMinecraftVersion,
152
- });
156
+ const defaults = {
157
+ name: path.basename(currDir),
158
+ version: config.DEFAULT_MODPACK_VERSION,
159
+ id: undefined,
160
+ description: undefined,
161
+ author: undefined,
162
+ projectUrl: undefined,
163
+ sourceUrl: undefined,
164
+ license: config.DEFAULT_MODPACK_LICENSE,
165
+ modloader: undefined,
166
+ targetModloaderVersion: undefined,
167
+ targetMinecraftVersion: undefined,
168
+ };
169
+
170
+ const modpackInfo = await promptUserForInfo(
171
+ mergeModpackInfo(existingInfo, options, defaults)
172
+ );
153
173
 
154
174
  await generateModpackFiles(modpackInfo, currDir, { dryRun: false });
155
175
  } catch (error) {
@@ -0,0 +1,8 @@
1
+ export const DEFAULT_MODPACK_VERSION = '1.0.0';
2
+ export const DEFAULT_MODPACK_LICENSE = 'MIT';
3
+ export const DEFAULT_PROJECT_URL = (id) => {
4
+ return `https://modrinth.com/modpack/${id}`;
5
+ };
6
+ export const DEFAULT_SOURCE_URL = (id, author) => {
7
+ return `https://github.com/${author}/${id}`;
8
+ };
@@ -2,3 +2,4 @@ export * from './constants.js';
2
2
  export * from './api.js';
3
3
  export * from './files.js';
4
4
  export * from './options.js';
5
+ export * from './defaults.js';
@@ -24,73 +24,72 @@ function validateNotEmpty(value, field) {
24
24
  * @returns {Promise<ModpackInfo>} The modpack information from the user
25
25
  */
26
26
  export default async function promptUserForInfo(defaults = {}) {
27
- let answers = await prompts([
28
- {
29
- type: 'text',
30
- name: 'name',
31
- message: 'Modpack name',
32
- initial: defaults.name,
33
- validate: (value) => {
34
- return validateNotEmpty(value, 'Name');
35
- },
27
+ let name = await prompts({
28
+ type: 'text',
29
+ name: 'name',
30
+ message: 'Modpack name',
31
+ initial: defaults.name,
32
+ validate: (value) => {
33
+ return validateNotEmpty(value, 'Name');
36
34
  },
37
- {
38
- type: 'text',
39
- name: 'version',
40
- message: 'Modpack version',
41
- initial: defaults.version || '1.0.0',
42
- validate: (value) => {
43
- return validateNotEmpty(value, 'Version');
44
- },
35
+ });
36
+ let version = await prompts({
37
+ type: 'text',
38
+ name: 'version',
39
+ message: 'Modpack version',
40
+ initial: defaults.version || config.DEFAULT_MODPACK_VERSION,
41
+ validate: (value) => {
42
+ return validateNotEmpty(value, 'Version');
45
43
  },
46
-
47
- {
48
- type: 'text',
49
- name: 'id',
50
- message: 'Modpack slug/ID',
51
- initial: slugify(defaults.id || defaults.name, config.SLUGIFY_OPTIONS),
52
- validate: (value) => {
53
- return validateNotEmpty(value, 'ID');
54
- },
44
+ });
45
+ let id = await prompts({
46
+ type: 'text',
47
+ name: 'id',
48
+ message: 'Modpack slug/ID',
49
+ initial: slugify(defaults.id || name.name, config.SLUGIFY_OPTIONS),
50
+ validate: (value) => {
51
+ return validateNotEmpty(value, 'ID');
55
52
  },
56
- {
57
- type: 'text',
58
- name: 'description',
59
- message: 'Modpack description',
60
- initial: defaults.description || undefined,
61
- },
62
- {
63
- type: 'text',
64
- name: 'author',
65
- message: 'Modpack author',
66
- initial: defaults.author || undefined,
67
- validate: (value) => {
68
- return validateNotEmpty(value, 'Author');
69
- },
53
+ });
54
+ let description = await prompts({
55
+ type: 'text',
56
+ name: 'description',
57
+ message: 'Modpack description',
58
+ initial: defaults.description,
59
+ });
60
+ let author = await prompts({
61
+ type: 'text',
62
+ name: 'author',
63
+ message: 'Modpack author',
64
+ initial: defaults.author,
65
+ validate: (value) => {
66
+ return validateNotEmpty(value, 'Author');
70
67
  },
68
+ });
69
+ let answers = await prompts([
71
70
  {
72
71
  type: 'text',
73
72
  name: 'projectUrl',
74
73
  message: 'Modpack URL',
75
- initial: defaults.projectUrl || undefined,
74
+ initial: defaults.projectUrl || config.DEFAULT_PROJECT_URL(id.id),
76
75
  },
77
76
  {
78
77
  type: 'text',
79
78
  name: 'sourceUrl',
80
79
  message: 'Modpack source code URL',
81
- initial: defaults.sourceUrl || undefined,
80
+ initial: defaults.sourceUrl || config.DEFAULT_SOURCE_URL(id.id, author.author),
82
81
  },
83
82
  {
84
83
  type: 'text',
85
84
  name: 'license',
86
85
  message: 'Modpack license',
87
- initial: defaults.license || undefined,
86
+ initial: defaults.license || config.DEFAULT_MODPACK_LICENSE,
88
87
  },
89
88
  {
90
89
  type: 'autocomplete',
91
90
  name: 'modloader',
92
91
  message: 'Modpack modloader',
93
- initial: defaults.modloader || undefined,
92
+ initial: defaults.modloader,
94
93
  choices: [
95
94
  { title: 'fabric' },
96
95
  { title: 'forge' },
@@ -114,21 +113,23 @@ export default async function promptUserForInfo(defaults = {}) {
114
113
  type: 'text',
115
114
  name: 'targetModloaderVersion',
116
115
  message: 'Target modloader version',
117
- initial: defaults.targetModloaderVersion || undefined,
116
+ initial: defaults.targetModloaderVersion,
118
117
  },
119
118
  {
120
119
  type: 'text',
121
120
  name: 'targetMinecraftVersion',
122
121
  message: 'Target Minecraft version',
123
- initial: defaults.targetMinecraftVersion || undefined,
122
+ initial: defaults.targetMinecraftVersion,
124
123
  validate: (value) => {
125
124
  return validateNotEmpty(value, 'Minecraft Version');
126
125
  },
127
126
  }
128
127
  ]);
129
- if (Object.keys(answers).length < 11) {
128
+
129
+ let modpackInfo = {...name, ...version, ...id, ...description, ...author, ...answers};
130
+ if (Object.keys(modpackInfo).length < 11) {
130
131
  console.warn('Modpack initialization was interrupted');
131
132
  process.exit(1);
132
133
  }
133
- return answers;
134
+ return modpackInfo;
134
135
  }