Skip to content

Commit

Permalink
feat(actions): remove needless "commitlint" workflow if exists (#1263)
Browse files Browse the repository at this point in the history
  • Loading branch information
ybiquitous authored May 11, 2022
1 parent 2a89182 commit acaba94
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
16 changes: 15 additions & 1 deletion lib/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ const initCommand = (baseDir, logger) => {
logger(`=> ${emphasize(relative(baseDir, file))} was updated`);
};

/**
* @param {string} firstPath
* @param {string[]} restPath
*/
const removeForcibly = async (firstPath, ...restPath) => {
await rm(currentPath(firstPath, ...restPath), { force: true });
};

return {
// eslint-disable-next-line max-statements, max-lines-per-function
async updatePackageFile() {
Expand Down Expand Up @@ -128,7 +136,12 @@ const initCommand = (baseDir, logger) => {
// NOTE: husky v7 no longer requires `.husky/.gitignore`.
// See https://github.com/typicode/husky/releases/tag/v7.0.0
async removeNeedlessHuskyIgnore() {
await rm(currentPath(".husky", ".gitignore"), { force: true });
await removeForcibly(".husky", ".gitignore");
},

// See https://github.com/ybiquitous/ybiq/pull/1257
async removeNeedlessCommitlintWorkflow() {
await removeForcibly(".github", "workflows", "commitlint.yml");
},
};
};
Expand All @@ -150,6 +163,7 @@ export async function init({ cwd = process.cwd(), logger = defaultLogger } = {})
await cmd.writePackageFile(".husky", "pre-commit");

await cmd.removeNeedlessHuskyIgnore();
await cmd.removeNeedlessCommitlintWorkflow();
}

export const command = "init";
Expand Down
11 changes: 11 additions & 0 deletions test/init.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,14 @@ test("Remove `.husky/.gitignore` if exists", () =>

expect(existsSync(join(ctx.workDir, ".husky", ".gitignore"))).toEqual(false);
}));

test("Remove `.github/workflows/commitlint.yml` if exists", () =>
sandbox(async (ctx) => {
mkdirSync(join(ctx.workDir, ".github", "workflows"), { recursive: true });
writeFileSync(join(ctx.workDir, ".github", "workflows", "commitlint.yml"), "dummy: 1");
writeFileSync(join(ctx.workDir, "package.json"), "{}");

await init(ctx.initArgs);

expect(existsSync(join(ctx.workDir, ".github", "workflows", "commitlint.yml"))).toEqual(false);
}));

0 comments on commit acaba94

Please sign in to comment.