-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprepare.ts
executable file
·52 lines (39 loc) · 1.24 KB
/
prepare.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env -S yarn pnpify ts-node -T --esm
import { $, argv, chalk, echo, fs, which } from "zx";
const skipLocal = argv["ci"];
const VSCODE_PATH = "./.vscode";
const VSCODE_SETTINGS_TEMPLATE = `${VSCODE_PATH}/settings-template.json`;
const VSCODE_SETTINGS = `${VSCODE_PATH}/settings.json`;
echo(`prepare.ts: Preparing workspace`);
async function prepareVSCode() {
if (skipLocal) return;
if (!fs.existsSync(VSCODE_SETTINGS)) {
echo(
`prepare.ts: ${chalk.blue("Copying VS Code template settings")} into ${VSCODE_SETTINGS}... `,
);
await fs.copyFile(VSCODE_SETTINGS_TEMPLATE, VSCODE_SETTINGS);
} else {
echo(
`prepare.ts: ${chalk.blue(
"VS Code workspace settings found",
)} - skipped overwriting them (see ${VSCODE_SETTINGS_TEMPLATE})`,
);
}
}
async function prepareCommitHooks() {
try {
await which("poetry");
} catch {
echo(
`prepare.ts: ${chalk.red(
"Failed",
)} - you must install poetry - see https://python-poetry.org/docs/#installation for a guide`,
);
process.exit(1);
}
echo(`prepare.ts: Installing commit hooks`);
await $`poetry install --no-interaction`;
if (!skipLocal) await $`poetry run pre-commit install -t commit-msg -t pre-commit`;
}
await prepareVSCode();
await prepareCommitHooks();