@adobe/create-ccweb-add-on 2.5.0 → 3.1.0

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 (136) hide show
  1. package/.c8rc.json +4 -1
  2. package/.mocharc.json +9 -2
  3. package/README.md +2 -2
  4. package/bin/run.js +2 -2
  5. package/dist/app/AddOnFactory.d.ts +30 -3
  6. package/dist/app/AddOnFactory.d.ts.map +1 -1
  7. package/dist/app/AddOnFactory.js +140 -1
  8. package/dist/app/{AddOnManager.d.ts → PackageManager.d.ts} +4 -4
  9. package/dist/app/PackageManager.d.ts.map +1 -0
  10. package/dist/app/{AddOnManager.js → PackageManager.js} +5 -6
  11. package/dist/app/TemplateSelector.d.ts +20 -4
  12. package/dist/app/TemplateSelector.d.ts.map +1 -1
  13. package/dist/app/TemplateSelector.js +142 -1
  14. package/dist/app/index.d.ts +1 -3
  15. package/dist/app/index.d.ts.map +1 -1
  16. package/dist/app/index.js +1 -3
  17. package/dist/commands/create.d.ts +6 -10
  18. package/dist/commands/create.d.ts.map +1 -1
  19. package/dist/commands/create.js +11 -37
  20. package/dist/config/inversify.config.d.ts +2 -1
  21. package/dist/config/inversify.config.d.ts.map +1 -1
  22. package/dist/config/inversify.config.js +8 -6
  23. package/dist/config/inversify.types.d.ts.map +1 -1
  24. package/dist/constants.d.ts.map +1 -1
  25. package/dist/index.d.ts +25 -0
  26. package/dist/index.d.ts.map +1 -0
  27. package/dist/index.js +25 -0
  28. package/dist/models/CLIOptions.d.ts +4 -4
  29. package/dist/models/CLIOptions.d.ts.map +1 -1
  30. package/dist/models/CLIOptions.js +5 -5
  31. package/dist/templates/react-javascript/template/src/components/App.jsx +2 -2
  32. package/dist/templates/react-javascript/template/webpack.config.js +1 -0
  33. package/dist/templates/react-javascript/template.json +4 -4
  34. package/dist/templates/react-javascript-with-document-sandbox/template/src/ui/components/App.jsx +2 -2
  35. package/dist/templates/react-javascript-with-document-sandbox/template/webpack.config.js +1 -0
  36. package/dist/templates/react-javascript-with-document-sandbox/template.json +4 -4
  37. package/dist/templates/react-typescript/template/src/components/App.tsx +2 -2
  38. package/dist/templates/react-typescript/template/webpack.config.js +1 -0
  39. package/dist/templates/react-typescript/template.json +4 -4
  40. package/dist/templates/react-typescript-with-document-sandbox/template/src/ui/components/App.tsx +2 -2
  41. package/dist/templates/react-typescript-with-document-sandbox/template/webpack.config.js +1 -0
  42. package/dist/templates/react-typescript-with-document-sandbox/template.json +4 -4
  43. package/dist/templates/swc-javascript/template/src/components/App.js +2 -2
  44. package/dist/templates/swc-javascript/template/webpack.config.js +1 -0
  45. package/dist/templates/swc-javascript/template.json +4 -4
  46. package/dist/templates/swc-javascript-with-document-sandbox/template/src/ui/components/App.js +2 -2
  47. package/dist/templates/swc-javascript-with-document-sandbox/template/webpack.config.js +1 -0
  48. package/dist/templates/swc-javascript-with-document-sandbox/template.json +4 -4
  49. package/dist/templates/swc-typescript/template/src/components/App.css.ts +2 -2
  50. package/dist/templates/swc-typescript/template/src/components/App.ts +4 -4
  51. package/dist/templates/swc-typescript/template/src/index.ts +2 -2
  52. package/dist/templates/swc-typescript/template/webpack.config.js +1 -0
  53. package/dist/templates/swc-typescript/template.json +4 -4
  54. package/dist/templates/swc-typescript-with-document-sandbox/template/src/ui/components/App.css.ts +2 -2
  55. package/dist/templates/swc-typescript-with-document-sandbox/template/src/ui/components/App.ts +4 -4
  56. package/dist/templates/swc-typescript-with-document-sandbox/template/src/ui/index.ts +2 -2
  57. package/dist/templates/swc-typescript-with-document-sandbox/template/webpack.config.js +1 -0
  58. package/dist/templates/swc-typescript-with-document-sandbox/template.json +4 -4
  59. package/dist/tsconfig.tsbuildinfo +1 -1
  60. package/dist/validators/DirectoryValidator.d.ts +22 -11
  61. package/dist/validators/DirectoryValidator.d.ts.map +1 -1
  62. package/dist/validators/DirectoryValidator.js +152 -1
  63. package/dist/validators/EnvironmentValidator.d.ts +17 -2
  64. package/dist/validators/EnvironmentValidator.d.ts.map +1 -1
  65. package/dist/validators/EnvironmentValidator.js +149 -1
  66. package/dist/validators/index.d.ts +0 -2
  67. package/dist/validators/index.d.ts.map +1 -1
  68. package/dist/validators/index.js +0 -2
  69. package/package.json +26 -20
  70. package/src/app/AddOnFactory.ts +164 -4
  71. package/src/app/{AddOnManager.ts → PackageManager.ts} +4 -6
  72. package/src/app/TemplateSelector.ts +157 -5
  73. package/src/app/index.ts +1 -3
  74. package/src/commands/create.ts +24 -48
  75. package/src/config/inversify.config.ts +11 -9
  76. package/src/config/inversify.types.ts +7 -1
  77. package/src/constants.ts +2 -2
  78. package/src/index.ts +25 -0
  79. package/src/models/CLIOptions.ts +5 -5
  80. package/src/test/app/{WxpAddOnFactory.spec.ts → AddOnFactory.spec.ts} +18 -17
  81. package/src/test/app/{AddOnManager.spec.ts → PackageManager.spec.ts} +6 -6
  82. package/src/test/app/{AddOnTemplateSelector.spec.ts → TemplateSelector.spec.ts} +57 -26
  83. package/src/test/commands/command.spec.ts +80 -0
  84. package/src/test/commands/create.spec.ts +44 -18
  85. package/src/test/models/CLIOptions.spec.ts +4 -4
  86. package/src/test/validators/{AddOnDirectoryValidator.spec.ts → DirectoryValidator.spec.ts} +29 -21
  87. package/src/test/validators/{NodeEnvironmentValidator.spec.ts → EnvironmentValidator.spec.ts} +11 -24
  88. package/src/validators/DirectoryValidator.ts +172 -11
  89. package/src/validators/EnvironmentValidator.ts +157 -5
  90. package/src/validators/index.ts +0 -2
  91. package/templates/react-javascript/template/src/components/App.jsx +2 -2
  92. package/templates/react-javascript/template/webpack.config.js +1 -0
  93. package/templates/react-javascript/template.json +4 -4
  94. package/templates/react-javascript-with-document-sandbox/template/src/ui/components/App.jsx +2 -2
  95. package/templates/react-javascript-with-document-sandbox/template/webpack.config.js +1 -0
  96. package/templates/react-javascript-with-document-sandbox/template.json +4 -4
  97. package/templates/react-typescript/template/src/components/App.tsx +2 -2
  98. package/templates/react-typescript/template/webpack.config.js +1 -0
  99. package/templates/react-typescript/template.json +4 -4
  100. package/templates/react-typescript-with-document-sandbox/template/src/ui/components/App.tsx +2 -2
  101. package/templates/react-typescript-with-document-sandbox/template/webpack.config.js +1 -0
  102. package/templates/react-typescript-with-document-sandbox/template.json +4 -4
  103. package/templates/swc-javascript/template/src/components/App.js +2 -2
  104. package/templates/swc-javascript/template/webpack.config.js +1 -0
  105. package/templates/swc-javascript/template.json +4 -4
  106. package/templates/swc-javascript-with-document-sandbox/template/src/ui/components/App.js +2 -2
  107. package/templates/swc-javascript-with-document-sandbox/template/webpack.config.js +1 -0
  108. package/templates/swc-javascript-with-document-sandbox/template.json +4 -4
  109. package/templates/swc-typescript/template/src/components/App.css.ts +2 -2
  110. package/templates/swc-typescript/template/src/components/App.ts +4 -4
  111. package/templates/swc-typescript/template/src/index.ts +2 -2
  112. package/templates/swc-typescript/template/webpack.config.js +1 -0
  113. package/templates/swc-typescript/template.json +4 -4
  114. package/templates/swc-typescript-with-document-sandbox/template/src/ui/components/App.css.ts +2 -2
  115. package/templates/swc-typescript-with-document-sandbox/template/src/ui/components/App.ts +4 -4
  116. package/templates/swc-typescript-with-document-sandbox/template/src/ui/index.ts +2 -2
  117. package/templates/swc-typescript-with-document-sandbox/template/webpack.config.js +1 -0
  118. package/templates/swc-typescript-with-document-sandbox/template.json +4 -4
  119. package/tsconfig.json +3 -1
  120. package/dist/app/AddOnManager.d.ts.map +0 -1
  121. package/dist/app/AddOnTemplateSelector.d.ts +0 -54
  122. package/dist/app/AddOnTemplateSelector.d.ts.map +0 -1
  123. package/dist/app/AddOnTemplateSelector.js +0 -168
  124. package/dist/app/WxpAddOnFactory.d.ts +0 -62
  125. package/dist/app/WxpAddOnFactory.d.ts.map +0 -1
  126. package/dist/app/WxpAddOnFactory.js +0 -159
  127. package/dist/validators/AddOnDirectoryValidator.d.ts +0 -55
  128. package/dist/validators/AddOnDirectoryValidator.d.ts.map +0 -1
  129. package/dist/validators/AddOnDirectoryValidator.js +0 -176
  130. package/dist/validators/NodeEnvironmentValidator.d.ts +0 -58
  131. package/dist/validators/NodeEnvironmentValidator.d.ts.map +0 -1
  132. package/dist/validators/NodeEnvironmentValidator.js +0 -173
  133. package/src/app/AddOnTemplateSelector.ts +0 -193
  134. package/src/app/WxpAddOnFactory.ts +0 -196
  135. package/src/validators/AddOnDirectoryValidator.ts +0 -207
  136. package/src/validators/NodeEnvironmentValidator.ts +0 -197
