This repository has been archived by the owner on Oct 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate.ts
199 lines (181 loc) · 5.01 KB
/
template.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
import {
Input,
prompt,
} from "https://deno.land/x/[email protected]/prompt/mod.ts";
import { join } from "https://deno.land/[email protected]/path/mod.ts";
const options = await prompt([
{
name: "mod_name",
message: "Enter mod name:",
type: Input,
},
{
name: "mod_id",
message: "Enter mod ID:",
type: Input,
},
{
name: "main_class_name",
message: "Enter main class name:",
type: Input,
},
{
name: "maven_group",
message: "Enter maven group:",
type: Input,
default: "io.github.jamalam360",
},
{
name: "description",
message: "Enter description:",
type: Input,
},
{
name: "author",
message: "Enter author:",
type: Input,
default: "Jamalam",
},
{
name: "github_user",
message: "Enter github user/organisation:",
type: Input,
default: "JamCoreModding",
},
{
name: "github_repo",
message: "Enter github repo:",
type: Input,
},
]);
const mainPackage = `${options.maven_group}/${
options.mod_id!.split("_").join("/").split("-").join("/")
}`.replaceAll(".", "/");
const mainClass = join(
Deno.cwd(),
"src/main/java",
mainPackage.replaceAll(".", "/"),
`${options.main_class_name}.java`,
);
await transformMainPackage();
await transformMainClass();
await transformAssetsDirectory();
await transformFabricModJson();
await transformMixinsJson();
await transformGradleProperties();
await transformReadme();
await transformLicense();
await transformChangelogs();
async function transformMainPackage() {
await Deno.mkdir(
join(Deno.cwd(), "src/main/java", mainPackage.replaceAll(".", "/")),
{ recursive: true },
);
await Deno.rename(
join(Deno.cwd(), "src/main/java/io/github/jamalam360/templatemod"),
join(Deno.cwd(), "src/main/java", mainPackage.replaceAll(".", "/")),
);
}
async function transformMainClass() {
await Deno.rename(
join(Deno.cwd(), "src/main/java", mainPackage, `TemplateModInit.java`),
mainClass,
);
const content = await Deno.readTextFile(mainClass);
await Deno.writeTextFile(
mainClass,
content.replaceAll("TemplateModInit", options.main_class_name!)
.replaceAll("templatemod", options.mod_id!)
.replaceAll("Template Mod", options.mod_name!)
.replaceAll(
"io.github.jamalam360.templatemod",
mainPackage.replaceAll("/", "."),
),
);
}
async function transformAssetsDirectory() {
await Deno.rename(
join(Deno.cwd(), "src/main/resources/assets/templatemod"),
join(Deno.cwd(), "src/main/resources/assets", options.mod_id!),
);
}
async function transformFabricModJson() {
const fmj = `./src/main/resources/fabric.mod.json`;
const fmjContent = await Deno.readTextFile(fmj);
await Deno.writeTextFile(
fmj,
fmjContent
.replaceAll(
"io.github.jamalam360.templatemod.TemplateModInit",
`${mainPackage}.${options.main_class_name}`,
)
.replaceAll("templatemod", options.mod_id!)
.replaceAll("Template Mod", options.mod_name!)
.replaceAll("A Fabric mod template", options.description!)
.replaceAll("Jamalam", options.author!)
.replaceAll("JamCoreModding", options.github_user!)
.replaceAll("TemplateMod", options.github_repo!)
.replaceAll("FabricTemplateMod", options.github_repo!),
);
}
async function transformMixinsJson() {
const mixins = join(
Deno.cwd(),
"src/main/resources",
`${options.mod_id}.mixins.json`,
);
await Deno.rename(
join(Deno.cwd(), "src/main/resources/templatemod.mixins.json"),
mixins,
);
const mixinsContent = await Deno.readTextFile(mixins);
await Deno.writeTextFile(
mixins,
mixinsContent.replaceAll(
"io.github.jamalam360.templatemod",
mainPackage.replaceAll("/", "."),
),
);
}
async function transformGradleProperties() {
const gradleProperties = join(Deno.cwd(), "gradle.properties");
const gradlePropertiesContent = await Deno.readTextFile(gradleProperties);
await Deno.writeTextFile(
gradleProperties,
gradlePropertiesContent
.replaceAll("TemplateMod", options.github_repo!)
.replaceAll("FabricTemplateMod", options.github_repo!)
.replaceAll("JamCoreModding", options.github_user!)
.replaceAll("template-mod", options.mod_id!.replaceAll("_", "-")),
);
}
async function transformReadme() {
await Deno.writeTextFile(
"./README.md",
`
# ${options.mod_name}
${options.description}
`.trim(),
);
}
async function transformLicense() {
await Deno.writeTextFile(
"./LICENSE",
await (await Deno.readTextFile("./LICENSE")).replaceAll(
"Jamalam",
options.author!,
).replaceAll("[YEAR]", new Date().getFullYear().toString()),
);
}
async function transformChangelogs() {
await Deno.writeTextFile(
"./CHANGELOG_TEMPLATE.md",
(await Deno.readTextFile("./CHANGELOG_TEMPLATE.md"))
.replaceAll("FabricTemplateMod", options.github_repo!)
.replaceAll("JamCoreModding", options.github_user!),
);
await Deno.writeTextFile(
"./CHANGELOG.md",
await Deno.readTextFile("./CHANGELOG_TEMPLATE.md"),
);
}