@suitegeezus/suitecloud-cli 3.1.4

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 (157) hide show
  1. package/CONTRIBUTING.md +7 -0
  2. package/DELTA.md +235 -0
  3. package/README.md +107 -0
  4. package/docs/Command.md +299 -0
  5. package/messages.json +317 -0
  6. package/package.json +51 -0
  7. package/postinstall.js +8 -0
  8. package/resources/FUTC-LICENSE.txt +115 -0
  9. package/src/ApplicationConstants.js +87 -0
  10. package/src/CLI.js +202 -0
  11. package/src/CLIException.js +21 -0
  12. package/src/ExecutionEnvironmentContext.js +39 -0
  13. package/src/SdkExecutionContext.js +90 -0
  14. package/src/SdkExecutor.js +160 -0
  15. package/src/commands/Command.js +158 -0
  16. package/src/commands/account/manageauth/ManageAccountAction.js +126 -0
  17. package/src/commands/account/manageauth/ManageAccountCommand.js +20 -0
  18. package/src/commands/account/manageauth/ManageAccountInputHandler.js +215 -0
  19. package/src/commands/account/manageauth/ManageAccountOutputHandler.js +30 -0
  20. package/src/commands/account/setup/SetupAction.js +39 -0
  21. package/src/commands/account/setup/SetupCommand.js +21 -0
  22. package/src/commands/account/setup/SetupInputHandler.js +169 -0
  23. package/src/commands/account/setup/SetupOutputHandler.js +65 -0
  24. package/src/commands/account/setupci/AccountSetupCiAction.js +58 -0
  25. package/src/commands/account/setupci/AccountSetupCiCommand.js +20 -0
  26. package/src/commands/account/setupci/AccountSetupCiConstants.js +21 -0
  27. package/src/commands/account/setupci/AccountSetupCiOutputHandler.js +40 -0
  28. package/src/commands/account/setupci/AccountSetupCiValidation.js +100 -0
  29. package/src/commands/base/BaseAction.js +37 -0
  30. package/src/commands/base/BaseInputHandler.js +24 -0
  31. package/src/commands/base/BaseOutputHandler.js +30 -0
  32. package/src/commands/custom/hello/Action.js +58 -0
  33. package/src/commands/custom/hello/Command.js +20 -0
  34. package/src/commands/custom/hello/Handler.js +26 -0
  35. package/src/commands/custom/hello/README.md +78 -0
  36. package/src/commands/custom/hook/Action.js +28 -0
  37. package/src/commands/custom/hook/Command.js +22 -0
  38. package/src/commands/custom/hook/InputHandler.js +8 -0
  39. package/src/commands/custom/hook/OutputHandler.js +8 -0
  40. package/src/commands/custom/hook/README.md +32 -0
  41. package/src/commands/file/create/CreateFileAction.js +89 -0
  42. package/src/commands/file/create/CreateFileCommand.js +20 -0
  43. package/src/commands/file/create/CreateFileInputHandler.js +175 -0
  44. package/src/commands/file/create/CreateFileOutputHandler.js +22 -0
  45. package/src/commands/file/import/ImportFilesAction.js +112 -0
  46. package/src/commands/file/import/ImportFilesCommand.js +22 -0
  47. package/src/commands/file/import/ImportFilesInputHandler.js +130 -0
  48. package/src/commands/file/import/ImportFilesOutputHandler.js +53 -0
  49. package/src/commands/file/list/ListFilesAction.js +55 -0
  50. package/src/commands/file/list/ListFilesCommand.js +20 -0
  51. package/src/commands/file/list/ListFilesInputHandler.js +55 -0
  52. package/src/commands/file/list/ListFilesOutputHandler.js +24 -0
  53. package/src/commands/file/upload/UploadFilesAction.js +67 -0
  54. package/src/commands/file/upload/UploadFilesCommand.js +20 -0
  55. package/src/commands/file/upload/UploadFilesInputHandler.js +125 -0
  56. package/src/commands/file/upload/UploadFilesOutputHandler.js +49 -0
  57. package/src/commands/object/create/CreateObjectAction.js +33 -0
  58. package/src/commands/object/create/CreateObjectCommand.js +19 -0
  59. package/src/commands/object/create/CreateObjectInputHandler.js +82 -0
  60. package/src/commands/object/import/ImportObjectsAction.js +225 -0
  61. package/src/commands/object/import/ImportObjectsCommand.js +20 -0
  62. package/src/commands/object/import/ImportObjectsInputHandler.js +310 -0
  63. package/src/commands/object/import/ImportObjectsOutputHandler.js +114 -0
  64. package/src/commands/object/list/ListObjectsAction.js +62 -0
  65. package/src/commands/object/list/ListObjectsCommand.js +20 -0
  66. package/src/commands/object/list/ListObjectsInputHandler.js +148 -0
  67. package/src/commands/object/list/ListObjectsOutputHandler.js +29 -0
  68. package/src/commands/object/update/UpdateAction.js +138 -0
  69. package/src/commands/object/update/UpdateCommand.js +20 -0
  70. package/src/commands/object/update/UpdateInputHandler.js +170 -0
  71. package/src/commands/object/update/UpdateOutputHandler.js +61 -0
  72. package/src/commands/project/adddependencies/AddDependenciesAction.js +55 -0
  73. package/src/commands/project/adddependencies/AddDependenciesCommand.js +19 -0
  74. package/src/commands/project/adddependencies/AddDependenciesOutputHandler.js +114 -0
  75. package/src/commands/project/create/CreateProjectAction.js +370 -0
  76. package/src/commands/project/create/CreateProjectCommand.js +20 -0
  77. package/src/commands/project/create/CreateProjectInputHandler.js +169 -0
  78. package/src/commands/project/create/CreateProjectOutputHandler.js +36 -0
  79. package/src/commands/project/deploy/DeployAction.js +161 -0
  80. package/src/commands/project/deploy/DeployCommand.js +20 -0
  81. package/src/commands/project/deploy/DeployInputHandler.js +100 -0
  82. package/src/commands/project/deploy/DeployOutputHandler.js +49 -0
  83. package/src/commands/project/package/PackageAction.js +59 -0
  84. package/src/commands/project/package/PackageCommand.js +18 -0
  85. package/src/commands/project/package/PackageOutputHandler.js +18 -0
  86. package/src/commands/project/validate/ValidateAction.js +106 -0
  87. package/src/commands/project/validate/ValidateCommand.js +20 -0
  88. package/src/commands/project/validate/ValidateInputHandler.js +92 -0
  89. package/src/commands/project/validate/ValidateOutputHandler.js +74 -0
  90. package/src/core/CommandActionExecutor.js +347 -0
  91. package/src/core/CommandAuthentication.js +13 -0
  92. package/src/core/CommandOptionsValidator.js +42 -0
  93. package/src/core/CommandRegistrationService.js +130 -0
  94. package/src/core/CommandsMetadataService.js +104 -0
  95. package/src/core/extensibility/CLIConfigurationService.js +192 -0
  96. package/src/core/extensibility/CommandUserExtension.js +64 -0
  97. package/src/core/sdksetup/SdkDownloadService.js +109 -0
  98. package/src/core/sdksetup/SdkLicense.js +39 -0
  99. package/src/core/sdksetup/SdkProperties.js +51 -0
  100. package/src/loggers/ConsoleLogger.js +32 -0
  101. package/src/loggers/LoggerFontFormatter.mjs +17 -0
  102. package/src/loggers/LoggerOsConstants.js +12 -0
  103. package/src/loggers/NodeConsoleLogger.js +47 -0
  104. package/src/metadata/CommandGenerators.json +92 -0
  105. package/src/metadata/NodeCommandsMetadata.json +139 -0
  106. package/src/metadata/ObjectTypesMetadata.js +615 -0
  107. package/src/metadata/SdkCommandsMetadata.json +846 -0
  108. package/src/metadata/SdkCommandsMetadataPatch.json +130 -0
  109. package/src/metadata/SuiteScriptModulesMetadata.js +152 -0
  110. package/src/metadata/SuiteScriptTypesMetadata.js +64 -0
  111. package/src/services/AccountFileCabinetService.js +86 -0
  112. package/src/services/EnvironmentInformationService.js +31 -0
  113. package/src/services/ExecutionContextService.js +108 -0
  114. package/src/services/FileCabinetService.js +65 -0
  115. package/src/services/FileSystemService.js +245 -0
  116. package/src/services/NodeTranslationService.js +22 -0
  117. package/src/services/NpmInstallRunner.js +33 -0
  118. package/src/services/ProjectInfoService.js +209 -0
  119. package/src/services/SuiteCloudAuthProxyService.js +469 -0
  120. package/src/services/TranslationKeys.js +506 -0
  121. package/src/services/TranslationService.js +30 -0
  122. package/src/services/actionresult/ActionResult.js +129 -0
  123. package/src/services/actionresult/AuthenticateActionResult.js +85 -0
  124. package/src/services/actionresult/CreateProjectActionResult.js +100 -0
  125. package/src/services/actionresult/DeployActionResult.js +69 -0
  126. package/src/services/actionresult/HelloActionResult.js +13 -0
  127. package/src/services/actionresult/ManageAccountActionResult.js +70 -0
  128. package/src/services/settings/CLISettings.js +46 -0
  129. package/src/services/settings/CLISettingsService.js +132 -0
  130. package/src/suitecloud.js +33 -0
  131. package/src/templates/TemplateKeys.js +25 -0
  132. package/src/templates/objects/commerceextension.xml +9 -0
  133. package/src/templates/projectconfigs/default_gitignore.template +47 -0
  134. package/src/templates/projectconfigs/sdf.config.js +4 -0
  135. package/src/templates/projectconfigs/suitecloud.config.js +4 -0
  136. package/src/templates/scripts/blankscript.js +3 -0
  137. package/src/templates/unittest/jest.config.js.template +7 -0
  138. package/src/templates/unittest/jsconfig.json.template +5 -0
  139. package/src/templates/unittest/package.json.template +12 -0
  140. package/src/templates/unittest/sample-test.js.template +37 -0
  141. package/src/templates/unittest/suitecloud.config.js.template +15 -0
  142. package/src/ui/CliSpinner.js +34 -0
  143. package/src/utils/AccountCredentialsFormatter.js +62 -0
  144. package/src/utils/AccountSpecificValuesUtils.js +55 -0
  145. package/src/utils/ActionResultUtils.js +47 -0
  146. package/src/utils/ApplyInstallationPreferencesUtils.js +41 -0
  147. package/src/utils/AuthenticationUtils.js +262 -0
  148. package/src/utils/CommandUtils.js +50 -0
  149. package/src/utils/CryptoUtils.js +41 -0
  150. package/src/utils/ExceptionUtils.js +33 -0
  151. package/src/utils/FileUtils.js +43 -0
  152. package/src/utils/SdkOperationResult.js +68 -0
  153. package/src/utils/SdkOperationResultUtils.js +20 -0
  154. package/src/utils/ValidationErrorsFormatter.js +23 -0
  155. package/src/utils/http/HttpConstants.js +39 -0
  156. package/src/utils/http/ProxyAgent.js +110 -0
  157. package/src/validation/InteractiveAnswersValidator.js +205 -0
