@adobe/ccweb-add-on-scaffolder 0.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 (93) hide show
  1. package/.c8rc.json +7 -0
  2. package/.mocharc.json +5 -0
  3. package/CODE_OF_CONDUCT.md +79 -0
  4. package/CONTRIBUTING.md +47 -0
  5. package/LICENSE +21 -0
  6. package/README.md +11 -0
  7. package/dist/app/AddOnBuilder.d.ts +72 -0
  8. package/dist/app/AddOnBuilder.d.ts.map +1 -0
  9. package/dist/app/AddOnBuilder.js +25 -0
  10. package/dist/app/AddOnScaffolder.d.ts +36 -0
  11. package/dist/app/AddOnScaffolder.d.ts.map +1 -0
  12. package/dist/app/AddOnScaffolder.js +25 -0
  13. package/dist/app/PackageBuilder.d.ts +38 -0
  14. package/dist/app/PackageBuilder.d.ts.map +1 -0
  15. package/dist/app/PackageBuilder.js +25 -0
  16. package/dist/app/TemplateAddOnBuilder.d.ts +90 -0
  17. package/dist/app/TemplateAddOnBuilder.d.ts.map +1 -0
  18. package/dist/app/TemplateAddOnBuilder.js +273 -0
  19. package/dist/app/TemplateAddOnScaffolder.d.ts +63 -0
  20. package/dist/app/TemplateAddOnScaffolder.d.ts.map +1 -0
  21. package/dist/app/TemplateAddOnScaffolder.js +130 -0
  22. package/dist/app/TemplatePackageBuilder.d.ts +49 -0
  23. package/dist/app/TemplatePackageBuilder.d.ts.map +1 -0
  24. package/dist/app/TemplatePackageBuilder.js +92 -0
  25. package/dist/app/index.d.ts +30 -0
  26. package/dist/app/index.d.ts.map +1 -0
  27. package/dist/app/index.js +30 -0
  28. package/dist/config/index.d.ts +26 -0
  29. package/dist/config/index.d.ts.map +1 -0
  30. package/dist/config/index.js +26 -0
  31. package/dist/config/inversify.config.d.ts +27 -0
  32. package/dist/config/inversify.config.d.ts.map +1 -0
  33. package/dist/config/inversify.config.js +47 -0
  34. package/dist/config/inversify.types.d.ts +31 -0
  35. package/dist/config/inversify.types.d.ts.map +1 -0
  36. package/dist/config/inversify.types.js +31 -0
  37. package/dist/constants.d.ts +33 -0
  38. package/dist/constants.d.ts.map +1 -0
  39. package/dist/constants.js +34 -0
  40. package/dist/index.d.ts +28 -0
  41. package/dist/index.d.ts.map +1 -0
  42. package/dist/index.js +28 -0
  43. package/dist/models/ScaffolderOptions.d.ts +65 -0
  44. package/dist/models/ScaffolderOptions.d.ts.map +1 -0
  45. package/dist/models/ScaffolderOptions.js +71 -0
  46. package/dist/models/index.d.ts +25 -0
  47. package/dist/models/index.d.ts.map +1 -0
  48. package/dist/models/index.js +25 -0
  49. package/dist/tsconfig.tsbuildinfo +1 -0
  50. package/dist/validators/AddOnTemplateValidator.d.ts +46 -0
  51. package/dist/validators/AddOnTemplateValidator.d.ts.map +1 -0
  52. package/dist/validators/AddOnTemplateValidator.js +78 -0
  53. package/dist/validators/TemplateValidator.d.ts +35 -0
  54. package/dist/validators/TemplateValidator.d.ts.map +1 -0
  55. package/dist/validators/TemplateValidator.js +25 -0
  56. package/dist/validators/index.d.ts +26 -0
  57. package/dist/validators/index.d.ts.map +1 -0
  58. package/dist/validators/index.js +26 -0
  59. package/package.json +57 -0
  60. package/src/app/AddOnBuilder.ts +79 -0
  61. package/src/app/AddOnScaffolder.ts +37 -0
  62. package/src/app/PackageBuilder.ts +40 -0
  63. package/src/app/TemplateAddOnBuilder.ts +319 -0
  64. package/src/app/TemplateAddOnScaffolder.ts +153 -0
  65. package/src/app/TemplatePackageBuilder.ts +102 -0
  66. package/src/app/index.ts +30 -0
  67. package/src/config/index.ts +26 -0
  68. package/src/config/inversify.config.ts +58 -0
  69. package/src/config/inversify.types.ts +31 -0
  70. package/src/constants.ts +36 -0
  71. package/src/index.ts +28 -0
  72. package/src/models/ScaffolderOptions.ts +86 -0
  73. package/src/models/index.ts +25 -0
  74. package/src/test/app/TemplateAddOnBuilder.spec.ts +1391 -0
  75. package/src/test/app/TemplateAddOnScaffolder.spec.ts +272 -0
  76. package/src/test/app/TemplatePackageBuilder.spec.ts +332 -0
  77. package/src/test/app/data/first-test-app/.template/template.json +10 -0
  78. package/src/test/app/data/first-test-app/package.json +19 -0
  79. package/src/test/app/data/first-test-app/src/manifest.json +21 -0
  80. package/src/test/app/data/first_test_app/.template/template.json +10 -0
  81. package/src/test/app/data/first_test_app/package.json +19 -0
  82. package/src/test/app/data/first_test_app/src/manifest.json +21 -0
  83. package/src/test/app/data/second-test-app/package.json +19 -0
  84. package/src/test/app/data/second-test-app/src/manifest.json +33 -0
  85. package/src/test/app/data/third-test-app/.template/template.json +10 -0
  86. package/src/test/app/data/third-test-app/package.json +19 -0
  87. package/src/test/app/data/third-test-app/src/manifest.json +23 -0
  88. package/src/test/models/ScaffolderOptions.spec.ts +61 -0
  89. package/src/test/validators/AppTemplateValidator.spec.ts +98 -0
  90. package/src/validators/AddOnTemplateValidator.ts +79 -0
  91. package/src/validators/TemplateValidator.ts +35 -0
  92. package/src/validators/index.ts +26 -0
  93. package/tsconfig.json +28 -0
