mirror of
https://github.com/oxc-project/oxc.git
synced 2026-09-14 19:36:11 +08:00
b4e8605a4d
```
.
├── bindings.d.ts
├── bindings.js
├── cli
│ ├── migration
│ │ ├── init.ts
│ │ ├── migrate-prettier.ts
│ │ └── shared.ts
│ └── worker-proxy.ts
├── cli-worker.ts # CLI worker endpoint
├── cli.ts # CLI endpoint
├── index.ts # API endpoint
└── libs
└── prettier.ts # Core logic shared by index, cli-worker, cli/worker-proxy
```
By doing this, Node.js API `format()` does not use `worker_threads` anymore.
28 lines
764 B
TypeScript
28 lines
764 B
TypeScript
/* oxlint-disable no-console */
|
|
|
|
import { hasOxfmtrcFile, createBlankOxfmtrcFile, saveOxfmtrcFile, exitWithError } from "./shared";
|
|
|
|
/**
|
|
* Run the `--init` command to scaffold a default `.oxfmtrc.json` file.
|
|
*/
|
|
export async function runInit() {
|
|
const cwd = process.cwd();
|
|
|
|
if (await hasOxfmtrcFile(cwd)) {
|
|
return exitWithError("Oxfmt configuration file already exists.");
|
|
}
|
|
|
|
// Create blank config
|
|
const oxfmtrc = await createBlankOxfmtrcFile(cwd);
|
|
const jsonStr = JSON.stringify(oxfmtrc, null, 2);
|
|
|
|
// TODO: Create napi `validateConfig()` and use to ensure validity?
|
|
|
|
try {
|
|
await saveOxfmtrcFile(cwd, jsonStr);
|
|
console.log("Created `.oxfmtrc.json`.");
|
|
} catch {
|
|
return exitWithError("Failed to create `.oxfmtrc.json`.");
|
|
}
|
|
}
|