Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import write from "./src/lib/write";
// Generate `build` object
const build: Build = {};

build.version = await version();
build.version = await version(args["package-json"]);
build.timestamp = new Date().toString();
build.message =
args.message || (args.message === "" ? await message() : null);
Expand All @@ -35,7 +35,7 @@ import write from "./src/lib/write";
};

// Write Build information to file
await write(build);
await write(build, args["output-file"]);

console.log("");
signale.success("Saved Build Information");
Expand Down
132 changes: 74 additions & 58 deletions package-lock.json

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

10 changes: 10 additions & 0 deletions src/lib/arguments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ const args = yargs(process.argv)
type: "boolean",
description: "Specify to skip git information",
})
.option("package-json", {
alias: "p",
type: "string",
description: "Specify location of `package.json`",
})
.option("output-file", {
alias: "o",
type: "string",
description: "Specify location of generated `build.ts` file",
})
.help().argv;

export default args;
11 changes: 8 additions & 3 deletions src/modules/version.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
const version = require(`${process.cwd()}/package.json`)?.version;
import { promises as fs } from "fs";

const getVersion = async (): Promise<string | null> => {
return version || null;
const getVersion = async (path?: string): Promise<string | null> => {
const read = await fs.readFile(
path || `${process.cwd()}/package.json`,
{ encoding: "utf-8" }
);

return JSON.parse(read)?.version || null;
};

export default getVersion;