Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module.exports = function (options) {

options = options || {};
options.isLibrary = !!options.isLibrary;
options.fileName = options.fileName || (options.isLibrary ? 'library-preload.json' : 'Component-preload.js');
options.fileName = options.fileName || ((options.isLibrary ? 'library-preload.' : 'Component-preload.') + (options.format || 'js'));

if (typeof options.base !== 'string') {
throw new PluginError('gulp-ui5-preload', '`base` parameter required');
Expand Down Expand Up @@ -64,9 +64,11 @@ module.exports = function (options) {
var template = 'jQuery.sap.registerPreloadedModules(JSON_CONTENT);';
var suffix = '.Component-preload';
if (options.isLibrary) {
template = 'JSON_CONTENT';
suffix = '.library-preload';
}
if (options.fileName.slice(-4) === 'json') {
template = 'JSON_CONTENT';
}

var jsonContent = JSON.stringify(
{
Expand Down
10 changes: 8 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,21 @@ The namespace at the `base` path. All source files are treated as sub-namespaces

##### fileName
* Type: `string`
* Default: 'Component-preload.js' or 'library-preload.json' (depends on `isLibrary` option)
* Default: 'Component-preload.js' or 'library-preload.js' (depends on `isLibrary` option)

File name of the combined file to emit.

##### isLibrary
* Type: `boolean`
* Default: false

If set to `true` a `library-preload.json` file is emitted instead of a `Component-preload.js` file (default). The emitted file contents between those options vary a little bit.
If set to `true` a `library-preload.js` file is emitted instead of a `Component-preload.js` file (default). The emitted file contents between those options vary a little bit.

##### format
* Type: `string`
* Default: 'js'

The output format. Can be set to 'json' in order to emit a `library-preload.json` file (which is required for UI5 versions < 1.40).

## License

Expand Down
77 changes: 76 additions & 1 deletion test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,33 @@ lab.test('creates a preload file full of unicorns and zebras :-)', function (don
stream.end();
});

lab.test('creates a library-preload file full of unicorns and zebras :-)', function (done) {
lab.test('creates a library-preload.js file full of unicorns and zebras :-)', function (done) {
var stream = ui5Preload({base: 'src/conf/ui', namespace: 'sap.pdms.fdn', isLibrary: true});
var expectedFile = 'jQuery.sap.registerPreloadedModules({\n\t"name": "sap.pdms.fdn.library-preload",\n\t"version": "2.0",\n\t"modules": {\n\t\t"sap/pdms/fdn/app/unicorns.js": "unicorns",\n\t\t\"sap/pdms/fdn/app/zebras.xml": "zebras"\n\t}\n});';

stream.write(new Vinyl({
base: __dirname,
path: __dirname + '/src/conf/ui/app/unicorns.js',
contents: new Buffer('unicorns')
}));

stream.write(new Vinyl({
base: __dirname,
path: __dirname + '/src/conf/ui/app/zebras.xml',
contents: new Buffer('zebras')
}));

stream.on('data', function (file) {
expect(file.contents.toString()).to.equal(expectedFile);
expect(file.path.split(path.sep).pop()).to.equal('library-preload.js');
});

stream.on('end', done);
stream.end();
});

lab.test('creates a library-preload.json file full of unicorns and zebras :-)', function (done) {
var stream = ui5Preload({base: 'src/conf/ui', namespace: 'sap.pdms.fdn', isLibrary: true, format: 'json'});
var expectedFile = '{\n\t"name": "sap.pdms.fdn.library-preload",\n\t"version": "2.0",\n\t"modules": {\n\t\t"sap/pdms/fdn/app/unicorns.js": "unicorns",\n\t\t\"sap/pdms/fdn/app/zebras.xml": "zebras"\n\t}\n}';

stream.write(new Vinyl({
Expand All @@ -54,3 +79,53 @@ lab.test('creates a library-preload file full of unicorns and zebras :-)', funct
stream.on('end', done);
stream.end();
});

lab.test('creates a foo.js file full of unicorns and zebras :-)', function (done) {
var stream = ui5Preload({base: 'src/conf/ui', namespace: 'sap.pdms.fdn', isLibrary: true, fileName: 'foo.js'});
var expectedFile = 'jQuery.sap.registerPreloadedModules({\n\t"name": "sap.pdms.fdn.library-preload",\n\t"version": "2.0",\n\t"modules": {\n\t\t"sap/pdms/fdn/app/unicorns.js": "unicorns",\n\t\t\"sap/pdms/fdn/app/zebras.xml": "zebras"\n\t}\n});';

stream.write(new Vinyl({
base: __dirname,
path: __dirname + '/src/conf/ui/app/unicorns.js',
contents: new Buffer('unicorns')
}));

stream.write(new Vinyl({
base: __dirname,
path: __dirname + '/src/conf/ui/app/zebras.xml',
contents: new Buffer('zebras')
}));

stream.on('data', function (file) {
expect(file.contents.toString()).to.equal(expectedFile);
expect(file.path.split(path.sep).pop()).to.equal('foo.js');
});

stream.on('end', done);
stream.end();
});

lab.test('creates a foo.json file full of unicorns and zebras :-)', function (done) {
var stream = ui5Preload({base: 'src/conf/ui', namespace: 'sap.pdms.fdn', isLibrary: true, fileName: 'foo.json'});
var expectedFile = '{\n\t"name": "sap.pdms.fdn.library-preload",\n\t"version": "2.0",\n\t"modules": {\n\t\t"sap/pdms/fdn/app/unicorns.js": "unicorns",\n\t\t\"sap/pdms/fdn/app/zebras.xml": "zebras"\n\t}\n}';

stream.write(new Vinyl({
base: __dirname,
path: __dirname + '/src/conf/ui/app/unicorns.js',
contents: new Buffer('unicorns')
}));

stream.write(new Vinyl({
base: __dirname,
path: __dirname + '/src/conf/ui/app/zebras.xml',
contents: new Buffer('zebras')
}));

stream.on('data', function (file) {
expect(file.contents.toString()).to.equal(expectedFile);
expect(file.path.split(path.sep).pop()).to.equal('foo.json');
});

stream.on('end', done);
stream.end();
});