Skip to content

Commit b6b4c17

Browse files
committed
feat: oxfmt action
1 parent 0160052 commit b6b4c17

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

actions/unjs/oxfmt.ts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import { defineAction } from "codeup";
2+
3+
// https://prettier.io/docs/configuration
4+
const PRETTIER_CONFIG_FILES = [
5+
".prettierrc",
6+
".prettierrc.json",
7+
".prettierrc.yml",
8+
".prettierrc.yaml",
9+
".prettierrc.json5",
10+
".prettierrc.js",
11+
".prettierrc.mjs",
12+
".prettierrc.cjs",
13+
".prettierrc.toml",
14+
"prettier.config.js",
15+
"prettier.config.mjs",
16+
"prettier.config.cjs",
17+
".prettierignore",
18+
];
19+
20+
export default defineAction({
21+
meta: {
22+
name: "oxfmt",
23+
description: "Switch from Prettier to oxfmt",
24+
date: "2026-01-29",
25+
},
26+
async filter({ utils }) {
27+
// Only apply if .prettierrc (with any extension) exists
28+
return await utils.existsWithAnyExt(".prettierrc");
29+
},
30+
async apply({ utils }) {
31+
// Remove prettier from devDependencies
32+
const packageJson = await utils.readPackageJSON();
33+
if (packageJson?.devDependencies?.prettier) {
34+
await utils.removeDependency("prettier");
35+
}
36+
37+
// Remove all prettier config files
38+
for (const file of PRETTIER_CONFIG_FILES) {
39+
await utils.remove(file);
40+
}
41+
42+
// Create .oxfmtrc.json (only if not exists)
43+
await utils.write(
44+
".oxfmtrc.json",
45+
JSON.stringify(
46+
{
47+
$schema: "https://unpkg.com/oxfmt/configuration_schema.json",
48+
},
49+
null,
50+
2,
51+
),
52+
{ skipIfExists: true },
53+
);
54+
55+
// Install oxfmt as dev dependency
56+
await utils.addDevDependency("oxfmt");
57+
},
58+
});

0 commit comments

Comments
 (0)