-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathindex.js
78 lines (62 loc) · 2.16 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
'use strict';
const getValidatedFlexiConfig = require('@html-next/flexi-config/lib/get-validated-flexi-config');
const LayoutCompiler = require('./lib/layout-compiler');
const mergeTrees = require('broccoli-merge-trees');
const Funnel = require('broccoli-funnel');
const commands = require('./lib/commands');
module.exports = {
name: '@html-next/flexi-layouts',
included(app, parentAddon) {
this._super.included.apply(this, arguments);
// Quick fix for add-on nesting
// https://github.com/aexmachina/ember-cli-sass/blob/v5.3.0/index.js#L73-L75
// see: https://github.com/ember-cli/ember-cli/issues/3718
while (typeof app.import !== 'function' && (app.app || app.parent)) {
app = app.app || app.parent;
}
// if app.import and parentAddon are blank, we're probably being consumed by an in-repo-addon
// or engine, for which the "bust through" technique above does not work.
if (typeof app.import !== 'function' && !parentAddon) {
if (app.registry && app.registry.app) {
app = app.registry.app;
}
}
if (!parentAddon && typeof app.import !== 'function') {
throw new Error('@html-next/flexi-layouts is being used within another addon or engine and is'
+ ' having trouble registering itself to the parent application.');
}
this.app = app;
return app;
},
isDevelopingAddon() {
return false;
},
_flexiConfig: null,
flexiConfig() {
if (!this._flexiConfig) {
this._flexiConfig = getValidatedFlexiConfig(this.project.root);
}
return this._flexiConfig;
},
config() {
let org = this._super.config.apply(this, arguments);
org.flexi = this.flexiConfig();
return org;
},
preprocessTree(type, tree) {
if (type === 'template') {
if (!tree) {
throw new Error('No Template Tree is Present');
}
let layoutTree = new LayoutCompiler(tree, { breakpoints: this.flexiConfig().breakpoints });
let templateTree = new Funnel(tree, {
exclude: ['**/-layouts/*.hbs']
});
return mergeTrees([templateTree, layoutTree], { overwrite: true });
}
return tree;
},
includedCommands() {
return commands;
}
};