@living-architecture/riviere-extract-conventions 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/default-config-fixtures.d.ts +4 -0
- package/dist/default-config-fixtures.d.ts.map +1 -0
- package/dist/default-config-fixtures.js +20 -0
- package/package.json +15 -2
- package/src/default-extraction.config.json +68 -0
- package/src/eslint/index.cjs +3 -0
- package/src/eslint/index.d.ts +10 -0
- package/src/eslint/require-component-decorator.cjs +55 -0
- package/src/eslint/require-component-decorator.d.cts +4 -0
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type ExtractionConfig } from '@living-architecture/riviere-extract-config';
|
|
2
|
+
export declare function loadDefaultConfig(): unknown;
|
|
3
|
+
export declare function getFirstModule(config: unknown): ExtractionConfig['modules'][number];
|
|
4
|
+
//# sourceMappingURL=default-config-fixtures.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"default-config-fixtures.d.ts","sourceRoot":"","sources":["../src/default-config-fixtures.ts"],"names":[],"mappings":"AAKA,OAAO,EAEL,KAAK,gBAAgB,EACtB,MAAM,6CAA6C,CAAA;AAIpD,wBAAgB,iBAAiB,IAAI,OAAO,CAI3C;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,OAAO,GAAG,gBAAgB,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,CAanF"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { join, dirname } from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
import { isValidExtractionConfig, } from '@living-architecture/riviere-extract-config';
|
|
5
|
+
const CURRENT_DIR = dirname(fileURLToPath(import.meta.url));
|
|
6
|
+
export function loadDefaultConfig() {
|
|
7
|
+
const configPath = join(CURRENT_DIR, 'default-extraction.config.json');
|
|
8
|
+
const configContent = readFileSync(configPath, 'utf-8');
|
|
9
|
+
return JSON.parse(configContent);
|
|
10
|
+
}
|
|
11
|
+
export function getFirstModule(config) {
|
|
12
|
+
if (!isValidExtractionConfig(config)) {
|
|
13
|
+
throw new Error(`Expected valid ExtractionConfig. Got invalid config. Validation needed.`);
|
|
14
|
+
}
|
|
15
|
+
const [module] = config.modules;
|
|
16
|
+
if (!module) {
|
|
17
|
+
throw new Error(`Expected modules[0] after schema validation. Got undefined. Schema enforces minItems: 1.`);
|
|
18
|
+
}
|
|
19
|
+
return module;
|
|
20
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@living-architecture/riviere-extract-conventions",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -15,10 +15,23 @@
|
|
|
15
15
|
"types": "./dist/index.d.ts",
|
|
16
16
|
"import": "./dist/index.js",
|
|
17
17
|
"default": "./dist/index.js"
|
|
18
|
+
},
|
|
19
|
+
"./default-config": "./src/default-extraction.config.json",
|
|
20
|
+
"./eslint-plugin": {
|
|
21
|
+
"types": "./src/eslint/index.d.ts",
|
|
22
|
+
"require": "./src/eslint/index.cjs",
|
|
23
|
+
"default": "./src/eslint/index.cjs"
|
|
18
24
|
}
|
|
19
25
|
},
|
|
20
26
|
"files": [
|
|
21
27
|
"dist",
|
|
28
|
+
"src/default-extraction.config.json",
|
|
29
|
+
"src/eslint/*.cjs",
|
|
30
|
+
"src/eslint/*.d.ts",
|
|
31
|
+
"src/eslint/*.d.cts",
|
|
22
32
|
"!**/*.tsbuildinfo"
|
|
23
|
-
]
|
|
33
|
+
],
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@living-architecture/riviere-extract-config": "0.1.4"
|
|
36
|
+
}
|
|
24
37
|
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://living-architecture.dev/schemas/extraction-config.schema.json",
|
|
3
|
+
"modules": [
|
|
4
|
+
{
|
|
5
|
+
"path": "**/*.ts",
|
|
6
|
+
"api": {
|
|
7
|
+
"find": "methods",
|
|
8
|
+
"where": {
|
|
9
|
+
"inClassWith": {
|
|
10
|
+
"hasDecorator": {
|
|
11
|
+
"name": "APIContainer",
|
|
12
|
+
"from": "@living-architecture/riviere-extract-conventions"
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"useCase": {
|
|
18
|
+
"find": "classes",
|
|
19
|
+
"where": {
|
|
20
|
+
"hasDecorator": {
|
|
21
|
+
"name": "UseCase",
|
|
22
|
+
"from": "@living-architecture/riviere-extract-conventions"
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"domainOp": {
|
|
27
|
+
"find": "methods",
|
|
28
|
+
"where": {
|
|
29
|
+
"inClassWith": {
|
|
30
|
+
"hasDecorator": {
|
|
31
|
+
"name": "DomainOpContainer",
|
|
32
|
+
"from": "@living-architecture/riviere-extract-conventions"
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"event": {
|
|
38
|
+
"find": "classes",
|
|
39
|
+
"where": {
|
|
40
|
+
"hasDecorator": {
|
|
41
|
+
"name": "Event",
|
|
42
|
+
"from": "@living-architecture/riviere-extract-conventions"
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
"eventHandler": {
|
|
47
|
+
"find": "methods",
|
|
48
|
+
"where": {
|
|
49
|
+
"inClassWith": {
|
|
50
|
+
"hasDecorator": {
|
|
51
|
+
"name": "EventHandlerContainer",
|
|
52
|
+
"from": "@living-architecture/riviere-extract-conventions"
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
"ui": {
|
|
58
|
+
"find": "classes",
|
|
59
|
+
"where": {
|
|
60
|
+
"hasDecorator": {
|
|
61
|
+
"name": "UI",
|
|
62
|
+
"from": "@living-architecture/riviere-extract-conventions"
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
]
|
|
68
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
const COMPONENT_DECORATORS = [
|
|
2
|
+
'DomainOpContainer',
|
|
3
|
+
'APIContainer',
|
|
4
|
+
'EventHandlerContainer',
|
|
5
|
+
'UseCase',
|
|
6
|
+
'Event',
|
|
7
|
+
'UI',
|
|
8
|
+
'Ignore',
|
|
9
|
+
]
|
|
10
|
+
|
|
11
|
+
const CALL_EXPRESSION_DECORATORS = ['Custom']
|
|
12
|
+
|
|
13
|
+
function getDecoratorName(expression) {
|
|
14
|
+
if (expression.type === 'Identifier') {
|
|
15
|
+
return expression.name
|
|
16
|
+
}
|
|
17
|
+
if (expression.type === 'CallExpression' && expression.callee.type === 'Identifier') {
|
|
18
|
+
return expression.callee.name
|
|
19
|
+
}
|
|
20
|
+
return null
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function hasComponentDecorator(decorators) {
|
|
24
|
+
return decorators.some((decorator) => {
|
|
25
|
+
const name = getDecoratorName(decorator.expression)
|
|
26
|
+
if (name === null) return false
|
|
27
|
+
return COMPONENT_DECORATORS.includes(name) || CALL_EXPRESSION_DECORATORS.includes(name)
|
|
28
|
+
})
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
module.exports = {
|
|
32
|
+
meta: {
|
|
33
|
+
type: 'problem',
|
|
34
|
+
docs: { description: 'Require classes to have a component decorator' },
|
|
35
|
+
schema: [],
|
|
36
|
+
messages: {
|
|
37
|
+
missingDecorator:
|
|
38
|
+
"Class '{{className}}' requires a component decorator. Add one of: @UseCase, @Event, @UI, @DomainOpContainer, @APIContainer, @EventHandlerContainer, @Custom('type'), or @Ignore",
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
create(context) {
|
|
42
|
+
return {
|
|
43
|
+
ClassDeclaration(node) {
|
|
44
|
+
if (!node.id) return
|
|
45
|
+
if (hasComponentDecorator(node.decorators)) return
|
|
46
|
+
|
|
47
|
+
context.report({
|
|
48
|
+
node: node.id,
|
|
49
|
+
messageId: 'missingDecorator',
|
|
50
|
+
data: { className: node.id.name },
|
|
51
|
+
})
|
|
52
|
+
},
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
}
|