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

IgniteUI / igniteui-cli / 11028706398

25 Sep 2024 07:53AM UTC coverage: 70.407% (-1.0%) from 71.398%
11028706398

Pull #1318

github

web-flow
Merge acd6f62ac into e121a9bbc
Pull Request #1318: Dependency updates iteration 3 - upgrade jasmine and schematics

910 of 1325 branches covered (68.68%)

Branch coverage included in aggregate %.

71 of 72 new or added lines in 14 files covered. (98.61%)

80 existing lines in 5 files now uncovered.

4731 of 6687 relevant lines covered (70.75%)

85.62 hits per line

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

29.21
/packages/ng-schematics/src/component/index.ts
1
import { normalize } from "@angular-devkit/core";
1✔
2
import {
1✔
3
        apply, chain, MergeStrategy, mergeWith,
4
        Rule, SchematicContext, SchematicsException, template, Tree, url
5
} from "@angular-devkit/schematics";
6
import { NodePackageInstallTask, RunSchematicTask } from "@angular-devkit/schematics/tasks";
1✔
7
import { IgniteUIForAngularTemplate } from "@igniteui/angular-templates";
8
import { App, FS_TYPE_TOKEN, FsTypes, GoogleAnalytics, ProjectConfig, Util } from "@igniteui/cli-core";
1✔
9
import { SchematicsPromptSession } from "../prompt/SchematicsPromptSession";
1✔
10
import { SchematicsTemplateManager } from "../SchematicsTemplateManager";
1✔
11
import { setVirtual } from "../utils/NgFileSystem";
1✔
12
import { ComponentOptions, TemplateOptions } from "./schema";
13

14
function registerInProject(templateOpts: TemplateOptions, skipRoute: boolean, modulePath?: string): Rule {
UNCOV
15
        return (_host: Tree, _context: SchematicContext) => {
×
UNCOV
16
                templateOpts.templateInst.registerInProject("", templateOpts.name, { skipRoute, modulePath });
×
17
        };
18
}
19

20
function getMissingPackages(templateOpts: TemplateOptions, packages: Map<string, string>): Rule {
UNCOV
21
        return (_host: Tree, _context: SchematicContext) => {
×
UNCOV
22
                for (const packageName of templateOpts.templateInst.packages) {
×
23
                        const packageMatch = packageName.split(/@(?=[^\/]+$)/);
×
24
                        packages.set(packageMatch[0], packageMatch[1] || "*");
×
25
                }
26
        };
27
}
28

29
function updatePackageJSON(installContext: { packages: Map<string, string>, shouldInstall?: boolean }): Rule {
UNCOV
30
        return (host: Tree, _context: SchematicContext) => {
×
UNCOV
31
                if (installContext.packages.size) {
×
32
                        const packageJSON = JSON.parse((host.read("package.json") || "").toString());
×
33
                        installContext.packages.forEach((version, name) => {
×
34
                                if (!packageJSON.dependencies[name]) {
×
35
                                        packageJSON.dependencies[name] = version;
×
36
                                        installContext.shouldInstall = true;
×
37
                                }
38
                        });
39
                        if (installContext.shouldInstall) {
×
40
                                host.overwrite("package.json", JSON.stringify(packageJSON, null, 2));
×
41
                        }
42
                }
43
        };
44
}
45

