-
Notifications
You must be signed in to change notification settings - Fork 159
Expand file tree
/
Copy pathindex.js
More file actions
111 lines (90 loc) · 2.97 KB
/
index.js
File metadata and controls
111 lines (90 loc) · 2.97 KB
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
/* jshint node: true */
'use strict';
var mergeTrees = require('broccoli-merge-trees');
var patchEmberApp = require('./lib/ext/patch-ember-app');
var fastbootAppModule = require('./lib/utilities/fastboot-app-module');
var filterInitializers = require('fastboot-filter-initializers');
var FastBootBuild = require('./lib/broccoli/fastboot-build');
/*
* Main entrypoint for the Ember CLI addon.
*/
module.exports = {
name: 'ember-cli-fastboot',
includedCommands: function() {
return {
'fastboot': require('./lib/commands/fastboot'),
/* fastboot:build is deprecated and will be removed in a future version */
'fastboot:build': require('./lib/commands/fastboot-build')
};
},
/**
* Called at the start of the build process to let the addon know it will be
* used. At this point, we can rely on the EMBER_CLI_FASTBOOT environment
* variable being set.
*
* Once we've determined which mode we're in (browser build or FastBoot build),
* we mixin additional Ember addon hooks appropriate to the current build target.
*/
included: function(app) {
patchEmberApp(app);
},
config: function() {
if (this.app && this.app.options.__is_building_fastboot__) {
return { APP: { autoboot: false } };
}
},
/**
* Inserts placeholders into index.html that are used by the FastBoot server
* to insert the rendered content into the right spot. Also injects a module
* for FastBoot application boot.
*/
contentFor: function(type, config, contents) {
if (type === 'body') {
return "<!-- EMBER_CLI_FASTBOOT_BODY -->";
}
if (type === 'head') {
return "<!-- EMBER_CLI_FASTBOOT_TITLE --><!-- EMBER_CLI_FASTBOOT_HEAD -->";
}
if (type === 'app-boot') {
return fastbootAppModule(config.modulePrefix);
}
if (type === 'config-module' && this.app.options.__is_building_fastboot__) {
var linesToRemove = contents.length;
while(linesToRemove) {
// Clear out the default config from ember-cli
contents.pop();
linesToRemove--;
}
return 'return FastBoot.config();';
}
},
/**
* Filters out initializers and instance initializers that should only run in
* browser mode.
*/
preconcatTree: function(tree) {
return filterInitializers(tree, this.app.name);
},
/**
* After the entire Broccoli tree has been built for the `dist` directory,
* adds the `fastboot-config.json` file to the root.
*/
postprocessTree: function(type, tree) {
if (type === 'all') {
var fastbootTree = this.buildFastBootTree();
// Merge the package.json with the existing tree
return mergeTrees([tree, fastbootTree], {overwrite: true});
}
return tree;
},
buildFastBootTree: function() {
var fastbootBuild = new FastBootBuild({
ui: this.ui,
assetMapPath: this.assetMapPath,
project: this.project,
app: this.app,
parent: this.parent
});
return fastbootBuild.toTree();
}
};