Skip to content

Commit f26b136

Browse files
authored
style: setup prettier (#22)
1 parent 7f07846 commit f26b136

File tree

8 files changed

+482
-44
lines changed

8 files changed

+482
-44
lines changed

.github/workflows/check.yml

+3
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,8 @@ jobs:
4848
- name: 📦 Install dependencies
4949
run: pnpm install
5050

51+
- name: 🔍 Check formatting
52+
run: pnpm format:check
53+
5154
- name: 🛠️ Build
5255
run: pnpm docs:build

.prettierignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Prettier ignores all files inside .gitignore by default so this file only contains
2+
# files that are checked into git but should not be formatted
3+
pnpm-lock.yaml
4+
CHANGELOG.md

.prettierrc.json

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"$schema": "https://json.schemastore.org/prettierrc",
3+
"printWidth": 100
4+
}

cli/src/commands/deploy.command.ts

+8-21
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,21 @@ import { cli } from "..";
44
import { cloneOrPullRepo } from "../utils/git";
55

66
export const deployCommand = new Command("deploy")
7-
.description(
8-
"Clone or pull latest git repository and (re)build docker-compose.yml"
9-
)
7+
.description("Clone or pull latest git repository and (re)build docker-compose.yml")
108
.argument("<url>", "URL of the git repository")
11-
.option(
12-
"-b, --branch <branch>",
13-
"Branch name to checkout before deploying",
14-
"main"
15-
)
9+
.option("-b, --branch <branch>", "Branch name to checkout before deploying", "main")
1610
.option(
1711
"-d, --dir <dir>",
1812
"Directory where the git repository should be cloned in. Will create a subfolder inside this directory (see option --folder)",
19-
"./applications"
13+
"./applications",
2014
)
2115
.option(
2216
"-f, --folder <folder>",
23-
"Folder name inside the applications directory that the repo is cloned to. If not provided, repository name will be used"
17+
"Folder name inside the applications directory that the repo is cloned to. If not provided, repository name will be used",
2418
)
2519
.option(
2620
"-r, --root <root>",
27-
"Root directory inside the git repository where the docker-compose.yml is located that should be deployed. If not provided, repository root (.) will be used"
21+
"Root directory inside the git repository where the docker-compose.yml is located that should be deployed. If not provided, repository root (.) will be used",
2822
)
2923
.action(async (url: string, options: OptionValues) => {
3024
if (!shell.which("git") || !shell.which("docker-compose")) {
@@ -36,10 +30,7 @@ export const deployCommand = new Command("deploy")
3630
const folderName = options.folder as string | undefined;
3731
const root = options.root as string | undefined;
3832

39-
if (
40-
folderName &&
41-
(folderName.startsWith(".") || folderName.includes("/"))
42-
) {
33+
if (folderName && (folderName.startsWith(".") || folderName.includes("/"))) {
4334
return cli.error(`Folder name "${folderName}" is invalid`);
4435
}
4536

@@ -55,9 +46,7 @@ export const deployCommand = new Command("deploy")
5546
return cli.error("URL must start with https://");
5647
}
5748

58-
shell.echo(
59-
`Deploying git repository "${url}" with branch "${branch}"...\n`
60-
);
49+
shell.echo(`Deploying git repository "${url}" with branch "${branch}"...\n`);
6150

6251
try {
6352
const repoPath = await cloneOrPullRepo(url, applicationsDir, folderName);
@@ -71,9 +60,7 @@ export const deployCommand = new Command("deploy")
7160
shell.echo(`Rebuilding docker-compose.yml...`);
7261
if (
7362
shell.exec(
74-
`${
75-
root ? `cd ${root} &&` : ""
76-
} docker-compose -f ./docker-compose.yml up -d --build`
63+
`${root ? `cd ${root} &&` : ""} docker-compose -f ./docker-compose.yml up -d --build`,
7764
).code !== 0
7865
) {
7966
cli.error(`Error: docker-compose rebuild failed`);

cli/src/utils/git.ts

+4-10
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { exists } from "./shell";
66
export async function cloneOrPullRepo(
77
url: string,
88
path: string,
9-
folderName?: string
9+
folderName?: string,
1010
): Promise<string> {
1111
folderName ||= basename(url);
1212
const repoPath = join(path, folderName);
@@ -16,21 +16,15 @@ export async function cloneOrPullRepo(
1616
}
1717

1818
if (!exists(repoPath)) {
19-
shell.echo(
20-
`Application "${folderName}" is deployed for the first time. Cloning repository.`
21-
);
19+
shell.echo(`Application "${folderName}" is deployed for the first time. Cloning repository.`);
2220
if (shell.exec(`cd ${path} && git clone ${url} ${folderName}`).code !== 0) {
2321
cli.error(`Error: Git clone repository failed`);
2422
}
2523
} else {
26-
const { stdout: gitUrl } = shell.exec(
27-
`cd ${repoPath} && git config --get remote.origin.url`
28-
);
24+
const { stdout: gitUrl } = shell.exec(`cd ${repoPath} && git config --get remote.origin.url`);
2925

3026
if (!gitUrl.includes(url)) {
31-
cli.error(
32-
`A different application with name "${folderName}" does already exist`
33-
);
27+
cli.error(`A different application with name "${folderName}" does already exist`);
3428
}
3529

3630
shell.echo("Pulling latest git changes.");

cli/tsconfig.json

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
{
2-
"compilerOptions": {
3-
"target": "ES2020",
4-
"module": "commonjs",
5-
"esModuleInterop": true,
6-
"forceConsistentCasingInFileNames": true,
7-
"strict": true,
8-
"skipLibCheck": true,
9-
"outDir": "bin",
10-
"rootDir": "src",
11-
"importHelpers": false
12-
},
13-
"include": ["src"]
2+
"compilerOptions": {
3+
"target": "ES2020",
4+
"module": "commonjs",
5+
"esModuleInterop": true,
6+
"forceConsistentCasingInFileNames": true,
7+
"strict": true,
8+
"skipLibCheck": true,
9+
"outDir": "bin",
10+
"rootDir": "src",
11+
"importHelpers": false
12+
},
13+
"include": ["src"]
1414
}

package.json

+13-1
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,21 @@
1515
"docs:dev": "vitepress dev docs",
1616
"docs:build": "vitepress build docs",
1717
"docs:serve": "vitepress serve docs",
18-
"preinstall": "npx only-allow pnpm"
18+
"format": "prettier . --write",
19+
"format:check": "prettier . --check",
20+
"preinstall": "npx only-allow pnpm",
21+
"prepare": "simple-git-hooks"
1922
},
2023
"devDependencies": {
24+
"lint-staged": "^15.2.2",
25+
"prettier": "^3.2.5",
26+
"simple-git-hooks": "^2.11.1",
2127
"vitepress": "^1.1.4"
28+
},
29+
"simple-git-hooks": {
30+
"pre-commit": "pnpm lint-staged"
31+
},
32+
"lint-staged": {
33+
"*": "prettier --write -u"
2234
}
2335
}

0 commit comments

Comments
 (0)