forked from aalasolutions-zz/ember-element-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
161 lines (123 loc) · 4.12 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
'use strict';
const path = require('path');
const fs = require('fs');
const Funnel = require('broccoli-funnel');
const mergeTrees = require('broccoli-merge-trees');
module.exports = {
name: require('./package').name,
normalizeEntityName: function () {
},
beforeInstall() {
// Add addons to package.json and run defaultBlueprint
return this.addAddonsToProject({
// a packages array defines the addons to install
packages: [
// name is the addon name, and target (optional) is the version
{name: 'ember-cli-sass'},
{name: 'ember-moment'},
]
});
},
afterInstall() {
var importStatement = '\n@import "ember-element-ui";\n';
var stylePath = path.join('app', 'styles');
var file = path.join(stylePath, `app.scss`);
if (!fs.existsSync(stylePath)) {
fs.mkdirSync(stylePath);
}
if (fs.existsSync(file)) {
this.ui.writeLine(`Added import statement to ${file}`);
this.insertIntoFile(file, importStatement, {});
} else {
fs.writeFileSync(file, importStatement);
this.ui.writeLine(`Created ${file}`);
}
this.addAddonsToProject({
packages: [
{name: "ember-font-awesome", target: "^4.0.0-rc.4"},
]
});
return this.addPackagesToProject([
{name: 'element-theme-chalk', target: '^2.4.9'},
{name: 'popper.js'},
{name: 'normalize.css'},
]);
},
included() {
this._super.included.apply(this, arguments);
this._ensureFindHost();
var popperPath = path.join('node_modules', 'popper.js', 'dist', 'umd');
var host = this._findHost();
host.import({
development: path.join(popperPath, 'popper.js'),
production: path.join(popperPath, 'popper.min.js'),
});
host.import({
development: path.join(popperPath, 'popper-utils.js'),
production: path.join(popperPath, 'popper-utils.min.js'),
});
host.import(path.join('node_modules', 'normalize.css', 'normalize.css'));
host.import(path.join('node_modules', 'animate.css', 'animate.css'));
host.import(path.join('node_modules', 'popper.js', 'dist', 'umd', 'popper.js'));
host.import(path.join('node_modules', 'popper.js', 'dist', 'umd', 'popper-utils.js'));
host.import(path.join('node_modules', 'element-theme-chalk', 'lib', 'display.css'));
let fontsPath = 'vendor/element-font/fonts';
let absoluteFontsPath = path.join('node_modules', 'element-theme-chalk', 'src', 'fonts');
let fontsFolderPath = '/assets/fonts';
let fontsToImport = fs.readdirSync(absoluteFontsPath);
fontsToImport.forEach(function (fontFilename) {
host.import(
path.join(fontsPath, fontFilename),
{destDir: fontsFolderPath}
);
});
},
treeForStyles: function (tree) {
var styleTrees = [];
var host = this._findHost();
if (host.project.findAddonByName('ember-cli-sass')) {
styleTrees.push(new Funnel(path.join('node_modules', 'element-theme-chalk', 'src'), {
destDir: 'ember-element-ui'
}));
}
if (tree) {
styleTrees.push(tree);
}
return mergeTrees(styleTrees, {overwrite: true});
},
treeForVendor: function(tree) {
// Get configured fontFormats
var fontsTree = [];
let fontFormats = ['ttf', 'woff'];
let fontFormatsString = fontFormats.join(',');
// Define fontFormatPattern
let fontFormatPattern;
if (fontFormats.length > 1) {
fontFormatPattern = `*.{${fontFormatsString}}`;
} else {
fontFormatPattern = `*.${fontFormatsString}`;
}
// Funnel required font types
let fonts = new Funnel(path.join('node_modules', 'element-theme-chalk', 'src'), {
destDir: 'element-font',
include: [`fonts/${fontFormatPattern}`]
});
fontsTree.push(fonts);
if (tree) {
fontsTree.push(tree);
}
return mergeTrees(fontsTree, {overwrite: true});
},
_ensureFindHost() {
if (!this._findHost) {
this._findHost = function findHostShim() {
var current = this;
var app;
do {
app = current.app || app;
} while (current.parent.parent && (current = current.parent));
return app;
};
}
}
};