Skip to content

Commit 7ee1cc3

Browse files
authored
Merge pull request #25 from acrontum/enh/smaller-boatsrc
enh/smaller-boatsrc
2 parents 446e492 + 39aec20 commit 7ee1cc3

File tree

9 files changed

+40
-71
lines changed

9 files changed

+40
-71
lines changed

eslint.config.mjs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,18 @@ export default [
55
{
66
rules: {
77
'@typescript-eslint/restrict-template-expressions': ['error', { allowNumber: true }],
8+
'@typescript-eslint/no-unused-vars': [
9+
'error',
10+
{
11+
args: 'all',
12+
argsIgnorePattern: '^_',
13+
caughtErrors: 'all',
14+
caughtErrorsIgnorePattern: '^_',
15+
destructuredArrayIgnorePattern: '^_',
16+
varsIgnorePattern: '^_',
17+
ignoreRestSiblings: true,
18+
},
19+
],
820
},
921
},
1022
];

src/templates/init.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,11 @@ export const getBoatsRc = (): string => {
4040
return (
4141
JSON.stringify(
4242
{
43-
nunjucksOptions: {
44-
// this empty object just needs to exist, otherwise boats explodes
45-
tags: {},
46-
},
4743
picomatchOptions: {
4844
bash: true,
4945
},
50-
permissionConfig: {
51-
globalPrefix: true,
52-
},
53-
paths: {
54-
'@shared/': '../shared/',
55-
},
5646
fancyPluralization: true,
47+
paths: {},
5748
},
5849
null,
5950
2,

test/boats.ts

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import { default as template } from 'boats/build/src/Template';
22
import { default as bundlerSwaggerParse } from 'boats/build/src/bundlerSwaggerParse';
33
import { BoatsRC } from 'boats/build/src/interfaces/BoatsRc';
4+
import { access, readFile } from 'fs/promises';
45
import { dirname } from 'path';
56
import pj from '../package.json';
7+
import { getBoatsRc } from '../src/templates/init';
68

79
export type ErrorWithLogs = Error & { code: string; logs: unknown[] };
810

@@ -12,14 +14,6 @@ type ConsoleMock = {
1214
unmock: () => void;
1315
};
1416

15-
export const defaultBoats: BoatsRC = {
16-
nunjucksOptions: { tags: {} },
17-
picomatchOptions: { bash: true },
18-
permissionConfig: { globalPrefix: true },
19-
paths: {},
20-
fancyPluralization: true,
21-
};
22-
2317
const mockConsoleLog = (): ConsoleMock => {
2418
/* eslint-disable no-console */
2519
const olog = console.log;
@@ -74,19 +68,31 @@ const overridePackageJsonReader = (): void => {
7468
};
7569
};
7670

71+
const defaultBoatsRc = JSON.parse(getBoatsRc()) as BoatsRC;
72+
7773
export const boats = async (inFile: string, outFile: string, validate = true): Promise<string> => {
7874
const trim = dirname(inFile) + '/paths/';
75+
const customBoatsRcPath = dirname(dirname(inFile)) + '/.boatsrc';
76+
let boatsRc = defaultBoatsRc;
77+
try {
78+
const hasBoatsRc = await access(customBoatsRcPath)
79+
.then(() => true)
80+
.catch(() => false);
81+
if (hasBoatsRc) {
82+
boatsRc = JSON.parse(await readFile(customBoatsRcPath, { encoding: 'utf8' })) as BoatsRC;
83+
}
84+
} catch (_e: unknown) {}
7985

8086
overridePackageJsonReader();
8187
// overwrite console during testing - no debug output needed
8288
const con = mockConsoleLog();
8389

8490
try {
85-
const indexFile = template.directoryParse(inFile, outFile, null as unknown as number, trim, [], [], defaultBoats, false);
91+
const indexFile = template.directoryParse(inFile, outFile, null as unknown as number, trim, [], [], boatsRc, false);
8692
const outApiFile = await bundlerSwaggerParse({
8793
inputFile: indexFile,
8894
outputFile: outFile,
89-
boatsRc: defaultBoats,
95+
boatsRc,
9096
dereference: false,
9197
doNotValidate: !validate,
9298
excludeVersion: false,

test/e2e.spec.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,11 @@ describe('e2e.spec.ts', async () => {
2626
content,
2727
trimIndent`\
2828
{
29-
"nunjucksOptions": {
30-
"tags": {}
31-
},
3229
"picomatchOptions": {
3330
"bash": true
3431
},
35-
"permissionConfig": {
36-
"globalPrefix": true
37-
},
38-
"paths": {
39-
"@shared/": "../shared/"
40-
},
41-
"fancyPluralization": true
32+
"fancyPluralization": true,
33+
"paths": {}
4234
}
4335
`,
4436
);

test/fixtures/e2e/gen1/.boatsrc

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,7 @@
11
{
2-
"nunjucksOptions": {
3-
"tags": {}
4-
},
52
"picomatchOptions": {
63
"bash": true
74
},
8-
"permissionConfig": {
9-
"globalPrefix": true
10-
},
11-
"paths": {
12-
"@shared/": "../shared/"
13-
},
14-
"fancyPluralization": true
5+
"fancyPluralization": true,
6+
"paths": {}
157
}

test/fixtures/e2e/gen2/.boatsrc

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,7 @@
11
{
2-
"nunjucksOptions": {
3-
"tags": {}
4-
},
52
"picomatchOptions": {
63
"bash": true
74
},
8-
"permissionConfig": {
9-
"globalPrefix": true
10-
},
11-
"paths": {
12-
"@shared/": "../shared/"
13-
},
14-
"fancyPluralization": true
5+
"fancyPluralization": true,
6+
"paths": {}
157
}

test/model.spec.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,19 +60,11 @@ describe('model.spec.ts', async () => {
6060
await getFile('test/output/model/.boatsrc'),
6161
trimIndent`\
6262
{
63-
"nunjucksOptions": {
64-
"tags": {}
65-
},
6663
"picomatchOptions": {
6764
"bash": true
6865
},
69-
"permissionConfig": {
70-
"globalPrefix": true
71-
},
72-
"paths": {
73-
"@shared/": "../shared/"
74-
},
75-
"fancyPluralization": true
66+
"fancyPluralization": true,
67+
"paths": {}
7668
}
7769
`,
7870
);

test/path.spec.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,19 +70,11 @@ describe('path.spec.ts', async () => {
7070
await getFile('test/output/path/.boatsrc'),
7171
trimIndent`\
7272
{
73-
"nunjucksOptions": {
74-
"tags": {}
75-
},
7673
"picomatchOptions": {
7774
"bash": true
7875
},
79-
"permissionConfig": {
80-
"globalPrefix": true
81-
},
82-
"paths": {
83-
"@shared/": "../shared/"
84-
},
85-
"fancyPluralization": true
76+
"fancyPluralization": true,
77+
"paths": {}
8678
}
8779
`,
8880
);

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@
1616
"strictNullChecks": true
1717
},
1818
"include": ["src", "test"],
19-
"exclude": ["node_modules"]
19+
"exclude": ["node_modules", "test/output"]
2020
}

0 commit comments

Comments
 (0)