@adobe/ccweb-add-on-core 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 (94) hide show
  1. package/.c8rc.json +14 -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/config/index.d.ts +26 -0
  8. package/dist/config/index.d.ts.map +1 -0
  9. package/dist/config/index.js +26 -0
  10. package/dist/config/inversify.config.d.ts +28 -0
  11. package/dist/config/inversify.config.d.ts.map +1 -0
  12. package/dist/config/inversify.config.js +33 -0
  13. package/dist/config/inversify.types.d.ts +30 -0
  14. package/dist/config/inversify.types.d.ts.map +1 -0
  15. package/dist/config/inversify.types.js +30 -0
  16. package/dist/constants.d.ts +37 -0
  17. package/dist/constants.d.ts.map +1 -0
  18. package/dist/constants.js +38 -0
  19. package/dist/index.d.ts +28 -0
  20. package/dist/index.d.ts.map +1 -0
  21. package/dist/index.js +28 -0
  22. package/dist/models/PackageJson.d.ts +61 -0
  23. package/dist/models/PackageJson.d.ts.map +1 -0
  24. package/dist/models/PackageJson.js +76 -0
  25. package/dist/models/PreferenceJson.d.ts +79 -0
  26. package/dist/models/PreferenceJson.d.ts.map +1 -0
  27. package/dist/models/PreferenceJson.js +88 -0
  28. package/dist/models/TemplateJson.d.ts +53 -0
  29. package/dist/models/TemplateJson.d.ts.map +1 -0
  30. package/dist/models/TemplateJson.js +112 -0
  31. package/dist/models/Types.d.ts +72 -0
  32. package/dist/models/Types.d.ts.map +1 -0
  33. package/dist/models/Types.js +25 -0
  34. package/dist/models/index.d.ts +28 -0
  35. package/dist/models/index.d.ts.map +1 -0
  36. package/dist/models/index.js +28 -0
  37. package/dist/tsconfig.tsbuildinfo +1 -0
  38. package/dist/utilities/CLIPreferences.d.ts +45 -0
  39. package/dist/utilities/CLIPreferences.d.ts.map +1 -0
  40. package/dist/utilities/CLIPreferences.js +80 -0
  41. package/dist/utilities/CLIProcess.d.ts +74 -0
  42. package/dist/utilities/CLIProcess.d.ts.map +1 -0
  43. package/dist/utilities/CLIProcess.js +190 -0
  44. package/dist/utilities/ConsoleLogger.d.ts +64 -0
  45. package/dist/utilities/ConsoleLogger.d.ts.map +1 -0
  46. package/dist/utilities/ConsoleLogger.js +103 -0
  47. package/dist/utilities/Extensions.d.ts +67 -0
  48. package/dist/utilities/Extensions.d.ts.map +1 -0
  49. package/dist/utilities/Extensions.js +92 -0
  50. package/dist/utilities/Logger.d.ts +65 -0
  51. package/dist/utilities/Logger.d.ts.map +1 -0
  52. package/dist/utilities/Logger.js +25 -0
  53. package/dist/utilities/Preferences.d.ts +41 -0
  54. package/dist/utilities/Preferences.d.ts.map +1 -0
  55. package/dist/utilities/Preferences.js +25 -0
  56. package/dist/utilities/Process.d.ts +63 -0
  57. package/dist/utilities/Process.d.ts.map +1 -0
  58. package/dist/utilities/Process.js +25 -0
  59. package/dist/utilities/UncaughtExceptionHandler.d.ts +40 -0
  60. package/dist/utilities/UncaughtExceptionHandler.d.ts.map +1 -0
  61. package/dist/utilities/UncaughtExceptionHandler.js +51 -0
  62. package/dist/utilities/index.d.ts +32 -0
  63. package/dist/utilities/index.d.ts.map +1 -0
  64. package/dist/utilities/index.js +32 -0
  65. package/package.json +51 -0
  66. package/src/config/index.ts +26 -0
  67. package/src/config/inversify.config.ts +39 -0
  68. package/src/config/inversify.types.ts +30 -0
  69. package/src/constants.ts +41 -0
  70. package/src/index.ts +28 -0
  71. package/src/models/PackageJson.ts +83 -0
  72. package/src/models/PreferenceJson.ts +112 -0
  73. package/src/models/TemplateJson.ts +121 -0
  74. package/src/models/Types.ts +80 -0
  75. package/src/models/index.ts +28 -0
  76. package/src/test/models/PackageJson.spec.ts +198 -0
  77. package/src/test/models/PreferenceJson.spec.ts +184 -0
  78. package/src/test/models/TemplateJson.spec.ts +179 -0
  79. package/src/test/utilities/CLIPreferences.spec.ts +208 -0
  80. package/src/test/utilities/CLIProcess.spec.ts +363 -0
  81. package/src/test/utilities/ConsoleLogger.spec.ts +165 -0
  82. package/src/test/utilities/Extensions.spec.ts +240 -0
  83. package/src/test/utilities/UncaughtExceptionHandler.spec.ts +83 -0
  84. package/src/types/applicationConfigPath.d.ts +1 -0
  85. package/src/utilities/CLIPreferences.ts +84 -0
  86. package/src/utilities/CLIProcess.ts +200 -0
  87. package/src/utilities/ConsoleLogger.ts +111 -0
  88. package/src/utilities/Extensions.ts +98 -0
  89. package/src/utilities/Logger.ts +70 -0
  90. package/src/utilities/Preferences.ts +43 -0
  91. package/src/utilities/Process.ts +66 -0
  92. package/src/utilities/UncaughtExceptionHandler.ts +55 -0
  93. package/src/utilities/index.ts +32 -0
  94. package/tsconfig.json +31 -0
