-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE] Generate the AppCacheBuster index file for apps
- Loading branch information
1 parent
b39b944
commit dd653c8
Showing
19 changed files
with
233 additions
and
2 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
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,30 @@ | ||
const resourceFactory = require("@ui5/fs").resourceFactory; | ||
|
||
/** | ||
* Task to generate the application cachebuster info file. | ||
* | ||
* @public | ||
* @alias module:@ui5/builder.tasks.generateCachebusterInfo | ||
* @param {Object} parameters Parameters | ||
* @param {module:@ui5/fs.DuplexCollection} parameters.workspace DuplexCollection to read and write files | ||
* @param {module:@ui5/fs.AbstractReader} parameters.dependencies Reader or Collection to read dependency files | ||
* @param {Object} parameters.options Options | ||
* @param {string} parameters.options.namespace Namespace of the application | ||
* @returns {Promise<undefined>} Promise resolving with <code>undefined</code> once data has been written | ||
*/ | ||
module.exports = function({workspace, dependencies, options}) { | ||
return workspace.byGlob(`/resources/${options.namespace}/**/*`) | ||
.then(async (resources) => { | ||
const cachebusterInfo = {}; | ||
const regex = new RegExp(`^/resources/${options.namespace}/`); | ||
resources.forEach((resource) => { | ||
const normalizedPath = resource.getPath().replace(regex, ""); | ||
cachebusterInfo[normalizedPath] = resource.getStatInfo().mtime.getTime(); | ||
}); | ||
const cachebusterInfoResource = resourceFactory.createResource({ | ||
path: `/resources/${options.namespace}/sap-ui-cachebuster-info.json`, | ||
string: JSON.stringify(cachebusterInfo, null, 2) | ||
}); | ||
return workspace.write(cachebusterInfoResource); | ||
}); | ||
}; |
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
8 changes: 8 additions & 0 deletions
8
test/expected/build/application.g/cachebuster/Component-dbg.js
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,8 @@ | ||
sap.ui.define(["sap/ui/core/UIComponent"], function(UIComponent){ | ||
"use strict"; | ||
return UIComponent.extend('application.g.Component', { | ||
metadata: { | ||
manifest: "json" | ||
} | ||
}); | ||
}); |
13 changes: 13 additions & 0 deletions
13
test/expected/build/application.g/cachebuster/Component-preload.js
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,13 @@ | ||
jQuery.sap.registerPreloadedModules({ | ||
"version":"2.0", | ||
"modules":{ | ||
"application.g/Component.js":function(){sap.ui.define(["sap/ui/core/UIComponent"],function(n){"use strict";return n.extend("application.g.Component",{metadata:{manifest:"json"}})}); | ||
}, | ||
"application.g/manifest.json":'{"_version":"1.1.0","sap.app":{"_version":"1.1.0","id":"application.g","type":"application","applicationVersion":{"version":"1.0.0"},"embeds":["embedded"],"title":"{{title}}"},"customCopyrightString":"Some fancy copyright"}', | ||
"application.g/subcomponentA/Component.js":function(){sap.ui.define(["sap/ui/core/UIComponent"],function(n){"use strict";return n.extend("application.g.subcomponentA.Component",{metadata:{manifest:"json"}})}); | ||
}, | ||
"application.g/subcomponentA/manifest.json":'{"_version":"1.1.0","sap.app":{"_version":"1.1.0","id":"application.g.subcomponentA","type":"application","applicationVersion":{"version":"1.2.2"},"embeds":["embedded"],"title":"{{title}}"}}', | ||
"application.g/subcomponentB/Component.js":function(){sap.ui.define(["sap/ui/core/UIComponent"],function(n){"use strict";return n.extend("application.g.subcomponentB.Component",{metadata:{manifest:"json"}})}); | ||
}, | ||
"application.g/subcomponentB/manifest.json":'{"_version":"1.1.0","sap.app":{"_version":"1.1.0","id":"application.g.subcomponentB","type":"application","applicationVersion":{"version":"1.2.2"},"embeds":["embedded"],"title":"{{title}}"}}' | ||
}}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
14 changes: 14 additions & 0 deletions
14
test/expected/build/application.g/cachebuster/manifest.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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"_version": "1.1.0", | ||
"sap.app": { | ||
"_version": "1.1.0", | ||
"id": "application.g", | ||
"type": "application", | ||
"applicationVersion": { | ||
"version": "1.0.0" | ||
}, | ||
"embeds": ["embedded"], | ||
"title": "{{title}}" | ||
}, | ||
"customCopyrightString": "Some fancy copyright" | ||
} |
12 changes: 12 additions & 0 deletions
12
test/expected/build/application.g/cachebuster/sap-ui-cachebuster-info.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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"Component-dbg.js": 1540570258000, | ||
"subcomponentA/manifest.json": 1540570258000, | ||
"subcomponentB/manifest.json": 1540570258000, | ||
"subcomponentB/Component.js": 1540570258000, | ||
"subcomponentA/Component.js": 1540570258000, | ||
"Component.js": 1540570258000, | ||
"Component-preload.js": 1554823987259, | ||
"subcomponentB/Component-dbg.js": 1540570258000, | ||
"subcomponentA/Component-dbg.js": 1540570258000, | ||
"manifest.json": 1540570258000 | ||
} |
8 changes: 8 additions & 0 deletions
8
test/expected/build/application.g/cachebuster/subcomponentA/Component-dbg.js
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,8 @@ | ||
sap.ui.define(["sap/ui/core/UIComponent"], function(UIComponent){ | ||
"use strict"; | ||
return UIComponent.extend('application.g.subcomponentA.Component', { | ||
metadata: { | ||
manifest: "json" | ||
} | ||
}); | ||
}); |
1 change: 1 addition & 0 deletions
1
test/expected/build/application.g/cachebuster/subcomponentA/Component.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
13 changes: 13 additions & 0 deletions
13
test/expected/build/application.g/cachebuster/subcomponentA/manifest.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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"_version": "1.1.0", | ||
"sap.app": { | ||
"_version": "1.1.0", | ||
"id": "application.g.subcomponentA", | ||
"type": "application", | ||
"applicationVersion": { | ||
"version": "1.2.2" | ||
}, | ||
"embeds": ["embedded"], | ||
"title": "{{title}}" | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
test/expected/build/application.g/cachebuster/subcomponentB/Component-dbg.js
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,8 @@ | ||
sap.ui.define(["sap/ui/core/UIComponent"], function(UIComponent){ | ||
"use strict"; | ||
return UIComponent.extend('application.g.subcomponentB.Component', { | ||
metadata: { | ||
manifest: "json" | ||
} | ||
}); | ||
}); |
1 change: 1 addition & 0 deletions
1
test/expected/build/application.g/cachebuster/subcomponentB/Component.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
13 changes: 13 additions & 0 deletions
13
test/expected/build/application.g/cachebuster/subcomponentB/manifest.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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"_version": "1.1.0", | ||
"sap.app": { | ||
"_version": "1.1.0", | ||
"id": "application.g.subcomponentB", | ||
"type": "application", | ||
"applicationVersion": { | ||
"version": "1.2.2" | ||
}, | ||
"embeds": ["embedded"], | ||
"title": "{{title}}" | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
const {test} = require("ava"); | ||
const fs = require("fs"); | ||
const path = require("path"); | ||
const chai = require("chai"); | ||
chai.use(require("chai-fs")); | ||
const assert = chai.assert; | ||
|
||
|
||
const ui5Builder = require("../../../"); | ||
const builder = ui5Builder.builder; | ||
const applicationGPath = path.join(__dirname, "..", "..", "fixtures", "application.g"); | ||
|
||
const recursive = require("recursive-readdir"); | ||
|
||
const findFiles = (folder) => { | ||
return new Promise((resolve, reject) => { | ||
recursive(folder, (err, files) => { | ||
if (err) { | ||
reject(err); | ||
} else { | ||
resolve(files); | ||
} | ||
}); | ||
}); | ||
}; | ||
|
||
test("integration: Build application.g with manifestBundler", (t) => { | ||
const destPath = path.join("test", "tmp", "build", "application.g", "cachebuster"); | ||
const expectedPath = path.join("test", "expected", "build", "application.g", "cachebuster"); | ||
const excludedTasks = ["generateVersionInfo"]; | ||
const includedTasks = ["generateCachebusterInfo"]; | ||
|
||
return builder.build({ | ||
tree: applicationGTree, | ||
destPath, | ||
excludedTasks, | ||
includedTasks | ||
}).then(() => { | ||
return findFiles(expectedPath); | ||
}).then((expectedFiles) => { | ||
// Check for all directories and files | ||
assert.directoryDeepEqual(destPath, expectedPath); | ||
|
||
// Check for all file contents | ||
expectedFiles.forEach((expectedFile) => { | ||
const relativeFile = path.relative(expectedPath, expectedFile); | ||
const destFile = path.join(destPath, relativeFile); | ||
if (expectedFile.endsWith("sap-ui-cachebuster-info.json")) { | ||
const currentContent = JSON.parse(fs.readFileSync(destFile, "utf-8").replace(/(:\s+)(\d+)/g, ": 0")); | ||
const expectedContent = JSON.parse(fs.readFileSync(expectedFile, "utf-8").replace(/(:\s+)(\d+)/g, ": 0")); | ||
assert.deepEqual(currentContent, expectedContent); | ||
} else { | ||
assert.fileEqual(destFile, expectedFile); | ||
} | ||
}); | ||
t.pass(); | ||
}); | ||
}); | ||
|
||
const applicationGTree = { | ||
"id": "application.g", | ||
"version": "1.0.0", | ||
"path": applicationGPath, | ||
"dependencies": [], | ||
"builder": {}, | ||
"_level": 0, | ||
"specVersion": "0.1", | ||
"type": "application", | ||
"metadata": { | ||
"name": "application.g", | ||
"namespace": "application.g", | ||
"copyright": "Some fancy copyright" | ||
}, | ||
"resources": { | ||
"configuration": { | ||
"paths": { | ||
"webapp": "webapp" | ||
} | ||
}, | ||
"pathMappings": { | ||
"/": "webapp" | ||
} | ||
} | ||
}; |
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