@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
package/.c8rc.json CHANGED
@@ -4,12 +4,15 @@
4
4
  "exclude": [
5
5
  "src/**/*.spec.ts",
6
6
  "src/**/index.ts",
7
- "src/**/Types.ts",
8
7
  "src/config/*",
9
8
  "src/constants.ts",
10
9
  "src/templates/*",
11
10
  "**/*.d.ts"
12
11
  ],
12
+ "lines": 100,
13
+ "functions": 100,
14
+ "branches": 100,
15
+ "statements": 100,
13
16
  "reporter": ["html", "text", "text-summary"],
14
17
  "report-dir": "coverage"
15
18
  }
package/.mocharc.json CHANGED
@@ -1,5 +1,12 @@
1
1
  {
2
2
  "extension": ["ts"],
3
- "node-option": ["experimental-specifier-resolution=node", "loader=ts-node/esm", "no-warnings"],
4
- "spec": ["src/test/**/*.spec.ts"]
3
+ "node-option": [
4
+ "experimental-specifier-resolution=node",
5
+ "loader=ts-node/esm",
6
+ "enable-source-maps",
7
+ "no-warnings"
8
+ ],
9
+ "spec": ["src/test/**/*.spec.ts"],
10
+ "recursive": true,
11
+ "timeout": 60000
5
12
  }
package/README.md CHANGED
@@ -27,8 +27,8 @@ To quickly get started building an Adobe Express add-on, follow these steps, or
27
27
 
28
28
  You'll need:
29
29
 
30
- - Node 16 or better
31
- - NPM 8 or better
30
+ - Node 18 or better
31
+ - NPM 10 or better
32
32
  - A text editor
33
33
  - A free Adobe account — don't have one? Get one [here](https://www.adobe.com/express/)
34
34
 
package/bin/run.js CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  import oclif from "@oclif/core";
4
4
 
5
- oclif
6
- .run(process.argv.slice(2), import.meta.url)
5
+ await oclif
6
+ .execute({ dir: import.meta.url })
7
7
  .then(oclif.flush)
8
8
  .catch(oclif.Errors.handle);
@@ -21,15 +21,42 @@
21
21
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
22
  * SOFTWARE.
23
23
  ********************************************************************************/
24
+ import type { AnalyticsService } from "@adobe/ccweb-add-on-analytics";
25
+ import type { Logger, Process } from "@adobe/ccweb-add-on-core";
26
+ import type { AddOnScaffolder } from "@adobe/ccweb-add-on-scaffolder";
27
+ import "reflect-metadata";
24
28
  import type { CLIOptions } from "../models/CLIOptions.js";
29
+ import { DirectoryValidator } from "../validators/DirectoryValidator.js";
30
+ import { EnvironmentValidator } from "../validators/EnvironmentValidator.js";
31
+ import { TemplateSelector } from "./TemplateSelector.js";
25
32
  /**
26
- * Factory interface for creating the Add-on project.
33
+ * AddOn factory implementation class.
27
34
  */
