Skip to content

Commit

Permalink
Working method to add version to Issue Templates
Browse files Browse the repository at this point in the history
Produces weird artifacts...
  • Loading branch information
IntegerLimit committed Sep 18, 2023
1 parent 3d643a7 commit f63480e
Show file tree
Hide file tree
Showing 7 changed files with 245 additions and 26 deletions.
2 changes: 2 additions & 0 deletions tools/globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ export const modpackManifest = manifest as ModpackManifest;
export const overridesFolder = modpackManifest.overrides || "overrides";
export const configFolder = upath.join(overridesFolder, "config");
export const configOverridesFolder = upath.join(overridesFolder, "config-overrides");

export const issueTemplatesFolder = upath.join("..", ".github", "ISSUE_TEMPLATE")
3 changes: 3 additions & 0 deletions tools/gulpfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ export const pruneCache = pruneCacheTask;
import * as quest from "./tasks/github/quest";
export const transformQB = quest.transformQuestBook;

import * as releaseCommit from "./tasks/misc/releaseCommit";
export const updateIssueTemplates = releaseCommit.updateIssueTemplates;

import sharedTasks from "./tasks/shared";
import clientTasks from "./tasks/client";
import serverTasks from "./tasks/server";
Expand Down
168 changes: 142 additions & 26 deletions tools/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions tools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"upath": "^2.0.1"
},
"dependencies": {
"js-yaml": "^4.1.0",
"md5": "^2.3.0"
}
}
38 changes: 38 additions & 0 deletions tools/tasks/lang/index 2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import gulp from "gulp";
import rename from "gulp-rename";
import merge from "merge-stream";
import upath from "upath";
import buildConfig from "../../buildConfig";
import { langDestDirectory, overridesFolder, sharedDestDirectory } from "../../globals";
import fs from "fs";

/**
* Checks and creates all necessary directories so we can build the client safely.
*/
async function createLangDirs() {
if (!fs.existsSync(langDestDirectory)) {
await fs.promises.mkdir(langDestDirectory, { recursive: true });
}
}

async function copyLang() {
const resourcesPath = upath.join(sharedDestDirectory, overridesFolder, "resources");

const opts = { nodir: true, base: resourcesPath };
const streams = [
gulp.src(upath.join(resourcesPath, "pack.mcmeta"), opts),
gulp.src(upath.join(resourcesPath, "**/*.lang"), opts).pipe(
rename((f) => {
f.dirname = upath.join("assets", f.dirname);
}),
),
];

return await new Promise((resolve) => {
merge(...streams)
.pipe(gulp.dest(upath.join(buildConfig.buildDestinationDirectory, langDestDirectory)))
.on("end", resolve);
});
}

export default gulp.series(createLangDirs, copyLang);
48 changes: 48 additions & 0 deletions tools/tasks/misc/releaseCommit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import fs from "fs";
import upath from "upath";
import gulp from "gulp";
import yaml from "js-yaml";

import { issueTemplatesFolder } from "../../globals";
import { IssueInput } from "../../types/issueInput";

// The name of the 'body' object.
const bodyID: string = 'body';

// The id of the version input field, in both Issue Templates.
const versionInputID: string = 'version';

// Temp/Debug
const tempVersionField: string = '2.0';

async function updateIssueTemplate(filepath : string) {
// Load the yaml file, and get its 'body'
const file: object = yaml.load(await fs.promises.readFile(filepath));
const fileBody: object[] = file[bodyID];

const newFileBody: object[] = [];
fileBody.forEach((input: IssueInput) => {
if (input.id == versionInputID) {
const versions: string[] = input.attributes.options;

// Add new version to start of list
versions.unshift(tempVersionField);

// Load new version list
input.attributes.options = versions; // May not be needed, but just incase
}
newFileBody.push(input);
});

// Set new file body
file[bodyID] = newFileBody; // May not be needed

// Write file
fs.promises.writeFile(filepath, yaml.dump(file));
}

// This can be added to with new issue templates.
export async function updateIssueTemplates() : Promise<void> {
updateIssueTemplate(upath.join(issueTemplatesFolder, "001-bug-report.yml"));
updateIssueTemplate(upath.join(issueTemplatesFolder, "002-feature-request.yml"));
}
Loading

0 comments on commit f63480e

Please sign in to comment.