modpack-lock 0.3.1 → 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 +1 -1
- package/src/cli.js +46 -27
- package/src/config/defaults.js +8 -0
- package/src/config/index.js +1 -0
- package/src/modpack_info.js +38 -39
package/package.json
CHANGED
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,20 +124,23 @@ modpackLock.command('init')
|
|
|
112
124
|
process.exitCode = 1;
|
|
113
125
|
return;
|
|
114
126
|
} else {
|
|
115
|
-
const
|
|
116
|
-
const
|
|
117
|
-
name:
|
|
118
|
-
version:
|
|
119
|
-
id:
|
|
120
|
-
description:
|
|
121
|
-
author: options.author,
|
|
122
|
-
projectUrl:
|
|
123
|
-
sourceUrl:
|
|
124
|
-
license:
|
|
125
|
-
modloader: options.modloader,
|
|
126
|
-
targetModloaderVersion:
|
|
127
|
-
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
|
|
128
140
|
};
|
|
141
|
+
|
|
142
|
+
const modpackInfo = mergeModpackInfo(existingInfo, options, defaults);
|
|
143
|
+
modpackInfo.id = slugify(modpackInfo.id, config.SLUGIFY_OPTIONS);
|
|
129
144
|
try {
|
|
130
145
|
await generateModpackFiles(modpackInfo, currDir, { dryRun: false });
|
|
131
146
|
} catch (error) {
|
|
@@ -138,19 +153,23 @@ modpackLock.command('init')
|
|
|
138
153
|
console.log("\nSee `modpack-lock init --help` for definitive documentation on these fields and exactly what they do.\n");
|
|
139
154
|
console.log("Press ^C at any time to quit.\n");
|
|
140
155
|
try {
|
|
141
|
-
const
|
|
142
|
-
name:
|
|
143
|
-
version:
|
|
144
|
-
id:
|
|
145
|
-
description:
|
|
146
|
-
author:
|
|
147
|
-
projectUrl:
|
|
148
|
-
sourceUrl:
|
|
149
|
-
license:
|
|
150
|
-
modloader:
|
|
151
|
-
targetModloaderVersion:
|
|
152
|
-
targetMinecraftVersion:
|
|
153
|
-
}
|
|
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
|
+
);
|
|
154
173
|
|
|
155
174
|
await generateModpackFiles(modpackInfo, currDir, { dryRun: false });
|
|
156
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
|
+
};
|
package/src/config/index.js
CHANGED
package/src/modpack_info.js
CHANGED
|
@@ -33,64 +33,63 @@ export default async function promptUserForInfo(defaults = {}) {
|
|
|
33
33
|
return validateNotEmpty(value, 'Name');
|
|
34
34
|
},
|
|
35
35
|
});
|
|
36
|
-
let
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
return validateNotEmpty(value, 'Version');
|
|
44
|
-
},
|
|
45
|
-
},
|
|
46
|
-
|
|
47
|
-
{
|
|
48
|
-
type: 'text',
|
|
49
|
-
name: 'id',
|
|
50
|
-
message: 'Modpack slug/ID',
|
|
51
|
-
initial: slugify(defaults.id || name.name, config.SLUGIFY_OPTIONS),
|
|
52
|
-
validate: (value) => {
|
|
53
|
-
return validateNotEmpty(value, 'ID');
|
|
54
|
-
},
|
|
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');
|
|
55
43
|
},
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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');
|
|
61
52
|
},
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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 ||
|
|
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 ||
|
|
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 ||
|
|
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
|
|
92
|
+
initial: defaults.modloader,
|
|
94
93
|
choices: [
|
|
95
94
|
{ title: 'fabric' },
|
|
96
95
|
{ title: 'forge' },
|
|
@@ -114,20 +113,20 @@ export default async function promptUserForInfo(defaults = {}) {
|
|
|
114
113
|
type: 'text',
|
|
115
114
|
name: 'targetModloaderVersion',
|
|
116
115
|
message: 'Target modloader version',
|
|
117
|
-
initial: defaults.targetModloaderVersion
|
|
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
|
|
122
|
+
initial: defaults.targetMinecraftVersion,
|
|
124
123
|
validate: (value) => {
|
|
125
124
|
return validateNotEmpty(value, 'Minecraft Version');
|
|
126
125
|
},
|
|
127
126
|
}
|
|
128
127
|
]);
|
|
129
128
|
|
|
130
|
-
let modpackInfo = {...name, ...answers};
|
|
129
|
+
let modpackInfo = {...name, ...version, ...id, ...description, ...author, ...answers};
|
|
131
130
|
if (Object.keys(modpackInfo).length < 11) {
|
|
132
131
|
console.warn('Modpack initialization was interrupted');
|
|
133
132
|
process.exit(1);
|