mirror of
https://github.com/shumadrid/obsidian-git-changelog.git
synced 2026-07-22 05:42:16 +00:00
chore: add prettier formatting scripts
This commit is contained in:
parent
c96e65f94e
commit
633a8f5f82
3 changed files with 35 additions and 0 deletions
7
scripts/format-check.ts
Normal file
7
scripts/format-check.ts
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
/* eslint-disable unicorn/filename-case */
|
||||
|
||||
import { formatWithPrettier } from './formatWithPrettier.ts';
|
||||
|
||||
export async function invoke(): Promise<void> {
|
||||
await formatWithPrettier(false);
|
||||
}
|
||||
5
scripts/format.ts
Normal file
5
scripts/format.ts
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
import { formatWithPrettier } from './formatWithPrettier.ts';
|
||||
|
||||
export async function invoke(): Promise<void> {
|
||||
await formatWithPrettier(true);
|
||||
}
|
||||
23
scripts/formatWithPrettier.ts
Normal file
23
scripts/formatWithPrettier.ts
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
import { getDirname } from 'obsidian-dev-utils/Path';
|
||||
import { existsSync } from 'obsidian-dev-utils/ScriptUtils/NodeModules';
|
||||
import {
|
||||
execFromRoot,
|
||||
getRootDir,
|
||||
resolvePathFromRootSafe
|
||||
} from 'obsidian-dev-utils/ScriptUtils/Root';
|
||||
|
||||
export async function formatWithPrettier(rewrite: boolean): Promise<void> {
|
||||
// Modified from https://github.com/mnaoumov/obsidian-dev-utils/blob/main/src/ScriptUtils/format.ts
|
||||
|
||||
const prettierJsonPath = resolvePathFromRootSafe('.prettierrc.json');
|
||||
if (!existsSync(prettierJsonPath)) {
|
||||
const packageDirectory = getRootDir(getDirname(import.meta.url));
|
||||
if (!packageDirectory) {
|
||||
throw new Error('Could not find package directory.');
|
||||
}
|
||||
throw new Error('.prettierrc.json not found');
|
||||
}
|
||||
|
||||
const command = rewrite ? '--write' : '--check';
|
||||
await execFromRoot(['npx', 'prettier', '.', command]);
|
||||
}
|
||||
Loading…
Reference in a new issue