@adobe/create-ccweb-add-on 3.0.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 (80) hide show
  1. package/.c8rc.json +4 -1
  2. package/bin/run.js +1 -2
  3. package/dist/app/AddOnFactory.d.ts +30 -3
  4. package/dist/app/AddOnFactory.d.ts.map +1 -1
  5. package/dist/app/AddOnFactory.js +140 -1
  6. package/dist/app/{AddOnPackageManager.d.ts → PackageManager.d.ts} +2 -2
  7. package/dist/app/PackageManager.d.ts.map +1 -0
  8. package/dist/app/{AddOnPackageManager.js → PackageManager.js} +2 -2
  9. package/dist/app/TemplateSelector.d.ts +20 -4
  10. package/dist/app/TemplateSelector.d.ts.map +1 -1
  11. package/dist/app/TemplateSelector.js +142 -1
  12. package/dist/app/index.d.ts +1 -3
  13. package/dist/app/index.d.ts.map +1 -1
  14. package/dist/app/index.js +1 -3
  15. package/dist/commands/create.d.ts +1 -1
  16. package/dist/commands/create.d.ts.map +1 -1
  17. package/dist/config/inversify.config.d.ts +1 -1
  18. package/dist/config/inversify.config.d.ts.map +1 -1
  19. package/dist/config/inversify.config.js +8 -6
  20. package/dist/templates/react-javascript/template.json +2 -2
  21. package/dist/templates/react-javascript-with-document-sandbox/template.json +2 -2
  22. package/dist/templates/react-typescript/template.json +2 -2
  23. package/dist/templates/react-typescript-with-document-sandbox/template.json +2 -2
  24. package/dist/templates/swc-javascript/template.json +2 -2
  25. package/dist/templates/swc-javascript-with-document-sandbox/template.json +2 -2
  26. package/dist/templates/swc-typescript/template.json +2 -2
  27. package/dist/templates/swc-typescript-with-document-sandbox/template.json +2 -2
  28. package/dist/tsconfig.tsbuildinfo +1 -1
  29. package/dist/validators/DirectoryValidator.d.ts +22 -11
  30. package/dist/validators/DirectoryValidator.d.ts.map +1 -1
  31. package/dist/validators/DirectoryValidator.js +152 -1
  32. package/dist/validators/EnvironmentValidator.d.ts +17 -2
  33. package/dist/validators/EnvironmentValidator.d.ts.map +1 -1
  34. package/dist/validators/EnvironmentValidator.js +149 -1
  35. package/dist/validators/index.d.ts +0 -2
  36. package/dist/validators/index.d.ts.map +1 -1
  37. package/dist/validators/index.js +0 -2
  38. package/package.json +8 -8
  39. package/src/app/AddOnFactory.ts +164 -4
  40. package/src/app/{AddOnPackageManager.ts → PackageManager.ts} +1 -1
  41. package/src/app/TemplateSelector.ts +157 -5
  42. package/src/app/index.ts +1 -3
  43. package/src/commands/create.ts +1 -1
  44. package/src/config/inversify.config.ts +10 -9
  45. package/src/test/app/{WxpAddOnFactory.spec.ts → AddOnFactory.spec.ts} +7 -6
  46. package/src/test/app/{AddOnPackageManager.spec.ts → PackageManager.spec.ts} +3 -6
  47. package/src/test/app/{AddOnTemplateSelector.spec.ts → TemplateSelector.spec.ts} +27 -14
  48. package/src/test/commands/command.spec.ts +1 -1
  49. package/src/test/commands/create.spec.ts +2 -2
  50. package/src/test/models/CLIOptions.spec.ts +1 -1
  51. package/src/test/validators/{AddOnDirectoryValidator.spec.ts → DirectoryValidator.spec.ts} +5 -6
  52. package/src/test/validators/{NodeEnvironmentValidator.spec.ts → EnvironmentValidator.spec.ts} +6 -19
  53. package/src/validators/DirectoryValidator.ts +172 -11
  54. package/src/validators/EnvironmentValidator.ts +157 -5
  55. package/src/validators/index.ts +0 -2
  56. package/templates/react-javascript/template.json +2 -2
  57. package/templates/react-javascript-with-document-sandbox/template.json +2 -2
  58. package/templates/react-typescript/template.json +2 -2
  59. package/templates/react-typescript-with-document-sandbox/template.json +2 -2
  60. package/templates/swc-javascript/template.json +2 -2
  61. package/templates/swc-javascript-with-document-sandbox/template.json +2 -2
  62. package/templates/swc-typescript/template.json +2 -2
  63. package/templates/swc-typescript-with-document-sandbox/template.json +2 -2
  64. package/dist/app/AddOnPackageManager.d.ts.map +0 -1
  65. package/dist/app/AddOnTemplateSelector.d.ts +0 -54
  66. package/dist/app/AddOnTemplateSelector.d.ts.map +0 -1
  67. package/dist/app/AddOnTemplateSelector.js +0 -168
  68. package/dist/app/WxpAddOnFactory.d.ts +0 -62
  69. package/dist/app/WxpAddOnFactory.d.ts.map +0 -1
  70. package/dist/app/WxpAddOnFactory.js +0 -159
  71. package/dist/validators/AddOnDirectoryValidator.d.ts +0 -55
  72. package/dist/validators/AddOnDirectoryValidator.d.ts.map +0 -1
  73. package/dist/validators/AddOnDirectoryValidator.js +0 -176
  74. package/dist/validators/NodeEnvironmentValidator.d.ts +0 -58
  75. package/dist/validators/NodeEnvironmentValidator.d.ts.map +0 -1
  76. package/dist/validators/NodeEnvironmentValidator.js +0 -173
  77. package/src/app/AddOnTemplateSelector.ts +0 -193
  78. package/src/app/WxpAddOnFactory.ts +0 -196
  79. package/src/validators/AddOnDirectoryValidator.ts +0 -207
  80. package/src/validators/NodeEnvironmentValidator.ts +0 -197
