@ui5/builder 3.0.0-alpha.11 → 3.0.0-alpha.12

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 (80) hide show
  1. package/CHANGELOG.md +18 -2
  2. package/jsdoc.json +2 -2
  3. package/lib/lbt/UI5ClientConstants.js +7 -8
  4. package/lib/lbt/analyzer/ComponentAnalyzer.js +10 -10
  5. package/lib/lbt/analyzer/FioriElementsAnalyzer.js +9 -9
  6. package/lib/lbt/analyzer/JSModuleAnalyzer.js +32 -25
  7. package/lib/lbt/analyzer/SmartTemplateAnalyzer.js +9 -9
  8. package/lib/lbt/analyzer/XMLCompositeAnalyzer.js +8 -8
  9. package/lib/lbt/analyzer/XMLTemplateAnalyzer.js +19 -17
  10. package/lib/lbt/analyzer/analyzeLibraryJS.js +8 -7
  11. package/lib/lbt/bundle/AutoSplitter.js +10 -11
  12. package/lib/lbt/bundle/Builder.js +29 -32
  13. package/lib/lbt/bundle/BundleDefinition.js +1 -5
  14. package/lib/lbt/bundle/BundleWriter.js +1 -2
  15. package/lib/lbt/bundle/ResolvedBundleDefinition.js +6 -7
  16. package/lib/lbt/bundle/Resolver.js +9 -10
  17. package/lib/lbt/calls/SapUiDefine.js +5 -6
  18. package/lib/lbt/graph/dependencyGraph.js +3 -4
  19. package/lib/lbt/graph/dominatorTree.js +3 -3
  20. package/lib/lbt/graph/topologicalSort.js +3 -3
  21. package/lib/lbt/resources/LibraryFileAnalyzer.js +5 -8
  22. package/lib/lbt/resources/LocatorResource.js +2 -2
  23. package/lib/lbt/resources/LocatorResourcePool.js +3 -3
  24. package/lib/lbt/resources/ModuleInfo.js +1 -2
  25. package/lib/lbt/resources/Resource.js +3 -4
  26. package/lib/lbt/resources/ResourceCollector.js +7 -8
  27. package/lib/lbt/resources/ResourceFilterList.js +38 -40
  28. package/lib/lbt/resources/ResourceInfo.js +1 -1
  29. package/lib/lbt/resources/ResourceInfoList.js +2 -2
  30. package/lib/lbt/resources/ResourcePool.js +15 -21
  31. package/lib/lbt/utils/ASTUtils.js +17 -30
  32. package/lib/lbt/utils/JSTokenizer.js +4 -4
  33. package/lib/lbt/utils/ModuleName.js +10 -20
  34. package/lib/lbt/utils/escapePropertiesFile.js +3 -3
  35. package/lib/lbt/utils/parseUtils.js +4 -10
  36. package/lib/processors/bootstrapHtmlTransformer.js +15 -7
  37. package/lib/processors/bundlers/flexChangesBundler.js +16 -8
  38. package/lib/processors/bundlers/manifestBundler.js +19 -10
  39. package/lib/processors/bundlers/moduleBundler.js +26 -15
  40. package/lib/processors/jsdoc/apiIndexGenerator.js +16 -9
  41. package/lib/processors/jsdoc/jsdocGenerator.js +31 -17
  42. package/lib/processors/jsdoc/lib/{createIndexFiles.js → createIndexFiles.cjs} +0 -0
  43. package/lib/processors/jsdoc/lib/{transformApiJson.js → transformApiJson.cjs} +0 -0
  44. package/lib/processors/jsdoc/lib/ui5/{plugin.js → plugin.cjs} +0 -0
  45. package/lib/processors/jsdoc/lib/ui5/template/{publish.js → publish.cjs} +1 -1
  46. package/lib/processors/jsdoc/lib/ui5/template/utils/{versionUtil.js → versionUtil.cjs} +0 -0
  47. package/lib/processors/jsdoc/sdkTransformer.js +18 -11
  48. package/lib/processors/libraryLessGenerator.js +28 -16
  49. package/lib/processors/manifestCreator.js +14 -13
  50. package/lib/processors/minifier.js +21 -15
  51. package/lib/processors/nonAsciiEscaper.js +16 -6
  52. package/lib/processors/resourceListCreator.js +13 -13
  53. package/lib/processors/stringReplacer.js +13 -6
  54. package/lib/processors/themeBuilder.js +30 -22
  55. package/lib/processors/versionInfoGenerator.js +33 -23
  56. package/lib/tasks/buildThemes.js +17 -10
  57. package/lib/tasks/bundlers/generateBundle.js +23 -12
  58. package/lib/tasks/bundlers/generateComponentPreload.js +18 -10
  59. package/lib/tasks/bundlers/generateFlexChangesBundle.js +16 -8
  60. package/lib/tasks/bundlers/generateLibraryPreload.js +22 -12
  61. package/lib/tasks/bundlers/generateManifestBundle.js +15 -6
  62. package/lib/tasks/bundlers/generateStandaloneAppBundle.js +21 -13
  63. package/lib/tasks/bundlers/utils/createModuleNameMapping.js +6 -6
  64. package/lib/tasks/escapeNonAsciiCharacters.js +12 -5
  65. package/lib/tasks/generateCachebusterInfo.js +16 -8
  66. package/lib/tasks/generateLibraryManifest.js +14 -8
  67. package/lib/tasks/generateResourcesJson.js +15 -9
  68. package/lib/tasks/generateThemeDesignerResources.js +19 -9
  69. package/lib/tasks/generateVersionInfo.js +12 -5
  70. package/lib/tasks/jsdoc/executeJsdocSdkTransformation.js +17 -9
  71. package/lib/tasks/jsdoc/generateApiIndex.js +16 -10
  72. package/lib/tasks/jsdoc/generateJsdoc.js +131 -119
  73. package/lib/tasks/minify.js +13 -6
  74. package/lib/tasks/replaceBuildtime.js +12 -5
  75. package/lib/tasks/replaceCopyright.js +12 -5
  76. package/lib/tasks/replaceVersion.js +12 -5
  77. package/lib/tasks/taskRepository.js +24 -29
  78. package/lib/tasks/transformBootstrapHtml.js +6 -5
  79. package/package.json +29 -15
  80. package/index.js +0 -173
