Skip to content

Commit d9646fe

Browse files
committed
feat(builder): broccoli bump to 1.0 + LESS & SASS Plugins
1 parent 6607ebb commit d9646fe

25 files changed

+505
-1496
lines changed

addon/ng2/blueprints/ng2/files/src/index.html

-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
<script src="vendor/angular2/bundles/http.dev.js"></script>
3333
<script src="vendor/angular2/bundles/router.dev.js"></script>
3434

35-
<script src="thirdparty/libs.js"></script>
3635
<script>
3736
System.config({
3837
packages: {

lib/broccoli/angular2-app.js

+113-196
Original file line numberDiff line numberDiff line change
@@ -1,218 +1,135 @@
1-
var path = require('path');
2-
var Concat = require('broccoli-concat');
3-
var configReplace = require('./broccoli-config-replace');
4-
var compileWithTypescript = require('./broccoli-typescript').default;
5-
var SwManifest = require('./service-worker-manifest').default;
6-
var fs = require('fs');
7-
var Funnel = require('broccoli-funnel');
8-
var mergeTrees = require('broccoli-merge-trees');
9-
var Project = require('ember-cli/lib/models/project');
10-
11-
module.exports = Angular2App;
12-
13-
function Angular2App(defaults, options, additionalPaths) {
14-
this._initProject();
15-
this._notifyAddonIncluded();
16-
this.options = options;
17-
this.additionalPaths = additionalPaths || [];
1+
/* jshint node: true, esnext: true */
2+
'use strict';
3+
4+
const path = require('path');
5+
const Funnel = require('broccoli-funnel');
6+
const mergeTrees = require('broccoli-merge-trees');
7+
const ts = require('./broccoli-typescript');
8+
const sass = require('./broccoli-sass');
9+
const less = require('./broccoli-less');
10+
const configReplace = require('./broccoli-config-replace');
11+
const SWManifest = require('./service-worker-manifest');
12+
const Project = require('ember-cli/lib/models/project');
13+
const sh = require('shelljs');
14+
15+
module.exports = Ng2App;
16+
17+
function Ng2App(defaults, options, additionalPaths) {
18+
this._initProject();
19+
this._notifyAddonIncluded();
20+
this.options = options;
21+
this.additionalPaths = additionalPaths || [];
1822
}
1923

20-
Angular2App.prototype.toTree = function() {
21-
var sourceTree = 'src';
22-
var vendorNpmFiles = [
23-
'systemjs/dist/system-polyfills.js',
24-
'systemjs/dist/system.src.js',
25-
'es6-shim/es6-shim.js',
26-
'angular2/bundles/angular2-polyfills.js',
27-
'rxjs/bundles/Rx.js',
28-
'angular2/bundles/angular2.dev.js',
29-
'angular2/bundles/http.dev.js',
30-
'angular2/bundles/router.dev.js',
31-
'angular2/bundles/upgrade.dev.js'
32-
];
33-
34-
if (this.options && this.options.vendorNpmFiles) {
35-
vendorNpmFiles = vendorNpmFiles.concat(this.options.vendorNpmFiles);
36-
}
37-
38-
var tsConfigCompilerOptions = JSON.parse(fs.readFileSync('src/tsconfig.json', 'utf-8')).compilerOptions;
39-
tsConfigCompilerOptions.rootFilePaths = ['typings.d.ts'].concat(this.additionalPaths)
40-
.map(function(name) {
41-
return path.join(process.cwd(), sourceTree, name)
42-
});
43-
44-
var tsTree = compileWithTypescript(sourceTree, tsConfigCompilerOptions);
45-
var tsSrcTree = new Funnel(sourceTree, {
46-
include: ['**/*.ts'],
47-
allowEmpty: true
48-
});
49-
50-
var jsTree = new Funnel(sourceTree, {
51-
include: ['**/*.js'],
52-
allowEmpty: true
53-
});
54-
55-
var assetTree = new Funnel(sourceTree, {
56-
include: ['**/*.*'],
57-
exclude: ['**/*.ts', '**/*.js'],
58-
allowEmpty: true
59-
});
60-
61-
var vendorNpmTree = new Funnel('node_modules', {
62-
include: vendorNpmFiles,
63-
destDir: 'vendor'
64-
});
65-
66-
var thirdPartyJsTree = new Funnel('node_modules', {
67-
include: ['ng2*/bundles/*.js'],
68-
exclude: ['ng2*/bundles/*.min.js', 'ng2*/bundles/*.standalone.js'],
69-
});
70-
71-
var thirdPartyJs = new Concat(thirdPartyJsTree, {
72-
inputFiles: ['**/*.js'],
73-
outputFile: '/thirdparty/libs.js',
74-
allowNone: true
75-
});
76-
77-
var merged = mergeTrees([
78-
assetTree,
79-
tsSrcTree,
80-
tsTree,
81-
jsTree,
82-
this.index(),
83-
vendorNpmTree,
84-
thirdPartyJs
85-
], { overwrite: true });
86-
87-
return mergeTrees([merged, new SwManifest(merged)]);
24+
Ng2App.prototype.toTree = function() {
25+
const src = 'src';
26+
27+
let tsCompilerOptions = require(path.resolve(process.cwd(), 'src/tsconfig.json')).compilerOptions;
28+
const tsNodeTree = new ts([src], tsCompilerOptions);
29+
30+
const vendorNpmFiles = [
31+
'systemjs/dist/system-polyfills.js',
32+
'systemjs/dist/system.src.js',
33+
'es6-shim/es6-shim.js',
34+
'angular2/bundles/angular2-polyfills.js',
35+
'rxjs/bundles/Rx.js',
36+
'angular2/bundles/angular2.dev.js',
37+
'angular2/bundles/http.dev.js',
38+
'angular2/bundles/router.dev.js',
39+
'angular2/bundles/upgrade.dev.js'
40+
];
41+
42+
const vendorNpmTree = new Funnel('node_modules', {
43+
include: vendorNpmFiles,
44+
destDir: 'vendor'
45+
});
46+
47+
const jsTree = new Funnel(src, {
48+
include: ['**/*.js'],
49+
allowEmpty: true
50+
});
51+
52+
const assetTree = new Funnel(src, {
53+
include: ['**/*.*'],
54+
exclude: ['**/*.ts', '**/*.js', '**/*.scss', '**/*.sass', '**/*.less'],
55+
allowEmpty: true
56+
});
57+
58+
let trees = [vendorNpmTree, assetTree, tsNodeTree, jsTree, this.index()];
59+
60+
if (require.resolve('node-sass') && sh.which('sass')) {
61+
const sassTree = new sass([src]);
62+
trees.push(sassTree);
63+
}
64+
65+
if (require.resolve('less')) {
66+
const lessTree = new less([src]);
67+
trees.push(lessTree);
68+
}
69+
70+
trees.push(new SWManifest([src]));
71+
72+
return mergeTrees(trees, { overwrite: true });
8873
};
8974

90-
/**
91-
@private
92-
@method _initProject
93-
@param {Object} options
94-
*/
95-
Angular2App.prototype._initProject = function() {
96-
this.project = Project.closestSync(process.cwd());
97-
98-
/*if (options.configPath) {
99-
this.project.configPath = function() { return options.configPath; };
100-
}*/
75+
Ng2App.prototype._initProject = function() {
76+
this.project = Project.closestSync(process.cwd());
10177
};
10278

103-
/**
104-
@private
105-
@method _notifyAddonIncluded
106-
*/
107-
Angular2App.prototype._notifyAddonIncluded = function() {
108-
this.initializeAddons();
109-
this.project.addons = this.project.addons.filter(function(addon) {
110-
addon.app = this;
111-
112-
if (!addon.isEnabled || addon.isEnabled()) {
113-
if (addon.included) {
114-
addon.included(this);
115-
}
116-
117-
return addon;
118-
}
119-
}, this);
120-
};
79+
Ng2App.prototype._notifyAddonIncluded = function() {
80+
this.initializeAddons();
81+
this.project.addons = this.project.addons.filter(function(addon) {
82+
addon.app = this;
12183

122-
/**
123-
Loads and initializes addons for this project.
124-
Calls initializeAddons on the Project.
84+
if (!addon.isEnabled || addon.isEnabled()) {
85+
if (addon.included) {
86+
addon.included(this);
87+
}
12588

126-
@private
127-
@method initializeAddons
128-
*/
129-
Angular2App.prototype.initializeAddons = function() {
130-
this.project.initializeAddons();
89+
return addon;
90+
}
91+
}, this);
13192
};
13293

133-
/**
134-
Returns the content for a specific type (section) for index.html.
135-
136-
Currently supported types:
137-
- 'head'
138-
//- 'config-module'
139-
//- 'app'
140-
//- 'head-footer'
141-
//- 'test-header-footer'
142-
//- 'body-footer'
143-
//- 'test-body-footer'
144-
145-
Addons can also implement this method and could also define additional
146-
types (eg. 'some-addon-section').
147-
148-
@private
149-
@method contentFor
150-
@param {RegExP} match Regular expression to match against
151-
@param {String} type Type of content
152-
@return {String} The content.
153-
*/
154-
Angular2App.prototype.contentFor = function(match, type) {
155-
var content = [];
94+
Ng2App.prototype.initializeAddons = function() {
95+
this.project.initializeAddons();
96+
};
15697

157-
/*switch (type) {
158-
case 'head': this._contentForHead(content, config); break;
159-
case 'config-module': this._contentForConfigModule(content, config); break;
160-
case 'app-boot': this._contentForAppBoot(content, config); break;
161-
}*/
98+
Ng2App.prototype.contentFor = function(match, type) {
99+
var content = [];
162100

163101
content = this.project.addons.reduce(function(content, addon) {
164-
var addonContent = addon.contentFor ? addon.contentFor(type) : null;
165-
if (addonContent) {
166-
return content.concat(addonContent);
167-
}
102+
var addonContent = addon.contentFor ? addon.contentFor(type) : null;
103+
if (addonContent) {
104+
return content.concat(addonContent);
105+
}
168106

169-
return content;
107+
return content;
170108
}, content);
171109

172-
173110
return content.join('\n');
174111
};
175112

176-
/**
177-
@private
178-
@method _configReplacePatterns
179-
@return
180-
*/
181-
Angular2App.prototype._configReplacePatterns = function() {
182-
return [/*{
183-
match: /\{\{EMBER_ENV\}\}/g,
184-
replacement: calculateEmberENV
185-
}, */{
186-
match: /\{\{content-for ['"](.+)["']\}\}/g,
187-
replacement: this.contentFor.bind(this)
188-
}/*, {
189-
match: /\{\{MODULE_PREFIX\}\}/g,
190-
replacement: calculateModulePrefix
191-
}*/];
113+
Ng2App.prototype._configReplacePatterns = function() {
114+
return [{
115+
match: /\{\{content-for ['"](.+)["']\}\}/g,
116+
replacement: this.contentFor.bind(this)
117+
}];
192118
};
193119

194-
195-
/**
196-
Returns the tree for app/index.html
197-
198-
@private
199-
@method index
200-
@return {Tree} Tree for app/index.html
201-
*/
202-
Angular2App.prototype.index = function() {
203-
var htmlName = 'index.html';
204-
var files = [
205-
'index.html'
206-
];
207-
208-
var index = new Funnel('src', {
209-
files: files,
210-
description: 'Funnel: index.html'
211-
});
212-
213-
214-
return configReplace(index, {
215-
files: [ htmlName ],
216-
patterns: this._configReplacePatterns()
217-
});
120+
Ng2App.prototype.index = function() {
121+
var htmlName = 'index.html';
122+
var files = [
123+
'index.html'
124+
];
125+
126+
var index = new Funnel('src', {
127+
files: files,
128+
description: 'Funnel: index.html'
129+
});
130+
131+
return configReplace(index, {
132+
files: [ htmlName ],
133+
patterns: this._configReplacePatterns()
134+
});
218135
};

lib/broccoli/broccoli-dest-copy.js

-37
This file was deleted.

lib/broccoli/broccoli-dest-copy.js.map

-1
This file was deleted.

0 commit comments

Comments
 (0)