@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,200 @@
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 { ChildProcess, ExecSyncOptions, SpawnSyncReturns } from "child_process";
26
+ import childprocess from "cross-spawn";
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 { ITypes } from "../config/inversify.types.js";
34
+ import type { ExecutionResult } from "../models/index.js";
35
+ import type { Logger } from "./Logger.js";
36
+ import type { Process } from "./Process.js";
37
+
38
+ /**
39
+ * CLI Process implementation class for managing execution of commands.
40
+ */
41
+ @injectable()
42
+ export class CLIProcess implements Process {
43
+ private readonly _logger: Logger;
44
+
45
+ /**
46
+ * Instantiate {@link CLIProcess}.
47
+ *
48
+ * @param logger - {@link Logger} reference.
49
+ * @returns Reference to a new {@link CLIProcess} instance.
50
+ */
51
+ constructor(@inject(ITypes.Logger) logger: Logger) {
52
+ this._logger = logger;
53
+ }
54
+
55
+ /**
56
+ * Execute a command asynchronously.
57
+ *
58
+ * @param command - Command to execute.
59
+ * @param args - Command arguments.
60
+ * @param options - Execution {@link ExecSyncOptions} options.
61
+ * @returns Promise of {@link ExecutionResult}.
62
+ */
63
+ execute(command: string, args: string[], options?: ExecSyncOptions): Promise<ExecutionResult> {
64
+ const commandWithArgs = args.length > 0 ? `${command} ${args.join(" ")}` : command;
65
+ return new Promise(resolve => {
66
+ let childProcess: ChildProcess;
67
+ if (options) {
68
+ childProcess = childprocess.spawn(command, args, options);
69
+ } else {
70
+ childProcess = childprocess.spawn(command, args);
71
+ }
72
+
73
+ childProcess.on("close", code => {
74
+ if (code !== 0) {
75
+ resolve({
76
+ command: commandWithArgs,
77
+ isSuccessful: false
78
+ });
79
+
80
+ return;
81
+ }
82
+
83
+ resolve({
84
+ command: commandWithArgs,
85
+ isSuccessful: true
86
+ });
87
+ });
88
+ });
89
+ }
90
+
91
+ /**
92
+ * Execute a command synchronously.
93
+ *
94
+ * @param command - Command to execute.
95
+ * @param args - Command arguments.
96
+ * @param options - Execution {@link ExecSyncOptions} options.
97
+ * @returns {@link ExecutionResult}.
98
+ */
99
+ executeSync(command: string, args: string[], options?: ExecSyncOptions): ExecutionResult {
100
+ const commandWithArgs = args.length > 0 ? `${command} ${args.join(" ")}` : command;
101
+ try {
102
+ let result: SpawnSyncReturns<string | Buffer>;
103
+ if (options) {
104
+ result = childprocess.sync(command, args, options);
105
+ } else {
106
+ result = childprocess.sync(command, args);
107
+ }
108
+
109
+ return {
110
+ command: commandWithArgs,
111
+ isSuccessful: true,
112
+ data: result.output.join("")
113
+ };
114
+ } catch (error: unknown) {
115
+ // eslint-disable-next-line no-throw-literal -- throw the object causing the error.
116
+ throw {
117
+ command: commandWithArgs,
118
+ isSuccessful: false,
119
+ error
120
+ };
121
+ }
122
+ }
123
+
124
+ /**
125
+ * Handle any error.
126
+ *
127
+ * @param error - Any error.
128
+ */
129
+ handleError(error: unknown): void {
130
+ this._logger.error(LOGS.abortingInstallation, { prefix: LOGS.newLine });
131
+ if (!error) {
132
+ return;
133
+ }
134
+
135
+ const executionError = error as ExecutionResult;
136
+ if (executionError && executionError.command) {
137
+ this._logger.warning(format(LOGS.hasFailed, { command: executionError.command }), {
138
+ prefix: LOGS.tab,
139
+ postfix: LOGS.newLine
140
+ });
141
+ } else {
142
+ this._logger.error(LOGS.unexpectedError);
143
+ this._logger.error(error, { postfix: LOGS.newLine });
144
+ }
145
+ }
146
+
147
+ /**
148
+ * Remove the created Add-on.
149
+ *
150
+ * @param addOnDirectory - Directory of the Add-on.
151
+ * @param addOnName - Name of the Add-on.
152
+ */
153
+ removeAddOn(addOnDirectory?: string, addOnName?: string): void {
154
+ if (!addOnDirectory || !addOnName) {
155
+ return process.exit(0);
156
+ }
157
+
158
+ const knownGeneratedFiles = new Set<string>([
159
+ ".env",
160
+ ".prettierignore",
161
+ ".prettierrc.json",
162
+ "node_modules",
163
+ "package-lock.json",
164
+ "package.json",
165
+ "src",
166
+ "ssl"
167
+ ]);
168
+
169
+ const addOnDirectoryPath = path.join(addOnDirectory);
170
+ const currentFiles = fs.readdirSync(addOnDirectoryPath, { withFileTypes: true }).map(file => file.name);
171
+ let remainingFiles = currentFiles.length;
172
+ currentFiles.forEach(file => {
173
+ if (knownGeneratedFiles.has(file)) {
174
+ this._logger.information(format(LOGS.deletingGeneratedFileOrDirectory, { file }));
175
+ fs.removeSync(path.join(addOnDirectory, file));
176
+ remainingFiles--;
177
+ }
178
+ });
179
+
180
+ if (remainingFiles === 0) {
181
+ const rootDirectory = path.resolve(addOnDirectory, "..");
182
+ this._logger.information(format(LOGS.deletingAddOn, { addOnName, rootDirectory }));
183
+ process.chdir(rootDirectory);
184
+ fs.removeSync(addOnDirectoryPath);
185
+ }
186
+
187
+ this._logger.warning(LOGS.done);
188
+ }
189
+ }
190
+
191
+ const LOGS = {
192
+ newLine: "\n",
193
+ tab: " ",
194
+ abortingInstallation: "Aborting installation.",
195
+ hasFailed: "{command} has failed.",
196
+ unexpectedError: "Unexpected error. Please report it as a bug:",
197
+ deletingGeneratedFileOrDirectory: "Deleting generated file/directory {file} ...",
198
+ deletingAddOn: "Deleting {addOnName}/ from {rootDirectory}",
199
+ done: "Done."
200
+ };
@@ -0,0 +1,111 @@
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 { Chalk } from "chalk";
26
+ import chalk from "chalk";
27
+ import { injectable } from "inversify";
28
+ import type { LoggerOptions } from "../models/index.js";
29
+ import type { Logger } from "./Logger.js";
30
+
31
+ /**
32
+ * Console logger implementation class to handle logging of different levels.
33
+ */
34
+ @injectable()
35
+ export class ConsoleLogger implements Logger {
36
+ /**
37
+ * Log message.
38
+ * @param message - Message to log.
39
+ * @param options - Logger {@link LoggerOptions} options.
40
+ */
41
+ message(message: string, options?: LoggerOptions): void {
42
+ this._log(message, options);
43
+ }
44
+
45
+ /**
46
+ * Log information message.
47
+ * @param message - Message to log.
48
+ * @param options - Logger {@link LoggerOptions} options.
49
+ */
50
+ information(message: string, options?: LoggerOptions): void {
51
+ this._log(message, options, chalk.cyan.bold);
52
+ }
53
+
54
+ /**
55
+ * Log success message.
56
+ * @param message - Message to log.
57
+ * @param options - Logger {@link LoggerOptions} options.
58
+ */
59
+ success(message: string, options?: LoggerOptions): void {
60
+ this._log(message, options, chalk.green.bold);
61
+ }
62
+
63
+ /**
64
+ * Log warning message.
65
+ * @param message - Message to log.
66
+ * @param options - Logger {@link LoggerOptions} options.
67
+ */
68
+ warning(message: string, options?: LoggerOptions): void {
69
+ this._log(message, options, chalk.hex("#E59400").bold);
70
+ }
71
+
72
+ /**
73
+ * Log error message.
74
+ * @param message - Message to log.
75
+ * @param options - Logger {@link LoggerOptions} options.
76
+ */
77
+ error(message: unknown, options?: LoggerOptions): void {
78
+ this._log(message, options, chalk.red);
79
+ }
80
+
81
+ private _log(message: unknown, options?: LoggerOptions, color?: Chalk): void {
82
+ if (!this._isString(message)) {
83
+ if (options?.prefix) {
84
+ this._logWithColor(options.prefix, color);
85
+ }
86
+
87
+ this._logWithColor(message, color);
88
+
89
+ if (options?.postfix) {
90
+ this._logWithColor(options.postfix, color);
91
+ }
92
+ } else {
93
+ let messageToLog = options?.prefix ? `${options.prefix}${message}` : message;
94
+ messageToLog = options?.postfix ? `${messageToLog}${options?.postfix}` : messageToLog;
95
+
96
+ this._logWithColor(messageToLog, color);
97
+ }
98
+ }
99
+
100
+ private _isString(value: unknown) {
101
+ return typeof value === "string" || value instanceof String;
102
+ }
103
+
104
+ private _logWithColor(message: unknown, color?: Chalk) {
105
+ if (!color) {
106
+ console.log(message);
107
+ } else {
108
+ console.log(color(message));
109
+ }
110
+ }
111
+ }
@@ -0,0 +1,98 @@
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 fs from "fs-extra";
26
+ import path from "path";
27
+
28
+ /**
29
+ * Get JSON string representation of an item.
30
+ * @param item - Unknown input.
31
+ * @returns JSON string of item.
32
+ */
33
+ export function getJSONString(item: unknown): string {
34
+ return JSON.stringify(item, undefined, 4);
35
+ }
36
+
37
+ /**
38
+ * Check whether a string value is null, undefined, empty or whitespace.
39
+ * @param value - String input.
40
+ * @returns Boolean value representing whether the string value is null, undefined, empty or whitespace.
41
+ */
42
+ export function isNullOrWhiteSpace(value: string | null | undefined): boolean {
43
+ return !value || value.trim().length === 0;
44
+ }
45
+
46
+ /**
47
+ * Check whether a value is an object.
48
+ * @param value - Value to check.
49
+ * @returns Boolean value representing whether the value is an object.
50
+ */
51
+ export function isObject(value: unknown) {
52
+ return typeof value === "object" && value !== null;
53
+ }
54
+
55
+ /**
56
+ * Recursively traverse a directory and execute an action on the underlying files.
57
+ * @param directory - Directory to traverse.
58
+ * @param action - Action to execute on the files.
59
+ */
60
+ export function traverseDirectory(directory: string, action: (absolutePath: string) => unknown): void {
61
+ fs.readdirSync(directory, { withFileTypes: true }).forEach(file => {
62
+ const absolutePath = path.join(directory, file.name);
63
+ if (fs.lstatSync(absolutePath).isDirectory()) {
64
+ return traverseDirectory(absolutePath, action);
65
+ } else {
66
+ action(absolutePath);
67
+ }
68
+ });
69
+ }
70
+
71
+ /**
72
+ * Get Base URL.
73
+ * @param protocol - Protocol.
74
+ * @param host - Host (which is equivalent to Hostname:Port).
75
+ * @returns Base URL as string.
76
+ */
77
+ export function getBaseUrl(protocol: string, host: string): string {
78
+ return new URL(`${protocol}://${host}`).href;
79
+ }
80
+
81
+ /**
82
+ * Remove symbols like `\n`, `\r` and `\t` from a string.
83
+ * @param value - Value to remove symbols from.
84
+ * @returns Value with symbols removed.
85
+ */
86
+ export function removeSymbols(value: string): string {
87
+ return value.replace(/[\n\r\t]/g, "");
88
+ }
89
+
90
+ /**
91
+ * Check whether a path is of a file.
92
+ * @param path - Path to check.
93
+ * @returns Boolean value representing whether the path is of a file.
94
+ */
95
+ export function isFile(path: string): boolean {
96
+ // Check if the path exists and the path is of a file, not a directory.
97
+ return fs.existsSync(path) && fs.lstatSync(path).isFile();
98
+ }
@@ -0,0 +1,70 @@
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 { LoggerOptions } from "../models/index.js";
26
+
27
+ /**
28
+ * Logger interface to handle logging of different levels.
29
+ */
30
+ export interface Logger {
31
+ /**
32
+ * Log message.
33
+ *
34
+ * @param message - Message to log.
35
+ * @param options - Logger {@link LoggerOptions} options.
36
+ */
37
+ message(message: string, options?: LoggerOptions): void;
38
+
39
+ /**
40
+ * Log information message.
41
+ *
42
+ * @param message - Message to log.
43
+ * @param options - Logger {@link LoggerOptions} options.
44
+ */
45
+ information(message: string, options?: LoggerOptions): void;
46
+
47
+ /**
48
+ * Log success message.
49
+ *
50
+ * @param message - Message to log.
51
+ * @param options - Logger {@link LoggerOptions} options.
52
+ */
53
+ success(message: string, options?: LoggerOptions): void;
54
+
55
+ /**
56
+ * Log warning message.
57
+ *
58
+ * @param message - Message to log.
59
+ * @param options - Logger {@link LoggerOptions} options.
60
+ */
61
+ warning(message: string, options?: LoggerOptions): void;
62
+
63
+ /**
64
+ * Log error message.
65
+ *
66
+ * @param message - Message to log.
67
+ * @param options - Logger {@link LoggerOptions} options.
68
+ */
69
+ error(message: unknown, options?: LoggerOptions): void;
70
+ }
@@ -0,0 +1,43 @@
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 { PreferenceJson } from "../models/index.js";
26
+
27
+ /**
28
+ * Preferences interface for managing preferences.
29
+ */
30
+ export interface Preferences {
31
+ /**
32
+ * Get the CCWeb Add-on CLI related user preferences.
33
+ * @param fromCache - (Optional) Whether to return the cached user preference.
34
+ * @returns User preference represented as {@link PreferenceJson}.
35
+ */
36
+ get(fromCache?: boolean): PreferenceJson;
37
+
38
+ /**
39
+ * Set the CCWeb Add-on CLI related user preferences.
40
+ * @param preferenceJson - {@link PreferenceJson} reference.
41
+ */
42
+ set(preferenceJson: PreferenceJson): void;
43
+ }
@@ -0,0 +1,66 @@
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 { ExecSyncOptions } from "child_process";
26
+ import type { ExecutionResult } from "../models/index.js";
27
+
28
+ /**
29
+ * Process interface for managing execution of commands.
30
+ */
31
+ export interface Process {
32
+ /**
33
+ * Execute a command asynchronously.
34
+ *
35
+ * @param command - Command to execute.
36
+ * @param args - Command arguments.
37
+ * @param options - Execution {@link ExecSyncOptions} options.
38
+ * @returns Promise of {@link ExecutionResult}.
39
+ */
40
+ execute(command: string, args: string[], options?: ExecSyncOptions): Promise<ExecutionResult>;
41
+
42
+ /**
43
+ * Execute a command synchronously.
44
+ *
45
+ * @param command - Command to execute.
46
+ * @param args - Command arguments.
47
+ * @param options - Execution {@link ExecSyncOptions} options.
48
+ * @returns {@link ExecutionResult}.
49
+ */
50
+ executeSync(command: string, args: string[], options?: ExecSyncOptions): ExecutionResult;
51
+
52
+ /**
53
+ * Handle any error.
54
+ *
55
+ * @param error - Any error.
56
+ */
57
+ handleError(error: unknown): void;
58
+
59
+ /**
60
+ * Remove the created Add-on.
61
+ *
62
+ * @param addOnDirectory - Directory of the Add-on.
63
+ * @param addOnName - Name of the Add-on.
64
+ */
65
+ removeAddOn(addOnDirectory?: string, addOnName?: string): void;
66
+ }
@@ -0,0 +1,55 @@
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 process from "process";
26
+ import { IContainer, ITypes } from "../config/index.js";
27
+ import { type Logger } from "./Logger.js";
28
+
29
+ /**
30
+ * Uncaught exception handler.
31
+ */
32
+ export class UncaughtExceptionHandler {
33
+ /**
34
+ * Register handler for catching any uncaught exception.
35
+ * @param programName - Program from where the exception could be thrown.
36
+ */
37
+ static registerExceptionHandler(programName: string) {
38
+ process.on("uncaughtException", error => this.handleUncaughtException(programName, error));
39
+ }
40
+
41
+ /**
42
+ * Handle any uncaught exception thrown during execution.
43
+ * @param programName - Program from where the exception could be thrown.
44
+ * @param error - Uncaught exception.
45
+ */
46
+ static handleUncaughtException(programName: string, error: Error): void {
47
+ const logger = IContainer.get<Logger>(ITypes.Logger);
48
+ logger.error(`${programName} failed. Reason: ${error.message}`, { postfix: LOGS.newLine });
49
+ return process.exit(0);
50
+ }
51
+ }
52
+
53
+ const LOGS = {
54
+ newLine: "\n"
55
+ };
@@ -0,0 +1,32 @@
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
+ export * from "./CLIPreferences.js";
26
+ export * from "./CLIProcess.js";
27
+ export * from "./ConsoleLogger.js";
28
+ export * from "./Extensions.js";
29
+ export * from "./Logger.js";
30
+ export * from "./Preferences.js";
31
+ export * from "./Process.js";
32
+ export * from "./UncaughtExceptionHandler.js";