@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,159 +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 { 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 { AddOnManager } from "./AddOnManager.js";
40
- /**
41
- * AddOn factory implementation class.
42
- */
43
- let WxpAddOnFactory = class WxpAddOnFactory {
44
- _directoryValidator;
45
- _environmentValidator;
46
- _templateSelector;
47
- _scaffolder;
48
- _process;
49
- _logger;
50
- _analyticsService;
51
- /**
52
- * Instantiate {@link WxpAddOnFactory}.
53
- * @param directoryValidator - {@link DirectoryValidator} reference.
54
- * @param environmentValidator - {@link EnvironmentValidator} reference.
55
- * @param templateSelector - {@link TemplateSelector} reference.
56
- * @param scaffolder - {@link AddOnScaffolder} reference.
57
- * @param cliProcess - {@link Process} reference.
58
- * @param logger - {@link Logger} reference.
59
- * @param analyticsService - {@link AnalyticsService} reference.
60
- * @returns Reference to a new {@link WxpAddOnFactory} instance.
61
- */
62
- constructor(directoryValidator, environmentValidator, templateSelector, scaffolder, cliProcess, logger, analyticsService) {
63
- this._directoryValidator = directoryValidator;
64
- this._environmentValidator = environmentValidator;
65
- this._templateSelector = templateSelector;
66
- this._scaffolder = scaffolder;
67
- this._process = cliProcess;
68
- this._logger = logger;
69
- this._analyticsService = analyticsService;
70
- }
71
- /**
72
- * Create the Add-on project.
73
- * @param options - {@link CLIOptions}.
74
- */
75
- async create(options) {
76
- let addOnDirectory = "";
77
- try {
78
- await this._environmentValidator.validateNodeVersion();
79
- await this._environmentValidator.validateNpmVersion();
80
- await this._environmentValidator.validateNpmConfiguration();
81
- await this._directoryValidator.validateAddOnName(options.addOnName);
82
- addOnDirectory = path.resolve(options.addOnName);
83
- await this._directoryValidator.validateAddOnDirectory(addOnDirectory, options.addOnName);
84
- this._logger.information(LOGS.creatingWxpAddOn);
85
- this._logger.message(LOGS.mayTakeAMinute);
86
- const templateName = await this._templateSelector.setupTemplate(options);
87
- const packageJson = AddOnManager.getPackageJson(options.addOnKind, options.addOnName);
88
- const packageJsonPath = path.join(addOnDirectory, PACKAGE_JSON);
89
- fs.writeFileSync(packageJsonPath, packageJson.toJSON() + os.EOL);
90
- this._copyTemplateFiles(addOnDirectory, templateName);
91
- const rootDirectory = process.cwd();
92
- process.chdir(addOnDirectory);
93
- const devDependencyArgs = [
94
- "install",
95
- "--save-dev",
96
- "@adobe/ccweb-add-on-scripts",
97
- "@types/adobe__ccweb-add-on-sdk"
98
- ];
99
- if (options.verbose) {
100
- devDependencyArgs.push("--verbose");
101
- }
102
- this._logger.information(LOGS.installingDevDependencies, { prefix: LOGS.newLine });
103
- await this._process.execute("npm", devDependencyArgs, { stdio: "inherit" });
104
- const scaffolderOptions = new ScaffolderOptions(addOnDirectory, options.addOnName, options.addOnKind, rootDirectory, templateName, options.verbose);
105
- this._logger.information(format(LOGS.scaffoldingProjectFromTemplate, { templateName }), {
106
- prefix: LOGS.newLine
107
- });
108
- await this._scaffolder.run(scaffolderOptions);
109
- const analyticsEventData = [
110
- "--addOnName",
111
- options.addOnName,
112
- "--kind",
113
- options.addOnKind,
114
- "--template",
115
- templateName
116
- ];
117
- await this._analyticsService.postEvent(AnalyticsSuccessMarkers.SUCCESS, analyticsEventData.join(" "), true);
118
- }
119
- catch (error) {
120
- this._process.handleError(error);
121
- this._process.removeAddOn(addOnDirectory, options.addOnName);
122
- await this._analyticsService.postEvent(AnalyticsErrorMarkers.ERROR_UNKNOWN_REASON, error.message, false);
123
- return process.exit(0);
124
- }
125
- }
126
- _copyTemplateFiles(addOnDirectory, templateName) {
127
- const targetPath = path.join(addOnDirectory, TEMP_TEMPLATE_PATH);
128
- fs.ensureDirSync(targetPath);
129
- const templateDirectory = path.join(url.fileURLToPath(import.meta.url), "..", "..", "templates", templateName);
130
- if (fs.existsSync(templateDirectory)) {
131
- fs.copySync(templateDirectory, targetPath);
132
- }
133
- else {
134
- this._logger.error(LOGS.templateNotFound);
135
- process.exit(1);
136
- }
137
- }
138
- };
139
- WxpAddOnFactory = __decorate([
140
- injectable(),
141
- __param(0, inject(ITypes.DirectoryValidator)),
142
- __param(1, inject(ITypes.EnvironmentValidator)),
143
- __param(2, inject(ITypes.TemplateSelector)),
144
- __param(3, inject(IScaffolderTypes.AddOnScaffolder)),
145
- __param(4, inject(ICoreTypes.Process)),
146
- __param(5, inject(ICoreTypes.Logger)),
147
- __param(6, inject(IAnalyticsTypes.AnalyticsService)),
148
- __metadata("design:paramtypes", [Object, Object, Object, Object, Object, Object, Object])
149
- ], WxpAddOnFactory);
150
- export { WxpAddOnFactory };
151
- const LOGS = {
152
- newLine: "\n",
153
- creatingWxpAddOn: "Creating a new Add-on ...",
154
- mayTakeAMinute: "This may take a minute ...",
155
- installingDevDependencies: "Installing dev dependencies ...",
156
- scaffoldingProjectFromTemplate: "Scaffolding project from template: {templateName} ...",
157
- templateNotFound: "Could not find the artifacts for the selected template."
158
- };
159
- //# sourceMappingURL=WxpAddOnFactory.js.map
@@ -1,55 +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 } from "@adobe/ccweb-add-on-core";
26
- import "reflect-metadata";
27
- import type { DirectoryValidator } from "./DirectoryValidator.js";
28
- /**
29
- * Directory validator implementation class to validate
30
- * whether the directory can be used to create the add-on project.
31
- */
32
- export declare class AddOnDirectoryValidator implements DirectoryValidator {
33
- private readonly _logger;
34
- private readonly _analyticsService;
35
- /**
36
- * Instantiate {@link AddOnDirectoryValidator}.
37
- * @param logger - {@link Logger} reference.
38
- * @param analyticsService - {@link AnalyticsService} reference.
39
- * @returns Reference to a new {@link AddOnDirectoryValidator} instance.
40
- */
41
- constructor(logger: Logger, analyticsService: AnalyticsService);
42
- /**
43
- * Validate the Add-on name.
44
- * @param addOnName - Name of the Add-on.
45
- */
46
- validateAddOnName(addOnName: string): Promise<void>;
47
- /**
48
- * Validate the addOn directory.
49
- * @param addOnDirectory - Root directory of the addOn.
50
- * @param addOnName - Name of the addOn.
51
- */
52
- validateAddOnDirectory(addOnDirectory: string, addOnName: string): Promise<void>;
53
- private _chooseDifferentAddOnName;
54
- }
55
- //# sourceMappingURL=AddOnDirectoryValidator.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"AddOnDirectoryValidator.d.ts","sourceRoot":"","sources":["../../src/validators/AddOnDirectoryValidator.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;AAM1B,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAElE;;;GAGG;AACH,qBACa,uBAAwB,YAAW,kBAAkB;IAC9D,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAmB;IAErD;;;;;OAKG;gBAE4B,MAAM,EAAE,MAAM,EACC,gBAAgB,EAAE,gBAAgB;IAMhF;;;OAGG;IACG,iBAAiB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IA4CzD;;;;OAIG;IACG,sBAAsB,CAAC,cAAc,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IA+DtF,OAAO,CAAC,yBAAyB;CAQpC"}
@@ -1,176 +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, isNullOrWhiteSpace } from "@adobe/ccweb-add-on-core";
27
- import fs from "fs-extra";
28
- import { inject, injectable } from "inversify";
29
- import path from "path";
30
- import process from "process";
31
- import "reflect-metadata";
32
- import format from "string-template";
33
- import validate from "validate-npm-package-name";
34
- import { AnalyticsErrorMarkers } from "../AnalyticsMarkers.js";
35
- import { PROGRAM_NAME } from "../constants.js";
36
- /**
37
- * Directory validator implementation class to validate
38
- * whether the directory can be used to create the add-on project.
39
- */
40
- let AddOnDirectoryValidator = class AddOnDirectoryValidator {
41
- _logger;
42
- _analyticsService;
43
- /**
44
- * Instantiate {@link AddOnDirectoryValidator}.
45
- * @param logger - {@link Logger} reference.
46
- * @param analyticsService - {@link AnalyticsService} reference.
47
- * @returns Reference to a new {@link AddOnDirectoryValidator} instance.
48
- */
49
- constructor(logger, analyticsService) {
50
- this._logger = logger;
51
- this._analyticsService = analyticsService;
52
- }
53
- /**
54
- * Validate the Add-on name.
55
- * @param addOnName - Name of the Add-on.
56
- */
57
- async validateAddOnName(addOnName) {
58
- if (isNullOrWhiteSpace(addOnName)) {
59
- this._logger.warning(LOGS.specifyAddOnName);
60
- this._chooseDifferentAddOnName();
61
- await this._analyticsService.postEvent(AnalyticsErrorMarkers.ERROR_NO_ADD_ON_NAME, LOGS.analyticsNoAddOnName, false);
62
- return process.exit(0);
63
- }
64
- const isValid = validate(addOnName).validForNewPackages;
65
- if (!isValid) {
66
- this._logger.warning(format(LOGS.npmNamingRestriction, { addOnName }));
67
- this._chooseDifferentAddOnName();
68
- await this._analyticsService.postEvent(AnalyticsErrorMarkers.ERROR_INVALID_NAME_NPM, LOGS.analyticsInvalidAddOnNameNPM, false);
69
- return process.exit(0);
70
- }
71
- const dependencies = new Set([
72
- "@adobe/create-ccweb-add-on",
73
- "create-ccweb-add-on",
74
- "@adobe/ccweb-add-on-scripts",
75
- "ccweb-add-on-scripts",
76
- "@adobe/ccweb-add-on-scaffolder",
77
- "ccweb-add-on-scaffolder"
78
- ]);
79
- if (dependencies.has(addOnName)) {
80
- this._logger.warning(format(LOGS.dependencyNamingRestriction, { addOnName }));
81
- this._chooseDifferentAddOnName();
82
- await this._analyticsService.postEvent(AnalyticsErrorMarkers.ERROR_INVALID_NAME_DEP, LOGS.analyticsInvalidAddOnNameDependency, false);
83
- return process.exit(0);
84
- }
85
- }
86
- /**
87
- * Validate the addOn directory.
88
- * @param addOnDirectory - Root directory of the addOn.
89
- * @param addOnName - Name of the addOn.
90
- */
91
- async validateAddOnDirectory(addOnDirectory, addOnName) {
92
- fs.ensureDirSync(addOnName);
93
- const validFiles = [
94
- ".DS_Store",
95
- ".git",
96
- ".gitattributes",
97
- ".gitignore",
98
- ".gitlab-ci.yml",
99
- ".hg",
100
- ".hgcheck",
101
- ".hgignore",
102
- ".idea",
103
- ".npmignore",
104
- ".travis.yml",
105
- "docs",
106
- "LICENSE",
107
- "README.md",
108
- "mkdocs.yml",
109
- "Thumbs.db"
110
- ];
111
- const errorLogFilePatterns = ["npm-debug.log"];
112
- const isErrorLog = (file) => {
113
- return errorLogFilePatterns.some(pattern => file.startsWith(pattern));
114
- };
115
- const existingFiles = fs.readdirSync(addOnDirectory, { withFileTypes: true });
116
- const conflictingFiles = existingFiles
117
- .filter(file => !validFiles.includes(file.name))
118
- .filter(file => !/\.iml$/.test(file.name))
119
- .filter(file => !isErrorLog(file.name));
120
- if (conflictingFiles.length === 0) {
121
- return;
122
- }
123
- this._logger.warning(format(LOGS.directoryContainsFiles, { addOnName }), {
124
- postfix: LOGS.newLine
125
- });
126
- for (const file of conflictingFiles) {
127
- try {
128
- if (fs.lstatSync(path.join(addOnDirectory, file.name)).isDirectory()) {
129
- this._logger.warning(`${file.name}/`, { prefix: LOGS.tab });
130
- }
131
- else {
132
- this._logger.warning(`${file.name}`, { prefix: LOGS.tab });
133
- }
134
- }
135
- catch {
136
- this._logger.warning(`${file.name}`, { prefix: LOGS.tab });
137
- }
138
- }
139
- this._logger.information(LOGS.newAddOnOrRemoveFiles, { prefix: LOGS.newLine });
140
- await this._analyticsService.postEvent(AnalyticsErrorMarkers.ERROR_INVALID_NAME_DIR, LOGS.analyticsInvalidAddOnDir, false);
141
- return process.exit(0);
142
- }
143
- _chooseDifferentAddOnName() {
144
- this._logger.warning(format(LOGS.executeProgram, { PROGRAM_NAME }), { prefix: LOGS.tab });
145
- this._logger.message(LOGS.forExample, { prefix: LOGS.newLine });
146
- this._logger.information(format(LOGS.executeProgramExample, { PROGRAM_NAME }), {
147
- prefix: LOGS.tab,
148
- postfix: LOGS.newLine
149
- });
150
- }
151
- };
152
- AddOnDirectoryValidator = __decorate([
153
- injectable(),
154
- __param(0, inject(ICoreTypes.Logger)),
155
- __param(1, inject(IAnalyticsTypes.AnalyticsService)),
156
- __metadata("design:paramtypes", [Object, Object])
157
- ], AddOnDirectoryValidator);
158
- export { AddOnDirectoryValidator };
159
- const LOGS = {
160
- newLine: "\n",
161
- tab: " ",
162
- specifyAddOnName: "Please specify an Add-on name",
163
- executeProgram: "{PROGRAM_NAME} <add-on-name> --kind <panel> --template <javascript>",
164
- executeProgramExample: "{PROGRAM_NAME} my-add-on --kind panel --template javascript",
165
- forExample: "For example:",
166
- npmNamingRestriction: "Cannot create a project named {addOnName} because of NPM naming restrictions.",
167
- dependencyNamingRestriction: "Cannot create a project named {addOnName} because a dependency with the same name exists.",
168
- chooseDifferentAddOnName: "Please choose a different Add-on name:",
169
- directoryContainsFiles: "The directory {addOnName} contains files that could conflict:",
170
- newAddOnOrRemoveFiles: "Either try using a new Add-on name, or remove the files listed above.",
171
- analyticsNoAddOnName: "Add-on name was not specified",
172
- analyticsInvalidAddOnNameNPM: "Invalid Add-on name. Npm name check failed",
173
- analyticsInvalidAddOnNameDependency: "Invalid Add-on name. Dependency with same name exists",
174
- analyticsInvalidAddOnDir: "Invalid Add-on name. Conflicting directory with same name exists"
175
- };
176
- //# sourceMappingURL=AddOnDirectoryValidator.js.map
@@ -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 = "16.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 = "8.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