-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE] Theme Build: Add compress option to minify output (#295)
- Loading branch information
Showing
11 changed files
with
243 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 3 additions & 1 deletion
4
test/expected/build/theme.j/dest/resources/theme/j/themes/somefancytheme/Button.less
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
.someClass{color:black} | ||
.someClass { | ||
color: @someColor | ||
} |
7 changes: 2 additions & 5 deletions
7
test/expected/build/theme.j/dest/resources/theme/j/themes/somefancytheme/library-RTL.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,3 @@ | ||
.someClass { | ||
color: #000000; | ||
} | ||
|
||
.someClass{color:#000} | ||
/* Inline theming parameters */ | ||
#sap-ui-theme-theme\.j{background-image:url('data:text/plain;utf-8,%7B%7D')} | ||
#sap-ui-theme-theme\.j{background-image:url('data:text/plain;utf-8,%7B%22someColor%22%3A%22%23000%22%7D')} |
2 changes: 1 addition & 1 deletion
2
...pected/build/theme.j/dest/resources/theme/j/themes/somefancytheme/library-parameters.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{} | ||
{"someColor":"#000"} |
7 changes: 2 additions & 5 deletions
7
test/expected/build/theme.j/dest/resources/theme/j/themes/somefancytheme/library.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,3 @@ | ||
.someClass { | ||
color: #000000; | ||
} | ||
|
||
.someClass{color:#000} | ||
/* Inline theming parameters */ | ||
#sap-ui-theme-theme\.j{background-image:url('data:text/plain;utf-8,%7B%7D')} | ||
#sap-ui-theme-theme\.j{background-image:url('data:text/plain;utf-8,%7B%22someColor%22%3A%22%23000%22%7D')} |
1 change: 1 addition & 0 deletions
1
test/expected/build/theme.j/dest/resources/theme/j/themes/somefancytheme/library.source.less
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
@someColor: black; | ||
@import "Button.less"; |
4 changes: 3 additions & 1 deletion
4
test/fixtures/theme.j/main/src/theme/j/themes/somefancytheme/Button.less
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
.someClass{color:black} | ||
.someClass { | ||
color: @someColor | ||
} |
1 change: 1 addition & 0 deletions
1
test/fixtures/theme.j/main/src/theme/j/themes/somefancytheme/library.source.less
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
@someColor: black; | ||
@import "Button.less"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,208 @@ | ||
const test = require("ava"); | ||
|
||
const resourceFactory = require("@ui5/fs").resourceFactory; | ||
const fsInterface = require("@ui5/fs").fsInterface; | ||
|
||
const themeBuilderProcessor = require("../../../lib/processors/themeBuilder"); | ||
const ThemeBuilder = require("../../../lib/processors/themeBuilder").ThemeBuilder; | ||
|
||
function prepareResources({library} = {}) { | ||
const input = | ||
`@someColor: black; | ||
.someClass { | ||
color: @someColor; | ||
padding: 1px 2px 3px 4px; | ||
}`; | ||
|
||
const memoryAdapter = resourceFactory.createAdapter({ | ||
virBasePath: "/" | ||
}); | ||
|
||
let lessFilePath; | ||
if (library === false) { | ||
lessFilePath = "/resources/foo.less"; | ||
} else { | ||
lessFilePath = "/resources/sap/ui/foo/themes/base/library.source.less"; | ||
} | ||
|
||
const resource = resourceFactory.createResource({ | ||
path: lessFilePath, | ||
string: input | ||
}); | ||
|
||
memoryAdapter.write(resource); | ||
|
||
return { | ||
resource, | ||
memoryAdapter | ||
}; | ||
} | ||
|
||
function getExpectedResults({compress, library}) { | ||
let css; let cssRtl; let json; | ||
if (compress) { | ||
css = | ||
`.someClass{color:#000;padding:1px 2px 3px 4px}`; | ||
|
||
cssRtl = | ||
`.someClass{color:#000;padding:1px 4px 3px 2px}`; | ||
json = `{"someColor":"#000"}`; | ||
} else { | ||
css = | ||
`.someClass { | ||
color: #000000; | ||
padding: 1px 2px 3px 4px; | ||
} | ||
`; | ||
|
||
cssRtl = | ||
`.someClass { | ||
color: #000000; | ||
padding: 1px 4px 3px 2px; | ||
} | ||
`; | ||
|
||
json = | ||
`{ | ||
"someColor": "#000000" | ||
}`; | ||
} | ||
|
||
if (library !== false) { | ||
css += | ||
` | ||
/* Inline theming parameters */ | ||
#sap-ui-theme-sap\\.ui\\.foo{background-image:url('data:text/plain;utf-8,%7B%22someColor%22%3A%22%23${compress ? "000" : "000000"}%22%7D')} | ||
`; | ||
cssRtl += | ||
` | ||
/* Inline theming parameters */ | ||
#sap-ui-theme-sap\\.ui\\.foo{background-image:url('data:text/plain;utf-8,%7B%22someColor%22%3A%22%23${compress ? "000" : "000000"}%22%7D')} | ||
`; | ||
} | ||
|
||
return {css, cssRtl, json}; | ||
} | ||
|
||
test("Processor: Builds a less file (default options)", async (t) => { | ||
const {resource, memoryAdapter} = prepareResources(); | ||
|
||
const [cssResource, cssRtlResource, jsonResource] = await themeBuilderProcessor({ | ||
resources: [resource], | ||
fs: fsInterface(memoryAdapter) | ||
}); | ||
|
||
const expected = getExpectedResults({compress: false}); | ||
t.is(await cssResource.getString(), expected.css, "CSS should be correct"); | ||
t.is(await cssRtlResource.getString(), expected.cssRtl, "Right-to-left CSS should be correct"); | ||
t.is(await jsonResource.getString(), expected.json, "JSON should be correct"); | ||
}); | ||
|
||
test("Processor: Builds a less file (compress = true)", async (t) => { | ||
const {resource, memoryAdapter} = prepareResources(); | ||
|
||
const [cssResource, cssRtlResource, jsonResource] = await themeBuilderProcessor({ | ||
resources: [resource], | ||
fs: fsInterface(memoryAdapter), | ||
options: { | ||
compress: true | ||
} | ||
}); | ||
|
||
const expected = getExpectedResults({compress: true}); | ||
t.is(await cssResource.getString(), expected.css, "CSS should be correct"); | ||
t.is(await cssRtlResource.getString(), expected.cssRtl, "Right-to-left CSS should be correct"); | ||
t.is(await jsonResource.getString(), expected.json, "JSON should be correct"); | ||
}); | ||
|
||
test("Processor: Builds a less file (compress = false)", async (t) => { | ||
const {resource, memoryAdapter} = prepareResources(); | ||
|
||
const [cssResource, cssRtlResource, jsonResource] = await themeBuilderProcessor({ | ||
resources: [resource], | ||
fs: fsInterface(memoryAdapter), | ||
options: { | ||
compress: false | ||
} | ||
}); | ||
|
||
const expected = getExpectedResults({compress: false}); | ||
t.is(await cssResource.getString(), expected.css, "CSS should be correct"); | ||
t.is(await cssRtlResource.getString(), expected.cssRtl, "Right-to-left CSS should be correct"); | ||
t.is(await jsonResource.getString(), expected.json, "JSON should be correct"); | ||
}); | ||
|
||
test("Processor: Builds a less file (no library)", async (t) => { | ||
const {resource, memoryAdapter} = prepareResources({library: false}); | ||
|
||
const [cssResource, cssRtlResource, jsonResource] = await themeBuilderProcessor({ | ||
resources: [resource], | ||
fs: fsInterface(memoryAdapter), | ||
options: { | ||
compress: false | ||
} | ||
}); | ||
|
||
const expected = getExpectedResults({compress: false, library: false}); | ||
t.is(await cssResource.getString(), expected.css, "CSS should be correct"); | ||
t.is(await cssRtlResource.getString(), expected.cssRtl, "Right-to-left CSS should be correct"); | ||
t.is(await jsonResource.getString(), expected.json, "JSON should be correct"); | ||
}); | ||
|
||
test("ThemeBuilder: Builds a less file", async (t) => { | ||
const {resource, memoryAdapter} = prepareResources(); | ||
|
||
const themeBuilder = new ThemeBuilder({fs: fsInterface(memoryAdapter)}); | ||
|
||
const [cssResource, cssRtlResource, jsonResource] = await themeBuilder.build([resource]); | ||
|
||
const expected = getExpectedResults({compress: false}); | ||
t.is(await cssResource.getString(), expected.css, "CSS should be correct"); | ||
t.is(await cssRtlResource.getString(), expected.cssRtl, "Right-to-left CSS should be correct"); | ||
t.is(await jsonResource.getString(), expected.json, "JSON should be correct"); | ||
}); | ||
|
||
test("ThemeBuilder: Builds a less file (compress = true)", async (t) => { | ||
const {resource, memoryAdapter} = prepareResources(); | ||
|
||
const themeBuilder = new ThemeBuilder({fs: fsInterface(memoryAdapter)}); | ||
|
||
const [cssResource, cssRtlResource, jsonResource] = await themeBuilder.build([resource], { | ||
compress: true | ||
}); | ||
|
||
const expected = getExpectedResults({compress: true}); | ||
t.is(await cssResource.getString(), expected.css, "CSS should be correct"); | ||
t.is(await cssRtlResource.getString(), expected.cssRtl, "Right-to-left CSS should be correct"); | ||
t.is(await jsonResource.getString(), expected.json, "JSON should be correct"); | ||
}); | ||
|
||
test("ThemeBuilder: Builds a less file (compress = false)", async (t) => { | ||
const {resource, memoryAdapter} = prepareResources(); | ||
|
||
const themeBuilder = new ThemeBuilder({fs: fsInterface(memoryAdapter)}); | ||
|
||
const [cssResource, cssRtlResource, jsonResource] = await themeBuilder.build([resource], { | ||
compress: false | ||
}); | ||
|
||
const expected = getExpectedResults({compress: false}); | ||
t.is(await cssResource.getString(), expected.css, "CSS should be correct"); | ||
t.is(await cssRtlResource.getString(), expected.cssRtl, "Right-to-left CSS should be correct"); | ||
t.is(await jsonResource.getString(), expected.json, "JSON should be correct"); | ||
}); | ||
|
||
test("ThemeBuilder: Builds a less file (no library)", async (t) => { | ||
const {resource, memoryAdapter} = prepareResources({library: false}); | ||
|
||
const themeBuilder = new ThemeBuilder({fs: fsInterface(memoryAdapter)}); | ||
|
||
const [cssResource, cssRtlResource, jsonResource] = await themeBuilder.build([resource], { | ||
compress: false | ||
}); | ||
|
||
const expected = getExpectedResults({compress: false, library: false}); | ||
t.is(await cssResource.getString(), expected.css, "CSS should be correct"); | ||
t.is(await cssRtlResource.getString(), expected.cssRtl, "Right-to-left CSS should be correct"); | ||
t.is(await jsonResource.getString(), expected.json, "JSON should be correct"); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters