Skip to content

Commit f8e356c

Browse files
committed
feat(editorconfig): scaffold editorconfig when lifting if not already in use
1 parent f8e38fb commit f8e356c

2 files changed

Lines changed: 28 additions & 11 deletions

File tree

src/lift.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,14 @@ import {applyEnhancers} from '@form8ion/core';
22
import {lift as liftReadme} from '@form8ion/readme';
33
import * as gitPlugin from '@form8ion/git';
44

5+
import {scaffold as scaffoldEditorconfig, test as editorconfigInUse} from './editorconfig/index.js';
56
import * as licensePlugin from './license/index.js';
67

78
export default async function ({projectRoot, results, enhancers, vcs, dependencies}) {
9+
if (!await editorconfigInUse({projectRoot})) {
10+
await scaffoldEditorconfig({projectRoot});
11+
}
12+
813
const enhancerResults = await applyEnhancers({
914
results,
1015
enhancers: {...enhancers, gitPlugin, licensePlugin},

src/lift.test.js

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,28 @@ import * as core from '@form8ion/core';
22
import * as readme from '@form8ion/readme';
33
import * as gitPlugin from '@form8ion/git';
44

5-
import {afterEach, describe, expect, it, vi} from 'vitest';
5+
import {beforeEach, describe, expect, it, vi} from 'vitest';
66
import any from '@travi/any';
77
import {when} from 'vitest-when';
88

9+
import {scaffold as scaffoldEditorconfig, test as editorconfigInUse} from './editorconfig/index.js';
910
import * as licensePlugin from './license/index.js';
1011
import lift from './lift.js';
1112

1213
vi.mock('deepmerge');
1314
vi.mock('@form8ion/core');
1415
vi.mock('@form8ion/readme');
16+
vi.mock('./editorconfig/index.js');
1517

1618
describe('lift', () => {
17-
afterEach(() => {
18-
vi.clearAllMocks();
19-
});
19+
const projectRoot = any.string();
20+
const results = any.simpleObject();
21+
const enhancers = any.simpleObject();
22+
const vcs = any.simpleObject();
23+
const dependencies = any.simpleObject();
24+
const enhancerResults = any.simpleObject();
2025

21-
it('should lift the README based on the provided results', async () => {
22-
const projectRoot = any.string();
23-
const enhancers = any.simpleObject();
24-
const dependencies = any.simpleObject();
25-
const vcs = any.simpleObject();
26-
const results = any.simpleObject();
27-
const enhancerResults = any.simpleObject();
26+
beforeEach(() => {
2827
when(core.applyEnhancers)
2928
.calledWith({
3029
results,
@@ -33,8 +32,21 @@ describe('lift', () => {
3332
dependencies
3433
})
3534
.thenResolve(enhancerResults);
35+
});
36+
37+
it('should lift the README based on the provided results', async () => {
38+
when(editorconfigInUse).calledWith({projectRoot}).thenResolve(true);
3639

3740
expect(await lift({projectRoot, results, enhancers, vcs, dependencies})).toEqual(enhancerResults);
3841
expect(readme.lift).toHaveBeenCalledWith({projectRoot, results: enhancerResults});
42+
expect(scaffoldEditorconfig).not.toHaveBeenCalled();
43+
});
44+
45+
it('should scaffold editorconfig when it isnt already in use', async () => {
46+
when(editorconfigInUse).calledWith({projectRoot}).thenResolve(false);
47+
48+
await lift({projectRoot, results, enhancers, vcs, dependencies});
49+
50+
expect(scaffoldEditorconfig).toHaveBeenCalledWith({projectRoot});
3951
});
4052
});

0 commit comments

Comments
 (0)