@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,7 +1,10 @@
1
1
  import babel from '@babel/core';
2
2
  import os from 'os';
3
3
 
4
- import { isPre7170Editor } from '../../../../../editorVersions.js';
4
+ import {
5
+ isPre810Editor,
6
+ isPre7170Editor,
7
+ } from '../../../../../editorVersions.js';
5
8
  import SchemaSummary from '../../../../schema/src/api/SchemaSummary.js';
6
9
  import addCommentToAstNode, {
7
10
  trickRecastIntoKeepingStatementsTogether,
@@ -49,7 +52,7 @@ const buildParagraphNodeNameForPastingConfiguration = template(
49
52
  // Configuration constants.
50
53
  const PARAGRAPH_COUTERPART_ELEMENT_NAME = 'p';
51
54
 
52
- export function buildConfigurationSetUniqueIdConfigurationStatement(version) {
55
+ function buildConfigurationSetUniqueIdConfigurationStatement(version) {
53
56
  return buildConfigurationSetUniqueIdConfigurations({
54
57
  CONFIGURATION_VALUE: t.arrayExpression([
55
58
  isPre7170Editor(version)
@@ -65,13 +68,15 @@ export function buildConfigurationSetUniqueIdConfigurationStatement(version) {
65
68
  * @param {Object} compiledSchemaResultsByXsdPath The compiled schema for a package by xsd path.
66
69
  * @param {ASTNode[]} statements The statements node array to add the configuration and/or comments to.
67
70
  * @param {string} version The sdk version used to configure.
71
+ * @param {ASTNode} lastStatement The statement to add the comment to in case no new statement is created.
68
72
  *
69
- * @return {Promise}
73
+ * @return {Promise<void>}
70
74
  */
71
75
  async function addUniqueIdGenerationConfigurations(
72
76
  compiledSchemaResultsByXsdPath,
73
77
  statements,
74
- version
78
+ version,
79
+ lastStatement
75
80
  ) {
76
81
  // Check if an id attribute exists in one of the schemas.
77
82
  const idAttributeExists = Object.values(
@@ -110,7 +115,7 @@ async function addUniqueIdGenerationConfigurations(
110
115
  configurationSetUniqueIdConfigurationStatement
111
116
  );
112
117
  addCommentToAstNode(
113
- statements[statements.length - 1],
118
+ lastStatement,
114
119
  [
115
120
  ...comments,
116
121
  'Example:',
@@ -123,18 +128,16 @@ async function addUniqueIdGenerationConfigurations(
123
128
  }
124
129
 
125
130
  /**
126
- * Creates the config/configuration.ts/js file for the Editor.
131
+ * Generates the config/configuration.ts/js file for the Editor.
127
132
  *
128
- * @param {string} configConfigurationJsFilePath The path to the configuration file.
129
133
  * @param {Object} prefixByNamespaceUri The namespace URIs with their prefix.
130
134
  * @param {Array} addons The selected addons for this editor instance.
131
135
  * @param {Object} compiledSchemaResultsByXsdPath The compiled schema for a package by xsd path.
132
136
  * @param {string} version The sdk version used to configure.
133
137
  *
134
- * @return {Promise}
138
+ * @return {Promise<Program>}
135
139
  */
136
- export default async function createConfigConfiguration(
137
- configConfigurationJsFilePath,
140
+ export async function generateConfigConfiguration(
138
141
  prefixByNamespaceUri,
139
142
  addons,
140
143
  compiledSchemaResultsByXsdPath,
@@ -160,16 +163,47 @@ export default async function createConfigConfiguration(
160
163
  );
161
164
  importStatements.push(configurationManagerImportStatement);
162
165
 
163
- // Enable the 'correct selection after enter' experiment.
164
- const correctSelectionAfterEnterConfigurationStatement =
165
- buildCorrectSelectionAfterEnterConfiguration();
166
- addCommentToAstNode(correctSelectionAfterEnterConfigurationStatement, [
167
- 'Enable an experiment where, when pressing enter at the edges of elements, the cursor is prevented',
168
- 'from ending up in positions that are not reachable using the cursor keys.',
169
- 'For more information:',
170
- 'https://documentation.fontoxml.com/latest/enable-experiment-correct-selection-after-enter-8d2ce78e26b8',
171
- ]);
172
- statements.push(correctSelectionAfterEnterConfigurationStatement);
166
+ // Get all prefix and namespace entries, sorted naturally by prefix.
167
+ const prefixByNamespaceUriEntries = Object.entries(
168
+ prefixByNamespaceUri
169
+ ).sort(([_nsA, prefixA], [_nsB, prefixB]) =>
170
+ prefixA === prefixB
171
+ ? 0
172
+ : prefixA === null
173
+ ? 1
174
+ : prefixB === null
175
+ ? -1
176
+ : prefixA.localeCompare(prefixB, undefined, {
177
+ numeric: true,
178
+ sensitivity: 'base',
179
+ })
180
+ );
181
+ if (prefixByNamespaceUriEntries.length) {
182
+ const namespaceManagerImport = buildNamespaceManagerImport();
183
+ trickRecastIntoKeepingStatementsTogether(namespaceManagerImport);
184
+ importStatements.push(namespaceManagerImport);
185
+ }
186
+
187
+ // Import xq for editor versions 7.17 or higher.
188
+ if (!isPre7170Editor(version)) {
189
+ const xqImportStatement = buildXqImport();
190
+ trickRecastIntoKeepingStatementsTogether(xqImportStatement);
191
+ importStatements.push(xqImportStatement);
192
+ }
193
+
194
+ // Set an experimental flag for editor versions 8.0.x or lower.
195
+ if (isPre810Editor(version)) {
196
+ const correctSelectionAfterEnterConfigurationStatement =
197
+ buildCorrectSelectionAfterEnterConfiguration();
198
+ // Enable the 'correct selection after enter' experiment.
199
+ addCommentToAstNode(correctSelectionAfterEnterConfigurationStatement, [
200
+ 'Enable an experiment where, when pressing enter at the edges of elements, the cursor is prevented',
201
+ 'from ending up in positions that are not reachable using the cursor keys.',
202
+ 'For more information:',
203
+ 'https://documentation.fontoxml.com/latest/enable-experiment-correct-selection-after-enter-8d2ce78e26b8',
204
+ ]);
205
+ statements.push(correctSelectionAfterEnterConfigurationStatement);
206
+ }
173
207
 
174
208
  // Configures the clipboard configuration option 'paragraph-node-name-for-pasting'.
175
209
  // Skips this configuration when the 'fontoxml-dita' add-on is enabled, since that add-on already configures this option.
@@ -219,7 +253,8 @@ export default async function createConfigConfiguration(
219
253
  comments.push('Example:');
220
254
  comments.push(...exampleCode.split(os.EOL).filter(Boolean));
221
255
  addCommentToAstNode(
222
- correctSelectionAfterEnterConfigurationStatement,
256
+ statements[statements.length - 1] ||
257
+ importStatements[importStatements.length - 1],
223
258
  comments,
224
259
  true,
225
260
  true
@@ -231,28 +266,13 @@ export default async function createConfigConfiguration(
231
266
  await addUniqueIdGenerationConfigurations(
232
267
  compiledSchemaResultsByXsdPath,
233
268
  statements,
234
- version
235
- );
236
-
237
- // Get all prefix and namespace entries, sorted naturally by prefix.
238
- const prefixByNamespaceUriEntries = Object.entries(
239
- prefixByNamespaceUri
240
- ).sort(([_nsA, prefixA], [_nsB, prefixB]) =>
241
- prefixA === prefixB
242
- ? 0
243
- : prefixA === null
244
- ? 1
245
- : prefixB === null
246
- ? -1
247
- : prefixA.localeCompare(prefixB, undefined, {
248
- numeric: true,
249
- sensitivity: 'base',
250
- })
269
+ version,
270
+ statements[statements.length - 1] ||
271
+ importStatements[importStatements.length - 1]
251
272
  );
252
273
 
253
274
  // Register all namespaces.
254
275
  if (prefixByNamespaceUriEntries.length) {
255
- importStatements.push(buildNamespaceManagerImport());
256
276
  let isFirstAddedNamespaceStatement = true;
257
277
  for (const [namespaceUri, prefix] of prefixByNamespaceUriEntries) {
258
278
  const namespaceConfigurationStatement =
@@ -281,16 +301,34 @@ export default async function createConfigConfiguration(
281
301
  }
282
302
  }
283
303
 
284
- // Import xq for editor versions 7.17 or higher.
285
- if (!isPre7170Editor(version)) {
286
- importStatements.push(buildXqImport());
287
- }
288
-
289
304
  // Generate the AST for the config/configuration.ts/js file.
290
- const configConfigurationJsAst = t.program([
291
- ...importStatements,
292
- ...statements,
293
- ]);
305
+ return t.program([...importStatements, ...statements]);
306
+ }
307
+
308
+ /**
309
+ * Creates the config/configuration.ts/js file for the Editor.
310
+ *
311
+ * @param {string} configConfigurationJsFilePath The path to the configuration file.
312
+ * @param {Object} prefixByNamespaceUri The namespace URIs with their prefix.
313
+ * @param {Array} addons The selected addons for this editor instance.
314
+ * @param {Object} compiledSchemaResultsByXsdPath The compiled schema for a package by xsd path.
315
+ * @param {string} version The sdk version used to configure.
316
+ *
317
+ * @return {Promise}
318
+ */
319
+ export default async function createConfigConfiguration(
320
+ configConfigurationJsFilePath,
321
+ prefixByNamespaceUri,
322
+ addons,
323
+ compiledSchemaResultsByXsdPath,
324
+ version
325
+ ) {
326
+ const configConfigurationJsAst = await generateConfigConfiguration(
327
+ prefixByNamespaceUri,
328
+ addons,
329
+ compiledSchemaResultsByXsdPath,
330
+ version
331
+ );
294
332
  await writeAstProgramToFile(
295
333
  configConfigurationJsFilePath,
296
334
  configConfigurationJsAst
@@ -1,5 +1,4 @@
1
- import requestPromise from 'request-promise-native';
2
- import url from 'url';
1
+ import fetch, { File, FormData } from 'node-fetch';
3
2
 
4
3
  /**
5
4
  * Compile a schema zip archive using the schema compile service.
@@ -12,34 +11,29 @@ import url from 'url';
12
11
  export default async (baseUrl, compressedSchema) => {
13
12
  let response;
14
13
  try {
15
- response = await requestPromise.post(
16
- url.resolve(baseUrl, '/api/compile'),
17
- {
18
- formData: {
19
- data: {
20
- options: {
21
- contentType: 'application/zip',
22
- filename: 'schema.zip',
23
- },
24
- value: compressedSchema,
25
- },
26
- },
27
- resolveWithFullResponse: true,
28
- simple: false,
29
- }
14
+ const form = new FormData();
15
+ form.set(
16
+ 'schema',
17
+ new File([compressedSchema], 'schema.zip', {
18
+ type: 'application/zip',
19
+ }),
20
+ 'schema.zip'
30
21
  );
22
+
23
+ const compileUrl = new URL('/api/compile', baseUrl);
24
+ response = await fetch(compileUrl.href, { method: 'POST', body: form });
31
25
  } catch (_error) {
32
26
  throw new Error('Could not connect to the schema compile service.');
33
27
  }
34
28
 
35
- switch (response.statusCode) {
29
+ switch (response.status) {
36
30
  case 200:
37
31
  case 400:
38
32
  try {
39
- return JSON.parse(response.body);
40
- } catch (_error) {
33
+ return await response.json();
34
+ } catch (_err) {
41
35
  throw new Error(
42
- 'Invalid response data from the schema compile service.'
36
+ `Invalid response data from the schema compile service.`
43
37
  );
44
38
  }
45
39
  case 401:
@@ -49,7 +43,7 @@ export default async (baseUrl, compressedSchema) => {
49
43
  );
50
44
  default:
51
45
  throw new Error(
52
- `Invalid response from the schema compile service (${response.statusCode}).`
46
+ `Invalid response from the schema compile service (${response.status}).`
53
47
  );
54
48
  }
55
49
  };
@@ -90,6 +90,14 @@ async function createPackageSchemaLocationsJsFile(
90
90
  ]);
91
91
 
92
92
  await writeAstProgramToFile(schemaLocationsFilePath, schemaLocationsJsAst);
93
+
94
+ await fs.remove(
95
+ path.join(
96
+ packageDirectoryPath,
97
+ 'src',
98
+ useTypeScript ? 'SCHEMA_LOCATIONS.js' : 'SCHEMA_LOCATIONS.ts'
99
+ )
100
+ );
93
101
  }
94
102
 
95
103
  /**
@@ -2,6 +2,80 @@ import fs from 'fs-extra';
2
2
  import os from 'os';
3
3
  import path from 'path';
4
4
 
5
+ /**
6
+ * Validate the schema fonto.json file contents.
7
+ *
8
+ * @param {string} fontoJson The schema fonto.json contents.
9
+ *
10
+ * @throws If the schema fonto Json is invalid.
11
+ */
12
+ export function validateSchemaFontoJson(fontoJson) {
13
+ if (!fontoJson.rootSchemas) {
14
+ throw new Error('Missing "rootSchemas" property in fonto.json.');
15
+ }
16
+
17
+ if (
18
+ typeof fontoJson.rootSchemas !== 'object' ||
19
+ Array.isArray(fontoJson.rootSchemas)
20
+ ) {
21
+ throw new Error(
22
+ 'The "rootSchemas" property is not an object in fonto.json.'
23
+ );
24
+ }
25
+
26
+ const xsdPaths = Object.keys(fontoJson.rootSchemas);
27
+ const requireLocations = xsdPaths.length > 1;
28
+ xsdPaths.forEach((xsdPath) => {
29
+ const schemaPackage = fontoJson.rootSchemas[xsdPath];
30
+
31
+ if (typeof schemaPackage !== 'object' || Array.isArray(schemaPackage)) {
32
+ throw new Error(
33
+ `Root schema "${xsdPath}" is not an object in fonto.json.`
34
+ );
35
+ }
36
+
37
+ if (!schemaPackage.packageName) {
38
+ throw new Error(
39
+ `Root schema "${xsdPath}" does not have a valid "packageName" property in fonto.json.`
40
+ );
41
+ }
42
+
43
+ // If there are multiple root schemas, the location property is required.
44
+ if (
45
+ requireLocations &&
46
+ (!schemaPackage.locations || !schemaPackage.locations.length)
47
+ ) {
48
+ const error = new Error(
49
+ !schemaPackage.locations
50
+ ? `Root schema "${xsdPath}" is missing the "locations" property, which is required when having multipe root schemas in fonto.json.`
51
+ : `Root schema "${xsdPath}" has an empty "locations" property, which is not allowed when having multipe root schemas in fonto.json.`
52
+ );
53
+
54
+ const solution = [
55
+ 'Make sure to set locations for each schema in fonto.json when having multipe root schemas.',
56
+ 'See: https://documentation.fontoxml.com/latest/schema-experiences-7d818ffb9db5',
57
+ ];
58
+
59
+ error.solution = solution.join(os.EOL);
60
+ throw error;
61
+ }
62
+
63
+ // Validate the locations property, if there is any.
64
+ if (
65
+ schemaPackage.locations &&
66
+ (!Array.isArray(schemaPackage.locations) ||
67
+ schemaPackage.locations.some(
68
+ (schemaLocation) =>
69
+ typeof schemaLocation !== 'string' || !schemaLocation
70
+ ))
71
+ ) {
72
+ throw new Error(
73
+ `Root schema "${xsdPath}" has an invalid "locations" property in fonto.json.`
74
+ );
75
+ }
76
+ });
77
+ }
78
+
5
79
  /**
6
80
  * Get the schema fonto.json file contents.
7
81
  *
@@ -10,7 +84,7 @@ import path from 'path';
10
84
  * @return {Promise<Object>} Returns the contents of fonto.json.
11
85
  *
12
86
  * @async
13
- * @throws If the required directory or files do not exist.
87
+ * @throws If the required directory or files do not exist or the schema fonto json is invalid.
14
88
  */
15
89
  export default async function getSchemaFontoJson(inputPath) {
16
90
  if (!inputPath) {
@@ -38,53 +112,7 @@ export default async function getSchemaFontoJson(inputPath) {
38
112
  throw new Error('The required fonto.json could not be parsed.');
39
113
  }
40
114
 
41
- if (!fontoJson.rootSchemas) {
42
- throw new Error('Missing rootSchemas property in fonto.json.');
43
- }
44
-
45
- const xsdPaths = Object.keys(fontoJson.rootSchemas);
46
- xsdPaths.forEach((xsdPath) => {
47
- const schemaPackage = fontoJson.rootSchemas[xsdPath];
48
- if (!schemaPackage.packageName) {
49
- throw new Error(
50
- `Root schema "${xsdPath}" has no package name in fonto.json.`
51
- );
52
- }
53
-
54
- if (
55
- schemaPackage.locations &&
56
- (!Array.isArray(schemaPackage.locations) ||
57
- schemaPackage.locations.some(
58
- (schemaLocation) => typeof schemaLocation !== 'string'
59
- ))
60
- ) {
61
- throw new Error(
62
- `Root schema "${xsdPath}" has invalid locations in fonto.json.`
63
- );
64
- }
65
-
66
- // In case of referencing multiple schemas, verify that each has valid locations.
67
- if (
68
- xsdPaths.length > 1 &&
69
- (!schemaPackage.locations ||
70
- !schemaPackage.locations.length ||
71
- schemaPackage.locations.some(
72
- (schemaLocation) => !schemaLocation
73
- ))
74
- ) {
75
- const error = new Error(
76
- 'One or more schemas in fonto.json do not have valid locations associated.'
77
- );
78
-
79
- const solution = [
80
- 'Make sure to set locations for each schema in fonto.json.',
81
- 'See: https://documentation.fontoxml.com/latest/schema-experiences-7d818ffb9db5',
82
- ];
83
-
84
- error.solution = solution.join(os.EOL);
85
- throw error;
86
- }
87
- });
115
+ validateSchemaFontoJson(fontoJson);
88
116
 
89
117
  return fontoJson;
90
118
  }
@@ -31,7 +31,12 @@ function zipSchemaSource(inputPath) {
31
31
  resolve(Buffer.concat(buffers));
32
32
  });
33
33
 
34
- zipArchive.glob('**/*', {
34
+ // Use .glob here, instead of .file, to properly handle symlinked fonto.json files
35
+ zipArchive.glob('fonto.json', {
36
+ cwd: inputPath,
37
+ follow: true,
38
+ });
39
+ zipArchive.glob('**/*.@(xml|xsd)', {
35
40
  cwd: inputPath,
36
41
  follow: true,
37
42
  });
@@ -1,3 +1,4 @@
1
+ import fs from 'fs-extra';
1
2
  import inquirer from 'inquirer';
2
3
  import path from 'path';
3
4
 
@@ -11,6 +12,29 @@ import schemaZipHelpers from './api/schema/zipHelpers.js';
11
12
  const SCHEMA_COMPILE_DOCUMENTATION_URL =
12
13
  'https://documentation.fontoxml.com/latest/create-a-schema-bundle-d186eeb79200';
13
14
 
15
+ /**
16
+ * Helper function to test whether to use TypeScript conditionally.
17
+ *
18
+ * @param {boolean} isEditorRepositoryPath Whether the command is run from an editor repo
19
+ * @param {boolean} editorSupportsTypeScript Whether the editor platform directory contains tsconfig.json
20
+ * @param {boolean} hasSchemaLocationsJs Whether there are existing SCHEMA_LOCATIONS.js files
21
+ * @param {boolean} hasSchemaLocationsTs Whether there are existing SCHEMA_LOCATIONS.ts files
22
+ *
23
+ * @return {boolean}
24
+ */
25
+ export function shouldUseTypeScriptForSchemaPackages(
26
+ isEditorRepositoryPath,
27
+ editorSupportsTypeScript,
28
+ hasSchemaLocationsJs,
29
+ hasSchemaLocationsTs
30
+ ) {
31
+ // If editor supports TS or if not running in editor, default to TS unless there are existing JS files and no existing TS files
32
+ // If editor does not support TS, default to JS
33
+ return editorSupportsTypeScript || !isEditorRepositoryPath
34
+ ? !(hasSchemaLocationsJs && !hasSchemaLocationsTs)
35
+ : false;
36
+ }
37
+
14
38
  export default async function schemaCompileCommand(req, res) {
15
39
  res.caption(req.command.getLongName());
16
40
 
@@ -96,7 +120,7 @@ export default async function schemaCompileCommand(req, res) {
96
120
  res.list(schemaCompileResult.error.details, '-');
97
121
  }
98
122
  res.outdent();
99
- throw new Error('The schema(s) failed to compiled.');
123
+ throw new Error('The schema(s) failed to compile.');
100
124
  }
101
125
 
102
126
  // Output schema warnings.
@@ -122,7 +146,20 @@ export default async function schemaCompileCommand(req, res) {
122
146
  fontoJson.rootSchemas,
123
147
  false
124
148
  );
149
+
150
+ let hasSchemaLocationsJs = false;
151
+ let hasSchemaLocationsTs = false;
152
+
125
153
  if (schemaPackagesWithExistingFiles.length) {
154
+ for (const file of schemaPackagesWithExistingFiles) {
155
+ if (path.basename(file) === 'SCHEMA_LOCATIONS.js') {
156
+ hasSchemaLocationsJs = true;
157
+ }
158
+ if (path.basename(file) === 'SCHEMA_LOCATIONS.ts') {
159
+ hasSchemaLocationsTs = true;
160
+ }
161
+ }
162
+
126
163
  res.caption('Existing files to be overwritten');
127
164
  res.log(
128
165
  `In${isEditorRepositoryPath ? ' editor' : ''} path "${outputPath}".`
@@ -161,6 +198,17 @@ export default async function schemaCompileCommand(req, res) {
161
198
  }
162
199
  }
163
200
 
201
+ const hasTsConfig = await fs.pathExists(
202
+ path.join(outputPath, 'platform', 'tsconfig.json')
203
+ );
204
+ const platformHasTsConfig = isEditorRepositoryPath && hasTsConfig;
205
+ const useTypeScript = shouldUseTypeScriptForSchemaPackages(
206
+ isEditorRepositoryPath,
207
+ platformHasTsConfig,
208
+ hasSchemaLocationsJs,
209
+ hasSchemaLocationsTs
210
+ );
211
+
164
212
  // Create schema packages.
165
213
  destroySpinner = res.spinner(
166
214
  'Creating package(s) for the compiled schema(s)...'
@@ -169,7 +217,8 @@ export default async function schemaCompileCommand(req, res) {
169
217
  await createSchemaPackages(
170
218
  outputPath,
171
219
  fontoJson.rootSchemas,
172
- schemaCompileResult
220
+ schemaCompileResult,
221
+ useTypeScript
173
222
  );
174
223
  } catch (error) {
175
224
  throw new res.ErrorWithInnerError(
@@ -1,47 +1,85 @@
1
- import babel from '@babel/core';
2
1
  import assert from 'assert';
2
+ import fs from 'fs-extra';
3
+ import path from 'path';
4
+ import { fileURLToPath } from 'url';
3
5
 
4
6
  import createPrettifiedCode from '../../../src/api/createPrettifiedCode.js';
5
- import { buildConfigurationSetUniqueIdConfigurationStatement } from '../../../src/api/init/createConfigConfiguration.js';
7
+ import { generateConfigConfiguration } from '../../../src/api/init/createConfigConfiguration.js';
8
+ import getPrefixByNamespaceUri from '../../../src/api/schema/getPrefixByNamespaceUri.js';
6
9
 
7
- const t = babel.types;
10
+ const __filename = fileURLToPath(import.meta.url);
11
+ const __dirname = path.dirname(__filename);
8
12
 
9
13
  describe('createConfigConfiguration', () => {
10
- it('works for pre 7.17 versions', async () => {
11
- const configStatement =
12
- buildConfigurationSetUniqueIdConfigurationStatement('7.16');
13
- const program = t.program([configStatement]);
14
+ it('works for versions pre 7.17.x', async () => {
15
+ // < 7.17.x (+experiment, -xq, -dita, -p, -namespaces, -id)
16
+ const abstractSchema = await fs.readJSON(
17
+ path.resolve(
18
+ __dirname,
19
+ '../schema/fixtures/abstract-test/compiledSchema.json'
20
+ )
21
+ );
22
+ const program = await generateConfigConfiguration(
23
+ getPrefixByNamespaceUri(abstractSchema),
24
+ [],
25
+ abstractSchema,
26
+ '7.16.0'
27
+ );
28
+ const stringOutcome = await createPrettifiedCode(program);
29
+
30
+ const fixture = await fs.readFile(
31
+ path.join(__dirname, 'fixtures/configjs-7160.js'),
32
+ 'utf8'
33
+ );
34
+
35
+ assert.strictEqual(stringOutcome, fixture);
36
+ });
37
+
38
+ it('works for versions 8.0.0 to 8.1.0', async () => {
39
+ // 8.0.0 - 8.1.0 (+experiment, +xq, -dita, +p, ?namespaces, ?id)
40
+ const abstractSchema = await fs.readJSON(
41
+ path.resolve(
42
+ __dirname,
43
+ '../schema/fixtures/training-schema-bundle/compiledSchema.json'
44
+ )
45
+ );
46
+ const program = await generateConfigConfiguration(
47
+ getPrefixByNamespaceUri(abstractSchema),
48
+ [],
49
+ abstractSchema,
50
+ '8.0.0'
51
+ );
14
52
  const stringOutcome = await createPrettifiedCode(program);
15
- assert.strictEqual(
16
- stringOutcome,
17
- `configurationManager.set('unique-id-configurations', [
18
- {
19
- selector: 'self::*',
20
- namespaceURI: null,
21
- localName: 'id',
22
- strategy: 'unique-for-document',
23
- },
24
- ]);
25
- `
53
+
54
+ const fixture = await fs.readFile(
55
+ path.join(__dirname, 'fixtures/configjs-800.js'),
56
+ 'utf8'
26
57
  );
58
+
59
+ assert.strictEqual(stringOutcome, fixture);
27
60
  });
28
61
 
29
- it('works for 7.17 and up', async () => {
30
- const configStatement =
31
- buildConfigurationSetUniqueIdConfigurationStatement('7.17');
32
- const program = t.program([configStatement]);
62
+ it('works for versions 8.1.x and up', async () => {
63
+ // > 8.1.x (-experiment, +xq, +dita, -p, +namespaces, +id)
64
+ const abstractSchema = await fs.readJSON(
65
+ path.resolve(
66
+ __dirname,
67
+ '../schema/fixtures/dita-example-schema-bundle/compiledSchema.json'
68
+ )
69
+ );
70
+ const program = await generateConfigConfiguration(
71
+ getPrefixByNamespaceUri(abstractSchema),
72
+ ['fontoxml-dita'],
73
+ abstractSchema,
74
+ '8.1.0'
75
+ );
33
76
  const stringOutcome = await createPrettifiedCode(program);
34
- assert.strictEqual(
35
- stringOutcome,
36
- `configurationManager.set('unique-id-configurations', [
37
- {
38
- selector: xq\`self::*\`,
39
- namespaceURI: null,
40
- localName: 'id',
41
- strategy: 'unique-for-document',
42
- },
43
- ]);
44
- `
77
+
78
+ const fixture = await fs.readFile(
79
+ path.join(__dirname, 'fixtures/configjs-810.js'),
80
+ 'utf8'
45
81
  );
82
+
83
+ assert.strictEqual(stringOutcome, fixture);
46
84
  });
47
85
  });