Skip to content

Commit

Permalink
feat: implement verifyConditions step
Browse files Browse the repository at this point in the history
  • Loading branch information
sheerlox committed Nov 18, 2023
1 parent 4f71478 commit a8e0763
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
3 changes: 3 additions & 0 deletions lib/helpers/regexs.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ export const semVerRegex = new RegExp(

export const regularVersionRegex = composeSemverRegex(/\bversion:\s*"/, /"/);
export const attributeVersionRegex = composeSemverRegex(/@version\s+"/, /"/);
export const allVersionRegexs = new RegExp(
regularVersionRegex.source + "|" + attributeVersionRegex.source,
);

function composeSemverRegex(head, tail) {
return new RegExp(
Expand Down
28 changes: 27 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,35 @@
/* eslint-disable no-unused-vars */
import SemanticReleaseError from "@semantic-release/error";
import fs from "node:fs";
import path from "node:path";
import { allVersionRegexs } from "./helpers/regexs";

let verified;
let prepared;

export async function verifyConditions(pluginConfig, context) {
export async function verifyConditions(_, context) {
const { cwd } = context;

const projectPath = path.resolve(cwd, "mix.exs");

if (!fs.existsSync(projectPath)) {
throw new SemanticReleaseError(
"mix.exs not found in the current working directory",
"ENOPROJECT",
);
}

const projectContent = fs.readFileSync(projectPath, {
encoding: "utf-8",
});

if (!projectContent.match(allVersionRegexs)) {
throw new SemanticReleaseError(
"no version was found in mix.exs",
"ENOVERSION",
);
}

verified = true;
}

Expand Down

0 comments on commit a8e0763

Please sign in to comment.