Skip to content

Commit f99dadb

Browse files
committed
refactor(project): Use dedicated build definition for component type
1 parent fd6d31f commit f99dadb

File tree

3 files changed

+529
-1
lines changed

3 files changed

+529
-1
lines changed

packages/project/lib/build/TaskRunner.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class TaskRunner {
5454
buildDefinition = "./definitions/library.js";
5555
break;
5656
case "component":
57-
buildDefinition = "./definitions/application.js";
57+
buildDefinition = "./definitions/component.js";
5858
break;
5959
case "module":
6060
buildDefinition = "./definitions/module.js";
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
import {enhancePatternWithExcludes} from "./_utils.js";
2+
import {enhanceBundlesWithDefaults} from "../../validation/validator.js";
3+
4+
/**
5+
* Get tasks and their configuration for a given component project
6+
*
7+
* @private
8+
* @param {object} parameters
9+
* @param {object} parameters.project
10+
* @param {object} parameters.taskUtil
11+
* @param {Function} parameters.getTask
12+
*/
13+
export default function({project, taskUtil, getTask}) {
14+
const tasks = new Map();
15+
tasks.set("escapeNonAsciiCharacters", {
16+
options: {
17+
encoding: project.getPropertiesFileSourceEncoding(),
18+
pattern: "/**/*.properties"
19+
}
20+
});
21+
22+
tasks.set("replaceCopyright", {
23+
options: {
24+
copyright: project.getCopyright(),
25+
pattern: "/**/*.{js,json}"
26+
}
27+
});
28+
29+
tasks.set("replaceVersion", {
30+
options: {
31+
version: project.getVersion(),
32+
pattern: "/**/*.{js,json}"
33+
}
34+
});
35+
36+
// Support rules should not be minified to have readable code in the Support Assistant
37+
const minificationPattern = ["/**/*.js", "!**/*.support.js"];
38+
const minificationExcludes = project.getMinificationExcludes();
39+
if (minificationExcludes.length) {
40+
enhancePatternWithExcludes(minificationPattern, minificationExcludes, "/resources/");
41+
}
42+
43+
tasks.set("minify", {
44+
options: {
45+
pattern: minificationPattern
46+
}
47+
});
48+
49+
tasks.set("enhanceManifest", {});
50+
51+
tasks.set("generateFlexChangesBundle", {});
52+
53+
const bundles = project.getBundles();
54+
const existingBundleDefinitionNames =
55+
bundles.map(({bundleDefinition}) => bundleDefinition.name).filter(Boolean);
56+
57+
const componentPreloadPaths = project.getComponentPreloadPaths();
58+
const componentPreloadNamespaces = project.getComponentPreloadNamespaces();
59+
const componentPreloadExcludes = project.getComponentPreloadExcludes();
60+
if (componentPreloadPaths.length || componentPreloadNamespaces.length) {
61+
tasks.set("generateComponentPreload", {
62+
options: {
63+
paths: componentPreloadPaths,
64+
namespaces: componentPreloadNamespaces,
65+
excludes: componentPreloadExcludes,
66+
skipBundles: existingBundleDefinitionNames
67+
}
68+
});
69+
} else {
70+
// Default component preload
71+
tasks.set("generateComponentPreload", {
72+
options: {
73+
namespaces: [project.getNamespace()],
74+
excludes: componentPreloadExcludes,
75+
skipBundles: existingBundleDefinitionNames
76+
}
77+
});
78+
}
79+
80+
if (bundles.length) {
81+
tasks.set("generateBundle", {
82+
requiresDependencies: true,
83+
taskFunction: async ({workspace, dependencies, taskUtil, options}) => {
84+
const generateBundleTask = await getTask("generateBundle");
85+
// Async resolve default values for bundle definitions and options
86+
const bundlesDefaults = await enhanceBundlesWithDefaults(bundles, taskUtil.getProject());
87+
88+
return bundlesDefaults.reduce(async function(sequence, bundle) {
89+
return sequence.then(function() {
90+
return generateBundleTask.task({
91+
workspace,
92+
dependencies,
93+
taskUtil,
94+
options: {
95+
projectName: options.projectName,
96+
bundleDefinition: bundle.bundleDefinition,
97+
bundleOptions: bundle.bundleOptions
98+
}
99+
});
100+
});
101+
}, Promise.resolve());
102+
}
103+
});
104+
} else {
105+
// No bundles defined. Just set task so that it can be referenced by custom tasks
106+
tasks.set("generateBundle", {
107+
taskFunction: null
108+
});
109+
}
110+
111+
tasks.set("generateVersionInfo", {
112+
requiresDependencies: true,
113+
options: {
114+
rootProject: project,
115+
pattern: "/resources/**/.library"
116+
}
117+
});
118+
119+
tasks.set("generateCachebusterInfo", {
120+
options: {
121+
signatureType: project.getCachebusterSignatureType(),
122+
}
123+
});
124+
125+
tasks.set("generateResourcesJson", {requiresDependencies: true});
126+
127+
return tasks;
128+
}

0 commit comments

Comments
 (0)