Passed
Push — trunk ( c77658...5e2f97 )
by Christian
13:17 queued 13s
created

src/Administration/Resources/app/administration/scripts/entitySchemaConverter/generate-package.ts   A

Complexity

Total Complexity 3
Complexity/F 3

Size

Lines of Code 42
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 33
dl 0
loc 42
rs 10
c 0
b 0
f 0
wmc 3
mnd 2
bc 2
fnc 1
bpm 2
cpm 3
noi 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A generate-package.ts ➔ main 0 34 3
1
import fs from 'fs';
2
import path from 'path';
3
import entitySchema from "../../test/_mocks_/entity-schema.json";
4
import { EntitySchemaConverter } from "./entity-schema-converter";
5
6
async function main() {
7
    const gitCommitTag = process.env.CI_COMMIT_TAG;
8
9
    if (!gitCommitTag || typeof gitCommitTag !== 'string') {
10
        throw new Error('No git commit tag found. Please set the CI_COMMIT_TAG environment variable.');
11
    }
12
13
    const converter = new EntitySchemaConverter();
14
    const packageName = '@shopware-ag/entity-schema-types'
15
    const folderPackagePath = path.join(__dirname, '../../entity-schema-types');
16
    const definitionFileName = 'entity-schema-definition.d.ts';
17
    const packageVersion = gitCommitTag.replace('v6.', '');
18
19
    // Delete package folder if exists
20
    if (fs.existsSync(folderPackagePath)) {
21
        // @ts-ignore
22
        fs.rmSync(folderPackagePath, { recursive: true });
23
    }
24
25
    // Create new empty package folder
26
    fs.mkdirSync(folderPackagePath);
27
28
    // Create package.json
29
    fs.writeFileSync(path.join(folderPackagePath, 'package.json'), JSON.stringify({
30
        name: packageName,
31
        version: packageVersion,
32
        description: 'TypeScript definition file for the corresponding entity schema',
33
        license: 'MIT',
34
        types: definitionFileName,
35
    }, null, 4));
36
37
    // @ts-ignore
38
    converter.convert(entitySchema, path.join(folderPackagePath, definitionFileName));
39
}
40
41
main();
42