Files
leaysgur b4e8605a4d refactor(oxfmt): Clean up src-js files and directories (#17040)
```
.
├── 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.
2025-12-18 10:44:28 +00:00

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`.");
}
}