Skip to content

Commit 5cc5fb7

Browse files
committed
feat(commitlint): switched generated config file from js to json
to improve esm compatibility and simplify lifting
1 parent eb8eb06 commit 5cc5fb7

File tree

7 files changed

+86
-12
lines changed

7 files changed

+86
-12
lines changed

package-lock.json

Lines changed: 41 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
"provenance": true
5858
},
5959
"dependencies": {
60+
"@form8ion/config-file": "^1.0.1",
6061
"@form8ion/core": "^2.0.0",
6162
"@form8ion/javascript-core": "^9.0.0",
6263
"deepmerge": "^4.2.2",

src/commitlint-test.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
import {promises as fsPromises} from 'fs';
1+
import {fileTypes} from '@form8ion/core';
2+
import * as configFile from '@form8ion/config-file';
3+
24
import any from '@travi/any';
35
import {assert} from 'chai';
46
import sinon from 'sinon';
7+
58
import scaffoldCommitlint from './commitlint';
69

710
suite('commitlint scaffolder', () => {
@@ -10,7 +13,7 @@ suite('commitlint scaffolder', () => {
1013
setup(() => {
1114
sandbox = sinon.createSandbox();
1215

13-
sandbox.stub(fsPromises, 'writeFile');
16+
sandbox.stub(configFile, 'write');
1417
});
1518

1619
teardown(() => sandbox.restore());
@@ -25,9 +28,13 @@ suite('commitlint scaffolder', () => {
2528
{devDependencies: [configPackageName]}
2629
);
2730
assert.calledWith(
28-
fsPromises.writeFile,
29-
`${projectRoot}/.commitlintrc.js`,
30-
`module.exports = {extends: ['${configName}']};`
31+
configFile.write,
32+
{
33+
format: fileTypes.JSON,
34+
name: 'commitlint',
35+
config: {extends: [configName]},
36+
path: projectRoot
37+
}
3138
);
3239
});
3340
});

src/commitlint.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1-
import {promises as fsPromises} from 'fs';
1+
import {fileTypes} from '@form8ion/core';
2+
import {write} from '@form8ion/config-file';
23

34
export default async function ({config, projectRoot}) {
4-
await fsPromises.writeFile(`${projectRoot}/.commitlintrc.js`, `module.exports = {extends: ['${config.name}']};`);
5+
await write({
6+
format: fileTypes.JSON,
7+
name: 'commitlint',
8+
path: projectRoot,
9+
config: {extends: [config.name]}
10+
});
511

612
return {devDependencies: [config.packageName]};
713
}

test/integration/features/scaffolder.feature

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
Feature: Scaffolder
22

3+
Scenario: configure the convention
4+
When the project is scaffolded
5+
Then commitlint will be configured
6+
37
Scenario: project not on github actions
48
When the project is scaffolded
59

test/integration/features/step_definitions/common-steps.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
import {resolve} from 'path';
22
import {dump} from 'js-yaml';
33

4-
import {After, When} from '@cucumber/cucumber';
4+
import {After, Before, When} from '@cucumber/cucumber';
55
import stubbedFs from 'mock-fs';
66
import any from '@travi/any';
77

88
const stubbedNodeModules = stubbedFs.load(resolve(__dirname, '..', '..', '..', '..', 'node_modules'));
9-
const projectRoot = process.cwd();
9+
10+
Before(function () {
11+
this.projectRoot = process.cwd();
12+
this.commilintConfigName = `@${any.word()}`;
13+
});
1014

1115
After(function () {
1216
stubbedFs.restore();
@@ -18,7 +22,7 @@ When('the project is scaffolded', async function () {
1822

1923
stubbedFs({node_modules: stubbedNodeModules});
2024

21-
await scaffold({projectRoot, configs: {}});
25+
await scaffold({projectRoot: this.projectRoot, configs: {commitlint: {name: this.commilintConfigName}}});
2226
});
2327

2428
When('the project is lifted', async function () {
@@ -86,7 +90,7 @@ When('the project is lifted', async function () {
8690
})
8791
});
8892

89-
if (await test({projectRoot})) {
90-
await lift({projectRoot});
93+
if (await test({projectRoot: this.projectRoot})) {
94+
await lift({projectRoot: this.projectRoot});
9195
}
9296
});
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import {promises as fs} from 'node:fs';
2+
3+
import {When} from '@cucumber/cucumber';
4+
import {assert} from 'chai';
5+
6+
When('commitlint will be configured', async function () {
7+
assert.equal(
8+
await fs.readFile(`${this.projectRoot}/.commitlintrc.json`, 'utf-8'),
9+
JSON.stringify({extends: [this.commilintConfigName]}, null, 2)
10+
);
11+
});

0 commit comments

Comments
 (0)