@fontoxml/fontoxml-development-tools 3.9.0-beta.2 → 3.9.0-beta.5

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 (49) hide show
  1. package/npm-shrinkwrap.json +13902 -22456
  2. package/package.json +13 -15
  3. package/src/addModulesToApp.js +1 -1
  4. package/src/modules/connectors/index.js +1 -1
  5. package/src/modules/core/src/command.module.js +1 -1
  6. package/src/modules/editor/dev-cms/connectors-cms-standard/configureAssetPostRouteHandler.js +0 -11
  7. package/src/modules/editor/dev-cms/connectors-cms-standard/configureConnectorsCmsStandardAssetRouter.js +0 -3
  8. package/src/modules/editor/index.js +1 -1
  9. package/src/modules/editor/src/commands/command.run.controller.js +12 -7
  10. package/src/modules/editor/src/getAppManifest.js +3 -3
  11. package/src/modules/editor/src/getWebpackConfig.js +160 -446
  12. package/src/modules/editor/src/getWebpackDevMiddlewareConfig.js +9 -16
  13. package/src/modules/editor/src/helpers/getNamesAndPaths.js +167 -0
  14. package/src/modules/editor/src/helpers/normalisePath.js +2 -2
  15. package/src/modules/editor/src/templates/app-entry.ts +66 -0
  16. package/src/modules/editor/src/templates/package.json +3 -0
  17. package/src/modules/editor/src/webpackLoaders/generatedLoader.cjs +88 -65
  18. package/src/modules/editor/src/webpackLoaders/platformSourceMapLoader.cjs +8 -10
  19. package/src/modules/editor/src/webpackLoaders/symbolLoader.cjs +7 -7
  20. package/src/modules/editor/src/webpackLoaders/vendorsSourceMapLoader.cjs +3 -5
  21. package/src/modules/editor/src/webpackPlugins/CopyPlugin.js +237 -171
  22. package/src/modules/editor/src/webpackPlugins/DependenciesInLoadOrderPlugin.js +12 -4
  23. package/src/modules/editor/src/webpackPlugins/FdtOutputPlugin.js +95 -102
  24. package/src/modules/editor/src/webpackPlugins/RemoveExplicitExtensionResolvePlugin.js +32 -21
  25. package/src/modules/editor/src/webpackPlugins/ResolveImportAliasPlugin.js +18 -10
  26. package/src/modules/editor/src/webpackPlugins/UnitTestPlugin.js +24 -15
  27. package/src/modules/editor-pre-7-7-0/instanceTemplate/packages/editor-masthead/src/Masthead.jsx +30 -33
  28. package/src/modules/editor-pre-7-7-0/instanceTemplate/packages/editor-masthead/src/install.js +2 -2
  29. package/src/modules/editor-pre-7-7-0/instanceTemplate/packages/editor-masthead/src/toolbars/ExampleToolbar.jsx +4 -4
  30. package/src/modules/editor-pre-7-7-0/instanceTemplateTypeScript/config/.gitkeep +0 -0
  31. package/src/modules/editor-pre-7-7-0/instanceTemplateTypeScript/config.js +12 -0
  32. package/src/modules/editor-pre-7-7-0/instanceTemplateTypeScript/dev-cms/files/.gitkeep +0 -0
  33. package/src/modules/editor-pre-7-7-0/instanceTemplateTypeScript/package.json +5 -0
  34. package/src/modules/editor-pre-7-7-0/instanceTemplateTypeScript/packages/editor-masthead/src/Masthead.tsx +39 -0
  35. package/src/modules/editor-pre-7-7-0/instanceTemplateTypeScript/packages/editor-masthead/src/install.ts +7 -0
  36. package/src/modules/editor-pre-7-7-0/instanceTemplateTypeScript/packages/editor-masthead/src/toolbars/ExampleToolbar.tsx +20 -0
  37. package/src/modules/editor-pre-7-7-0/instanceTemplateTypeScript/platform/.gitkeep +0 -0
  38. package/src/modules/editor-pre-7-7-0/instanceTemplateTypeScript/tsconfig.json +6 -0
  39. package/src/modules/editor-pre-7-7-0/src/api/init/checkEditorDestination.js +1 -0
  40. package/src/modules/editor-pre-7-7-0/src/api/init/createConfigConfiguration.js +17 -22
  41. package/src/modules/editor-pre-7-7-0/src/api/init/createSchemaExperienceResolver.js +19 -15
  42. package/src/modules/editor-pre-7-7-0/src/api/schema/checkIfCompiledSchemaOverwritesFiles.js +5 -5
  43. package/src/modules/editor-pre-7-7-0/src/api/schema/createSchemaExperiencePackages.js +104 -46
  44. package/src/modules/editor-pre-7-7-0/src/api/schema/createSchemaPackages.js +32 -26
  45. package/src/modules/editor-pre-7-7-0/src/command.init.controller.js +26 -17
  46. package/src/modules/editor-pre-7-7-0/src/command.init.js +6 -0
  47. package/src/modules/editor-pre-7-7-0/src/command.upgrade.controller.js +25 -0
  48. package/src/modules/editor/dev-cms/connectors-cms-standard/configureAssetGetRouteHandler.js +0 -29
  49. package/src/modules/editor/src/templates/app-entry.cjs +0 -69
