Skip to content
This repository has been archived by the owner on May 24, 2023. It is now read-only.

Commit

Permalink
Merge pull request #25 from SAP/exclude-dest-file
Browse files Browse the repository at this point in the history
Always exclude corresponding preload files
  • Loading branch information
matz3 committed Apr 25, 2016
2 parents e761993 + 92cd3d8 commit e26c3c0
Show file tree
Hide file tree
Showing 14 changed files with 186 additions and 2 deletions.
76 changes: 75 additions & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ module.exports = function(grunt) {

// Before generating any new files, remove any previously-created files.
clean: {
tests: ['tmp']
tests: [
'tmp',
'test/preload/fixtures/app-same-dest/my/app/Component-preload.js',
'test/preload/fixtures/library-same-dest/my/ui/lib/library-preload.json'
]
},

// Configuration to be run (and then tested).
Expand Down Expand Up @@ -111,6 +115,24 @@ module.exports = function(grunt) {
components: '**'
},

// The following two targets are testing that a generated preload file
// doesn't get included when runnign the preload again
// (same folder for src and dest)
'component_same_dest_1': {
options: {
resources: 'test/preload/fixtures/app-same-dest',
dest: 'test/preload/fixtures/app-same-dest'
},
components: '**'
},
'component_same_dest_2': {
options: {
resources: 'test/preload/fixtures/app-same-dest',
dest: 'test/preload/fixtures/app-same-dest'
},
components: '**'
},

'library_default_options': {
options: {
resources: 'test/preload/fixtures/library',
Expand Down Expand Up @@ -139,6 +161,58 @@ module.exports = function(grunt) {
compress: false
},
libraries: '**'
},

// The following two targets are testing that a generated preload file
// doesn't get included when runnign the preload again
// (same folder for src and dest)
'library_same_dest_1': {
options: {
resources: [
{
cwd: 'test/preload/fixtures/library-same-dest',
src: [
// Defaults
'**/*.js',
'**/*.fragment.html',
'**/*.fragment.json',
'**/*.fragment.xml',
'**/*.view.html',
'**/*.view.json',
'**/*.view.xml',
'**/*.properties',
// Include "library-preload.json" for this test
'**/library-preload.json'
]
}
],
dest: 'test/preload/fixtures/library-same-dest'
},
libraries: '**'
},
'library_same_dest_2': {
options: {
resources: [
{
cwd: 'test/preload/fixtures/library-same-dest',
src: [
// Defaults
'**/*.js',
'**/*.fragment.html',
'**/*.fragment.json',
'**/*.fragment.xml',
'**/*.view.html',
'**/*.view.json',
'**/*.view.xml',
'**/*.properties',
// Include "library-preload.json" for this test
'**/library-preload.json'
]
}
],
dest: 'test/preload/fixtures/library-same-dest'
},
libraries: '**'
}

},
Expand Down
10 changes: 9 additions & 1 deletion tasks/preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,15 @@ module.exports = function (grunt) {
preloadObject.name = preloadModuleName;
}

var preloadPatterns = preloadOption.src ? preloadOption.src : (preloadDir + '/**');
var preloadPatterns = preloadOption.src ? preloadOption.src : [ preloadDir + '/**' ];
if (typeof preloadPatterns === "string") {
preloadPatterns = [ preloadPatterns ];
}

// Always exclude the corresponding preload file (Component-preload.js / library-preload.json)
// Otherwise it might get included every time the build runs if src / dest are the same dir
preloadPatterns.push('!' + preloadDir + '/' + preloadInfo.moduleName + preloadInfo.ext);

var preloadFiles = grunt.file.match(preloadPatterns, resourceFiles);
if (preloadFiles.length === 0) {
var patternsString = (typeof preloadPatterns === 'string') ? preloadPatterns : preloadPatterns.join('", "');
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
jQuery.sap.registerPreloadedModules({
"version": "2.0",
"name": "my/app/Component-preload",
"modules": {
"my/app/Component.js": "/* © */\n\"use strict\";function myFunction(n,o){return n+o}/**\n* This is a copyright comment\n*/\n/* (c) */\n/* released under */\n/* license */\nconsole.log(\"myJS\");",
"my/app/view/my.view.xml": "<my>XML</my>\n",
"my/app/view/myHtmlPre.view.xml": "<my>XML</my>\n<!-- A comment in XML is the same as in HTML -->\n<html:pre> </html:pre>"
}
});
22 changes: 22 additions & 0 deletions test/preload/fixtures/app-same-dest/my/app/Component.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* © */
'use strict';

/**
* This is a copyright comment
*/

/* (c) */

/* released under */
/* normal comment */
/* license */


console.log('myJS');

/**
* This is a little comment
*/
function myFunction(longVariableName, longerVariableName) {
return longVariableName + longerVariableName;
}
2 changes: 2 additions & 0 deletions test/preload/fixtures/app-same-dest/my/app/view/my.view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<my>XML</my>
<!-- A comment in XML is the same as in HTML -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<my>XML</my>
<!-- A comment in XML is the same as in HTML -->
<html:pre> </html:pre>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FOO=BAR
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"version": "2.0",
"name": "my.ui.lib.library-preload",
"modules": {
"my/ui/lib/library.js": "jQuery.sap.require(\"sap.ui.core.library\"),jQuery.sap.declare(\"my.ui.lib.library\"),sap.ui.getCore().initLibrary({name:\"my.ui.lib\",version:\"0.0.0\",dependencies:[\"sap.ui.core\"]});",
"my/ui/lib/myJS.js": "/* © */\n\"use strict\";function myFunction(n,o){return n+o}/**\n* This is a copyright comment\n*/\n/* (c) */\n/* released under */\n/* license */\nconsole.log(\"myJS\");",
"my/ui/lib/my.view.xml": "<my>XML</my>\n",
"my/ui/lib/myHtmlPre.view.xml": "<my>XML</my>\n<!-- A comment in XML is the same as in HTML -->\n<html:pre> </html:pre>",
"my/ui/lib/foo.properties": "FOO=BAR\n"
}
}
8 changes: 8 additions & 0 deletions test/preload/fixtures/library-same-dest/my/ui/lib/library.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
jQuery.sap.require("sap.ui.core.library");
jQuery.sap.declare("my.ui.lib.library");

sap.ui.getCore().initLibrary({
name : "my.ui.lib",
version: "0.0.0",
dependencies : ["sap.ui.core"]
});
2 changes: 2 additions & 0 deletions test/preload/fixtures/library-same-dest/my/ui/lib/my.view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<my>XML</my>
<!-- A comment in XML is the same as in HTML -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<my>XML</my>
<!-- A comment in XML is the same as in HTML -->
<html:pre> </html:pre>
22 changes: 22 additions & 0 deletions test/preload/fixtures/library-same-dest/my/ui/lib/myJS.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* © */
'use strict';

/**
* This is a copyright comment
*/

/* (c) */

/* released under */
/* normal comment */
/* license */


console.log('myJS');

/**
* This is a little comment
*/
function myFunction(longVariableName, longerVariableName) {
return longVariableName + longerVariableName;
}
3 changes: 3 additions & 0 deletions test/preload/fixtures/library-same-dest/my/ui/lib/myJSON.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"my": "json"
}
16 changes: 16 additions & 0 deletions test/preload_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ describe('openui5_preload', function() {
});
});

it('library_same_dest', function() {
fileContent.equal({
sActualFileSource: 'test/preload/fixtures/library-same-dest/my/ui/lib/library-preload.json',
sExpectedFileSource: 'test/preload/expected/library_default_options/my/ui/lib/library-preload.json',
sMessage: 'library preload JSON should be correctly created.'
});
});

});

describe('component', function() {
Expand Down Expand Up @@ -73,6 +81,14 @@ describe('openui5_preload', function() {
});
});

it('component_same_dest', function() {
fileContent.equal({
sActualFileSource: 'test/preload/fixtures/app-same-dest/my/app/Component-preload.js',
sExpectedFileSource: 'test/preload/expected/component_default_options/my/app/Component-preload.js',
sMessage: 'component preload JS should be correctly created.'
});
});

});

});

0 comments on commit e26c3c0

Please sign in to comment.