28
- export interface AddOnFactory {
35
+ export declare class AddOnFactory {
36
+ private readonly _directoryValidator;
37
+ private readonly _environmentValidator;
38
+ private readonly _templateSelector;
39
+ private readonly _scaffolder;
40
+ private readonly _process;
41
+ private readonly _logger;
42
+ private readonly _analyticsService;
29
43
  /**
30
- * Create the Add-on.
44
+ * Instantiate {@link AddOnFactory}.
45
+ * @param directoryValidator - {@link DirectoryValidator} reference.
46
+ * @param environmentValidator - {@link EnvironmentValidator} reference.
47
+ * @param templateSelector - {@link TemplateSelector} reference.
48
+ * @param scaffolder - {@link AddOnScaffolder} reference.
49
+ * @param cliProcess - {@link Process} reference.
50
+ * @param logger - {@link Logger} reference.
51
+ * @param analyticsService - {@link AnalyticsService} reference.
52
+ * @returns Reference to a new {@link AddOnFactory} instance.
53
+ */
54
+ constructor(directoryValidator: DirectoryValidator, environmentValidator: EnvironmentValidator, templateSelector: TemplateSelector, scaffolder: AddOnScaffolder, cliProcess: Process, logger: Logger, analyticsService: AnalyticsService);
55
+ /**
56
+ * Create the Add-on project.
31
57
  * @param options - {@link CLIOptions}.
32
58
  */
33
59
  create(options: CLIOptions): Promise<void>;
60
+ private _copyTemplateFiles;
34
61
  }
35
62
  //# sourceMappingURL=AddOnFactory.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"AddOnFactory.d.ts","sourceRoot":"","sources":["../../src/app/AddOnFactory.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;kFAsBkF;AAElF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAE1D;;GAEG;AACH,MAAM,WAAW,YAAY;IACzB;;;OAGG;IACH,MAAM,CAAC,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC9C"}
1
+ {"version":3,"file":"AddOnFactory.d.ts","sourceRoot":"","sources":["../../src/app/AddOnFactory.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;AAEhE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AAOtE,OAAO,kBAAkB,CAAC;AAM1B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,qCAAqC,CAAC;AACzE,OAAO,EAAE,oBAAoB,EAAE,MAAM,uCAAuC,CAAC;AAE7E,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEzD;;GAEG;AACH,qBACa,YAAY;IACrB,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAAqB;IACzD,OAAO,CAAC,QAAQ,CAAC,qBAAqB,CAAuB;IAC7D,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAmB;IAErD,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAkB;IAE9C,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAU;IACnC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IAEjC,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAmB;IAErD;;;;;;;;;;OAUG;gBAEoC,kBAAkB,EAAE,kBAAkB,EACpC,oBAAoB,EAAE,oBAAoB,EAC9C,gBAAgB,EAAE,gBAAgB,EACzB,UAAU,EAAE,eAAe,EACzC,UAAU,EAAE,OAAO,EACpB,MAAM,EAAE,MAAM,EACC,gBAAgB,EAAE,gBAAgB;IAchF;;;OAGG;IACG,MAAM,CAAC,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IA0EhD,OAAO,CAAC,kBAAkB;CAa7B"}
@@ -21,5 +21,144 @@
21
21
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
22
  * SOFTWARE.
23
23
  ********************************************************************************/
24
- export {};
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 { ITypes as IScaffolderTypes, PACKAGE_JSON, ScaffolderOptions } from "@adobe/ccweb-add-on-scaffolder";
28
+ import fs from "fs-extra";
29
+ import { inject, injectable } from "inversify";
30
+ import os from "os";
31
+ import path from "path";
32
+ import process from "process";
33
+ import "reflect-metadata";
34
+ import format from "string-template";
35
+ import url from "url";
36
+ import { AnalyticsErrorMarkers, AnalyticsSuccessMarkers } from "../AnalyticsMarkers.js";
37
+ import { ITypes } from "../config/inversify.types.js";
38
+ import { TEMP_TEMPLATE_PATH } from "../constants.js";
39
+ import { DirectoryValidator } from "../validators/DirectoryValidator.js";
40
+ import { EnvironmentValidator } from "../validators/EnvironmentValidator.js";
41
+ import { PackageManager } from "./PackageManager.js";
42
+ import { TemplateSelector } from "./TemplateSelector.js";
43
+ /**
44
+ * AddOn factory implementation class.
45
+ */
46
+ let AddOnFactory = class AddOnFactory {
47
+ _directoryValidator;
48
+ _environmentValidator;
49
+ _templateSelector;
50
+ _scaffolder;
51
+ _process;
52
+ _logger;
53
+ _analyticsService;
54
+ /**
55
+ * Instantiate {@link AddOnFactory}.
56
+ * @param directoryValidator - {@link DirectoryValidator} reference.
57
+ * @param environmentValidator - {@link EnvironmentValidator} reference.
58
+ * @param templateSelector - {@link TemplateSelector} reference.
59
+ * @param scaffolder - {@link AddOnScaffolder} reference.
60
+ * @param cliProcess - {@link Process} reference.
61
+ * @param logger - {@link Logger} reference.
62
+ * @param analyticsService - {@link AnalyticsService} reference.
63
+ * @returns Reference to a new {@link AddOnFactory} instance.
64
+ */
65
+ constructor(directoryValidator, environmentValidator, templateSelector, scaffolder, cliProcess, logger, analyticsService) {
66
+ this._directoryValidator = directoryValidator;
67
+ this._environmentValidator = environmentValidator;
68
+ this._templateSelector = templateSelector;
69
+ this._scaffolder = scaffolder;
70
+ this._process = cliProcess;
71
+ this._logger = logger;
72
+ this._analyticsService = analyticsService;
73
+ }
74
+ /**
75
+ * Create the Add-on project.
76
+ * @param options - {@link CLIOptions}.
77
+ */
78
+ async create(options) {
79
+ let addOnDirectory = "";
80
+ try {
81
+ await this._environmentValidator.validateNodeVersion();
82
+ await this._environmentValidator.validateNpmVersion();
83
+ await this._environmentValidator.validateNpmConfiguration();
84
+ await this._directoryValidator.validateAddOnName(options.addOnName);
85
+ addOnDirectory = path.resolve(options.addOnName);
86
+ await this._directoryValidator.validateAddOnDirectory(addOnDirectory, options.addOnName);
87
+ this._logger.information(LOGS.creatingAddOn);
88
+ this._logger.message(LOGS.mayTakeAMinute);
89
+ const templateName = await this._templateSelector.setupTemplate(options);
90
+ const packageJson = PackageManager.getPackageJson(options.entrypointType, options.addOnName);
91
+ const packageJsonPath = path.join(addOnDirectory, PACKAGE_JSON);
92
+ fs.writeFileSync(packageJsonPath, packageJson.toJSON() + os.EOL);
93
+ this._copyTemplateFiles(addOnDirectory, templateName);
94
+ const rootDirectory = process.cwd();
95
+ process.chdir(addOnDirectory);
96
+ const devDependencyArgs = [
97
+ "install",
98
+ "--save-dev",
99
+ "@adobe/ccweb-add-on-scripts",
100
+ "@types/adobe__ccweb-add-on-sdk"
101
+ ];
102
+ if (options.verbose) {
103
+ devDependencyArgs.push("--verbose");
104
+ }
105
+ this._logger.information(LOGS.installingDevDependencies, { prefix: LOGS.newLine });
106
+ await this._process.execute("npm", devDependencyArgs, { stdio: "inherit" });
107
+ const scaffolderOptions = new ScaffolderOptions(addOnDirectory, options.addOnName, options.entrypointType, rootDirectory, templateName, options.verbose);
108
+ this._logger.information(format(LOGS.scaffoldingProjectFromTemplate, { templateName }), {
109
+ prefix: LOGS.newLine
110
+ });
111
+ await this._scaffolder.run(scaffolderOptions);
112
+ const analyticsEventData = [
113
+ "--addOnName",
114
+ options.addOnName,
115
+ "--entrypointType",
116
+ options.entrypointType,
117
+ "--template",
118
+ templateName
119
+ ];
120
+ await this._analyticsService.postEvent(AnalyticsSuccessMarkers.SUCCESS, analyticsEventData.join(" "), true);
121
+ }
122
+ catch (error) {
123
+ this._process.handleError(error);
124
+ this._process.removeAddOn(addOnDirectory, options.addOnName);
125
+ await this._analyticsService.postEvent(AnalyticsErrorMarkers.ERROR_UNKNOWN_REASON, error.message, false);
126
+ return process.exit(0);
127
+ }
128
+ }
129
+ _copyTemplateFiles(addOnDirectory, templateName) {
130
+ const targetPath = path.join(addOnDirectory, TEMP_TEMPLATE_PATH);
131
+ fs.ensureDirSync(targetPath);
132
+ const templateDirectory = path.join(url.fileURLToPath(import.meta.url), "..", "..", "templates", templateName);
133
+ if (fs.existsSync(templateDirectory)) {
134
+ fs.copySync(templateDirectory, targetPath);
135
+ }
136
+ else {
137
+ this._logger.error(LOGS.templateNotFound);
138
+ process.exit(1);
139
+ }
140
+ }
141
+ };
142
+ AddOnFactory = __decorate([
143
+ injectable(),
144
+ __param(0, inject(ITypes.DirectoryValidator)),
145
+ __param(1, inject(ITypes.EnvironmentValidator)),
146
+ __param(2, inject(ITypes.TemplateSelector)),
147
+ __param(3, inject(IScaffolderTypes.AddOnScaffolder)),
148
+ __param(4, inject(ICoreTypes.Process)),
149
+ __param(5, inject(ICoreTypes.Logger)),
150
+ __param(6, inject(IAnalyticsTypes.AnalyticsService)),
151
+ __metadata("design:paramtypes", [DirectoryValidator,
152
+ EnvironmentValidator,
153
+ TemplateSelector, Function, Object, Object, Function])
154
+ ], AddOnFactory);
155
+ export { AddOnFactory };
156
+ const LOGS = {
157
+ newLine: "\n",
158
+ creatingAddOn: "Creating a new Add-on ...",
159
+ mayTakeAMinute: "This may take a minute ...",
160
+ installingDevDependencies: "Installing dev dependencies ...",
161
+ scaffoldingProjectFromTemplate: "Scaffolding project from template: {templateName} ...",
162
+ templateNotFound: "Could not find the artifacts for the selected template."
163
+ };
25
164
  //# sourceMappingURL=AddOnFactory.js.map
@@ -26,13 +26,13 @@ import type { EntrypointType } from "@adobe/ccweb-add-on-manifest";
26
26
  /**
27
27
  * Class to manage the Add-on project requirements.
28
28
  */
29
- export declare class AddOnManager {
29
+ export declare class PackageManager {
30
30
  /**
31
31
  * Get package.json for the Add-on project.
32
- * @param addOnKind - Kind of Add-on. For example: panel.
32
+ * @param entrypointType - Entrypoint type of Add-on. For example: panel, command, etc.
33
33
  * @param addOnName - Name of Add-on.
34
34
  * @returns package.json as {@link PackageJson}.
35
35
  */
36
- static getPackageJson(addOnKind: EntrypointType, addOnName: string): PackageJson;
36
+ static getPackageJson(entrypointType: EntrypointType, addOnName: string): PackageJson;
37
37
  }
38
- //# sourceMappingURL=AddOnManager.d.ts.map
38
+ //# sourceMappingURL=PackageManager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PackageManager.d.ts","sourceRoot":"","sources":["../../src/app/PackageManager.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;kFAsBkF;AAElF,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAEnE;;GAEG;AACH,qBAAa,cAAc;IACvB;;;;;OAKG;IACH,MAAM,CAAC,cAAc,CAAC,cAAc,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,GAAG,WAAW;CAaxF"}
@@ -25,20 +25,19 @@ import { PackageJson } from "@adobe/ccweb-add-on-core";
25
25
  /**
26
26
  * Class to manage the Add-on project requirements.
27
27
  */
28
- export class AddOnManager {
28
+ export class PackageManager {
29
29
  /**
30
30
  * Get package.json for the Add-on project.
31
- * @param addOnKind - Kind of Add-on. For example: panel.
31
+ * @param entrypointType - Entrypoint type of Add-on. For example: panel, command, etc.
32
32
  * @param addOnName - Name of Add-on.
33
33
  * @returns package.json as {@link PackageJson}.
34
34
  */
35
- // ToDo: [WXP-1625] Update the addOnKind parameter to entrypointType
36
- static getPackageJson(addOnKind, addOnName) {
35
+ static getPackageJson(entrypointType, addOnName) {
37
36
  return new PackageJson({
38
37
  name: addOnName,
39
38
  version: "1.0.0",
40
39
  description: "Adobe Creative Cloud Web Add-on.",
41
- keywords: ["Adobe", "Creative Cloud Web", "Add-on", addOnKind],
40
+ keywords: ["Adobe", "Creative Cloud Web", "Add-on", entrypointType],
42
41
  scripts: {
43
42
  clean: "ccweb-add-on-scripts clean",
44
43
  build: "ccweb-add-on-scripts build",
@@ -47,4 +46,4 @@ export class AddOnManager {
47
46
  });
48
47
  }
49
48
  }
50
- //# sourceMappingURL=AddOnManager.js.map
49
+ //# sourceMappingURL=PackageManager.js.map
@@ -21,11 +21,20 @@
21
21
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
22
  * SOFTWARE.
23
23
  ********************************************************************************/
24
+ import type { AnalyticsService } from "@adobe/ccweb-add-on-analytics";
25
+ import type { Logger } from "@adobe/ccweb-add-on-core";
26
+ import "reflect-metadata";
24
27
  import type { CLIOptions } from "../models/CLIOptions.js";
25
- /**
26
- * Template Selector interface.
27
- */
28
- export interface TemplateSelector {
28
+ export declare class TemplateSelector {
29
+ private readonly _logger;
30
+ private readonly _analyticsService;
31
+ /**
32
+ * Instantiate {@link TemplateSelector}.
33
+ * @param logger - {@link Logger} reference.
34
+ * @param analyticsService - {@link AnalyticsService} reference.
35
+ * @returns Reference to a new {@link TemplateSelector} instance.
36
+ */
37
+ constructor(logger: Logger, analyticsService: AnalyticsService);
29
38
  /**
30
39
  * Sets up a template, as selected/provided by the user
31
40
  * for scaffolding the add-on project.
@@ -33,5 +42,12 @@ export interface TemplateSelector {
33
42
  * @returns User selected/provided template name.
34
43
  */
35
44
  setupTemplate(options: CLIOptions): Promise<string>;
45
+ private _promptMessage;
46
+ private _promptMessageOption;
47
+ /**
48
+ * Validate whether entrypointType is valid or not.
49
+ * @param entrypointType - Add-on entrypoint. For example: panel.
50
+ */
51
+ private _validateAddOnEntrypoint;
36
52
  }
37
53
  //# sourceMappingURL=TemplateSelector.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"TemplateSelector.d.ts","sourceRoot":"","sources":["../../src/app/TemplateSelector.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;kFAsBkF;AAElF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAE1D;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC7B;;;;;OAKG;IACH,aAAa,CAAC,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CACvD"}
1
+ {"version":3,"file":"TemplateSelector.d.ts","sourceRoot":"","sources":["../../src/app/TemplateSelector.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;kFAsBkF;AAElF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AAEtE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAMvD,OAAO,kBAAkB,CAAC;AAI1B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAE1D,qBACa,gBAAgB;IACzB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAmB;IAErD;;;;;OAKG;gBAE4B,MAAM,EAAE,MAAM,EACC,gBAAgB,EAAE,gBAAgB;IAMhF;;;;;OAKG;IACG,aAAa,CAAC,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC;IAoEzD,OAAO,CAAC,cAAc;IAItB,OAAO,CAAC,oBAAoB;IAO5B;;;OAGG;YACW,wBAAwB;CA6BzC"}
@@ -21,5 +21,146 @@
21
21
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
22
  * SOFTWARE.
23
23
  ********************************************************************************/
24
- export {};
24
+ import { __decorate, __metadata, __param } from "tslib";
25
+ import { ITypes as IAnalyticsTypes } from "@adobe/ccweb-add-on-analytics";
26
+ import { ITypes as ICoreTypes, isNullOrWhiteSpace } from "@adobe/ccweb-add-on-core";
27
+ import { EntrypointType } from "@adobe/ccweb-add-on-manifest";
28
+ import chalk from "chalk";
29
+ import { inject, injectable } from "inversify";
30
+ import prompts from "prompts";
31
+ import "reflect-metadata";
32
+ import format from "string-template";
33
+ import { AnalyticsErrorMarkers } from "../AnalyticsMarkers.js";
34
+ import { ADD_ON_TEMPLATES, AVAILABLE_ADD_ON_TEMPLATES, PROGRAM_NAME, WITH_DOCUMENT_SANDBOX } from "../constants.js";
35
+ let TemplateSelector = class TemplateSelector {
36
+ _logger;
37
+ _analyticsService;
38
+ /**
39
+ * Instantiate {@link TemplateSelector}.
40
+ * @param logger - {@link Logger} reference.
41
+ * @param analyticsService - {@link AnalyticsService} reference.
42
+ * @returns Reference to a new {@link TemplateSelector} instance.
43
+ */
44
+ constructor(logger, analyticsService) {
45
+ this._logger = logger;
46
+ this._analyticsService = analyticsService;
47
+ }
48
+ /**
49
+ * Sets up a template, as selected/provided by the user
50
+ * for scaffolding the add-on project.
51
+ * @param options - {@link CLIOptions}.
52
+ * @returns User selected/provided template name.
53
+ */
54
+ async setupTemplate(options) {
55
+ await this._validateAddOnEntrypoint(options.entrypointType);
56
+ if (!isNullOrWhiteSpace(options.templateName)) {
57
+ if (AVAILABLE_ADD_ON_TEMPLATES.includes(options.templateName)) {
58
+ return options.templateName;
59
+ }
60
+ else {
61
+ this._logger.warning(LOGS.chooseValidTemplate, { prefix: LOGS.newLine });
62
+ }
63
+ }
64
+ // Add a line break for better log readability.
65
+ console.log();
66
+ const templateChoices = [];
67
+ for (const [templateName, description] of ADD_ON_TEMPLATES.entries()) {
68
+ templateChoices.push({
69
+ title: this._promptMessageOption(templateName, description),
70
+ value: templateName
71
+ });
72
+ }
73
+ const templateResponse = await prompts.prompt({
74
+ type: "select",
75
+ name: "selectedTemplate",
76
+ message: this._promptMessage(LOGS.setupTemplate),
77
+ choices: templateChoices,
78
+ initial: 0
79
+ });
80
+ if (!templateResponse || !templateResponse.selectedTemplate) {
81
+ console.log();
82
+ return process.exit(0);
83
+ }
84
+ if (!AVAILABLE_ADD_ON_TEMPLATES.includes(`${templateResponse.selectedTemplate}-${WITH_DOCUMENT_SANDBOX}`)) {
85
+ return templateResponse.selectedTemplate;
86
+ }
87
+ const documentSandboxChoices = [
88
+ {
89
+ title: this._promptMessageOption(LOGS.no),
90
+ value: false
91
+ },
92
+ {
93
+ title: this._promptMessageOption(LOGS.yes),
94
+ value: true
95
+ }
96
+ ];
97
+ const documentSandboxResponse = await prompts.prompt({
98
+ type: "select",
99
+ name: "includeDocumentSandbox",
100
+ message: this._promptMessage(LOGS.includeDocumentSandbox),
101
+ choices: documentSandboxChoices,
102
+ initial: 0
103
+ });
104
+ if (!documentSandboxResponse || documentSandboxResponse.includeDocumentSandbox === undefined) {
105
+ console.log();
106
+ return process.exit(0);
107
+ }
108
+ // Append `with-document-sandbox` to the template name if user wants to include document sandbox
109
+ return documentSandboxResponse.includeDocumentSandbox
110
+ ? `${templateResponse.selectedTemplate}-${WITH_DOCUMENT_SANDBOX}`
111
+ : templateResponse.selectedTemplate;
112
+ }
113
+ _promptMessage(message) {
114
+ return chalk.cyan(message);
115
+ }
116
+ _promptMessageOption(option, description) {
117
+ if (description) {
118
+ return `${chalk.hex("#E59400").bold(`[${option}]:`)} ${chalk.green(description)}`;
119
+ }
120
+ return chalk.green.bold(option);
121
+ }
122
+ /**
123
+ * Validate whether entrypointType is valid or not.
124
+ * @param entrypointType - Add-on entrypoint. For example: panel.
125
+ */
126
+ async _validateAddOnEntrypoint(entrypointType) {
127
+ if (entrypointType !== EntrypointType.PANEL) {
128
+ this._logger.warning(LOGS.chooseValidEntrypointType);
129
+ this._logger.warning(format(LOGS.executeProgramWithValidEntrypointType, {
130
+ PROGRAM_NAME
131
+ }), {
132
+ prefix: LOGS.tab
133
+ });
134
+ this._logger.message(LOGS.forExample, { prefix: LOGS.newLine });
135
+ this._logger.information(format(LOGS.executeProgramWithValidEntrypointTypeExample, {
136
+ PROGRAM_NAME
137
+ }), {
138
+ prefix: LOGS.tab
139
+ });
140
+ await this._analyticsService.postEvent(AnalyticsErrorMarkers.ERROR_INVALID_KIND, LOGS.analyticsInvalidEntrypointType, false);
141
+ return process.exit(0);
142
+ }
143
+ }
144
+ };
145
+ TemplateSelector = __decorate([
146
+ injectable(),
147
+ __param(0, inject(ICoreTypes.Logger)),
148
+ __param(1, inject(IAnalyticsTypes.AnalyticsService)),
149
+ __metadata("design:paramtypes", [Object, Function])
150
+ ], TemplateSelector);
151
+ export { TemplateSelector };
152
+ const LOGS = {
153
+ newLine: "\n",
154
+ tab: " ",
155
+ setupTemplate: "Please select a template which you want to scaffold the Add-on project with",
156
+ chooseValidEntrypointType: "Please choose a valid Add-on entrypoint (valid entrypoint: panel)",
157
+ executeProgramWithValidEntrypointType: "{PROGRAM_NAME} <add-on-name> --entrypoint <panel>",
158
+ executeProgramWithValidEntrypointTypeExample: "{PROGRAM_NAME} my-add-on --entrypoint panel",
159
+ chooseValidTemplate: "You have chosen an invalid template.",
160
+ forExample: "For example:",
161
+ analyticsInvalidEntrypointType: "Invalid Add-on entrypoint specified",
162
+ includeDocumentSandbox: "Do you want to include document sandbox runtime?",
163
+ yes: "Yes",
164
+ no: "No"
165
+ };
25
166
  //# sourceMappingURL=TemplateSelector.js.map
@@ -22,8 +22,6 @@
22
22
  * SOFTWARE.
23
23
  ********************************************************************************/
24
24
  export * from "./AddOnFactory.js";
25
- export * from "./AddOnManager.js";
26
- export * from "./AddOnTemplateSelector.js";
25
+ export * from "./PackageManager.js";
27
26
  export * from "./TemplateSelector.js";
28
- export * from "./WxpAddOnFactory.js";
29
27
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/app/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;kFAsBkF;AAElF,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/app/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;kFAsBkF;AAElF,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC"}
package/dist/app/index.js CHANGED
@@ -22,8 +22,6 @@
22
22
  * SOFTWARE.
23
23
  ********************************************************************************/
24
24
  export * from "./AddOnFactory.js";
25
- export * from "./AddOnManager.js";
26
- export * from "./AddOnTemplateSelector.js";
25
+ export * from "./PackageManager.js";
27
26
  export * from "./TemplateSelector.js";
28
- export * from "./WxpAddOnFactory.js";
29
27
  //# sourceMappingURL=index.js.map
@@ -21,32 +21,28 @@
21
21
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
22
  * SOFTWARE.
23
23
  ********************************************************************************/
24
+ import { BaseCommand } from "@adobe/ccweb-add-on-analytics";
24
25
  import type { Config } from "@oclif/core";
25
- import { Command } from "@oclif/core";
26
+ import type { Arg, CustomOptions, OptionFlag } from "@oclif/core/lib/interfaces/parser.js";
26
27
  import "reflect-metadata";
27
28
  /**
28
29
  * Implementation class of the create-ccweb-add-on command.
29
30
  */
30
- export declare class CreateCCWebAddOn extends Command {
31
- private readonly _analyticsConsent;
32
- private readonly _analyticsService;
31
+ export declare class Create extends BaseCommand {
33
32
  private readonly _addOnFactory;
34
33
  static description: string;
35
34
  static examples: string[];
36
35
  static flags: {
37
- kind: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
38
- template: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
39
- analytics: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
40
- verbose: import("@oclif/core/lib/interfaces/parser.js").BooleanFlag<boolean>;
36
+ entrypoint: OptionFlag<string, CustomOptions>;
37
+ template: OptionFlag<string, CustomOptions>;
41
38
  };
42
39
  static args: {
43
- addOnName: import("@oclif/core/lib/interfaces/parser.js").Arg<string, Record<string, unknown>>;
40
+ name: Arg<string, Record<string, unknown>>;
44
41
  };
45
42
  constructor(argv: string[], config: Config);
46
43
  run(): Promise<void>;
47
44
  catch(error: {
48
45
  message: string;
49
46
  }): Promise<void>;
50
- private _seekAnalyticsConsent;
51
47
  }
52
48
  //# sourceMappingURL=create.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../src/commands/create.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;kFAsBkF;AAMlF,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAQ,OAAO,EAAS,MAAM,aAAa,CAAC;AACnD,OAAO,kBAAkB,CAAC;AAO1B;;GAEG;AACH,qBAAa,gBAAiB,SAAQ,OAAO;IACzC,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAmB;IACrD,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAmB;IAErD,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAe;IAE7C,MAAM,CAAC,WAAW,SAAgD;IAElE,MAAM,CAAC,QAAQ,WAAiE;IAEhF,MAAM,CAAC,KAAK;;;;;MA0BV;IAEF,MAAM,CAAC,IAAI;;MAMT;gBAEU,IAAI,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,MAAM;IAYpC,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;IAsBpB,KAAK,CAAC,KAAK,EAAE;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE;YAKxB,qBAAqB;CAOtC"}
1
+ {"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../src/commands/create.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;kFAsBkF;AAElF,OAAO,EAAE,WAAW,EAAc,MAAM,+BAA+B,CAAC;AAGxE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAE1C,OAAO,KAAK,EAAE,GAAG,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,sCAAsC,CAAC;AAC3F,OAAO,kBAAkB,CAAC;AAO1B;;GAEG;AACH,qBAAa,MAAO,SAAQ,WAAW;IACnC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAe;IAE7C,MAAM,CAAC,WAAW,SAAgD;IAElE,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,CAAiE;IAE1F,MAAM,CAAC,KAAK,EAAE;QACV,UAAU,EAAE,UAAU,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;QAC9C,QAAQ,EAAE,UAAU,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;KAC/C,CAcC;IAEF,MAAM,CAAC,IAAI,EAAE;QACT,IAAI,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;KAC9C,CAMC;gBAEU,IAAI,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,MAAM;IAMpC,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;IAsBpB,KAAK,CAAC,KAAK,EAAE;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;CAIzD"}