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

IgniteUI / igniteui-cli / 8631556716

10 Apr 2024 12:52PM UTC coverage: 67.144% (+0.4%) from 66.741%
8631556716

push

github

web-flow
chore: update typescript; migrate to eslint (#1235)

997 of 1601 branches covered (62.27%)

Branch coverage included in aggregate %.

17 of 17 new or added lines in 4 files covered. (100.0%)

117 existing lines in 26 files now uncovered.

4541 of 6647 relevant lines covered (68.32%)

156.03 hits per line

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

80.37
/packages/core/templates/BaseProjectLibrary.ts
1
import * as path from "path";
12✔
2
import { Component, ComponentGroup, ProjectLibrary, ProjectTemplate, Template } from "../types";
3
import { Util } from "../util";
12✔
4

5
export class BaseProjectLibrary implements ProjectLibrary {
12✔
6
        public projectType: string;
7
        public framework: string;
8
        //templates: Template[];
9
        public name: string;
10
        public themes: string[];
11

12
        /** Implementation, not part of the interface */
13
        public groupDescriptions = new Map<string, string>();
120✔
14

15
        /** Used to prefix folders that don't contain usable templates */
16
        protected _ignorePrefix = "_";
120✔
17
        protected _projectsPath: string = "projects";
120✔
18
        protected _customTemplatesPath: string = "custom-templates";
120✔
19
        protected _generateCommandPath: string = "generate";
120✔
20

21
        private _templates: Template[];
22
        public get templates(): Template[] {
23
                let list: Template[] = [];
7,804✔
24
                for (const component of this.components) {
7,804✔
25
                        list = list.concat(component.templates);
170,700✔
26
                }
27
                list = list.concat(this.customTemplates);
7,804✔
28
                return list;
7,804✔
29
        }
30
        private _projectIds: string[] = [];
120✔
31
        public get projectIds(): string[] {
32
                //read projects list
33
                if (!this._projectIds.length) {
80✔
34
                        this._projectIds = Util.getDirectoryNames(path.join(this.rootPath, this._projectsPath));
10✔
35
                        this._projectIds = this._projectIds.filter(x => !x.startsWith(this._ignorePrefix));
26✔
36
                }
37
                return this._projectIds;
80✔
38
        }
39

40
        private _projects: ProjectTemplate[] = [];
120✔
41
        public get projects(): ProjectTemplate[] {
42
                if (!this._projects.length) {
8✔
43
                        this._projects = this.projectIds.map(x => this.getProject(x));
8✔
44
                }
45
                return this._projects;
8✔
46
        }
47

48
        /*        private _customTemplates : string[];
49
                public get customTemplates() : string[] {
50
                        if (!this._customTemplates.length) {
51
                                this._customTemplates = Util.getDirectoryNames(path.join(this.rootPath, this._customTemplatesPath));
52
                        }
53
                        return this._customTemplates;
54
                }*/
55

56
        private _customTemplates: Template[] = [];
120✔
57
        public get customTemplates(): Template[] {
58
                if (!this._customTemplates.length) {
7,816✔
59
                        const customTemplatesFolders: string[] = Util.getDirectoryNames(path.join(this.rootPath, this._customTemplatesPath));
1,708✔
60

61
                        for (const element of customTemplatesFolders) {
1,708✔
62
                                this._customTemplates.push(require(path.join(
52✔
63
                                        this.rootPath,
64
                                        this._customTemplatesPath,
65
                                        element)) as Template);
66
                        }
67
                }
68
                return this._customTemplates;
7,816✔
69
        }
70

71
        private _components: Component[] = [];
120✔
72
        public get components(): Component[] {
73
                if (!this._components.length) {
7,844✔
74
                        //read file
75
                        //read components lists
76
                        const componentFolders: string[] = Util.getDirectoryNames(this.rootPath)
26✔
77
                                .filter(
78
                                        x => x !== this._projectsPath &&
266✔
79
                                                x !== this._customTemplatesPath &&
80
                                                x !== this._generateCommandPath);
81

82
                        for (const componentFolder of componentFolders) {
26✔
83

84
                                this._components.push(require(path.join(this.rootPath, componentFolder)) as Component);
238✔
85
                        }
86
                }
87
                return this._components;
7,844✔
88
        }
89

90
        private _generateTemplateFolderPath: string = "";
120✔
91
        public get generateTemplateFolderPath(): string {
92
                if (this._generateTemplateFolderPath === "") {
8!
93
                        this._generateTemplateFolderPath = path.join(this.rootPath, "generate");
8✔
94
                }
95
                return this._generateTemplateFolderPath;
8✔
96
        }
97

98
        /**
99
         *
100
         */
101
        constructor(private rootPath: string) { }
120✔
102

103
        public getTemplateById(id: string): Template {
104
                return this.templates.find(x => x.id === id);
278✔
105
        }
106
        public getTemplateByName(name: string): Template {
107
                return this.templates.find(x => x.name === name);
20✔
108
        }
109

110
        public registerTemplate(template: Template): void {
111
                if (template) {
2!
112
                        this.templates.push(template);
2✔
113
                        const newComponents = template.components.filter(x => !this.components.find(f => f.name === x));
4✔
114
                        for (const newComponent of newComponents) {
2✔
115
                                const component: Component = {
116
                                        name: newComponent,
117
                                        description: "",
118
                                        group: template.controlGroup,
119
                                        groupPriority: 0,
120
                                        templates: []
121
                                };
122
                                this.components.push(component);
2✔
123
                        }
124
                        if (template.listInComponentTemplates) {
2!
125
                                const currentComponents = template.components.filter(x => this.components.find(f => f.name === x));
×
UNCOV
126
                                for (const currentComponent of currentComponents) {
×
127
                                        this.components.find(f => f.name === currentComponent).templates.push(template);
×
128
                                }
129
                        }
130
                        if (template.listInCustomTemplates) {
2!
131
                                this.customTemplates.push(template);
×
132
                        }
133
                }
134
        }
135

136
        public getComponentByName(name: string): Component {
137
                return this.components.find(x => x.name === name);
20✔
138
        }
139

140
        public getCustomTemplates(): Template[] {
141
                return this.customTemplates;
×
142
        }
143

144
        public getCustomTemplateNames(): string[] {
145
                const cTemplates: string[] = [];
2✔
146
                for (const customTemplate of this.customTemplates) {
2✔
147
                        //var p: CustomTemplate = this.customTemplates[index] as CustomTemplate;
148
                        cTemplates.push(customTemplate.name);
4✔
149
                }
150
                return cTemplates;
2✔
151
        }
152
        public getCustomTemplateByName(name: string): Template {
153
                return this.customTemplates.find((x, y, z) => x.name === name);
2✔
154
        }
155

156
        public getComponentGroupNames(): string[] {
157
                let groups: string[];
158

159
                //poor-man's groupBy reduce
160
                groups = this.components.reduce((prev, current, index, array) => {
2✔
161
                        if (prev.indexOf(current.group) === -1) {
10!
162
                                prev.push(current.group);
10✔
163
                        }
164
                        return prev;
10✔
165
                }, []);
166
                return [...this.groupDescriptions.keys()].filter(item => groups.includes(item));
10✔
167
        }
168

169
        public getComponentsByGroup(group: string): Component[] {
170
                return this.components.filter(x => x.group === group)
26✔
171
                        .sort((a, b) => b.groupPriority - a.groupPriority);
30✔
172
        }
173

174
        // /**
175
        //  * Return Component Groups with descriptions
176
        //  */
177
        public getComponentGroups(): ComponentGroup[] {
178
                const groups: ComponentGroup[] = [];
×
179

UNCOV
180
                for (const groupName of this.getComponentGroupNames()) {
×
181
                        groups.push({
×
182
                                name: groupName,
183
                                description: this.groupDescriptions.get(groupName) || ""
×
184
                        });
185
                }
186
                return groups;
×
187
        }
188

189
        public getComponentNamesByGroup(group: string): string[] {
190
                return this.components.filter(x => x.group === group)
×
191
                        .sort((a, b) => b.groupPriority - a.groupPriority)
×
192
                        .map(x => x.name);
×
193
        }
194

195
        /**
196
         * Get project template
197
         * @param id ID of the project template.
198
         */
199
        public getProject(id: string): ProjectTemplate {
200
                if (this.hasProject(id)) {
26!
201
                        const projModule = require(path.join(this.rootPath, this._projectsPath, id));
26✔
202
                        return projModule.default || projModule as ProjectTemplate;
26✔
203
                }
204
                return null;
×
205
        }
206

207
        public hasProject(id: string): boolean {
208
                return this.projectIds.indexOf(id) > -1;
28✔
209
        }
210
        //abstraction for projects
211

212
        public hasTemplate(id: string): boolean {
213
                return this.templates.find(x => x.id === id) !== undefined;
340✔
214
        }
215
}
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