diff --git a/package.json b/package.json index 17cda0eb34e8..554f285a5373 100644 --- a/package.json +++ b/package.json @@ -50,13 +50,11 @@ "autoprefixer": "^6.5.3", "chalk": "^1.1.3", "common-tags": "^1.3.1", - "configstore": "^2.0.0", "css-loader": "^0.23.1", "debug": "^2.1.3", "denodeify": "^1.2.1", "diff": "^2.2.2", "ember-cli-normalize-entity-name": "^1.0.0", - "ember-cli-preprocess-registry": "^2.0.0", "ember-cli-string-utils": "^1.0.0", "enhanced-resolve": "^2.3.0", "exists-sync": "0.0.3", @@ -117,7 +115,6 @@ "tslint-loader": "^3.3.0", "typescript": "~2.0.3", "url-loader": "^0.5.7", - "uuid": "^3.0.0", "walk-sync": "^0.2.6", "webpack": "2.1.0-beta.25", "webpack-dev-server": "2.1.0-beta.9", diff --git a/packages/angular-cli/ember-cli/lib/cli/index.js b/packages/angular-cli/ember-cli/lib/cli/index.js index 945ec74b0b65..3750c0364720 100644 --- a/packages/angular-cli/ember-cli/lib/cli/index.js +++ b/packages/angular-cli/ember-cli/lib/cli/index.js @@ -6,27 +6,9 @@ var Project = require('../models/project'); var commands = require('../commands'); var tasks = require('../tasks'); var CLI = require('./cli'); -var packageConfig = require('../../../package.json'); var debug = require('debug')('ember-cli:cli/index'); var merge = require('lodash/merge'); -var version = packageConfig.version; -var name = packageConfig.name; -var trackingCode = packageConfig.trackingCode; - -function clientId() { - var ConfigStore = require('configstore'); - var configStore = new ConfigStore('ember-cli'); - var id = configStore.get('client-id'); - - if (id) { - return id; - } else { - id = require('uuid').v4().toString(); - configStore.set('client-id', id); - return id; - } -} // Options: Array cliArgs, Stream inputStream, Stream outputStream module.exports = function(options) { diff --git a/packages/angular-cli/ember-cli/lib/models/addon-discovery.js b/packages/angular-cli/ember-cli/lib/models/addon-discovery.js deleted file mode 100644 index 17656d2f0a7d..000000000000 --- a/packages/angular-cli/ember-cli/lib/models/addon-discovery.js +++ /dev/null @@ -1,260 +0,0 @@ -'use strict'; - -/** -@module ember-cli -*/ - -var assign = require('lodash/assign'); -var debug = require('debug')('ember-cli:addon-discovery'); -var existsSync = require('exists-sync'); -var path = require('path'); -var CoreObject = require('../ext/core-object'); -var resolve = require('resolve'); -var findup = require('findup'); - -/** - AddonDiscovery is responsible for collecting information about all of the - addons that will be used with a project. - - @class AddonDiscovery - @extends CoreObject - @constructor -*/ - -function AddonDiscovery(ui) { - this.ui = ui; -} - -AddonDiscovery.__proto__ = CoreObject; -AddonDiscovery.prototype.constructor = AddonDiscovery; - -/** - This is one of the primary APIs for this class and is called by the project. - It returns a tree of plain objects that each contain information about a - discovered addon. Each node has `name`, `path`, `pkg` and - `childAddons` properties. The latter is an array containing any addons - discovered from applying the discovery process to that addon. - - @private - @method discoverProjectAddons - */ -AddonDiscovery.prototype.discoverProjectAddons = function(project) { - var projectAsAddon = this.discoverFromProjectItself(project); - var internalAddons = this.discoverFromInternalProjectAddons(project); - var cliAddons = this.discoverFromCli(project.cli); - var dependencyAddons; - - if (project.hasDependencies()) { - dependencyAddons = this.discoverFromDependencies(project.root, project.nodeModulesPath, project.pkg, false); - } else { - dependencyAddons = []; - } - - var inRepoAddons = this.discoverInRepoAddons(project.root, project.pkg); - var addons = projectAsAddon.concat(cliAddons, internalAddons, dependencyAddons, inRepoAddons); - - return addons; -}; - -/** - This is one of the primary APIs for this class and is called by addons. - It returns a tree of plain objects that each contain information about a - discovered addon. Each node has `name`, `path`, `pkg` and - `childAddons` properties. The latter is an array containing any addons - discovered from applying the discovery process to that addon. - - @private - @method discoverProjectAddons - */ -AddonDiscovery.prototype.discoverChildAddons = function(addon) { - debug('discoverChildAddons: %s(%s)', addon.name, addon.root); - var dependencyAddons = this.discoverFromDependencies(addon.root, addon.nodeModulesPath, addon.pkg, true); - var inRepoAddons = this.discoverInRepoAddons(addon.root, addon.pkg); - var addons = dependencyAddons.concat(inRepoAddons); - - addons = addons.filter(function(childAddon) { - return !addon.shouldIncludeChildAddon || addon.shouldIncludeChildAddon(childAddon); - }); - - return addons; -}; - -/** - Returns an array containing zero or one nodes, depending on whether or not - the passed project is an addon. - - @private - @method discoverFromProjectItself - */ -AddonDiscovery.prototype.discoverFromProjectItself = function(project) { - if (project.isEmberCLIAddon()) { - var addonPkg = this.discoverAtPath(project.root); - if (addonPkg) { - return [addonPkg]; - } - } - return []; -}; - -/** - Returns a tree based on the addons referenced in the provided `pkg` through - the package.json `dependencies` and optionally `devDependencies` collections, - as well as those discovered addons' child addons. - - @private - @method discoverFromDependencies - */ -AddonDiscovery.prototype.discoverFromDependencies = function(root, nodeModulesPath, pkg, excludeDevDeps) { - var discovery = this; - var addons = Object.keys(this.dependencies(pkg, excludeDevDeps)).map(function(name) { - if (name !== 'ember-cli') { - var addonPath = this.resolvePackage(root, name); - - if (addonPath) { - return discovery.discoverAtPath(addonPath); - } - - // this supports packages that do not have a valid entry point - // script (aka `main` entry in `package.json` or `index.js`) - addonPath = path.join(nodeModulesPath, name); - var addon = discovery.discoverAtPath(addonPath); - if (addon) { - var chalk = require('chalk'); - - discovery.ui.writeLine(chalk.yellow('The package `' + name + '` is not a properly formatted package, we have used a fallback lookup to resolve it at `' + addonPath + '`. This is generally caused by an addon not having a `main` entry point (or `index.js`).'), 'WARNING'); - - return addon; - } - } - }, this).filter(Boolean); - return addons; -}; - -AddonDiscovery.prototype.resolvePackage = function(root, packageName) { - try { - - var entryModulePath = resolve.sync(packageName, { basedir: root }); - - return findup.sync(entryModulePath, 'package.json'); - } catch (e) { - var acceptableError = 'Cannot find module \'' + packageName + '\' from \'' + root + '\''; - // pending: https://github.com/substack/node-resolve/pull/80 - var workAroundError = 'Cannot read property \'isFile\' of undefined'; - - if (e.message === workAroundError || e.message === acceptableError) { - return; - } - throw e; - } -}; - -/** - Returns a tree based on the in-repo addons referenced in the provided `pkg` - through paths listed in the `ember-addon` entry, as well as those discovered - addons' child addons. - - @private - @method discoverInRepoAddons - */ -AddonDiscovery.prototype.discoverInRepoAddons = function(root, pkg) { - if (!pkg || !pkg['ember-addon'] || !pkg['ember-addon'].paths) { - return []; - } - var discovery = this; - var addons = pkg['ember-addon'].paths.map(function(addonPath) { - addonPath = path.join(root, addonPath); - return discovery.discoverAtPath(addonPath); - }, this).filter(Boolean); - return addons; -}; - -/** - Returns a tree based on the internal addons that may be defined within the project. - It does this by consulting the projects `supportedInternalAddonPaths()` method, which - is primarily used for middleware addons. - - @private - @method discoverFromInternalProjectAddons - */ -AddonDiscovery.prototype.discoverFromInternalProjectAddons = function(project) { - var discovery = this; - return project.supportedInternalAddonPaths().map(function(path) { - return discovery.discoverAtPath(path); - }).filter(Boolean); -}; - -AddonDiscovery.prototype.discoverFromCli = function (cli) { - if (!cli) { return []; } - - var cliPkg = require(path.resolve(cli.root, 'package.json')); - return this.discoverInRepoAddons(cli.root, cliPkg); -}; - -/** - Given a particular path, return undefined if the path is not an addon, or if it is, - a node with the info about the addon. - - @private - @method discoverAtPath - */ -AddonDiscovery.prototype.discoverAtPath = function(addonPath) { - var pkgPath = path.join(addonPath, 'package.json'); - debug('attemping to add: %s', addonPath); - - if (existsSync(pkgPath)) { - var addonPkg = require(pkgPath); - var keywords = addonPkg.keywords || []; - debug(' - module found: %s', addonPkg.name); - - addonPkg['ember-addon'] = addonPkg['ember-addon'] || {}; - - if (keywords.indexOf('ember-addon') > -1) { - debug(' - is addon, adding...'); - var addonInfo = { - name: addonPkg.name, - path: addonPath, - pkg: addonPkg, - }; - return addonInfo; - } else { - debug(' - no ember-addon keyword, not including.'); - } - } else { - debug(' - no package.json (looked at ' + pkgPath + ').'); - } - - return null; -}; - -/** - Returns the dependencies from a package.json - - @private - @method dependencies - @param {Object} pkg Package object. If false, the current package is used. - @param {Boolean} excludeDevDeps Whether or not development dependencies should be excluded, defaults to false. - @return {Object} Dependencies - */ -AddonDiscovery.prototype.dependencies = function(pkg, excludeDevDeps) { - pkg = pkg || {}; - - var devDependencies = pkg['devDependencies']; - if (excludeDevDeps) { - devDependencies = {}; - } - - return assign({}, devDependencies, pkg['dependencies']); -}; - -AddonDiscovery.prototype.addonPackages = function(addonsList) { - var addonPackages = {}; - - addonsList.forEach(function(addonPkg) { - addonPackages[addonPkg.name] = addonPkg; - }); - - return addonPackages; -}; - -// Export -module.exports = AddonDiscovery; diff --git a/packages/angular-cli/ember-cli/lib/models/addon.js b/packages/angular-cli/ember-cli/lib/models/addon.js index f0dc2b504f3a..3af4880111a7 100644 --- a/packages/angular-cli/ember-cli/lib/models/addon.js +++ b/packages/angular-cli/ember-cli/lib/models/addon.js @@ -10,31 +10,11 @@ var assign = require('lodash/assign'); var SilentError = require('silent-error'); var debug = require('debug')('ember-cli:addon'); -var nodeModulesPath = require('node-modules-path'); - -var p = require('ember-cli-preprocess-registry/preprocessors'); -var preprocessJs = p.preprocessJs; -var preprocessCss = p.preprocessCss; -var preprocessTemplates = p.preprocessTemplates; - -var AddonDiscovery = require('../models/addon-discovery'); -var AddonsFactory = require('../models/addons-factory'); var CoreObject = require('../ext/core-object'); -var Project = require('./project'); var walkSync = require('walk-sync'); -function mergeTrees(inputTree, options) { - options = options || {}; - options.description = options.annotation; - var tree = upstreamMergeTrees(inputTree, options); - - tree.description = options && options.description; - - return tree; -} - /** Root class for an Addon. If your addon module exports an Object this @@ -67,130 +47,23 @@ function Addon(parent, project) { this.ui = project && project.ui; this.addonPackages = {}; this.addons = []; - this.addonDiscovery = new AddonDiscovery(this.ui); - this.addonsFactory = new AddonsFactory(this, this.project); - this.registry = p.defaultRegistry(this); - this._didRequiredBuildPackages = false; - - if (!this.root) { - throw new Error('Addon classes must be instantiated with the `root` property'); - } - this.nodeModulesPath = nodeModulesPath(this.root); - - p.setupRegistry(this); - - if (!this.name) { - throw new SilentError('An addon must define a `name` property.'); - } } Addon.__proto__ = CoreObject; Addon.prototype.constructor = Addon; -Addon.prototype.hintingEnabled = function() { - var isProduction = process.env.EMBER_ENV === 'production'; - var testsEnabledDefault = process.env.EMBER_CLI_TEST_COMMAND || !isProduction; - - return testsEnabledDefault; -}; - -/** - Loads all required modules for a build - - @private - @method _requireBuildPackages - */ - -Addon.prototype._requireBuildPackages = function() { - if (this._didRequiredBuildPackages === true) { - return; - } else { - this._didRequiredBuildPackages = true; - } - - this.transpileModules = deprecatedAddonFilters(this, 'this.transpileModules', 'broccoli-es6modules', function(tree, options) { - }); - - this.pickFiles = deprecatedAddonFilters(this, 'this.pickFiles', 'broccoli-funnel', function(tree, options) { - return new Funnel(tree, options); - }); - - - this.Funnel = deprecatedAddonFilters(this, 'new this.Funnel(..)', 'broccoli-funnel', function(tree, options) { - return new Funnel(tree, options); - }); - - this.walkSync = deprecatedAddonFilters(this, 'this.walkSync', 'node-walk-sync', walkSync); -}; - -function deprecatedAddonFilters(addon, name, insteadUse, fn) { - return function(tree, options) { - var message = name + ' is deprecated, please use ' + - insteadUse + ' directly instead [addon: ' + addon.name + ']'; - - this.ui && this.ui.writeDeprecateLine(message); - - if (!this.ui) { - console.warn(message); - } - - return fn(tree, options); - }; -} - -/** - Shorthand method for [broccoli-concat](https://github.com/ember-cli/broccoli-concat) - - @private - @method concatFiles - @param {tree} tree Tree of files - @param {Object} options Options for broccoli-concat - @return {tree} Modified tree -*/ -Addon.prototype.concatFiles = function(tree, options) { -}; - -/** - Returns whether or not this addon is running in development - - @public - @method isDevelopingAddon - @return {Boolean} -*/ -Addon.prototype.isDevelopingAddon = function() { - if (process.env.EMBER_ADDON_ENV === 'development' && (this.parent instanceof Project)) { - return this.parent.name() === this.name; - } - return false; -}; - -/** - Discovers all child addons of this addon and stores their names and - package.json contents in this.addonPackages as key-value pairs - - @private - @method discoverAddons - */ -Addon.prototype.discoverAddons = function() { - var addonsList = this.addonDiscovery.discoverChildAddons(this); - - this.addonPackages = this.addonDiscovery.addonPackages(addonsList); -}; - Addon.prototype.initializeAddons = function() { if (this._addonsInitialized) { return; } this._addonsInitialized = true; - - debug('initializeAddons for: %s', this.name); - - this.discoverAddons(); - this.addons = this.addonsFactory.initializeAddons(this.addonPackages); - - this.addons.forEach(function(addon) { - debug('addon: %s', addon.name); - }); + this.addonPackages = { + 'angular-cli': { + name: 'angular-cli', + path: path.join(__dirname, '../../../'), + pkg: cliPkg, + } + }; }; /** @@ -213,68 +86,6 @@ Addon.prototype.eachAddonInvoke = function eachAddonInvoke(methodName, args) { }).filter(Boolean); }; -/** - Returns a given type of tree (if present), merged with the - application tree. For each of the trees available using this - method, you can also use a direct method called treeFor[Type] (eg. `treeForApp`). - - Available tree names: - - {{#crossLink "Addon/treeForApp:method"}}app{{/crossLink}} - - {{#crossLink "Addon/treeForStyles:method"}}styles{{/crossLink}} - - {{#crossLink "Addon/treeForTemplates:method"}}templates{{/crossLink}} - - {{#crossLink "Addon/treeForAddonTemplates:method"}}addon-templates{{/crossLink}} - - {{#crossLink "Addon/treeForAddon:method"}}addon{{/crossLink}} - - {{#crossLink "Addon/treeForVendor:method"}}vendor{{/crossLink}} - - {{#crossLink "Addon/treeForTestSupport:method"}}test-support{{/crossLink}} - - {{#crossLink "Addon/treeForPublic:method"}}public{{/crossLink}} - - @public - @method treeFor - @param {String} name - @return {tree} -*/ -Addon.prototype.treeFor = function treeFor(name) { - this._requireBuildPackages(); - - var trees = this.eachAddonInvoke('treeFor', [name]); - var tree = this._treeFor(name); - - if (tree) { - trees.push(tree); - } - - if (this.isDevelopingAddon() && this.hintingEnabled() && name === 'app') { - trees.push(this.jshintAddonTree()); - } - - // return mergeTrees(trees.filter(Boolean), { - // overwrite: true, - // annotation: 'Addon#treeFor (' + this.name + ' - ' + name + ')' - // }); -}; -// -// /** -// @private -// @param {String} name -// @method _treeFor -// @return {tree} -// */ -// Addon.prototype._treeFor = function _treeFor(name) { -// var treePath = path.resolve(this.root, this.treePaths[name]); -// var treeForMethod = this.treeForMethods[name]; -// var tree; -// -// // if (existsSync(treePath)) { -// // tree = this.treeGenerator(treePath); -// // } -// -// if (this[treeForMethod]) { -// tree = this[treeForMethod](tree); -// } -// -// return tree; -// }; - /** This method is called when the addon is included in a build. You would typically use this hook to perform additional imports @@ -299,416 +110,6 @@ Addon.prototype.included = function(/* app */) { this.eachAddonInvoke('included', [this]); }; -/** - Returns the tree for all app files - - @public - @method treeForApp - @param {Tree} tree - @return {Tree} App file tree -*/ -Addon.prototype.treeForApp = function(tree) { - return tree; -}; - -/** - Returns the tree for all template files - - @public - @method treeForTemplates - @param {Tree} tree - @return {Tree} Template file tree -*/ -Addon.prototype.treeForTemplates = function(tree) { - return tree; -}; - -/** - Returns the tree for this addon's templates - - @public - @method treeForAddonTemplates - @param {Tree} tree - @return {Tree} Addon Template file tree -*/ -Addon.prototype.treeForAddonTemplates = function(tree) { - return tree; -}; - -/** - Returns a tree for this addon - - @public - @method treeForAddon - @param {Tree} tree - @return {Tree} Addon file tree -*/ -Addon.prototype.treeForAddon = function(tree) { - this._requireBuildPackages(); - - if (!tree) { - return tree; - } - - var addonTree = this.compileAddon(tree); - var stylesTree = this.compileStyles(this._treeFor('addon-styles')); - - return mergeTrees([addonTree, stylesTree].filter(Boolean), { - annotation: 'Addon#treeForAddon(' + this.name + ')' - }); -}; - -/** - Returns the tree for all style files - - @public - @method treeForStyles - @param {Tree} tree The tree to process, usually `app/styles/` in the addon. - @returns {Tree} The return tree has the same contents as the input tree, but is moved so that the `app/styles/` path is preserved. -*/ -Addon.prototype.treeForStyles = function(tree) { - this._requireBuildPackages(); - - if (!tree) { - return tree; - } - - return new Funnel(tree, { - destDir: 'app/styles' - }); -}; - -/** - Returns the tree for all vendor files - - @public - @method treeForVendor - @param {Tree} tree - @return {Tree} Vendor file tree -*/ -Addon.prototype.treeForVendor = function(tree) { - return tree; -}; - -/** - Returns the tree for all test support files - - @public - @method treeForTestSupport - @param {Tree} tree - @return {Tree} Test Support file tree -*/ -Addon.prototype.treeForTestSupport = function(tree) { - return tree; -}; - -/** - Returns the tree for all public files - - @public - @method treeForPublic - @param {Tree} tree - @return {Tree} Public file tree -*/ -Addon.prototype.treeForPublic = function(tree) { - this._requireBuildPackages(); - - if (!tree) { - return tree; - } - - return new Funnel(tree, { - srcDir: '/', - destDir: '/' + this.moduleName() - }); -}; - -/** - Returns the tree for all test files namespaced to a given addon. - - @public - @method treeForAddonTestSupport - @param {Tree} tree - @return {Tree} - */ -Addon.prototype.treeForAddonTestSupport = function(tree) { - if (!tree) { - return tree; - } - - var processed = this.preprocessJs(tree, '/', this.name, { - registry: this.registry - }); - - return new Funnel(processed, { - srcDir: '/', - destDir: '/' + this.moduleName() + '/test-support' - }); -}; - -/** - Runs the styles tree through preprocessors. - - @private - @method compileStyles - @param {Tree} tree Styles file tree - @return {Tree} Compiled styles tree -*/ -Addon.prototype.compileStyles = function(tree) { - this._requireBuildPackages(); - - if (tree) { - return preprocessCss(tree, '/', '/', { - outputPaths: { 'addon': this.name + '.css' }, - registry: this.registry - }); - } -}; - -/** - Looks in the addon/ and addon/templates trees to determine if template files - exists that need to be precompiled. - - This is executed once when building, but not on rebuilds. - - @private - @method shouldCompileTemplates - @returns Boolean indicates if templates need to be compiled for this addon -*/ -Addon.prototype.shouldCompileTemplates = function() { - var templateExtensions = this.registry.extensionsForType('template'); - var addonTreePath = path.join(this.root, this.treePaths['addon']); - var addonTemplatesTreePath = path.join(this.root, this.treePaths['addon-templates']); - - var files = []; - - if (existsSync(addonTreePath)) { - files = files.concat(walkSync(addonTreePath)); - } - - if (existsSync(addonTemplatesTreePath)) { - files = files.concat(walkSync(addonTemplatesTreePath)); - } - - var extensionMatcher = new RegExp('(' + templateExtensions.join('|') + ')$'); - - return files.some(function(file) { - return file.match(extensionMatcher); - }); -}; - -Addon.prototype._addonTemplateFiles = function addonTemplateFiles(tree) { - this._requireBuildPackages(); - - if (this._cachedAddonTemplateFiles) { - return this._cachedAddonTemplateFiles; - } - - var trees = []; - var addonTemplates = this._treeFor('addon-templates'); - var standardTemplates; - - if (addonTemplates) { - standardTemplates = new Funnel(addonTemplates, { - srcDir: '/', - destDir: 'modules/' + this.name + '/templates' - }); - - trees.push(standardTemplates); - } - - var includePatterns = this.registry.extensionsForType('template').map(function(extension) { - return '**/*/template.' + extension; - }); - - var podTemplates = new Funnel(tree, { - include: includePatterns, - destDir: 'modules/' + this.name + '/', - annotation: 'Funnel: Addon Pod Templates' - }); - - trees.push(podTemplates); - - this._cachedAddonTemplateFiles = mergeTrees(trees, { - annotation: 'TreeMerge (' + this.name + ' templates)' - }); - - return this._cachedAddonTemplateFiles; -}; - -/** - Invoke the specified method for each of the project's addons. - - @private - @method _eachProjectAddonInvoke - @param {String} methodName the method to invoke on each addon - @param {Array} args the arguments to pass to the invoked method -*/ -Addon.prototype._eachProjectAddonInvoke = function eachProjectAddonInvoke(methodName, args) { - this.initializeAddons(); - - var invokeArguments = args || []; - - return this.project.addons.map(function(addon) { - if (addon[methodName]) { - return addon[methodName].apply(addon, invokeArguments); - } - }).filter(Boolean); -}; - -/** - Runs the templates tree through preprocessors. - - @private - @method compileTemplates - @param {Tree} tree Templates file tree - @return {Tree} Compiled templates tree -*/ -Addon.prototype.compileTemplates = function(tree) { - this._requireBuildPackages(); - - if (this.shouldCompileTemplates()) { - var plugins = this.registry.load('template'); - - if (plugins.length === 0) { - throw new SilentError('Addon templates were detected, but there ' + - 'are no template compilers registered for `' + this.name + '`. ' + - 'Please make sure your template precompiler (commonly `ember-cli-htmlbars`) ' + - 'is listed in `dependencies` (NOT `devDependencies`) in ' + - '`' + this.name + '`\'s `package.json`.'); - } - - - return preprocessTemplates(this._addonTemplateFiles(tree), { - annotation: 'compileTemplates(' + this.name + ')', - registry: this.registry - }); - } -}; - -/** - Runs the addon tree through preprocessors. - - @private - @method compileAddon - @param {Tree} tree Addon file tree - @return {Tree} Compiled addon tree -*/ -Addon.prototype.compileAddon = function(tree) { - this._requireBuildPackages(); - - var reexported; - - var addonJs = this.processedAddonJsFiles(tree); - var templatesTree = this.compileTemplates(tree); - - var trees = [addonJs, templatesTree, reexported].filter(Boolean); - - return mergeTrees(trees, { - annotation: 'Addon#compileAddon(' + this.name + ') ' - }); -}; - -/** - Returns a tree with JSHhint output for all addon JS. - - @private - @method jshintAddonTree - @return {Tree} Tree with JShint output (tests) -*/ -Addon.prototype.jshintAddonTree = function() { - this._requireBuildPackages(); - - var addonPath = path.join(this.root, this.treePaths['addon']); - - if (!existsSync(addonPath)) { - return; - } - - var addonJs = this.addonJsFiles(addonPath); - var addonTemplates = this._addonTemplateFiles(addonPath); - var lintJsTrees = this._eachProjectAddonInvoke('lintTree', ['addon', addonJs]); - var lintTemplateTrees = this._eachProjectAddonInvoke('lintTree', ['templates', addonTemplates]); - var lintTrees = [].concat(lintJsTrees, lintTemplateTrees).filter(Boolean); - var lintedAddon = mergeTrees(lintTrees, { - overwrite: true, - annotation: 'TreeMerger (addon-lint)' - }); - - return new Funnel(lintedAddon, { - srcDir: '/', - destDir: this.name + '/tests/' - }); -}; - -/** - Returns a tree containing the addon's js files - - @private - @method addonJsFiles - @return {Tree} The filtered addon js files -*/ -Addon.prototype.addonJsFiles = function(tree) { - this._requireBuildPackages(); - - if (this._cachedAddonJsFiles) { - return this._cachedAddonJsFiles; - } - - var includePatterns = this.registry.extensionsForType('js').map(function(extension) { - return new RegExp(extension + '$'); - }); - - this._cachedAddonJsFiles = new Funnel(tree, { - include: includePatterns, - destDir: 'modules/' + this.moduleName(), - description: 'Funnel: Addon JS' - }); - - return this._cachedAddonJsFiles; -}; - - -/** - Preprocesses a javascript tree. - - @private - @method preprocessJs - @return {Tree} Preprocessed javascript -*/ -Addon.prototype.preprocessJs = function() { - return preprocessJs.apply(preprocessJs, arguments); -}; - -/** - Returns a tree with all javascript for this addon. - - @private - @method processedAddonJsFiles - @param {Tree} the tree to preprocess - @return {Tree} Processed javascript file tree -*/ -Addon.prototype.processedAddonJsFiles = function(tree) { - return this.preprocessJs(this.addonJsFiles(tree), '/', this.name, { - registry: this.registry - }); -}; - -/** - Returns the module name for this addon. - - @public - @method moduleName - @return {String} module name -*/ -Addon.prototype.moduleName = function() { - if (!this.modulePrefix) { - this.modulePrefix = (this.modulePrefix || this.name).toLowerCase().replace(/\s/g, '-'); - } - - return this.modulePrefix; -}; - /** Returns the path for addon blueprints. @@ -717,11 +118,7 @@ Addon.prototype.moduleName = function() { @return {String} The path for blueprints */ Addon.prototype.blueprintsPath = function() { - var blueprintPath = path.join(this.root, 'blueprints'); - - if (existsSync(blueprintPath)) { - return blueprintPath; - } + return path.join(this.root, 'blueprints'); }; /** @@ -760,28 +157,11 @@ Addon.prototype.config = function (env, baseConfig) { @return {Object} The addon's dependencies based on the addon's package.json */ Addon.prototype.dependencies = function() { + throw new Error() var pkg = this.pkg || {}; return assign({}, pkg['devDependencies'], pkg['dependencies']); }; -/** - @public - @method isEnabled - @return {Boolean} Whether or not this addon is enabled -*/ -Addon.prototype.isEnabled = function() { - return true; -}; - -/** - @public - @method shouldIncludeChildAddon - @return {Boolean} Whether or not a child addon is supposed to be included -*/ -Addon.prototype.shouldIncludeChildAddon = function() { - return true; -}; - /** Returns the absolute path for a given addon @@ -847,102 +227,4 @@ Addon.lookup = function(addon) { return Constructor; }; - -// Methods without default implementation - -/** - CLI commands included with this addon. This function should return - an object with command names and command instances/create options. - - This function is not implemented by default - - ```js - includedCommands: function() { - return { - 'do-foo': require('./lib/commands/foo') - }; - } - ``` - - @public - @method includedCommands - @return {Object} An object with included commands -*/ - - -/** - Post-process a tree - - @public - @method postProcessTree - @param {String} type What kind of tree (eg. 'javascript', 'styles') - @param {Tree} Tree to process - @return {Tree} Processed tree -*/ - -/** - This hook allows you to make changes to the express server run by ember-cli. - It's passed an `startOptions` object which contains: - - `app` Express server instance - - `options` A hash with: - - `project` Current {{#crossLink "Project"}}project{{/crossLink}} - - `watcher` - - `environment` - - This function is not implemented by default - - ```js - serverMiddleware: function(startOptions) { - var app = startOptions.app; - - app.use(function(req, res, next) { - // Some middleware - }); - } - ``` - - @public - @method serverMiddleware - @param {Object} startOptions Express server start options -*/ - -/** - This hook is called before a build takes place. - - @public - @method preBuild - @param {Object} result Build object -*/ - -/** - This hook is called after a build is complete. - - It's passed an `result` object which contains: - - `directory` Path to build output - - @public - @method postBuild - @param {Object} result Build result object -*/ - -/** - This hook is called after the build files have been copied to the output directory - - It's passed an `result` object which contains: - - `directory` Path to build output - - @public - @method outputReady - @param {Object} result Build result object -*/ - -/** - This hook is called when an error occurs during the preBuild, postBuild or outputReady hooks - for addons, or when the build fails - - @public - @method buildError - @param {Error} error The error that was caught during the processes listed above -*/ - module.exports = Addon; diff --git a/packages/angular-cli/ember-cli/lib/models/addons-factory.js b/packages/angular-cli/ember-cli/lib/models/addons-factory.js deleted file mode 100644 index 39c231b43633..000000000000 --- a/packages/angular-cli/ember-cli/lib/models/addons-factory.js +++ /dev/null @@ -1,66 +0,0 @@ -'use strict'; - -/** -@module ember-cli -*/ - -var CoreObject = require('../ext/core-object'); -var DAG = require('../utilities/DAG'); -var debug = require('debug')('ember-cli:addons-factory'); - -/** - AddonsFactory is responsible for instantiating a collection of addons, in the right order. - - @class AddonsFactory - @extends CoreObject - @constructor -*/ -function AddonsFactory(addonParent, project) { - this.addonParent = addonParent; - this.project = project; -} - -AddonsFactory.__proto__ = CoreObject; -AddonsFactory.prototype.constructor = AddonsFactory; - -AddonsFactory.prototype.initializeAddons = function(addonPackages) { - var addonParent = this.addonParent; - var project = this.project; - var graph = new DAG(); - var Addon = require('../models/addon'); - var addonInfo, emberAddonConfig; - - debug('initializeAddons for: ', typeof addonParent.name === 'function' ? addonParent.name() : addonParent.name); - debug(' addon names are:', Object.keys(addonPackages)); - - for (var name in addonPackages) { - addonInfo = addonPackages[name]; - emberAddonConfig = addonInfo.pkg['ember-addon']; - - graph.addEdges(name, addonInfo, emberAddonConfig.before, emberAddonConfig.after); - } - - var addons = []; - graph.topsort(function (vertex) { - var addonInfo = vertex.value; - if (addonInfo) { - var AddonConstructor = Addon.lookup(addonInfo); - var addon = new AddonConstructor(addonParent, project); - if (addon.initializeAddons) { - addon.initializeAddons(); - } else { - addon.addons = []; - } - addons.push(addon); - } - }); - - debug(' addons ordered as:', addons.map(function(addon) { - return addon.name; - })); - - return addons; -}; - -// Export -module.exports = AddonsFactory; diff --git a/packages/angular-cli/ember-cli/lib/models/project.js b/packages/angular-cli/ember-cli/lib/models/project.js index fda4ed524a51..5dbaf44c5582 100644 --- a/packages/angular-cli/ember-cli/lib/models/project.js +++ b/packages/angular-cli/ember-cli/lib/models/project.js @@ -14,8 +14,6 @@ var assign = require('lodash/assign'); var forOwn = require('lodash/forOwn'); var merge = require('lodash/merge'); var debug = require('debug')('ember-cli:project'); -var AddonDiscovery = require('../models/addon-discovery'); -var AddonsFactory = require('../models/addons-factory'); var Command = require('../models/command'); var UI = require('../ui'); var nodeModulesPath = require('node-modules-path'); @@ -42,8 +40,6 @@ function Project(root, pkg, ui, cli) { this.addons = []; this.liveReloadFilterPatterns = []; this.setupNodeModulesPath(); - this.addonDiscovery = new AddonDiscovery(this.ui); - this.addonsFactory = new AddonsFactory(this, this); this._watchmanInfo = { enabled: false, version: null, @@ -285,19 +281,6 @@ Project.prototype.supportedInternalAddonPaths = function() { ]; }; -/** - Discovers all addons for this project and stores their names and - package.json contents in this.addonPackages as key-value pairs - - @private - @method discoverAddons - */ -Project.prototype.discoverAddons = function() { - var addonsList = this.addonDiscovery.discoverProjectAddons(this); - - this.addonPackages = this.addonDiscovery.addonPackages(addonsList); -}; - /** Loads and initializes all addons for this project. @@ -312,13 +295,16 @@ Project.prototype.initializeAddons = function() { debug('initializeAddons for: %s', this.name()); - this.discoverAddons(); - - this.addons = this.addonsFactory.initializeAddons(this.addonPackages); - - this.addons.forEach(function(addon) { - debug('addon: %s', addon.name); + const cliPkg = require(path.resolve(__dirname, '../../../package.json')); + const Addon = require('../models/addon'); + const Constructor = Addon.lookup({ + name: 'angular-cli', + path: path.join(__dirname, '../../../'), + pkg: cliPkg, }); + + const addon = new Constructor(this.addonParent, this); + this.addons = [addon]; }; /** diff --git a/packages/angular-cli/package.json b/packages/angular-cli/package.json index 24fed046dc80..7ac4355e9dba 100644 --- a/packages/angular-cli/package.json +++ b/packages/angular-cli/package.json @@ -35,13 +35,11 @@ "autoprefixer": "^6.5.3", "chalk": "^1.1.3", "common-tags": "^1.3.1", - "configstore": "^2.0.0", "css-loader": "^0.23.1", "debug": "^2.1.3", "denodeify": "^1.2.1", "diff": "^2.2.2", "ember-cli-normalize-entity-name": "^1.0.0", - "ember-cli-preprocess-registry": "^2.0.0", "ember-cli-string-utils": "^1.0.0", "exists-sync": "0.0.3", "extract-text-webpack-plugin": "^2.0.0-beta.4", @@ -96,7 +94,6 @@ "tslint-loader": "^3.3.0", "typescript": "~2.0.3", "url-loader": "^0.5.7", - "uuid": "^3.0.0", "walk-sync": "^0.2.6", "webpack": "2.1.0-beta.25", "webpack-dev-server": "2.1.0-beta.9",