Skip to content

Commit

Permalink
prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
stopachka committed Nov 25, 2024
1 parent 0a080b8 commit 40da48d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
18 changes: 14 additions & 4 deletions client/packages/cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
getInstallCommand,
} from "./src/util/packageManager.js";
import { pathExists, readJsonFile } from "./src/util/fs.js";
import prettier from 'prettier';

const execAsync = promisify(exec);

Expand Down Expand Up @@ -603,6 +604,15 @@ async function detectOrCreateAppWithErrorLogging(opts) {
return await promptImportAppOrCreateApp();
}

async function writeTypescript(path, content, encoding) {
const prettierConfig = await prettier.resolveConfig(path);
const formattedCode = await prettier.format(content, {
...prettierConfig,
parser: 'typescript',
});
return await writeFile(path, formattedCode, encoding);
}

async function handleCreatedApp(
{ pkgDir, instantModuleName },
appId,
Expand All @@ -618,7 +628,7 @@ async function handleCreatedApp(

if (!schema) {
const schemaPath = join(pkgDir, "instant.schema.ts");
await writeFile(
await writeTypescript(
schemaPath,
instantSchemaTmpl(appTitle, appId, instantModuleName),
"utf-8",
Expand All @@ -627,7 +637,7 @@ async function handleCreatedApp(
}

if (!perms) {
await writeFile(
await writeTypescript(
join(pkgDir, "instant.perms.ts"),
examplePermsTmpl,
"utf-8",
Expand Down Expand Up @@ -719,7 +729,7 @@ async function pullSchema(appId, { pkgDir, instantModuleName }) {
}

const schemaPath = join(pkgDir, "instant.schema.ts");
await writeFile(
await writeTypescript(
schemaPath,
generateSchemaTypescriptFile(
appId,
Expand Down Expand Up @@ -760,7 +770,7 @@ async function pullPerms(appId, { pkgDir }) {
}

const permsPath = join(pkgDir, "instant.perms.ts");
await writeFile(
await writeTypescript(
permsPath,
`export default ${JSON.stringify(pullRes.data.perms, null, " ")};`,
"utf-8",
Expand Down
1 change: 1 addition & 0 deletions client/packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"open": "^10.1.0",
"ora": "^8.1.1",
"pkg-dir": "^8.0.0",
"prettier": "^3.3.3",
"terminal-link": "^3.0.0",
"unconfig": "^0.5.5"
}
Expand Down
4 changes: 3 additions & 1 deletion client/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 40da48d

Please sign in to comment.