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

generate-package.ts ➔ main   A

Complexity

Conditions 3

Size

Total Lines 34
Code Lines 28

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 28
dl 0
loc 34
rs 9.208
c 0
b 0
f 0
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