@fontoxml/fontoxml-development-tools 3.10.0 → 3.12.0-beta.1

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 (206) hide show
  1. package/npm-shrinkwrap.json +3842 -8330
  2. package/package.json +13 -19
  3. package/src/App.js +1 -1
  4. package/src/FdtCommand.js +3 -3
  5. package/src/FdtLicense.js +95 -114
  6. package/src/ModuleRegistrationApi.js +44 -16
  7. package/src/addCoreModulesToApp.js +8 -0
  8. package/src/editorVersions.js +19 -5
  9. package/src/modules/connectors/index.js +109 -16
  10. package/src/modules/connectors/instanceBuild/Dockerfile.build +1 -1
  11. package/src/modules/connectors/instanceBuild/Dockerfile.run +1 -1
  12. package/src/modules/connectors/instanceDevBuild/docker-compose.yml +2 -2
  13. package/src/modules/content-quality/index.js +101 -20
  14. package/src/modules/content-quality/instanceBuild/Dockerfile +1 -1
  15. package/src/modules/content-quality/instanceDevBuild/docker-compose.yml +1 -1
  16. package/src/modules/core/src/precontroller.help.js +23 -26
  17. package/src/modules/document-history/index.js +101 -20
  18. package/src/modules/document-history/instanceBuild/Dockerfile +1 -1
  19. package/src/modules/document-history/instanceDevBuild/docker-compose.yml +1 -1
  20. package/src/modules/editor/dev-cms/connectors-cms-standard/configureConnectorsCmsStandardDocumentRouter.js +10 -0
  21. package/src/modules/editor/dev-cms/connectors-cms-standard/configureDocumentHistoryGetPostRouteHandler.js +51 -0
  22. package/src/modules/editor/dev-cms/connectors-cms-standard/configureDocumentPostRouteHandler.js +65 -76
  23. package/src/modules/editor/dev-cms/connectors-cms-standard/configureDocumentPresearchPostRouteHandler.js +10 -7
  24. package/src/modules/editor/dev-cms/connectors-cms-standard/configureDocumentPreviewRouteHandler.js +10 -0
  25. package/src/modules/editor/dev-cms/connectors-cms-standard/configureDocumentRevisionGetPostRouteHandler.js +69 -0
  26. package/src/modules/editor/src/commands/command.convert.editor.controller.js +11 -4
  27. package/src/modules/editor/src/commands/command.convert.package.controller.js +11 -4
  28. package/src/modules/editor/src/getAppManifest.js +3 -3
  29. package/src/modules/editor/src/getWebpackConfig.js +13 -0
  30. package/src/modules/editor/src/webpackPlugins/CheckDeepImportsResolvePlugin.js +4 -0
  31. package/src/modules/editor-pre-7-7-0/src/api/downloadEditorSDK.js +16 -12
  32. package/src/modules/editor-pre-7-7-0/src/api/executeAndLog.js +3 -2
  33. package/src/modules/editor-pre-7-7-0/src/api/init/createConfigConfiguration.js +86 -48
  34. package/src/modules/editor-pre-7-7-0/src/api/schema/compile.js +16 -22
  35. package/src/modules/editor-pre-7-7-0/src/api/schema/createSchemaPackages.js +8 -0
  36. package/src/modules/editor-pre-7-7-0/src/api/schema/getSchemaFontoJson.js +76 -48
  37. package/src/modules/editor-pre-7-7-0/src/api/schema/zipHelpers.js +6 -1
  38. package/src/modules/editor-pre-7-7-0/src/command.schema.compile.controller.js +51 -2
  39. package/src/modules/editor-pre-7-7-0/test/api/init/createConfigConfiguration.test.js +71 -33
  40. package/src/modules/editor-pre-7-7-0/test/api/init/fixtures/configjs-7160.js +45 -0
  41. package/src/modules/editor-pre-7-7-0/test/api/init/fixtures/configjs-800.js +45 -0
  42. package/src/modules/editor-pre-7-7-0/test/api/init/fixtures/configjs-810.js +32 -0
  43. package/src/modules/editor-pre-7-7-0/test/api/schema/buildSchemaExperienceConfigurationModel.test.js +70 -79
  44. package/src/modules/editor-pre-7-7-0/test/api/schema/fixtures/dita-example-schema-bundle/listOfFiles.json +1 -36
  45. package/src/modules/editor-pre-7-7-0/test/api/schema/fixtures/invalid-fonto-json/fonto.json +1 -0
  46. package/src/modules/editor-pre-7-7-0/test/api/schema/getSchemaFontoJson.test.js +174 -0
  47. package/src/modules/editor-pre-7-7-0/test/api/schema/zipSchemaSource.test.js +10 -4
  48. package/src/modules/editor-pre-7-7-0/test/schemaCompileController.test.js +205 -0
  49. package/src/modules/localization/index.js +2 -2
  50. package/src/modules/operations/src/api/getOperations.js +3 -3
  51. package/src/modules/review/index.js +103 -18
  52. package/src/modules/review/instanceBuild/Dockerfile +1 -1
  53. package/src/modules/review/instanceDevBuild/docker-compose.yml +1 -1
  54. package/src/modules/schema/src/api/getSchemaSummaries.js +2 -2
  55. package/src/modules/schema/test/getSchemaSummaries.test.js +14 -10
  56. package/src/modules/schema-compiler/index.js +99 -18
  57. package/src/modules/schema-compiler/instanceBuild/Dockerfile +1 -1
  58. package/src/modules/schema-compiler/instanceDevBuild/docker-compose.yml +1 -1
  59. package/src/modules/shared/index.js +3 -0
  60. package/src/modules/shared/package.json +14 -0
  61. package/src/modules/shared/src/addBackendDockerCommands.js +334 -0
  62. package/src/modules/shared/src/addBackendDownloadSelfContainedCommands.js +78 -0
  63. package/src/modules/shared/src/addBackendVersionsCommands.js +55 -0
  64. package/src/modules/shared/src/controller-templates/command.backend.build.controller.factory.js +273 -0
  65. package/src/modules/shared/src/controller-templates/command.backend.download-self-contained.controller.factory.js +131 -0
  66. package/src/modules/shared/src/controller-templates/command.backend.init.controller.factory.js +88 -0
  67. package/src/modules/shared/src/controller-templates/command.backend.run.controller.factory.js +420 -0
  68. package/src/modules/shared/src/controller-templates/command.backend.upgrade.controller.factory.js +79 -0
  69. package/src/modules/shared/src/controller-templates/command.backend.versions.controller.factory.js +23 -0
  70. package/src/modules/shared/src/controller-templates/docker/BackendManifest.js +42 -0
  71. package/src/modules/shared/src/controller-templates/docker/copyWhitelistedFiles.js +23 -0
  72. package/src/modules/shared/src/controller-templates/docker/dockerCleanup.js +146 -0
  73. package/src/modules/shared/src/controller-templates/docker/tryDockerLogout.js +31 -0
  74. package/src/modules/shared/src/controller-templates/docker/validateBackendInstance.js +48 -0
  75. package/src/modules/shared/src/ensureDockerCommands.js +61 -0
  76. package/src/modules/shared/src/executeAndLog.js +113 -0
  77. package/src/modules/{review/src/utilities/setEntryVisibility.js → shared/src/setFileVisibility.js} +8 -2
  78. package/src/modules/spell-checker/index.js +101 -18
  79. package/src/modules/spell-checker/instanceBuild/Dockerfile +1 -1
  80. package/src/modules/spell-checker/instanceDevBuild/docker-compose.yml +1 -1
  81. package/test/module.shared.test.js +81 -0
  82. package/src/modules/connectors/src/command.build.controller.js +0 -256
  83. package/src/modules/connectors/src/command.build.js +0 -54
  84. package/src/modules/connectors/src/command.download-self-contained.controller.js +0 -110
  85. package/src/modules/connectors/src/command.download-self-contained.js +0 -50
  86. package/src/modules/connectors/src/command.init.controller.js +0 -91
  87. package/src/modules/connectors/src/command.init.js +0 -42
  88. package/src/modules/connectors/src/command.run.controller.js +0 -462
  89. package/src/modules/connectors/src/command.run.js +0 -67
  90. package/src/modules/connectors/src/command.upgrade.controller.js +0 -52
  91. package/src/modules/connectors/src/command.upgrade.js +0 -42
  92. package/src/modules/connectors/src/command.versions.controller.js +0 -14
  93. package/src/modules/connectors/src/command.versions.js +0 -25
  94. package/src/modules/connectors/src/utilities/FontoxmlConnectorsManifest.js +0 -32
  95. package/src/modules/connectors/src/utilities/cleanup.js +0 -70
  96. package/src/modules/connectors/src/utilities/constants.js +0 -42
  97. package/src/modules/connectors/src/utilities/copyWhitelistedFiles.js +0 -22
  98. package/src/modules/connectors/src/utilities/executeAndLog.js +0 -63
  99. package/src/modules/connectors/src/utilities/getVerbosityLevel.js +0 -11
  100. package/src/modules/connectors/src/utilities/getWhitelist.js +0 -16
  101. package/src/modules/connectors/src/utilities/setEntryVisibility.js +0 -22
  102. package/src/modules/connectors/src/utilities/validateInstance.js +0 -29
  103. package/src/modules/content-quality/src/command.build.controller.js +0 -260
  104. package/src/modules/content-quality/src/command.build.js +0 -56
  105. package/src/modules/content-quality/src/command.download-self-contained.controller.js +0 -110
  106. package/src/modules/content-quality/src/command.download-self-contained.js +0 -52
  107. package/src/modules/content-quality/src/command.init.controller.js +0 -91
  108. package/src/modules/content-quality/src/command.init.js +0 -44
  109. package/src/modules/content-quality/src/command.run.controller.js +0 -444
  110. package/src/modules/content-quality/src/command.run.js +0 -64
  111. package/src/modules/content-quality/src/command.upgrade.controller.js +0 -52
  112. package/src/modules/content-quality/src/command.upgrade.js +0 -44
  113. package/src/modules/content-quality/src/command.versions.controller.js +0 -14
  114. package/src/modules/content-quality/src/command.versions.js +0 -25
  115. package/src/modules/content-quality/src/utilities/FontoxmlFcqManifest.js +0 -30
  116. package/src/modules/content-quality/src/utilities/cleanup.js +0 -70
  117. package/src/modules/content-quality/src/utilities/constants.js +0 -44
  118. package/src/modules/content-quality/src/utilities/copyWhitelistedFiles.js +0 -22
  119. package/src/modules/content-quality/src/utilities/executeAndLog.js +0 -63
  120. package/src/modules/content-quality/src/utilities/getVerbosityLevel.js +0 -11
  121. package/src/modules/content-quality/src/utilities/getWhitelist.js +0 -16
  122. package/src/modules/content-quality/src/utilities/setEntryVisibility.js +0 -22
  123. package/src/modules/content-quality/src/utilities/validateInstance.js +0 -29
  124. package/src/modules/document-history/src/command.build.controller.js +0 -260
  125. package/src/modules/document-history/src/command.build.js +0 -56
  126. package/src/modules/document-history/src/command.download-self-contained.controller.js +0 -110
  127. package/src/modules/document-history/src/command.download-self-contained.js +0 -50
  128. package/src/modules/document-history/src/command.init.controller.js +0 -91
  129. package/src/modules/document-history/src/command.init.js +0 -44
  130. package/src/modules/document-history/src/command.run.controller.js +0 -444
  131. package/src/modules/document-history/src/command.run.js +0 -64
  132. package/src/modules/document-history/src/command.upgrade.controller.js +0 -52
  133. package/src/modules/document-history/src/command.upgrade.js +0 -44
  134. package/src/modules/document-history/src/command.versions.controller.js +0 -14
  135. package/src/modules/document-history/src/command.versions.js +0 -25
  136. package/src/modules/document-history/src/utilities/FontoxmlFdhManifest.js +0 -30
  137. package/src/modules/document-history/src/utilities/cleanup.js +0 -70
  138. package/src/modules/document-history/src/utilities/constants.js +0 -44
  139. package/src/modules/document-history/src/utilities/copyWhitelistedFiles.js +0 -22
  140. package/src/modules/document-history/src/utilities/executeAndLog.js +0 -63
  141. package/src/modules/document-history/src/utilities/getVerbosityLevel.js +0 -11
  142. package/src/modules/document-history/src/utilities/getWhitelist.js +0 -16
  143. package/src/modules/document-history/src/utilities/setEntryVisibility.js +0 -22
  144. package/src/modules/document-history/src/utilities/validateInstance.js +0 -29
  145. package/src/modules/review/src/command.build.controller.js +0 -256
  146. package/src/modules/review/src/command.build.js +0 -54
  147. package/src/modules/review/src/command.download-self-contained.controller.js +0 -107
  148. package/src/modules/review/src/command.download-self-contained.js +0 -50
  149. package/src/modules/review/src/command.init.controller.js +0 -89
  150. package/src/modules/review/src/command.init.js +0 -42
  151. package/src/modules/review/src/command.run.controller.js +0 -428
  152. package/src/modules/review/src/command.run.js +0 -60
  153. package/src/modules/review/src/command.upgrade.controller.js +0 -59
  154. package/src/modules/review/src/command.upgrade.js +0 -42
  155. package/src/modules/review/src/command.versions.controller.js +0 -12
  156. package/src/modules/review/src/command.versions.js +0 -25
  157. package/src/modules/review/src/utilities/FontoxmlReviewManifest.js +0 -30
  158. package/src/modules/review/src/utilities/cleanup.js +0 -70
  159. package/src/modules/review/src/utilities/constants.js +0 -42
  160. package/src/modules/review/src/utilities/copyWhitelistedFiles.js +0 -22
  161. package/src/modules/review/src/utilities/executeAndLog.js +0 -63
  162. package/src/modules/review/src/utilities/getVerbosityLevel.js +0 -11
  163. package/src/modules/review/src/utilities/getWhitelist.js +0 -16
  164. package/src/modules/review/src/utilities/validateInstance.js +0 -45
  165. package/src/modules/schema-compiler/src/command.build.controller.js +0 -256
  166. package/src/modules/schema-compiler/src/command.build.js +0 -54
  167. package/src/modules/schema-compiler/src/command.download-self-contained.controller.js +0 -110
  168. package/src/modules/schema-compiler/src/command.download-self-contained.js +0 -50
  169. package/src/modules/schema-compiler/src/command.init.controller.js +0 -91
  170. package/src/modules/schema-compiler/src/command.init.js +0 -42
  171. package/src/modules/schema-compiler/src/command.run.controller.js +0 -430
  172. package/src/modules/schema-compiler/src/command.run.js +0 -60
  173. package/src/modules/schema-compiler/src/command.upgrade.controller.js +0 -64
  174. package/src/modules/schema-compiler/src/command.upgrade.js +0 -42
  175. package/src/modules/schema-compiler/src/command.versions.controller.js +0 -14
  176. package/src/modules/schema-compiler/src/command.versions.js +0 -25
  177. package/src/modules/schema-compiler/src/utilities/FontoxmlSchemaCompilerManifest.js +0 -32
  178. package/src/modules/schema-compiler/src/utilities/cleanup.js +0 -70
  179. package/src/modules/schema-compiler/src/utilities/constants.js +0 -43
  180. package/src/modules/schema-compiler/src/utilities/copyWhitelistedFiles.js +0 -22
  181. package/src/modules/schema-compiler/src/utilities/executeAndLog.js +0 -63
  182. package/src/modules/schema-compiler/src/utilities/getVerbosityLevel.js +0 -11
  183. package/src/modules/schema-compiler/src/utilities/getWhitelist.js +0 -16
  184. package/src/modules/schema-compiler/src/utilities/setEntryVisibility.js +0 -22
  185. package/src/modules/schema-compiler/src/utilities/validateInstance.js +0 -47
  186. package/src/modules/spell-checker/src/command.build.controller.js +0 -257
  187. package/src/modules/spell-checker/src/command.build.js +0 -54
  188. package/src/modules/spell-checker/src/command.download-self-contained.controller.js +0 -110
  189. package/src/modules/spell-checker/src/command.download-self-contained.js +0 -50
  190. package/src/modules/spell-checker/src/command.init.controller.js +0 -91
  191. package/src/modules/spell-checker/src/command.init.js +0 -42
  192. package/src/modules/spell-checker/src/command.run.controller.js +0 -430
  193. package/src/modules/spell-checker/src/command.run.js +0 -62
  194. package/src/modules/spell-checker/src/command.upgrade.controller.js +0 -61
  195. package/src/modules/spell-checker/src/command.upgrade.js +0 -42
  196. package/src/modules/spell-checker/src/command.versions.controller.js +0 -14
  197. package/src/modules/spell-checker/src/command.versions.js +0 -25
  198. package/src/modules/spell-checker/src/utilities/FontoxmlSpellCheckerManifest.js +0 -32
  199. package/src/modules/spell-checker/src/utilities/cleanup.js +0 -70
  200. package/src/modules/spell-checker/src/utilities/constants.js +0 -42
  201. package/src/modules/spell-checker/src/utilities/copyWhitelistedFiles.js +0 -22
  202. package/src/modules/spell-checker/src/utilities/executeAndLog.js +0 -63
  203. package/src/modules/spell-checker/src/utilities/getVerbosityLevel.js +0 -11
  204. package/src/modules/spell-checker/src/utilities/getWhitelist.js +0 -16
  205. package/src/modules/spell-checker/src/utilities/setEntryVisibility.js +0 -22
  206. package/src/modules/spell-checker/src/utilities/validateInstance.js +0 -47