@@ -1,58 +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
- import type { AnalyticsService } from "@adobe/ccweb-add-on-analytics";
25
- import type { Logger, Process } from "@adobe/ccweb-add-on-core";
26
- import "reflect-metadata";
27
- import type { EnvironmentValidator } from "./EnvironmentValidator.js";
28
- /**
29
- * Environment validator implementation class to validate
30
- * the system requirements required for running the app.
31
- */
32
- export declare class NodeEnvironmentValidator implements EnvironmentValidator {
33
- private readonly _process;
34
- private readonly _logger;
35
- private readonly _analyticsService;
36
- /**
37
- * Instantiate {@link NodeEnvironmentValidator}.
38
- *
39
- * @param processHandler - {@link Process} reference.
40
- * @param logger - {@link Logger} reference.
41
- * @param analyticsService - {@link AnalyticsService} reference.
42
- * @returns Reference to a new {@link NodeEnvironmentValidator} instance.
43
- */
44
- constructor(processHandler: Process, logger: Logger, analyticsService: AnalyticsService);
45
- /**
46
- * Validate the node version in the user's system.
47
- */
48
- validateNodeVersion(): Promise<void>;
49
- /**
50
- * Validate the npm version in the user's system.
51
- */
52
- validateNpmVersion(): Promise<void>;
53
- /**
54
- * Validate the npm configuration in the user's system.
55
- */
56
- validateNpmConfiguration(): Promise<void>;
57
- }
58
- //# sourceMappingURL=NodeEnvironmentValidator.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"NodeEnvironmentValidator.d.ts","sourceRoot":"","sources":["../../src/validators/NodeEnvironmentValidator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;kFAsBkF;AAElF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AAEtE,OAAO,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AAIhE,OAAO,kBAAkB,CAAC;AAK1B,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAEtE;;;GAGG;AACH,qBACa,wBAAyB,YAAW,oBAAoB;IACjE,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAU;IACnC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAmB;IACrD;;;;;;;OAOG;gBAE6B,cAAc,EAAE,OAAO,EACxB,MAAM,EAAE,MAAM,EACC,gBAAgB,EAAE,gBAAgB;IAOhF;;OAEG;IACG,mBAAmB,IAAI,OAAO,CAAC,IAAI,CAAC;IA2B1C;;OAEG;IACG,kBAAkB,IAAI,OAAO,CAAC,IAAI,CAAC;IAwCzC;;OAEG;IACG,wBAAwB,IAAI,OAAO,CAAC,IAAI,CAAC;CAmClD"}
@@ -1,173 +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
- import { __decorate, __metadata, __param } from "tslib";
25
- import { ITypes as IAnalyticsTypes } from "@adobe/ccweb-add-on-analytics";
26
- import { ITypes as ICoreTypes } from "@adobe/ccweb-add-on-core";
27
- import { inject, injectable } from "inversify";
28
- import process from "process";
29
- import "reflect-metadata";
30
- import semver from "semver";
31
- import format from "string-template";
32
- import { AnalyticsErrorMarkers } from "../AnalyticsMarkers.js";
33
- import { PROGRAM_NAME } from "../constants.js";
34
- /**
35
- * Environment validator implementation class to validate
36
- * the system requirements required for running the app.
37
- */
38
- let NodeEnvironmentValidator = class NodeEnvironmentValidator {
39
- _process;
40
- _logger;
41
- _analyticsService;
42
- /**
43
- * Instantiate {@link NodeEnvironmentValidator}.
44
- *
45
- * @param processHandler - {@link Process} reference.
46
- * @param logger - {@link Logger} reference.
47
- * @param analyticsService - {@link AnalyticsService} reference.
48
- * @returns Reference to a new {@link NodeEnvironmentValidator} instance.
49
- */
50
- constructor(processHandler, logger, analyticsService) {
51
- this._process = processHandler;
52
- this._logger = logger;
53
- this._analyticsService = analyticsService;
54
- }
55
- /**
56
- * Validate the node version in the user's system.
57
- */
58
- async validateNodeVersion() {
59
- const minNode = "18.0.0";
60
- try {
61
- const result = this._process.executeSync("node", ["--version"]);
62
- const nodeVersion = String(result?.data)?.trim();
63
- const hasMinNode = semver.gte(nodeVersion, minNode);
64
- if (!hasMinNode) {
65
- this._logger.warning(format(LOGS.usingNodeVersion, { nodeVersion }));
66
- this._logger.information(format(LOGS.requiresHigherNode, {
67
- PROGRAM_NAME,
68
- minNode
69
- }));
70
- this._logger.information(LOGS.updateNodeVersion);
71
- await this._analyticsService.postEvent(AnalyticsErrorMarkers.ERROR_INVALID_NODE, format(LOGS.analyticsInvalidNode, { nodeVersion }), false);
72
- return process.exit(0);
73
- }
74
- }
75
- catch (error) {
76
- this._process.handleError(error);
77
- }
78
- }
79
- /**
80
- * Validate the npm version in the user's system.
81
- */
82
- async validateNpmVersion() {
83
- const minNpm = "10.0.0";
84
- try {
85
- const result = this._process.executeSync("npm", ["--version"]);
86
- const npmVersion = result.data ? String(result.data)?.trim() : undefined;
87
- if (!npmVersion) {
88
- this._logger.warning(LOGS.notUsingNpm);
89
- this._logger.information(format(LOGS.requiresHigherNpm, {
90
- PROGRAM_NAME,
91
- minNpm
92
- }));
93
- this._logger.information(LOGS.installNpm);
94
- await this._analyticsService.postEvent(AnalyticsErrorMarkers.ERROR_NO_NPM, LOGS.analyticsNoNpm, false);
95
- return process.exit(0);
96
- }
97
- const hasMinNpm = semver.gte(npmVersion, minNpm);
98
- if (!hasMinNpm) {
99
- this._logger.warning(format(LOGS.usingNpmVersion, { npmVersion }));
100
- this._logger.information(format(LOGS.requiresHigherNpm, {
101
- PROGRAM_NAME,
102
- minNpm
103
- }));
104
- this._logger.information(LOGS.updateNpm);
105
- await this._analyticsService.postEvent(AnalyticsErrorMarkers.ERROR_INVALID_NPM, format(LOGS.analyticsInvalidNpm, { npmVersion }), false);
106
- return process.exit(0);
107
- }
108
- }
109
- catch (error) {
110
- this._process.handleError(error);
111
- }
112
- }
113
- /**
114
- * Validate the npm configuration in the user's system.
115
- */
116
- async validateNpmConfiguration() {
117
- try {
118
- const cwd = process.cwd();
119
- const configList = this._process.executeSync("npm", ["config", "list"])?.data;
120
- if (!configList) {
121
- return;
122
- }
123
- const prefix = "; cwd = ";
124
- const configLines = configList.split("\n");
125
- const cwdLine = configLines.find(line => line.startsWith(prefix));
126
- if (!cwdLine) {
127
- return;
128
- }
129
- const npmCWD = cwdLine.substring(prefix.length);
130
- if (npmCWD === cwd) {
131
- return;
132
- }
133
- this._logger.warning(LOGS.couldNotStartNpmProcess);
134
- this._logger.information(format(LOGS.currentDirectory, { cwd }));
135
- this._logger.information(format(LOGS.newNpmProcessRunsIn, { npmCWD }));
136
- this._logger.information(LOGS.misconfiguredTerminalShell);
137
- await this._analyticsService.postEvent(AnalyticsErrorMarkers.ERROR_NPM_NOT_STARTED, LOGS.analyticsNotStartNpm, false);
138
- return process.exit(0);
139
- }
140
- catch (error) {
141
- return;
142
- }
143
- }
144
- };
145
- NodeEnvironmentValidator = __decorate([
146
- injectable(),
147
- __param(0, inject(ICoreTypes.Process)),
148
- __param(1, inject(ICoreTypes.Logger)),
149
- __param(2, inject(IAnalyticsTypes.AnalyticsService)),
150
- __metadata("design:paramtypes", [Object, Object, Object])
151
- ], NodeEnvironmentValidator);
152
- export { NodeEnvironmentValidator };
153
- const LOGS = {
154
- newLine: "\n",
155
- tab: " ",
156
- usingNodeVersion: "You are using node {nodeVersion}.",
157
- requiresHigherNode: "{PROGRAM_NAME} requires node {minNode} or higher.",
158
- updateNodeVersion: "Please update your version of node.",
159
- notUsingNpm: "You are not using npm.",
160
- requiresHigherNpm: "{PROGRAM_NAME} requires npm {minNpm} or higher.",
161
- installNpm: "Please install npm.",
162
- usingNpmVersion: "You are using npm {npmVersion}.",
163
- updateNpm: "Please update your version of npm.",
164
- couldNotStartNpmProcess: "Could not start an npm process in the right directory.",
165
- currentDirectory: "The current directory is: {cwd}",
166
- newNpmProcessRunsIn: "However, a newly started npm process runs in: {npmCWD}",
167
- misconfiguredTerminalShell: "This is probably caused by a misconfigured system terminal shell.",
168
- analyticsInvalidNode: "Invalid node version: {nodeVersion}",
169
- analyticsNoNpm: "npm is not present",
170
- analyticsInvalidNpm: "Invalid npm version: {npmVersion}",
171
- analyticsNotStartNpm: "npm process could not be started"
172
- };
173
- //# sourceMappingURL=NodeEnvironmentValidator.js.map
@@ -1,193 +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 } from "@adobe/ccweb-add-on-core";
28
- import { ITypes as ICoreTypes, isNullOrWhiteSpace } from "@adobe/ccweb-add-on-core";
29
- import { EntrypointType } from "@adobe/ccweb-add-on-manifest";
30
- import chalk from "chalk";
31
- import { inject, injectable } from "inversify";
32
- import prompts from "prompts";
33
- import "reflect-metadata";
34
- import format from "string-template";
35
- import { AnalyticsErrorMarkers } from "../AnalyticsMarkers.js";
36
- import { ADD_ON_TEMPLATES, AVAILABLE_ADD_ON_TEMPLATES, PROGRAM_NAME, WITH_DOCUMENT_SANDBOX } from "../constants.js";
37
- import type { CLIOptions } from "../models/index.js";
38
- import type { TemplateSelector } from "./TemplateSelector.js";
39
-
40
- @injectable()
41
- export class AddOnTemplateSelector implements TemplateSelector {
42
- private readonly _logger: Logger;
43
- private readonly _analyticsService: AnalyticsService;
44
-
45
- /**
46
- * Instantiate {@link AddOnTemplateSelector}.
47
- * @param logger - {@link Logger} reference.
48
- * @param analyticsService - {@link AnalyticsService} reference.
49
- * @returns Reference to a new {@link AddOnTemplateSelector} instance.
50
- */
51
- constructor(
52
- @inject(ICoreTypes.Logger) logger: Logger,
53
- @inject(IAnalyticsTypes.AnalyticsService) analyticsService: AnalyticsService
54
- ) {
55
- this._logger = logger;
56
- this._analyticsService = analyticsService;
57
- }
58
-
59
- /**
60
- * Sets up a template, as selected/provided by the user
61
- * for scaffolding the add-on project.
62
- * @param options - {@link CLIOptions}.
63
- * @returns User selected/provided template name.
64
- */
65
- async setupTemplate(options: CLIOptions): Promise<string> {
66
- await this._validateAddOnEntrypoint(options.entrypointType);
67
-
68
- if (!isNullOrWhiteSpace(options.templateName)) {
69
- if (AVAILABLE_ADD_ON_TEMPLATES.includes(options.templateName)) {
70
- return options.templateName;
71
- } else {
72
- this._logger.warning(LOGS.chooseValidTemplate, { prefix: LOGS.newLine });
73
- }
74
- }
75
-
76
- // Add a line break for better log readability.
77
- console.log();
78
-
79
- const templateChoices = [];
80
- for (const [templateName, description] of ADD_ON_TEMPLATES.entries()) {
81
- templateChoices.push({
82
- title: this._promptMessageOption(templateName, description),
83
- value: templateName
84
- });
85
- }
86
-
87
- const templateResponse = await prompts.prompt({
88
- type: "select",
89
- name: "selectedTemplate",
90
- message: this._promptMessage(LOGS.setupTemplate),
91
- choices: templateChoices,
92
- initial: 0
93
- });
94
-
95
- if (!templateResponse || !templateResponse.selectedTemplate) {
96
- console.log();
97
- return process.exit(0);
98
- }
99
-
100
- /* c8 ignore next 4 */
101
- /* All templates are currently available. */
102
- if (!AVAILABLE_ADD_ON_TEMPLATES.includes(`${templateResponse.selectedTemplate}-${WITH_DOCUMENT_SANDBOX}`)) {
103
- return templateResponse.selectedTemplate;
104
- }
105
-
106
- const documentSandboxChoices = [
107
- {
108
- title: this._promptMessageOption(LOGS.no),
109
- value: false
110
- },
111
- {
112
- title: this._promptMessageOption(LOGS.yes),
113
- value: true
114
- }
115
- ];
116
- const documentSandboxResponse = await prompts.prompt({
117
- type: "select",
118
- name: "includeDocumentSandbox",
119
- message: this._promptMessage(LOGS.includeDocumentSandbox),
120
- choices: documentSandboxChoices,
121
- initial: 0
122
- });
123
-
124
- if (!documentSandboxResponse || documentSandboxResponse.includeDocumentSandbox === undefined) {
125
- console.log();
126
- return process.exit(0);
127
- }
128
-
129
- // Append `with-document-sandbox` to the template name if user wants to include document sandbox
130
- return documentSandboxResponse.includeDocumentSandbox
131
- ? `${templateResponse.selectedTemplate}-${WITH_DOCUMENT_SANDBOX}`
132
- : templateResponse.selectedTemplate;
133
- }
134
-
135
- private _promptMessage(message: string): string {
136
- return chalk.cyan(message);
137
- }
138
-
139
- private _promptMessageOption(option: string, description?: string): string {
140
- if (description) {
141
- return `${chalk.hex("#E59400").bold(`[${option}]:`)} ${chalk.green(description)}`;
142
- }
143
- return chalk.green.bold(option);
144
- }
145
-
146
- /**
147
- * Validate whether entrypointType is valid or not.
148
- * @param entrypointType - Add-on entrypoint. For example: panel.
149
- */
150
- private async _validateAddOnEntrypoint(entrypointType: EntrypointType): Promise<void> {
151
- if (entrypointType !== EntrypointType.PANEL) {
152
- this._logger.warning(LOGS.chooseValidEntrypointType);
153
- this._logger.warning(
154
- format(LOGS.executeProgramWithValidEntrypointType, {
155
- PROGRAM_NAME
156
- }),
157
- {
158
- prefix: LOGS.tab
159
- }
160
- );
161
- this._logger.message(LOGS.forExample, { prefix: LOGS.newLine });
162
- this._logger.information(
163
- format(LOGS.executeProgramWithValidEntrypointTypeExample, {
164
- PROGRAM_NAME
165
- }),
166
- {
167
- prefix: LOGS.tab
168
- }
169
- );
170
-
171
- await this._analyticsService.postEvent(
172
- AnalyticsErrorMarkers.ERROR_INVALID_KIND,
173
- LOGS.analyticsInvalidEntrypointType,
174
- false
175
- );
176
- return process.exit(0);
177
- }
178
- }
179
- }
180
- const LOGS = {
181
- newLine: "\n",
182
- tab: " ",
183
- setupTemplate: "Please select a template which you want to scaffold the Add-on project with",
184
- chooseValidEntrypointType: "Please choose a valid Add-on entrypoint (valid entrypoint: panel)",
185
- executeProgramWithValidEntrypointType: "{PROGRAM_NAME} <add-on-name> --entrypoint <panel>",
186
- executeProgramWithValidEntrypointTypeExample: "{PROGRAM_NAME} my-add-on --entrypoint panel",
187
- chooseValidTemplate: "You have chosen an invalid template.",
188
- forExample: "For example:",
189
- analyticsInvalidEntrypointType: "Invalid Add-on entrypoint specified",
190
- includeDocumentSandbox: "Do you want to include document sandbox runtime?",
191
- yes: "Yes",
192
- no: "No"
193
- };
@@ -1,196 +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 type { AddOnScaffolder } from "@adobe/ccweb-add-on-scaffolder";
30
- import { ITypes as IScaffolderTypes, PACKAGE_JSON, ScaffolderOptions } from "@adobe/ccweb-add-on-scaffolder";
31
- import fs from "fs-extra";
32
- import { inject, injectable } from "inversify";
33
- import os from "os";
34
- import path from "path";
35
- import process from "process";
36
- import "reflect-metadata";
37
- import format from "string-template";
38
- import url from "url";
39
- import { AnalyticsErrorMarkers, AnalyticsSuccessMarkers } from "../AnalyticsMarkers.js";
40
- import { ITypes } from "../config/inversify.types.js";
41
- import { TEMP_TEMPLATE_PATH } from "../constants.js";
42
- import type { CLIOptions } from "../models/CLIOptions.js";
43
- import type { DirectoryValidator, EnvironmentValidator } from "../validators/index.js";
44
- import type { AddOnFactory } from "./AddOnFactory.js";
45
- import { AddOnPackageManager } from "./AddOnPackageManager.js";
46
- import type { TemplateSelector } from "./TemplateSelector.js";
47
-
48
- /**
49
- * AddOn factory implementation class.
50
- */
51
- @injectable()
52
- export class WxpAddOnFactory implements AddOnFactory {
53
- private readonly _directoryValidator: DirectoryValidator;
54
- private readonly _environmentValidator: EnvironmentValidator;
55
- private readonly _templateSelector: TemplateSelector;
56
-
57
- private readonly _scaffolder: AddOnScaffolder;
58
-
59
- private readonly _process: Process;
60
- private readonly _logger: Logger;
61
-
62
- private readonly _analyticsService: AnalyticsService;
63
-
64
- /**
65
- * Instantiate {@link WxpAddOnFactory}.
66
- * @param directoryValidator - {@link DirectoryValidator} reference.
67
- * @param environmentValidator - {@link EnvironmentValidator} reference.
68
- * @param templateSelector - {@link TemplateSelector} reference.
69
- * @param scaffolder - {@link AddOnScaffolder} reference.
70
- * @param cliProcess - {@link Process} reference.
71
- * @param logger - {@link Logger} reference.
72
- * @param analyticsService - {@link AnalyticsService} reference.
73
- * @returns Reference to a new {@link WxpAddOnFactory} instance.
74
- */
75
- constructor(
76
- @inject(ITypes.DirectoryValidator) directoryValidator: DirectoryValidator,
77
- @inject(ITypes.EnvironmentValidator) environmentValidator: EnvironmentValidator,
78
- @inject(ITypes.TemplateSelector) templateSelector: TemplateSelector,
79
- @inject(IScaffolderTypes.AddOnScaffolder) scaffolder: AddOnScaffolder,
80
- @inject(ICoreTypes.Process) cliProcess: Process,
81
- @inject(ICoreTypes.Logger) logger: Logger,
82
- @inject(IAnalyticsTypes.AnalyticsService) analyticsService: AnalyticsService
83
- ) {
84
- this._directoryValidator = directoryValidator;
85
- this._environmentValidator = environmentValidator;
86
- this._templateSelector = templateSelector;
87
-
88
- this._scaffolder = scaffolder;
89
-
90
- this._process = cliProcess;
91
- this._logger = logger;
92
-
93
- this._analyticsService = analyticsService;
94
- }
95
-
96
- /**
97
- * Create the Add-on project.
98
- * @param options - {@link CLIOptions}.
99
- */
100
- async create(options: CLIOptions): Promise<void> {
101
- let addOnDirectory = "";
102
-
103
- try {
104
- await this._environmentValidator.validateNodeVersion();
105
- await this._environmentValidator.validateNpmVersion();
106
- await this._environmentValidator.validateNpmConfiguration();
107
-
108
- await this._directoryValidator.validateAddOnName(options.addOnName);
109
- addOnDirectory = path.resolve(options.addOnName);
110
- await this._directoryValidator.validateAddOnDirectory(addOnDirectory, options.addOnName);
111
-
112
- this._logger.information(LOGS.creatingWxpAddOn);
113
- this._logger.message(LOGS.mayTakeAMinute);
114
-
115
- const templateName = await this._templateSelector.setupTemplate(options);
116
-
117
- const packageJson = AddOnPackageManager.getPackageJson(options.entrypointType, options.addOnName);
118
- const packageJsonPath = path.join(addOnDirectory, PACKAGE_JSON);
119
-
120
- fs.writeFileSync(packageJsonPath, packageJson.toJSON() + os.EOL);
121
-
122
- this._copyTemplateFiles(addOnDirectory, templateName);
123
-
124
- const rootDirectory = process.cwd();
125
- process.chdir(addOnDirectory);
126
-
127
- const devDependencyArgs = [
128
- "install",
129
- "--save-dev",
130
- "@adobe/ccweb-add-on-scripts",
131
- "@types/adobe__ccweb-add-on-sdk"
132
- ];
133
-
134
- if (options.verbose) {
135
- devDependencyArgs.push("--verbose");
136
- }
137
-
138
- this._logger.information(LOGS.installingDevDependencies, { prefix: LOGS.newLine });
139
- await this._process.execute("npm", devDependencyArgs, { stdio: "inherit" });
140
-
141
- const scaffolderOptions = new ScaffolderOptions(
142
- addOnDirectory,
143
- options.addOnName,
144
- options.entrypointType,
145
- rootDirectory,
146
- templateName,
147
- options.verbose
148
- );
149
-
150
- this._logger.information(format(LOGS.scaffoldingProjectFromTemplate, { templateName }), {
151
- prefix: LOGS.newLine
152
- });
153
-
154
- await this._scaffolder.run(scaffolderOptions);
155
-
156
- const analyticsEventData = [
157
- "--addOnName",
158
- options.addOnName,
159
- "--entrypointType",
160
- options.entrypointType,
161
- "--template",
162
- templateName
163
- ];
164
- await this._analyticsService.postEvent(AnalyticsSuccessMarkers.SUCCESS, analyticsEventData.join(" "), true);
165
- } catch (error) {
166
- this._process.handleError(error);
167
- this._process.removeAddOn(addOnDirectory, options.addOnName);
168
- await this._analyticsService.postEvent(AnalyticsErrorMarkers.ERROR_UNKNOWN_REASON, error.message, false);
169
-
170
- return process.exit(0);
171
- }
172
- }
173
-
174
- private _copyTemplateFiles(addOnDirectory: string, templateName: string) {
175
- const targetPath = path.join(addOnDirectory, TEMP_TEMPLATE_PATH);
176
- fs.ensureDirSync(targetPath);
177
-
178
- const templateDirectory = path.join(url.fileURLToPath(import.meta.url), "..", "..", "templates", templateName);
179
-
180
- if (fs.existsSync(templateDirectory)) {
181
- fs.copySync(templateDirectory, targetPath);
182
- } else {
183
- this._logger.error(LOGS.templateNotFound);
184
- process.exit(1);
185
- }
186
- }
187
- }
188
-
189
- const LOGS = {
190
- newLine: "\n",
191
- creatingWxpAddOn: "Creating a new Add-on ...",
192
- mayTakeAMinute: "This may take a minute ...",
193
- installingDevDependencies: "Installing dev dependencies ...",
194
- scaffoldingProjectFromTemplate: "Scaffolding project from template: {templateName} ...",
195
- templateNotFound: "Could not find the artifacts for the selected template."
196
- };