modpack-lock 0.5.0 → 0.6.0
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/README.md +2 -2
- package/package.json +2 -2
- package/src/cli.js +121 -120
- package/src/config/api.js +11 -2
- package/src/config/constants.js +13 -10
- package/src/config/defaults.js +42 -42
- package/src/config/index.js +6 -6
- package/src/config/options.js +7 -5
- package/src/config/strings.js +38 -41
- package/src/config/types.js +3 -2
- package/src/directory_scanning.js +15 -14
- package/src/generate_gitignore.js +113 -0
- package/src/generate_json.js +40 -39
- package/src/generate_license.js +25 -21
- package/src/generate_lockfile.js +68 -298
- package/src/generate_readme.js +224 -0
- package/src/github_interactions.js +21 -15
- package/src/logger.js +178 -0
- package/src/modpack-lock.js +47 -11
- package/src/modpack_info.js +102 -117
- package/src/modrinth_interactions.js +37 -16
package/src/config/strings.js
CHANGED
|
@@ -1,85 +1,82 @@
|
|
|
1
|
-
import * as defaults from
|
|
2
|
-
import
|
|
1
|
+
import * as defaults from "./defaults.js";
|
|
2
|
+
import * as files from "./files.js";
|
|
3
|
+
import pkg from "../../package.json" with {type: "json"};
|
|
3
4
|
|
|
4
5
|
export const infoFields = {
|
|
5
6
|
name: {
|
|
6
|
-
prompt:
|
|
7
|
-
option:
|
|
7
|
+
prompt: "modpack name",
|
|
8
|
+
option: "Modpack name; defaults to the directory name",
|
|
8
9
|
},
|
|
9
10
|
version: {
|
|
10
|
-
prompt:
|
|
11
|
-
option: `Modpack version; defaults to ${defaults.DEFAULT_MODPACK_VERSION}
|
|
11
|
+
prompt: "modpack version",
|
|
12
|
+
option: `Modpack version; defaults to ${defaults.DEFAULT_MODPACK_VERSION}`,
|
|
12
13
|
},
|
|
13
14
|
id: {
|
|
14
|
-
prompt:
|
|
15
|
-
option:
|
|
15
|
+
prompt: "modpack slug/ID",
|
|
16
|
+
option: "Modpack slug/ID; defaults to the directory name slugified",
|
|
16
17
|
},
|
|
17
18
|
description: {
|
|
18
|
-
prompt:
|
|
19
|
-
option:
|
|
19
|
+
prompt: "modpack description",
|
|
20
|
+
option: "Modpack description",
|
|
20
21
|
},
|
|
21
22
|
author: {
|
|
22
|
-
prompt:
|
|
23
|
-
option:
|
|
23
|
+
prompt: "modpack author",
|
|
24
|
+
option: "Modpack author; required",
|
|
24
25
|
},
|
|
25
26
|
projectUrl: {
|
|
26
|
-
prompt:
|
|
27
|
-
option:
|
|
27
|
+
prompt: "modpack URL",
|
|
28
|
+
option: "Modpack URL; defaults to a guessed Modrinth project URL",
|
|
28
29
|
},
|
|
29
30
|
sourceUrl: {
|
|
30
|
-
prompt:
|
|
31
|
-
option:
|
|
31
|
+
prompt: "modpack source code URL",
|
|
32
|
+
option: "Modpack source code URL; defaults to a guessed GitHub repository URL",
|
|
32
33
|
},
|
|
33
34
|
license: {
|
|
34
|
-
prompt:
|
|
35
|
-
option: `Modpack license, popular licenses fetched from GitHub; defaults to ${defaults.DEFAULT_MODPACK_LICENSE} in interactive mode
|
|
35
|
+
prompt: "modpack license",
|
|
36
|
+
option: `Modpack license, popular licenses fetched from GitHub; defaults to ${defaults.DEFAULT_MODPACK_LICENSE} in interactive mode`,
|
|
36
37
|
},
|
|
37
38
|
modloader: {
|
|
38
|
-
prompt:
|
|
39
|
-
option:
|
|
39
|
+
prompt: "modpack modloader",
|
|
40
|
+
option: "Modpack modloader, list of loaders fetched from Modrinth; required",
|
|
40
41
|
},
|
|
41
42
|
targetModloaderVersion: {
|
|
42
|
-
prompt:
|
|
43
|
-
option:
|
|
43
|
+
prompt: "target modloader version",
|
|
44
|
+
option: "Target modloader version",
|
|
44
45
|
},
|
|
45
46
|
targetMinecraftVersion: {
|
|
46
|
-
prompt:
|
|
47
|
-
option:
|
|
48
|
-
}
|
|
49
|
-
}
|
|
47
|
+
prompt: "target Minecraft version",
|
|
48
|
+
option: "Target Minecraft version, list of versions fetched from Modrinth; required",
|
|
49
|
+
},
|
|
50
|
+
};
|
|
50
51
|
|
|
51
52
|
export const fileFields = {
|
|
52
53
|
addLicense: {
|
|
53
|
-
prompt:
|
|
54
|
-
option:
|
|
54
|
+
prompt: `Add the ${files.MODPACK_LICENSE_NAME} file`,
|
|
55
|
+
option: `Add the ${files.MODPACK_LICENSE_NAME} file to the modpack`,
|
|
55
56
|
},
|
|
56
57
|
addGitignore: {
|
|
57
|
-
prompt:
|
|
58
|
-
option:
|
|
58
|
+
prompt: `Update the ${files.GITIGNORE_NAME} file`,
|
|
59
|
+
option: `Update the ${files.GITIGNORE_NAME} file to ignore content hosted on Modrinth`,
|
|
59
60
|
},
|
|
60
61
|
addReadme: {
|
|
61
|
-
prompt:
|
|
62
|
-
option:
|
|
63
|
-
}
|
|
64
|
-
}
|
|
62
|
+
prompt: `Generate ${files.README_NAME} files`,
|
|
63
|
+
option: `Generate ${files.README_NAME} files for each category`,
|
|
64
|
+
},
|
|
65
|
+
};
|
|
65
66
|
|
|
66
67
|
export const headings = {
|
|
67
68
|
options: "Options:",
|
|
68
69
|
generation: "GENERATION",
|
|
69
70
|
logging: "LOGGING",
|
|
70
71
|
packInfo: "MODPACK INFORMATION",
|
|
71
|
-
information: "INFORMATION"
|
|
72
|
+
information: "INFORMATION",
|
|
72
73
|
};
|
|
73
74
|
|
|
74
75
|
export const dryRunText = (filename, location) => {
|
|
75
76
|
return `[DRY RUN] Would write ${filename} to: ${location}`;
|
|
76
|
-
}
|
|
77
|
+
};
|
|
77
78
|
|
|
78
79
|
/** All-Rights-Reserved license text */
|
|
79
|
-
export const ARR_LICENSE_TEXT =
|
|
80
|
-
"Copyright (c) [year] [fullname]\n" +
|
|
81
|
-
"\n" +
|
|
82
|
-
"All rights reserved.\n";
|
|
83
|
-
|
|
80
|
+
export const ARR_LICENSE_TEXT = "Copyright (c) [year] [fullname]\n" + "\n" + "All rights reserved.\n";
|
|
84
81
|
|
|
85
82
|
export {pkg};
|
package/src/config/types.js
CHANGED
|
@@ -40,6 +40,7 @@
|
|
|
40
40
|
* @property {boolean} silent - Whether to silent the console output
|
|
41
41
|
* @property {boolean} gitignore - Whether to generate a .gitignore file
|
|
42
42
|
* @property {boolean} readme - Whether to generate README.md files
|
|
43
|
+
* @property {boolean} licenseFile - Whether to generate a license file
|
|
43
44
|
*/
|
|
44
45
|
|
|
45
46
|
/**
|
|
@@ -48,8 +49,8 @@
|
|
|
48
49
|
* @property {string} folder - The folder to generate the modpack files in
|
|
49
50
|
* @property {boolean} noninteractive - Whether to run the interactive mode
|
|
50
51
|
* @property {boolean} addLicense - Whether to add the license file to the modpack
|
|
51
|
-
* @property {boolean}
|
|
52
|
-
* @property {boolean}
|
|
52
|
+
* @property {boolean} addGitignore - Whether to generate .gitignore rules
|
|
53
|
+
* @property {boolean} addReadme - Whether to generate README.md files
|
|
53
54
|
* @property {string} name - The name of the modpack
|
|
54
55
|
* @property {string} version - The version of the modpack
|
|
55
56
|
* @property {string} id - The slug/ID of the modpack
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import fs from
|
|
2
|
-
import crypto from
|
|
3
|
-
import path from
|
|
4
|
-
import * as config from
|
|
1
|
+
import fs from "fs/promises";
|
|
2
|
+
import crypto from "crypto";
|
|
3
|
+
import path from "path";
|
|
4
|
+
import * as config from "./config/index.js";
|
|
5
|
+
import {logm} from "./logger.js";
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* @typedef {import('./config/types.js').ModpackInfo} ModpackInfo
|
|
@@ -16,7 +17,7 @@ import * as config from './config/index.js';
|
|
|
16
17
|
export function getScanDirectories(directoryPath) {
|
|
17
18
|
const scanDirectories = [];
|
|
18
19
|
for (const category of config.DEPENDENCY_CATEGORIES) {
|
|
19
|
-
scanDirectories.push({
|
|
20
|
+
scanDirectories.push({name: category, path: path.join(directoryPath, category)});
|
|
20
21
|
}
|
|
21
22
|
return scanDirectories;
|
|
22
23
|
}
|
|
@@ -26,7 +27,7 @@ export function getScanDirectories(directoryPath) {
|
|
|
26
27
|
*/
|
|
27
28
|
async function calculateSHA1(filePath) {
|
|
28
29
|
const fileBuffer = await fs.readFile(filePath);
|
|
29
|
-
return crypto.createHash(
|
|
30
|
+
return crypto.createHash("sha1").update(fileBuffer).digest("hex");
|
|
30
31
|
}
|
|
31
32
|
|
|
32
33
|
/**
|
|
@@ -36,21 +37,21 @@ async function findFiles(dirPath) {
|
|
|
36
37
|
const files = [];
|
|
37
38
|
|
|
38
39
|
try {
|
|
39
|
-
const entries = await fs.readdir(dirPath, {
|
|
40
|
+
const entries = await fs.readdir(dirPath, {withFileTypes: true});
|
|
40
41
|
|
|
41
42
|
for (const entry of entries) {
|
|
42
|
-
if (entry.isFile() && (entry.name.endsWith(
|
|
43
|
+
if (entry.isFile() && (entry.name.endsWith(".jar") || entry.name.endsWith(".zip"))) {
|
|
43
44
|
const fullPath = path.join(dirPath, entry.name);
|
|
44
45
|
files.push(fullPath);
|
|
45
46
|
}
|
|
46
47
|
}
|
|
47
48
|
} catch (error) {
|
|
48
|
-
if (error.code !==
|
|
49
|
-
|
|
49
|
+
if (error.code !== "ENOENT") {
|
|
50
|
+
logm.warn(`Could not read directory ${dirPath}: ${error.message}`);
|
|
50
51
|
}
|
|
51
52
|
}
|
|
52
53
|
|
|
53
|
-
files.sort((a, b) => a.localeCompare(b,
|
|
54
|
+
files.sort((a, b) => a.localeCompare(b, "en", {numeric: true, sensitivity: "base"}));
|
|
54
55
|
return files;
|
|
55
56
|
}
|
|
56
57
|
|
|
@@ -73,7 +74,7 @@ export async function scanDirectory(dirInfo, workspaceRoot) {
|
|
|
73
74
|
category: dirInfo.name,
|
|
74
75
|
});
|
|
75
76
|
} catch (error) {
|
|
76
|
-
|
|
77
|
+
logm.warn(`Could not hash file ${filePath}: ${error.message}`);
|
|
77
78
|
}
|
|
78
79
|
}
|
|
79
80
|
|
|
@@ -87,10 +88,10 @@ async function getJsonFile(directoryPath, filename) {
|
|
|
87
88
|
const jsonPath = path.join(directoryPath, filename);
|
|
88
89
|
// try to read the file
|
|
89
90
|
try {
|
|
90
|
-
const fileContent = await fs.readFile(jsonPath,
|
|
91
|
+
const fileContent = await fs.readFile(jsonPath, "utf-8");
|
|
91
92
|
return JSON.parse(fileContent);
|
|
92
93
|
} catch (error) {
|
|
93
|
-
if (error.code !==
|
|
94
|
+
if (error.code !== "ENOENT") {
|
|
94
95
|
throw new Error(`Error: Could not read file ${jsonPath}: ${error.message}`);
|
|
95
96
|
} else {
|
|
96
97
|
return null;
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import fs from "fs/promises";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import * as config from "./config/index.js";
|
|
4
|
+
import {logm, styleText} from "./logger.js";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @typedef {import('./config/types.js').Options} Options
|
|
8
|
+
* @typedef {import('./config/types.js').InitOptions} InitOptions
|
|
9
|
+
* @typedef {import('./config/types.js').Lockfile} Lockfile
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Generate .gitignore rules for files not hosted on Modrinth and write them to .gitignore file
|
|
14
|
+
* @param {Lockfile} lockfile - The lockfile object
|
|
15
|
+
* @param {string} workingDir - The working directory
|
|
16
|
+
* @param {Options | InitOptions} options - The options object
|
|
17
|
+
*/
|
|
18
|
+
export async function generateGitignoreRules(lockfile, workingDir, options = {}) {
|
|
19
|
+
logm.quietFromOptions(options);
|
|
20
|
+
|
|
21
|
+
const rules = [];
|
|
22
|
+
const exceptions = [];
|
|
23
|
+
|
|
24
|
+
// Base ignore patterns for each category
|
|
25
|
+
for (const category of config.DEPENDENCY_CATEGORIES) {
|
|
26
|
+
rules.push(`${category}/*.${category === "mods" ? "jar" : "zip"}`);
|
|
27
|
+
}
|
|
28
|
+
rules.push(`*/**/*.disabled`);
|
|
29
|
+
|
|
30
|
+
// Find files not hosted on Modrinth
|
|
31
|
+
for (const [category, entries] of Object.entries(lockfile.dependencies)) {
|
|
32
|
+
for (const entry of entries) {
|
|
33
|
+
if (entry.version === null) {
|
|
34
|
+
exceptions.push(`!${entry.path}`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Add exceptions if any
|
|
40
|
+
if (exceptions.length > 0) {
|
|
41
|
+
rules.push("\n## Exceptions");
|
|
42
|
+
rules.push(...exceptions);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const rulesContent = rules.join("\n");
|
|
46
|
+
const gitignorePath = path.join(workingDir, config.GITIGNORE_NAME);
|
|
47
|
+
|
|
48
|
+
// Read existing .gitignore file if it exists
|
|
49
|
+
let existingContent = "";
|
|
50
|
+
try {
|
|
51
|
+
existingContent = await fs.readFile(gitignorePath, "utf-8");
|
|
52
|
+
} catch (error) {
|
|
53
|
+
// File doesn't exist, that's okay - we'll create it
|
|
54
|
+
if (error.code !== "ENOENT") {
|
|
55
|
+
logm.warn(`Could not read ${config.GITIGNORE_NAME} file: ${error.message}`);
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Find markers in existing content
|
|
61
|
+
const startMarkerIndex = existingContent.indexOf(config.GITIGNORE_START_MARKER);
|
|
62
|
+
const endMarkerIndex = existingContent.indexOf(config.GITIGNORE_END_MARKER);
|
|
63
|
+
|
|
64
|
+
let newContent = "";
|
|
65
|
+
|
|
66
|
+
if (startMarkerIndex !== -1 && endMarkerIndex !== -1 && endMarkerIndex > startMarkerIndex) {
|
|
67
|
+
// Both markers exist, replace content between them
|
|
68
|
+
const beforeSection = existingContent.substring(0, startMarkerIndex);
|
|
69
|
+
const afterSection = existingContent.substring(endMarkerIndex + config.GITIGNORE_END_MARKER.length);
|
|
70
|
+
|
|
71
|
+
// Remove trailing newlines from before section and leading newlines from after section
|
|
72
|
+
const beforeTrimmed = beforeSection.replace(/\n+$/, "");
|
|
73
|
+
const afterTrimmed = afterSection.replace(/^\n+/, "");
|
|
74
|
+
|
|
75
|
+
const parts = [beforeTrimmed];
|
|
76
|
+
if (beforeTrimmed) parts.push(""); // Add separator if there's content before
|
|
77
|
+
parts.push(config.GITIGNORE_START_MARKER, rulesContent, config.GITIGNORE_END_MARKER);
|
|
78
|
+
if (afterTrimmed) {
|
|
79
|
+
parts.push(""); // Add separator if there's content after
|
|
80
|
+
parts.push(afterTrimmed);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
newContent = parts.join("\n");
|
|
84
|
+
} else if (startMarkerIndex !== -1 || endMarkerIndex !== -1) {
|
|
85
|
+
// Only one marker exists, append to end
|
|
86
|
+
const trimmed = existingContent.replace(/\n+$/, "");
|
|
87
|
+
newContent = [trimmed, "", config.GITIGNORE_START_MARKER, rulesContent, config.GITIGNORE_END_MARKER].join("\n");
|
|
88
|
+
} else {
|
|
89
|
+
// No markers exist, append to end
|
|
90
|
+
if (existingContent.trim() === "") {
|
|
91
|
+
// File is empty or only whitespace
|
|
92
|
+
newContent = [config.GITIGNORE_START_MARKER, rulesContent, config.GITIGNORE_END_MARKER].join("\n");
|
|
93
|
+
} else {
|
|
94
|
+
// File has content, append with newline
|
|
95
|
+
const trimmed = existingContent.replace(/\n+$/, "");
|
|
96
|
+
newContent = [trimmed, "", config.GITIGNORE_START_MARKER, rulesContent, config.GITIGNORE_END_MARKER].join(
|
|
97
|
+
"\n",
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// Write the updated content
|
|
103
|
+
if (options.dryRun) {
|
|
104
|
+
logm.debug(config.dryRunText(config.GITIGNORE_NAME, gitignorePath));
|
|
105
|
+
} else {
|
|
106
|
+
try {
|
|
107
|
+
await fs.writeFile(gitignorePath, newContent, "utf-8");
|
|
108
|
+
logm.generated(config.GITIGNORE_NAME, gitignorePath);
|
|
109
|
+
} catch (error) {
|
|
110
|
+
logm.warn(`Could not write ${config.GITIGNORE_NAME} file: ${error.message}`);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
package/src/generate_json.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import fs from
|
|
2
|
-
import path from
|
|
3
|
-
import {
|
|
4
|
-
import * as config from
|
|
1
|
+
import fs from "fs/promises";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import {getProjects} from "./modrinth_interactions.js";
|
|
4
|
+
import * as config from "./config/index.js";
|
|
5
|
+
import {logm} from "./logger.js";
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* @typedef {import('./config/types.js').ModpackInfo} ModpackInfo
|
|
@@ -25,19 +26,21 @@ function createModpackJson(modpackInfo, dependencies) {
|
|
|
25
26
|
*/
|
|
26
27
|
async function writeJson(jsonObject, outputPath) {
|
|
27
28
|
const content = JSON.stringify(jsonObject, null, 2);
|
|
28
|
-
await fs.writeFile(path.join(outputPath, config.MODPACK_JSON_NAME), content,
|
|
29
|
-
|
|
29
|
+
await fs.writeFile(path.join(outputPath, config.MODPACK_JSON_NAME), content, "utf-8");
|
|
30
|
+
logm.generated(config.MODPACK_JSON_NAME, path.join(outputPath, config.MODPACK_JSON_NAME));
|
|
30
31
|
}
|
|
31
32
|
|
|
32
33
|
/**
|
|
33
34
|
* Generate a modpack.json file
|
|
34
35
|
* @param {ModpackInfo} modpackInfo - The modpack information
|
|
35
36
|
* @param {Lockfile} lockfile - The lockfile
|
|
36
|
-
* @param {string}
|
|
37
|
+
* @param {string} workingDir - The path to write the JSON object to
|
|
37
38
|
* @param {Options | InitOptions} options - The options object
|
|
38
39
|
* @returns {Promise<Lockfile>} The JSON file's object
|
|
39
40
|
*/
|
|
40
|
-
export default async function generateJson(modpackInfo, lockfile,
|
|
41
|
+
export default async function generateJson(modpackInfo, lockfile, workingDir, options = {}) {
|
|
42
|
+
logm.quietFromOptions(options);
|
|
43
|
+
|
|
41
44
|
// Validate modpack info
|
|
42
45
|
for (const field of config.MODPACK_INFO_REQUIRED_FIELDS) {
|
|
43
46
|
if (!modpackInfo[field]) {
|
|
@@ -53,53 +56,51 @@ export default async function generateJson(modpackInfo, lockfile, outputDir, opt
|
|
|
53
56
|
}
|
|
54
57
|
|
|
55
58
|
// Collect project IDs from lockfile
|
|
56
|
-
if (lockfile)
|
|
57
|
-
|
|
58
|
-
for (const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
59
|
+
if (lockfile)
|
|
60
|
+
if (lockfile.dependencies) {
|
|
61
|
+
for (const [category, entries] of Object.entries(lockfile.dependencies)) {
|
|
62
|
+
for (const entry of entries) {
|
|
63
|
+
if (entry.version && entry.version.project_id) {
|
|
64
|
+
projectIds[category].add(entry.version.project_id);
|
|
65
|
+
} else {
|
|
66
|
+
packDependencies[category].push(entry.path);
|
|
67
|
+
}
|
|
63
68
|
}
|
|
64
69
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
+
const allProjectIds = new Set();
|
|
71
|
+
for (const category of config.DEPENDENCY_CATEGORIES) {
|
|
72
|
+
for (const projectId of projectIds[category]) {
|
|
73
|
+
allProjectIds.add(projectId);
|
|
74
|
+
}
|
|
70
75
|
}
|
|
71
|
-
}
|
|
72
76
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
77
|
+
// Fetch projects from Modrinth
|
|
78
|
+
const projects = await getProjects(Array.from(allProjectIds));
|
|
79
|
+
const projectsMap = {};
|
|
80
|
+
for (const project of projects) {
|
|
81
|
+
projectsMap[project.id] = project.slug;
|
|
82
|
+
}
|
|
79
83
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
84
|
+
// Add projects to dependencies by category
|
|
85
|
+
for (const category of config.DEPENDENCY_CATEGORIES) {
|
|
86
|
+
for (const projectId of projectIds[category]) {
|
|
87
|
+
const projectSlug = projectsMap[projectId];
|
|
88
|
+
if (projectSlug) {
|
|
89
|
+
packDependencies[category].push(projectSlug);
|
|
90
|
+
}
|
|
86
91
|
}
|
|
87
92
|
}
|
|
88
93
|
}
|
|
89
|
-
}
|
|
90
94
|
|
|
91
95
|
// Create modpack JSON object
|
|
92
96
|
const jsonObject = createModpackJson(modpackInfo, packDependencies);
|
|
93
97
|
|
|
94
98
|
// Write modpack JSON object to disk
|
|
95
99
|
if (options.dryRun) {
|
|
96
|
-
|
|
100
|
+
logm.debug(config.dryRunText(config.MODPACK_JSON_NAME, path.join(workingDir, config.MODPACK_JSON_NAME)));
|
|
97
101
|
} else {
|
|
98
|
-
await writeJson(jsonObject,
|
|
102
|
+
await writeJson(jsonObject, workingDir);
|
|
99
103
|
}
|
|
100
104
|
|
|
101
105
|
return jsonObject;
|
|
102
106
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
package/src/generate_license.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import fs from
|
|
2
|
-
import path from
|
|
3
|
-
import {
|
|
4
|
-
import * as config from
|
|
1
|
+
import fs from "fs/promises";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import {getLicenseText} from "./github_interactions.js";
|
|
4
|
+
import * as config from "./config/index.js";
|
|
5
|
+
import {logm} from "./logger.js";
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* @typedef {import('./config/types.js').ModpackInfo} ModpackInfo
|
|
@@ -10,41 +11,44 @@ import * as config from './config/index.js';
|
|
|
10
11
|
*/
|
|
11
12
|
|
|
12
13
|
async function writeLicense(licenseText, outputPath) {
|
|
13
|
-
await fs.writeFile(path.join(outputPath, config.MODPACK_LICENSE_NAME), licenseText,
|
|
14
|
-
|
|
14
|
+
await fs.writeFile(path.join(outputPath, config.MODPACK_LICENSE_NAME), licenseText, "utf-8");
|
|
15
|
+
logm.generated(config.MODPACK_LICENSE_NAME, path.join(outputPath, config.MODPACK_LICENSE_NAME));
|
|
15
16
|
}
|
|
16
17
|
|
|
17
18
|
/**
|
|
18
19
|
* Write a license to a file
|
|
19
20
|
* @param {ModpackInfo} modpackInfo - The modpack information
|
|
20
|
-
* @param {string}
|
|
21
|
+
* @param {string} workingDir - The path to write the license to
|
|
21
22
|
* @param {InitOptions} options - The initialization options object
|
|
22
23
|
* @param {string} licenseTextOverride - The license text to override the default license text with
|
|
23
24
|
* @returns {Promise<string> | null} The license text or null if the license text could not be generated
|
|
24
25
|
*/
|
|
25
|
-
export default async function generateLicense(modpackInfo,
|
|
26
|
+
export default async function generateLicense(modpackInfo, workingDir, options = {}, licenseTextOverride = null) {
|
|
27
|
+
logm.quietFromOptions(options);
|
|
28
|
+
|
|
26
29
|
try {
|
|
27
30
|
const spdxId = modpackInfo.license;
|
|
28
|
-
console.log(`Generating license for: ${spdxId}`);
|
|
29
31
|
|
|
30
|
-
let licenseText = licenseTextOverride || await getLicenseText(spdxId);
|
|
31
|
-
licenseText = licenseText.replace(
|
|
32
|
-
licenseText = licenseText.replace(
|
|
33
|
-
licenseText = licenseText.replace(
|
|
34
|
-
licenseText = licenseText.replace(
|
|
35
|
-
licenseText = licenseText.replace(
|
|
36
|
-
licenseText = licenseText.replace(
|
|
37
|
-
licenseText = licenseText.replace(
|
|
38
|
-
licenseText = licenseText.replace(
|
|
32
|
+
let licenseText = licenseTextOverride || (await getLicenseText(spdxId));
|
|
33
|
+
licenseText = licenseText.replace("[year]", new Date().getFullYear());
|
|
34
|
+
licenseText = licenseText.replace("{{year}}", new Date().getFullYear());
|
|
35
|
+
licenseText = licenseText.replace("[fullname]", modpackInfo.author);
|
|
36
|
+
licenseText = licenseText.replace("{{fullname}}", modpackInfo.author);
|
|
37
|
+
licenseText = licenseText.replace("[organization]", modpackInfo.author);
|
|
38
|
+
licenseText = licenseText.replace("{{organization}}", modpackInfo.author);
|
|
39
|
+
licenseText = licenseText.replace("[project]", modpackInfo.name);
|
|
40
|
+
licenseText = licenseText.replace("{{project}}", modpackInfo.name);
|
|
39
41
|
|
|
40
42
|
if (options.dryRun) {
|
|
41
|
-
|
|
43
|
+
logm.debug(
|
|
44
|
+
config.dryRunText(config.MODPACK_LICENSE_NAME, path.join(workingDir, config.MODPACK_LICENSE_NAME)),
|
|
45
|
+
);
|
|
42
46
|
} else {
|
|
43
|
-
await writeLicense(licenseText,
|
|
47
|
+
await writeLicense(licenseText, workingDir);
|
|
44
48
|
}
|
|
45
49
|
return licenseText;
|
|
46
50
|
} catch (error) {
|
|
47
|
-
|
|
51
|
+
logm.warn(`Unable to generate license for: ${modpackInfo.license}`);
|
|
48
52
|
return null;
|
|
49
53
|
}
|
|
50
54
|
}
|