@@ -1,197 +0,0 @@
1
- /********************************************************************************
2
- * MIT License
3
-
4
- * © Copyright 2023 Adobe. All rights reserved.
5
-
6
- * Permission is hereby granted, free of charge, to any person obtaining a copy
7
- * of this software and associated documentation files (the "Software"), to deal
8
- * in the Software without restriction, including without limitation the rights
9
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- * copies of the Software, and to permit persons to whom the Software is
11
- * furnished to do so, subject to the following conditions:
12
- *
13
- * The above copyright notice and this permission notice shall be included in all
14
- * copies or substantial portions of the Software.
15
- *
16
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
- * SOFTWARE.
23
- ********************************************************************************/
24
-
25
- import type { AnalyticsService } from "@adobe/ccweb-add-on-analytics";
26
- import { ITypes as IAnalyticsTypes } from "@adobe/ccweb-add-on-analytics";
27
- import type { Logger, Process } from "@adobe/ccweb-add-on-core";
28
- import { ITypes as ICoreTypes } from "@adobe/ccweb-add-on-core";
29
- import { inject, injectable } from "inversify";
30
- import process from "process";
31
- import "reflect-metadata";
32
- import semver from "semver";
33
- import format from "string-template";
34
- import { AnalyticsErrorMarkers } from "../AnalyticsMarkers.js";
35
- import { PROGRAM_NAME } from "../constants.js";
36
- import type { EnvironmentValidator } from "./EnvironmentValidator.js";
37
-
38
- /**
39
- * Environment validator implementation class to validate
40
- * the system requirements required for running the app.
41
- */
42
- @injectable()
43
- export class NodeEnvironmentValidator implements EnvironmentValidator {
44
- private readonly _process: Process;
45
- private readonly _logger: Logger;
46
- private readonly _analyticsService: AnalyticsService;
47
- /**
48
- * Instantiate {@link NodeEnvironmentValidator}.
49
- *
50
- * @param processHandler - {@link Process} reference.
51
- * @param logger - {@link Logger} reference.
52
- * @param analyticsService - {@link AnalyticsService} reference.
53
- * @returns Reference to a new {@link NodeEnvironmentValidator} instance.
54
- */
55
- constructor(
56
- @inject(ICoreTypes.Process) processHandler: Process,
57
- @inject(ICoreTypes.Logger) logger: Logger,
58
- @inject(IAnalyticsTypes.AnalyticsService) analyticsService: AnalyticsService
59
- ) {
60
- this._process = processHandler;
61
- this._logger = logger;
62
- this._analyticsService = analyticsService;
63
- }
64
-
65
- /**
66
- * Validate the node version in the user's system.
67
- */
68
- async validateNodeVersion(): Promise<void> {
69
- const minNode = "16.0.0";
70
- try {
71
- const result = this._process.executeSync("node", ["--version"]);
72
- const nodeVersion = String(result?.data)?.trim();
73
- const hasMinNode = semver.gte(nodeVersion, minNode);
74
- if (!hasMinNode) {
75
- this._logger.warning(format(LOGS.usingNodeVersion, { nodeVersion }));
76
- this._logger.information(
77
- format(LOGS.requiresHigherNode, {
78
- PROGRAM_NAME,
79
- minNode
80
- })
81
- );
82
- this._logger.information(LOGS.updateNodeVersion);
83
- await this._analyticsService.postEvent(
84
- AnalyticsErrorMarkers.ERROR_INVALID_NODE,
85
- format(LOGS.analyticsInvalidNode, { nodeVersion }),
86
- false
87
- );
88
- return process.exit(0);
89
- }
90
- } catch (error) {
91
- this._process.handleError(error);
92
- }
93
- }
94
-
95
- /**
96
- * Validate the npm version in the user's system.
97
- */
98
- async validateNpmVersion(): Promise<void> {
99
- const minNpm = "8.0.0";
100
- try {
101
- const result = this._process.executeSync("npm", ["--version"]);
102
- const npmVersion = result.data ? String(result.data)?.trim() : undefined;
103
- if (!npmVersion) {
104
- this._logger.warning(LOGS.notUsingNpm);
105
- this._logger.information(
106
- format(LOGS.requiresHigherNpm, {
107
- PROGRAM_NAME,
108
- minNpm
109
- })
110
- );
111
- this._logger.information(LOGS.installNpm);
112
- await this._analyticsService.postEvent(AnalyticsErrorMarkers.ERROR_NO_NPM, LOGS.analyticsNoNpm, false);
113
- return process.exit(0);
114
- }
115
-
116
- const hasMinNpm = semver.gte(npmVersion, minNpm);
117
- if (!hasMinNpm) {
118
- this._logger.warning(format(LOGS.usingNpmVersion, { npmVersion }));
119
- this._logger.information(
120
- format(LOGS.requiresHigherNpm, {
121
- PROGRAM_NAME,
122
- minNpm
123
- })
124
- );
125
- this._logger.information(LOGS.updateNpm);
126
- await this._analyticsService.postEvent(
127
- AnalyticsErrorMarkers.ERROR_INVALID_NPM,
128
- format(LOGS.analyticsInvalidNpm, { npmVersion }),
129
- false
130
- );
131
- return process.exit(0);
132
- }
133
- } catch (error) {
134
- this._process.handleError(error);
135
- }
136
- }
137
-
138
- /**
139
- * Validate the npm configuration in the user's system.
140
- */
141
- async validateNpmConfiguration(): Promise<void> {
142
- try {
143
- const cwd = process.cwd();
144
- const configList = this._process.executeSync("npm", ["config", "list"])?.data;
145
- if (!configList) {
146
- return;
147
- }
148
-
149
- const prefix = "; cwd = ";
150
- const configLines = configList.split("\n");
151
- const cwdLine = configLines.find(line => line.startsWith(prefix));
152
- if (!cwdLine) {
153
- return;
154
- }
155
-
156
- const npmCWD = cwdLine.substring(prefix.length);
157
- if (npmCWD === cwd) {
158
- return;
159
- }
160
-
161
- this._logger.warning(LOGS.couldNotStartNpmProcess);
162
- this._logger.information(format(LOGS.currentDirectory, { cwd }));
163
- this._logger.information(format(LOGS.newNpmProcessRunsIn, { npmCWD }));
164
- this._logger.information(LOGS.misconfiguredTerminalShell);
165
-
166
- await this._analyticsService.postEvent(
167
- AnalyticsErrorMarkers.ERROR_NPM_NOT_STARTED,
168
- LOGS.analyticsNotStartNpm,
169
- false
170
- );
171
- return process.exit(0);
172
- } catch (error) {
173
- return;
174
- }
175
- }
176
- }
177
-
178
- const LOGS = {
179
- newLine: "\n",
180
- tab: " ",
181
- usingNodeVersion: "You are using node {nodeVersion}.",
182
- requiresHigherNode: "{PROGRAM_NAME} requires node {minNode} or higher.",
183
- updateNodeVersion: "Please update your version of node.",
184
- notUsingNpm: "You are not using npm.",
185
- requiresHigherNpm: "{PROGRAM_NAME} requires npm {minNpm} or higher.",
186
- installNpm: "Please install npm.",
187
- usingNpmVersion: "You are using npm {npmVersion}.",
188
- updateNpm: "Please update your version of npm.",
189
- couldNotStartNpmProcess: "Could not start an npm process in the right directory.",
190
- currentDirectory: "The current directory is: {cwd}",
191
- newNpmProcessRunsIn: "However, a newly started npm process runs in: {npmCWD}",
192
- misconfiguredTerminalShell: "This is probably caused by a misconfigured system terminal shell.",
193
- analyticsInvalidNode: "Invalid node version: {nodeVersion}",
194
- analyticsNoNpm: "npm is not present",
195
- analyticsInvalidNpm: "Invalid npm version: {npmVersion}",
196
- analyticsNotStartNpm: "npm process could not be started"
197
- };