modpack-lock 0.6.2 → 0.8.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.
Files changed (121) hide show
  1. package/README.md +24 -18
  2. package/build/cli.d.ts +3 -0
  3. package/build/cli.d.ts.map +1 -0
  4. package/build/cli.js +257 -0
  5. package/build/cli.js.map +1 -0
  6. package/build/config/api.d.ts +29 -0
  7. package/build/config/api.d.ts.map +1 -0
  8. package/{src → build}/config/api.js +4 -14
  9. package/build/config/api.js.map +1 -0
  10. package/build/config/constants.d.ts +17 -0
  11. package/build/config/constants.d.ts.map +1 -0
  12. package/{src → build}/config/constants.js +10 -10
  13. package/build/config/constants.js.map +1 -0
  14. package/build/config/defaults.d.ts +16 -0
  15. package/build/config/defaults.d.ts.map +1 -0
  16. package/build/config/defaults.js +60 -0
  17. package/build/config/defaults.js.map +1 -0
  18. package/build/config/files.d.ts +11 -0
  19. package/build/config/files.d.ts.map +1 -0
  20. package/{src → build}/config/files.js +1 -4
  21. package/build/config/files.js.map +1 -0
  22. package/build/config/index.d.ts +7 -0
  23. package/build/config/index.d.ts.map +1 -0
  24. package/{src → build}/config/index.js +1 -0
  25. package/build/config/index.js.map +1 -0
  26. package/build/config/options.d.ts +8 -0
  27. package/build/config/options.d.ts.map +1 -0
  28. package/{src → build}/config/options.js +7 -6
  29. package/build/config/options.js.map +1 -0
  30. package/build/config/strings.d.ts +35 -0
  31. package/build/config/strings.d.ts.map +1 -0
  32. package/{src → build}/config/strings.js +14 -19
  33. package/build/config/strings.js.map +1 -0
  34. package/build/directory_scanning.d.ts +26 -0
  35. package/build/directory_scanning.d.ts.map +1 -0
  36. package/{src → build}/directory_scanning.js +23 -36
  37. package/build/directory_scanning.js.map +1 -0
  38. package/build/generate_gitignore.d.ts +9 -0
  39. package/build/generate_gitignore.d.ts.map +1 -0
  40. package/{src → build}/generate_gitignore.js +21 -35
  41. package/build/generate_gitignore.js.map +1 -0
  42. package/build/generate_json.d.ts +18 -0
  43. package/build/generate_json.d.ts.map +1 -0
  44. package/build/generate_json.js +137 -0
  45. package/build/generate_json.js.map +1 -0
  46. package/build/generate_license.d.ts +11 -0
  47. package/build/generate_license.d.ts.map +1 -0
  48. package/build/generate_license.js +54 -0
  49. package/build/generate_license.js.map +1 -0
  50. package/build/generate_lockfile.d.ts +14 -0
  51. package/build/generate_lockfile.d.ts.map +1 -0
  52. package/{src → build}/generate_lockfile.js +19 -69
  53. package/build/generate_lockfile.js.map +1 -0
  54. package/build/generate_readme.d.ts +9 -0
  55. package/build/generate_readme.d.ts.map +1 -0
  56. package/{src → build}/generate_readme.js +46 -72
  57. package/build/generate_readme.js.map +1 -0
  58. package/build/github_interactions.d.ts +14 -0
  59. package/build/github_interactions.d.ts.map +1 -0
  60. package/{src → build}/github_interactions.js +16 -19
  61. package/build/github_interactions.js.map +1 -0
  62. package/build/logger.d.ts +96 -0
  63. package/build/logger.d.ts.map +1 -0
  64. package/{src → build}/logger.js +47 -55
  65. package/build/logger.js.map +1 -0
  66. package/build/modpack-lock.d.ts +25 -0
  67. package/build/modpack-lock.d.ts.map +1 -0
  68. package/build/modpack-lock.js +43 -0
  69. package/build/modpack-lock.js.map +1 -0
  70. package/build/modrinth_interactions.d.ts +31 -0
  71. package/build/modrinth_interactions.d.ts.map +1 -0
  72. package/{src → build}/modrinth_interactions.js +72 -55
  73. package/build/modrinth_interactions.js.map +1 -0
  74. package/build/types/Jsonfile.d.ts +26 -0
  75. package/build/types/Jsonfile.d.ts.map +1 -0
  76. package/build/types/Jsonfile.js +2 -0
  77. package/build/types/Jsonfile.js.map +1 -0
  78. package/build/types/Lockfile.d.ts +39 -0
  79. package/build/types/Lockfile.d.ts.map +1 -0
  80. package/build/types/Lockfile.js +2 -0
  81. package/build/types/Lockfile.js.map +1 -0
  82. package/build/types/ModpackInfo.d.ts +28 -0
  83. package/build/types/ModpackInfo.d.ts.map +1 -0
  84. package/build/types/ModpackInfo.js +2 -0
  85. package/build/types/ModpackInfo.js.map +1 -0
  86. package/build/types/OptionalFileOptions.d.ts +8 -0
  87. package/build/types/OptionalFileOptions.d.ts.map +1 -0
  88. package/build/types/OptionalFileOptions.js +2 -0
  89. package/build/types/OptionalFileOptions.js.map +1 -0
  90. package/build/types/contentFiles.d.ts +24 -0
  91. package/build/types/contentFiles.d.ts.map +1 -0
  92. package/build/types/contentFiles.js +2 -0
  93. package/build/types/contentFiles.js.map +1 -0
  94. package/build/types/githubResponses.d.ts +17 -0
  95. package/build/types/githubResponses.d.ts.map +1 -0
  96. package/build/types/githubResponses.js +2 -0
  97. package/build/types/githubResponses.js.map +1 -0
  98. package/build/types/index.d.ts +9 -0
  99. package/build/types/index.d.ts.map +1 -0
  100. package/build/types/index.js +2 -0
  101. package/build/types/index.js.map +1 -0
  102. package/build/types/modrinthResponses.d.ts +135 -0
  103. package/build/types/modrinthResponses.d.ts.map +1 -0
  104. package/build/types/modrinthResponses.js +2 -0
  105. package/build/types/modrinthResponses.js.map +1 -0
  106. package/build/types/options.d.ts +70 -0
  107. package/build/types/options.d.ts.map +1 -0
  108. package/build/types/options.js +2 -0
  109. package/build/types/options.js.map +1 -0
  110. package/build/user_prompts.d.ts +16 -0
  111. package/build/user_prompts.d.ts.map +1 -0
  112. package/build/user_prompts.js +132 -0
  113. package/build/user_prompts.js.map +1 -0
  114. package/package.json +13 -6
  115. package/src/cli.js +0 -310
  116. package/src/config/defaults.js +0 -66
  117. package/src/config/types.js +0 -76
  118. package/src/generate_json.js +0 -106
  119. package/src/generate_license.js +0 -54
  120. package/src/modpack-lock.js +0 -69
  121. package/src/modpack_info.js +0 -200