46
function addComponent(options: TemplateOptions, skipRoute = false, modulePath?: string): Rule {
×
UNCOV
47
        return async (tree: Tree, _context: SchematicContext) => {
×
UNCOV
48
                setVirtual(tree);
×
UNCOV
49
                const config = options.templateInst.generateConfig(options.name, {});
×
UNCOV
50
                return chain([...options.templateInst.templatePaths.map(templatePath =>
×
51
                        mergeWith(
×
52
                                apply(url(Util.relativePath(__filename, templatePath, true)), [
53
                                        template(config)
54
                                ]
55
                                ), MergeStrategy.Overwrite)
56
                ), registerInProject(options, skipRoute, modulePath)]);
57
        };
58
}
59
export function singleComponent(templateOptions: TemplateOptions, skipRoute: boolean) {
1✔
60
        return async (_tree: Tree, _context: SchematicContext) => {
×
61
                const packages = new Map<string, string>();
×
62
                return chain([
×
63
                        addComponent(templateOptions, skipRoute),
64
                        getMissingPackages(templateOptions, packages),
65
                        updatePackageJSON({ packages })
66
                ]);
67
        };
68
}
69
export function component(options: ComponentOptions): Rule {
1✔
70
        return async (tree: Tree, context: SchematicContext) => {
1✔
71
                App.initialize("angular-cli");
1✔
72
                GoogleAnalytics.post({
1✔
73
                        t: "screenview",
74
                        cd: "Add"
75
                });
76
                const addedComponents: TemplateOptions[] = [];
1✔
77
                const templateManager = new SchematicsTemplateManager();
1✔
78
                const projLib = templateManager.getProjectLibrary("angular", "igx-ts");
1✔
79
                /**
80
                 * MDNT
81
                 * Once inside the chooseActionLoop, the projLibrary cannot properly get
82
                 * its templates, as it seems it cannot read outside of the current context
83
                 * Since the projLib caches its templates, we make the initial call here so we have
84
                 * access to the in the following steps.
85
                 */
86
                const properties = {
1✔
87
                        component: projLib.components,
88
                        custom: projLib.getCustomTemplates()
89
                };
90
                let prompt: SchematicsPromptSession;
91
                if (!options.template || !options.name) {
1!
92
                        prompt = new SchematicsPromptSession(templateManager);
×
93
                        prompt.setContext(context, tree, options.name as string);
×
94
                        setVirtual(tree);
×
95
                        await prompt.chooseActionLoop(projLib);
×
96
                } else {
97
                        if (!projLib.hasTemplate(options.template)) {
1!
98
                                throw new SchematicsException(`template with id '${options.template}' not found`);
×
99
                        }
100
                        options.templateInst = projLib.getTemplateById(options.template) as IgniteUIForAngularTemplate;
1✔
101
                        addedComponents.push(options as TemplateOptions);
1✔
102

103
                        const config =  ProjectConfig.getConfig();
1✔
104
                        const selectedTemplate = options.templateInst;
1✔
105
                        GoogleAnalytics.post({
1✔
106
                                t: "event",
107
                                ec: "$ng add",
108
                                ea: `template id: ${options.template}; file name: ${options.name}`,
109
                                cd1: selectedTemplate.framework,
110
                                cd2: selectedTemplate.projectType,
111
                                cd5: selectedTemplate.controlGroup,
112
                                cd7: selectedTemplate.id,
113
                                cd8: selectedTemplate.name,
114
                                cd11: !!config.skipGit,
115
                                cd14: config.project.theme
116
                        });
117
                }
118

UNCOV
119
                const installContext = {
×
120
                        packages: new Map(),
121
                        shouldInstall: false
122
                };
UNCOV
123
                return chain([
×
124
                        ...addedComponents.map(templateOpts => {
UNCOV
125
                                context.logger.info(`Generating ${templateOpts.templateInst.name} with name: ${templateOpts.name}`);
×
UNCOV
126
                                return chain([
×
127
                                        (_tree: Tree, _context: SchematicContext) => {
UNCOV
128
                                                return App.container.get(FS_TYPE_TOKEN) === FsTypes.virtual ?
×
129
                                                        _tree :
130
                                                        addComponent(templateOpts, options.skipRoute || false, options.module);
×
131
                                        },
132
                                        getMissingPackages(templateOpts, installContext.packages)]);
133
                        }),
134
                        updatePackageJSON(installContext),
135
                        (_host: Tree, _context: SchematicContext) => {
136
                                // if called w/ command line arguments, check if dependencies are added and add install task.
UNCOV
137
                                if (!prompt) {
×
UNCOV
138
                                        if (installContext.shouldInstall) {
×
139
                                                _context.addTask(new NodePackageInstallTask());
×
140
                                                return;
×
141
                                        }
UNCOV
142
                                        return;
×
143
                                } else if (_host.actions.find(x => x.path === normalize("/package.json") && x.kind === "o")) {
×
144
                                        // prompt added components with extra packages
145
                                        installContext.shouldInstall = true;
×
146
                                }
147
                                _context.addTask(
×
148
                                        new RunSchematicTask("start", {}),
149
                                        installContext.shouldInstall ? [_context.addTask(new NodePackageInstallTask())] : []
×
150
                                );
151
                        }
152
                ]);
153
        };
154
}
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

© 2025 Coveralls, Inc