@@ -0,0 +1,85 @@
1
+ /*
2
+ ** Copyright (c) 2024 Oracle and/or its affiliates. All rights reserved.
3
+ ** Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4
+ */
5
+ 'use strict';
6
+ const assert = require('assert');
7
+ const { ActionResult, ActionResultBuilder, STATUS } = require('./ActionResult');
8
+
9
+ class AuthenticateActionResult extends ActionResult {
10
+ constructor(parameters) {
11
+ super(parameters);
12
+ this._mode = parameters.mode;
13
+ this._authId = parameters.authId;
14
+ this._accountInfo = parameters.accountInfo;
15
+ }
16
+
17
+ validateParameters(parameters) {
18
+ assert(parameters);
19
+ assert(parameters.status, 'status is required when creating an ActionResult object.');
20
+ if (parameters.status === STATUS.SUCCESS) {
21
+ assert(parameters.mode, 'mode is required when ActionResult is a success.');
22
+ assert(parameters.authId, 'authId is required when ActionResult is a success.');
23
+ assert(parameters.accountInfo, 'accountInfo is required when ActionResult is a success.');
24
+ } else {
25
+ assert(parameters.errorMessages, 'errorMessages is required when ActionResult is an error.');
26
+ assert(Array.isArray(parameters.errorMessages), 'errorMessages argument must be an array');
27
+ }
28
+ }
29
+
30
+ get mode() {
31
+ return this._mode;
32
+ }
33
+
34
+ get authId() {
35
+ return this._authId;
36
+ }
37
+
38
+ get accountInfo() {
39
+ return this._accountInfo;
40
+ }
41
+
42
+ static get Builder() {
43
+ return new AuthenticateActionResultBuilder();
44
+ }
45
+ }
46
+
47
+ class AuthenticateActionResultBuilder extends ActionResultBuilder {
48
+ constructor() {
49
+ super();
50
+ }
51
+
52
+ success() {
53
+ this.status = STATUS.SUCCESS;
54
+ return this;
55
+ }
56
+
57
+ withMode(mode) {
58
+ this.mode = mode;
59
+ return this;
60
+ }
61
+
62
+ withAuthId(authId) {
63
+ this.authId = authId;
64
+ return this;
65
+ }
66
+
67
+ withAccountInfo(accountInfo) {
68
+ this.accountInfo = accountInfo;
69
+ return this;
70
+ }
71
+
72
+ build() {
73
+ return new AuthenticateActionResult({
74
+ status: this.status,
75
+ ...(this.errorMessages && { errorMessages: this.errorMessages }),
76
+ ...(this.mode && { mode: this.mode }),
77
+ ...(this.authId && { authId: this.authId }),
78
+ ...(this.accountInfo && { accountInfo: this.accountInfo }),
79
+ ...(this.projectFolder && { projectFolder: this.projectFolder }),
80
+ ...(this.commandParameters && { commandParameters: this.commandParameters }),
81
+ });
82
+ }
83
+ }
84
+
85
+ module.exports = AuthenticateActionResult;
@@ -0,0 +1,100 @@
1
+ /*
2
+ ** Copyright (c) 2024 Oracle and/or its affiliates. All rights reserved.
3
+ ** Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4
+ */
5
+ 'use strict';
6
+ const assert = require('assert');
7
+ const { ActionResult, ActionResultBuilder } = require('./ActionResult');
8
+
9
+ class CreateProjectActionResult extends ActionResult {
10
+ constructor(parameters) {
11
+ super(parameters);
12
+ this._projectType = parameters.projectType;
13
+ this._projectName = parameters.projectName;
14
+ this._projectDirectory = parameters.projectDirectory;
15
+ this._includeUnitTesting = parameters.includeUnitTesting;
16
+ this._npmPackageInitialized = parameters.npmPackageInitialized;
17
+ }
18
+
19
+ validateParameters(parameters) {
20
+ super.validateParameters(parameters);
21
+ if (this.isSuccess()) {
22
+ assert(parameters.projectDirectory, 'projectDirectory is required when ActionResult is a success.');
23
+ assert(parameters.projectType, 'projectType is required when ActionResult is a success.');
24
+ }
25
+ }
26
+
27
+ get projectType() {
28
+ return this._projectType;
29
+ }
30
+
31
+ get projectName() {
32
+ return this._projectName;
33
+ }
34
+
35
+ get projectDirectory() {
36
+ return this._projectDirectory;
37
+ }
38
+
39
+ get includeUnitTesting() {
40
+ return this._includeUnitTesting;
41
+ }
42
+
43
+ get npmPackageInitialized() {
44
+ return this._npmPackageInitialized;
45
+ }
46
+
47
+ static get Builder() {
48
+ return new CreateProjectActionResultBuilder();
49
+ }
50
+ }
51
+
52
+ class CreateProjectActionResultBuilder extends ActionResultBuilder {
53
+ constructor() {
54
+ super();
55
+ }
56
+
57
+ withProjectType(projectType) {
58
+ this.projectType = projectType;
59
+ return this;
60
+ }
61
+
62
+ withProjectName(projectName) {
63
+ this.projectName = projectName;
64
+ return this;
65
+ }
66
+
67
+ withProjectDirectory(projectDirectory) {
68
+ this.projectDirectory = projectDirectory;
69
+ return this;
70
+ }
71
+
72
+ withUnitTesting(includeUnitTesting) {
73
+ this.includeUnitTesting = includeUnitTesting;
74
+ return this;
75
+ }
76
+
77
+ withNpmPackageInitialized(npmPackageInitialized) {
78
+ this.npmPackageInitialized = npmPackageInitialized;
79
+ return this;
80
+ }
81
+
82
+ build() {
83
+ return new CreateProjectActionResult({
84
+ status: this.status,
85
+ ...(this.data && { data: this.data }),
86
+ ...(this.resultMessage && { resultMessage: this.resultMessage }),
87
+ ...(this.errorMessages && { errorMessages: this.errorMessages }),
88
+ ...(this.projectType && { projectType: this.projectType }),
89
+ ...(this.projectName && { projectName: this.projectName }),
90
+ ...(this.projectDirectory && { projectDirectory: this.projectDirectory }),
91
+ ...(this.includeUnitTesting && { includeUnitTesting: this.includeUnitTesting }),
92
+ ...(this.npmPackageInitialized && { npmPackageInitialized: this.npmPackageInitialized }),
93
+ ...(this.projectFolder && { projectFolder: this.projectFolder }),
94
+ ...(this.commandParameters && { commandParameters: this.commandParameters }),
95
+ ...(this.commandFlags && { commandFlags: this.commandFlags }),
96
+ });
97
+ }
98
+ }
99
+
100
+ module.exports = CreateProjectActionResult;
@@ -0,0 +1,69 @@
1
+ /*
2
+ ** Copyright (c) 2024 Oracle and/or its affiliates. All rights reserved.
3
+ ** Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4
+ */
5
+ 'use strict';
6
+ const { ActionResult, ActionResultBuilder } = require('./ActionResult');
7
+
8
+ class DeployActionResult extends ActionResult {
9
+ constructor(parameters) {
10
+ super(parameters);
11
+ this._isServerValidation = !!parameters.isServerValidation;
12
+ this._appliedInstallationPreferences = !!parameters.appliedInstallationPreferences;
13
+ this._projectType = parameters.projectType;
14
+ }
15
+
16
+ get isServerValidation() {
17
+ return this._isServerValidation;
18
+ }
19
+
20
+ get appliedInstallationPreferences() {
21
+ return this._appliedInstallationPreferences;
22
+ }
23
+
24
+ get projectType() {
25
+ return this._projectType;
26
+ }
27
+
28
+ static get Builder() {
29
+ return new DeployActionResultBuilder();
30
+ }
31
+ }
32
+
33
+ class DeployActionResultBuilder extends ActionResultBuilder {
34
+ constructor() {
35
+ super();
36
+ }
37
+
38
+ withServerValidation(isServerValidation) {
39
+ this.isServerValidation = isServerValidation;
40
+ return this;
41
+ }
42
+
43
+ withAppliedInstallationPreferences(appliedInstallationPreferences) {
44
+ this.appliedInstallationPreferences = appliedInstallationPreferences;
45
+ return this;
46
+ }
47
+
48
+ withProjectType(projectType) {
49
+ this.projectType = projectType;
50
+ return this;
51
+ }
52
+
53
+ build() {
54
+ return new DeployActionResult({
55
+ status: this.status,
56
+ ...(this.data && { data: this.data }),
57
+ ...(this.resultMessage && { resultMessage: this.resultMessage }),
58
+ ...(this.errorMessages && { errorMessages: this.errorMessages }),
59
+ ...(this.isServerValidation && { isServerValidation: this.isServerValidation }),
60
+ ...(this.appliedInstallationPreferences && { appliedInstallationPreferences: this.appliedInstallationPreferences }),
61
+ ...(this.projectType && { projectType: this.projectType }),
62
+ ...(this.projectFolder && { projectFolder: this.projectFolder }),
63
+ ...(this.commandParameters && { commandParameters: this.commandParameters }),
64
+ ...(this.commandFlags && { commandFlags: this.commandFlags }),
65
+ });
66
+ }
67
+ }
68
+
69
+ module.exports = DeployActionResult;
@@ -0,0 +1,13 @@
1
+
2
+ const { ActionResult,
3
+ ActionResultBuilder,
4
+ STATUS
5
+ } = require('./ActionResult');
6
+
7
+ class HelloActionResult extends ActionResult {
8
+ constructor(parameters) {
9
+ super(parameters);
10
+ }
11
+ }
12
+
13
+ module.exports.HelloActionResult = HelloActionResult;
@@ -0,0 +1,70 @@
1
+ /*
2
+ ** Copyright (c) 2024 Oracle and/or its affiliates. All rights reserved.
3
+ ** Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4
+ */
5
+ 'use strict';
6
+ const assert = require('assert');
7
+ const { ActionResult, ActionResultBuilder, STATUS } = require('./ActionResult');
8
+
9
+ const MANAGE_ACTION = {
10
+ LIST: 'list',
11
+ EXIT: 'exit',
12
+ INFO: 'info',
13
+ RENAME: 'rename',
14
+ REMOVE: 'remove',
15
+ REVOKE: 'revoke',
16
+ UNKNOWN: 'unknown',
17
+ };
18
+
19
+ class ManageAccountActionResult extends ActionResult {
20
+ constructor(parameters) {
21
+ super(parameters);
22
+ this._actionExecuted = parameters.actionExecuted;
23
+ }
24
+
25
+ validateParameters(parameters) {
26
+ assert(parameters);
27
+ assert(parameters.status, 'status is required when creating an ActionResult object.');
28
+ if (parameters.status === STATUS.SUCCESS) {
29
+ assert(parameters.actionExecuted);
30
+ }
31
+ if (parameters.status === STATUS.ERROR) {
32
+ assert(parameters.errorMessages, 'errorMessages is required when ActionResult is an error.');
33
+ assert(Array.isArray(parameters.errorMessages), 'errorMessages argument must be an array');
34
+ }
35
+ }
36
+
37
+ get actionExecuted() {
38
+ return this._actionExecuted;
39
+ }
40
+
41
+ static get Builder() {
42
+ return new ManageAccountActionResultBuilder();
43
+ }
44
+ }
45
+
46
+ class ManageAccountActionResultBuilder extends ActionResultBuilder {
47
+ constructor() {
48
+ super();
49
+ }
50
+
51
+ withExecutedAction(actionExecuted) {
52
+ this.actionExecuted = actionExecuted;
53
+ return this;
54
+ }
55
+
56
+ build() {
57
+ return new ManageAccountActionResult({
58
+ status: this.status,
59
+ ...(this.data && { data: this.data }),
60
+ ...(this.resultMessage && { resultMessage: this.resultMessage }),
61
+ ...(this.errorMessages && { errorMessages: this.errorMessages }),
62
+ ...(this.actionExecuted && { actionExecuted: this.actionExecuted }),
63
+ ...(this.commandParameters && { commandParameters: this.commandParameters }),
64
+ });
65
+ }
66
+ }
67
+
68
+ module.exports.ManageAccountActionResult = ManageAccountActionResult;
69
+ module.exports.ManageAccountActionResultBuilder = ManageAccountActionResultBuilder;
70
+ module.exports.MANAGE_ACTION = MANAGE_ACTION;
@@ -0,0 +1,46 @@
1
+ /*
2
+ ** Copyright (c) 2024 Oracle and/or its affiliates. All rights reserved.
3
+ ** Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4
+ */
5
+ 'use strict';
6
+
7
+ const DEFAULT_CLI_SETTINGS = {
8
+ isJavaVersionValid: false,
9
+ }
10
+
11
+ module.exports = class CLISettings {
12
+ // should not be directly used, use static fromJson(json) method
13
+ constructor(options) {
14
+ this._isJavaVersionValid = options.isJavaVersionValid ? options.isJavaVersionValid : DEFAULT_CLI_SETTINGS.isJavaVersionValid;
15
+ // we only accept an object as a value for vmOptions
16
+ if (options.hasOwnProperty("vmOptions")) {
17
+ if (options.vmOptions !== null && typeof options.vmOptions === 'object') {
18
+ this._vmOptions = options.vmOptions;
19
+ } else {
20
+ this._vmOptions = {};
21
+ }
22
+ }
23
+ }
24
+
25
+ get isJavaVersionValid() {
26
+ return this._isJavaVersionValid;
27
+ }
28
+
29
+ get vmOptions() {
30
+ return this._vmOptions;
31
+ }
32
+
33
+ toJSON() {
34
+ return {
35
+ isJavaVersionValid: this._isJavaVersionValid,
36
+ ...(this._vmOptions && { vmOptions: this._vmOptions }),
37
+ };
38
+ }
39
+
40
+ static fromJson(json) {
41
+ return new CLISettings({
42
+ isJavaVersionValid: json.isJavaVersionValid,
43
+ ...(json.hasOwnProperty("vmOptions") && { vmOptions: json.vmOptions })
44
+ });
45
+ }
46
+ };
@@ -0,0 +1,132 @@
1
+ /*
2
+ ** Copyright (c) 2024 Oracle and/or its affiliates. All rights reserved.
3
+ ** Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4
+ */
5
+ 'use strict';
6
+
7
+ const FileSystemService = require('../FileSystemService');
8
+ const FileUtils = require('../../utils/FileUtils');
9
+ const CLISettings = require('./CLISettings');
10
+ const path = require('path');
11
+ const NodeTranslationService = require('../NodeTranslationService');
12
+ const {
13
+ ERRORS: { SDK_SETTINGS_FILE },
14
+ } = require('../TranslationKeys');
15
+
16
+ const HOME_PATH = require('os').homedir();
17
+ const { FILES, FOLDERS } = require('../../ApplicationConstants');
18
+
19
+ const SDK_SETTINGS_FILEPATH = path.join(HOME_PATH, FOLDERS.SUITECLOUD_SDK, FILES.SDK_SETTINGS);
20
+
21
+ const CLI_SETTINGS_PROPERTIES_KEYS = ['isJavaVersionValid'];
22
+ const DEFAULT_CLI_SETTINGS = CLISettings.fromJson({
23
+ isJavaVersionValid: false,
24
+ });
25
+
26
+ const VM_OPTION_VALIDATION_ERROR_NAME = 'VmOptionValidationError';
27
+ const SYNTAX_ERROR_NAME = 'SyntaxError';
28
+ class VmOptionValidationError extends Error {
29
+ constructor(message) {
30
+ super(message);
31
+ this.name = VM_OPTION_VALIDATION_ERROR_NAME;
32
+ }
33
+ }
34
+
35
+ let CACHED_CLI_SETTINGS;
36
+
37
+ module.exports = class CLISettingsService {
38
+ constructor() {
39
+ this._fileSystemService = new FileSystemService();
40
+ }
41
+
42
+ _saveSettings(cliSettings) {
43
+ this._fileSystemService.createFolder(HOME_PATH, FOLDERS.SUITECLOUD_SDK);
44
+ FileUtils.create(SDK_SETTINGS_FILEPATH, cliSettings);
45
+ }
46
+
47
+ _getSettings() {
48
+ if (CACHED_CLI_SETTINGS) {
49
+ return CACHED_CLI_SETTINGS;
50
+ }
51
+ if (FileUtils.exists(SDK_SETTINGS_FILEPATH)) {
52
+ try {
53
+ const cliSettingsJson = FileUtils.readAsJson(SDK_SETTINGS_FILEPATH);
54
+ CACHED_CLI_SETTINGS = CLISettings.fromJson(cliSettingsJson);
55
+
56
+ // check if the settings file has the expected properties
57
+ if (!this._settingsFileHasExpectedProperties(cliSettingsJson) || this._settingsFileHasVmOptionsNotObjectType(cliSettingsJson)) {
58
+ // regenerate the file with the missing properties default values
59
+ this._saveSettings(CACHED_CLI_SETTINGS);
60
+ }
61
+ this._validateVmOptions(CACHED_CLI_SETTINGS.vmOptions);
62
+ return CACHED_CLI_SETTINGS;
63
+ } catch (error) {
64
+ if (error && error.constructor && error.constructor.name) {
65
+ if (error.constructor.name === SYNTAX_ERROR_NAME) {
66
+ throw NodeTranslationService.getMessage(SDK_SETTINGS_FILE.WRONG_JSON_SYNTAX, SDK_SETTINGS_FILEPATH, error);
67
+ }
68
+ if (error.constructor.name === VM_OPTION_VALIDATION_ERROR_NAME) {
69
+ throw NodeTranslationService.getMessage(SDK_SETTINGS_FILE.INVALID_CUSTOM_VM_OPTION, SDK_SETTINGS_FILEPATH, error);
70
+ }
71
+ }
72
+ throw NodeTranslationService.getMessage(
73
+ SDK_SETTINGS_FILE.GENERIC_PROBLEM,
74
+ SDK_SETTINGS_FILEPATH,
75
+ error
76
+ );
77
+ }
78
+ }
79
+ CACHED_CLI_SETTINGS = DEFAULT_CLI_SETTINGS;
80
+ return DEFAULT_CLI_SETTINGS;
81
+ }
82
+
83
+ isJavaVersionValid() {
84
+ return this._getSettings().isJavaVersionValid === true;
85
+ }
86
+
87
+ setJavaVersionValid(value) {
88
+ const newSettings = this._getSettings().toJSON();
89
+ if (newSettings.isJavaVersionValid === value) {
90
+ return;
91
+ }
92
+ newSettings.isJavaVersionValid = value;
93
+ CACHED_CLI_SETTINGS = CLISettings.fromJson(newSettings);
94
+ this._saveSettings(CACHED_CLI_SETTINGS);
95
+ }
96
+
97
+ getCustomVmOptions() {
98
+ return this._getSettings().vmOptions;
99
+ }
100
+
101
+ _settingsFileHasExpectedProperties(settingsFromFile) {
102
+ return CLI_SETTINGS_PROPERTIES_KEYS.every((key) => settingsFromFile.hasOwnProperty(key));
103
+ }
104
+
105
+ _settingsFileHasVmOptionsNotObjectType(settingsFromFile) {
106
+ if (!settingsFromFile.hasOwnProperty('vmOptions')) {
107
+ return false;
108
+ }
109
+
110
+ if (settingsFromFile.vmOptions !== null && typeof settingsFromFile.vmOptions === 'object') {
111
+ return false;
112
+ }
113
+
114
+ return true;
115
+ }
116
+
117
+ _validateVmOptions(vmOptions) {
118
+ if (vmOptions === null || vmOptions === undefined) {
119
+ return;
120
+ }
121
+
122
+ for (const [key, value] of Object.entries(vmOptions)) {
123
+ // All vmOptions should be named '-Dx' and have at least another character
124
+ if (!key.startsWith('-D') || key.lenght < 3) {
125
+ throw new VmOptionValidationError(`vmOptions keys must start with '-D', and contain at least three characters.`);
126
+ }
127
+ if (typeof value !== 'string') {
128
+ throw new VmOptionValidationError(`vmOptions keys only support string values.`);
129
+ }
130
+ }
131
+ }
132
+ };
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/env node
2
+ /*
3
+ ** Copyright (c) 2024 Oracle and/or its affiliates. All rights reserved.
4
+ ** Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
5
+ */
6
+ 'use strict';
7
+
8
+ const CLI = require('./CLI');
9
+ const CommandsMetadataService = require('./core/CommandsMetadataService');
10
+ const CommandActionExecutor = require('./core/CommandActionExecutor');
11
+ const CommandRegistrationService = require('./core/CommandRegistrationService');
12
+ const CommandOptionsValidator = require('./core/CommandOptionsValidator');
13
+ const CLIConfigurationService = require('./core/extensibility/CLIConfigurationService');
14
+ const sdkPath = require('./core/sdksetup/SdkProperties').getSdkPath();
15
+ const NodeConsoleLogger = require('./loggers/NodeConsoleLogger');
16
+
17
+ const executionPath = process.cwd();
18
+ const commandsMetadataServiceSingleton = new CommandsMetadataService();
19
+
20
+ const cliInstance = new CLI({
21
+ commandsMetadataService: commandsMetadataServiceSingleton,
22
+ commandRegistrationService: new CommandRegistrationService(),
23
+ commandActionExecutor: new CommandActionExecutor({
24
+ executionPath,
25
+ commandOptionsValidator: new CommandOptionsValidator(),
26
+ cliConfigurationService: new CLIConfigurationService(),
27
+ commandsMetadataService: commandsMetadataServiceSingleton,
28
+ log: NodeConsoleLogger,
29
+ sdkPath: sdkPath
30
+ }),
31
+ });
32
+
33
+ cliInstance.start(process);
@@ -0,0 +1,25 @@
1
+ /*
2
+ ** Copyright (c) 2024 Oracle and/or its affiliates. All rights reserved.
3
+ ** Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4
+ */
5
+ 'use strict';
6
+
7
+ module.exports = {
8
+ SCRIPTS: {
9
+ blankscript: require.resolve('./scripts/blankscript.js'),
10
+ },
11
+ OBJECTS: {
12
+ commerceextension: require.resolve('./objects/commerceextension.xml'),
13
+ },
14
+ PROJECTCONFIGS: {
15
+ cliconfig: require.resolve('./projectconfigs/suitecloud.config.js'),
16
+ gitignore: require.resolve('./projectconfigs/default_gitignore.template')
17
+ },
18
+ UNIT_TEST: {
19
+ cliconfig: require.resolve('./unittest/suitecloud.config.js.template'),
20
+ jestconfig: require.resolve('./unittest/jest.config.js.template'),
21
+ packagejson: require.resolve('./unittest/package.json.template'),
22
+ sampletest: require.resolve('./unittest/sample-test.js.template'),
23
+ jsconfig: require.resolve('./unittest/jsconfig.json.template')
24
+ }
25
+ };
@@ -0,0 +1,9 @@
1
+ <commerceextension objecttypeappid="" scriptid="{{scriptid}}">
2
+ <name></name>
3
+ <description></description>
4
+ <vendor></vendor>
5
+ <type></type>
6
+ <version></version>
7
+ <target></target>
8
+ <basepath></basepath>
9
+ </commerceextension>
@@ -0,0 +1,47 @@
1
+ # IDEs and editors
2
+ .idea
3
+ *.iml
4
+ *.iws
5
+ .project
6
+ .classpath
7
+ *.launch
8
+ .settings
9
+ *.sublime-workspace
10
+ .vscode
11
+
12
+ # Dependency directories
13
+ node_modules
14
+
15
+ # TypeScript cache
16
+ *.tsbuildinfo
17
+
18
+ # Logs
19
+ logs
20
+ *.log
21
+ npm-debug.log*
22
+
23
+ # Packaged SuiteCloud projects
24
+ build
25
+
26
+ # misc
27
+ .sass-cache
28
+
29
+ # Optional npm cache directory
30
+ .npm
31
+
32
+ # System Files
33
+ .DS_Store
34
+ Thumbs.db
35
+
36
+ # Output of 'npm pack'
37
+ *.tgz
38
+
39
+ # Project config
40
+ project.json
41
+
42
+ # temp files
43
+ sdftemp*
44
+
45
+ # default deploy and manifest file
46
+ deploy.xml
47
+ manifest.xml
@@ -0,0 +1,4 @@
1
+ module.exports = {
2
+ defaultProjectFolder: "src",
3
+ commands: {}
4
+ };
@@ -0,0 +1,4 @@
1
+ module.exports = {
2
+ defaultProjectFolder: "src",
3
+ commands: {}
4
+ };
@@ -0,0 +1,3 @@
1
+ function main(){
2
+ return 'hello world'
3
+ }
@@ -0,0 +1,7 @@
1
+ const SuiteCloudJestConfiguration = require("@oracle/suitecloud-unit-testing/jest-configuration/SuiteCloudJestConfiguration");
2
+ const cliConfig = require("./suitecloud.config");
3
+
4
+ module.exports = SuiteCloudJestConfiguration.build({
5
+ projectFolder: cliConfig.defaultProjectFolder,
6
+ projectType: {{projectType}},
7
+ });
@@ -0,0 +1,5 @@
1
+ {
2
+ "typeAcquisition": {
3
+ "include": ["jest"]
4
+ }
5
+ }
@@ -0,0 +1,12 @@
1
+ {
2
+ "name": "suitecloud-project",
3
+ "version": "{{version}}",
4
+ "scripts": {
5
+ "test": "jest"
6
+ },
7
+ "devDependencies": {
8
+ "jest": "29.7.0",
9
+ "@types/jest": "29.5.14",
10
+ "@oracle/suitecloud-unit-testing": "^1.7.0"
11
+ }
12
+ }