igniteui-cli 12.0.6 → 12.1.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (110) hide show
  1. package/lib/commands/new.js +4 -1
  2. package/lib/commands/start.js +11 -6
  3. package/lib/templates/IgniteUIForReactTemplate.js +5 -11
  4. package/package.json +3 -3
  5. package/templates/react/ReactTypeScriptFileUpdate.d.ts +52 -0
  6. package/templates/react/ReactTypeScriptFileUpdate.js +344 -0
  7. package/templates/react/igr-es6/index.js +1 -1
  8. package/templates/react/igr-ts/bullet-graph/default/files/src/views/__path__/index.test.tsx +8 -0
  9. package/templates/react/igr-ts/bullet-graph/default/files/src/views/__path__/index.tsx +56 -0
  10. package/templates/react/igr-ts/bullet-graph/default/files/src/views/__path__/style.module.css +12 -0
  11. package/templates/react/igr-ts/bullet-graph/default/index.d.ts +1 -0
  12. package/templates/react/igr-ts/bullet-graph/default/index.js +18 -0
  13. package/templates/react/igr-ts/bullet-graph/index.d.ts +1 -0
  14. package/templates/react/igr-ts/bullet-graph/index.js +15 -0
  15. package/templates/react/igr-ts/category-chart/default/files/src/views/__path__/index.test.tsx +8 -0
  16. package/templates/react/igr-ts/category-chart/default/files/src/views/__path__/index.tsx +41 -0
  17. package/templates/react/igr-ts/category-chart/default/files/src/views/__path__/style.module.css +9 -0
  18. package/templates/react/igr-ts/category-chart/default/index.d.ts +1 -0
  19. package/templates/react/igr-ts/category-chart/default/index.js +19 -0
  20. package/templates/react/igr-ts/category-chart/index.d.ts +1 -0
  21. package/templates/react/igr-ts/category-chart/index.js +16 -0
  22. package/templates/react/igr-ts/doughnut-chart/default/files/src/views/__path__/index.test.tsx +8 -0
  23. package/templates/react/igr-ts/doughnut-chart/default/files/src/views/__path__/index.tsx +63 -0
  24. package/templates/react/igr-ts/doughnut-chart/default/files/src/views/__path__/style.module.css +9 -0
  25. package/templates/react/igr-ts/doughnut-chart/default/index.d.ts +1 -0
  26. package/templates/react/igr-ts/doughnut-chart/default/index.js +18 -0
  27. package/templates/react/igr-ts/doughnut-chart/index.d.ts +1 -0
  28. package/templates/react/igr-ts/doughnut-chart/index.js +15 -0
  29. package/templates/react/igr-ts/financial-chart/default/files/src/views/__path__/index.test.tsx +8 -0
  30. package/templates/react/igr-ts/financial-chart/default/files/src/views/__path__/index.tsx +49 -0
  31. package/templates/react/igr-ts/financial-chart/default/files/src/views/__path__/style.module.css +10 -0
  32. package/templates/react/igr-ts/financial-chart/default/index.d.ts +1 -0
  33. package/templates/react/igr-ts/financial-chart/default/index.js +20 -0
  34. package/templates/react/igr-ts/financial-chart/index.d.ts +1 -0
  35. package/templates/react/igr-ts/financial-chart/index.js +16 -0
  36. package/templates/react/igr-ts/grid/basic/files/src/views/__path__/data.tsx +46 -0
  37. package/templates/react/igr-ts/grid/basic/files/src/views/__path__/index.test.tsx +8 -0
  38. package/templates/react/igr-ts/grid/basic/files/src/views/__path__/index.tsx +62 -0
  39. package/templates/react/igr-ts/grid/basic/files/src/views/__path__/style.module.css +17 -0
  40. package/templates/react/igr-ts/grid/basic/index.d.ts +1 -0
  41. package/templates/react/igr-ts/grid/basic/index.js +23 -0
  42. package/templates/react/igr-ts/grid/index.d.ts +1 -0
  43. package/templates/react/igr-ts/grid/index.js +15 -0
  44. package/templates/react/igr-ts/groups.json +5 -0
  45. package/templates/react/igr-ts/index.d.ts +1 -0
  46. package/templates/react/igr-ts/index.js +17 -0
  47. package/templates/react/igr-ts/linear-gauge/default/files/src/views/__path__/index.test.tsx +8 -0
  48. package/templates/react/igr-ts/linear-gauge/default/files/src/views/__path__/index.tsx +59 -0
  49. package/templates/react/igr-ts/linear-gauge/default/files/src/views/__path__/style.module.css +12 -0
  50. package/templates/react/igr-ts/linear-gauge/default/index.d.ts +1 -0
  51. package/templates/react/igr-ts/linear-gauge/default/index.js +18 -0
  52. package/templates/react/igr-ts/linear-gauge/index.d.ts +1 -0
  53. package/templates/react/igr-ts/linear-gauge/index.js +15 -0
  54. package/templates/react/igr-ts/pie-chart/default/files/src/views/__path__/index.test.tsx +8 -0
  55. package/templates/react/igr-ts/pie-chart/default/files/src/views/__path__/index.tsx +57 -0
  56. package/templates/react/igr-ts/pie-chart/default/files/src/views/__path__/style.module.css +9 -0
  57. package/templates/react/igr-ts/pie-chart/default/index.d.ts +1 -0
  58. package/templates/react/igr-ts/pie-chart/default/index.js +18 -0
  59. package/templates/react/igr-ts/pie-chart/index.d.ts +1 -0
  60. package/templates/react/igr-ts/pie-chart/index.js +15 -0
  61. package/templates/react/igr-ts/projects/_base/files/README.md +48 -0
  62. package/templates/react/igr-ts/projects/_base/files/__dot__editorconfig +3 -0
  63. package/templates/react/igr-ts/projects/_base/files/__dot__eslintrc.cjs +18 -0
  64. package/templates/react/igr-ts/projects/_base/files/__dot__gitignore +23 -0
  65. package/templates/react/igr-ts/projects/_base/files/ignite-ui-cli.json +16 -0
  66. package/templates/react/igr-ts/projects/_base/files/index.html +33 -0
  67. package/templates/react/igr-ts/projects/_base/files/package.json +52 -0
  68. package/templates/react/igr-ts/projects/_base/files/public/favicon.ico +0 -0
  69. package/templates/react/igr-ts/projects/_base/files/public/manifest.json +15 -0
  70. package/templates/react/igr-ts/projects/_base/files/src/App.test.tsx +8 -0
  71. package/templates/react/igr-ts/projects/_base/files/src/App.tsx +10 -0
  72. package/templates/react/igr-ts/projects/_base/files/src/index.css +14 -0
  73. package/templates/react/igr-ts/projects/_base/files/src/main.tsx +20 -0
  74. package/templates/react/igr-ts/projects/_base/files/src/routes.tsx +3 -0
  75. package/templates/react/igr-ts/projects/_base/files/src/setupTests.ts +5 -0
  76. package/templates/react/igr-ts/projects/_base/files/src/vite-env.d.ts +1 -0
  77. package/templates/react/igr-ts/projects/_base/files/tsconfig.json +25 -0
  78. package/templates/react/igr-ts/projects/_base/files/tsconfig.node.json +10 -0
  79. package/templates/react/igr-ts/projects/_base/files/vite.config.ts +23 -0
  80. package/templates/react/igr-ts/projects/_base/index.d.ts +29 -0
  81. package/templates/react/igr-ts/projects/_base/index.js +58 -0
  82. package/templates/react/igr-ts/projects/_base_with_home/files/public/logo.svg +7 -0
  83. package/templates/react/igr-ts/projects/_base_with_home/files/src/App.module.css +36 -0
  84. package/templates/react/igr-ts/projects/_base_with_home/files/src/App.test.tsx +8 -0
  85. package/templates/react/igr-ts/projects/_base_with_home/files/src/App.tsx +21 -0
  86. package/templates/react/igr-ts/projects/_base_with_home/files/src/setupTests.ts +5 -0
  87. package/templates/react/igr-ts/projects/_base_with_home/index.d.ts +14 -0
  88. package/templates/react/igr-ts/projects/_base_with_home/index.js +22 -0
  89. package/templates/react/igr-ts/projects/base/index.d.ts +14 -0
  90. package/templates/react/igr-ts/projects/base/index.js +22 -0
  91. package/templates/react/igr-ts/projects/empty/index.d.ts +14 -0
  92. package/templates/react/igr-ts/projects/empty/index.js +22 -0
  93. package/templates/react/igr-ts/projects/top-nav/files/src/App.css +59 -0
  94. package/templates/react/igr-ts/projects/top-nav/files/src/App.tsx +21 -0
  95. package/templates/react/igr-ts/projects/top-nav/files/src/components/navigation-header/index.tsx +29 -0
  96. package/templates/react/igr-ts/projects/top-nav/files/src/routes.tsx +5 -0
  97. package/templates/react/igr-ts/projects/top-nav/files/src/setupTests.ts +5 -0
  98. package/templates/react/igr-ts/projects/top-nav/files/src/views/home/index.tsx +17 -0
  99. package/templates/react/igr-ts/projects/top-nav/files/src/views/home/logo.svg +7 -0
  100. package/templates/react/igr-ts/projects/top-nav/files/src/views/home/style.module.css +27 -0
  101. package/templates/react/igr-ts/projects/top-nav/index.d.ts +14 -0
  102. package/templates/react/igr-ts/projects/top-nav/index.js +22 -0
  103. package/templates/react/igr-ts/radial-gauge/default/files/src/views/__path__/index.test.tsx +8 -0
  104. package/templates/react/igr-ts/radial-gauge/default/files/src/views/__path__/index.tsx +60 -0
  105. package/templates/react/igr-ts/radial-gauge/default/files/src/views/__path__/style.module.css +12 -0
  106. package/templates/react/igr-ts/radial-gauge/default/index.d.ts +1 -0
  107. package/templates/react/igr-ts/radial-gauge/default/index.js +19 -0
  108. package/templates/react/igr-ts/radial-gauge/index.d.ts +1 -0
  109. package/templates/react/igr-ts/radial-gauge/index.js +16 -0
  110. package/templates/react/index.js +1 -0
