Skip to content

Commit 090ffa2

Browse files
millotpshortcuts
authored andcommitted
test
1 parent 7c0c8ba commit 090ffa2

File tree

6 files changed

+54
-9
lines changed

6 files changed

+54
-9
lines changed

.husky/pre-commit

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/bin/sh
22
. "$(dirname "$0")/_/husky.sh"
33

4-
./scripts/ci/husky/pre-commit.js
4+
./scripts/husky/pre-commit.js
5+
./scripts/husky/format-generators.js

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"clean": "rm -rf **/dist **/build **/node_modules **/.gradle **/vendor || true",
1414
"cli": "yarn workspace scripts ts-node --transpile-only ./cli/index.ts",
1515
"docker": "docker exec -it dev yarn cli $*",
16+
"docker:no-tty": "docker exec -t dev yarn cli $*",
1617
"docker:build": "./scripts/docker/build.sh",
1718
"docker:clean": "docker stop dev; docker rm -f dev; docker image rm -f api-clients-automation",
1819
"docker:mount": "./scripts/docker/mount.sh",

scripts/husky/format-generators.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env node
2+
/* eslint-disable @typescript-eslint/no-var-requires */
3+
/* eslint-disable import/no-commonjs */
4+
const { exit } = require('process');
5+
6+
const ora = require('ora-classic');
7+
8+
const { run } = require('./utils');
9+
10+
async function formatGenerators() {
11+
const diff = (await run('git diff --name-only --cached -- generators')).split(
12+
'\n'
13+
);
14+
if (diff.length === 0 || diff[0].trim() === '') {
15+
return;
16+
}
17+
const spinner = ora('Linting generators').start();
18+
try {
19+
await run('yarn docker:no-tty format java generators');
20+
await run(`git add ${diff.join(' ')}`);
21+
} catch (e) {
22+
// eslint-disable-next-line no-console
23+
console.log(e);
24+
spinner.fail('Failed to format generators');
25+
exit(1);
26+
}
27+
spinner.succeed();
28+
}
29+
30+
if (require.main === module && process.env.CI !== 'true') {
31+
formatGenerators();
32+
}

scripts/ci/husky/pre-commit.js renamed to scripts/husky/pre-commit.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,13 @@
33
/* eslint-disable import/no-commonjs */
44
/* eslint-disable @typescript-eslint/no-var-requires */
55
const chalk = require('chalk');
6-
const execa = require('execa');
76
const micromatch = require('micromatch');
87

9-
const clientConfig = require('../../../config/clients.config.json');
8+
const clientConfig = require('../../config/clients.config.json');
109
const GENERATED_FILE_PATTERNS =
11-
require('../../../config/generation.config').patterns;
10+
require('../../config/generation.config').patterns;
1211

13-
const run = async (command, { cwd } = {}) => {
14-
return (
15-
(await execa.command(command, { shell: 'bash', all: true, cwd })).all ?? ''
16-
);
17-
};
12+
const { run } = require('./utils');
1813

1914
function getPatterns() {
2015
const patterns = GENERATED_FILE_PATTERNS;

scripts/husky/utils.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/* eslint-disable import/no-commonjs */
2+
/* eslint-disable @typescript-eslint/no-var-requires */
3+
const execa = require('execa');
4+
5+
async function run(command) {
6+
return (
7+
(
8+
await execa.command(command, {
9+
shell: 'bash',
10+
all: true,
11+
})
12+
).all ?? ''
13+
);
14+
}
15+
16+
module.exports = { run };

0 commit comments

Comments
 (0)