Skip to content

Commit 129d4aa

Browse files
authored
feat(commitlint-config): use chore commit prefix when git has changes inside demo project (#924)
1 parent 9cb4231 commit 129d4aa

9 files changed

+70
-25
lines changed

commitlint.config.ts

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import commitlint from './projects/commitlint-config';
2+
3+
export default commitlint;

package.json

-5
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,6 @@
1414
"after:bump": "npx nx build syncer && node projects/syncer/bin/src/index.js",
1515
"release": "npx nx run-many --target publish --all"
1616
},
17-
"commitlint": {
18-
"extends": [
19-
"@taiga-ui/commitlint-config"
20-
]
21-
},
2217
"lint-staged": {
2318
"*.less": [
2419
"stylelint --fix"

projects/commitlint-config/.npmignore

-2
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,12 @@
1-
import fs from 'node:fs';
2-
31
import conventional from '@commitlint/config-conventional';
42

3+
import {getGitDiffLines} from './utils/get-git-diff-lines';
4+
import {getTypes} from './utils/get-types';
5+
56
export default {
67
extends: ['@commitlint/config-conventional'],
78
rules: {
89
'scope-enum': () => {
9-
function getTypes(dir) {
10-
try {
11-
const {readdirSync, statSync} = fs;
12-
13-
return readdirSync(dir).filter((entity) =>
14-
statSync(`${dir}/${entity}`).isDirectory(),
15-
);
16-
} catch {
17-
return [];
18-
}
19-
}
20-
2110
return [
2211
2,
2312
'always',
@@ -35,9 +24,19 @@ export default {
3524
];
3625
},
3726
'type-enum': () => {
27+
const staged = getGitDiffLines();
28+
const demoChanges = staged.filter(
29+
(path) =>
30+
path.startsWith('projects/demo') || path.startsWith('apps/demo'),
31+
);
32+
3833
const [level, applicable, types] = conventional.rules['type-enum'];
34+
const prefixes =
35+
demoChanges.length === staged.length
36+
? ['chore']
37+
: [...types, 'deprecate'];
3938

40-
return [level, applicable, [...types, 'deprecate']];
39+
return [level, applicable, prefixes];
4140
},
4241
},
4342
};

projects/commitlint-config/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
},
1313
"license": "Apache-2.0",
1414
"type": "module",
15-
"exports": "./commitlint.config.js",
1615
"peerDependencies": {
1716
"@commitlint/cli": "^19.8.0",
1817
"@commitlint/config-conventional": "^19.8.0"

projects/commitlint-config/project.json

+21-2
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,30 @@
55
"projectType": "library",
66
"sourceRoot": "projects/commitlint-config",
77
"targets": {
8+
"build": {
9+
"executor": "@nx/rollup:rollup",
10+
"outputs": ["{workspaceRoot}/dist/{projectName}"],
11+
"options": {
12+
"main": "projects/{projectName}/index.ts",
13+
"outputPath": "{workspaceRoot}/dist/{projectName}",
14+
"tsConfig": "projects/{projectName}/tsconfig.lib.json",
15+
"assets": ["projects/{projectName}/README.md"],
16+
"generateExportsField": true,
17+
"format": ["esm"]
18+
}
19+
},
820
"publish": {
921
"executor": "nx:run-commands",
1022
"options": {
11-
"command": "npm publish ./projects/{projectName} --access=public --ignore-scripts"
12-
}
23+
"command": "npm publish ./dist/{projectName} --access=public --ignore-scripts"
24+
},
25+
"dependsOn": [
26+
{
27+
"target": "build",
28+
"params": "ignore",
29+
"dependencies": false
30+
}
31+
]
1332
}
1433
}
1534
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"extends": "../../tsconfig.json",
3+
"include": ["./*.ts"],
4+
"compilerOptions": {
5+
"baseUrl": ".",
6+
"checkJs": false,
7+
"allowJs": false,
8+
"esModuleInterop": true,
9+
"moduleResolution": "bundler",
10+
"module": "esnext"
11+
}
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import {execSync} from 'node:child_process';
2+
3+
export function getGitDiffLines(): string[] {
4+
try {
5+
return execSync('git diff --name-only --staged').toString().trim().split('\n');
6+
} catch {
7+
return [];
8+
}
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import {readdirSync, statSync} from 'node:fs';
2+
3+
export function getTypes(dir: string): string[] {
4+
try {
5+
return readdirSync(dir).filter((entity) =>
6+
statSync(`${dir}/${entity}`).isDirectory(),
7+
);
8+
} catch {
9+
return [];
10+
}
11+
}

0 commit comments

Comments
 (0)