@@ -107,7 +107,10 @@ command = {
107
107
  }
108
108
  }
109
109
  const theme = projectLib.themes[themeIndex];
110
- const projectTemplate = argv.template || projectLib.projectIds[0];
110
+ const indexOfEmptyOrFirst = projectLib.projectIds.indexOf("empty") !== -1 ?
111
+ projectLib.projectIds.indexOf("empty") :
112
+ 0;
113
+ const projectTemplate = argv.template || projectLib.projectIds[indexOfEmptyOrFirst];
111
114
  cli_core_1.Util.log(`Project Name: ${argv.name}, framework ${argv.framework}, type ${projectLib.projectType}, theme ${theme}`);
112
115
  const projTemplate = projectLib.getProject(projectTemplate);
113
116
  if (projTemplate == null) {
@@ -81,12 +81,17 @@ command = {
81
81
  break;
82
82
  case "react":
83
83
  if (port) {
84
- // https://facebook.github.io/create-react-app/docs/advanced-configuration
85
- // react-scripts start "--port=dafaultPort" is not a valid command for all environments.
86
- // .env file is included and used by both igr-es6 and es6 now,
87
- // to specify the port for all environments (Windows, Mac, etc)
88
- process.env.PORT = `${port}`;
89
- port = null;
84
+ if (projectType === "igr-ts") {
85
+ execSyncNpmStart(port, options);
86
+ }
87
+ else {
88
+ // https://facebook.github.io/create-react-app/docs/advanced-configuration
89
+ // react-scripts start "--port=dafaultPort" is not a valid command for all environments.
90
+ // .env file is included and used by both igr-es6 and es6 now,
91
+ // to specify the port for all environments (Windows, Mac, etc)
92
+ process.env.PORT = `${port}`;
93
+ port = null;
94
+ }
90
95
  }
91
96
  /* falls through */
92
97
  case "angular":
@@ -2,8 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.IgniteUIForReactTemplate = void 0;
4
4
  const cli_core_1 = require("@igniteui/cli-core");
5
- const fs = require("fs-extra");
6
5
  const path = require("path");
6
+ const ReactTypeScriptFileUpdate_1 = require("../../templates/react/ReactTypeScriptFileUpdate");
7
7
  class IgniteUIForReactTemplate {
8
8
  /**
9
9
  * Base ReactTemplate constructor
@@ -15,11 +15,10 @@ class IgniteUIForReactTemplate {
15
15
  this.listInCustomTemplates = false;
16
16
  this.dependencies = [];
17
17
  this.framework = "react";
18
- this.projectType = "igr-es6";
19
18
  this.hasExtraConfiguration = false;
20
19
  this.packages = [];
21
20
  this.delimiters = cli_core_1.defaultDelimiters;
22
- this.configFile = "./src/routes.json";
21
+ this.configFile = "./src/routes.tsx";
23
22
  }
24
23
  get templatePaths() {
25
24
  return [path.join(this.rootPath, "files")];
@@ -46,14 +45,9 @@ class IgniteUIForReactTemplate {
46
45
  if (options && options.skipRoute) {
47
46
  return;
48
47
  }
49
- const configFile = fs.readFileSync(path.join(projectPath, this.configFile), "utf8");
50
- const viewsArr = JSON.parse(configFile);
51
- viewsArr.push({
52
- componentPath: this.getViewLink(name),
53
- path: "/" + this.folderName(cli_core_1.Util.nameFromPath(name)),
54
- text: this.getToolbarLink(name)
55
- });
56
- fs.writeFileSync(path.join(projectPath, this.configFile), JSON.stringify(viewsArr, null, 4));
48
+ const routeModulePath = "src/routes.tsx";
49
+ const routingModule = new ReactTypeScriptFileUpdate_1.ReactTypeScriptFileUpdate(path.join(projectPath, routeModulePath));
50
+ routingModule.addRoute(path.join(projectPath, `src/views/${this.folderName(name)}`), cli_core_1.Util.lowerDashed(cli_core_1.Util.nameFromPath(name)), cli_core_1.Util.className(cli_core_1.Util.nameFromPath(name)), options.routerChildren, undefined);
57
51
  }
58
52
  getExtraConfiguration() {
59
53
  throw new Error("Method not implemented.");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "igniteui-cli",
3
- "version": "12.0.6",
3
+ "version": "12.1.0-beta.1",
4
4
  "description": "CLI tool for creating Ignite UI projects",
5
5
  "keywords": [
6
6
  "CLI",
@@ -72,8 +72,8 @@
72
72
  "all": true
73
73
  },
74
74
  "dependencies": {
75
- "@igniteui/angular-templates": "~16.0.1206",
76
- "@igniteui/cli-core": "~12.0.6",
75
+ "@igniteui/angular-templates": "~16.0.1210-beta.1",
76
+ "@igniteui/cli-core": "~12.1.0-beta.1",
77
77
  "chalk": "^2.3.2",
78
78
  "fs-extra": "^3.0.1",
79
79
  "glob": "^7.1.2",
@@ -0,0 +1,52 @@
1
+ import * as ts from "typescript";
2
+ /**
3
+ * Apply various updates to typescript files using AST
4
+ */
5
+ export declare class ReactTypeScriptFileUpdate {
6
+ private targetPath;
7
+ protected formatOptions: {
8
+ spaces: boolean;
9
+ indentSize: number;
10
+ singleQuotes: boolean;
11
+ };
12
+ private fileSystem;
13
+ private targetSource;
14
+ private importsMeta;
15
+ private requestedImports;
16
+ private createdStringLiterals;
17
+ /** Create updates for a file. Use `add<X>` methods to add transformations and `finalize` to apply and save them. */
18
+ constructor(targetPath: string);
19
+ /** Applies accumulated transforms, saves and formats the file */
20
+ finalize(): void;
21
+ addRoute(path: string, component: string, name: string, routerChildren: string, importAlias: string, routesVariable?: string): void;
22
+ /** Initializes existing imports info, [re]sets import and `NgModule` edits */
23
+ protected initState(): void;
24
+ protected loadImportsMeta(): {
25
+ lastIndex: number;
26
+ modulePaths: any[];
27
+ };
28
+ protected addRouteModuleEntry(path: string, component: string, name: string, routerChildren: string, importAlias: string, routesVariable?: string): void;
29
+ protected requestImport(modulePath: string, routerAlias: string, componentName: string): void;
30
+ /** Add `import` statements not previously found in the file */
31
+ protected addNewFileImports(): void;
32
+ protected createIdentifierImport(importPath: string, as: string, component: string): ts.ImportDeclaration;
33
+ /** Transformation to apply edits to existing named import declarations */
34
+ protected importsTransformer: ts.TransformerFactory<ts.Node>;
35
+ /** Format a TS source file, very TBD */
36
+ protected formatFile(filePath: string): void;
37
+ /** Try and parse formatting from project `.editorconfig` / `tslint.json` */
38
+ protected readFormatConfigs(): void;
39
+ /**
40
+ * Apply formatting changes (position based) in reverse
41
+ * from https://github.com/Microsoft/TypeScript/issues/1651#issuecomment-69877863
42
+ */
43
+ private applyChanges;
44
+ /** Return source file formatting options */
45
+ private getFormattingOptions;
46
+ /** Get language service host, sloppily */
47
+ private getLanguageHost;
48
+ /** Convert a string or string array union to array. Splits strings as comma delimited */
49
+ private asArray;
50
+ private createVisitor;
51
+ private createRouteEntry;
52
+ }
@@ -0,0 +1,344 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ReactTypeScriptFileUpdate = void 0;
4
+ const cli_core_1 = require("@igniteui/cli-core");
5
+ const ts = require("typescript");
6
+ const DEFAULT_ROUTES_VARIABLE = "routes";
7
+ /**
8
+ * Apply various updates to typescript files using AST
9
+ */
10
+ class ReactTypeScriptFileUpdate {
11
+ /** Create updates for a file. Use `add<X>` methods to add transformations and `finalize` to apply and save them. */
12
+ constructor(targetPath) {
13
+ this.targetPath = targetPath;
14
+ this.formatOptions = { spaces: false, indentSize: 4, singleQuotes: false };
15
+ //#region ts.TransformerFactory
16
+ /** Transformation to apply edits to existing named import declarations */
17
+ this.importsTransformer = (context) => (rootNode) => {
18
+ const editImports = this.requestedImports.filter(x => x.edit);
19
+ // https://github.com/Microsoft/TypeScript/issues/14419#issuecomment-307256171
20
+ const visitor = (node) => {
21
+ if (node.kind === ts.SyntaxKind.ImportDeclaration &&
22
+ editImports.find(x => x.from === node.moduleSpecifier.text)) {
23
+ // visit just the source file main array (second visit)
24
+ return visitImport(node);
25
+ }
26
+ else {
27
+ node = ts.visitEachChild(node, visitor, context);
28
+ }
29
+ return node;
30
+ };
31
+ function visitImport(node) {
32
+ node = ts.visitEachChild(node, visitImport, context);
33
+ return node;
34
+ }
35
+ return ts.visitNode(rootNode, visitor);
36
+ };
37
+ this.fileSystem = cli_core_1.App.container.get(cli_core_1.FS_TOKEN);
38
+ this.initState();
39
+ }
40
+ /** Applies accumulated transforms, saves and formats the file */
41
+ finalize() {
42
+ // add new import statements after visitor walks:
43
+ this.addNewFileImports();
44
+ cli_core_1.TypeScriptUtils.saveFile(this.targetPath, this.targetSource);
45
+ this.formatFile(this.targetPath);
46
+ // reset state in case of further updates
47
+ this.initState();
48
+ }
49
+ addRoute(path, component, name, routerChildren, importAlias, routesVariable = DEFAULT_ROUTES_VARIABLE) {
50
+ this.addRouteModuleEntry(path, component, name, routerChildren, importAlias, routesVariable);
51
+ }
52
+ //#region File state
53
+ /** Initializes existing imports info, [re]sets import and `NgModule` edits */
54
+ initState() {
55
+ this.targetSource = cli_core_1.TypeScriptUtils.getFileSource(this.targetPath);
56
+ this.importsMeta = this.loadImportsMeta();
57
+ this.requestedImports = [];
58
+ this.createdStringLiterals = [];
59
+ }
60
+ /* load some metadata about imports */
61
+ loadImportsMeta() {
62
+ const meta = { lastIndex: 0, modulePaths: [] };
63
+ for (let i = 0; i < this.targetSource.statements.length; i++) {
64
+ const statement = this.targetSource.statements[i];
65
+ switch (statement.kind) {
66
+ case ts.SyntaxKind.ImportDeclaration:
67
+ const importStmt = statement;
68
+ if (importStmt.importClause && importStmt.importClause.namedBindings &&
69
+ importStmt.importClause.namedBindings.kind !== ts.SyntaxKind.NamespaceImport) {
70
+ // don't add imports without named (e.g. `import $ from "JQuery"` or `import "./my-module.js";`)
71
+ // don't add namespace imports (`import * as fs`) as available for editing, maybe in the future
72
+ meta.modulePaths.push(importStmt.moduleSpecifier.text);
73
+ }
74
+ // don't add equals imports (`import url = require("url")`) as available for editing, maybe in the future
75
+ case ts.SyntaxKind.ImportEqualsDeclaration:
76
+ meta.lastIndex = i + 1;
77
+ break;
78
+ default:
79
+ break;
80
+ }
81
+ }
82
+ return meta;
83
+ }
84
+ //#endregion File state
85
+ addRouteModuleEntry(path, component, name, routerChildren, importAlias, routesVariable = DEFAULT_ROUTES_VARIABLE) {
86
+ const isRouting = path.indexOf("routing") >= 0;
87
+ if (isRouting && this.targetSource.text.indexOf(path.slice(0, -3)) > 0) {
88
+ return;
89
+ }
90
+ const moduleName = path.substring(0, path.indexOf("-routing"));
91
+ if (path) {
92
+ const relativePath = isRouting ?
93
+ "./views/" + moduleName + "/" + path.slice(0, -3) : cli_core_1.Util.relativePath(this.targetPath, path, true, true);
94
+ this.requestImport(relativePath, importAlias, name);
95
+ }
96
+ // https://github.com/Microsoft/TypeScript/issues/14419#issuecomment-307256171
97
+ const transformer = (context) => (rootNode) => {
98
+ // the visitor that should be used when adding routes to the main route array
99
+ const conditionalVisitor = (node) => {
100
+ if (node.kind === ts.SyntaxKind.ArrayLiteralExpression) {
101
+ const newObject = this.createRouteEntry(component, name, routerChildren);
102
+ const array = node;
103
+ this.createdStringLiterals.push(path, name);
104
+ const notFoundWildCard = ".*";
105
+ const nodes = ts.visitNodes(array.elements, visitor);
106
+ const errorRouteNode = nodes.filter(element => element.getText().includes(notFoundWildCard))[0];
107
+ let resultNodes = null;
108
+ if (errorRouteNode) {
109
+ resultNodes = nodes
110
+ .slice(0, nodes.indexOf(errorRouteNode))
111
+ .concat(newObject)
112
+ .concat(errorRouteNode);
113
+ }
114
+ else {
115
+ resultNodes = nodes
116
+ .concat(newObject);
117
+ }
118
+ const elements = ts.factory.createNodeArray([
119
+ ...resultNodes
120
+ ]);
121
+ return ts.factory.updateArrayLiteralExpression(array, elements);
122
+ }
123
+ else {
124
+ return ts.visitEachChild(node, conditionalVisitor, context);
125
+ }
126
+ };
127
+ let visitCondition;
128
+ if (!isRouting) {
129
+ visitCondition = (node) => {
130
+ return node.kind === ts.SyntaxKind.VariableDeclaration &&
131
+ node.name.getText() === routesVariable;
132
+ // no type currently
133
+ //(node as ts.VariableDeclaration).type.getText() === "Route[]";
134
+ };
135
+ }
136
+ else {
137
+ visitCondition = (node) => {
138
+ return undefined;
139
+ };
140
+ }
141
+ const visitor = this.createVisitor(conditionalVisitor, visitCondition, context);
142
+ context.enableSubstitution(ts.SyntaxKind.ClassDeclaration);
143
+ return ts.visitNode(rootNode, visitor);
144
+ };
145
+ this.targetSource = ts.transform(this.targetSource, [transformer], {
146
+ pretty: true // oh well..
147
+ }).transformed[0];
148
+ this.finalize();
149
+ }
150
+ requestImport(modulePath, routerAlias, componentName) {
151
+ const existing = this.requestedImports.find(x => x.from === modulePath);
152
+ if (!existing) {
153
+ // new imports, check if already exists in file
154
+ this.requestedImports.push({
155
+ as: routerAlias,
156
+ from: modulePath,
157
+ component: componentName,
158
+ edit: this.importsMeta.modulePaths.indexOf(modulePath) !== -1
159
+ });
160
+ }
161
+ else {
162
+ return;
163
+ }
164
+ }
165
+ /** Add `import` statements not previously found in the file */
166
+ addNewFileImports() {
167
+ const newImports = this.requestedImports.filter(x => !x.edit);
168
+ if (!newImports.length) {
169
+ return;
170
+ }
171
+ const newStatements = ts.factory.createNodeArray([
172
+ ...this.targetSource.statements.slice(0, this.importsMeta.lastIndex),
173
+ ...newImports.map(x => this.createIdentifierImport(x.from, x.as, x.component)),
174
+ ...this.targetSource.statements.slice(this.importsMeta.lastIndex)
175
+ ]);
176
+ newImports.forEach(x => this.createdStringLiterals.push(x.from));
177
+ this.targetSource = ts.factory.updateSourceFile(this.targetSource, newStatements);
178
+ }
179
+ createIdentifierImport(importPath, as, component) {
180
+ let exportedObject;
181
+ let exportedObjectName;
182
+ let importClause;
183
+ if (as) {
184
+ exportedObject = "routes";
185
+ exportedObjectName = as.replace(/\s/g, "");
186
+ importClause = ts.factory.createImportClause(false, undefined, ts.factory.createNamedImports([
187
+ ts.factory.createImportSpecifier(false, ts.factory.createIdentifier(exportedObject), ts.factory.createIdentifier(exportedObjectName))
188
+ ]));
189
+ }
190
+ else {
191
+ importClause = ts.factory.createImportClause(false, ts.factory.createIdentifier(component), undefined);
192
+ }
193
+ const importDeclaration = ts.factory.createImportDeclaration(undefined, undefined, importClause, ts.factory.createStringLiteral(importPath, true));
194
+ return importDeclaration;
195
+ }
196
+ //#endregion ts.TransformerFactory
197
+ //#region Formatting
198
+ /** Format a TS source file, very TBD */
199
+ formatFile(filePath) {
200
+ // formatting via LanguageService https://github.com/Microsoft/TypeScript/wiki/Using-the-Compiler-API
201
+ // https://github.com/Microsoft/TypeScript/issues/1651
202
+ let text = this.fileSystem.readFile(filePath);
203
+ // create the language service files
204
+ const services = ts.createLanguageService(this.getLanguageHost(filePath), ts.createDocumentRegistry());
205
+ this.readFormatConfigs();
206
+ const textChanges = services.getFormattingEditsForDocument(filePath, this.getFormattingOptions());
207
+ text = this.applyChanges(text, textChanges);
208
+ if (this.formatOptions.singleQuotes) {
209
+ for (const str of this.createdStringLiterals) {
210
+ // there shouldn't be duplicate strings of these
211
+ text = text.replace(`"${str}"`, `'${str}'`);
212
+ }
213
+ }
214
+ this.fileSystem.writeFile(filePath, text);
215
+ }
216
+ /** Try and parse formatting from project `.editorconfig` / `tslint.json` */
217
+ readFormatConfigs() {
218
+ if (this.fileSystem.fileExists(".editorconfig")) {
219
+ // very basic parsing support
220
+ const text = this.fileSystem.readFile(".editorconfig", "utf-8");
221
+ const options = text
222
+ .replace(/\s*[#;].*([\r\n])/g, "$1") //remove comments
223
+ .replace(/\[(?!\*\]|\*.ts).+\][^\[]+/g, "") // leave [*]/[*.ts] sections
224
+ .split(/\r\n|\r|\n/)
225
+ .reduce((obj, x) => {
226
+ if (x.indexOf("=") !== -1) {
227
+ const pair = x.split("=");
228
+ obj[pair[0].trim()] = pair[1].trim();
229
+ }
230
+ return obj;
231
+ }, {});
232
+ this.formatOptions.spaces = options["indent_style"] === "space";
233
+ if (options["indent_size"]) {
234
+ this.formatOptions.indentSize = parseInt(options["indent_size"], 10) || this.formatOptions.indentSize;
235
+ }
236
+ if (options["quote_type"]) {
237
+ this.formatOptions.singleQuotes = options["quote_type"] === "single";
238
+ }
239
+ }
240
+ if (this.fileSystem.fileExists("tslint.json")) {
241
+ // tslint prio - overrides other settings
242
+ const options = JSON.parse(this.fileSystem.readFile("tslint.json", "utf-8"));
243
+ if (options.rules && options.rules.indent && options.rules.indent[0]) {
244
+ this.formatOptions.spaces = options.rules.indent[1] === "spaces";
245
+ if (options.rules.indent[2]) {
246
+ this.formatOptions.indentSize = parseInt(options.rules.indent[2], 10);
247
+ }
248
+ }
249
+ if (options.rules && options.rules.quotemark && options.rules.quotemark[0]) {
250
+ this.formatOptions.singleQuotes = options.rules.quotemark.indexOf("single") !== -1;
251
+ }
252
+ }
253
+ }
254
+ /**
255
+ * Apply formatting changes (position based) in reverse
256
+ * from https://github.com/Microsoft/TypeScript/issues/1651#issuecomment-69877863
257
+ */
258
+ applyChanges(orig, changes) {
259
+ let result = orig;
260
+ for (let i = changes.length - 1; i >= 0; i--) {
261
+ const change = changes[i];
262
+ const head = result.slice(0, change.span.start);
263
+ const tail = result.slice(change.span.start + change.span.length);
264
+ result = head + change.newText + tail;
265
+ }
266
+ return result;
267
+ }
268
+ /** Return source file formatting options */
269
+ getFormattingOptions() {
270
+ const formatOptions = {
271
+ // tslint:disable:object-literal-sort-keys
272
+ indentSize: this.formatOptions.indentSize,
273
+ tabSize: 4,
274
+ newLineCharacter: ts.sys.newLine,
275
+ convertTabsToSpaces: this.formatOptions.spaces,
276
+ indentStyle: ts.IndentStyle.Smart,
277
+ insertSpaceAfterCommaDelimiter: true,
278
+ insertSpaceAfterSemicolonInForStatements: true,
279
+ insertSpaceBeforeAndAfterBinaryOperators: true,
280
+ insertSpaceAfterKeywordsInControlFlowStatements: true,
281
+ insertSpaceAfterTypeAssertion: true
282
+ // tslint:enable:object-literal-sort-keys
283
+ };
284
+ return formatOptions;
285
+ }
286
+ /** Get language service host, sloppily */
287
+ getLanguageHost(filePath) {
288
+ const files = {};
289
+ files[filePath] = { version: 0 };
290
+ // create the language service host to allow the LS to communicate with the host
291
+ const servicesHost = {
292
+ getCompilationSettings: () => ({}),
293
+ getScriptFileNames: () => Object.keys(files),
294
+ getScriptVersion: fileName => files[fileName] && files[fileName].version.toString(),
295
+ getScriptSnapshot: fileName => {
296
+ if (!this.fileSystem.fileExists(fileName)) {
297
+ return undefined;
298
+ }
299
+ return ts.ScriptSnapshot.fromString(this.fileSystem.readFile(fileName));
300
+ },
301
+ getCurrentDirectory: () => process.cwd(),
302
+ getDefaultLibFileName: options => ts.getDefaultLibFilePath(options),
303
+ readDirectory: ts.sys.readDirectory,
304
+ readFile: ts.sys.readFile,
305
+ fileExists: ts.sys.fileExists
306
+ };
307
+ return servicesHost;
308
+ }
309
+ //#endregion Formatting
310
+ /** Convert a string or string array union to array. Splits strings as comma delimited */
311
+ asArray(value, variables) {
312
+ let result = [];
313
+ if (value) {
314
+ result = typeof value === "string" ? value.split(/\s*,\s*/) : value;
315
+ result = result.map(x => cli_core_1.Util.applyConfigTransformation(x, variables));
316
+ }
317
+ return result;
318
+ }
319
+ createVisitor(conditionalVisitor, visitCondition, nodeContext) {
320
+ return function visitor(node) {
321
+ if (visitCondition(node)) {
322
+ node = ts.visitEachChild(node, conditionalVisitor, nodeContext);
323
+ }
324
+ else {
325
+ node = ts.visitEachChild(node, visitor, nodeContext);
326
+ }
327
+ return node;
328
+ };
329
+ }
330
+ createRouteEntry(className, linkText, routerAlias) {
331
+ const routePath = ts.factory.createPropertyAssignment("path", ts.factory.createStringLiteral(className, true));
332
+ const jsxElement = ts.factory.createJsxSelfClosingElement(ts.factory.createIdentifier(linkText), [], undefined);
333
+ const routeComponent = ts.factory.createPropertyAssignment("element", jsxElement);
334
+ const routeData = ts.factory.createPropertyAssignment("text", ts.factory.createStringLiteral(linkText, true));
335
+ if (routerAlias) {
336
+ const childrenData = ts.factory.createPropertyAssignment("children", ts.factory.createIdentifier(routerAlias));
337
+ return ts.factory.createObjectLiteralExpression([routePath, routeComponent, routeData, childrenData]);
338
+ }
339
+ else {
340
+ return ts.factory.createObjectLiteralExpression([routePath, routeComponent, routeData]);
341
+ }
342
+ }
343
+ }
344
+ exports.ReactTypeScriptFileUpdate = ReactTypeScriptFileUpdate;
@@ -4,7 +4,7 @@ const cli_core_1 = require("@igniteui/cli-core");
4
4
  class IgrReactProjectLibrary extends cli_core_1.BaseProjectLibrary {
5
5
  constructor() {
6
6
  super(__dirname);
7
- this.name = "Ignite UI for React";
7
+ this.name = "Ignite UI for React (deprecated)";
8
8
  this.projectType = "igr-es6";
9
9
  this.themes = ["default"];
10
10
  const groups = require("./groups.json");
@@ -0,0 +1,8 @@
1
+ import { expect, test } from 'vitest';
2
+ import { render } from '@testing-library/react';
3
+ import $(ClassName) from './index';
4
+
5
+ test('renders $(ClassName) component', () => {
6
+ const wrapper = render(<$(ClassName) />);
7
+ expect(wrapper).toBeTruthy();
8
+ });
@@ -0,0 +1,56 @@
1
+ import { IgrBulletGraphModule } from 'igniteui-react-gauges';
2
+ import { IgrBulletGraph } from 'igniteui-react-gauges';
3
+ import style from './style.module.css';
4
+
5
+ IgrBulletGraphModule.register();
6
+
7
+
8
+ export default function $(ClassName)() {
9
+ const title = 'Bullet Graph';
10
+
11
+ return (
12
+ <div>
13
+ <h1 className={style.title}>{title}</h1>
14
+ <div>
15
+ Read more on the&nbsp;
16
+ <a href="https://www.infragistics.com/products/ignite-ui-react/react/components/bulletgraph.html">
17
+ official documentation page
18
+ </a>
19
+ </div>
20
+ <div className={style.container}>
21
+ <div className={style.graph}>
22
+ <IgrBulletGraph
23
+ height="80px" width="400px"
24
+ minimumValue={0} value={70} interval={10}
25
+ maximumValue={100} targetValue={90}
26
+ isScaleInverted={false}
27
+ scaleBackgroundBrush="DodgerBlue"
28
+ scaleBackgroundOutline="DarkViolet"
29
+ scaleBackgroundThickness={2}
30
+ scaleStartExtent={0.05}
31
+ scaleEndExtent={0.95}>
32
+ </IgrBulletGraph>
33
+ </div>
34
+ <div className={style.graph}>
35
+ <IgrBulletGraph
36
+ value={50}
37
+ valueBrush="DodgerBlue"
38
+ valueStrokeThickness={1}
39
+ valueInnerExtent={0.5}
40
+ valueOuterExtent={0.65}
41
+ targetValue={80}
42
+ targetValueBreadth={10}
43
+ targetValueBrush="LimeGreen"
44
+ targetValueOutline="LimeGreen"
45
+ targetValueStrokeThickness={1}
46
+ targetValueInnerExtent={0.3}
47
+ targetValueOuterExtent={0.85}
48
+ height="80px" width="400px"
49
+ minimumValue={0}
50
+ maximumValue={100}>
51
+ </IgrBulletGraph>
52
+ </div>
53
+ </div>
54
+ </div>
55
+ )
56
+ }
@@ -0,0 +1,12 @@
1
+ :local(.container) {
2
+ padding-top: 24px;
3
+ display: flex;
4
+ flex-flow: row;
5
+ justify-content: space-around;
6
+ }
7
+ :local(.title) {
8
+ color: rgb(0, 153, 255);
9
+ }
10
+ :local(.graph) {
11
+ width: 50%;
12
+ }
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const IgniteUIForReactTemplate_1 = require("../../../../../lib/templates/IgniteUIForReactTemplate");
4
+ class IgrTsBulletGraphTemplate extends IgniteUIForReactTemplate_1.IgniteUIForReactTemplate {
5
+ constructor() {
6
+ super(__dirname);
7
+ this.components = ["Bullet Graph"];
8
+ this.controlGroup = "Gauges";
9
+ this.listInComponentTemplates = true;
10
+ this.id = "bullet-graph";
11
+ this.projectType = "igr-ts";
12
+ this.name = "Bullet Graph";
13
+ this.description = `allows for a linear and concise view of measures compared against a scale.`;
14
+ // TODO: read version from igniteui-react-core in package.json
15
+ this.packages = ["igniteui-react-gauges@18.2.2-beta.0"];
16
+ }
17
+ }
18
+ module.exports = new IgrTsBulletGraphTemplate();
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const cli_core_1 = require("@igniteui/cli-core");
4
+ class IgrTsBulletGraphComponent extends cli_core_1.BaseComponent {
5
+ /**
6
+ *
7
+ */
8
+ constructor() {
9
+ super(__dirname);
10
+ this.name = "Bullet Graph";
11
+ this.group = "Gauges";
12
+ this.description = `allows for a linear and concise view of measures compared against a scale.`;
13
+ }
14
+ }
15
+ module.exports = new IgrTsBulletGraphComponent();
@@ -0,0 +1,8 @@
1
+ import { expect, test } from 'vitest';
2
+ import { render } from '@testing-library/react';
3
+ import $(ClassName) from './index';
4
+
5
+ test('renders $(ClassName) component', () => {
6
+ const wrapper = render(<$(ClassName) />);
7
+ expect(wrapper).toBeTruthy();
8
+ });