Skip to content

Commit

Permalink
feat: preserve comments in properties file
Browse files Browse the repository at this point in the history
close #569

Signed-off-by: Kengo TODA <skypencil@gmail.com>
  • Loading branch information
KengoTODA committed Dec 31, 2023
1 parent fedfd20 commit 0bbb179
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
16 changes: 8 additions & 8 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"prepare": "husky install"
},
"dependencies": {
"promisified-properties": "^2.0.27",
"promisified-properties": "^3.0.0",
"split2": "^4.1.0"
},
"devDependencies": {
Expand Down
17 changes: 13 additions & 4 deletions src/prepare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,27 @@ import { join } from "path";
import { parseFile, write } from "promisified-properties";
import { IContext } from "./definition";
import { getVersion } from "./gradle";
import { Entry } from "promisified-properties/lib/types";

export async function updateVersion(
cwd: string,
version: string,
): Promise<void> {
const path = join(cwd, "gradle.properties");
let prop = new Map<string, string>();
if (existsSync(path)) {
prop = await parseFile(path);
const prop = await parseFile(path);
const index = prop.findIndex(
(entry) => "key" in entry && entry.key == "version",
);
if (index < 0) {
prop.push({ key: "version", value: version });
} else {
(prop[index] as Entry).value = version;
}
return write(prop, path);
} else {
write([{ key: "version", value: version }], path);
}
prop.set("version", version);
return write(prop, path);
}

export default async function prepare(pluginConfig: object, context: IContext) {
Expand Down

0 comments on commit 0bbb179

Please sign in to comment.