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

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 (66) hide show
  1. package/CHANGELOG.md +867 -0
  2. package/index.js +0 -43
  3. package/lib/lbt/analyzer/FioriElementsAnalyzer.js +23 -12
  4. package/lib/lbt/analyzer/JSModuleAnalyzer.js +115 -61
  5. package/lib/lbt/analyzer/SmartTemplateAnalyzer.js +23 -12
  6. package/lib/lbt/analyzer/XMLCompositeAnalyzer.js +29 -19
  7. package/lib/lbt/analyzer/XMLTemplateAnalyzer.js +2 -1
  8. package/lib/lbt/analyzer/analyzeLibraryJS.js +15 -0
  9. package/lib/lbt/bundle/Builder.js +365 -138
  10. package/lib/lbt/bundle/BundleWriter.js +17 -0
  11. package/lib/lbt/bundle/Resolver.js +2 -2
  12. package/lib/lbt/calls/SapUiDefine.js +13 -7
  13. package/lib/lbt/resources/LocatorResource.js +7 -7
  14. package/lib/lbt/resources/LocatorResourcePool.js +8 -4
  15. package/lib/lbt/resources/ResourceCollector.js +22 -15
  16. package/lib/lbt/resources/ResourceInfoList.js +0 -1
  17. package/lib/lbt/resources/ResourcePool.js +7 -6
  18. package/lib/lbt/utils/ASTUtils.js +45 -18
  19. package/lib/lbt/utils/escapePropertiesFile.js +3 -6
  20. package/lib/lbt/utils/parseUtils.js +1 -1
  21. package/lib/processors/bundlers/moduleBundler.js +31 -10
  22. package/lib/processors/jsdoc/lib/createIndexFiles.js +1 -1
  23. package/lib/processors/jsdoc/lib/transformApiJson.js +78 -22
  24. package/lib/processors/jsdoc/lib/ui5/plugin.js +414 -122
  25. package/lib/processors/jsdoc/lib/ui5/template/publish.js +112 -91
  26. package/lib/processors/jsdoc/lib/ui5/template/utils/versionUtil.js +1 -1
  27. package/lib/processors/manifestCreator.js +8 -45
  28. package/lib/processors/minifier.js +11 -5
  29. package/lib/tasks/buildThemes.js +1 -1
  30. package/lib/tasks/bundlers/generateBundle.js +70 -30
  31. package/lib/tasks/bundlers/generateComponentPreload.js +26 -19
  32. package/lib/tasks/bundlers/generateFlexChangesBundle.js +10 -5
  33. package/lib/tasks/bundlers/generateLibraryPreload.js +113 -94
  34. package/lib/tasks/bundlers/generateManifestBundle.js +8 -10
  35. package/lib/tasks/bundlers/generateStandaloneAppBundle.js +42 -10
  36. package/lib/tasks/bundlers/utils/createModuleNameMapping.js +31 -0
  37. package/lib/tasks/generateCachebusterInfo.js +7 -3
  38. package/lib/tasks/generateLibraryManifest.js +6 -8
  39. package/lib/tasks/generateResourcesJson.js +3 -3
  40. package/lib/tasks/generateThemeDesignerResources.js +118 -2
  41. package/lib/tasks/generateVersionInfo.js +5 -5
  42. package/lib/tasks/jsdoc/generateJsdoc.js +1 -1
  43. package/lib/tasks/minify.js +14 -4
  44. package/lib/tasks/taskRepository.js +1 -13
  45. package/lib/tasks/transformBootstrapHtml.js +6 -1
  46. package/package.json +13 -11
  47. package/lib/builder/BuildContext.js +0 -56
  48. package/lib/builder/ProjectBuildContext.js +0 -57
  49. package/lib/builder/builder.js +0 -419
  50. package/lib/tasks/TaskUtil.js +0 -160
  51. package/lib/types/AbstractBuilder.js +0 -270
  52. package/lib/types/AbstractFormatter.js +0 -66
  53. package/lib/types/AbstractUi5Formatter.js +0 -95
  54. package/lib/types/application/ApplicationBuilder.js +0 -211
  55. package/lib/types/application/ApplicationFormatter.js +0 -227
  56. package/lib/types/application/applicationType.js +0 -15
  57. package/lib/types/library/LibraryBuilder.js +0 -231
  58. package/lib/types/library/LibraryFormatter.js +0 -519
  59. package/lib/types/library/libraryType.js +0 -15
  60. package/lib/types/module/ModuleBuilder.js +0 -7
  61. package/lib/types/module/ModuleFormatter.js +0 -54
  62. package/lib/types/module/moduleType.js +0 -15
  63. package/lib/types/themeLibrary/ThemeLibraryBuilder.js +0 -63
  64. package/lib/types/themeLibrary/ThemeLibraryFormatter.js +0 -90
  65. package/lib/types/themeLibrary/themeLibraryType.js +0 -15
  66. package/lib/types/typeRepository.js +0 -46