@@ -36,8 +36,8 @@ async function createPackageManifestJsonFile(packageDirectoryPath) {
36
36
  * Create the schema file for a specific package.
37
37
  *
38
38
  * @param {string} packageDirectoryPath The path to a single package directory.
39
- * @param {string} packageName The package name.
40
- * @param {Object} schemaData The schema data for this package.
39
+ * @param {string} packageName The package name.
40
+ * @param {Object} schemaData The schema data for this package.
41
41
  *
42
42
  * @return {Promise}
43
43
  */
@@ -58,25 +58,27 @@ async function createPackageSchemaJsonFile(
58
58
  }
59
59
 
60
60
  /**
61
- * Create the SCHEMA_LOCATIONS.js file for a specific package.
61
+ * Create the SCHEMA_LOCATIONS.ts/js file for a specific package.
62
62
  *
63
- * @param {string} packageDirectoryPath The path to a single package directory.
64
- * @param {Array<string>} schemaLocations An array of schema locations for this package.
63
+ * @param {string} packageDirectoryPath The path to a single package directory.
64
+ * @param {Array<string>} schemaLocations An array of schema locations for this package.
65
+ * @param {boolean} useTypeScript Output TypeScript instead of JavaScript.
65
66
  *
66
67
  * @return {Promise}
67
68
  */
68
69
  async function createPackageSchemaLocationsJsFile(
69
70
  packageDirectoryPath,
70
- schemaLocations = []
71
+ schemaLocations = [],
72
+ useTypeScript
71
73
  ) {
72
- const t = babel.types;
73
- // @TODO: @TS: Remove file extensions from imports in generated imports when
74
- // supporting TS configuration.
75
- const schemaLocationsJsFilePath = path.join(
74
+ const { types: t } = babel;
75
+
76
+ const schemaLocationsFilePath = path.join(
76
77
  packageDirectoryPath,
77
78
  'src',
78
- 'SCHEMA_LOCATIONS.js'
79
+ `SCHEMA_LOCATIONS${useTypeScript ? '.ts' : '.js'}`
79
80
  );
81
+
80
82
  const schemaLocationsJsAst = t.program([
81
83
  t.exportDefaultDeclaration(
82
84
  t.arrayExpression(
@@ -86,19 +88,18 @@ async function createPackageSchemaLocationsJsFile(
86
88
  )
87
89
  ),
88
90
  ]);
89
- await writeAstProgramToFile(
90
- schemaLocationsJsFilePath,
91
- schemaLocationsJsAst
92
- );
91
+
92
+ await writeAstProgramToFile(schemaLocationsFilePath, schemaLocationsJsAst);
93
93
  }
94
94
 
95
95
  /**
96
96
  * Create a schema package from a compiled schema.
97
97
  *
98
- * @param {string} outputPath The path of the Fonto Editor, or the schema source directory.
99
- * @param {Object} schemaPackagesByXsdPath The package information by xsd path.
100
- * @param {Object} compiledSchemaResultsByXsdPath The compiled schema for a package by xsd path.
101
- * @param {string} xsdPath The path of the xsd file for this package.
98
+ * @param {string} outputPath The path of the Fonto Editor, or the schema source directory.
99
+ * @param {Object} schemaPackagesByXsdPath The package information by xsd path.
100
+ * @param {Object} compiledSchemaResultsByXsdPath The compiled schema for a package by xsd path.
101
+ * @param {string} xsdPath The path of the xsd file for this package.
102
+ * @param {boolean} useTypeScript Output TypeScript instead of JavaScript.
102
103
  *
103
104
  * @return {Promise}
104
105
  */
@@ -106,7 +107,8 @@ async function createSchemaPackageFromCompiledSchemaResults(
106
107
  outputPath,
107
108
  schemaPackagesByXsdPath,
108
109
  compiledSchemaResultsByXsdPath,
109
- xsdPath
110
+ xsdPath,
111
+ useTypeScript
110
112
  ) {
111
113
  // Resolve the schema package directory path.
112
114
  const schemaPackage = schemaPackagesByXsdPath[xsdPath];
@@ -124,7 +126,8 @@ async function createSchemaPackageFromCompiledSchemaResults(
124
126
  ),
125
127
  await createPackageSchemaLocationsJsFile(
126
128
  schemaPackageDirectoryPath,
127
- schemaPackage.locations
129
+ schemaPackage.locations,
130
+ useTypeScript
128
131
  ),
129
132
  ]);
130
133
  }
@@ -133,16 +136,18 @@ async function createSchemaPackageFromCompiledSchemaResults(
133
136
  * Create all schema packages, will also create the fonto-manifest.json file when the package
134
137
  * directory does not yet exists.
135
138
  *
136
- * @param {string} outputPath The path of the Fonto Editor, or the schema source directory.
137
- * @param {Object} schemaPackagesByXsdPath The package information by xsd path.
138
- * @param {Object} compiledSchemaResultsByXsdPath The compiled schema for a package by xsd path.
139
+ * @param {string} outputPath The path of the Fonto Editor, or the schema source directory.
140
+ * @param {Object} schemaPackagesByXsdPath The package information by xsd path.
141
+ * @param {Object} compiledSchemaResultsByXsdPath The compiled schema for a package by xsd path.
142
+ * @param {boolean} useTypeScript Output TypeScript instead of JavaScript.
139
143
  *
140
144
  * @return {Promise}
141
145
  */
142
146
  export default async function createSchemaPackages(
143
147
  outputPath,
144
148
  schemaPackagesByXsdPath,
145
- compiledSchemaResultsByXsdPath
149
+ compiledSchemaResultsByXsdPath,
150
+ useTypeScript
146
151
  ) {
147
152
  await Promise.all(
148
153
  Object.keys(schemaPackagesByXsdPath).map((xsdPath) => {
@@ -150,7 +155,8 @@ export default async function createSchemaPackages(
150
155
  path.resolve(outputPath),
151
156
  schemaPackagesByXsdPath,
152
157
  compiledSchemaResultsByXsdPath,
153
- xsdPath
158
+ xsdPath,
159
+ useTypeScript
154
160
  );
155
161
  })
156
162
  );
@@ -4,7 +4,7 @@ import path from 'path';
4
4
  import unzipper from 'unzipper';
5
5
  import { fileURLToPath } from 'url';
6
6
 
7
- import { isNightly, isPre770Editor } from '../../../editorVersions.js';
7
+ import { isNightly } from '../../../editorVersions.js';
8
8
  import addonsAddDependencies from './api/addonsAddDependencies.js';
9
9
  import createMessageTemplate from './api/createMessageTemplate.js';
10
10
  import downloadEditorSDK from './api/downloadEditorSDK.js';
@@ -117,6 +117,14 @@ export default async function editorInitCommand(req, res) {
117
117
  destroySpinner();
118
118
  }
119
119
 
120
+ // Do not initialise with TypeScript when no tsconfig.json is found.
121
+ const platformHasTsConfig = sdkFiles.some(
122
+ (file) => file.path === 'tsconfig.json'
123
+ );
124
+ const useTypeScript = req.options['output-javascript']
125
+ ? false
126
+ : platformHasTsConfig;
127
+
120
128
  // Set the sdkVersion to the actual version, for nightlies it's sets to the specific nightly version string instead of 'nightly'.
121
129
  sdkVersion = sdkManifest.version;
122
130
 
@@ -274,15 +282,12 @@ export default async function editorInitCommand(req, res) {
274
282
  return;
275
283
  }
276
284
 
277
- // @TODO: @TS: Remove file extensions from imports in template files when
278
- // supporting TS configuration.
279
-
280
285
  // Copy the Fonto Editor instance template.
281
286
  destroySpinner = res.spinner('Setting up a new Fonto Editor instance...');
282
287
  const templateDirectoryPath = path.join(
283
288
  __dirname,
284
289
  '..',
285
- 'instanceTemplate'
290
+ useTypeScript ? 'instanceTemplateTypeScript' : 'instanceTemplate'
286
291
  );
287
292
  try {
288
293
  await fs.copy(templateDirectoryPath, editorPath, {
@@ -308,7 +313,8 @@ export default async function editorInitCommand(req, res) {
308
313
  await createSchemaPackages(
309
314
  editorPath,
310
315
  fontoJson.rootSchemas,
311
- schemaCompileResults
316
+ schemaCompileResults,
317
+ useTypeScript
312
318
  );
313
319
  } catch (error) {
314
320
  throw new res.ErrorWithInnerError(
@@ -347,7 +353,8 @@ export default async function editorInitCommand(req, res) {
347
353
  schemaCompileResults,
348
354
  prefixByNamespaceUri,
349
355
  addons,
350
- sdkVersion
356
+ sdkVersion,
357
+ useTypeScript
351
358
  );
352
359
  } catch (error) {
353
360
  throw new res.ErrorWithInnerError(
@@ -380,12 +387,12 @@ export default async function editorInitCommand(req, res) {
380
387
  destroySpinner();
381
388
  }
382
389
 
383
- // Creating config/configuration.js.
390
+ // Creating config/configuration.ts/js.
384
391
  destroySpinner = res.spinner('Creating the config configuration file...');
385
392
  const configConfigurationPath = path.join(
386
393
  editorPath,
387
394
  'config',
388
- 'configuration.js'
395
+ `configuration${useTypeScript ? '.ts' : '.js'}`
389
396
  );
390
397
  try {
391
398
  await createConfigConfiguration(
@@ -397,21 +404,23 @@ export default async function editorInitCommand(req, res) {
397
404
  );
398
405
  } catch (error) {
399
406
  throw new res.ErrorWithInnerError(
400
- 'Could not create the config/configuration.js file.',
407
+ `Could not create the config/configuration${
408
+ useTypeScript ? '.ts' : '.js'
409
+ } file.`,
401
410
  error
402
411
  );
403
412
  } finally {
404
413
  destroySpinner();
405
414
  }
406
415
 
407
- // Creating config/schemaExperienceResolver.js.
416
+ // Creating config/schemaExperienceResolver.ts/js.
408
417
  destroySpinner = res.spinner(
409
418
  'Creating the config schema experience resolver file...'
410
419
  );
411
420
  const schemaExperienceResolverPath = path.join(
412
421
  editorPath,
413
422
  'config',
414
- 'schemaExperienceResolver.js'
423
+ `schemaExperienceResolver${useTypeScript ? '.ts' : '.js'}`
415
424
  );
416
425
  try {
417
426
  await createSchemaExperienceResolver(
@@ -420,7 +429,9 @@ export default async function editorInitCommand(req, res) {
420
429
  );
421
430
  } catch (error) {
422
431
  throw new res.ErrorWithInnerError(
423
- 'Could not create the config/schemaExperienceResolver.js file.',
432
+ `Could not create the config/schemaExperienceResolver${
433
+ useTypeScript ? '.ts' : '.js'
434
+ } file.`,
424
435
  error
425
436
  );
426
437
  } finally {
@@ -524,10 +535,8 @@ export default async function editorInitCommand(req, res) {
524
535
 
525
536
  destroySpinner();
526
537
 
527
- // npm install.
528
- if (isPre770Editor(sdkVersion)) {
529
- await npmInstall(editorPath, res);
530
- }
538
+ // Install NPM depencencies when there's a package.json.
539
+ await npmInstall(editorPath, res);
531
540
 
532
541
  // Done.
533
542
  res.break();
@@ -56,6 +56,12 @@ export default (moduleRegistration, editorCommand) => {
56
56
  'Specify the schema compiler backend base url.'
57
57
  )
58
58
 
59
+ .addHiddenOption(
60
+ 'output-javascript',
61
+ undefined,
62
+ 'Generate JavaScript instead of TypeScript.'
63
+ )
64
+
59
65
  .addOption(
60
66
  'version',
61
67
  undefined,
@@ -1,6 +1,7 @@
1
1
  import fs from 'fs-extra';
2
2
  import path from 'path';
3
3
  import unzipper from 'unzipper';
4
+ import { fileURLToPath } from 'url';
4
5
 
5
6
  import { isPre770Editor } from '../../../editorVersions.js';
6
7
  import convertEditorWithOutput from '../../editor/src/commands/api/convertEditorWithOutput.js';
@@ -18,6 +19,9 @@ import updateConfigFontoManifest from './api/upgrade/updateConfigFontoManifest.j
18
19
  import validateAddons from './api/validateAddons.js';
19
20
  import validateManifest from './api/validateManifest.js';
20
21
 
22
+ const __filename = fileURLToPath(import.meta.url);
23
+ const __dirname = path.dirname(__filename);
24
+
21
25
  export default async function editorUpgradeCommand(req, res) {
22
26
  if (req.options['remove-backup']) {
23
27
  // DEV-9386
@@ -308,6 +312,27 @@ export default async function editorUpgradeCommand(req, res) {
308
312
  );
309
313
  }
310
314
 
315
+ // Set up code intelligence if there's a base tsconfig.json and it hasn't
316
+ // been set up yet.
317
+ const platformHasTsConfig = await fs.pathExists(
318
+ path.join(editorPath, 'platform', 'tsconfig.json')
319
+ );
320
+ if (platformHasTsConfig) {
321
+ await fs.copy(
322
+ path.resolve(
323
+ __dirname,
324
+ '..',
325
+ 'instanceTemplateTypeScript',
326
+ 'tsconfig.json'
327
+ ),
328
+ path.resolve(editorPath, 'tsconfig.json'),
329
+ {
330
+ // Silently fail when target already exists.
331
+ overwrite: false,
332
+ }
333
+ );
334
+ }
335
+
311
336
  await req.fdt.license.sendTelemetry({
312
337
  product: req.command.parent.name,
313
338
  type: 'selfContained',
@@ -1,29 +0,0 @@
1
- function configureAssetGetRouteHandler(config) {
2
- return (req, res) => {
3
- const editSessionToken =
4
- req.query &&
5
- req.query.context &&
6
- JSON.parse(req.query.context).editSessionToken;
7
-
8
- let id = req.query.id;
9
- if (id && id.indexOf('..') !== -1) {
10
- res.status(403).end();
11
- return;
12
- }
13
-
14
- // Strip assets and /assets prefixes
15
- id = id.replace(/^\/?assets/g, '');
16
-
17
- const filePath = req.cms.getPath(id, editSessionToken);
18
- if (filePath) {
19
- res.sendFile(filePath, {
20
- cacheControl: !config.cacheControlDisabled,
21
- maxAge: config.cacheControlMaxAge,
22
- });
23
- } else {
24
- res.status(404).end();
25
- }
26
- };
27
- }
28
-
29
- export default configureAssetGetRouteHandler;
@@ -1,69 +0,0 @@
1
- (function appEntry() {
2
- return Promise.resolve()
3
- .then(function () {
4
- window.startFontoBootstrap();
5
-
6
- require('fontoxml-shims/src/main');
7
-
8
- const glamor = require('glamor');
9
- glamor.styleSheet.maxLength = 4;
10
- glamor.plugins.remove(
11
- glamor.plugins.fns.find(function (pluginFn) {
12
- return pluginFn.name === 'prefixes';
13
- })
14
- );
15
-
16
- const getQueryParameterByName =
17
- require('fontoxml-utils/src/getQueryParameterByName').default;
18
- const scope = getQueryParameterByName(
19
- window.location.search,
20
- 'scope'
21
- );
22
- const configurationManager =
23
- require('fontoxml-configuration/src/configurationManager').default;
24
- configurationManager.set('scope', scope ? JSON.parse(scope) : {});
25
- configurationManager.set(
26
- 'version-info',
27
- require('./generated?type=versionInfo').default
28
- );
29
- configurationManager.set(
30
- 'fonto-debug-build',
31
- require('./generated?type=debugBuild').default
32
- );
33
-
34
- require('./generated?type=styles');
35
-
36
- require('./generated?type=setDefaultConfiguration');
37
-
38
- require('config/configuration');
39
-
40
- return configurationManager.applyDefaults();
41
- })
42
- .then(function () {
43
- require('./generated?type=messages');
44
-
45
- require('./generated?type=configureSxModule');
46
-
47
- require('config/schemaExperienceResolver');
48
-
49
- require('./generated?type=install');
50
-
51
- require('react');
52
- const ReactDOM = require('react-dom');
53
- const renderApp = require('fontoxml-editor/src/renderApp').default;
54
-
55
- ReactDOM.render(
56
- renderApp(),
57
- window.document.getElementById('index-app-root')
58
- );
59
-
60
- window.completeFontoBootstrap();
61
- })
62
- .catch(function (error) {
63
- if (window.showFontoError) {
64
- window.showFontoError(error);
65
- } else {
66
- throw error;
67
- }
68
- });
69
- })();