-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy paththeme.js
130 lines (105 loc) · 3.88 KB
/
theme.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
/* jshint node: true */
'use strict';
var fs = require('fs');
var path = require('path');
var Addon = require('ember-cli/lib/models/addon');
var ThemeCore = require('./lib/theme-core');
var TransformComponentClasses = require('./lib/htmlbars-plugins/transform-component-classes');
var TransformUIRoot = require('./lib/htmlbars-plugins/transform-ui-root');
var TransformUITableComponents = require('./lib/htmlbars-plugins/transform-ui-table-components');
var StyleguideServer = require('./lib/server-middleware/styleguide-server');
var funnel = require('broccoli-funnel');
var walkSync = require('walk-sync');
var themeCore;
var Theme = Addon.extend({
themeCore: null,
parentTheme: null,
jsPath: 'addon',
scssPath: 'addon/styles',
hbsPath: 'addon/templates',
isDevelopingAddon: function() {
return true;
},
init: function() {
this._super.init && this._super.init.apply(this, arguments);
// set this theme's parent theme that was saved on themeCore
// from the super class, then set the parent theme to the
// current theme for the next sub class
this.parentTheme = this.themeCore.parentTheme;
this.themeCore.parentTheme = this;
this.themeCore.register(this);
},
setupPreprocessorRegistry: function(type, registry) {
// only instantiate themeCore once for all themes
this.themeCore = themeCore || new ThemeCore({
appName: registry.app.project.pkg.name
});
themeCore = this.themeCore;
// if we're running inside any theme/subtheme's dummy app
// then the appName is not the project.pkg.name, it's "dummy"
if (this.name === this.themeCore.appName) {
this.themeCore.appName = 'dummy';
}
if (type === 'parent' && !registry.app.parent) {
this.themeCore.setupAppPreprocessors(registry);
}
if (type === 'self') {
this.themeCore.setupThemePreprocessors(registry, this.name);
this.setupHtmlTransforms(registry);
}
},
setupHtmlTransforms: function(registry) {
registry.add('htmlbars-ast-plugin', {
name: 'transform-component-classes',
plugin: TransformComponentClasses,
baseDir: function() { return __dirname }
});
registry.add('htmlbars-ast-plugin', {
name: 'transform-ui-root',
plugin: TransformUIRoot,
baseDir: function() { return __dirname }
});
registry.add('htmlbars-ast-plugin', {
name: 'transform-ui-table-components',
plugin: TransformUITableComponents,
baseDir: function() { return __dirname }
});
},
toScssTree: function() {
var scssDir = path.join(this._baseDiskDir(), this.scssPath);
var tree = this.treeGenerator(scssDir);
return funnel(tree, { include: ['**/*.scss'] });
},
toJsTree: function() {
var jsDir = path.join(this._baseDiskDir(), this.jsPath);
var tree = this.treeGenerator(jsDir);
return funnel(tree, { include: ['**/*.js'] });
},
toHbsTree: function() {
var hbsDir = path.join(this._baseDiskDir(), this.hbsPath);
var tree = this.treeGenerator(hbsDir);
return funnel(tree, { include: ['**/*.hbs'] });
},
shouldAddServerMiddleware(themeCore) {
return !themeCore.didSetupServerMiddleware;
},
serverMiddleware: function(startOptions) {
if (this.shouldAddServerMiddleware(this.themeCore)) {
var styleguideServer = new StyleguideServer({ themeCore: this.themeCore });
styleguideServer.addServerMiddleware(startOptions);
themeCore.didSetupServerMiddleware = true;
}
},
toJsComponentFilesArray: function() {
var jsDir = path.join(this._baseDiskDir(), this.jsPath);
return walkSync(jsDir, { globs: ['components/*.js'] });
},
toScssComponentFilesArray: function() {
var scssDir = path.join(this._baseDiskDir(), this.scssPath);
return walkSync(scssDir, { globs: ['components/*.scss'] });
},
_baseDiskDir: function() {
return this.nodeModulesPath.replace(/\/node_modules$/, '');
}
});
module.exports = Theme;