@@ -1,227 +0,0 @@
1
- const log = require("@ui5/logger").getLogger("types:application:ApplicationFormatter");
2
- const path = require("path");
3
- const fs = require("graceful-fs");
4
- const {promisify} = require("util");
5
- const readFile = promisify(fs.readFile);
6
- const AbstractUi5Formatter = require("../AbstractUi5Formatter");
7
-
8
- class ApplicationFormatter extends AbstractUi5Formatter {
9
- /**
10
- * Constructor
11
- *
12
- * @param {object} parameters
13
- * @param {object} parameters.project Project
14
- */
15
- constructor(parameters) {
16
- super(parameters);
17
- this._pManifests = {};
18
- }
19
- /**
20
- * Formats and validates the project
21
- *
22
- * @returns {Promise}
23
- */
24
- async format() {
25
- const project = this._project;
26
- await this.validate();
27
- log.verbose("Formatting application project %s...", project.metadata.name);
28
- project.resources.pathMappings = {
29
- "/": project.resources.configuration.paths.webapp
30
- };
31
-
32
- project.metadata.namespace = await this.getNamespace();
33
- }
34
-
35
- /**
36
- * Returns the base *source* path of the project. Runtime resources like manifest.json are expected
37
- * to be located inside this path.
38
- *
39
- * @param {boolean} [posix] whether to return a POSIX path
40
- * @returns {string} Base source path of the project
41
- */
42
- getSourceBasePath(posix) {
43
- let p = path;
44
- let projectPath = this._project.path;
45
- if (posix) {
46
- projectPath = projectPath.replace(/\\/g, "/");
47
- p = path.posix;
48
- }
49
- return p.join(projectPath, this._project.resources.pathMappings["/"]);
50
- }
51
-
52
- /**
53
- * Determine application namespace either based on a project`s
54
- * manifest.json or manifest.appdescr_variant (fallback if present)
55
- *
56
- * @returns {string} Namespace of the project
57
- * @throws {Error} if namespace can not be determined
58
- */
59
- async getNamespace() {
60
- try {
61
- return await this.getNamespaceFromManifestJson();
62
- } catch (manifestJsonError) {
63
- if (manifestJsonError.code !== "ENOENT") {
64
- throw manifestJsonError;
65
- }
66
- // No manifest.json present
67
- // => attempt fallback to manifest.appdescr_variant (typical for App Variants)
68
- try {
69
- return await this.getNamespaceFromManifestAppDescVariant();
70
- } catch (appDescVarError) {
71
- if (appDescVarError.code === "ENOENT") {
72
- // Fallback not possible: No manifest.appdescr_variant present
73
- // => Throw error indicating missing manifest.json
74
- // (do not mention manifest.appdescr_variant since it is only
75
- // relevant for the rather "uncommon" App Variants)
76
- throw new Error(
77
- `Could not find required manifest.json for project ` +
78
- `${this._project.metadata.name}: ${manifestJsonError.message}`);
79
- }
80
- throw appDescVarError;
81
- }
82
- }
83
- }
84
-
85
- /**
86
- * Determine application namespace by checking manifest.json.
87
- * Any maven placeholders are resolved from the projects pom.xml
88
- *
89
- * @returns {string} Namespace of the project
90
- * @throws {Error} if namespace can not be determined
91
- */
92
- async getNamespaceFromManifestJson() {
93
- const {content: manifest} = await this.getJson("manifest.json");
94
- let appId;
95
- // check for a proper sap.app/id in manifest.json to determine namespace
96
- if (manifest["sap.app"] && manifest["sap.app"].id) {
97
- appId = manifest["sap.app"].id;
98
- } else {
99
- throw new Error(
100
- `No sap.app/id configuration found in manifest.json of project ${this._project.metadata.name}`);
101
- }
102
-
103
- if (this.hasMavenPlaceholder(appId)) {
104
- try {
105
- appId = await this.resolveMavenPlaceholder(appId);
106
- } catch (err) {
107
- throw new Error(
108
- `Failed to resolve namespace of project ${this._project.metadata.name}: ${err.message}`);
109
- }
110
- }
111
- const namespace = appId.replace(/\./g, "/");
112
- log.verbose(
113
- `Namespace of project ${this._project.metadata.name} is ${namespace} (from manifest.json)`);
114
- return namespace;
115
- }
116
-
117
- /**
118
- * Determine application namespace by checking manifest.appdescr_variant.
119
- *
120
- * @returns {string} Namespace of the project
121
- * @throws {Error} if namespace can not be determined
122
- */
123
- async getNamespaceFromManifestAppDescVariant() {
124
- const {content: manifest} = await this.getJson("manifest.appdescr_variant");
125
- let appId;
126
- // check for the id property in manifest.appdescr_variant to determine namespace
127
- if (manifest && manifest.id) {
128
- appId = manifest.id;
129
- } else {
130
- throw new Error(
131
- `No "id" property found in manifest.appdescr_variant of project ${this._project.metadata.name}`);
132
- }
133
-
134
- const namespace = appId.replace(/\./g, "/");
135
- log.verbose(
136
- `Namespace of project ${this._project.metadata.name} is ${namespace} (from manifest.appdescr_variant)`);
137
- return namespace;
138
- }
139
-
140
- /**
141
- * Reads and parses a JSON file with the provided name from the projects source directory
142
- *
143
- * @param {string} fileName Name of the JSON file to read. Typically "manifest.json" or "manifest.appdescr_variant"
144
- * @returns {Promise<object>} resolves with an object containing the <code>content</code> (as JSON) and
145
- * <code>fsPath</code> (as string) of the requested file
146
- */
147
- async getJson(fileName) {
148
- if (this._pManifests[fileName]) {
149
- return this._pManifests[fileName];
150
- }
151
- const fsPath = path.join(this.getSourceBasePath(), fileName);
152
- return this._pManifests[fileName] = readFile(fsPath)
153
- .then((content) => {
154
- return {
155
- content: JSON.parse(content),
156
- fsPath
157
- };
158
- })
159
- .catch((err) => {
160
- if (err.code === "ENOENT") {
161
- throw err;
162
- }
163
- throw new Error(
164
- `Failed to read ${fileName} for project ` +
165
- `${this._project.metadata.name}: ${err.message}`);
166
- });
167
- }
168
-
169
- /**
170
- * Validates the project
171
- *
172
- * @returns {Promise} resolves if successfully validated
173
- * @throws {Error} if validation fails
174
- */
175
- validate() {
176
- const project = this._project;
177
- return Promise.resolve().then(() => {
178
- if (!project) {
179
- throw new Error("Project is undefined");
180
- } else if (!project.metadata || !project.metadata.name) {
181
- throw new Error(`"metadata.name" configuration is missing for project ${project.id}`);
182
- } else if (!project.type) {
183
- throw new Error(`"type" configuration is missing for project ${project.id}`);
184
- } else if (project.version === undefined) {
185
- throw new Error(`"version" is missing for project ${project.id}`);
186
- }
187
-
188
- if (!project.resources) {
189
- project.resources = {};
190
- }
191
- if (!project.resources.configuration) {
192
- project.resources.configuration = {};
193
- }
194
- if (!project.resources.configuration.paths) {
195
- project.resources.configuration.paths = {};
196
- }
197
- if (!project.resources.configuration.paths.webapp) {
198
- project.resources.configuration.paths.webapp = "webapp";
199
- }
200
-
201
- if (!project.resources.configuration.propertiesFileSourceEncoding) {
202
- if (["0.1", "1.0", "1.1"].includes(project.specVersion)) {
203
- // default encoding to "ISO-8859-1" for old specVersions
204
- project.resources.configuration.propertiesFileSourceEncoding = "ISO-8859-1";
205
- } else {
206
- // default encoding to "UTF-8" for all projects starting with specVersion 2.0
207
- project.resources.configuration.propertiesFileSourceEncoding = "UTF-8";
208
- }
209
- }
210
- if (!["ISO-8859-1", "UTF-8"].includes(project.resources.configuration.propertiesFileSourceEncoding)) {
211
- throw new Error(`Invalid properties file encoding specified for project ${project.id}. ` +
212
- `Encoding provided: ${project.resources.configuration.propertiesFileSourceEncoding}. ` +
213
- `Must be either "ISO-8859-1" or "UTF-8".`);
214
- }
215
-
216
- const absolutePath = path.join(project.path, project.resources.configuration.paths.webapp);
217
- return this.dirExists(absolutePath).then((bExists) => {
218
- if (!bExists) {
219
- throw new Error(`Could not find application directory of project ${project.id}: ` +
220
- `${absolutePath}`);
221
- }
222
- });
223
- });
224
- }
225
- }
226
-
227
- module.exports = ApplicationFormatter;
@@ -1,15 +0,0 @@
1
- const ApplicationFormatter = require("./ApplicationFormatter");
2
- const ApplicationBuilder = require("./ApplicationBuilder");
3
-
4
- module.exports = {
5
- format: function(project) {
6
- return new ApplicationFormatter({project}).format();
7
- },
8
- build: function({resourceCollections, tasks, project, parentLogger, taskUtil}) {
9
- return new ApplicationBuilder({resourceCollections, project, parentLogger, taskUtil}).build(tasks);
10
- },
11
-
12
- // Export type classes for extensibility
13
- Builder: ApplicationBuilder,
14
- Formatter: ApplicationFormatter
15
- };
@@ -1,231 +0,0 @@
1
- const AbstractBuilder = require("../AbstractBuilder");
2
- const {getTask} = require("../../tasks/taskRepository");
3
-
4
- class LibraryBuilder extends AbstractBuilder {
5
- addStandardTasks({resourceCollections, project, log, taskUtil}) {
6
- if (!project.metadata.namespace) {
7
- // TODO 3.0: Throw here
8
- log.info("Skipping some tasks due to missing library namespace information. Your project " +
9
- "might be missing a manifest.json or .library file. " +
10
- "Also see: https://sap.github.io/ui5-tooling/pages/Builder/#library");
11
- }
12
-
13
- this.addTask("escapeNonAsciiCharacters", async () => {
14
- const propertiesFileSourceEncoding = project.resources &&
15
- project.resources.configuration &&
16
- project.resources.configuration.propertiesFileSourceEncoding;
17
- return getTask("escapeNonAsciiCharacters").task({
18
- workspace: resourceCollections.workspace,
19
- options: {
20
- encoding: propertiesFileSourceEncoding,
21
- pattern: "/**/*.properties"
22
- }
23
- });
24
- });
25
-
26
- this.addTask("replaceCopyright", async () => {
27
- return getTask("replaceCopyright").task({
28
- workspace: resourceCollections.workspace,
29
- options: {
30
- copyright: project.metadata.copyright,
31
- pattern: "/resources/**/*.{js,library,less,theme}"
32
- }
33
- });
34
- });
35
-
36
- this.addTask("replaceVersion", async () => {
37
- return getTask("replaceVersion").task({
38
- workspace: resourceCollections.workspace,
39
- options: {
40
- version: project.version,
41
- pattern: "/resources/**/*.{js,json,library,less,theme}"
42
- }
43
- });
44
- });
45
-
46
- this.addTask("replaceBuildtime", async () => {
47
- return getTask("replaceBuildtime").task({
48
- workspace: resourceCollections.workspace,
49
- options: {
50
- pattern: "/resources/sap/ui/Global.js"
51
- }
52
- });
53
- });
54
-
55
- if (project.metadata.namespace) {
56
- this.addTask("generateJsdoc", async () => {
57
- const patterns = ["/resources/**/*.js"];
58
- // Add excludes
59
- if (project.builder && project.builder.jsdoc && project.builder.jsdoc.excludes) {
60
- const excludes = project.builder.jsdoc.excludes.map((pattern) => {
61
- return `!/resources/${pattern}`;
62
- });
63
-
64
- patterns.push(...excludes);
65
- }
66
-
67
- return getTask("generateJsdoc").task({
68
- workspace: resourceCollections.workspace,
69
- dependencies: resourceCollections.dependencies,
70
- taskUtil,
71
- options: {
72
- projectName: project.metadata.name,
73
- namespace: project.metadata.namespace,
74
- version: project.version,
75
- pattern: patterns
76
- }
77
- });
78
- });
79
-
80
- this.addTask("executeJsdocSdkTransformation", async () => {
81
- return getTask("executeJsdocSdkTransformation").task({
82
- workspace: resourceCollections.workspace,
83
- dependencies: resourceCollections.dependencies,
84
- options: {
85
- projectName: project.metadata.name,
86
- dotLibraryPattern: "/resources/**/*.library",
87
- }
88
- });
89
- });
90
- }
91
-
92
- // Support rules should not be minified to have readable code in the Support Assistant
93
- const minificationPattern = ["/resources/**/*.js", "!**/*.support.js"];
94
- if (["2.6"].includes(project.specVersion)) {
95
- const minificationExcludes = project.builder && project.builder.minification &&
96
- project.builder.minification.excludes;
97
- if (minificationExcludes) {
98
- this.enhancePatternWithExcludes(minificationPattern, minificationExcludes, "/resources/");
99
- }
100
- }
101
-
102
- this.addTask("minify", async () => {
103
- return getTask("minify").task({
104
- workspace: resourceCollections.workspace,
105
- taskUtil,
106
- options: {
107
- pattern: minificationPattern
108
- }
109
- });
110
- });
111
-
112
- const componentPreload = project.builder && project.builder.componentPreload;
113
- if (componentPreload) {
114
- this.addTask("generateComponentPreload", async () => {
115
- return getTask("generateComponentPreload").task({
116
- workspace: resourceCollections.workspace,
117
- dependencies: resourceCollections.dependencies,
118
- taskUtil,
119
- options: {
120
- projectName: project.metadata.name,
121
- paths: componentPreload.paths,
122
- namespaces: componentPreload.namespaces,
123
- excludes: componentPreload.excludes
124
- }
125
- });
126
- });
127
- }
128
-
129
- this.addTask("generateLibraryManifest", async () => {
130
- return getTask("generateLibraryManifest").task({
131
- workspace: resourceCollections.workspace,
132
- dependencies: resourceCollections.dependencies,
133
- taskUtil,
134
- options: {
135
- projectName: project.metadata.name
136
- }
137
- });
138
- });
139
-
140
-
141
- if (project.metadata.namespace) {
142
- this.addTask("generateManifestBundle", async () => {
143
- return getTask("generateManifestBundle").task({
144
- workspace: resourceCollections.workspace,
145
- options: {
146
- projectName: project.metadata.name,
147
- namespace: project.metadata.namespace
148
- }
149
- });
150
- });
151
- }
152
-
153
- this.addTask("generateLibraryPreload", async () => {
154
- return getTask("generateLibraryPreload").task({
155
- workspace: resourceCollections.workspace,
156
- dependencies: resourceCollections.dependencies,
157
- taskUtil,
158
- options: {
159
- projectName: project.metadata.name,
160
- excludes:
161
- project.builder &&
162
- project.builder.libraryPreload &&
163
- project.builder.libraryPreload.excludes
164
- }
165
- });
166
- });
167
-
168
- const bundles = project.builder && project.builder.bundles;
169
- if (bundles) {
170
- this.addTask("generateBundle", async () => {
171
- return bundles.reduce(function(sequence, bundle) {
172
- return sequence.then(function() {
173
- return getTask("generateBundle").task({
174
- workspace: resourceCollections.workspace,
175
- dependencies: resourceCollections.dependencies,
176
- taskUtil,
177
- options: {
178
- projectName: project.metadata.name,
179
- bundleDefinition: bundle.bundleDefinition,
180
- bundleOptions: bundle.bundleOptions
181
- }
182
- });
183
- });
184
- }, Promise.resolve());
185
- });
186
- }
187
-
188
- this.addTask("buildThemes", async () => {
189
- // Only compile themes directly below the lib namespace to be in sync with the theme support at runtime
190
- // which only loads themes from that folder.
191
- // TODO 3.0: Remove fallback in case of missing namespace
192
- const inputPattern = `/resources/${project.metadata.namespace || "**"}/themes/*/library.source.less`;
193
-
194
- return getTask("buildThemes").task({
195
- workspace: resourceCollections.workspace,
196
- dependencies: resourceCollections.dependencies,
197
- options: {
198
- projectName: project.metadata.name,
199
- librariesPattern: !taskUtil.isRootProject() ? "/resources/**/(*.library|library.js)" : undefined,
200
- themesPattern: !taskUtil.isRootProject() ? "/resources/sap/ui/core/themes/*" : undefined,
201
- inputPattern
202
- }
203
- });
204
- });
205
-
206
- this.addTask("generateThemeDesignerResources", async () => {
207
- return getTask("generateThemeDesignerResources").task({
208
- workspace: resourceCollections.workspace,
209
- dependencies: resourceCollections.dependencies,
210
- options: {
211
- projectName: project.metadata.name,
212
- version: project.version,
213
- namespace: project.metadata.namespace
214
- }
215
- });
216
- });
217
-
218
- this.addTask("generateResourcesJson", () => {
219
- return getTask("generateResourcesJson").task({
220
- workspace: resourceCollections.workspace,
221
- dependencies: resourceCollections.dependencies,
222
- taskUtil,
223
- options: {
224
- projectName: project.metadata.name
225
- }
226
- });
227
- });
228
- }
229
- }
230
-
231
- module.exports = LibraryBuilder;