• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

typeorm / typeorm / 13573761448

27 Feb 2025 06:53PM UTC coverage: 72.376% (+0.007%) from 72.369%
13573761448

push

github

web-flow
refactor: use ansis instead of chalk (#11263)

8657 of 12650 branches covered (68.43%)

Branch coverage included in aggregate %.

35 of 52 new or added lines in 11 files covered. (67.31%)

4 existing lines in 3 files now uncovered.

17895 of 24036 relevant lines covered (74.45%)

144036.91 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

30.43
/src/commands/EntityCreateCommand.ts
1
import ansi from "ansis"
248✔
2
import path from "path"
248✔
3
import yargs from "yargs"
4
import { PlatformTools } from "../platform/PlatformTools"
248✔
5
import { CommandUtils } from "./CommandUtils"
248✔
6

7
/**
8
 * Generates a new entity.
9
 */
10
export class EntityCreateCommand implements yargs.CommandModule {
248✔
11
    command = "entity:create <path>"
248✔
12
    describe = "Generates a new entity."
248✔
13

14
    builder(args: yargs.Argv) {
15
        return args.positional("path", {
×
16
            type: "string",
17
            describe: "Path of the entity file",
18
            demandOption: true,
19
        })
20
    }
21

22
    async handler(args: yargs.Arguments) {
23
        try {
×
24
            const fullPath = (args.path as string).startsWith("/")
×
25
                ? (args.path as string)
26
                : path.resolve(process.cwd(), args.path as string)
27
            const filename = path.basename(fullPath)
×
28
            const fileContent = EntityCreateCommand.getTemplate(filename)
×
29
            const fileExists = await CommandUtils.fileExists(fullPath + ".ts")
×
30
            if (fileExists) {
×
NEW
31
                throw new Error(`File "${fullPath}.ts" already exists`)
×
32
            }
33
            await CommandUtils.createFile(fullPath + ".ts", fileContent)
×
34
            console.log(
×
35
                ansi.green`Entity ${ansi.blue`${fullPath}.ts`} has been created successfully.`,
36
            )
37
        } catch (error) {
NEW
38
            PlatformTools.logCmdErr("Error during entity creation:", error)
×
UNCOV
39
            process.exit(1)
×
40
        }
41
    }
42

43
    // -------------------------------------------------------------------------
44
    // Protected Static Methods
45
    // -------------------------------------------------------------------------
46

47
    /**
48
     * Gets contents of the entity file.
49
     */
50
    protected static getTemplate(name: string): string {
51
        return `import { Entity } from "typeorm"
×
52

53
@Entity()
54
export class ${name} {
55

56
}
57
`
58
    }
59
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc