• 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

60.82
/packages/ng-schematics/src/ng-new/index.ts
1
import {
1✔
2
        apply,
3
        chain,
4
        empty,
5
        MergeStrategy,
6
        mergeWith,
7
        move,
8
        Rule,
9
        schematic,
10
        SchematicContext,
11
        SchematicsException,
12
        TaskId,
13
        Tree } from "@angular-devkit/schematics";
14
import { NodePackageInstallTask, RepositoryInitializerTask, RunSchematicTask } from "@angular-devkit/schematics/tasks";
1✔
15
import { App, GoogleAnalytics, ProjectLibrary, ProjectTemplate, Util } from "@igniteui/cli-core";
1✔
16
import { defer, Observable } from "rxjs";
1✔
17
import { NewProjectOptions } from "../app-projects/schema";
18
import { SchematicsPromptSession } from "../prompt/SchematicsPromptSession";
1✔
19
import { SchematicsTemplateManager } from "../SchematicsTemplateManager";
1✔
20
import { setVirtual } from "../utils/NgFileSystem";
1✔
21
import { OptionsSchema } from "./schema";
22

23
interface IgxSchematicContext extends SchematicContext {
24
        projectType: string;
25
        theme: string;
26
}
27

28
export function newProject(options: OptionsSchema): Rule {
1✔
29
        return (_host: Tree, _hostContext: IgxSchematicContext) => {
2✔
30
                App.initialize("angular-cli");
2✔
31
                GoogleAnalytics.post({
2✔
32
                        t: "screenview",
33
                        cd: "New"
34
                });
35
                let projLibrary: ProjectLibrary;
36
                let projectOptions: NewProjectOptions;
37
                const templateManager = new SchematicsTemplateManager();
2✔
38
                const prompt = new SchematicsPromptSession(templateManager);
2✔
39

40
                // TODO:
41
                const defaultProjName = "IG Project";
2✔
42
                let nameProvided: boolean = false;
2✔
43
                let projTemplate: ProjectTemplate;
44

45
                return chain([
2✔
46
                        (tree: Tree, _context: IgxSchematicContext): Observable<Tree> => {
47
                                return defer(async () => {
2✔
48
                                        if (options.name) {
2✔
49
                                                options.name = options.name.trim();
1✔
50
                                                nameProvided = true;
1✔
51

52
                                                // letter+alphanumeric check
53
                                                if (!Util.isAlphanumericExt(options.name)) {
1!
54
                                                        throw new SchematicsException(`Name '${options.name}' is not valid. `
×
55
                                                                + "Name should start with a letter and can also contain numbers, dashes and spaces.");
56
                                                }
57
                                        }
58

59
                                        if (Util.directoryExists(options.name)) {
2!
60
                                                throw new SchematicsException(`Folder "${options.name}" already exists!`);
×
61
                                        }
62
                                        const framework = templateManager.getFrameworkByName("angular");
2✔
63
                                        projLibrary = await prompt.getProjectLibraryByType(framework, options.type);
2✔
64

65
                                        if (!options.name || !prompt.nameIsValid(options.name)) {
2✔
66
                                                options.name = await prompt.getUserInput({
1✔
67
                                                        type: "input",
68
                                                        name: "projectName",
69
                                                        message: "Enter a name for your project:",
70
                                                        default: Util.getAvailableName(defaultProjName, true),
71
                                                        choices: null as unknown as string[],
72
                                                        validate: prompt.nameIsValid
73
                                                });
UNCOV
74
                                                nameProvided = false;
×
75

UNCOV
76
                                                projTemplate = await prompt.getProjectTemplate(projLibrary);
×
77

UNCOV
78
                                                options.theme = await prompt.getTheme(projLibrary);
×
79
                                        }
80

81
                                        let themeIndex = 0;
1✔
82
                                        if (options.theme) {
1!
UNCOV
83
                                                themeIndex = projLibrary.themes.findIndex(item => options.theme.toLowerCase() === item.toLowerCase());
×
UNCOV
84
                                                if (themeIndex === -1) {
×
85
                                                        throw new SchematicsException(`Theme not supported`);
×
86
                                                }
87
                                        }
88

89
                                        if (projTemplate === undefined) {
1✔
90
                                                const projectTemplate = options.template || projLibrary.projectIds[0];
1✔
91
                                                projTemplate = projLibrary.getProject(projectTemplate);
1✔
92
                                                if (!projTemplate) {
1!
93
                                                        throw new SchematicsException(`template with id '${options.template}' not found`);
×
94
                                                }
95
                                        }
96
                                        const theme = projLibrary.themes[themeIndex];
1✔
97
                                        Util.log(`Project Name: ${options.name}, theme ${theme}`);
1✔
98

99
                                        // project options:
100
                                        // cache available views and components, same as in component Schematic
101
                                        const components = projLibrary.components;
1✔
102
                                        const views = (projLibrary as any).customTemplates;
1✔
103

104
                                        projectOptions = {
1✔
105
                                                projTemplate,
106
                                                theme,
107
                                                name: options.name
108
                                        };
109

110
                                        GoogleAnalytics.post({
1✔
111
                                                t: "event",
112
                                                ec: "$ng new",
113
                                                ea: `project name: ${options.name}; framework: ${projTemplate.framework}; ` +
114
                                                        `project type: ${projTemplate.projectType}; theme: ${theme}; skip-git: ${!!options.skipGit}`,
115
                                                cd1: projTemplate.framework,
116
                                                cd2: projTemplate.projectType,
117
                                                cd3: options.name,
118
                                                cd11: !!options.skipGit,
119
                                                cd14: theme
120
                                        });
121

122
                                        return tree;
1✔
123
                                });
124
                        },
125
                        mergeWith(
126
                                apply(empty(), [
127
                                        // TODO: Task chain based on @schematics/angular ng-new schematic
128
                                        // externalSchematic("@schematics/angular", "workspace", { name: options.name }),
129
                                        // externalSchematic("@schematics/angular", "application", {
130
                                        //         projectRoot: "", name: options.name, skipInstall: true, routing: true, style: "scss"
131
                                        // }),
132
                                        (tree: Tree, _context: IgxSchematicContext) => {
133
                                                setVirtual(tree);
1✔
134
                                                // extend project entry point:
135
                                                return schematic("app-projects", projectOptions);
1✔
136
                                        },
137
                                        (tree: Tree, _context: IgxSchematicContext) => {
138
                                                // extend project entry point:
139
                                                // tree.create("ignite-ui-cli.json", JSON.stringify({ theme: context.theme }));
140
                                                if (tree.exists("gitignore")) {
1!
UNCOV
141
                                                        tree.rename("gitignore", ".gitignore");
×
142
                                                }
143
                                        },
144
                                        (tree: Tree, context: IgxSchematicContext) => {
145
                                                if (!nameProvided) {
1!
UNCOV
146
                                                        return defer(async () => {
×
UNCOV
147
                                                                prompt.setContext(context, tree, options.name as string);
×
UNCOV
148
                                                                await prompt.chooseActionLoop(projLibrary);
×
UNCOV
149
                                                                return tree;
×
150
                                                        });
151
                                                }
152
                                        },
153
                                        (_tree: Tree, _context: IgxSchematicContext) => {
154
                                                return move(options.name!);
1✔
155
                                        }
156
                                ]), MergeStrategy.Overwrite
157
                        ),
158
                        (tree: Tree, _context: IgxSchematicContext) => {
159
                                if (prompt.userAnswers && prompt.userAnswers.get("upgradePackages")) {
1✔
160
                                        return defer(async () => {
1✔
161
                                                setVirtual(tree);
1✔
162
                                                await projectOptions.projTemplate.upgradeIgniteUIPackages(options.name || "", "");
1!
UNCOV
163
                                                return tree;
×
164
                                        });
165
                                }
166
                        },
167
                        (tree: Tree, context: IgxSchematicContext) => {
UNCOV
168
                                const installChain: TaskId[] = [];
×
UNCOV
169
                                if (!options.skipInstall) {
×
UNCOV
170
                                        const installTask = context.addTask(
×
171
                                                new NodePackageInstallTask(options.name),
172
                                                [...installChain]);
UNCOV
173
                                        installChain.push(installTask);
×
174
                                }
UNCOV
175
                                if (!options.skipGit) {
×
UNCOV
176
                                        const gitTask = context.addTask(
×
177
                                                new RepositoryInitializerTask(options.name, { message: `Initial commit for project: ${options.name}` }),
178
                                                [...installChain] //copy
179
                                        );
UNCOV
180
                                        installChain.push(gitTask);
×
181
                                }
182

UNCOV
183
                                if (!options.skipInstall && !nameProvided) {
×
UNCOV
184
                                        context.addTask(new RunSchematicTask("start", { directory: options.name }), installChain);
×
185
                                }
UNCOV
186
                                return tree;
×
187
                        }
188
                ]);
189
        };
190
}
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