@@ -1,6 +1,12 @@
1
- const crypto = require("crypto");
2
- const resourceFactory = require("@ui5/fs").resourceFactory;
3
- const log = require("@ui5/logger").getLogger("builder:tasks:generateCachebusterInfo");
1
+ import crypto from "node:crypto";
2
+ import {createResource} from "@ui5/fs/resourceFactory";
3
+ import logger from "@ui5/logger";
4
+ const log = logger.getLogger("builder:tasks:generateCachebusterInfo");
5
+
6
+ /**
7
+ * @public
8
+ * @module @ui5/builder/tasks/generateCachebusterInfo
9
+ */
4
10
 
5
11
  async function signByTime(resource) {
6
12
  return resource.getStatInfo().mtime.getTime();
@@ -33,15 +39,17 @@ function getSigner(type) {
33
39
  * Task to generate the application cachebuster info file.
34
40
  *
35
41
  * @public
36
- * @alias module:@ui5/builder.tasks.generateCachebusterInfo
42
+ * @function default
43
+ * @static
44
+ *
37
45
  * @param {object} parameters Parameters
38
- * @param {module:@ui5/fs.DuplexCollection} parameters.workspace DuplexCollection to read and write files
46
+ * @param {@ui5/fs/DuplexCollection} parameters.workspace DuplexCollection to read and write files
39
47
  * @param {object} parameters.options Options
40
48
  * @param {string} parameters.options.projectNamespace Namespace of the application
41
49
  * @param {string} [parameters.options.signatureType='time'] Type of signature to be used ('time' or 'hash')
42
50
  * @returns {Promise<undefined>} Promise resolving with <code>undefined</code> once data has been written
43
51
  */
44
- module.exports = function({workspace, options}) {
52
+ export default function({workspace, options}) {
45
53
  const {signatureType} = options;
46
54
  // Backward compatibility: "namespace" option got renamed to "projectNamespace"
47
55
  const namespace = options.projectNamespace || options.namespace;
@@ -63,10 +71,10 @@ module.exports = function({workspace, options}) {
63
71
  resourcePath = resourcePath.replace(basePath, "");
64
72
  cachebusterInfo[resourcePath] = await signer(resource);
65
73
  }));
66
- const cachebusterInfoResource = resourceFactory.createResource({
74
+ const cachebusterInfoResource = createResource({
67
75
  path: `/resources/${namespace}/sap-ui-cachebuster-info.json`,
68
76
  string: JSON.stringify(cachebusterInfo, null, 2)
69
77
  });
70
78
  return workspace.write(cachebusterInfoResource);
71
79
  });
72
- };
80
+ }
@@ -1,22 +1,28 @@
1
- "use strict";
2
1
 
3
- const log = require("@ui5/logger").getLogger("builder:tasks:generateLibraryManifest");
4
- const manifestCreator = require("../processors/manifestCreator");
2
+ import logger from "@ui5/logger";
3
+ const log = logger.getLogger("builder:tasks:generateLibraryManifest");
4
+ import manifestCreator from "../processors/manifestCreator.js";
5
5
 
6
+ /**
7
+ * @public
8
+ * @module @ui5/builder/tasks/generateLibraryManifest
9
+ */
6
10
 