@@ -0,0 +1,272 @@
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, PackageJson, TemplateJson } from "@adobe/ccweb-add-on-core";
27
+ import { EntrypointType } from "@adobe/ccweb-add-on-manifest";
28
+ import { SetupCommandOptions, type CommandExecutor as SSLCommandExecutor } from "@adobe/ccweb-add-on-ssl";
29
+ import { assert } from "chai";
30
+ import "mocha";
31
+ import path from "path";
32
+ import type { SinonSandbox } from "sinon";
33
+ import sinon from "sinon";
34
+ import type { StubbedInstance } from "ts-sinon";
35
+ import { stubInterface } from "ts-sinon";
36
+ import { fileURLToPath } from "url";
37
+ import type {
38
+ AddOnBuilder,
39
+ AddOnBuilderFactory,
40
+ AddOnScaffolder,
41
+ PackageBuilder,
42
+ PackageBuilderFactory
43
+ } from "../../app/index.js";
44
+ import { TemplateAddOnScaffolder } from "../../app/index.js";
45
+ import { ScaffolderOptions } from "../../models/ScaffolderOptions.js";
46
+ import type { TemplateValidator } from "../../validators/TemplateValidator.js";
47
+
48
+ describe("TemplateAddOnScaffolder", () => {
49
+ const __filename = fileURLToPath(import.meta.url);
50
+ const __dirname = path.dirname(__filename);
51
+
52
+ describe("run", () => {
53
+ let sandbox: SinonSandbox;
54
+
55
+ let templateValidator: StubbedInstance<TemplateValidator>;
56
+
57
+ let packageBuilder: StubbedInstance<PackageBuilder>;
58
+ let packageBuilderFactory: PackageBuilderFactory;
59
+
60
+ let addOnBuilder: StubbedInstance<AddOnBuilder>;
61
+ let addOnBuilderFactory: AddOnBuilderFactory;
62
+
63
+ let sslCommandExecutor: StubbedInstance<SSLCommandExecutor>;
64
+
65
+ let cliProcess: StubbedInstance<Process>;
66
+ let logger: StubbedInstance<Logger>;
67
+
68
+ let addOnScaffolder: AddOnScaffolder;
69
+
70
+ beforeEach(() => {
71
+ sandbox = sinon.createSandbox();
72
+
73
+ templateValidator = stubInterface();
74
+
75
+ packageBuilder = stubInterface();
76
+ packageBuilderFactory = sandbox.stub().returns(sandbox.stub().returns(packageBuilder));
77
+
78
+ addOnBuilder = stubInterface();
79
+ addOnBuilderFactory = sandbox.stub().returns(addOnBuilder);
80
+
81
+ sslCommandExecutor = stubInterface();
82
+
83
+ cliProcess = stubInterface();
84
+ logger = stubInterface();
85
+
86
+ addOnScaffolder = new TemplateAddOnScaffolder(
87
+ addOnBuilderFactory,
88
+ packageBuilderFactory,
89
+ templateValidator,
90
+ sslCommandExecutor,
91
+ cliProcess,
92
+ logger
93
+ );
94
+ });
95
+
96
+ afterEach(() => {
97
+ sandbox.restore();
98
+ });
99
+
100
+ it("should handle any error and exit.", async () => {
101
+ const error = new Error("Unexpected error.");
102
+ templateValidator.validateTemplate.throws(error);
103
+
104
+ const processExitStub = sandbox.stub(process, "exit");
105
+
106
+ const addOnDirectory = `${__dirname}/data/first-test-app`;
107
+ const addOnName = "first-test-app";
108
+ const addOnKind = EntrypointType.PANEL;
109
+ const rootDirectory = `${__dirname}/data`;
110
+ const templateName = "javascript";
111
+ const verbose = false;
112
+
113
+ const options = new ScaffolderOptions(
114
+ addOnDirectory,
115
+ addOnName,
116
+ addOnKind,
117
+ rootDirectory,
118
+ templateName,
119
+ verbose
120
+ );
121
+
122
+ await addOnScaffolder.run(options);
123
+
124
+ assert.equal(cliProcess.handleError.callCount, 1);
125
+ assert.equal(cliProcess.handleError.calledWithMatch(error), true);
126
+
127
+ sinon.assert.calledWith(processExitStub, 1);
128
+ });
129
+
130
+ const runs = [
131
+ {
132
+ addOnDirectory: `${__dirname}/data/first-test-app`,
133
+ addOnName: "first-test-app",
134
+ addOnKind: EntrypointType.PANEL,
135
+ rootDirectory: `${__dirname}/data`,
136
+ templateName: "javascript",
137
+ verbose: true
138
+ },
139
+ {
140
+ addOnDirectory: `${__dirname}/data/second-test-app`,
141
+ addOnName: "second-test-app",
142
+ addOnKind: EntrypointType.PANEL,
143
+ rootDirectory: `${__dirname}/data`,
144
+ templateName: "javascript",
145
+ verbose: false
146
+ }
147
+ ];
148
+ runs.forEach(run => {
149
+ it("should scaffold an Add-on and install template devDependencies and dependencies when there are no errors.", async () => {
150
+ templateValidator.validateTemplate.returns();
151
+
152
+ const packageJson = new PackageJson({
153
+ name: run.addOnName,
154
+ version: "1.0.0",
155
+ description: `WXP ${run.addOnKind} application.`,
156
+ keywords: ["adobe", "wxp", run.addOnKind],
157
+ scripts: {
158
+ clean: "ccweb-add-on-scripts clean",
159
+ build: "ccweb-add-on-scripts build",
160
+ start: "ccweb-add-on-scripts start"
161
+ },
162
+ devDependencies: {
163
+ a: "1.0.0"
164
+ },
165
+ dependencies: {
166
+ x: "3.0.0"
167
+ }
168
+ });
169
+ addOnBuilder.getTemplateJson.returns(packageJson);
170
+
171
+ const templateJson = new TemplateJson({
172
+ devDependencies: {
173
+ b: "2.0.0"
174
+ },
175
+ dependencies: {
176
+ y: "4.0.0",
177
+ z: "5.0.0"
178
+ }
179
+ });
180
+ addOnBuilder.getTemplateJson.returns(templateJson);
181
+
182
+ const combinedPackageJson = new PackageJson({
183
+ name: run.addOnName,
184
+ version: "1.0.0",
185
+ description: `WXP ${run.addOnKind} application.`,
186
+ keywords: ["adobe", "wxp", run.addOnKind],
187
+ scripts: {
188
+ clean: "ccweb-add-on-scripts clean",
189
+ build: "ccweb-add-on-scripts build",
190
+ start: "ccweb-add-on-scripts start"
191
+ },
192
+ devDependencies: {
193
+ a: "1.0.0",
194
+ b: "2.0.0"
195
+ },
196
+ dependencies: {
197
+ x: "3.0.0",
198
+ y: "4.0.0",
199
+ z: "5.0.0"
200
+ }
201
+ });
202
+ packageBuilder.build.returns(combinedPackageJson);
203
+
204
+ addOnBuilder.build.withArgs(combinedPackageJson.toJSON()).returns();
205
+
206
+ const devDependencies = new Set(["b@2.0.0"]);
207
+ addOnBuilder.getDevDependenciesToInstall.withArgs(templateJson).returns(devDependencies);
208
+
209
+ const expectedDevDependenciesArgs = ["install", "--save-dev", "--save-exact", ...devDependencies];
210
+ if (run.verbose) {
211
+ expectedDevDependenciesArgs.push("--verbose");
212
+ }
213
+
214
+ const installDevDependenciesResult = {
215
+ isSuccessful: true,
216
+ command: `npm ${expectedDevDependenciesArgs.join(" ")}`
217
+ };
218
+ cliProcess.execute
219
+ .withArgs("npm", expectedDevDependenciesArgs, { stdio: "inherit" })
220
+ .returns(Promise.resolve(installDevDependenciesResult));
221
+
222
+ const dependencies = new Set(["y@4.0.0", "z@5.0.0"]);
223
+ addOnBuilder.getDependenciesToInstall.withArgs(templateJson).returns(dependencies);
224
+
225
+ const expectedDependenciesArgs = ["install", "--save-exact", ...dependencies];
226
+ if (run.verbose) {
227
+ expectedDependenciesArgs.push("--verbose");
228
+ }
229
+
230
+ const installDependenciesResult = {
231
+ isSuccessful: true,
232
+ command: `npm ${expectedDependenciesArgs.join(" ")}`
233
+ };
234
+ cliProcess.execute
235
+ .withArgs("npm", expectedDependenciesArgs, { stdio: "inherit" })
236
+ .returns(Promise.resolve(installDependenciesResult));
237
+
238
+ const setupCommandOptions = new SetupCommandOptions(DEFAULT_HOST_NAME, true, run.verbose);
239
+ sslCommandExecutor.execute.withArgs(setupCommandOptions).resolves();
240
+
241
+ addOnBuilder.displaySuccess.returns();
242
+
243
+ const options = new ScaffolderOptions(
244
+ run.addOnDirectory,
245
+ run.addOnName,
246
+ run.addOnKind as EntrypointType,
247
+ run.rootDirectory,
248
+ run.templateName,
249
+ run.verbose
250
+ );
251
+
252
+ await addOnScaffolder.run(options);
253
+
254
+ assert.equal(logger.information.callCount, 2);
255
+ assert.equal(
256
+ logger.information.getCall(0).calledWith("Installing template dev dependencies ...", {
257
+ prefix: "\n"
258
+ }),
259
+ true
260
+ );
261
+ assert.equal(
262
+ logger.information.getCall(1).calledWith("Installing template dependencies ...", {
263
+ prefix: "\n"
264
+ }),
265
+ true
266
+ );
267
+
268
+ assert.equal(sslCommandExecutor.execute.calledOnceWith(setupCommandOptions), true);
269
+ });
270
+ });
271
+ });
272
+ });
@@ -0,0 +1,332 @@
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 { PackageJson, TemplateJson } from "@adobe/ccweb-add-on-core";
26
+ import { assert } from "chai";
27
+ import "mocha";
28
+ import type { PackageBuilder } from "../../app/index.js";
29
+ import { TemplatePackageBuilder } from "../../app/index.js";
30
+
31
+ describe("TemplatePackageBuilder", () => {
32
+ describe("build()", () => {
33
+ describe("buildDevDependencies ...", () => {
34
+ it("should combine devDependencies from package when template does not have devDependencies.", () => {
35
+ const packageJsonContent = {
36
+ name: "test-app",
37
+ version: "1.0.0",
38
+ description: `WXP panel application.`,
39
+ keywords: ["adobe", "wxp", "panel"],
40
+ devDependencies: { p: "0.1.1", q: "0.1.2", r: "0.1.3" }
41
+ };
42
+ const packageJson = new PackageJson(packageJsonContent);
43
+
44
+ const templateJsonContent = {
45
+ dependencies: { c: "0.0.3", d: "0.0.4" },
46
+ scripts: { e: "echo 'e'", f: "echo 'f'" }
47
+ };
48
+ const templateJson = new TemplateJson(templateJsonContent);
49
+
50
+ const expectedPackageJsonContent = {
51
+ ...packageJsonContent,
52
+ ...templateJsonContent
53
+ };
54
+
55
+ const packageBuilder: PackageBuilder = new TemplatePackageBuilder(packageJson, templateJson);
56
+ const combinedPackageJson = packageBuilder.build();
57
+
58
+ assert.deepEqual(combinedPackageJson, new PackageJson(expectedPackageJsonContent));
59
+ });
60
+
61
+ it("should combine devDependencies from template when package does not have devDependencies.", () => {
62
+ const packageJsonContent = {
63
+ name: "test-app",
64
+ version: "1.0.0",
65
+ description: `WXP panel application.`,
66
+ keywords: ["adobe", "wxp", "panel"]
67
+ };
68
+ const packageJson = new PackageJson(packageJsonContent);
69
+
70
+ const templateJsonContent = {
71
+ devDependencies: { p: "0.1.1", q: "0.1.2", r: "0.1.3" },
72
+ dependencies: { c: "0.0.3", d: "0.0.4" },
73
+ scripts: { e: "echo 'e'", f: "echo 'f'" }
74
+ };
75
+ const templateJson = new TemplateJson(templateJsonContent);
76
+
77
+ const expectedPackageJsonContent = {
78
+ ...packageJsonContent,
79
+ ...templateJsonContent
80
+ };
81
+
82
+ const packageBuilder: PackageBuilder = new TemplatePackageBuilder(packageJson, templateJson);
83
+ const combinedPackageJson = packageBuilder.build();
84
+
85
+ assert.deepEqual(combinedPackageJson, new PackageJson(expectedPackageJsonContent));
86
+ });
87
+
88
+ it("should combine devDependencies when both have devDependencies.", () => {
89
+ const packageJsonContent = {
90
+ name: "test-app",
91
+ version: "1.0.0",
92
+ description: `WXP panel application.`,
93
+ keywords: ["adobe", "wxp", "panel"],
94
+ devDependencies: { m: "1.0.1", n: "1.0.2", o: "1.0.3" }
95
+ };
96
+ const packageJson = new PackageJson(packageJsonContent);
97
+
98
+ const templateJsonContent = {
99
+ devDependencies: { a: "0.0.1", b: "0.0.2" },
100
+ dependencies: { c: "0.0.3", d: "0.0.4" },
101
+ scripts: { e: "echo 'e'", f: "echo 'f'" }
102
+ };
103
+ const templateJson = new TemplateJson(templateJsonContent);
104
+
105
+ const expectedPackageJsonContent = {
106
+ ...packageJsonContent,
107
+ ...templateJsonContent,
108
+ devDependencies: {
109
+ ...packageJsonContent.devDependencies,
110
+ ...templateJsonContent.devDependencies
111
+ }
112
+ };
113
+
114
+ const packageBuilder: PackageBuilder = new TemplatePackageBuilder(packageJson, templateJson);
115
+ const combinedPackageJson = packageBuilder.build();
116
+
117
+ assert.deepEqual(combinedPackageJson, new PackageJson(expectedPackageJsonContent));
118
+ });
119
+ });
120
+
121
+ describe("buildDependencies ...", () => {
122
+ it("should combine dependencies from package when template does not have dependencies.", () => {
123
+ const packageJsonContent = {
124
+ name: "test-app",
125
+ version: "1.0.0",
126
+ description: `WXP panel application.`,
127
+ keywords: ["adobe", "wxp", "panel"],
128
+ dependencies: { p: "0.1.1", q: "0.1.2", r: "0.1.3" }
129
+ };
130
+ const packageJson = new PackageJson(packageJsonContent);
131
+
132
+ const templateJsonContent = {
133
+ devDependencies: { a: "0.0.1", b: "0.0.2" },
134
+ scripts: { e: "echo 'e'", f: "echo 'f'" }
135
+ };
136
+ const templateJson = new TemplateJson(templateJsonContent);
137
+
138
+ const expectedPackageJsonContent = {
139
+ ...packageJsonContent,
140
+ ...templateJsonContent
141
+ };
142
+
143
+ const packageBuilder: PackageBuilder = new TemplatePackageBuilder(packageJson, templateJson);
144
+ const combinedPackageJson = packageBuilder.build();
145
+
146
+ assert.deepEqual(combinedPackageJson, new PackageJson(expectedPackageJsonContent));
147
+ });
148
+
149
+ it("should combine dependencies from template when package does not have dependencies.", () => {
150
+ const packageJsonContent = {
151
+ name: "test-app",
152
+ version: "1.0.0",
153
+ description: `WXP panel application.`,
154
+ keywords: ["adobe", "wxp", "panel"]
155
+ };
156
+ const packageJson = new PackageJson(packageJsonContent);
157
+
158
+ const templateJsonContent = {
159
+ dependencies: { p: "0.1.1", q: "0.1.2", r: "0.1.3" },
160
+ devDependencies: { a: "0.0.1", b: "0.0.2" },
161
+ scripts: { e: "echo 'e'", f: "echo 'f'" }
162
+ };
163
+ const templateJson = new TemplateJson(templateJsonContent);
164
+
165
+ const expectedPackageJsonContent = {
166
+ ...packageJsonContent,
167
+ ...templateJsonContent
168
+ };
169
+
170
+ const packageBuilder: PackageBuilder = new TemplatePackageBuilder(packageJson, templateJson);
171
+ const combinedPackageJson = packageBuilder.build();
172
+
173
+ assert.deepEqual(combinedPackageJson, new PackageJson(expectedPackageJsonContent));
174
+ });
175
+
176
+ it("should combine dependencies when both have dependencies.", () => {
177
+ const packageJsonContent = {
178
+ name: "test-app",
179
+ version: "1.0.0",
180
+ description: `WXP panel application.`,
181
+ keywords: ["adobe", "wxp", "panel"],
182
+ dependencies: { p: "0.1.1", q: "0.1.2", r: "0.1.3" }
183
+ };
184
+ const packageJson = new PackageJson(packageJsonContent);
185
+
186
+ const templateJsonContent = {
187
+ devDependencies: { a: "0.0.1", b: "0.0.2" },
188
+ dependencies: { c: "0.0.3", d: "0.0.4" },
189
+ scripts: { e: "echo 'e'", f: "echo 'f'" }
190
+ };
191
+ const templateJson = new TemplateJson(templateJsonContent);
192
+
193
+ const expectedPackageJsonContent = {
194
+ ...packageJsonContent,
195
+ ...templateJsonContent,
196
+ dependencies: {
197
+ ...packageJsonContent.dependencies,
198
+ ...templateJsonContent.dependencies
199
+ }
200
+ };
201
+
202
+ const packageBuilder: PackageBuilder = new TemplatePackageBuilder(packageJson, templateJson);
203
+ const combinedPackageJson = packageBuilder.build();
204
+
205
+ assert.deepEqual(combinedPackageJson, new PackageJson(expectedPackageJsonContent));
206
+ });
207
+ });
208
+
209
+ describe("buildScripts ...", () => {
210
+ it("should combine scripts from package when template does not have scripts.", () => {
211
+ const packageJsonContent = {
212
+ name: "test-app",
213
+ version: "1.0.0",
214
+ description: `WXP panel application.`,
215
+ keywords: ["adobe", "wxp", "panel"],
216
+ scripts: { s: "echo 's'", t: "echo 't'", u: "echo 'u'" }
217
+ };
218
+ const packageJson = new PackageJson(packageJsonContent);
219
+
220
+ const templateJsonContent = {
221
+ devDependencies: { a: "0.0.1", b: "0.0.2" },
222
+ dependencies: { c: "0.0.3", d: "0.0.4" }
223
+ };
224
+ const templateJson = new TemplateJson(templateJsonContent);
225
+
226
+ const expectedPackageJsonContent = {
227
+ ...packageJsonContent,
228
+ ...templateJsonContent
229
+ };
230
+
231
+ const packageBuilder: PackageBuilder = new TemplatePackageBuilder(packageJson, templateJson);
232
+ const combinedPackageJson = packageBuilder.build();
233
+
234
+ assert.deepEqual(combinedPackageJson, new PackageJson(expectedPackageJsonContent));
235
+ });
236
+
237
+ it("should combine scripts from template when package does not have scripts.", () => {
238
+ const packageJsonContent = {
239
+ name: "test-app",
240
+ version: "1.0.0",
241
+ description: `WXP panel application.`,
242
+ keywords: ["adobe", "wxp", "panel"]
243
+ };
244
+ const packageJson = new PackageJson(packageJsonContent);
245
+
246
+ const templateJsonContent = {
247
+ devDependencies: { a: "0.0.1", b: "0.0.2" },
248
+ dependencies: { c: "0.0.3", d: "0.0.4" },
249
+ scripts: { s: "echo 's'", t: "echo 't'", u: "echo 'u'" }
250
+ };
251
+ const templateJson = new TemplateJson(templateJsonContent);
252
+
253
+ const expectedPackageJsonContent = {
254
+ ...packageJsonContent,
255
+ ...templateJsonContent
256
+ };
257
+
258
+ const packageBuilder: PackageBuilder = new TemplatePackageBuilder(packageJson, templateJson);
259
+ const combinedPackageJson = packageBuilder.build();
260
+
261
+ assert.deepEqual(combinedPackageJson, new PackageJson(expectedPackageJsonContent));
262
+ });
263
+
264
+ it("should combine scripts when both have scripts.", () => {
265
+ const packageJsonContent = {
266
+ name: "test-app",
267
+ version: "1.0.0",
268
+ description: `WXP panel application.`,
269
+ keywords: ["adobe", "wxp", "panel"],
270
+ scripts: { s: "echo 's'", t: "echo 't'", u: "echo 'u'" }
271
+ };
272
+ const packageJson = new PackageJson(packageJsonContent);
273
+
274
+ const templateJsonContent = {
275
+ devDependencies: { a: "0.0.1", b: "0.0.2" },
276
+ dependencies: { c: "0.0.3", d: "0.0.4" },
277
+ scripts: { e: "echo 'e'", f: "echo 'f'" }
278
+ };
279
+ const templateJson = new TemplateJson(templateJsonContent);
280
+
281
+ const expectedPackageJsonContent = {
282
+ ...packageJsonContent,
283
+ ...templateJsonContent,
284
+ scripts: { ...packageJsonContent.scripts, ...templateJsonContent.scripts }
285
+ };
286
+
287
+ const packageBuilder: PackageBuilder = new TemplatePackageBuilder(packageJson, templateJson);
288
+ const combinedPackageJson = packageBuilder.build();
289
+
290
+ assert.deepEqual(combinedPackageJson, new PackageJson(expectedPackageJsonContent));
291
+ });
292
+
293
+ it("should combine package and template when both have all properties.", () => {
294
+ const packageJsonContent = {
295
+ name: "test-app",
296
+ version: "1.0.0",
297
+ description: `WXP panel application.`,
298
+ keywords: ["adobe", "wxp", "panel"],
299
+ devDependencies: { p: "0.0.1", q: "0.0.2" },
300
+ dependencies: { r: "0.0.3", s: "0.0.4" },
301
+ scripts: { t: "echo 's'", u: "echo 't'", v: "echo 'u'" }
302
+ };
303
+ const packageJson = new PackageJson(packageJsonContent);
304
+
305
+ const templateJsonContent = {
306
+ devDependencies: { a: "0.0.1", b: "0.0.2" },
307
+ dependencies: { c: "0.0.3", d: "0.0.4" },
308
+ scripts: { e: "echo 'e'", f: "echo 'f'" }
309
+ };
310
+ const templateJson = new TemplateJson(templateJsonContent);
311
+
312
+ const expectedPackageJsonContent = {
313
+ ...packageJsonContent,
314
+ devDependencies: {
315
+ ...packageJsonContent.devDependencies,
316
+ ...templateJsonContent.devDependencies
317
+ },
318
+ dependencies: {
319
+ ...packageJsonContent.dependencies,
320
+ ...templateJsonContent.dependencies
321
+ },
322
+ scripts: { ...packageJsonContent.scripts, ...templateJsonContent.scripts }
323
+ };
324
+
325
+ const packageBuilder: PackageBuilder = new TemplatePackageBuilder(packageJson, templateJson);
326
+ const combinedPackageJson = packageBuilder.build();
327
+
328
+ assert.deepEqual(combinedPackageJson, new PackageJson(expectedPackageJsonContent));
329
+ });
330
+ });
331
+ });
332
+ });
@@ -0,0 +1,10 @@
1
+ {
2
+ "scripts": {
3
+ "clean": "ccweb-add-on-scripts clean",
4
+ "build": "ccweb-add-on-scripts build",
5
+ "start": "ccweb-add-on-scripts start"
6
+ },
7
+ "devDependencies": {
8
+ "prettier": "2.6.0"
9
+ }
10
+ }
@@ -0,0 +1,19 @@
1
+ {
2
+ "name": "iframe-panel",
3
+ "version": "1.0.0",
4
+ "description": "Iframe Add-on.",
5
+ "scripts": {
6
+ "clean": "ccweb-add-on-scripts clean",
7
+ "build": "ccweb-add-on-scripts build",
8
+ "start": "ccweb-add-on-scripts start"
9
+ },
10
+ "keywords": [
11
+ "Adobe",
12
+ "Horizon",
13
+ "WXP",
14
+ "Iframe",
15
+ "Panel"
16
+ ],
17
+ "author": "Adobe Systems Inc.",
18
+ "license": "ISC"
19
+ }
@@ -0,0 +1,21 @@
1
+ {
2
+ "testId": "",
3
+ "name": "",
4
+ "version": "",
5
+ "manifestVersion": 2,
6
+ "requirements": {
7
+ "apps": [
8
+ {
9
+ "name": "Express",
10
+ "apiVersion": 1
11
+ }
12
+ ]
13
+ },
14
+ "entryPoints": [
15
+ {
16
+ "type": "panel",
17
+ "id": "panel1",
18
+ "main": "index.html"
19
+ }
20
+ ]
21
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "scripts": {
3
+ "clean": "ccweb-add-on-scripts clean",
4
+ "build": "ccweb-add-on-scripts build",
5
+ "start": "ccweb-add-on-scripts start"
6
+ },
7
+ "devDependencies": {
8
+ "prettier": "2.6.0"
9
+ }
10
+ }