Skip to content

feat(builder): broccoli bump to 1.0 #299

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion addon/ng2/blueprints/ng2/files/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
<script src="vendor/angular2/bundles/http.dev.js"></script>
<script src="vendor/angular2/bundles/router.dev.js"></script>

<script src="thirdparty/libs.js"></script>
<script>
System.config({
packages: {
Expand Down
299 changes: 103 additions & 196 deletions lib/broccoli/angular2-app.js
Original file line number Diff line number Diff line change
@@ -1,218 +1,125 @@
var path = require('path');
var Concat = require('broccoli-concat');
var configReplace = require('./broccoli-config-replace');
var compileWithTypescript = require('./broccoli-typescript').default;
var SwManifest = require('./service-worker-manifest').default;
var fs = require('fs');
var Funnel = require('broccoli-funnel');
var mergeTrees = require('broccoli-merge-trees');
var Project = require('ember-cli/lib/models/project');

module.exports = Angular2App;

function Angular2App(defaults, options, additionalPaths) {
this._initProject();
this._notifyAddonIncluded();
this.options = options;
this.additionalPaths = additionalPaths || [];
/* jshint node: true, esnext: true */
'use strict';

const path = require('path');
const Funnel = require('broccoli-funnel');
const mergeTrees = require('broccoli-merge-trees');
const ts = require('./broccoli-typescript');
const sass = require('./broccoli-sass');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requires not needed anymore.

const less = require('./broccoli-less');
const configReplace = require('./broccoli-config-replace');
const SWManifest = require('./service-worker-manifest');
const Project = require('ember-cli/lib/models/project');
const sh = require('shelljs');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove unused variables please.


module.exports = Ng2App;

function Ng2App(defaults, options, additionalPaths) {
this._initProject();
this._notifyAddonIncluded();
this.options = options;
this.additionalPaths = additionalPaths || [];
}

Angular2App.prototype.toTree = function() {
var sourceTree = 'src';
var vendorNpmFiles = [
'systemjs/dist/system-polyfills.js',
'systemjs/dist/system.src.js',
'es6-shim/es6-shim.js',
'angular2/bundles/angular2-polyfills.js',
'rxjs/bundles/Rx.js',
'angular2/bundles/angular2.dev.js',
'angular2/bundles/http.dev.js',
'angular2/bundles/router.dev.js',
'angular2/bundles/upgrade.dev.js'
];

if (this.options && this.options.vendorNpmFiles) {
vendorNpmFiles = vendorNpmFiles.concat(this.options.vendorNpmFiles);
}

var tsConfigCompilerOptions = JSON.parse(fs.readFileSync('src/tsconfig.json', 'utf-8')).compilerOptions;
tsConfigCompilerOptions.rootFilePaths = ['typings.d.ts'].concat(this.additionalPaths)
.map(function(name) {
return path.join(process.cwd(), sourceTree, name)
});

var tsTree = compileWithTypescript(sourceTree, tsConfigCompilerOptions);
var tsSrcTree = new Funnel(sourceTree, {
include: ['**/*.ts'],
allowEmpty: true
});

var jsTree = new Funnel(sourceTree, {
include: ['**/*.js'],
allowEmpty: true
});

var assetTree = new Funnel(sourceTree, {
include: ['**/*.*'],
exclude: ['**/*.ts', '**/*.js'],
allowEmpty: true
});

var vendorNpmTree = new Funnel('node_modules', {
include: vendorNpmFiles,
destDir: 'vendor'
});

var thirdPartyJsTree = new Funnel('node_modules', {
include: ['ng2*/bundles/*.js'],
exclude: ['ng2*/bundles/*.min.js', 'ng2*/bundles/*.standalone.js'],
});

var thirdPartyJs = new Concat(thirdPartyJsTree, {
inputFiles: ['**/*.js'],
outputFile: '/thirdparty/libs.js',
allowNone: true
});

var merged = mergeTrees([
assetTree,
tsSrcTree,
tsTree,
jsTree,
this.index(),
vendorNpmTree,
thirdPartyJs
], { overwrite: true });

return mergeTrees([merged, new SwManifest(merged)]);
Ng2App.prototype.toTree = function() {
const src = 'src';

let tsCompilerOptions = require(path.resolve(process.cwd(), 'src/tsconfig.json')).compilerOptions;
const tsNodeTree = new ts([src], tsCompilerOptions);

const vendorNpmFiles = [
'systemjs/dist/system-polyfills.js',
'systemjs/dist/system.src.js',
'es6-shim/es6-shim.js',
'angular2/bundles/angular2-polyfills.js',
'rxjs/bundles/Rx.js',
'angular2/bundles/angular2.dev.js',
'angular2/bundles/http.dev.js',
'angular2/bundles/router.dev.js',
'angular2/bundles/upgrade.dev.js'
];

const vendorNpmTree = new Funnel('node_modules', {
include: vendorNpmFiles,
destDir: 'vendor'
});

const jsTree = new Funnel(src, {
include: ['**/*.js'],
allowEmpty: true
});

const assetTree = new Funnel(src, {
include: ['**/*.*'],
exclude: ['**/*.ts', '**/*.js', '**/*.scss', '**/*.sass', '**/*.less'],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now, just exclude ts, js and css.

allowEmpty: true
});

let trees = [vendorNpmTree, assetTree, tsNodeTree, jsTree, this.index()];

trees.push(new SWManifest([src]));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be included as part of the trees variable above.


return mergeTrees(trees, { overwrite: true });
};

/**
@private
@method _initProject
@param {Object} options
*/
Angular2App.prototype._initProject = function() {
this.project = Project.closestSync(process.cwd());

/*if (options.configPath) {
this.project.configPath = function() { return options.configPath; };
}*/
Ng2App.prototype._initProject = function() {
this.project = Project.closestSync(process.cwd());
};

/**
@private
@method _notifyAddonIncluded
*/
Angular2App.prototype._notifyAddonIncluded = function() {
this.initializeAddons();
this.project.addons = this.project.addons.filter(function(addon) {
addon.app = this;

if (!addon.isEnabled || addon.isEnabled()) {
if (addon.included) {
addon.included(this);
}

return addon;
}
}, this);
};
Ng2App.prototype._notifyAddonIncluded = function() {
this.initializeAddons();
this.project.addons = this.project.addons.filter(function(addon) {
addon.app = this;

/**
Loads and initializes addons for this project.
Calls initializeAddons on the Project.
if (!addon.isEnabled || addon.isEnabled()) {
if (addon.included) {
addon.included(this);
}

@private
@method initializeAddons
*/
Angular2App.prototype.initializeAddons = function() {
this.project.initializeAddons();
return addon;
}
}, this);
};

/**
Returns the content for a specific type (section) for index.html.

Currently supported types:
- 'head'
//- 'config-module'
//- 'app'
//- 'head-footer'
//- 'test-header-footer'
//- 'body-footer'
//- 'test-body-footer'

Addons can also implement this method and could also define additional
types (eg. 'some-addon-section').

@private
@method contentFor
@param {RegExP} match Regular expression to match against
@param {String} type Type of content
@return {String} The content.
*/
Angular2App.prototype.contentFor = function(match, type) {
var content = [];
Ng2App.prototype.initializeAddons = function() {
this.project.initializeAddons();
};

/*switch (type) {
case 'head': this._contentForHead(content, config); break;
case 'config-module': this._contentForConfigModule(content, config); break;
case 'app-boot': this._contentForAppBoot(content, config); break;
}*/
Ng2App.prototype.contentFor = function(match, type) {
var content = [];

content = this.project.addons.reduce(function(content, addon) {
var addonContent = addon.contentFor ? addon.contentFor(type) : null;
if (addonContent) {
return content.concat(addonContent);
}
var addonContent = addon.contentFor ? addon.contentFor(type) : null;
if (addonContent) {
return content.concat(addonContent);
}

return content;
return content;
}, content);


return content.join('\n');
};

/**
@private
@method _configReplacePatterns
@return
*/
Angular2App.prototype._configReplacePatterns = function() {
return [/*{
match: /\{\{EMBER_ENV\}\}/g,
replacement: calculateEmberENV
}, */{
match: /\{\{content-for ['"](.+)["']\}\}/g,
replacement: this.contentFor.bind(this)
}/*, {
match: /\{\{MODULE_PREFIX\}\}/g,
replacement: calculateModulePrefix
}*/];
Ng2App.prototype._configReplacePatterns = function() {
return [{
match: /\{\{content-for ['"](.+)["']\}\}/g,
replacement: this.contentFor.bind(this)
}];
};


/**
Returns the tree for app/index.html

@private
@method index
@return {Tree} Tree for app/index.html
*/
Angular2App.prototype.index = function() {
var htmlName = 'index.html';
var files = [
'index.html'
];

var index = new Funnel('src', {
files: files,
description: 'Funnel: index.html'
});


return configReplace(index, {
files: [ htmlName ],
patterns: this._configReplacePatterns()
});
Ng2App.prototype.index = function() {
var htmlName = 'index.html';
var files = [
'index.html'
];

var index = new Funnel('src', {
files: files,
description: 'Funnel: index.html'
});

return configReplace(index, {
files: [ htmlName ],
patterns: this._configReplacePatterns()
});
};
37 changes: 0 additions & 37 deletions lib/broccoli/broccoli-dest-copy.js

This file was deleted.

1 change: 0 additions & 1 deletion lib/broccoli/broccoli-dest-copy.js.map

This file was deleted.

Loading