@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
@@ -1,59 +0,0 @@
1
- import fs from 'fs-extra';
2
- import path from 'path';
3
-
4
- import constants from './utilities/constants.js';
5
- import FontoxmlReviewManifest from './utilities/FontoxmlReviewManifest.js';
6
- import setEntryVisibility from './utilities/setEntryVisibility.js';
7
- import validateInstance from './utilities/validateInstance.js';
8
-
9
- export default async function upgradeCommand(req, res) {
10
- res.caption(req.command.getLongName());
11
-
12
- // Check if the given version exist.
13
- const sdkVersions = await req.fdt.license.getVersionsForProduct('review');
14
- const version = req.options.version;
15
- if (!sdkVersions.includes(version)) {
16
- throw new Error(
17
- `Could not upgrade to version (${version}), please check if it is a valid version. The latest version is ${sdkVersions.getLatestStable()}, run \`fdt review versions\` to get a list of all available versions.`
18
- );
19
- }
20
-
21
- const destroySpinner = res.spinner(
22
- `Upgrading your Fonto Review instance to ${version}...`
23
- );
24
-
25
- const directoryPath = path.resolve(
26
- req.options.location ? req.options.location : process.cwd()
27
- );
28
- const manifestFilePath = path.join(
29
- directoryPath,
30
- constants.MANIFEST_FILENAME
31
- );
32
- let currentVersion;
33
- return validateInstance(directoryPath)
34
- .then(() => setEntryVisibility(manifestFilePath, true))
35
- .then(() => FontoxmlReviewManifest.fromJsonFile(manifestFilePath))
36
- .then((manifest) => {
37
- currentVersion = manifest.reviewVersion;
38
- manifest.reviewVersion = version;
39
- return fs.writeJson(manifestFilePath, manifest);
40
- })
41
- .then(() => setEntryVisibility(manifestFilePath, false))
42
- .then(() =>
43
- req.fdt.license.sendTelemetry({
44
- product: req.command.parent.name,
45
- type: 'docker',
46
- version,
47
- currentVersion,
48
- action: req.command.name,
49
- })
50
- )
51
- .then(() => destroySpinner())
52
- .catch((error) => {
53
- res.notice(
54
- `See our documentation at ${constants.DOCUMENTATION_EXECUTE_ERROR} for help.`
55
- );
56
-
57
- throw error;
58
- });
59
- }
@@ -1,42 +0,0 @@
1
- import path from 'path';
2
- import { fileURLToPath } from 'url';
3
-
4
- const __filename = fileURLToPath(import.meta.url);
5
- const __dirname = path.dirname(__filename);
6
-
7
- export default (moduleRegistration, reviewCommand) => {
8
- reviewCommand
9
- .addCommand(
10
- 'upgrade',
11
- path.resolve(__dirname, 'command.upgrade.controller.js')
12
- )
13
- .setDescription(
14
- 'Upgrade an existing Fonto Review instance to the specified version.'
15
- )
16
-
17
- .addOption(
18
- 'location',
19
- 'l',
20
- 'The directory of the instance to upgrade. If not set this defaults to the current working directory.',
21
- false
22
- )
23
- .addOption(
24
- 'version',
25
- null,
26
- 'The version to upgrade to. Can be either a specific version or "nightly". Be warned: nightly can be unstable or may not work at all.',
27
- true
28
- )
29
-
30
- .addExample(
31
- `${
32
- moduleRegistration.getAppInfo().name
33
- } review upgrade --version x.x.x`,
34
- 'Upgrade the Fonto Review instance located at the current working directory to version x.x.x.'
35
- )
36
- .addExample(
37
- `${
38
- moduleRegistration.getAppInfo().name
39
- } review upgrade --location /opt/my-instance/ --version x.x.x`,
40
- 'Upgrade the Fonto Review instance located at "/opt/my-instance/" to version x.x.x.'
41
- );
42
- };
@@ -1,12 +0,0 @@
1
- export default async function versionsCommand(req, res) {
2
- res.caption(req.command.getLongName());
3
-
4
- const all = req.options.all;
5
- const destroySpinner = res.spinner(
6
- `Retrieving ${all ? 'all ' : ''}Fonto Review versions...`
7
- );
8
- const sdkVersions = await req.fdt.license.getVersionsForProduct('review');
9
- destroySpinner();
10
- res.caption('Fonto Review versions');
11
- res.list(all ? sdkVersions.getAll() : sdkVersions.getAllStable(), '-');
12
- }
@@ -1,25 +0,0 @@
1
- import path from 'path';
2
- import { fileURLToPath } from 'url';
3
-
4
- const __filename = fileURLToPath(import.meta.url);
5
- const __dirname = path.dirname(__filename);
6
-
7
- export default (moduleRegistration, reviewCommand) => {
8
- reviewCommand
9
- .addCommand(
10
- 'versions',
11
- path.resolve(__dirname, 'command.versions.controller.js')
12
- )
13
- .setDescription('List the available Fonto Review versions.')
14
-
15
- .addHiddenOption(
16
- 'all',
17
- undefined,
18
- 'Include nightly and prerelease versions.'
19
- )
20
-
21
- .addExample(
22
- `${moduleRegistration.getAppInfo().name} review versions`,
23
- 'Request the available versions for Fonto Review.'
24
- );
25
- };
@@ -1,30 +0,0 @@
1
- import fs from 'fs-extra';
2
-
3
- export default class FontoxmlReviewManifest {
4
- constructor(reviewVersion) {
5
- this.reviewVersion = reviewVersion;
6
- }
7
-
8
- static fromJsonFile(filePath) {
9
- return fs
10
- .exists(filePath)
11
- .then((exists) => {
12
- if (!exists) {
13
- throw new Error(`The file ${filePath} does not exist.`);
14
- }
15
- })
16
- .then(() => fs.readJson(filePath))
17
- .then((content) => {
18
- FontoxmlReviewManifest.validate(content);
19
- return new FontoxmlReviewManifest(content.reviewVersion);
20
- });
21
- }
22
-
23
- static validate(input) {
24
- if (!input.reviewVersion) {
25
- throw new Error(
26
- "The Fonto Review manifest file does not contain a 'reviewVersion'."
27
- );
28
- }
29
- }
30
- }
@@ -1,70 +0,0 @@
1
- import fs from 'fs-extra';
2
- import path from 'path';
3
-
4
- import constants from './constants.js';
5
- import executeAndLog from './executeAndLog.js';
6
-
7
- export default async function cleanup(
8
- temporaryDirectoryPath,
9
- projectName,
10
- res,
11
- verbosityLevel
12
- ) {
13
- const temporaryDirectoryExists = await fs.exists(temporaryDirectoryPath);
14
- if (!temporaryDirectoryExists) {
15
- return;
16
- }
17
-
18
- const destroySpinner = res.spinner('Removing temporary resources...');
19
-
20
- try {
21
- const dockerComposeFileExists = await fs.exists(
22
- path.join(temporaryDirectoryPath, 'docker-compose.yml')
23
- );
24
-
25
- const errors = [];
26
- const tasks = [
27
- async () => {
28
- if (dockerComposeFileExists && projectName) {
29
- await executeAndLog(
30
- res,
31
- 'docker-compose',
32
- verbosityLevel === constants.VERBOSITY_LEVEL_DEBUG
33
- ? [
34
- '-p',
35
- projectName,
36
- '--verbose',
37
- 'down',
38
- '--rmi',
39
- 'local',
40
- ]
41
- : ['-p', projectName, 'down', '--rmi', 'local'],
42
- temporaryDirectoryPath,
43
- verbosityLevel
44
- );
45
- }
46
- },
47
- async () => {
48
- await fs.remove(temporaryDirectoryPath);
49
- },
50
- ];
51
-
52
- // Run all cleanup tasks in order. Continue on errors. But collect the errors.
53
- for (let i = 0; i < tasks.length; i++) {
54
- try {
55
- await tasks[i]();
56
- } catch (error) {
57
- errors.push(error);
58
- }
59
- }
60
-
61
- // Only throw if a task have failed.
62
- if (errors.length > 0) {
63
- throw errors[0];
64
- }
65
- } catch (error) {
66
- throw error;
67
- } finally {
68
- destroySpinner();
69
- }
70
- }
@@ -1,42 +0,0 @@
1
- import path from 'path';
2
- import { fileURLToPath } from 'url';
3
-
4
- const __filename = fileURLToPath(import.meta.url);
5
- const __dirname = path.dirname(__filename);
6
-
7
- export default {
8
- DEFAULT_IMAGE_NAME: 'fonto-review',
9
- DEFAULT_IMAGE_TAG: 'latest',
10
- VERBOSITY_LEVEL_DEBUG: 'debug',
11
- VERBOSITY_LEVEL_NORMAL: 'normal',
12
- VERBOSITY_LEVEL_VERBOSE: 'verbose',
13
- DOCUMENTATION_CONFIGURATION_GUIDE:
14
- 'https://documentation.fontoxml.com/latest/configuration-13d2d631668c',
15
- DOCUMENTATION_GETTING_STARTED_GUIDE:
16
- 'https://documentation.fontoxml.com/latest/getting-started-8ca615260377',
17
- DOCUMENTATION_EXECUTE_ERROR:
18
- 'https://documentation.fontoxml.com/latest/review-9c9f35e6d1bf',
19
- INSTANCE_BUILD_DIRECTORY_PATH: path.join(
20
- __dirname,
21
- '..',
22
- '..',
23
- 'instanceBuild'
24
- ),
25
- INSTANCE_DEV_BUILD_DIRECTORY_PATH: path.join(
26
- __dirname,
27
- '..',
28
- '..',
29
- 'instanceDevBuild'
30
- ),
31
- INSTANCE_TEMPLATE_DIRECTORY_PATH: path.join(
32
- __dirname,
33
- '..',
34
- '..',
35
- 'instanceTemplate'
36
- ),
37
- MANIFEST_FILENAME: '.fontoxmlReviewManifest',
38
- REQUIRED_CONFIGURATION: [],
39
- TEMPORARY_DIRECTORY_NAME: '.reviewTmp',
40
- TEMPORARY_BUILD_DIRECTORY_NAME: '.reviewBuildTmp',
41
- WHITELIST: ['nlog.config'],
42
- };
@@ -1,22 +0,0 @@
1
- import fs from 'fs-extra';
2
- import path from 'path';
3
-
4
- export default function copyWhitelistedFiles(
5
- whitelistedFiles,
6
- sourceDirectory,
7
- destinationDirectory
8
- ) {
9
- return Promise.all(
10
- whitelistedFiles.map((item) => {
11
- const itemPath = path.join(sourceDirectory, item);
12
- return fs.exists(itemPath).then((exists) => {
13
- if (exists) {
14
- return fs.copy(
15
- itemPath,
16
- path.join(destinationDirectory, item)
17
- );
18
- }
19
- });
20
- })
21
- );
22
- }
@@ -1,63 +0,0 @@
1
- import cp from 'child_process';
2
-
3
- import constants from './constants.js';
4
-
5
- export default function executeAndLog(
6
- res,
7
- command,
8
- args,
9
- currentWorkingDirectoryPath,
10
- verbosityLevel,
11
- showStdout,
12
- processCreatedCallback
13
- ) {
14
- return new Promise((resolve, reject) => {
15
- const errors = [];
16
- const childProcess = cp.spawn(command, args, {
17
- cwd: currentWorkingDirectoryPath,
18
- });
19
- const verbose = verbosityLevel !== constants.VERBOSITY_LEVEL_NORMAL;
20
-
21
- if (processCreatedCallback) {
22
- processCreatedCallback(process);
23
- }
24
-
25
- childProcess.stdout.on('data', (data) => {
26
- if (verbose || showStdout) {
27
- res.log(data);
28
- }
29
- });
30
-
31
- childProcess.stderr.on('data', (data) => {
32
- if (verbosityLevel === constants.VERBOSITY_LEVEL_DEBUG) {
33
- res.log(data);
34
- } else {
35
- errors.push(data.toString());
36
- }
37
- });
38
-
39
- childProcess.on('error', (error) => {
40
- res.error(error);
41
- });
42
-
43
- childProcess.on('close', (code) => {
44
- if (code === 0) {
45
- if (verbose) {
46
- res.debug(
47
- `${command} ${args.join(' ')} exited with code ${code}`
48
- );
49
- }
50
- resolve();
51
- } else {
52
- if (verbosityLevel !== constants.VERBOSITY_LEVEL_DEBUG) {
53
- errors.forEach((error) => res.log(error));
54
- }
55
- reject(
56
- new Error(
57
- `${command} ${args.join(' ')} exited with code ${code}`
58
- )
59
- );
60
- }
61
- });
62
- });
63
- }
@@ -1,11 +0,0 @@
1
- import constants from './constants.js';
2
-
3
- export default function getVerbosityLevel(verbose, debug) {
4
- if (debug) {
5
- return constants.VERBOSITY_LEVEL_DEBUG;
6
- }
7
- if (verbose) {
8
- return constants.VERBOSITY_LEVEL_VERBOSE;
9
- }
10
- return constants.VERBOSITY_LEVEL_NORMAL;
11
- }
@@ -1,16 +0,0 @@
1
- import fs from 'fs-extra';
2
- import path from 'path';
3
-
4
- import constants from './constants.js';
5
-
6
- export default function getWhitelist() {
7
- return fs
8
- .readdir(constants.INSTANCE_TEMPLATE_DIRECTORY_PATH)
9
- .then((entries) => {
10
- return entries.map((entry) => path.basename(entry));
11
- })
12
- .then((whitelist) => {
13
- whitelist.push(...constants.WHITELIST);
14
- return whitelist;
15
- });
16
- }
@@ -1,45 +0,0 @@
1
- import fs from 'fs-extra';
2
- import path from 'path';
3
-
4
- import constants from './constants.js';
5
- import FontoxmlReviewManifest from './FontoxmlReviewManifest.js';
6
-
7
- export default function validateInstance(directoryPath) {
8
- const manifestFilePath = path.join(
9
- directoryPath,
10
- constants.MANIFEST_FILENAME
11
- );
12
- return fs
13
- .exists(directoryPath)
14
- .then((exists) => {
15
- if (!exists) {
16
- throw new Error(`Directory "${directoryPath}" does not exist.`);
17
- }
18
- })
19
- .then(() => fs.exists(manifestFilePath))
20
- .then((exists) => {
21
- // Verify fontoxmlReviewManifest file is present and valid.
22
- if (!exists) {
23
- throw new Error(
24
- 'The Fonto Review manifest file does not exist.'
25
- );
26
- } else {
27
- return FontoxmlReviewManifest.fromJsonFile(manifestFilePath);
28
- }
29
- })
30
- .then(() => {
31
- return Promise.all(
32
- constants.REQUIRED_CONFIGURATION.map((entryName) => {
33
- return fs
34
- .exists(path.join(directoryPath, entryName))
35
- .then((exists) => {
36
- if (!exists) {
37
- throw new Error(
38
- `Directory "${directoryPath}" does not contain a valid Fonto Review instance. Missing "${entryName}".`
39
- );
40
- }
41
- });
42
- })
43
- );
44
- });
45
- }
@@ -1,256 +0,0 @@
1
- import fs from 'fs-extra';
2
- import path from 'path';
3
-
4
- import cleanup from './utilities/cleanup.js';
5
- import constants from './utilities/copyWhitelistedFiles.js';
6
- import executeAndLog from './utilities/executeAndLog.js';
7
- import FontoxmlSchemaCompilerManifest from './utilities/FontoxmlSchemaCompilerManifest.js';
8
- import getVerbosityLevel from './utilities/getVerbosityLevel.js';
9
- import getWhitelist from './utilities/getWhitelist.js';
10
- import setEntryVisibility from './utilities/setEntryVisibility.js';
11
- import validateInstance from './utilities/validateInstance.js';
12
-
13
- export default function buildCommand(req, res) {
14
- res.caption(req.command.getLongName());
15
-
16
- const directoryPath = path.resolve(
17
- req.options.location ? req.options.location : process.cwd()
18
- );
19
- const temporaryDirectoryPath = path.join(
20
- directoryPath,
21
- constants.TEMPORARY_BUILD_DIRECTORY_NAME
22
- );
23
- const imageName = req.options['image-name']
24
- ? req.options['image-name']
25
- : constants.DEFAULT_IMAGE_NAME;
26
- const imageTag = req.options['image-tag']
27
- ? req.options['image-tag']
28
- : constants.DEFAULT_IMAGE_TAG;
29
- const manifestFilePath = path.join(
30
- directoryPath,
31
- constants.MANIFEST_FILENAME
32
- );
33
- const verbosityLevel = getVerbosityLevel(
34
- req.options.verbose,
35
- req.options.debug
36
- );
37
-
38
- let pidToKillOnForceExit = null;
39
- const setPidToKillOnForceExit = (process) => {
40
- pidToKillOnForceExit = process && process.pid;
41
- };
42
-
43
- // Ensure we cleanup before exiting.
44
- let stopping = false;
45
- process.on('SIGINT', (_code) => {
46
- if (stopping) {
47
- if (pidToKillOnForceExit) {
48
- process.kill(pidToKillOnForceExit);
49
- }
50
- process.exit();
51
- return;
52
- }
53
-
54
- stopping = true;
55
- res.log('Gracefully stopping... (press Ctrl+C again to force)');
56
- return cleanup(
57
- temporaryDirectoryPath,
58
- undefined,
59
- res,
60
- verbosityLevel
61
- ).then(process.exit);
62
- });
63
-
64
- return (
65
- validateInstance(directoryPath)
66
- // Cleanup possible remaining resources from a previous build or run.
67
- .then(() =>
68
- cleanup(temporaryDirectoryPath, undefined, res, verbosityLevel)
69
- )
70
- .then(() => {
71
- const destroySpinner = res.spinner(
72
- `Building the production image "${imageName}:${imageTag}" at "${directoryPath}"...`
73
- );
74
-
75
- // Retrieve data for the docker image
76
- return FontoxmlSchemaCompilerManifest.fromJsonFile(
77
- manifestFilePath
78
- ).then((manifestObj) => {
79
- const requestObj = {
80
- 'schema-compiler': {
81
- docker: {
82
- version: manifestObj.schemaCompilerVersion,
83
- },
84
- },
85
- };
86
-
87
- return req.fdt.license
88
- .getDataForProducts(requestObj)
89
- .catch((error) => {
90
- if (error.statusCode === 404) {
91
- error.solution =
92
- 'This error might be caused by requesting a nonexistent Fonto Schema Compiler version, please check your version.';
93
- }
94
- throw error;
95
- })
96
- .then((productData) => {
97
- const dockerData =
98
- productData.products['schema-compiler'].docker;
99
-
100
- // Create a hidden temporary directory.
101
- return (
102
- fs
103
- .mkdir(temporaryDirectoryPath)
104
- .then(() =>
105
- setEntryVisibility(
106
- temporaryDirectoryPath,
107
- false
108
- )
109
- )
110
- // Copy the instance files into the temporary directory.
111
- .then(() => {
112
- // Rewrite the version in the Dockerfile.
113
- return fs
114
- .readFile(
115
- path.join(
116
- constants.INSTANCE_BUILD_DIRECTORY_PATH,
117
- 'Dockerfile'
118
- ),
119
- 'utf8'
120
- )
121
- .then((dockerContent) =>
122
- dockerContent.replace(
123
- '${schemaCompilerImage}',
124
- dockerData.image
125
- )
126
- )
127
- .then((fixedDockerContent) =>
128
- fs.writeFile(
129
- path.join(
130
- temporaryDirectoryPath,
131
- 'Dockerfile'
132
- ),
133
- fixedDockerContent,
134
- 'utf8'
135
- )
136
- );
137
- })
138
- .then(() => getWhitelist())
139
- .then((whitelist) =>
140
- copyWhitelistedFiles(
141
- whitelist,
142
- directoryPath,
143
- path.join(
144
- temporaryDirectoryPath,
145
- 'instance'
146
- )
147
- )
148
- )
149
-
150
- // Pull the docker image
151
- .then(() => {
152
- return executeAndLog(
153
- res,
154
- 'docker',
155
- [
156
- 'login',
157
- dockerData.registry,
158
- '-u',
159
- dockerData.login,
160
- '-p',
161
- dockerData.password,
162
- ],
163
- null,
164
- constants.VERBOSITY_LEVEL_NORMAL,
165
- false,
166
- setPidToKillOnForceExit
167
- )
168
- .then(() =>
169
- executeAndLog(
170
- res,
171
- 'docker',
172
- ['pull', dockerData.image],
173
- null,
174
- verbosityLevel,
175
- false,
176
- setPidToKillOnForceExit
177
- )
178
- )
179
- .then(() =>
180
- executeAndLog(
181
- res,
182
- 'docker',
183
- [
184
- 'logout',
185
- dockerData.registry,
186
- ],
187
- null,
188
- constants.VERBOSITY_LEVEL_NORMAL,
189
- false,
190
- setPidToKillOnForceExit
191
- )
192
- )
193
- .catch(() => {
194
- throw new Error(
195
- 'Failed to retrieve the image file.'
196
- );
197
- });
198
- })
199
-
200
- // Build the docker image.
201
- .then(() =>
202
- executeAndLog(
203
- res,
204
- 'docker',
205
- [
206
- 'build',
207
- '-t',
208
- `${imageName}:${imageTag}`,
209
- '.',
210
- ],
211
- temporaryDirectoryPath,
212
- verbosityLevel,
213
- false,
214
- setPidToKillOnForceExit
215
- )
216
- )
217
- .then(() =>
218
- req.fdt.license.sendTelemetry({
219
- product: req.command.parent.name,
220
- type: 'docker',
221
- version:
222
- manifestObj.schemaCompilerVersion,
223
- action: req.command.name,
224
- })
225
- )
226
- .then(() => destroySpinner())
227
- );
228
- });
229
- });
230
- })
231
- // Cleanup temporary directory.
232
- .then(() =>
233
- cleanup(temporaryDirectoryPath, undefined, res, verbosityLevel)
234
- )
235
- .catch((error) => {
236
- if (!stopping) {
237
- res.notice(
238
- `See our documentation at ${constants.DOCUMENTATION_EXECUTE_ERROR} for help.`
239
- );
240
- }
241
-
242
- return cleanup(
243
- temporaryDirectoryPath,
244
- undefined,
245
- res,
246
- verbosityLevel
247
- )
248
- .then(() => {
249
- throw error;
250
- })
251
- .catch(() => {
252
- throw error;
253
- });
254
- })
255
- );
256
- }