@adobe/ccweb-add-on-scaffolder 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 (66) hide show
  1. package/.c8rc.json +5 -1
  2. package/.mocharc.json +9 -2
  3. package/dist/app/AddOnBuilder.d.ts +27 -7
  4. package/dist/app/AddOnBuilder.d.ts.map +1 -1
  5. package/dist/app/AddOnBuilder.js +247 -0
  6. package/dist/app/AddOnScaffolder.d.ts +29 -2
  7. package/dist/app/AddOnScaffolder.d.ts.map +1 -1
  8. package/dist/app/AddOnScaffolder.js +106 -1
  9. package/dist/app/PackageBuilder.d.ts +21 -7
  10. package/dist/app/PackageBuilder.d.ts.map +1 -1
  11. package/dist/app/PackageBuilder.js +68 -1
  12. package/dist/app/index.d.ts +0 -3
  13. package/dist/app/index.d.ts.map +1 -1
  14. package/dist/app/index.js +0 -3
  15. package/dist/config/inversify.config.d.ts +2 -1
  16. package/dist/config/inversify.config.d.ts.map +1 -1
  17. package/dist/config/inversify.config.js +8 -6
  18. package/dist/config/inversify.types.d.ts +0 -1
  19. package/dist/config/inversify.types.d.ts.map +1 -1
  20. package/dist/config/inversify.types.js +0 -1
  21. package/dist/index.d.ts +1 -1
  22. package/dist/index.d.ts.map +1 -1
  23. package/dist/index.js +0 -1
  24. package/dist/models/ScaffolderOptions.d.ts +3 -3
  25. package/dist/models/ScaffolderOptions.d.ts.map +1 -1
  26. package/dist/models/ScaffolderOptions.js +4 -4
  27. package/dist/tsconfig.tsbuildinfo +1 -1
  28. package/dist/validators/TemplateValidator.d.ts +12 -2
  29. package/dist/validators/TemplateValidator.d.ts.map +1 -1
  30. package/dist/validators/TemplateValidator.js +54 -1
  31. package/dist/validators/index.d.ts +0 -1
  32. package/dist/validators/index.d.ts.map +1 -1
  33. package/dist/validators/index.js +0 -1
  34. package/package.json +11 -11
  35. package/src/app/AddOnBuilder.ts +258 -15
  36. package/src/app/AddOnScaffolder.ts +120 -3
  37. package/src/app/PackageBuilder.ts +75 -9
  38. package/src/app/index.ts +0 -3
  39. package/src/config/inversify.config.ts +10 -10
  40. package/src/config/inversify.types.ts +6 -2
  41. package/src/index.ts +1 -1
  42. package/src/models/ScaffolderOptions.ts +4 -4
  43. package/src/test/app/{TemplateAddOnBuilder.spec.ts → AddOnBuilder.spec.ts} +21 -22
  44. package/src/test/app/{TemplateAddOnScaffolder.spec.ts → AddOnScaffolder.spec.ts} +20 -22
  45. package/src/test/app/{TemplatePackageBuilder.spec.ts → PackageBuilder.spec.ts} +13 -14
  46. package/src/test/models/ScaffolderOptions.spec.ts +5 -5
  47. package/src/test/validators/{AppTemplateValidator.spec.ts → TemplateValidator.spec.ts} +2 -3
  48. package/src/validators/TemplateValidator.ts +46 -3
  49. package/src/validators/index.ts +0 -1
  50. package/tsconfig.json +4 -1
  51. package/dist/app/TemplateAddOnBuilder.d.ts +0 -90
  52. package/dist/app/TemplateAddOnBuilder.d.ts.map +0 -1
  53. package/dist/app/TemplateAddOnBuilder.js +0 -273
  54. package/dist/app/TemplateAddOnScaffolder.d.ts +0 -63
  55. package/dist/app/TemplateAddOnScaffolder.d.ts.map +0 -1
  56. package/dist/app/TemplateAddOnScaffolder.js +0 -130
  57. package/dist/app/TemplatePackageBuilder.d.ts +0 -49
  58. package/dist/app/TemplatePackageBuilder.d.ts.map +0 -1
  59. package/dist/app/TemplatePackageBuilder.js +0 -92
  60. package/dist/validators/AddOnTemplateValidator.d.ts +0 -46
  61. package/dist/validators/AddOnTemplateValidator.d.ts.map +0 -1
  62. package/dist/validators/AddOnTemplateValidator.js +0 -78
  63. package/src/app/TemplateAddOnBuilder.ts +0 -319
  64. package/src/app/TemplateAddOnScaffolder.ts +0 -153
  65. package/src/app/TemplatePackageBuilder.ts +0 -102
  66. package/src/validators/AddOnTemplateValidator.ts +0 -79