@@ -0,0 +1,273 @@
1
+ import fs from 'fs-extra';
2
+ import path from 'path';
3
+
4
+ import ensureDockerCommands from '../ensureDockerCommands.js';
5
+ import executeAndLog, {
6
+ getVerbosityLevel,
7
+ VERBOSITY_LEVEL,
8
+ } from '../executeAndLog.js';
9
+ import setFileVisibility from '../setFileVisibility.js';
10
+ import BackendManifest from './docker/BackendManifest.js';
11
+ import copyWhitelistedFiles from './docker/copyWhitelistedFiles.js';
12
+ import dockerCleanup from './docker/dockerCleanup.js';
13
+ import tryDockerLogout from './docker/tryDockerLogout.js';
14
+ import validateBackendInstance from './docker/validateBackendInstance.js';
15
+
16
+ /** @typedef {import('../addBackendDockerCommands').AddBackendDockerCommandsOptions} AddBackendDockerCommandsOptions */
17
+
18
+ /**
19
+ * @param {AddBackendDockerCommandsOptions} options
20
+ *
21
+ * @returns {(req: AskNicelyRequest, res: FdtResponse) => Promise<void>}
22
+ */
23
+ export default function backendBuildCommandFactory(options) {
24
+ return async function backendBuildCommand(req, res) {
25
+ res.caption(req.command.getLongName());
26
+
27
+ const directoryPath = path.resolve(
28
+ req.options.location ? req.options.location : process.cwd()
29
+ );
30
+ const temporaryDirectoryPath = path.join(
31
+ directoryPath,
32
+ options.temporaryBuildDirectoryName
33
+ );
34
+ const imageName = req.options['image-name']
35
+ ? req.options['image-name']
36
+ : options.defaultImageName;
37
+ const imageTag = req.options['image-tag']
38
+ ? req.options['image-tag']
39
+ : options.defaultImageTag;
40
+ const manifestFilePath = path.join(
41
+ directoryPath,
42
+ options.manifestFileName
43
+ );
44
+ const verbosityLevel = getVerbosityLevel(
45
+ req.options.verbose,
46
+ req.options.debug
47
+ );
48
+
49
+ // Check if the working directory path exists and is a directory.
50
+ try {
51
+ const stats = await fs.stat(directoryPath);
52
+ if (!stats.isDirectory()) {
53
+ throw new res.InputError(
54
+ 'The provided location is not a directory.'
55
+ );
56
+ }
57
+ } catch (error) {
58
+ if (error.code === 'ENOENT') {
59
+ throw new res.InputError(
60
+ 'The provided location does not exist.'
61
+ );
62
+ }
63
+ throw error;
64
+ }
65
+
66
+ // Ensure that the Docker commands are available.
67
+ await ensureDockerCommands(directoryPath, res, {
68
+ checkDocker: true,
69
+ checkDockerCompose: false,
70
+ });
71
+
72
+ let pidToKillOnForceExit = null;
73
+ const setPidToKillOnForceExit = (process) => {
74
+ pidToKillOnForceExit = process && process.pid;
75
+ };
76
+
77
+ // Ensure we cleanup before exiting on SIGINT.
78
+ let stopping = false;
79
+ process.on('SIGINT', (_code) => {
80
+ if (stopping) {
81
+ if (pidToKillOnForceExit) {
82
+ process.kill(pidToKillOnForceExit);
83
+ }
84
+ process.exit();
85
+ return;
86
+ }
87
+
88
+ stopping = true;
89
+ res.log('Gracefully stopping... (press Ctrl+C again to force)');
90
+ // eslint-disable-next-line consistent-return
91
+ return dockerCleanup(
92
+ temporaryDirectoryPath,
93
+ undefined,
94
+ res,
95
+ verbosityLevel
96
+ ).then(() => {
97
+ process.exit();
98
+ });
99
+ });
100
+
101
+ try {
102
+ await validateBackendInstance(directoryPath, options);
103
+
104
+ // Cleanup possible remaining resources from a previous build or run.
105
+ await dockerCleanup(
106
+ temporaryDirectoryPath,
107
+ undefined,
108
+ res,
109
+ verbosityLevel
110
+ );
111
+
112
+ const destroySpinner = res.spinner(
113
+ `Building the production image "${imageName}:${imageTag}" at "${directoryPath}"...`
114
+ );
115
+
116
+ // Read the manifest file.
117
+ const manifestObj = await BackendManifest.fromJsonFile(
118
+ manifestFilePath,
119
+ options.manifestVersionPropertyName
120
+ );
121
+
122
+ // Retrieve data for the docker image
123
+ let dockerData;
124
+ try {
125
+ const requestObj = {
126
+ [options.licenseProductName]: {
127
+ docker: {
128
+ version: manifestObj.version,
129
+ },
130
+ },
131
+ };
132
+ const productData = await req.fdt.license.getDataForProducts(
133
+ requestObj
134
+ );
135
+ dockerData =
136
+ productData.products[options.licenseProductName].docker;
137
+ } catch (error) {
138
+ if (error.statusCode === 404) {
139
+ error.solution = `This error might be caused by requesting a nonexistent ${options.productLabel} version, please check your version.`;
140
+ }
141
+ throw error;
142
+ }
143
+
144
+ // Create a hidden temporary directory.
145
+ await fs.mkdir(temporaryDirectoryPath);
146
+ await setFileVisibility(temporaryDirectoryPath, false);
147
+ // Copy the instance files into the temporary directory.
148
+ const dockerfileContent = await fs.readFile(
149
+ options.instanceBuildDockerfilePath,
150
+ 'utf8'
151
+ );
152
+ // Rewrite the image in the Dockerfile.
153
+ const fixedDockerfileContent = dockerfileContent.replace(
154
+ '${image}',
155
+ dockerData.image
156
+ );
157
+ await fs.writeFile(
158
+ path.join(temporaryDirectoryPath, 'Dockerfile'),
159
+ fixedDockerfileContent,
160
+ 'utf8'
161
+ );
162
+ const temporaryInstanceDirectoryPath = path.join(
163
+ temporaryDirectoryPath,
164
+ 'instance'
165
+ );
166
+ await fs.ensureDir(temporaryInstanceDirectoryPath);
167
+ // Copy whitelisted files.
168
+ await copyWhitelistedFiles(
169
+ options.whitelist,
170
+ directoryPath,
171
+ temporaryInstanceDirectoryPath
172
+ );
173
+
174
+ // Pull the docker image.
175
+ try {
176
+ await executeAndLog(
177
+ res,
178
+ 'docker',
179
+ [
180
+ 'login',
181
+ dockerData.registry,
182
+ '-u',
183
+ dockerData.login,
184
+ '-p',
185
+ dockerData.password,
186
+ ],
187
+ null,
188
+ VERBOSITY_LEVEL.NORMAL,
189
+ false,
190
+ setPidToKillOnForceExit
191
+ );
192
+ await executeAndLog(
193
+ res,
194
+ 'docker',
195
+ ['pull', dockerData.image],
196
+ null,
197
+ verbosityLevel,
198
+ false,
199
+ setPidToKillOnForceExit
200
+ );
201
+ } catch (error) {
202
+ await tryDockerLogout(
203
+ dockerData.registry,
204
+ res,
205
+ setPidToKillOnForceExit
206
+ );
207
+ throw new res.ErrorWithInnerError(
208
+ 'Failed to retrieve the image file.',
209
+ error
210
+ );
211
+ }
212
+
213
+ // Build the docker image.
214
+ try {
215
+ await executeAndLog(
216
+ res,
217
+ 'docker',
218
+ ['build', '-t', `${imageName}:${imageTag}`, '.'],
219
+ temporaryDirectoryPath,
220
+ verbosityLevel,
221
+ false,
222
+ setPidToKillOnForceExit
223
+ );
224
+ } finally {
225
+ await tryDockerLogout(
226
+ dockerData.registry,
227
+ res,
228
+ setPidToKillOnForceExit
229
+ );
230
+ }
231
+
232
+ // Send telemetry.
233
+ await req.fdt.license.sendTelemetry({
234
+ product: req.command.parent.name,
235
+ type: 'docker',
236
+ version: manifestObj.version,
237
+ action: req.command.name,
238
+ });
239
+
240
+ destroySpinner();
241
+
242
+ // Cleanup temporary directory.
243
+ await dockerCleanup(
244
+ temporaryDirectoryPath,
245
+ undefined,
246
+ res,
247
+ verbosityLevel
248
+ );
249
+ } catch (error) {
250
+ if (!stopping) {
251
+ res.notice(
252
+ options.documentationExecuteError
253
+ ? `See our documentation at ${options.documentationExecuteError} for help.`
254
+ : 'See our documentation for help.'
255
+ );
256
+ }
257
+
258
+ try {
259
+ await dockerCleanup(
260
+ temporaryDirectoryPath,
261
+ undefined,
262
+ res,
263
+ verbosityLevel
264
+ );
265
+ } catch (_cleanupError) {
266
+ // Ignore cleanup error.
267
+ }
268
+
269
+ // Re-throw the actual error.
270
+ throw error;
271
+ }
272
+ };
273
+ }
@@ -0,0 +1,131 @@
1
+ import fs from 'fs-extra';
2
+ import fetch from 'node-fetch';
3
+ import path from 'path';
4
+ import url from 'url';
5
+
6
+ /** @typedef {import('../addBackendDownloadSelfContainedCommands').AddBackendDownloadSelfContainedCommandsOptions} AddBackendDownloadSelfContainedCommandsOptions */
7
+
8
+ /**
9
+ * @param {AddBackendDownloadSelfContainedCommandsOptions} options
10
+ *
11
+ * @returns {(req: AskNicelyRequest, res: FdtResponse) => Promise<void>}
12
+ */
13
+ export default function backendDownloadSelfContainedCommandFactory(options) {
14
+ return async function backendDownloadSelfContainedCommand(req, res) {
15
+ res.caption(req.command.getLongName());
16
+
17
+ const directoryPath = path.resolve(
18
+ req.options.location ? req.options.location : process.cwd()
19
+ );
20
+ const version = req.options.version;
21
+ const runtime = req.options.runtime;
22
+
23
+ const destroySpinner = res.spinner(
24
+ `Downloading self-contained build...`
25
+ );
26
+
27
+ // Get the download URI for the self-contained build.
28
+ let downloadUri;
29
+ try {
30
+ const requestObj = {
31
+ [options.licenseProductName]: {
32
+ selfContained: {
33
+ runtime,
34
+ version,
35
+ },
36
+ },
37
+ };
38
+ const productData = await req.fdt.license.getDataForProducts(
39
+ requestObj
40
+ );
41
+ downloadUri =
42
+ productData.products[options.licenseProductName].selfContained
43
+ .uri;
44
+ } catch (error) {
45
+ if (error.statusCode === 404) {
46
+ try {
47
+ const sdkVersions =
48
+ await req.fdt.license.getVersionsForProduct(
49
+ options.licenseProductName
50
+ );
51
+ // eslint-disable-next-line no-ex-assign
52
+ error = new res.ErrorWithSolution(
53
+ `Could not download self-contained for version (${version}) and runtime environment (${runtime}). Please check if it is a valid version and runtime environment.`,
54
+ `The latest version is ${sdkVersions.getLatestStable()}, run \`fdt ${
55
+ options.commandPrefix
56
+ } versions\` to get a list of all available versions and run \`fdt ${
57
+ options.commandPrefix
58
+ } download-self-contained --help\` to get a list of all available runtime environments.`,
59
+ error
60
+ );
61
+ } catch (_error) {
62
+ throw new res.ErrorWithSolution(
63
+ `Could not download self-contained for version (${version}) and runtime environment (${runtime}). Please check if it is a valid version and runtime environment.`,
64
+ `Run \`fdt ${options.commandPrefix} versions\` to get a list of all available versions and run \`fdt ${options.commandPrefix} download-self-contained --help\` to get a list of all available runtime environments.`,
65
+ error
66
+ );
67
+ }
68
+ }
69
+ throw error;
70
+ }
71
+
72
+ // Download the self-contained build.
73
+ const data = await fetch(downloadUri, { method: 'GET' }).then(
74
+ async (response) => {
75
+ switch (response.status) {
76
+ case 200:
77
+ try {
78
+ return Buffer.from(await response.arrayBuffer());
79
+ } catch (_err) {
80
+ throw new Error(
81
+ `Invalid response data from the self-contained builds server.`
82
+ );
83
+ }
84
+ case 401:
85
+ case 403:
86
+ throw new Error(
87
+ 'You are currently not allowed to download this self-contained build, even though you might have the license for it.'
88
+ );
89
+ case 404:
90
+ throw new Error(
91
+ 'The file for the requested self-contained build could not be found.'
92
+ );
93
+ default:
94
+ throw new Error(
95
+ `Invalid response from the self-contained builds server (${response.status}).`
96
+ );
97
+ }
98
+ }
99
+ );
100
+
101
+ // Write the self-contained build to disk.
102
+ const parsed = url.parse(downloadUri);
103
+ const filename = path.basename(parsed.pathname);
104
+ const filePath = path.join(directoryPath, filename);
105
+ try {
106
+ await fs.outputFile(filePath, data);
107
+ } catch (error) {
108
+ throw new res.ErrorWithInnerError(
109
+ 'Could not save self-contained build download to disk.',
110
+ error
111
+ );
112
+ }
113
+
114
+ await req.fdt.license.sendTelemetry({
115
+ product: req.command.parent.name,
116
+ type: 'selfContained',
117
+ runtime: req.options.runtime,
118
+ version,
119
+ action: req.command.name,
120
+ });
121
+
122
+ destroySpinner();
123
+ res.break();
124
+ const locationString = req.options.location
125
+ ? path.isAbsolute(req.options.location)
126
+ ? filePath
127
+ : path.join(req.options.location, filename)
128
+ : filename;
129
+ res.notice(`Saved self-contained build to ${locationString}`);
130
+ };
131
+ }
@@ -0,0 +1,88 @@
1
+ import fs from 'fs-extra';
2
+ import path from 'path';
3
+
4
+ import setFileVisibility from '../setFileVisibility.js';
5
+ import BackendManifest from './docker/BackendManifest.js';
6
+
7
+ /** @typedef {import('../addBackendDockerCommands').AddBackendDockerCommandsOptions} AddBackendDockerCommandsOptions */
8
+
9
+ /**
10
+ * @param {AddBackendDockerCommandsOptions} options
11
+ *
12
+ * @returns {(req: AskNicelyRequest, res: FdtResponse) => Promise<void>}
13
+ */
14
+ export default function backendInitCommandFactory(options) {
15
+ return async function backendInitCommand(req, res) {
16
+ res.caption(req.command.getLongName());
17
+
18
+ // Check if the version exists.
19
+ const sdkVersions = await req.fdt.license.getVersionsForProduct(
20
+ options.licenseProductName
21
+ );
22
+ const version = req.options.version;
23
+ if (!sdkVersions.includes(version)) {
24
+ throw new res.ErrorWithSolution(
25
+ `Could not initialize for version (${version}), please check if it is a valid version. The latest version is ${sdkVersions.getLatestStable()}.`,
26
+ `Run \`fdt ${options.commandPrefix} versions\` to get a list of all available versions.`
27
+ );
28
+ }
29
+
30
+ const directoryPath = path.resolve(
31
+ req.options.location ? req.options.location : process.cwd()
32
+ );
33
+ // Ensure the directory exist.
34
+ await fs.ensureDir(directoryPath);
35
+ // Ensure the directory is empty if it does exist.
36
+ const files = await fs.readdir(directoryPath);
37
+ if (files.length) {
38
+ throw new res.InputError(
39
+ `The directory "${directoryPath}" is not empty.`
40
+ );
41
+ }
42
+
43
+ const destroySpinner = res.spinner(
44
+ `Initializing a ${options.productLabel} instance at "${directoryPath}"...`
45
+ );
46
+ try {
47
+ await fs.copy(
48
+ options.instanceTemplateDirectoryPath,
49
+ directoryPath,
50
+ {
51
+ filter: (src, _dest) => {
52
+ const filename = path.basename(src);
53
+ return filename !== '.gitkeep';
54
+ },
55
+ }
56
+ );
57
+ const data = new BackendManifest(
58
+ options.manifestVersionPropertyName,
59
+ version
60
+ );
61
+ const manifest = path.join(directoryPath, options.manifestFileName);
62
+ await fs.writeJson(manifest, data);
63
+ await setFileVisibility(manifest, false);
64
+ } catch (error) {
65
+ await fs.emptyDir(directoryPath);
66
+ destroySpinner();
67
+ throw error;
68
+ }
69
+
70
+ await req.fdt.license.sendTelemetry({
71
+ product: req.command.parent.name,
72
+ type: 'docker',
73
+ version,
74
+ action: req.command.name,
75
+ });
76
+
77
+ destroySpinner();
78
+
79
+ res.log(
80
+ 'Complete the configuration before building or running the instance.'
81
+ );
82
+ if (options.documentationGettingStartedGuide) {
83
+ res.log(
84
+ `See ${options.documentationGettingStartedGuide} for more information.`
85
+ );
86
+ }
87
+ };
88
+ }