7
11
  /**
8
12
  * Task for creating a library manifest.json from its .library file.
9
13
  *
10
14
  * @public
11
- * @alias module:@ui5/builder.tasks.generateLibraryManifest
15
+ * @function default
16
+ * @static
17
+ *
12
18
  * @param {object} parameters Parameters
13
- * @param {module:@ui5/fs.DuplexCollection} parameters.workspace DuplexCollection to read and write files
14
- * @param {module:@ui5/project.build.helpers.TaskUtil|object} [parameters.taskUtil] TaskUtil
19
+ * @param {@ui5/fs/DuplexCollection} parameters.workspace DuplexCollection to read and write files
20
+ * @param {@ui5/project/build/helpers/TaskUtil|object} [parameters.taskUtil] TaskUtil
15
21
  * @param {object} parameters.options Options
16
22
  * @param {string} parameters.options.projectName Project name
17
23
  * @returns {Promise<undefined>} Promise resolving with <code>undefined</code> once data has been written
18
24
  */
19
- module.exports = function({workspace, taskUtil, options: {projectName}}) {
25
+ export default function({workspace, taskUtil, options: {projectName}}) {
20
26
  // Note:
21
27
  // *.library files are needed to identify libraries
22
28
  // *.json files are needed to avoid overwriting them
@@ -64,4 +70,4 @@ module.exports = function({workspace, taskUtil, options: {projectName}}) {
64
70
  }));
65
71
  });
66
72
  });
67
- };
73
+ }
@@ -1,6 +1,5 @@
1
- "use strict";
2
1
 
3
- const resourceListCreator = require("../processors/resourceListCreator");
2
+ import resourceListCreator from "../processors/resourceListCreator.js";
4
3
 
