-
Notifications
You must be signed in to change notification settings - Fork 77
/
index.js
107 lines (87 loc) · 2.63 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
'use strict';
const stew = require('broccoli-stew');
const VersionChecker = require('ember-cli-version-checker');
const path = require('path');
const Funnel = require('broccoli-funnel');
const mergeTrees = require('broccoli-merge-trees');
module.exports = {
name: require('./package').name,
init(app) {
this._super.init && this._super.init.apply(this, arguments);
// determine if ember-data is present
let checker = new VersionChecker(this);
let npmDep = checker.for('ember-data', 'npm');
if (
npmDep.version &&
(npmDep.satisfies('>= 1.13.0') ||
npmDep.satisfies('>= 2.0.0') ||
npmDep.gt('2.0.0'))
) {
this.hasEmberData = true;
this.loadInitializer = true;
}
if (
npmDep.version &&
(npmDep.satisfies('>= 4.12.0') || npmDep.gt('4.12.0'))
) {
this.loadInitializer = false;
}
// determine if saveAs and Blob should be imported
let projectConfig = this.project.config(app.env);
let options = {};
if (projectConfig) {
options = projectConfig['ember-local-storage'] || {};
if ('includeEmberDataSupport' in options) {
this.hasEmberData = options.includeEmberDataSupport;
}
if (options.fileExport && this.hasEmberData) {
this.needsFileExport = true;
}
if (options.loadInitializer === false) {
this.loadInitializer = options.loadInitializer;
}
}
},
included: function included(app) {
if (this.needsFileExport) {
app.import('vendor/save-as.js');
app.import('vendor/Blob.js');
}
this._super.included.apply(this, arguments);
},
treeForApp: function (tree) {
if (!this.loadInitializer) {
['initializers/local-storage-adapter.js'].forEach(function (file) {
tree = stew.rm(tree, file);
});
}
return tree;
},
treeForAddon: function (tree) {
if (!this.hasEmberData) {
[
'adapters/adapter.js',
'adapters/base.js',
'adapters/local.js',
'adapters/session.js',
'initializers/local-storage-adapter.js',
'mixins/adapters/import-export.js',
'serializers/serializer.js',
].forEach(function (file) {
tree = stew.rm(tree, file);
});
}
if (!this.loadInitializer) {
['initializers/local-storage-adapter.js'].forEach(function (file) {
tree = stew.rm(tree, file);
});
}
return this._super.treeForAddon.call(this, tree);
},
treeForVendor(vendorTree) {
let blobTree = new Funnel(path.dirname(require.resolve('blob-polyfill')), {
files: ['Blob.js'],
});
return mergeTrees([vendorTree, blobTree]);
},
};