Skip to content

Commit adaec15

Browse files
committed
ci: add custom updater for standard-version to update manifest
1 parent 1bfe822 commit adaec15

File tree

5 files changed

+53
-84
lines changed

5 files changed

+53
-84
lines changed

.versionrc.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const manifest = {
2+
filename: "./src/module.json",
3+
updater: require("./update-manifest.js")
4+
};
5+
6+
module.exports = {
7+
bumpFiles: [manifest]
8+
}

gulpfile.js

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ const stylesExtension = "css";
1515
const sourceFileExtension = "ts";
1616
const staticFiles = ["lang", "templates", "module.json"];
1717
const distFiles = ["LICENSE"];
18-
const getDownloadURL = (version) =>
19-
`https://github.com/Ethaks/FVTT-Quench/releases/download/${version}/module.zip`;
2018

2119
/********************/
2220
/* BUILD */
@@ -122,55 +120,8 @@ async function clean() {
122120
}
123121
}
124122

125-
/********************/
126-
/* VERSIONING */
127-
/********************/
128-
129-
/**
130-
* Get the contents of the manifest file as object.
131-
*/
132-
function getManifest() {
133-
const manifestPath = `${sourceDirectory}/module.json`;
134-
135-
if (fs.existsSync(manifestPath)) {
136-
return {
137-
file: fs.readJSONSync(manifestPath),
138-
name: "module.json",
139-
};
140-
}
141-
}
142-
143-
/**
144-
* Update version and download URL.
145-
*/
146-
function bumpVersion(cb) {
147-
const packageJson = fs.readJSONSync("package.json");
148-
const manifest = getManifest();
149-
150-
if (!manifest) cb(Error(chalk.red("Manifest JSON not found")));
151-
152-
try {
153-
const targetVersion = packageJson.version;
154-
155-
if (!targetVersion) {
156-
return cb(new Error(chalk.red("Error: Incorrect version arguments")));
157-
}
158-
159-
console.log(`Updating version number to '${targetVersion}'`);
160-
161-
manifest.file.version = targetVersion;
162-
manifest.file.download = getDownloadURL(targetVersion);
163-
fs.writeJSONSync(`${sourceDirectory}/${manifest.name}`, manifest.file, { spaces: 2 });
164-
165-
return cb();
166-
} catch (err) {
167-
cb(err);
168-
}
169-
}
170-
171123
const execBuild = gulp.parallel(buildProd, buildStyles, copyFiles);
172124

173125
exports.build = gulp.series(clean, execBuild);
174126
exports.watch = buildWatch;
175127
exports.clean = clean;
176-
exports.bumpVersion = bumpVersion;

package-lock.json

Lines changed: 30 additions & 30 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,5 @@
6666
"lint-staged": {
6767
"*.(ts|js)": "eslint --cache --fix",
6868
"*.(json|css|yml)": "prettier --write"
69-
},
70-
"standard-version": {
71-
"scripts": {
72-
"prerelease": "gulp bumpVersion && git add src/module.json"
73-
}
7469
}
7570
}

update-manifest.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const prettier = require("prettier");
2+
3+
module.exports.readVersion = function (contents) {
4+
return JSON.parse(contents).version;
5+
};
6+
7+
module.exports.writeVersion = function (contents, version) {
8+
const json = JSON.parse(contents);
9+
json.version = version;
10+
json.download = `https://github.com/Ethaks/FVTT-Quench/releases/download/${version}/module.zip`;
11+
const str = prettier.format(JSON.stringify(json), {
12+
parser: "json",
13+
});
14+
return str;
15+
};

0 commit comments

Comments
 (0)