@@ -1,153 +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 { Logger, Process } from "@adobe/ccweb-add-on-core";
26
- import { DEFAULT_HOST_NAME, ITypes as ICoreTypes } from "@adobe/ccweb-add-on-core";
27
- import type { CommandExecutor as SSLCommandExecutor } from "@adobe/ccweb-add-on-ssl";
28
- import { ITypes as ISSLTypes, SetupCommandOptions } from "@adobe/ccweb-add-on-ssl";
29
- import { inject, injectable, named } from "inversify";
30
- import "reflect-metadata";
31
- import { ITypes } from "../config/inversify.types.js";
32
- import type { ScaffolderOptions } from "../models/ScaffolderOptions.js";
33
- import type { TemplateValidator } from "../validators/index.js";
34
- import type { AddOnBuilderFactory } from "./AddOnBuilder.js";
35
- import type { AddOnScaffolder } from "./AddOnScaffolder.js";
36
- import type { PackageBuilderFactory } from "./PackageBuilder.js";
37
-
38
- /**
39
- * Add-on scaffolder implementation class for orchestrating the creation of the Add-on project.
40
- */
41
- @injectable()
42
- export class TemplateAddOnScaffolder implements AddOnScaffolder {
43
- private readonly _addOnBuilderFactory: AddOnBuilderFactory;
44
- private readonly _packageBuilderFactory: PackageBuilderFactory;
45
- private readonly _templateValidator: TemplateValidator;
46
-
47
- private readonly _sslCommandExecutor: SSLCommandExecutor;
48
-
49
- private readonly _process: Process;
50
- private readonly _logger: Logger;
51
-
52
- /**
53
- * Instantiate {@link TemplateAppScaffolder}.
54
- * @param addOnBuilderFactory - {@link AddOnBuilderFactory} reference.
55
- * @param packageBuilderFactory - {@link PackageBuilderFactory} reference.
56
- * @param templateValidator - {@link TemplateValidator} reference.
57
- * @param sslCommandExecutor - {@link SSLCommandExecutor} reference.
58
- * @param cliProcess - {@link Process} reference.
59
- * @param logger - {@link Logger} reference.
60
- * @returns Reference to a new {@link TemplateAppScaffolder} instance.
61
- */
62
- constructor(
63
- @inject(ITypes.AddOnBuilder) addOnBuilderFactory: AddOnBuilderFactory,
64
- @inject(ITypes.PackageBuilder) packageBuilderFactory: PackageBuilderFactory,
65
- @inject(ITypes.TemplateValidator) templateValidator: TemplateValidator,
66
- @inject(ISSLTypes.CommandExecutor) @named("setup") sslCommandExecutor: SSLCommandExecutor,
67
- @inject(ICoreTypes.Process) cliProcess: Process,
68
- @inject(ICoreTypes.Logger) logger: Logger
69
- ) {
70
- this._addOnBuilderFactory = addOnBuilderFactory;
71
- this._packageBuilderFactory = packageBuilderFactory;
72
- this._templateValidator = templateValidator;
73
-
74
- this._sslCommandExecutor = sslCommandExecutor;
75
-
76
- this._process = cliProcess;
77
- this._logger = logger;
78
- }
79
-
80
- /**
81
- * Run the scaffolder to create the Add-on project from the provided options.
82
- * @param options - {@link ScaffolderOptions} reference.
83
- * @returns Promise.
84
- */
85
- async run(options: ScaffolderOptions): Promise<void> {
86
- try {
87
- this._templateValidator.validateTemplate(options.templateName);
88
-
89
- const addOnBuilder = this._addOnBuilderFactory(options);
90
- const packageJson = addOnBuilder.getPackageJson();
91
- const templateJson = addOnBuilder.getTemplateJson();
92
-
93
- const packageBuilder = this._packageBuilderFactory(packageJson)(templateJson);
94
- const combinedPackage = packageBuilder.build();
95
-
96
- addOnBuilder.build(combinedPackage.toJSON());
97
-
98
- const templateDevDependencies = addOnBuilder.getDevDependenciesToInstall(templateJson);
99
- await this._installDevDependencies(templateDevDependencies, options.verbose);
100
-
101
- const templateDependencies = addOnBuilder.getDependenciesToInstall(templateJson);
102
- await this._installDependencies(templateDependencies, options.verbose);
103
-
104
- await this._setupSSL(options.verbose);
105
-
106
- addOnBuilder.displaySuccess();
107
- } catch (error) {
108
- this._process.handleError(error);
109
- process.exit(1);
110
- }
111
- }
112
-
113
- private async _installDevDependencies(templateDevDependencies: Set<string>, verbose: boolean) {
114
- if (templateDevDependencies.size > 0) {
115
- const devDependencyArgs = ["install", "--save-dev", "--save-exact", ...templateDevDependencies];
116
- if (verbose) {
117
- devDependencyArgs.push("--verbose");
118
- }
119
-
120
- this._logger.information(LOGS.installingTemplateDevDependencies, {
121
- prefix: LOGS.newLine
122
- });
123
-
124
- await this._process.execute("npm", devDependencyArgs, { stdio: "inherit" });
125
- }
126
- }
127
-
128
- private async _installDependencies(templateDependencies: Set<string>, verbose: boolean) {
129
- if (templateDependencies.size > 0) {
130
- const dependencyArgs = ["install", "--save", "--save-exact", ...templateDependencies];
131
- if (verbose) {
132
- dependencyArgs.push("--verbose");
133
- }
134
-
135
- this._logger.information(LOGS.installingTemplateDependencies, {
136
- prefix: LOGS.newLine
137
- });
138
-
139
- await this._process.execute("npm", dependencyArgs, { stdio: "inherit" });
140
- }
141
- }
142
-
143
- private async _setupSSL(verbose: boolean): Promise<void> {
144
- const setupCommandOptions = new SetupCommandOptions(DEFAULT_HOST_NAME, true, verbose);
145
- await this._sslCommandExecutor.execute(setupCommandOptions);
146
- }
147
- }
148
-
149
- const LOGS = {
150
- newLine: "\n",
151
- installingTemplateDevDependencies: "Installing template dev dependencies ...",
152
- installingTemplateDependencies: "Installing template dependencies ..."
153
- };
@@ -1,102 +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 { TemplateJson } from "@adobe/ccweb-add-on-core";
26
- import { PackageJson } from "@adobe/ccweb-add-on-core";
27
- import { injectable } from "inversify";
28
- import type { PackageBuilder } from "./PackageBuilder.js";
29
-
30
- /**
31
- * Package builder implementation class for constructing the package.json of the Add-on project.
32
- */
33
- @injectable()
34
- export class TemplatePackageBuilder implements PackageBuilder {
35
- private _combinedPackage: PackageJson;
36
- private _templateJson: TemplateJson;
37
-
38
- /**
39
- * Instantiate {@link TemplatePackageBuilder}.
40
- *
41
- * @param packageJson - {@link PackageJson}.
42
- * @param templateJson - {@link TemplateJson}.
43
- * @returns Reference to a new {@link TemplatePackageBuilder} instance.
44
- */
45
- constructor(packageJson: PackageJson, templateJson: TemplateJson) {
46
- this._combinedPackage = new PackageJson({ ...packageJson });
47
- this._templateJson = templateJson;
48
- }
49
-
50
- /**
51
- * Build {@link PackageJson}.
52
- */
53
- build(): PackageJson {
54
- this._buildDevDependencies();
55
- this._buildDependencies();
56
- this._buildScripts();
57
-
58
- return this._combinedPackage;
59
- }
60
-
61
- private _buildDevDependencies(): void {
62
- if (!this._templateJson.devDependencies || this._templateJson.devDependencies.size === 0) {
63
- return;
64
- }
65
-
66
- this._templateJson.devDependencies.forEach((value, key) => {
67
- if (!this._combinedPackage.devDependencies) {
68
- this._combinedPackage.devDependencies = new Map<string, string>();
69
- }
70
-
71
- this._combinedPackage.devDependencies.set(key, value);
72
- });
73
- }
74
-
75
- private _buildDependencies(): void {
76
- if (!this._templateJson.dependencies || this._templateJson.dependencies.size === 0) {
77
- return;
78
- }
79
-
80
- this._templateJson.dependencies.forEach((value, key) => {
81
- if (!this._combinedPackage.dependencies) {
82
- this._combinedPackage.dependencies = new Map<string, string>();
83
- }
84
-
85
- this._combinedPackage.dependencies.set(key, value);
86
- });
87
- }
88
-
89
- private _buildScripts(): void {
90
- if (!this._templateJson.scripts || this._templateJson.scripts.size === 0) {
91
- return;
92
- }
93
-
94
- this._templateJson.scripts.forEach((value, key) => {
95
- if (!this._combinedPackage.scripts) {
96
- this._combinedPackage.scripts = new Map<string, string>();
97
- }
98
-
99
- this._combinedPackage.scripts.set(key, value);
100
- });
101
- }
102
- }
@@ -1,79 +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 { Logger } from "@adobe/ccweb-add-on-core";
26
- import { ITypes as ICoreTypes, isNullOrWhiteSpace } from "@adobe/ccweb-add-on-core";
27
- import { inject, injectable } from "inversify";
28
- import process from "process";
29
- import "reflect-metadata";
30
- import format from "string-template";
31
- import { PROGRAM_NAME } from "../constants.js";
32
- import type { TemplateValidator } from "./TemplateValidator.js";
33
-
34
- /**
35
- * Template validator implementation class to validate user selected template..
36
- */
37
- @injectable()
38
- export class AddOnTemplateValidator implements TemplateValidator {
39
- private readonly _logger: Logger;
40
-
41
- /**
42
- * Instantiate {@link AppTemplateValidator}.
43
- *
44
- * @param logger - {@link Logger} reference.
45
- * @returns Reference to a new {@link AppTemplateValidator} instance.
46
- */
47
- constructor(@inject(ICoreTypes.Logger) logger: Logger) {
48
- this._logger = logger;
49
- }
50
-
51
- /**
52
- * Validate the template.
53
- *
54
- * @param templateName - Name of the template.
55
- */
56
- validateTemplate(templateName: string) {
57
- if (isNullOrWhiteSpace(templateName)) {
58
- this._logger.warning(LOGS.specifyValidTemplateName);
59
- this._logger.warning(format(LOGS.executeProgram, { PROGRAM_NAME }), {
60
- prefix: LOGS.tab
61
- });
62
- this._logger.message(LOGS.forExample, { prefix: LOGS.newLine });
63
- this._logger.information(format(LOGS.executeProgramExample, { PROGRAM_NAME }), {
64
- prefix: LOGS.tab
65
- });
66
-
67
- process.exit(1);
68
- }
69
- }
70
- }
71
-
72
- const LOGS = {
73
- newLine: "\n",
74
- tab: " ",
75
- specifyValidTemplateName: "Please specify a valid template name:",
76
- executeProgram: "{PROGRAM_NAME} --template <template-name>",
77
- executeProgramExample: "{PROGRAM_NAME} --template javascript",
78
- forExample: "For example:"
79
- };