@@ -1,69 +0,0 @@
1
- import {generateLockfile} from "./generate_lockfile.js";
2
- import {generateReadmeFiles} from "./generate_readme.js";
3
- import {generateGitignoreRules} from "./generate_gitignore.js";
4
- import generateJson from "./generate_json.js";
5
- import generateLicense from "./generate_license.js";
6
- import {logm} from "./logger.js";
7
- import {promptUserForInfo} from "./modpack_info.js";
8
- import {getModpackInfo, getLockfile} from "./directory_scanning.js";
9
-
10
- /**
11
- * @typedef {import('./config/types.js').ModpackInfo} ModpackInfo
12
- * @typedef {import('./config/types.js').Options} Options
13
- * @typedef {import('./config/types.js').InitOptions} InitOptions
14
- * @typedef {import('./config/types.js').Lockfile} Lockfile
15
- */
16
-
17
- /**
18
- * @license MIT
19
- * @author nickesc
20
- * @module modpack-lock
21
- */
22
-
23
- /**
24
- * Generate the modpack files (lockfile, JSON, and optionally license, gitignore, and readme)
25
- * @param {ModpackInfo} modpackInfo - The modpack information
26
- * @param {string} workingDir - The directory to generate the files in
27
- * @param {Options | InitOptions } options - The options object
28
- * @returns {Promise<Lockfile>} The lockfile object
29
- */
30
- async function generateModpackFiles(modpackInfo, workingDir, options = {}) {
31
- logm.quietFromOptions(options);
32
-
33
- const lockfile = await generateLockfile(workingDir, options);
34
-
35
- await generateJson(modpackInfo, lockfile, workingDir, options);
36
-
37
- if (options.licenseFile || options.gitignore || options.readme) {
38
- logm.header("Generating Optional Files");
39
- }
40
-
41
- // Generate license if requested
42
- if (options.licenseFile) {
43
- await generateLicense(modpackInfo, workingDir, options);
44
- }
45
-
46
- // Generate gitignore if requested
47
- if (options.gitignore) {
48
- await generateGitignoreRules(lockfile, workingDir, options);
49
- }
50
-
51
- // Generate README files if requested
52
- if (options.readme) {
53
- await generateReadmeFiles(lockfile, workingDir, options);
54
- }
55
-
56
- return lockfile;
57
- }
58
-
59
- export {
60
- generateModpackFiles,
61
- generateJson,
62
- generateLockfile,
63
- generateGitignoreRules,
64
- generateReadmeFiles,
65
- generateLicense,
66
- getModpackInfo,
67
- getLockfile,
68
- promptUserForInfo,
69
- };
@@ -1,200 +0,0 @@
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
-
7
- /**
8
- * @typedef {import('./config/types.js').ModpackInfo} ModpackInfo
9
- */
10
-
11
- /**
12
- * Capitalizes a string
13
- */
14
- function capitalize(string) {
15
- return `${string.charAt(0).toUpperCase()}${string.slice(1)}`;
16
- }
17
-
18
- /**
19
- * Validate that a value is not empty
20
- */
21
- function validateNotEmpty(value, field) {
22
- if (value === undefined || value?.trim().length === 0) {
23
- return `${field} cannot be empty`;
24
- }
25
- return true;
26
- }
27
-
28
- /**
29
- * Returns a required text prompt
30
- */
31
- function requiredText(name, message, initial) {
32
- return {
33
- type: "text",
34
- name: name,
35
- message: `${capitalize(message)}`,
36
- initial: initial,
37
- validate: (value) => {
38
- return validateNotEmpty(value, name);
39
- },
40
- };
41
- }
42
-
43
- /**
44
- * Returns an optional text prompt
45
- */
46
- function optionalText(name, message, initial) {
47
- return {
48
- type: "text",
49
- name: name,
50
- message: `${capitalize(message)}`,
51
- initial: initial,
52
- };
53
- }
54
-
55
- /**
56
- * Get an other answer from the user
57
- */
58
- async function getOtherAnswer(value, message, initial) {
59
- if (value && value !== config.OTHER_OPTION.value) {
60
- return value;
61
- }
62
- const question = await prompts(requiredText("other", message, initial), config.PROMPTS_OPTIONS);
63
-
64
- return question.other || config.OTHER_OPTION.value;
65
- }
66
-
67
- /**
68
- * Returns a required autocomplete prompt with a fallback to the other option
69
- */
70
- function requiredAutocomplete(name, message, initial, choices, defaultValue) {
71
- initial = initial || defaultValue || config.OTHER_OPTION.value;
72
- if (initial && !choices.some((choice) => choice.value === initial)) {
73
- choices.push({title: initial, value: initial});
74
- }
75
-
76
- return {
77
- type: "autocomplete",
78
- name: name,
79
- message: `${capitalize(message)}`,
80
- initial: initial,
81
- choices: choices,
82
- fallback: config.OTHER_OPTION.value,
83
- format: async (value) => {
84
- return await getOtherAnswer(value, ` └─𜰙 Other ${message}`, initial);
85
- },
86
- };
87
- }
88
-
89
- /**
90
- * Returns an confirmation prompt to generate an optional file
91
- */
92
- function fileGenerationConfirm(name, message, showPrompt) {
93
- return {
94
- type: showPrompt ? "confirm" : null,
95
- name: name,
96
- message: `${capitalize(message)}`,
97
- initial: true,
98
- };
99
- }
100
-
101
- /**
102
- * Get user input for modpack information
103
- * @param {ModpackInfo} defaults - The initial/default modpack information
104
- * @returns {Promise<ModpackInfo>} The modpack information from the user
105
- */
106
- export async function promptUserForInfo(defaults = {}) {
107
- const licenseList = await getLicenseList();
108
- const minecraftVersions = await getMinecraftVersions();
109
- const modloaders = await getModloaders();
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
- );
162
-
163
- return answers;
164
- }
165
-
166
- /**
167
- * Prompt the user about adding the license text to the modpack
168
- * @param {ModpackInfo} modpackInfo - The modpack information
169
- * @returns {Promise<Object>} The answers from the user
170
- */
171
- export async function promptUserAboutOptionalFiles(modpackInfo, defaults = {}) {
172
- const licenseText = await getLicenseText(modpackInfo.license);
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
- );
193
-
194
- answers.addLicense =
195
- answers.addLicense === undefined ? (licenseText ? defaults.addLicense : false) : answers.addLicense;
196
- answers.addReadme = answers.addReadme === undefined ? defaults.addReadme : answers.addReadme;
197
- answers.addGitignore = answers.addGitignore === undefined ? defaults.addGitignore : answers.addGitignore;
198
-
199
- return answers;
200
- }