@@ -0,0 +1,198 @@
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 { assert } from "chai";
26
+ import "mocha";
27
+ import { PackageJson } from "../../models/PackageJson.js";
28
+ import { removeSymbols } from "../../utilities/Extensions.js";
29
+
30
+ describe("PackageJson", () => {
31
+ describe("constructor ...", () => {
32
+ it(`should not set any properties when the constructor argument is empty.`, () => {
33
+ const packageJson = new PackageJson({});
34
+ assert.isDefined(packageJson);
35
+ assert.isUndefined(packageJson.name);
36
+ assert.isUndefined(packageJson.version);
37
+ assert.isUndefined(packageJson.description);
38
+ assert.isUndefined(packageJson.keywords);
39
+ assert.isUndefined(packageJson.devDependencies);
40
+ assert.isUndefined(packageJson.dependencies);
41
+ assert.isUndefined(packageJson.scripts);
42
+ });
43
+
44
+ it(`should only set name when the constructor argument only contains name.`, () => {
45
+ const content = {
46
+ name: "simple-app"
47
+ };
48
+
49
+ const packageJson = new PackageJson(content);
50
+ assert.isDefined(packageJson);
51
+ assert.equal(packageJson.name, content.name);
52
+
53
+ assert.isUndefined(packageJson.version);
54
+ assert.isUndefined(packageJson.description);
55
+ assert.isUndefined(packageJson.keywords);
56
+
57
+ assert.isUndefined(packageJson.devDependencies);
58
+ assert.isUndefined(packageJson.dependencies);
59
+ assert.isUndefined(packageJson.scripts);
60
+ });
61
+
62
+ it(`should only set version when the constructor argument only contains version.`, () => {
63
+ const content = {
64
+ version: "1.0.0"
65
+ };
66
+
67
+ const packageJson = new PackageJson(content);
68
+ assert.isDefined(packageJson);
69
+ assert.equal(packageJson.version, content.version);
70
+
71
+ assert.isUndefined(packageJson.name);
72
+ assert.isUndefined(packageJson.description);
73
+ assert.isUndefined(packageJson.keywords);
74
+
75
+ assert.isUndefined(packageJson.devDependencies);
76
+ assert.isUndefined(packageJson.dependencies);
77
+ assert.isUndefined(packageJson.scripts);
78
+ });
79
+
80
+ it(`should only set description when the constructor argument only contains description.`, () => {
81
+ const content = {
82
+ description: "simple app"
83
+ };
84
+
85
+ const packageJson = new PackageJson(content);
86
+ assert.isDefined(packageJson);
87
+ assert.equal(packageJson.description, content.description);
88
+
89
+ assert.isUndefined(packageJson.name);
90
+ assert.isUndefined(packageJson.version);
91
+ assert.isUndefined(packageJson.keywords);
92
+
93
+ assert.isUndefined(packageJson.devDependencies);
94
+ assert.isUndefined(packageJson.dependencies);
95
+ assert.isUndefined(packageJson.scripts);
96
+ });
97
+
98
+ it(`should only set keywords when the constructor argument only contains keywords.`, () => {
99
+ const content = {
100
+ keywords: ["simple", "app"]
101
+ };
102
+
103
+ const packageJson = new PackageJson(content);
104
+ assert.isDefined(packageJson);
105
+ assert.equal(packageJson.keywords, content.keywords);
106
+
107
+ assert.isUndefined(packageJson.name);
108
+ assert.isUndefined(packageJson.description);
109
+ assert.isUndefined(packageJson.version);
110
+
111
+ assert.isUndefined(packageJson.devDependencies);
112
+ assert.isUndefined(packageJson.dependencies);
113
+ assert.isUndefined(packageJson.scripts);
114
+ });
115
+
116
+ it(`should set all properties when the constructor argument contains them.`, () => {
117
+ const content = {
118
+ name: "simple-app",
119
+ version: "1.0.0",
120
+ description: "simple app",
121
+ keywords: ["simple", "app"],
122
+ devDependencies: {
123
+ a: "1.0.0",
124
+ b: "2.0.0"
125
+ },
126
+ dependencies: {
127
+ c: "3.0.0",
128
+ d: "4.0.0"
129
+ },
130
+ scripts: {
131
+ e: "clean",
132
+ f: "build"
133
+ }
134
+ };
135
+
136
+ const packageJson = new PackageJson(content);
137
+ assert.isDefined(packageJson);
138
+ assert.equal(packageJson.name, content.name);
139
+ assert.equal(packageJson.version, content.version);
140
+ assert.equal(packageJson.description, content.description);
141
+ assert.equal(packageJson.keywords, content.keywords);
142
+
143
+ assert.isDefined(packageJson.devDependencies);
144
+ assert.equal(packageJson.devDependencies?.get("a"), content.devDependencies.a);
145
+ assert.equal(packageJson.devDependencies?.get("b"), content.devDependencies.b);
146
+
147
+ assert.isDefined(packageJson.dependencies);
148
+ assert.equal(packageJson.dependencies?.get("c"), content.dependencies.c);
149
+ assert.equal(packageJson.dependencies?.get("d"), content.dependencies.d);
150
+
151
+ assert.isDefined(packageJson.scripts);
152
+ assert.equal(packageJson.scripts?.get("e"), content.scripts.e);
153
+ assert.equal(packageJson.scripts?.get("f"), content.scripts.f);
154
+ });
155
+ });
156
+
157
+ describe("toJSON ...", () => {
158
+ it(`should return stringify-ed PackageJson with properties except for the undefined ones.`, () => {
159
+ const content = {
160
+ name: "simple-app",
161
+ version: "1.0.0",
162
+ description: "simple app",
163
+ keywords: ["simple", "app"]
164
+ };
165
+
166
+ const packageJson = new PackageJson(content);
167
+ const packageJsonString = packageJson.toJSON();
168
+
169
+ assert.equal(removeSymbols(packageJsonString), removeSymbols(JSON.stringify(content, undefined, 4)));
170
+ });
171
+
172
+ it(`should return stringify-ed PackageJson with all properties when all are defined.`, () => {
173
+ const content = {
174
+ name: "simple-app",
175
+ version: "1.0.0",
176
+ description: "simple app",
177
+ scripts: {
178
+ e: "clean",
179
+ f: "build"
180
+ },
181
+ keywords: ["simple", "app"],
182
+ dependencies: {
183
+ c: "3.0.0",
184
+ d: "4.0.0"
185
+ },
186
+ devDependencies: {
187
+ a: "1.0.0",
188
+ b: "2.0.0"
189
+ }
190
+ };
191
+
192
+ const packageJson = new PackageJson(content);
193
+ const packageJsonString = packageJson.toJSON();
194
+
195
+ assert.equal(removeSymbols(packageJsonString), removeSymbols(JSON.stringify(content, undefined, 4)));
196
+ });
197
+ });
198
+ });
@@ -0,0 +1,184 @@
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 { assert } from "chai";
26
+ import "mocha";
27
+ import { DEFAULT_HOST_NAME } from "../../constants.js";
28
+ import { PreferenceJson } from "../../models/PreferenceJson.js";
29
+ import { removeSymbols } from "../../utilities/Extensions.js";
30
+
31
+ describe("PreferenceJson", () => {
32
+ describe("constructor", () => {
33
+ it("should set required properties to default value when the constructor argument is empty.", () => {
34
+ const preferenceJson = new PreferenceJson({});
35
+
36
+ assert.isDefined(preferenceJson);
37
+ assert.isUndefined(preferenceJson.hasTelemetryConsent);
38
+ assert.isUndefined(preferenceJson.ims);
39
+ assert.isUndefined(preferenceJson.clientId);
40
+ assert.isUndefined(preferenceJson.ssl);
41
+ });
42
+
43
+ it("should set the properties from the 'content' constructor argument.", () => {
44
+ const content = {
45
+ hasTelemetryConsent: false,
46
+ ims: {
47
+ contexts: {
48
+ cli: {
49
+ "cli.bare-output": true
50
+ }
51
+ }
52
+ },
53
+ clientId: 1096361282655,
54
+ ssl: {
55
+ localhost: {
56
+ certificatePath: "/some-directory/localhost/ssl/certificate.cert",
57
+ keyPath: "/some-directory/localhost/ssl/private-key.key"
58
+ },
59
+ "localhost.adobe.com": {
60
+ certificatePath: "/some-directory/localhost.adobe.com/ssl/certificate.cert",
61
+ keyPath: "/some-directory/localhost.adobe.com/ssl/private-key.key"
62
+ }
63
+ }
64
+ };
65
+
66
+ const preferenceJson = new PreferenceJson(content);
67
+
68
+ assert.isDefined(preferenceJson);
69
+ assert.equal(preferenceJson.hasTelemetryConsent, content.hasTelemetryConsent);
70
+ assert.deepEqual(preferenceJson.ims, content.ims);
71
+ assert.equal(preferenceJson.clientId, content.clientId);
72
+ assert.deepEqual(Object.fromEntries(preferenceJson.ssl!), content.ssl);
73
+ });
74
+
75
+ it("should set the backward compatible SSL properties from the 'content' constructor argument.", () => {
76
+ const content = {
77
+ hasTelemetryConsent: false,
78
+ ims: {
79
+ contexts: {
80
+ cli: {
81
+ "cli.bare-output": true
82
+ }
83
+ }
84
+ },
85
+ clientId: 1096361282655,
86
+ sslCertPath: "/some-directory/localhost/ssl/certificate.cert",
87
+ sslKeyPath: "/some-directory/localhost/ssl/private-key.key"
88
+ };
89
+
90
+ const preferenceJson = new PreferenceJson(content);
91
+
92
+ assert.isDefined(preferenceJson);
93
+ assert.equal(preferenceJson.hasTelemetryConsent, content.hasTelemetryConsent);
94
+ assert.deepEqual(preferenceJson.ims, content.ims);
95
+ assert.equal(preferenceJson.clientId, content.clientId);
96
+ assert.deepEqual(Object.fromEntries(preferenceJson.ssl!), {
97
+ [DEFAULT_HOST_NAME]: {
98
+ certificatePath: content.sslCertPath,
99
+ keyPath: content.sslKeyPath
100
+ }
101
+ });
102
+ });
103
+
104
+ it("should set the latest SSL version when both versions are present in the 'content' constructor argument.", () => {
105
+ const content = {
106
+ hasTelemetryConsent: false,
107
+ ims: {
108
+ contexts: {
109
+ cli: {
110
+ "cli.bare-output": true
111
+ }
112
+ }
113
+ },
114
+ clientId: 1096361282655,
115
+ ssl: {
116
+ localhost: {
117
+ certificatePath: "/some-directory/localhost/ssl/certificate.cert",
118
+ keyPath: "/some-directory/localhost/ssl/private-key.key"
119
+ },
120
+ "localhost.adobe.com": {
121
+ certificatePath: "/some-directory/localhost.adobe.com/ssl/certificate.cert",
122
+ keyPath: "/some-directory/localhost.adobe.com/ssl/private-key.key"
123
+ }
124
+ },
125
+ sslCertPath: "/some-directory/localhost/ssl/certificate.cert",
126
+ sslKeyPath: "/some-directory/localhost/ssl/private-key.key"
127
+ };
128
+
129
+ const preferenceJson = new PreferenceJson(content);
130
+
131
+ assert.isDefined(preferenceJson);
132
+ assert.equal(preferenceJson.hasTelemetryConsent, content.hasTelemetryConsent);
133
+ assert.deepEqual(preferenceJson.ims, content.ims);
134
+ assert.equal(preferenceJson.clientId, content.clientId);
135
+ assert.deepEqual(Object.fromEntries(preferenceJson.ssl!), content.ssl);
136
+ });
137
+ });
138
+
139
+ describe("toJSON", () => {
140
+ const runs = [
141
+ {
142
+ content: {
143
+ hasTelemetryConsent: true,
144
+ clientId: 1096361282655
145
+ }
146
+ },
147
+ {
148
+ content: {
149
+ hasTelemetryConsent: false,
150
+ ims: {
151
+ contexts: {
152
+ cli: {
153
+ "cli.bare-output": true
154
+ }
155
+ }
156
+ },
157
+ clientId: 1096361282655,
158
+ ssl: {
159
+ localhost: {
160
+ certificatePath: "/some-directory/localhost/ssl/certificate.cert",
161
+ keyPath: "/some-directory/localhost/ssl/private-key.key"
162
+ },
163
+ "localhost.adobe.com": {
164
+ certificatePath: "/some-directory/localhost.adobe.com/ssl/certificate.cert",
165
+ keyPath: "/some-directory/localhost.adobe.com/ssl/private-key.key"
166
+ }
167
+ }
168
+ }
169
+ }
170
+ ];
171
+
172
+ runs.forEach(run => {
173
+ it("should return stringify-ed PreferenceJson with properties except for the undefined ones.", () => {
174
+ const preferenceJson = new PreferenceJson(run.content);
175
+ const preferenceJsonString = preferenceJson.toJSON();
176
+
177
+ assert.equal(
178
+ removeSymbols(preferenceJsonString),
179
+ removeSymbols(JSON.stringify(run.content, undefined, 4))
180
+ );
181
+ });
182
+ });
183
+ });
184
+ });
@@ -0,0 +1,179 @@
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 { assert } from "chai";
26
+ import "mocha";
27
+ import { TemplateJson } from "../../models/index.js";
28
+
29
+ describe("TemplateJson", () => {
30
+ describe("constructor ...", () => {
31
+ it(`should not set any properties when the constructor argument is undefined.`, () => {
32
+ const templateJson = new TemplateJson({});
33
+ assert.isDefined(templateJson);
34
+ assert.isUndefined(templateJson.devDependencies);
35
+ assert.isUndefined(templateJson.dependencies);
36
+ assert.isUndefined(templateJson.scripts);
37
+ });
38
+
39
+ it(`should only set devDependencies when the constructor argument only contains devDependencies.`, () => {
40
+ const content = {
41
+ devDependencies: {
42
+ a: "1.0.0",
43
+ b: "2.0.0"
44
+ }
45
+ };
46
+
47
+ let templateJson = new TemplateJson(content);
48
+ assert.isDefined(templateJson);
49
+
50
+ assert.isDefined(templateJson.devDependencies);
51
+ assert.equal(templateJson.devDependencies?.get("a"), content.devDependencies.a);
52
+ assert.equal(templateJson.devDependencies?.get("b"), content.devDependencies.b);
53
+
54
+ assert.isUndefined(templateJson.dependencies);
55
+ assert.isUndefined(templateJson.scripts);
56
+
57
+ const contentMap = {
58
+ devDependencies: new Map([
59
+ ["a", "1.0.0"],
60
+ ["b", "2.0.0"]
61
+ ])
62
+ };
63
+
64
+ templateJson = new TemplateJson(contentMap);
65
+ assert.isDefined(templateJson);
66
+
67
+ assert.isDefined(templateJson.devDependencies);
68
+ assert.equal(templateJson.devDependencies?.get("a"), content.devDependencies.a);
69
+ assert.equal(templateJson.devDependencies?.get("b"), content.devDependencies.b);
70
+
71
+ assert.isUndefined(templateJson.dependencies);
72
+ assert.isUndefined(templateJson.scripts);
73
+ });
74
+
75
+ it(`should only set dependencies when the constructor argument only contains dependencies.`, () => {
76
+ const content = {
77
+ dependencies: {
78
+ c: "3.0.0",
79
+ d: "4.0.0"
80
+ }
81
+ };
82
+
83
+ let templateJson = new TemplateJson(content);
84
+ assert.isDefined(templateJson);
85
+
86
+ assert.isDefined(templateJson.dependencies);
87
+ assert.equal(templateJson.dependencies?.get("c"), content.dependencies.c);
88
+ assert.equal(templateJson.dependencies?.get("d"), content.dependencies.d);
89
+
90
+ assert.isUndefined(templateJson.devDependencies);
91
+ assert.isUndefined(templateJson.scripts);
92
+
93
+ const contentMap = {
94
+ dependencies: new Map([
95
+ ["c", "3.0.0"],
96
+ ["d", "4.0.0"]
97
+ ])
98
+ };
99
+
100
+ templateJson = new TemplateJson(contentMap);
101
+ assert.isDefined(templateJson);
102
+
103
+ assert.isDefined(templateJson.dependencies);
104
+ assert.equal(templateJson.dependencies?.get("c"), content.dependencies.c);
105
+ assert.equal(templateJson.dependencies?.get("d"), content.dependencies.d);
106
+
107
+ assert.isUndefined(templateJson.devDependencies);
108
+ assert.isUndefined(templateJson.scripts);
109
+ });
110
+
111
+ it(`should only set scripts when the constructor argument only contains scripts.`, () => {
112
+ const content = {
113
+ scripts: {
114
+ e: "clean",
115
+ f: "build"
116
+ }
117
+ };
118
+
119
+ let templateJson = new TemplateJson(content);
120
+ assert.isDefined(templateJson);
121
+
122
+ assert.isDefined(templateJson.scripts);
123
+ assert.equal(templateJson.scripts?.get("e"), content.scripts.e);
124
+ assert.equal(templateJson.scripts?.get("f"), content.scripts.f);
125
+
126
+ assert.isUndefined(templateJson.devDependencies);
127
+ assert.isUndefined(templateJson.dependencies);
128
+
129
+ const contentMap = {
130
+ scripts: new Map([
131
+ ["e", "clean"],
132
+ ["f", "build"]
133
+ ])
134
+ };
135
+
136
+ templateJson = new TemplateJson(contentMap);
137
+ assert.isDefined(templateJson);
138
+
139
+ assert.isDefined(templateJson.scripts);
140
+ assert.equal(templateJson.scripts?.get("e"), content.scripts.e);
141
+ assert.equal(templateJson.scripts?.get("f"), content.scripts.f);
142
+
143
+ assert.isUndefined(templateJson.devDependencies);
144
+ assert.isUndefined(templateJson.dependencies);
145
+ });
146
+
147
+ it(`should set all properties when the constructor argument contains them.`, () => {
148
+ const content = {
149
+ devDependencies: {
150
+ a: "1.0.0",
151
+ b: "2.0.0"
152
+ },
153
+ dependencies: {
154
+ c: "3.0.0",
155
+ d: "4.0.0"
156
+ },
157
+ scripts: {
158
+ e: "clean",
159
+ f: "build"
160
+ }
161
+ };
162
+
163
+ const templateJson = new TemplateJson(content);
164
+ assert.isDefined(templateJson);
165
+
166
+ assert.isDefined(templateJson.devDependencies);
167
+ assert.equal(templateJson.devDependencies?.get("a"), content.devDependencies.a);
168
+ assert.equal(templateJson.devDependencies?.get("b"), content.devDependencies.b);
169
+
170
+ assert.isDefined(templateJson.dependencies);
171
+ assert.equal(templateJson.dependencies?.get("c"), content.dependencies.c);
172
+ assert.equal(templateJson.dependencies?.get("d"), content.dependencies.d);
173
+
174
+ assert.isDefined(templateJson.scripts);
175
+ assert.equal(templateJson.scripts?.get("e"), content.scripts.e);
176
+ assert.equal(templateJson.scripts?.get("f"), content.scripts.f);
177
+ });
178
+ });
179
+ });