5
4
  const DEFAULT_EXCLUDES = [
6
5
  /*
@@ -38,6 +37,11 @@ function getCreatorOptions(projectName) {
38
37
  return creatorOptions;
39
38
  }
40
39
 
40
+ /**
41
+ * @public
42
+ * @module @ui5/builder/tasks/generateResourcesJson
43
+ */
44
+
41
45
  /**
42
46
  * Task for creating a resources.json file, describing all productive build resources.
43
47
  *
@@ -47,7 +51,7 @@ function getCreatorOptions(projectName) {
47
51
  * </p>
48
52
  *
49
53
  * <p>
50
- * Not supported in combination with task {@link module:@ui5/builder.tasks.generateStandaloneAppBundle}.
54
+ * Not supported in combination with task {@link @ui5/builder/tasks/generateStandaloneAppBundle}.
51
55
  * Therefore it is also not supported in combination with self-contained build.
52
56
  * </p>
53
57
  *
@@ -93,16 +97,18 @@ function getCreatorOptions(projectName) {
93
97
  * };
94
98
  *
95
99
  * @public
96
- * @alias module:@ui5/builder.tasks.generateResourcesJson
100
+ * @function default
101
+ * @static
102
+ *
97
103
  * @param {object} parameters Parameters
98
- * @param {module:@ui5/fs.DuplexCollection} parameters.workspace DuplexCollection to read and write files
99
- * @param {module:@ui5/fs.AbstractReader} parameters.dependencies Reader or Collection to read dependency files
100
- * @param {module:@ui5/project.build.helpers.TaskUtil|object} [parameters.taskUtil] TaskUtil
104
+ * @param {@ui5/fs/DuplexCollection} parameters.workspace DuplexCollection to read and write files
105
+ * @param {@ui5/fs/AbstractReader} parameters.dependencies Reader or Collection to read dependency files
106
+ * @param {@ui5/project/build/helpers/TaskUtil|object} [parameters.taskUtil] TaskUtil
101
107
  * @param {object} parameters.options Options
102
108
  * @param {string} parameters.options.projectName Project name
103
109
  * @returns {Promise<undefined>} Promise resolving with <code>undefined</code> once data has been written
104
110
  */
105
- module.exports = async function({workspace, dependencies, taskUtil, options: {projectName}}) {
111
+ export default async function({workspace, dependencies, taskUtil, options: {projectName}}) {
106
112
  let resources = await workspace.byGlob(["/resources/**/*"].concat(DEFAULT_EXCLUDES));
107
113
  let dependencyResources =
108
114
  await dependencies.byGlob("/resources/**/*.{js,json,xml,html,properties,library,js.map}");
@@ -125,4 +131,4 @@ module.exports = async function({workspace, dependencies, taskUtil, options: {pr
125
131
  await Promise.all(
126
132
  resourceLists.map((resourceList) => workspace.write(resourceList))
127
133
  );
128
- };
134
+ }
@@ -1,7 +1,10 @@
1
- const posixPath = require("path").posix;
2
- const log = require("@ui5/logger").getLogger("builder:tasks:generateThemeDesignerResources");
3
- const libraryLessGenerator = require("../processors/libraryLessGenerator");
4
- const {ReaderCollectionPrioritized, Resource, fsInterface} = require("@ui5/fs");
1
+ import posixPath from "node:path/posix";
2
+ import logger from "@ui5/logger";
3
+ const log = logger.getLogger("builder:tasks:generateThemeDesignerResources");
4
+ import libraryLessGenerator from "../processors/libraryLessGenerator.js";
5
+ import ReaderCollectionPrioritized from "@ui5/fs/ReaderCollectionPrioritized";
6
+ import Resource from "@ui5/fs/Resource";
7
+ import fsInterface from "@ui5/fs/fsInterface";
5
8
 
6
9
  /**
7
10
  * Returns a relative path from the given themeFolder to the root namespace.
@@ -187,15 +190,22 @@ async function generateCssVariablesLess({workspace, combo, namespace}) {
187
190
  }
188
191
  }
189
192
 
193
+ /**
194
+ * @public
195
+ * @module @ui5/builder/tasks/generateThemeDesignerResources
196
+ */
197
+
190
198
  /* eslint "jsdoc/check-param-names": ["error", {"disableExtraPropertyReporting":true}] */
191
199
  /**
192
200
  * Generates resources required for integration with the SAP Theme Designer.
193
201
  *
194
202
  * @public
195
- * @alias module:@ui5/builder.tasks.generateThemeDesignerResources
203
+ * @function default
204
+ * @static
205
+ *
196
206
  * @param {object} parameters Parameters
197
- * @param {module:@ui5/fs.DuplexCollection} parameters.workspace DuplexCollection to read and write files
198
- * @param {module:@ui5/fs.AbstractReader} parameters.dependencies Reader or Collection to read dependency files
207
+ * @param {@ui5/fs/DuplexCollection} parameters.workspace DuplexCollection to read and write files
208
+ * @param {@ui5/fs/AbstractReader} parameters.dependencies Reader or Collection to read dependency files
199
209
  * @param {object} parameters.options Options
200
210
  * @param {string} parameters.options.projectName Project name
201
211
  * @param {string} parameters.options.version Project version
@@ -204,7 +214,7 @@ async function generateCssVariablesLess({workspace, combo, namespace}) {
204
214
  * Omit for type <code>theme-library</code>
205
215
  * @returns {Promise<undefined>} Promise resolving with <code>undefined</code> once data has been written
206
216
  */
207
- module.exports = async function({workspace, dependencies, options}) {
217
+ export default async function({workspace, dependencies, options}) {
208
218
  const {projectName, version} = options;
209
219
  // Backward compatibility: "namespace" option got renamed to "projectNamespace"
210
220
  const namespace = options.projectNamespace || options.namespace;
@@ -279,4 +289,4 @@ module.exports = async function({workspace, dependencies, options}) {
279
289
 
280
290
  // css_variables.less
281
291
  await generateCssVariablesLess({workspace, combo, namespace});
282
- };
292
+ }
@@ -1,21 +1,28 @@
1
- const versionInfoGenerator = require("../processors/versionInfoGenerator");
1
+ import versionInfoGenerator from "../processors/versionInfoGenerator.js";
2
2
 
3
3
  const MANIFEST_JSON = "manifest.json";
4
4
 
5
+ /**
6
+ * @public
7
+ * @module @ui5/builder/tasks/generateVersionInfo
8
+ */
9
+
5
10
  /**
6
11
  * Task to create sap-ui-version.json
7
12
  *
8
13
  * @public
9
- * @alias module:@ui5/builder.tasks.generateVersionInfo
14
+ * @function default
15
+ * @static
16
+ *
10
17
  * @param {object} parameters Parameters
11
- * @param {module:@ui5/fs.DuplexCollection} parameters.workspace DuplexCollection to read and write files
12
- * @param {module:@ui5/fs.AbstractReader} parameters.dependencies Reader or Collection to read dependency files
18
+ * @param {@ui5/fs/DuplexCollection} parameters.workspace DuplexCollection to read and write files
19
+ * @param {@ui5/fs/AbstractReader} parameters.dependencies Reader or Collection to read dependency files
13
20
  * @param {object} parameters.options Options
14
21
  * @param {string} parameters.options.pattern Glob pattern for .library resources
15
22
  * @param {object} parameters.options.rootProject DuplexCollection to read and write files
16
23
  * @returns {Promise<undefined>} Promise resolving with <code>undefined</code> once data has been written
17
24
  */
18
- module.exports = async ({workspace, dependencies, options: {rootProject, pattern}}) => {
25
+ export default async ({workspace, dependencies, options: {rootProject, pattern}}) => {
19
26
  const resources = await dependencies.byGlob(pattern);
20
27
 
21
28
  const libraryInfosPromises = resources.map((dotLibResource) => {
@@ -1,18 +1,26 @@
1
- const log = require("@ui5/logger").getLogger("builder:tasks:jsdoc:executeJsdocSdkTransformation");
2
- const ReaderCollectionPrioritized = require("@ui5/fs").ReaderCollectionPrioritized;
3
- const fsInterface = require("@ui5/fs").fsInterface;
4
- const sdkTransformer = require("../../processors/jsdoc/sdkTransformer");
1
+ import logger from "@ui5/logger";
2
+ const log = logger.getLogger("builder:tasks:jsdoc:executeJsdocSdkTransformation");
3
+ import ReaderCollectionPrioritized from "@ui5/fs/ReaderCollectionPrioritized";
4
+ import fsInterface from "@ui5/fs/fsInterface";
5
+ import sdkTransformer from "../../processors/jsdoc/sdkTransformer.js";
6
+
7
+ /**
8
+ * @public
9
+ * @module @ui5/builder/tasks/executeJsdocSdkTransformation
10
+ */
5
11
 
6
12
  /**
7
13
  * Task to transform the api.json file as created by the
8
- * [generateJsdoc]{@link module:@ui5/builder.tasks.generateJsdoc} task into a pre-processed api.json
14
+ * [generateJsdoc]{@link @ui5/builder/tasks/generateJsdoc} task into a pre-processed api.json
9
15
  * file suitable for the SDK.
10
16
  *
11
17
  * @public
12
- * @alias module:@ui5/builder.tasks.executeJsdocSdkTransformation
18
+ * @function default
19
+ * @static
20
+ *
13
21
  * @param {object} parameters Parameters
14
- * @param {module:@ui5/fs.DuplexCollection} parameters.workspace DuplexCollection to read and write files
15
- * @param {module:@ui5/fs.AbstractReader} parameters.dependencies Reader or Collection to read dependency files
22
+ * @param {@ui5/fs/DuplexCollection} parameters.workspace DuplexCollection to read and write files
23
+ * @param {@ui5/fs/AbstractReader} parameters.dependencies Reader or Collection to read dependency files
16
24
  * @param {object} parameters.options Options
17
25
  * @param {string|Array} parameters.options.dotLibraryPattern Pattern to locate the .library resource to be processed
18
26
  * @param {string} parameters.options.projectName Project name
@@ -73,4 +81,4 @@ const executeJsdocSdkTransformation = async function(
73
81
  }));
74
82
  };
75
83
 
76
- module.exports = executeJsdocSdkTransformation;
84
+ export default executeJsdocSdkTransformation;
@@ -1,23 +1,29 @@
1
- const ui5Fs = require("@ui5/fs");
2
- const ReaderCollectionPrioritized = ui5Fs.ReaderCollectionPrioritized;
3
- const fsInterface = ui5Fs.fsInterface;
4
- const apiIndexGenerator = require("../../processors/jsdoc/apiIndexGenerator");
1
+ import ReaderCollectionPrioritized from "@ui5/fs/ReaderCollectionPrioritized";
2
+ import fsInterface from "@ui5/fs/fsInterface";
3
+ import apiIndexGenerator from "../../processors/jsdoc/apiIndexGenerator.js";
4
+
5
+ /**
6
+ * @public
7
+ * @module @ui5/builder/tasks/generateApiIndex
8
+ */
5
9
 
6
10
  /**
7
11
  * Compiles an api-index.json resource from all available api.json resources as created by the
8
- * [executeJsdocSdkTransformation]{@link module:@ui5/builder.tasks.executeJsdocSdkTransformation} task.
12
+ * [executeJsdocSdkTransformation]{@link @ui5/builder/tasks/executeJsdocSdkTransformation} task.
9
13
  * The resulting api-index.json resource is mainly to be used in the SDK.
10
14
  *
11
15
  * @public
12
- * @alias module:@ui5/builder.tasks.generateApiIndex
16
+ * @function default
17
+ * @static
18
+ *
13
19
  * @param {object} parameters Parameters
14
- * @param {module:@ui5/fs.DuplexCollection} parameters.workspace DuplexCollection to read and write files
15
- * @param {module:@ui5/fs.AbstractReader} parameters.dependencies Reader or Collection to read dependency files
20
+ * @param {@ui5/fs/DuplexCollection} parameters.workspace DuplexCollection to read and write files
21
+ * @param {@ui5/fs/AbstractReader} parameters.dependencies Reader or Collection to read dependency files
16
22
  * @param {object} parameters.options Options
17
23
  * @param {string} parameters.options.projectName Project name
18
24
  * @returns {Promise<undefined>} Promise resolving with <code>undefined</code> once data has been written
19
25
  */
20
- module.exports = async function({
26
+ export default async function({
21
27
  workspace,
22
28
  dependencies,
23
29
  options: {projectName}
@@ -47,4 +53,4 @@ module.exports = async function({
47
53
  await Promise.all(createdResources.map((resource) => {
48
54
  return workspace.write(resource);
49
55
  }));
50
- };
56
+ }
@@ -1,13 +1,20 @@
1
- const log = require("@ui5/logger").getLogger("builder:tasks:jsdoc:generateJsdoc");
2
- const path = require("path");
3
- const makeDir = require("make-dir");
4
- const os = require("os");
5
- const fs = require("graceful-fs");
6
- const {promisify} = require("util");
1
+ import logger from "@ui5/logger";
2
+ const log = logger.getLogger("builder:tasks:jsdoc:generateJsdoc");
3
+ import path from "node:path";
4
+ import makeDir from "make-dir";
5
+ import os from "node:os";
6
+ import fs from "graceful-fs";
7
+ import _rimraf from "rimraf";
8
+ import {promisify} from "node:util";
7
9
  const mkdtemp = promisify(fs.mkdtemp);
8
- const rimraf = promisify(require("rimraf"));
9
- const jsdocGenerator = require("../../processors/jsdoc/jsdocGenerator");
10
- const {resourceFactory} = require("@ui5/fs");
10
+ const rimraf = promisify(_rimraf);
11
+ import jsdocGenerator from "../../processors/jsdoc/jsdocGenerator.js";
12
+ import {createAdapter} from "@ui5/fs/resourceFactory";
13
+
14
+ /**
15
+ * @public
16
+ * @module @ui5/builder/tasks/generateJsdoc
17
+ */
11
18
 
12
19
  /**
13
20
  *
@@ -23,30 +30,33 @@ const {resourceFactory} = require("@ui5/fs");
23
30
  * Task to execute a JSDoc build for UI5 projects
24
31
  *
25
32
  * @public
26
- * @alias module:@ui5/builder.tasks.generateJsdoc
33
+ * @function default
34
+ * @static
35
+ *
27
36
  * @param {object} parameters Parameters
28
- * @param {module:@ui5/fs.DuplexCollection} parameters.workspace DuplexCollection to read and write files
29
- * @param {module:@ui5/fs.AbstractReader} parameters.dependencies Reader or Collection to read dependency files
30
- * @param {GenerateJsdocOptions} parameters.options Options
31
- * @param {module:@ui5/project.build.helpers.TaskUtil|object} [parameters.taskUtil] TaskUtil
37
+ * @param {@ui5/fs/DuplexCollection} parameters.workspace DuplexCollection to read and write files
38
+ * @param {@ui5/fs/AbstractReader} parameters.dependencies Reader or Collection to read dependency files
39
+ * @param {module:@ui5/builder/tasks/generateJsdoc~GenerateJsdocOptions} parameters.options Options
40
+ * @param {@ui5/project/build/helpers/TaskUtil|object} [parameters.taskUtil] TaskUtil
32
41
  * @param {object} [parameters.buildContext] Internal, deprecated parameter
33
42
  * @returns {Promise<undefined>} Promise resolving with <code>undefined</code> once data has been written
34
43
  */
35
- const generateJsdoc = async function({
44
+ export default async function generateJsdoc({
36
45
  taskUtil,
37
46
  buildContext,
38
47
  workspace,
39
48
  dependencies,
40
49
  options = {}
41
50
  }) {
42
- const {projectName, namespace, version, pattern} = /** @type {GenerateJsdocOptions} */ (options);
51
+ const {projectName, namespace, version, pattern} =
52
+ /** @type {module:@ui5/builder/tasks/generateJsdoc~GenerateJsdocOptions} */ (options);
43
53
 
44
54
  if (!projectName || !namespace || !version || !pattern) {
45
55
  throw new Error("[generateJsdoc]: One or more mandatory options not provided");
46
56
  }
47
57
 
48
58
  const {sourcePath: resourcePath, targetPath, tmpPath, cleanup} =
49
- await generateJsdoc._createTmpDirs(projectName);
59
+ await utils.createTmpDirs(projectName);
50
60
 
51
61
  // TODO 3.0: remove buildContext
52
62
  const _taskUtil = taskUtil || buildContext;
@@ -55,12 +65,12 @@ const generateJsdoc = async function({
55
65
  }
56
66
 
57
67
  const [writtenResourcesCount] = await Promise.all([
58
- generateJsdoc._writeResourcesToDir({
68
+ utils.writeResourcesToDir({
59
69
  workspace,
60
70
  pattern,
61
71
  targetPath: resourcePath
62
72
  }),
63
- generateJsdoc._writeDependencyApisToDir({
73
+ utils.writeDependencyApisToDir({
64
74
  dependencies,
65
75
  targetPath: path.join(tmpPath, "dependency-apis")
66
76
  })
@@ -87,110 +97,112 @@ const generateJsdoc = async function({
87
97
  await Promise.all(createdResources.map((resource) => {
88
98
  return workspace.write(resource);
89
99
  }));
90
- };
91
-
92
- /**
93
- * Create temporary directories for JSDoc generation processor
94
- *
95
- * @private
96
- * @param {string} projectName Project name used for naming the temporary working directory
97
- * @returns {Promise<object>} Promise resolving with sourcePath, targetPath and tmpPath strings
98
- */
99
- async function createTmpDirs(projectName) {
100
- const tmpDirPath = await generateJsdoc._createTmpDir(projectName);
101
-
102
- const sourcePath = path.join(tmpDirPath, "src"); // dir will be created by writing project resources below
103
- await makeDir(sourcePath, {fs});
104
- const targetPath = path.join(tmpDirPath, "target"); // dir will be created by jsdoc itself
105
- await makeDir(targetPath, {fs});
106
-
107
- const tmpPath = path.join(tmpDirPath, "tmp"); // dir needs to be created by us
108
- await makeDir(tmpPath, {fs});
109
-
110
- return {
111
- sourcePath,
112
- targetPath,
113
- tmpPath,
114
- cleanup: async () => {
115
- return rimraf(tmpDirPath);
116
- }
117
- };
118
- }
119
-
120
- /**
121
- * Create a temporary directory on the host system
122
- *
123
- * @private
124
- * @param {string} projectName Project name used for naming the temporary directory
125
- * @returns {Promise<string>} Promise resolving with path of the temporary directory
126
- */
127
- async function createTmpDir(projectName) {
128
- const sanitizedProjectName = projectName.replace(/[^A-Za-z0-9]/g, "");
129
-
130
- const tmpRootPath = path.join(os.tmpdir(), "ui5-tooling");
131
- await makeDir(tmpRootPath, {fs});
132
-
133
- // Appending minus sign also because node docs advise to "avoid trailing X characters in prefix"
134
- return mkdtemp(path.join(tmpRootPath, `jsdoc-${sanitizedProjectName}-`));
135
100
  }
136
101
 
137
- /**
138
- * Write resources from workspace matching the given pattern to the given fs destination
139
- *
140
- * @private
141
- * @param {object} parameters Parameters
142
- * @param {module:@ui5/fs.DuplexCollection} parameters.workspace DuplexCollection to read and write files
143
- * @param {string} parameters.pattern Pattern to match resources in workspace against
144
- * @param {string} parameters.targetPath Path to write the resources to
145
- * @returns {Promise<number>} Promise resolving with number of resources written to given directory
146
- */
147
- async function writeResourcesToDir({workspace, pattern, targetPath}) {
148
- const fsTarget = resourceFactory.createAdapter({
149
- fsBasePath: targetPath,
150
- virBasePath: "/resources/"
151
- });
152
-
153
- let allResources;
154
- if (workspace.byGlobSource) { // API only available on duplex collections
155
- allResources = await workspace.byGlobSource(pattern);
156
- } else {
157
- allResources = await workspace.byGlob(pattern);
158
- }
159
-
160
- // write all resources to the tmp folder
161
- await Promise.all(allResources.map((resource) => fsTarget.write(resource)));
162
- return allResources.length;
163
- }
164
-
165
- /**
166
- * Write api.json files of dependencies to given target path in a flat structure
167
- *
168
- * @private
169
- * @param {object} parameters Parameters
170
- * @param {module:@ui5/fs.AbstractReader} parameters.dependencies Reader or Collection to read dependency files
171
- * @param {string} parameters.targetPath Path to write the resources to
172
- * @returns {Promise<number>} Promise resolving with number of resources written to given directory
173
- */
174
- async function writeDependencyApisToDir({dependencies, targetPath}) {
175
- const depApis = await dependencies.byGlob("/test-resources/**/designtime/api.json");
102
+ const utils = {
103
+ /**
104
+ * Create temporary directories for JSDoc generation processor
105
+ *
106
+ * @private
107
+ * @param {string} projectName Project name used for naming the temporary working directory
108
+ * @returns {Promise<object>} Promise resolving with sourcePath, targetPath and tmpPath strings
109
+ */
110
+ createTmpDirs: async function(projectName) {
111
+ const tmpDirPath = await utils.createTmpDir(projectName);
112
+
113
+ const sourcePath = path.join(tmpDirPath, "src"); // dir will be created by writing project resources below
114
+ await makeDir(sourcePath, {fs});
115
+ const targetPath = path.join(tmpDirPath, "target"); // dir will be created by jsdoc itself
116
+ await makeDir(targetPath, {fs});
117
+
118
+ const tmpPath = path.join(tmpDirPath, "tmp"); // dir needs to be created by us
119
+ await makeDir(tmpPath, {fs});
120
+
121
+ return {
122
+ sourcePath,
123
+ targetPath,
124
+ tmpPath,
125
+ cleanup: async () => {
126
+ return rimraf(tmpDirPath);
127
+ }
128
+ };
129
+ },
130
+
131
+ /**
132
+ * Create a temporary directory on the host system
133
+ *
134
+ * @private
135
+ * @param {string} projectName Project name used for naming the temporary directory
136
+ * @returns {Promise<string>} Promise resolving with path of the temporary directory
137
+ */
138
+ createTmpDir: async function(projectName) {
139
+ const sanitizedProjectName = projectName.replace(/[^A-Za-z0-9]/g, "");
140
+
141
+ const tmpRootPath = path.join(os.tmpdir(), "ui5-tooling");
142
+ await makeDir(tmpRootPath, {fs});
143
+
144
+ // Appending minus sign also because node docs advise to "avoid trailing X characters in prefix"
145
+ return mkdtemp(path.join(tmpRootPath, `jsdoc-${sanitizedProjectName}-`));
146
+ },
147
+
148
+ /**
149
+ * Write resources from workspace matching the given pattern to the given fs destination
150
+ *
151
+ * @private
152
+ * @param {object} parameters Parameters
153
+ * @param {@ui5/fs/DuplexCollection} parameters.workspace DuplexCollection to read and write files
154
+ * @param {string} parameters.pattern Pattern to match resources in workspace against
155
+ * @param {string} parameters.targetPath Path to write the resources to
156
+ * @returns {Promise<number>} Promise resolving with number of resources written to given directory
157
+ */
158
+ writeResourcesToDir: async function({workspace, pattern, targetPath}) {
159
+ const fsTarget = createAdapter({
160
+ fsBasePath: targetPath,
161
+ virBasePath: "/resources/"
162
+ });
163
+
164
+ let allResources;
165
+ if (workspace.byGlobSource) { // API only available on duplex collections
166
+ allResources = await workspace.byGlobSource(pattern);
167
+ } else {
168
+ allResources = await workspace.byGlob(pattern);
169
+ }
176
170
 
177
- // Clone resources before changing their path
178
- const apis = await Promise.all(depApis.map((resource) => resource.clone()));
171
+ // write all resources to the tmp folder
172
+ await Promise.all(allResources.map((resource) => fsTarget.write(resource)));
173
+ return allResources.length;
174
+ },
175
+
176
+ /**
177
+ * Write api.json files of dependencies to given target path in a flat structure
178
+ *
179
+ * @private
180
+ * @param {object} parameters Parameters
181
+ * @param {@ui5/fs/AbstractReader} parameters.dependencies Reader or Collection to read dependency files
182
+ * @param {string} parameters.targetPath Path to write the resources to
183
+ * @returns {Promise<number>} Promise resolving with number of resources written to given directory
184
+ */
185
+ writeDependencyApisToDir: async function({dependencies, targetPath}) {
186
+ const depApis = await dependencies.byGlob("/test-resources/**/designtime/api.json");
187
+
188
+ // Clone resources before changing their path
189
+ const apis = await Promise.all(depApis.map((resource) => resource.clone()));
190
+
191
+ for (let i = 0; i < apis.length; i++) {
192
+ apis[i].setPath(`/api-${i}.json`);
193
+ }
179
194
 
180
- for (let i = 0; i < apis.length; i++) {
181
- apis[i].setPath(`/api-${i}.json`);
195
+ const fsTarget = createAdapter({
196
+ fsBasePath: targetPath,
197
+ virBasePath: "/"
198
+ });
199
+ await Promise.all(apis.map((resource) => fsTarget.write(resource)));
200
+ return apis.length;
182
201
  }
202
+ };
183
203
 
184
- const fsTarget = resourceFactory.createAdapter({
185
- fsBasePath: targetPath,
186
- virBasePath: "/"
187
- });
188
- await Promise.all(apis.map((resource) => fsTarget.write(resource)));
189
- return apis.length;
204
+ // Export utils for testing only
205
+ /* istanbul ignore else */
206
+ if (process.env.NODE_ENV === "test") {
207
+ generateJsdoc._utils = utils;
190
208
  }
191
-
192
- module.exports = generateJsdoc;
193
- module.exports._createTmpDirs = createTmpDirs;
194
- module.exports._createTmpDir = createTmpDir;
195
- module.exports._writeResourcesToDir = writeResourcesToDir;
196
- module.exports._writeDependencyApisToDir = writeDependencyApisToDir;