From 7ba8b394b0367a41b82eb53bacbe7116fad928d4 Mon Sep 17 00:00:00 2001 From: zackarychapple Date: Thu, 24 Mar 2016 13:25:01 -0400 Subject: [PATCH] feat(formatting): adding editor config, adding eslint and tslint config. --- .editorconfig | 15 + .eslintrc | 11 + addon/ng2/blueprints/component-test/index.js | 7 +- addon/ng2/blueprints/component/index.js | 13 +- addon/ng2/blueprints/directive/index.js | 13 +- .../blueprints/ng2/files/karma-test-shim.js | 26 +- addon/ng2/blueprints/ng2/files/karma.conf.js | 40 +- .../blueprints/ng2/files/protractor.conf.js | 3 +- addon/ng2/blueprints/ng2/index.js | 10 +- addon/ng2/blueprints/pipe/index.js | 17 +- addon/ng2/blueprints/route-config/index.js | 24 +- addon/ng2/blueprints/route-test/index.js | 9 +- addon/ng2/blueprints/route/index.js | 34 +- addon/ng2/blueprints/service-test/index.js | 9 +- addon/ng2/blueprints/service/index.js | 17 +- addon/ng2/commands/completion.js | 6 +- addon/ng2/commands/e2e.js | 2 +- addon/ng2/commands/format.js | 13 +- addon/ng2/commands/init.js | 55 +- addon/ng2/commands/lint.js | 2 +- addon/ng2/commands/new.ts | 107 ++-- addon/ng2/commands/test.js | 55 +- addon/ng2/commands/version.ts | 11 +- addon/ng2/index.js | 18 +- addon/ng2/tasks/e2e.js | 2 +- addon/ng2/tasks/format.js | 9 +- addon/ng2/tasks/git-init.js | 47 +- addon/ng2/tasks/lint.js | 9 +- addon/ng2/tasks/test.js | 4 +- addon/ng2/utilities/dynamic-path-parser.js | 13 +- bin/ng | 90 +-- eslint.json | 220 +++++++ index.js | 4 +- lib/broccoli/angular2-app.js | 301 +++++---- lib/broccoli/broccoli-config-replace.js | 90 +-- lib/broccoli/broccoli-typescript.js | 575 +++++++++--------- lib/broccoli/service-worker-manifest.js | 8 +- lib/cli/index.js | 22 +- package.json | 5 +- tests/acceptance/dynamic-path-parser.spec.js | 38 +- tests/acceptance/generate-component.spec.js | 202 +++--- tests/acceptance/generate-directive.spec.js | 205 +++---- tests/acceptance/generate-pipe.spec.js | 187 +++--- tests/acceptance/generate-route.spec.js | 94 ++- tests/acceptance/generate-service.spec.js | 198 +++--- tests/acceptance/init.spec.js | 352 +++++------ tests/acceptance/new.spec.js | 323 +++++----- tests/e2e/e2e_workflow.spec.js | 155 ++--- tests/helpers/mock-analytics.js | 12 +- tests/helpers/mock-ui.js | 58 +- tests/helpers/ng.js | 30 +- tests/helpers/tmp.js | 33 +- tests/runner.js | 7 +- tslint.json | 63 ++ 54 files changed, 1918 insertions(+), 1955 deletions(-) create mode 100644 .editorconfig create mode 100644 .eslintrc create mode 100644 eslint.json create mode 100644 tslint.json diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 000000000000..f1cc3ad329c5 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,15 @@ +# http://editorconfig.org + +root = true + +[*] +charset = utf-8 +indent_style = space +indent_size = 2 +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true + +[*.md] +insert_final_newline = false +trim_trailing_whitespace = false diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 000000000000..1124293f2957 --- /dev/null +++ b/.eslintrc @@ -0,0 +1,11 @@ +{ + "ecmaFeatures": { + "modules": true, + "module": true + }, + "env": { + "mocha": true, + "node": true, + "es6": true + } +} diff --git a/addon/ng2/blueprints/component-test/index.js b/addon/ng2/blueprints/component-test/index.js index 557bbba0b12f..50992809f319 100644 --- a/addon/ng2/blueprints/component-test/index.js +++ b/addon/ng2/blueprints/component-test/index.js @@ -1,12 +1,13 @@ module.exports = { description: '', - + // ****************************************************** // ****************************************************** // LEAVE THIS HERE // Must override install to prevent ember's component tests // ****************************************************** // ****************************************************** - - install: function(options){} + + install: function () { + } }; diff --git a/addon/ng2/blueprints/component/index.js b/addon/ng2/blueprints/component/index.js index 9af8160bf9ce..d8f38de52005 100644 --- a/addon/ng2/blueprints/component/index.js +++ b/addon/ng2/blueprints/component/index.js @@ -1,29 +1,28 @@ -var stringUtils = require('ember-cli/lib/utilities/string'); var dynamicPathParser = require('../../utilities/dynamic-path-parser'); module.exports = { description: '', - normalizeEntityName: function(entityName) { + normalizeEntityName: function (entityName) { var parsedPath = dynamicPathParser(this.project, entityName); - + this.dynamicPath = parsedPath; return parsedPath.name; }, - locals: function(options) { + locals: function () { return { dynamicPath: this.dynamicPath.dir }; }, - fileMapTokens: function(options) { + fileMapTokens: function () { // Return custom template variables here. return { - __name__: (options) => { + __name__: () => { return this.dynamicPath.name; }, - __path__: (options) => { + __path__: () => { return this.dynamicPath.dir; } }; diff --git a/addon/ng2/blueprints/directive/index.js b/addon/ng2/blueprints/directive/index.js index 9af8160bf9ce..d8f38de52005 100644 --- a/addon/ng2/blueprints/directive/index.js +++ b/addon/ng2/blueprints/directive/index.js @@ -1,29 +1,28 @@ -var stringUtils = require('ember-cli/lib/utilities/string'); var dynamicPathParser = require('../../utilities/dynamic-path-parser'); module.exports = { description: '', - normalizeEntityName: function(entityName) { + normalizeEntityName: function (entityName) { var parsedPath = dynamicPathParser(this.project, entityName); - + this.dynamicPath = parsedPath; return parsedPath.name; }, - locals: function(options) { + locals: function () { return { dynamicPath: this.dynamicPath.dir }; }, - fileMapTokens: function(options) { + fileMapTokens: function () { // Return custom template variables here. return { - __name__: (options) => { + __name__: () => { return this.dynamicPath.name; }, - __path__: (options) => { + __path__: () => { return this.dynamicPath.dir; } }; diff --git a/addon/ng2/blueprints/ng2/files/karma-test-shim.js b/addon/ng2/blueprints/ng2/files/karma-test-shim.js index a62ac95bc9b7..22254c16f3c8 100644 --- a/addon/ng2/blueprints/ng2/files/karma-test-shim.js +++ b/addon/ng2/blueprints/ng2/files/karma-test-shim.js @@ -1,8 +1,10 @@ +/*global jasmine, __karma__, window*/ Error.stackTraceLimit = Infinity; jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000; -__karma__.loaded = function() {}; +__karma__.loaded = function () { +}; System.config({ packages: { @@ -11,30 +13,30 @@ System.config({ format: 'register', map: Object.keys(window.__karma__.files) .filter(onlyAppFiles) - .reduce(function(pathsMapping, appPath) { + .reduce(function (pathsMapping, appPath) { var moduleName = appPath.replace(/^\/base\/dist\/app\//, './').replace(/\.js$/, ''); - pathsMapping[moduleName] = appPath + '?' + window.__karma__.files[appPath] - return pathsMapping; - }, {}) + pathsMapping[moduleName] = appPath + '?' + window.__karma__.files[appPath]; + return pathsMapping; + }, {}) } } }); -System.import('angular2/testing').then(function(testing) { - return System.import('angular2/platform/testing/browser').then(function(providers) { +System.import('angular2/testing').then(function (testing) { + return System.import('angular2/platform/testing/browser').then(function (providers) { testing.setBaseTestProviders(providers.TEST_BROWSER_PLATFORM_PROVIDERS, - providers.TEST_BROWSER_APPLICATION_PROVIDERS); + providers.TEST_BROWSER_APPLICATION_PROVIDERS); }); -}).then(function() { +}).then(function () { return Promise.all( Object.keys(window.__karma__.files) .filter(onlySpecFiles) - .map(function(moduleName) { + .map(function (moduleName) { return System.import(moduleName); })); -}).then(function() { +}).then(function () { __karma__.start(); -}, function(error) { +}, function (error) { __karma__.error(error.stack || error); }); diff --git a/addon/ng2/blueprints/ng2/files/karma.conf.js b/addon/ng2/blueprints/ng2/files/karma.conf.js index f95f0a872f3d..4b352a933036 100644 --- a/addon/ng2/blueprints/ng2/files/karma.conf.js +++ b/addon/ng2/blueprints/ng2/files/karma.conf.js @@ -1,4 +1,4 @@ -module.exports = function(config) { +module.exports = function (config) { config.set({ basePath: '', frameworks: ['jasmine'], @@ -9,39 +9,39 @@ module.exports = function(config) { customLaunchers: { // chrome setup for travis CI using chromium Chrome_travis_ci: { - base: 'Chrome', - flags: ['--no-sandbox'] - }, + base: 'Chrome', + flags: ['--no-sandbox'] + } }, files: [ - {pattern: 'node_modules/systemjs/dist/system-polyfills.js', included: true, watched: true}, - {pattern: 'node_modules/systemjs/dist/system.src.js', included: true, watched: true}, - {pattern: 'node_modules/es6-shim/es6-shim.js', included: true, watched: true}, - {pattern: 'node_modules/angular2/bundles/angular2-polyfills.js', included: true, watched: true}, - {pattern: 'node_modules/rxjs/bundles/Rx.js', included: true, watched: true}, - {pattern: 'node_modules/angular2/bundles/angular2.js', included: true, watched: true}, - {pattern: 'node_modules/angular2/bundles/http.dev.js', included: true, watched: true}, - {pattern: 'node_modules/angular2/bundles/router.dev.js', included: true, watched: true}, - {pattern: 'node_modules/angular2/bundles/testing.dev.js', included: true, watched: true}, + { pattern: 'node_modules/systemjs/dist/system-polyfills.js', included: true, watched: true }, + { pattern: 'node_modules/systemjs/dist/system.src.js', included: true, watched: true }, + { pattern: 'node_modules/es6-shim/es6-shim.js', included: true, watched: true }, + { pattern: 'node_modules/angular2/bundles/angular2-polyfills.js', included: true, watched: true }, + { pattern: 'node_modules/rxjs/bundles/Rx.js', included: true, watched: true }, + { pattern: 'node_modules/angular2/bundles/angular2.js', included: true, watched: true }, + { pattern: 'node_modules/angular2/bundles/http.dev.js', included: true, watched: true }, + { pattern: 'node_modules/angular2/bundles/router.dev.js', included: true, watched: true }, + { pattern: 'node_modules/angular2/bundles/testing.dev.js', included: true, watched: true }, - {pattern: 'karma-test-shim.js', included: true, watched: true}, + { pattern: 'karma-test-shim.js', included: true, watched: true }, // paths loaded via module imports - {pattern: 'dist/**/*.js', included: false, watched: true}, + { pattern: 'dist/**/*.js', included: false, watched: true }, // paths loaded via Angular's component compiler // (these paths need to be rewritten, see proxies section) - {pattern: 'dist/**/*.html', included: false, watched: true}, - {pattern: 'dist/**/*.css', included: false, watched: true}, + { pattern: 'dist/**/*.html', included: false, watched: true }, + { pattern: 'dist/**/*.css', included: false, watched: true }, // paths to support debugging with source maps in dev tools - {pattern: 'dist/**/*.ts', included: false, watched: false}, - {pattern: 'dist/**/*.js.map', included: false, watched: false} + { pattern: 'dist/**/*.ts', included: false, watched: false }, + { pattern: 'dist/**/*.js.map', included: false, watched: false } ], proxies: { // required for component assets fetched by Angular's compiler - "/app/": "/base/dist/app/" + '/app/': '/base/dist/app/' }, exclude: [], preprocessors: {}, diff --git a/addon/ng2/blueprints/ng2/files/protractor.conf.js b/addon/ng2/blueprints/ng2/files/protractor.conf.js index 2dc4d5a3ba06..b779eefed9af 100644 --- a/addon/ng2/blueprints/ng2/files/protractor.conf.js +++ b/addon/ng2/blueprints/ng2/files/protractor.conf.js @@ -1,3 +1,4 @@ +/*global jasmine */ var SpecReporter = require('jasmine-spec-reporter'); exports.config = { @@ -24,5 +25,5 @@ exports.config = { }, onPrepare: function() { jasmine.getEnv().addReporter(new SpecReporter()); - }, + } }; diff --git a/addon/ng2/blueprints/ng2/index.js b/addon/ng2/blueprints/ng2/index.js index 1da0d1bef363..c38eb51ea90d 100644 --- a/addon/ng2/blueprints/ng2/index.js +++ b/addon/ng2/blueprints/ng2/index.js @@ -4,11 +4,11 @@ module.exports = { description: '', locals: function(options) { - // Return custom template variables here. - return { - htmlComponentName: stringUtils.dasherize(options.entity.name), - jsComponentName: stringUtils.classify(options.entity.name) - }; + // Return custom template variables here. + return { + htmlComponentName: stringUtils.dasherize(options.entity.name), + jsComponentName: stringUtils.classify(options.entity.name) + }; } // afterInstall: function(options) { diff --git a/addon/ng2/blueprints/pipe/index.js b/addon/ng2/blueprints/pipe/index.js index 9af8160bf9ce..5b520c0a0278 100644 --- a/addon/ng2/blueprints/pipe/index.js +++ b/addon/ng2/blueprints/pipe/index.js @@ -1,29 +1,26 @@ -var stringUtils = require('ember-cli/lib/utilities/string'); var dynamicPathParser = require('../../utilities/dynamic-path-parser'); module.exports = { description: '', - normalizeEntityName: function(entityName) { + normalizeEntityName: function (entityName) { var parsedPath = dynamicPathParser(this.project, entityName); - + this.dynamicPath = parsedPath; return parsedPath.name; }, - locals: function(options) { - return { - dynamicPath: this.dynamicPath.dir - }; + locals: function () { + return { dynamicPath: this.dynamicPath.dir }; }, - fileMapTokens: function(options) { + fileMapTokens: function () { // Return custom template variables here. return { - __name__: (options) => { + __name__: () => { return this.dynamicPath.name; }, - __path__: (options) => { + __path__: () => { return this.dynamicPath.dir; } }; diff --git a/addon/ng2/blueprints/route-config/index.js b/addon/ng2/blueprints/route-config/index.js index 8345c2c7937c..39ac11805264 100644 --- a/addon/ng2/blueprints/route-config/index.js +++ b/addon/ng2/blueprints/route-config/index.js @@ -15,6 +15,7 @@ module.exports = { try { fs.unlinkSync(routeConfigPath); } catch (e) { + // doing nothing here } } }; @@ -23,17 +24,16 @@ function generateLocals(options) { var ngCliConfigPath = path.join(options.project.root, 'angular-cli.json'); var ngCliConfig = JSON.parse(fs.readFileSync(ngCliConfigPath, 'utf-8')); - imports = ngCliConfig.routes.map(route => - `import {${route.component}} from '${route.componentPath}';`) - .join('\n'); + imports = + ngCliConfig.routes.map(route => `import {${route.component}} from '${route.componentPath}';`) + .join('\n'); - routeDefinitions = ngCliConfig.routes.map(route => - `{path: '${route.routePath}', name: '${route.component}', component: ${route.component}},` - ) - .join('\n'); + routeDefinitions = + ngCliConfig.routes + .map( + route => + `{path: '${route.routePath}', name: '${route.component}', component: ${route.component}},`) + .join('\n'); - return { - imports, - routeDefinitions - } -} \ No newline at end of file + return { imports, routeDefinitions } +} diff --git a/addon/ng2/blueprints/route-test/index.js b/addon/ng2/blueprints/route-test/index.js index e1d2a516ee13..0fbcb7230a14 100644 --- a/addon/ng2/blueprints/route-test/index.js +++ b/addon/ng2/blueprints/route-test/index.js @@ -1,14 +1,13 @@ -var stringUtils = require('ember-cli/lib/utilities/string'); - module.exports = { description: '', - + // ****************************************************** // ****************************************************** // LEAVE THIS HERE // Must override install to prevent ember's route tests // ****************************************************** // ****************************************************** - - install: function(options){} + + install: function () { + } }; diff --git a/addon/ng2/blueprints/route/index.js b/addon/ng2/blueprints/route/index.js index a55d7d6d31c3..0023d8ff8e57 100644 --- a/addon/ng2/blueprints/route/index.js +++ b/addon/ng2/blueprints/route/index.js @@ -5,16 +5,10 @@ var chalk = require('chalk'); module.exports = { description: 'Generates a route and a template.', - availableOptions: [{ - name: 'skip-router-generation', - type: Boolean, - default: false, - aliases: ['srg'] - }, { - name: 'default', - type: Boolean, - default: false - }], + availableOptions: [ + { name: 'skip-router-generation', type: Boolean, default: false, aliases: ['srg'] }, + { name: 'default', type: Boolean, default: false } + ], beforeInstall: function (options, locals) { if (!options.skipRouterGeneration) { @@ -22,10 +16,9 @@ module.exports = { } }, - afterInstall: function (options, locals) { + afterInstall: function (options) { if (!options.skipRouterGeneration) { - return this.lookupBlueprint('route-config') - .install(options); + return this.lookupBlueprint('route-config').install(options); } }, @@ -33,18 +26,14 @@ module.exports = { updateRouteConfig.call(this, 'remove', options, locals); }, - afterUninstall: function (options, locals) { - return this.lookupBlueprint('route-config') - .install(options); + afterUninstall: function (options) { + return this.lookupBlueprint('route-config').install(options); } }; function updateRouteConfig(action, options, locals) { var entity = options.entity; - var actionColorMap = { - add: 'green', - remove: 'red' - }; + var actionColorMap = { add: 'green', remove: 'red' }; var color = actionColorMap[action] || 'gray'; this._writeStatusToUI(chalk[color], action + ' route', entity.name); @@ -59,7 +48,8 @@ function updateRouteConfig(action, options, locals) { }; var ngCliConfig = JSON.parse(fs.readFileSync(ngCliConfigPath, 'utf-8')); - if (action === 'add' && ngCliConfig.routes.findIndex(el => el.routePath === route.routePath) === -1) { + if (action === 'add' && + ngCliConfig.routes.findIndex(el => el.routePath === route.routePath) === -1) { ngCliConfig.routes.push(route) } else if (action === 'remove') { var idx = ngCliConfig.routes.findIndex(el => el.routePath === route.routePath); @@ -68,4 +58,4 @@ function updateRouteConfig(action, options, locals) { } } fs.writeFileSync(ngCliConfigPath, JSON.stringify(ngCliConfig, null, 2)); -} \ No newline at end of file +} diff --git a/addon/ng2/blueprints/service-test/index.js b/addon/ng2/blueprints/service-test/index.js index b5a248591b86..d0dfac69a3ab 100644 --- a/addon/ng2/blueprints/service-test/index.js +++ b/addon/ng2/blueprints/service-test/index.js @@ -1,14 +1,13 @@ -var stringUtils = require('ember-cli/lib/utilities/string'); - module.exports = { description: '', - + // ****************************************************** // ****************************************************** // LEAVE THIS HERE // Must override install to prevent ember's service tests // ****************************************************** // ****************************************************** - - install: function(options){} + + install: function () { + } }; diff --git a/addon/ng2/blueprints/service/index.js b/addon/ng2/blueprints/service/index.js index 9af8160bf9ce..5b520c0a0278 100644 --- a/addon/ng2/blueprints/service/index.js +++ b/addon/ng2/blueprints/service/index.js @@ -1,29 +1,26 @@ -var stringUtils = require('ember-cli/lib/utilities/string'); var dynamicPathParser = require('../../utilities/dynamic-path-parser'); module.exports = { description: '', - normalizeEntityName: function(entityName) { + normalizeEntityName: function (entityName) { var parsedPath = dynamicPathParser(this.project, entityName); - + this.dynamicPath = parsedPath; return parsedPath.name; }, - locals: function(options) { - return { - dynamicPath: this.dynamicPath.dir - }; + locals: function () { + return { dynamicPath: this.dynamicPath.dir }; }, - fileMapTokens: function(options) { + fileMapTokens: function () { // Return custom template variables here. return { - __name__: (options) => { + __name__: () => { return this.dynamicPath.name; }, - __path__: (options) => { + __path__: () => { return this.dynamicPath.dir; } }; diff --git a/addon/ng2/commands/completion.js b/addon/ng2/commands/completion.js index bbddefbfafb9..35f2a466df46 100644 --- a/addon/ng2/commands/completion.js +++ b/addon/ng2/commands/completion.js @@ -1,9 +1,9 @@ -/* jshint node: true */ +/*eslint-disable no-console */ 'use strict'; var Command = require('ember-cli/lib/models/command'); -var path = require('path'); -var fs = require('fs'); +var path = require('path'); +var fs = require('fs'); module.exports = Command.extend({ name: 'completion', diff --git a/addon/ng2/commands/e2e.js b/addon/ng2/commands/e2e.js index e2ae53a8a4a9..77ca127a21aa 100644 --- a/addon/ng2/commands/e2e.js +++ b/addon/ng2/commands/e2e.js @@ -8,7 +8,7 @@ module.exports = Command.extend({ name: 'e2e', description: 'Run e2e tests in existing project', works: 'insideProject', - run: function() { + run: function () { var e2eTask = new E2ETask({ ui: this.ui, analytics: this.analytics, diff --git a/addon/ng2/commands/format.js b/addon/ng2/commands/format.js index 29aeebab949c..6b9d980cc2b2 100644 --- a/addon/ng2/commands/format.js +++ b/addon/ng2/commands/format.js @@ -8,12 +8,13 @@ module.exports = Command.extend({ name: 'format', description: 'Formats code in existing project', works: 'insideProject', - run: function() { - var formatTask = new FormatTask({ - ui: this.ui, - analytics: this.analytics, - project: this.project - }); + run: function () { + var formatTask = + new FormatTask({ + ui: this.ui, + analytics: this.analytics, + project: this.project + }); return formatTask.run(); } diff --git a/addon/ng2/commands/init.js b/addon/ng2/commands/init.js index 62b0de8d396b..a8770a1c3d8b 100644 --- a/addon/ng2/commands/init.js +++ b/addon/ng2/commands/init.js @@ -1,11 +1,11 @@ 'use strict'; -var Command = require('ember-cli/lib/models/command'); -var Promise = require('ember-cli/lib/ext/promise'); -var SilentError = require('silent-error'); -var validProjectName = require('ember-cli/lib/utilities/valid-project-name'); +var Command = require('ember-cli/lib/models/command'); +var Promise = require('ember-cli/lib/ext/promise'); +var SilentError = require('silent-error'); +var validProjectName = require('ember-cli/lib/utilities/valid-project-name'); var normalizeBlueprint = require('ember-cli/lib/utilities/normalize-blueprint-option'); -var GitInit = require('../tasks/git-init'); +var GitInit = require('../tasks/git-init'); module.exports = Command.extend({ name: 'init', @@ -14,19 +14,17 @@ module.exports = Command.extend({ works: 'everywhere', availableOptions: [ - { name: 'dry-run', type: Boolean, default: false, aliases: ['d'] }, - { name: 'verbose', type: Boolean, default: false, aliases: ['v'] }, - { name: 'blueprint', type: String, aliases: ['b'] }, - { name: 'skip-npm', type: Boolean, default: false, aliases: ['sn'] }, - { name: 'skip-bower', type: Boolean, default: true, aliases: ['sb'] }, - { name: 'name', type: String, default: '', aliases: ['n'] } + { name: 'dry-run', type: Boolean, default: false, aliases: ['d'] }, + { name: 'verbose', type: Boolean, default: false, aliases: ['v'] }, + { name: 'blueprint', type: String, aliases: ['b'] }, + { name: 'skip-npm', type: Boolean, default: false, aliases: ['sn'] }, + { name: 'skip-bower', type: Boolean, default: true, aliases: ['sb'] }, + { name: 'name', type: String, default: '', aliases: ['n'] } ], - anonymousOptions: [ - '' - ], + anonymousOptions: [''], - _defaultBlueprint: function() { + _defaultBlueprint: function () { if (this.project.isEmberCLIAddon()) { return 'addon'; } else { @@ -34,7 +32,7 @@ module.exports = Command.extend({ } }, - run: function(commandOptions, rawArgs) { + run: function (commandOptions, rawArgs) { if (commandOptions.dryRun) { commandOptions.skipNpm = true; commandOptions.skipBower = true; @@ -71,13 +69,13 @@ module.exports = Command.extend({ }); } - var project = this.project; + var project = this.project; var packageName = commandOptions.name !== '.' && commandOptions.name || project.name(); if (!packageName) { var message = 'The `ng ' + this.name + '` command requires a ' + - 'package.json in current folder with name attribute or a specified name via arguments. ' + - 'For more details, use `ng help`.'; + 'package.json in current folder with name attribute or a specified name via arguments. ' + + 'For more details, use `ng help`.'; return Promise.reject(new SilentError(message)); } @@ -91,30 +89,31 @@ module.exports = Command.extend({ }; if (!validProjectName(packageName)) { - return Promise.reject(new SilentError('We currently do not support a name of `' + packageName + '`.')); + return Promise.reject( + new SilentError('We currently do not support a name of `' + packageName + '`.')); } blueprintOpts.blueprint = normalizeBlueprint(blueprintOpts.blueprint); return installBlueprint.run(blueprintOpts) - .then(function() { + .then(function () { if (commandOptions.skipGit === false) { return gitInit.run(commandOptions, rawArgs); } }.bind(this)) - .then(function() { + .then(function () { if (!commandOptions.skipNpm) { return npmInstall.run({ - verbose: commandOptions.verbose, - optional: false - }); + verbose: commandOptions.verbose, + optional: false + }); } }) - .then(function() { + .then(function () { if (!commandOptions.skipBower) { return bowerInstall.run({ - verbose: commandOptions.verbose - }); + verbose: commandOptions.verbose + }); } }); } diff --git a/addon/ng2/commands/lint.js b/addon/ng2/commands/lint.js index 459d3ec39fc9..f93c3cc5eab1 100644 --- a/addon/ng2/commands/lint.js +++ b/addon/ng2/commands/lint.js @@ -8,7 +8,7 @@ module.exports = Command.extend({ name: 'lint', description: 'Lints code in existing project', works: 'insideProject', - run: function() { + run: function () { var lintTask = new LintTask({ ui: this.ui, analytics: this.analytics, diff --git a/addon/ng2/commands/new.ts b/addon/ng2/commands/new.ts index f990f101295c..6e1d424bc200 100644 --- a/addon/ng2/commands/new.ts +++ b/addon/ng2/commands/new.ts @@ -8,73 +8,68 @@ const normalizeBlueprint = require('ember-cli/lib/utilities/normalize-blueprint- const InitCommand = require('./init'); const NewCommand = Command.extend({ - name: 'new', - description: `Creates a new directory and runs ${chalk.green('ng init')} in it.`, - works: 'outsideProject', + name: 'new', + description: `Creates a new directory and runs ${chalk.green('ng init')} in it.`, + works: 'outsideProject', - availableOptions: [ - { name: 'dry-run', type: Boolean, default: false, aliases: ['d'] }, - { name: 'verbose', type: Boolean, default: false, aliases: ['v'] }, - { name: 'blueprint', type: String, default: 'ng2', aliases: ['b'] }, - { name: 'skip-npm', type: Boolean, default: false, aliases: ['sn'] }, - { name: 'skip-bower', type: Boolean, default: true, aliases: ['sb'] }, - { name: 'skip-git', type: Boolean, default: false, aliases: ['sg'] }, - { name: 'directory', type: String , aliases: ['dir'] }, - ], + availableOptions: [ + { name: 'dry-run', type: Boolean, default: false, aliases: ['d'] }, + { name: 'verbose', type: Boolean, default: false, aliases: ['v'] }, + { name: 'blueprint', type: String, default: 'ng2', aliases: ['b'] }, + { name: 'skip-npm', type: Boolean, default: false, aliases: ['sn'] }, + { name: 'skip-bower', type: Boolean, default: true, aliases: ['sb'] }, + { name: 'skip-git', type: Boolean, default: false, aliases: ['sg'] }, + { name: 'directory', type: String, aliases: ['dir'] }, + ], - run: function(commandOptions, rawArgs) { - const packageName = rawArgs.shift(); + run: function (commandOptions, rawArgs) { + const packageName = rawArgs.shift(); - if (!packageName) { - return Promise.reject(new SilentError( - `The "ng ${this.name}" command requires a name argument to be specified. ` + - `For more details, use "ng help".` - )); - } + if (!packageName) { + return Promise.reject(new SilentError( + `The "ng ${this.name}" command requires a name argument to be specified. ` + + `For more details, use "ng help".`)); + } - commandOptions.name = packageName; - if (commandOptions.dryRun){ - commandOptions.skipGit = true; - } + commandOptions.name = packageName; + if (commandOptions.dryRun) { + commandOptions.skipGit = true; + } - if (packageName === '.') { - return Promise.reject(new SilentError( - `Trying to generate an application structure in this directory? Use "ng init" ` + - `instead.` - )); - } + if (packageName === '.') { + return Promise.reject(new SilentError( + `Trying to generate an application structure in this directory? Use "ng init" ` + + `instead.`)); + } - if (!validProjectName(packageName)) { - return Promise.reject(new SilentError( - `We currently do not support a name of "${packageName}".` - )); - } + if (!validProjectName(packageName)) { + return Promise.reject( + new SilentError(`We currently do not support a name of "${packageName}".`)); + } - commandOptions.blueprint = normalizeBlueprint(commandOptions.blueprint); + commandOptions.blueprint = normalizeBlueprint(commandOptions.blueprint); - if (!commandOptions.directory) { - commandOptions.directory = packageName; - } + if (!commandOptions.directory) { + commandOptions.directory = packageName; + } - const createAndStepIntoDirectory = new this.tasks.CreateAndStepIntoDirectory({ - ui: this.ui, - analytics: this.analytics - }); + const createAndStepIntoDirectory = + new this.tasks.CreateAndStepIntoDirectory({ ui: this.ui, analytics: this.analytics }); - const initCommand = new InitCommand({ - ui: this.ui, - analytics: this.analytics, - tasks: this.tasks, - project: Project.nullProject(this.ui, this.cli) - }); + const initCommand = new InitCommand({ + ui: this.ui, + analytics: this.analytics, + tasks: this.tasks, + project: Project.nullProject(this.ui, this.cli) + }); - return createAndStepIntoDirectory - .run({ - directoryName: commandOptions.directory, - dryRun: commandOptions.dryRun - }) - .then(initCommand.run.bind(initCommand, commandOptions, rawArgs)); - } + return createAndStepIntoDirectory + .run({ + directoryName: commandOptions.directory, + dryRun: commandOptions.dryRun + }) + .then(initCommand.run.bind(initCommand, commandOptions, rawArgs)); + } }); module.exports = NewCommand; diff --git a/addon/ng2/commands/test.js b/addon/ng2/commands/test.js index 80d9ebe1c328..44f0c2c0b42f 100644 --- a/addon/ng2/commands/test.js +++ b/addon/ng2/commands/test.js @@ -1,17 +1,8 @@ 'use strict'; -var chalk = require('chalk'); -var Command = require('ember-cli/lib/models/command'); -var Promise = require('ember-cli/lib/ext/promise'); -var Project = require('ember-cli/lib/models/project'); -var SilentError = require('silent-error'); -var validProjectName = require('ember-cli/lib/utilities/valid-project-name'); -var normalizeBlueprint = require('ember-cli/lib/utilities/normalize-blueprint-option'); - +var Promise = require('ember-cli/lib/ext/promise'); var TestCommand = require('ember-cli/lib/commands/test'); var win = require('ember-cli/lib/utilities/windows-admin'); -var path = require('path'); - var BuildTask = require('ember-cli/lib/tasks/build'); var BuildWatchTask = require('ember-cli/lib/tasks/build-watch'); var TestTask = require('../tasks/test'); @@ -24,15 +15,16 @@ module.exports = TestCommand.extend({ { name: 'colors', type: Boolean }, { name: 'log-level', type: String }, { name: 'port', type: Number }, - { name: 'reporters', type: String }, + { name: 'reporters', type: String } ], - run: function(commandOptions, rawArgs) { - var buildWatchTask = new BuildWatchTask({ - ui: this.ui, - analytics: this.analytics, - project: this.project - }); + run: function (commandOptions) { + var buildWatchTask = + new BuildWatchTask({ + ui: this.ui, + analytics: this.analytics, + project: this.project + }); var buildTask = new BuildTask({ ui: this.ui, analytics: this.analytics, @@ -48,27 +40,28 @@ module.exports = TestCommand.extend({ environment: 'development', outputPath: 'dist/' }; - - if (commandOptions.watch){ + + if (commandOptions.watch) { return win.checkWindowsElevation(this.ui) - .then(_ => { - // perform initial build to avoid race condition - return buildTask.run(buildOptions); - }, _ => { /* handle build error to allow watch mode to start */}) - .then(_ => { - return Promise.all([ - buildWatchTask.run(buildOptions), - testTask.run(commandOptions) - ]); + .then( + () => { + // perform initial build to avoid race condition + return buildTask.run(buildOptions); + }, + () => { + /* handle build error to allow watch mode to start */ + }) + .then(() => { + return Promise.all([buildWatchTask.run(buildOptions), testTask.run(commandOptions)]); }); } else { // if not watching ensure karma is doing a single run commandOptions.singleRun = true; return win.checkWindowsElevation(this.ui) - .then(_ => { + .then(() => { return buildTask.run(buildOptions); }) - .then(_ => { + .then(() => { return testTask.run(commandOptions); }); } @@ -76,4 +69,4 @@ module.exports = TestCommand.extend({ } }); -module.exports.overrideCore = true; \ No newline at end of file +module.exports.overrideCore = true; diff --git a/addon/ng2/commands/version.ts b/addon/ng2/commands/version.ts index 1ae03426e3cc..20989468b6b3 100644 --- a/addon/ng2/commands/version.ts +++ b/addon/ng2/commands/version.ts @@ -8,11 +8,12 @@ const VersionCommand = Command.extend({ aliases: ['v', '--version', '-v'], works: 'everywhere', - availableOptions: [ - { name: 'verbose', type: Boolean, 'default': false } - ], + availableOptions: [{ + name: 'verbose', + type: Boolean, 'default': false + }], - run: function(options) { + run: function (options) { var versions = process.versions; var pkg = require(path.resolve(__dirname, '..', '..', '..', 'package.json')); @@ -29,7 +30,7 @@ const VersionCommand = Command.extend({ } }, - printVersion: function(module, version) { + printVersion: function (module, version) { this.ui.writeLine(module + ': ' + version); } }); diff --git a/addon/ng2/index.js b/addon/ng2/index.js index b128441bf853..d18b3405f8e5 100644 --- a/addon/ng2/index.js +++ b/addon/ng2/index.js @@ -3,16 +3,16 @@ module.exports = { name: 'ng2', - includedCommands: function() { + includedCommands: function () { return { - 'new' : require('./commands/new'), - 'generate' : require('./commands/generate'), - 'init' : require('./commands/init'), - 'test' : require('./commands/test'), - 'e2e' : require('./commands/e2e'), - 'lint' : require('./commands/lint'), - 'format' : require('./commands/format'), - 'version' : require('./commands/version'), + 'new': require('./commands/new'), + 'generate': require('./commands/generate'), + 'init': require('./commands/init'), + 'test': require('./commands/test'), + 'e2e': require('./commands/e2e'), + 'lint': require('./commands/lint'), + 'format': require('./commands/format'), + 'version': require('./commands/version'), 'completion': require('./commands/completion') }; } diff --git a/addon/ng2/tasks/e2e.js b/addon/ng2/tasks/e2e.js index a78151b30172..11b57178109d 100644 --- a/addon/ng2/tasks/e2e.js +++ b/addon/ng2/tasks/e2e.js @@ -6,7 +6,7 @@ var Task = require('ember-cli/lib/models/task'); var exec = Promise.denodeify(require('shelljs').exec); module.exports = Task.extend({ - run: function() { + run: function () { return exec('npm run e2e'); } }); diff --git a/addon/ng2/tasks/format.js b/addon/ng2/tasks/format.js index 06dcbd07802e..a78e2a5d263e 100644 --- a/addon/ng2/tasks/format.js +++ b/addon/ng2/tasks/format.js @@ -6,18 +6,17 @@ var Task = require('ember-cli/lib/models/task'); var exec = Promise.denodeify(require('child_process').exec); module.exports = Task.extend({ - run: function() { + run: function () { var chalk = require('chalk'); var ui = this.ui; return exec('npm run format') - .then(function() { + .then(function () { ui.writeLine(chalk.green('Successfully formatted files.')); }) - .catch(function( /*error*/ ) { + .catch(function (/*error*/) { ui.writeLine(chalk.red( - 'Couldn\'t do \'npm run format\'. Please check this script exists in your package.json.' - )); + 'Couldn\'t do \'npm run format\'. Please check this script exists in your package.json.')); }); } }); diff --git a/addon/ng2/tasks/git-init.js b/addon/ng2/tasks/git-init.js index 4f1c7dfa44e3..57094373227d 100644 --- a/addon/ng2/tasks/git-init.js +++ b/addon/ng2/tasks/git-init.js @@ -1,42 +1,51 @@ 'use strict'; -var Promise = require('ember-cli/lib/ext/promise'); -var exec = Promise.denodeify(require('child_process').exec); -var path = require('path'); -var pkg = require('../package.json'); -var fs = require('fs'); +var Promise = require('ember-cli/lib/ext/promise'); +var exec = Promise.denodeify(require('child_process').exec); +var path = require('path'); +var pkg = require('../package.json'); +var fs = require('fs'); var template = require('lodash/template'); -var Task = require('ember-cli/lib/models/task'); +var Task = require('ember-cli/lib/models/task'); var gitEnvironmentVariables = { GIT_AUTHOR_NAME: 'angular-cli', GIT_AUTHOR_EMAIL: 'angular-cli@angular.io', - get GIT_COMMITTER_NAME(){ return this.GIT_AUTHOR_NAME; }, - get GIT_COMMITTER_EMAIL(){ return this.GIT_AUTHOR_EMAIL; } + get GIT_COMMITTER_NAME() { + return this.GIT_AUTHOR_NAME; + }, + get GIT_COMMITTER_EMAIL() { + return this.GIT_AUTHOR_EMAIL; + } }; module.exports = Task.extend({ - run: function(commandOptions) { - var chalk = require('chalk'); - var ui = this.ui; + run: function (commandOptions) { + var chalk = require('chalk'); + var ui = this.ui; - if(commandOptions.skipGit) { return Promise.resolve(); } + if (commandOptions.skipGit) { + return Promise.resolve(); + } return exec('git --version') - .then(function() { + .then(function () { return exec('git init') - .then(function() { + .then(function () { return exec('git add .'); }) - .then(function(){ - var commitTemplate = fs.readFileSync(path.join(__dirname, '../utilities/INITIAL_COMMIT_MESSAGE.txt')); + .then(function () { + var commitTemplate = fs.readFileSync( + path.join(__dirname, '../utilities/INITIAL_COMMIT_MESSAGE.txt')); var commitMessage = template(commitTemplate)(pkg); - return exec('git commit -m "' + commitMessage + '"', {env: gitEnvironmentVariables}); + return exec( + 'git commit -m "' + commitMessage + '"', { env: gitEnvironmentVariables }); }) - .then(function(){ + .then(function () { ui.writeLine(chalk.green('Successfully initialized git.')); }); - }).catch(function(/*error*/){ + }) + .catch(function (/*error*/) { // if git is not found or an error was thrown during the `git` // init process just swallow any errors here }); diff --git a/addon/ng2/tasks/lint.js b/addon/ng2/tasks/lint.js index bd24dcb438ea..4351c1f693a0 100644 --- a/addon/ng2/tasks/lint.js +++ b/addon/ng2/tasks/lint.js @@ -6,18 +6,17 @@ var Task = require('ember-cli/lib/models/task'); var exec = Promise.denodeify(require('child_process').exec); module.exports = Task.extend({ - run: function() { + run: function () { var chalk = require('chalk'); var ui = this.ui; return exec('npm run lint') - .then(function() { + .then(function () { ui.writeLine(chalk.green('Successfully linted files.')); }) - .catch(function( /*error*/ ) { + .catch(function (/*error*/) { ui.writeLine(chalk.red( - 'Couldn\'t do \'npm run lint\'. Please check this script exists in your package.json.' - )); + 'Couldn\'t do \'npm run lint\'. Please check this script exists in your package.json.')); }); } }); diff --git a/addon/ng2/tasks/test.js b/addon/ng2/tasks/test.js index 278a0924efcf..c5d99c19f1c1 100644 --- a/addon/ng2/tasks/test.js +++ b/addon/ng2/tasks/test.js @@ -13,10 +13,10 @@ function requireDependency(root, moduleName) { } module.exports = Task.extend({ - + run: function (options) { var projectRoot = this.project.root; - return new Promise(function (resolve, reject) { + return new Promise(function (resolve) { var karma = requireDependency(projectRoot, 'karma'); var karmaConfig = path.join(projectRoot, 'karma.conf'); diff --git a/addon/ng2/utilities/dynamic-path-parser.js b/addon/ng2/utilities/dynamic-path-parser.js index a0effe7731b2..d78ff23cea4d 100644 --- a/addon/ng2/utilities/dynamic-path-parser.js +++ b/addon/ng2/utilities/dynamic-path-parser.js @@ -4,7 +4,7 @@ var process = require('process'); module.exports = function dynamicPathParser(project, entityName) { var projectRoot = project.root; var cwd = process.env.PWD; - + var rootPath = path.join(projectRoot, 'src', 'app'); var outputPath = path.join(rootPath, entityName); @@ -13,8 +13,7 @@ module.exports = function dynamicPathParser(project, entityName) { outputPath = path.join(rootPath, entityName.substr(1)); } else if (cwd.indexOf(rootPath) >= 0) { outputPath = path.join(cwd, entityName); - } else if (cwd.indexOf(path.join(projectRoot, 'src')) >= 0 - && entityName.indexOf('app') === 0) { + } else if (cwd.indexOf(path.join(projectRoot, 'src')) >= 0 && entityName.indexOf('app') === 0) { outputPath = path.join(cwd, entityName); } else if (cwd.indexOf(path.join(projectRoot, 'src')) >= 0) { outputPath = path.join(cwd, 'app', entityName); @@ -22,14 +21,14 @@ module.exports = function dynamicPathParser(project, entityName) { if (outputPath.indexOf(rootPath) < 0) { throw `Invalid path: "${entityName}" cannot be ` + - `above the "${path.join('src', 'app')}" directory`; + `above the "${path.join('src', 'app')}" directory`; } var adjustedPath = outputPath.replace(rootPath, ''); var parsedPath = path.parse(adjustedPath); - + parsedPath.dir = parsedPath.dir === path.sep ? '' : parsedPath.dir; - + return parsedPath; -} \ No newline at end of file +}; \ No newline at end of file diff --git a/bin/ng b/bin/ng index b852883ea26d..9b2c78afd776 100755 --- a/bin/ng +++ b/bin/ng @@ -4,50 +4,50 @@ // Provide a title to the process in `ps` process.title = 'angular-cli'; -const path = require('path'); -const resolve = require('resolve'); -const exit = require('exit'); +const resolve = require('resolve'); +const exit = require('exit'); const packageJson = require('../package.json'); -const Leek = require('leek'); -const fs = require('fs'); - - -resolve('angular-cli', { - basedir: process.cwd() -}, function(error, projectLocalCli) { - var cli; - if (error) { - // If there is an error, resolve could not find the ember-cli - // library from a package.json. Instead, include it from a relative - // path to this script file (which is likely a globally installed - // npm package). Most common cause for hitting this is `ember new` - cli = require('../lib/cli'); - } else { - // No error implies a projectLocalCli, which will load whatever - // version of ember-cli you have installed in a local package.json - cli = require(projectLocalCli); - } - - if ('default' in cli) { - cli = cli['default']; - } - - cli({ - cliArgs: process.argv.slice(2), - inputStream: process.stdin, - outputStream: process.stdout, - Leek: CustomLeek - }).then(function(result) { - var exitCode = typeof result === 'object' ? result.exitCode : result; - exit(exitCode); +const Leek = require('leek'); +const fs = require('fs'); + +resolve('angular-cli', { basedir: process.cwd() }, + function (error, projectLocalCli) { + var cli; + if (error) { + // If there is an error, resolve could not find the ember-cli + // library from a package.json. Instead, include it from a relative + // path to this script file (which is likely a globally installed + // npm package). Most common cause for hitting this is `ember new` + cli = require('../lib/cli'); + } else { + // No error implies a projectLocalCli, which will load whatever + // version of ember-cli you have installed in a local package.json + cli = require(projectLocalCli); + } + + if ('default' in cli) { + cli = cli['default']; + } + + if ('default' in cli) { + cli = cli['default']; + } + + cli({ + cliArgs: process.argv.slice(2), + inputStream: process.stdin, + outputStream: process.stdout, + Leek: CustomLeek + }).then(function (result) { + var exitCode = typeof result === 'object' ? result.exitCode : result; + exit(exitCode); + }); + + function CustomLeek(options) { + options.trackingCode = packageJson.trackingCode; + options.globalName = packageJson.name; + options.name = packageJson.name; + options.version = packageJson.version; + return new Leek(options); + } }); -}); - - -function CustomLeek(options) { - options.trackingCode = packageJson.trackingCode; - options.globalName = packageJson.name; - options.name = packageJson.name; - options.version = packageJson.version; - return new Leek(options); -} diff --git a/eslint.json b/eslint.json new file mode 100644 index 000000000000..a1cb5d9c0f92 --- /dev/null +++ b/eslint.json @@ -0,0 +1,220 @@ +{ + "parser": "espree", + "ecmaFeatures": {}, + "rules": { + "no-alert": "off", + "no-array-constructor": "off", + "no-bitwise": "off", + "no-caller": "off", + "no-case-declarations": "error", + "no-catch-shadow": "off", + "no-class-assign": "error", + "no-cond-assign": "error", + "no-confusing-arrow": "off", + "no-console": "error", + "no-const-assign": "error", + "no-constant-condition": "error", + "no-continue": "off", + "no-control-regex": "error", + "no-debugger": "error", + "no-delete-var": "error", + "no-div-regex": "off", + "no-dupe-class-members": "error", + "no-dupe-keys": "error", + "no-dupe-args": "error", + "no-duplicate-case": "error", + "no-duplicate-imports": "off", + "no-else-return": "off", + "no-empty": "error", + "no-empty-character-class": "error", + "no-empty-function": "off", + "no-empty-pattern": "error", + "no-eq-null": "off", + "no-eval": "off", + "no-ex-assign": "error", + "no-extend-native": "off", + "no-extra-bind": "off", + "no-extra-boolean-cast": "error", + "no-extra-label": "off", + "no-extra-parens": "off", + "no-extra-semi": "error", + "no-fallthrough": "error", + "no-floating-decimal": "off", + "no-func-assign": "error", + "no-implicit-coercion": "off", + "no-implicit-globals": "off", + "no-implied-eval": "off", + "no-inline-comments": "off", + "no-inner-declarations": "error", + "no-invalid-regexp": "error", + "no-invalid-this": "off", + "no-irregular-whitespace": "error", + "no-iterator": "off", + "no-label-var": "off", + "no-labels": "off", + "no-lone-blocks": "off", + "no-lonely-if": "off", + "no-loop-func": "off", + "no-mixed-requires": "off", + "no-mixed-spaces-and-tabs": "error", + "linebreak-style": "off", + "no-multi-spaces": "off", + "no-multi-str": "off", + "no-multiple-empty-lines": "off", + "no-native-reassign": "off", + "no-negated-condition": "off", + "no-negated-in-lhs": "error", + "no-nested-ternary": "off", + "no-new": "off", + "no-new-func": "off", + "no-new-object": "off", + "no-new-require": "off", + "no-new-symbol": "error", + "no-new-wrappers": "off", + "no-obj-calls": "error", + "no-octal": "error", + "no-octal-escape": "off", + "no-param-reassign": "off", + "no-path-concat": "off", + "no-plusplus": "off", + "no-process-env": "off", + "no-process-exit": "off", + "no-proto": "off", + "no-redeclare": "error", + "no-regex-spaces": "error", + "no-restricted-globals": "off", + "no-restricted-imports": "off", + "no-restricted-modules": "off", + "no-restricted-syntax": "off", + "no-return-assign": "off", + "no-script-url": "off", + "no-self-assign": "error", + "no-self-compare": "off", + "no-sequences": "off", + "no-shadow": "off", + "no-shadow-restricted-names": "off", + "no-whitespace-before-property": "off", + "no-spaced-func": "off", + "no-sparse-arrays": "error", + "no-sync": "off", + "no-ternary": "off", + "no-trailing-spaces": "off", + "no-this-before-super": "error", + "no-throw-literal": "off", + "no-undef": "error", + "no-undef-init": "off", + "no-undefined": "off", + "no-unexpected-multiline": "error", + "no-underscore-dangle": "off", + "no-unmodified-loop-condition": "off", + "no-unneeded-ternary": "off", + "no-unreachable": "error", + "no-unused-expressions": "off", + "no-unused-labels": "error", + "no-unused-vars": "error", + "no-use-before-define": "off", + "no-useless-call": "off", + "no-useless-concat": "off", + "no-useless-constructor": "off", + "no-void": "off", + "no-var": "off", + "no-warning-comments": "off", + "no-with": "off", + "no-magic-numbers": "off", + "array-bracket-spacing": "off", + "array-callback-return": "off", + "arrow-body-style": "off", + "arrow-parens": "off", + "arrow-spacing": "off", + "accessor-pairs": "off", + "block-scoped-var": "off", + "block-spacing": "off", + "brace-style": [2, "1tbs", { "allowSingleLine": false }], + "callback-return": "off", + "camelcase": "off", + "comma-dangle": "error", + "comma-spacing": "off", + "comma-style": "off", + "complexity": ["off", 11], + "computed-property-spacing": "off", + "consistent-return": "off", + "consistent-this": "off", + "constructor-super": "error", + "curly": "off", + "default-case": "off", + "dot-location": "off", + "dot-notation": "off", + "eol-last": "off", + "eqeqeq": "off", + "func-names": "off", + "func-style": "off", + "generator-star-spacing": "off", + "global-require": "off", + "guard-for-in": "off", + "handle-callback-err": "off", + "id-length": "off", + "indent": [2,2], + "init-declarations": "off", + "jsx-quotes": "off", + "key-spacing": [2, { + "multiLine": { + "beforeColon": false, + "afterColon": true, + "mode": "minimum" + } + }], + "keyword-spacing": "off", + "lines-around-comment": "off", + "max-depth": "off", + "max-len": "off", + "max-nested-callbacks": "off", + "max-params": "off", + "max-statements": "off", + "max-statements-per-line": "off", + "new-cap": "off", + "new-parens": "off", + "newline-after-var": "off", + "newline-before-return": "off", + "newline-per-chained-call": "off", + "object-curly-spacing": [2, "always"], + "object-shorthand": "off", + "one-var": "off", + "one-var-declaration-per-line": "off", + "operator-assignment": "off", + "operator-linebreak": "off", + "padded-blocks": "off", + "prefer-arrow-callback": "off", + "prefer-const": "off", + "prefer-reflect": "off", + "prefer-rest-params": "off", + "prefer-spread": "off", + "prefer-template": "off", + "quote-props": "off", + "quotes": [2, "single"], + "radix": "off", + "id-match": "off", + "id-blacklist": "off", + "require-jsdoc": "off", + "require-yield": "off", + "semi": "off", + "semi-spacing": "off", + "sort-vars": "off", + "sort-imports": "off", + "space-before-blocks": "off", + "space-before-function-paren": "off", + "space-in-parens": "off", + "space-infix-ops": "off", + "space-unary-ops": "off", + "spaced-comment": "off", + "strict": "off", + "template-curly-spacing": "off", + "use-isnan": "error", + "valid-jsdoc": "off", + "valid-typeof": "error", + "vars-on-top": "off", + "wrap-iife": "off", + "wrap-regex": "off", + "yield-star-spacing": "off", + "yoda": "off" + } +} diff --git a/index.js b/index.js index d1d0c8b6a8c9..71d781c53b48 100644 --- a/index.js +++ b/index.js @@ -2,5 +2,5 @@ 'use strict'; module.exports = { - name: 'ng' -}; \ No newline at end of file + name: 'ng' +}; diff --git a/lib/broccoli/angular2-app.js b/lib/broccoli/angular2-app.js index 57f560773c5e..6b02cd3a468c 100644 --- a/lib/broccoli/angular2-app.js +++ b/lib/broccoli/angular2-app.js @@ -1,5 +1,4 @@ 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; @@ -11,98 +10,98 @@ var Project = require('ember-cli/lib/models/project'); module.exports = Angular2App; function Angular2App(defaults, options) { - this._initProject(); - this._notifyAddonIncluded(); - this.options = options; + this._initProject(); + this._notifyAddonIncluded(); + this.options = options; } -Angular2App.prototype.toTree = function() { - var sourceDir = 'src'; - - var sourceTree = new Funnel('src', { - include: ['*.ts', '**/*.ts', '**/*.d.ts'], - destDir: 'src' - }); - - var typingsTree = new Funnel('typings', { - include: ['browser.d.ts', 'browser/**'], - destDir: 'typings' - }); - - 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); +Angular2App.prototype.toTree = function () { + var sourceDir = 'src'; + + var sourceTree = new Funnel('src', { + include: ['*.ts', '**/*.ts', '**/*.d.ts'], + destDir: 'src' + }); + + var typingsTree = new Funnel('typings', { + include: ['browser.d.ts', 'browser/**'], + destDir: 'typings' + }); + + 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 tsconfig = JSON.parse(fs.readFileSync('src/tsconfig.json', 'utf-8')); + // Add all spec files to files. We need this because spec files are their own entry + // point. + fs.readdirSync(sourceDir).forEach(function addPathRecursive(name) { + const filePath = path.join(sourceDir, name); + if (filePath.match(/\.spec\.[jt]s$/)) { + tsconfig.files.push(name); + } else if (fs.statSync(filePath).isDirectory()) { + // Recursively call this function with the full sub-path. + fs.readdirSync(filePath).forEach(function (n) { + addPathRecursive(path.join(name, n)); + }); } - - var tsconfig = JSON.parse(fs.readFileSync('src/tsconfig.json', 'utf-8')); - // Add all spec files to files. We need this because spec files are their own entry - // point. - fs.readdirSync(sourceDir).forEach(function addPathRecursive(name) { - const filePath = path.join(sourceDir, name); - if (filePath.match(/\.spec\.[jt]s$/)) { - tsconfig.files.push(name); - } else if (fs.statSync(filePath).isDirectory()) { - // Recursively call this function with the full sub-path. - fs.readdirSync(filePath).forEach(function(n) { - addPathRecursive(path.join(name, n)); - }); - } - }); - - // Because the tsconfig does not include the source directory, add this as the first path - // element. - tsconfig.files = tsconfig.files.map(name => path.join(sourceDir, name)); - - var srcAndTypingsTree = mergeTrees([sourceTree, typingsTree]); - var tsTree = new compileWithTypescript(srcAndTypingsTree, tsconfig); - - tsTree = new Funnel(tsTree, { - srcDir: 'src', - exclude: ['*.d.ts', 'tsconfig.json'] - }); - - var tsSrcTree = new Funnel(sourceDir, { - include: ['**/*.ts'], - allowEmpty: true - }); - - var jsTree = new Funnel(sourceDir, { - include: ['**/*.js'], - allowEmpty: true - }); - - var assetTree = new Funnel(sourceDir, { - include: ['**/*.*'], - exclude: ['**/*.ts', '**/*.js'], - allowEmpty: true - }); - - var vendorNpmTree = new Funnel('node_modules', { - include: vendorNpmFiles, - destDir: 'vendor' - }); - - var merged = mergeTrees([ - assetTree, - tsSrcTree, - tsTree, - jsTree, - this.index(), - vendorNpmTree, - ], { overwrite: true }); - - return mergeTrees([merged, new SwManifest([merged])]); + }); + + // Because the tsconfig does not include the source directory, add this as the first path + // element. + tsconfig.files = tsconfig.files.map(name => path.join(sourceDir, name)); + + var srcAndTypingsTree = mergeTrees([sourceTree, typingsTree]); + var tsTree = new compileWithTypescript(srcAndTypingsTree, tsconfig); + + tsTree = new Funnel(tsTree, { + srcDir: 'src', + exclude: ['*.d.ts', 'tsconfig.json'] + }); + + var tsSrcTree = new Funnel(sourceDir, { + include: ['**/*.ts'], + allowEmpty: true + }); + + var jsTree = new Funnel(sourceDir, { + include: ['**/*.js'], + allowEmpty: true + }); + + var assetTree = new Funnel(sourceDir, { + include: ['**/*.*'], + exclude: ['**/*.ts', '**/*.js'], + allowEmpty: true + }); + + var vendorNpmTree = new Funnel('node_modules', { + include: vendorNpmFiles, + destDir: 'vendor' + }); + + var merged = mergeTrees([ + assetTree, + tsSrcTree, + tsTree, + jsTree, + this.index(), + vendorNpmTree + ], { overwrite: true }); + + return mergeTrees([merged, new SwManifest([merged])]); }; /** @@ -110,31 +109,31 @@ Angular2App.prototype.toTree = function() { @method _initProject @param {Object} options */ -Angular2App.prototype._initProject = function() { - this.project = Project.closestSync(process.cwd()); +Angular2App.prototype._initProject = function () { + this.project = Project.closestSync(process.cwd()); - /*if (options.configPath) { - this.project.configPath = function() { return options.configPath; }; - }*/ + /*if (options.configPath) { + this.project.configPath = function() { return options.configPath; }; + }*/ }; /** @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); +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); }; /** @@ -144,8 +143,8 @@ Angular2App.prototype._notifyAddonIncluded = function() { @private @method initializeAddons */ -Angular2App.prototype.initializeAddons = function() { - this.project.initializeAddons(); +Angular2App.prototype.initializeAddons = function () { + this.project.initializeAddons(); }; /** @@ -169,26 +168,26 @@ Angular2App.prototype.initializeAddons = function() { @param {String} type Type of content @return {String} The content. */ -Angular2App.prototype.contentFor = function(match, type) { - var content = []; - - /*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; - }*/ - - content = this.project.addons.reduce(function(content, addon) { - var addonContent = addon.contentFor ? addon.contentFor(type) : null; - if (addonContent) { - return content.concat(addonContent); - } +Angular2App.prototype.contentFor = function (match, type) { + var content = []; + + /*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; + }*/ + + content = this.project.addons.reduce(function (content, addon) { + var addonContent = addon.contentFor ? addon.contentFor(type) : null; + if (addonContent) { + return content.concat(addonContent); + } - return content; - }, content); + return content; + }, content); - return content.join('\n'); + return content.join('\n'); }; /** @@ -196,17 +195,11 @@ Angular2App.prototype.contentFor = function(match, type) { @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 - }*/]; +Angular2App.prototype._configReplacePatterns = function () { + return [{ + match: /\{\{content-for ['"](.+)["']\}\}/g, + replacement: this.contentFor.bind(this) + }]; }; @@ -217,20 +210,20 @@ Angular2App.prototype._configReplacePatterns = function() { @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() - }); +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() + }); }; diff --git a/lib/broccoli/broccoli-config-replace.js b/lib/broccoli/broccoli-config-replace.js index ae5450d209e7..c9892c9b672e 100644 --- a/lib/broccoli/broccoli-config-replace.js +++ b/lib/broccoli/broccoli-config-replace.js @@ -4,68 +4,68 @@ var fs = require('fs-extra'); var path = require('path'); var Writer = require('broccoli-writer'); -function CustomReplace (inputTree, options) { - if (!(this instanceof CustomReplace)) { - return new CustomReplace(inputTree, options); - } +function CustomReplace(inputTree, options) { + if (!(this instanceof CustomReplace)) { + return new CustomReplace(inputTree, options); + } - Writer.call(this, inputTree, options); // this._super(); + Writer.call(this, inputTree, options); // this._super(); - this.inputTree = inputTree; - this.options = options; + this.inputTree = inputTree; + this.options = options; } CustomReplace.prototype = Object.create(Writer.prototype); CustomReplace.prototype.constructor = CustomReplace; CustomReplace.prototype.write = function (readTree, destDir) { - var inputDir; - - return readTree(this.inputTree) - .then(function(path) { - inputDir = path; - - return { - inputDir: inputDir, - destDir: destDir - }; - }) - .then(this.process.bind(this)); + var inputDir; + + return readTree(this.inputTree) + .then(function (path) { + inputDir = path; + + return { + inputDir: inputDir, + destDir: destDir + }; + }) + .then(this.process.bind(this)); }; -CustomReplace.prototype.process = function(results) { - var files = this.options.files; +CustomReplace.prototype.process = function (results) { + var files = this.options.files; - for (var i = 0, l = files.length; i < l; i++) { - var file = files[i]; - var filePath = path.join(results.inputDir, file); - var destPath = path.join(results.destDir, file); + for (var i = 0, l = files.length; i < l; i++) { + var file = files[i]; + var filePath = path.join(results.inputDir, file); + var destPath = path.join(results.destDir, file); - this.processFile(filePath, destPath); - } + this.processFile(filePath, destPath); + } }; -CustomReplace.prototype.processFile = function(filePath, destPath) { - var contents = fs.readFileSync(filePath, { encoding: 'utf8' }); - - for (var i = 0, l = this.options.patterns.length; i < l; i++) { - // jshint loopfunc:true - var pattern = this.options.patterns[i]; - var replacement = pattern.replacement; +CustomReplace.prototype.processFile = function (filePath, destPath) { + var contents = fs.readFileSync(filePath, { encoding: 'utf8' }); - if (typeof pattern.replacement === 'function') { - replacement = function() { - var args = Array.prototype.slice.call(arguments); - return pattern.replacement.apply(null, args); - }; - } + for (var i = 0, l = this.options.patterns.length; i < l; i++) { + // jshint loopfunc:true + var pattern = this.options.patterns[i]; + var replacement = pattern.replacement; - contents = contents.replace(pattern.match, replacement); + if (typeof pattern.replacement === 'function') { + replacement = function () { + var args = Array.prototype.slice.call(arguments); + return pattern.replacement.apply(null, args); + }; } - if (!fs.existsSync(path.dirname(destPath))) { - fs.mkdirsSync(path.dirname(destPath)); - } - fs.writeFileSync(destPath, contents, { encoding: 'utf8' }); + contents = contents.replace(pattern.match, replacement); + } + + if (!fs.existsSync(path.dirname(destPath))) { + fs.mkdirsSync(path.dirname(destPath)); + } + fs.writeFileSync(destPath, contents, { encoding: 'utf8' }); }; module.exports = CustomReplace; diff --git a/lib/broccoli/broccoli-typescript.js b/lib/broccoli/broccoli-typescript.js index c48659ef0083..003fd2dcfc0d 100644 --- a/lib/broccoli/broccoli-typescript.js +++ b/lib/broccoli/broccoli-typescript.js @@ -1,12 +1,14 @@ +/*eslint-disable no-console */ + /// -"use strict"; +'use strict'; const Plugin = require('broccoli-caching-writer'); var fs = require('fs'); var fse = require('fs-extra'); var path = require('path'); var ts = require('typescript'); var FS_OPTS = { - encoding: 'utf-8' + encoding: 'utf-8' }; // Sub-directory where the @internal typing files (.d.ts) are stored exports.INTERNAL_TYPINGS_PATH = 'internal_typings'; @@ -14,16 +16,16 @@ exports.INTERNAL_TYPINGS_PATH = 'internal_typings'; var tsEmitInternal = false; var originalEmitFiles = ts.emitFiles; ts.emitFiles = function (resolver, host, targetSourceFile) { - if (tsEmitInternal) { - var orignalgetCompilerOptions_1 = host.getCompilerOptions; - host.getCompilerOptions = function () { - var options = clone(orignalgetCompilerOptions_1.call(host)); - options.stripInternal = false; - options.outDir = options.outDir + "/" + exports.INTERNAL_TYPINGS_PATH; - return options; - }; - } - return originalEmitFiles(resolver, host, targetSourceFile); + if (tsEmitInternal) { + var orignalgetCompilerOptions_1 = host.getCompilerOptions; + host.getCompilerOptions = function () { + var options = clone(orignalgetCompilerOptions_1.call(host)); + options.stripInternal = false; + options.outDir = options.outDir + '/' + exports.INTERNAL_TYPINGS_PATH; + return options; + }; + } + return originalEmitFiles(resolver, host, targetSourceFile); }; /** * Broccoli plugin that implements incremental Typescript compiler. @@ -36,315 +38,312 @@ ts.emitFiles = function (resolver, host, targetSourceFile) { * requires global emit, which can affect many files. */ class DiffingTSCompiler extends Plugin { - constructor(inputPath, options) { - super([inputPath], {}); + constructor(inputPath, options) { + super([inputPath], {}); - this.options = options; - this.fileRegistry = Object.create(null); - this.firstRun = true; - this.previousRunFailed = false; - // Whether to generate the @internal typing files (they are only generated when `stripInternal` is - // true) - this.genInternalTypings = false; - if (options.files) { - this.rootFilePaths = options.files.splice(0); - } - else { - this.rootFilePaths = []; - } - if (options.internalTypings) { - this.genInternalTypings = true; - delete options.internalTypings; - } + this.options = options; + this.fileRegistry = Object.create(null); + this.firstRun = true; + this.previousRunFailed = false; + // Whether to generate the @internal typing files (they are only generated when `stripInternal` is + // true) + this.genInternalTypings = false; + if (options.files) { + this.rootFilePaths = options.files.splice(0); + } else { + this.rootFilePaths = []; } + if (options.internalTypings) { + this.genInternalTypings = true; + delete options.internalTypings; + } + } - createServiceHost() { - // the conversion is a bit awkward, see https://github.com/Microsoft/TypeScript/issues/5276 - // in 1.8 use convertCompilerOptionsFromJson - this.tsOpts = ts.parseJsonConfigFileContent(this.options, null, null).options; - if (this.tsOpts.stripInternal === false) { - // @internal are included in the generated .d.ts, do not generate them separately - this.genInternalTypings = false; - } - this.tsOpts.rootDir = ''; - this.tsOpts.outDir = ''; - - this.tsServiceHost = new CustomLanguageServiceHost( - this.tsOpts, this.rootFilePaths, this.fileRegistry, this.inputPaths[0]); - this.tsService = ts.createLanguageService(this.tsServiceHost, ts.createDocumentRegistry()); + createServiceHost() { + // the conversion is a bit awkward, see https://github.com/Microsoft/TypeScript/issues/5276 + // in 1.8 use convertCompilerOptionsFromJson + this.tsOpts = ts.parseJsonConfigFileContent(this.options, null, null).options; + if (this.tsOpts.stripInternal === false) { + // @internal are included in the generated .d.ts, do not generate them separately + this.genInternalTypings = false; } + this.tsOpts.rootDir = ''; + this.tsOpts.outDir = ''; - build() { - if (!this.tsServiceHost) { - this.createServiceHost(); - this.doFullBuild(); - return; - } + this.tsServiceHost = new CustomLanguageServiceHost( + this.tsOpts, this.rootFilePaths, this.fileRegistry, this.inputPaths[0]); + this.tsService = ts.createLanguageService(this.tsServiceHost, ts.createDocumentRegistry()); + } - var _this = this; - var pathsWithErrors = []; - var errorMessages = []; - var pathsEmitted = []; - var entries = this.listEntries(); + build() { + if (!this.tsServiceHost) { + this.createServiceHost(); + this.doFullBuild(); + return; + } - entries.forEach(function(entry) { - const tsFilePath = path.join(_this.inputPaths[0], entry.relativePath); - // const entry = entries.filter(e => e.relativePath == tsFilePath)[0]; - if (!tsFilePath.match(/\.ts$/)) { - return; - } - if (!_this.fileRegistry[tsFilePath]) { - _this.fileRegistry[tsFilePath] = {version: entry.mtime}; - } else if (_this.fileRegistry[tsFilePath].version >= entry.mtime) { - // Nothing to do for this file. Just reoutput. - } else { - _this.fileRegistry[tsFilePath].version = entry.mtime; - } - pathsEmitted.push(tsFilePath); + var _this = this; + var pathsWithErrors = []; + var errorMessages = []; + var pathsEmitted = []; + var entries = this.listEntries(); - var output = _this.tsService.getEmitOutput(tsFilePath); - if (output.emitSkipped) { - var errorFound = _this.collectErrors(tsFilePath); - if (errorFound) { - pathsWithErrors.push(tsFilePath); - errorMessages.push(errorFound); - } - } - else { - output.outputFiles.forEach(function (o) { - var filePath = o.name; - if (path.isAbsolute(filePath)) { - filePath = filePath.replace(_this.inputPaths[0], _this.outputPath); - } else { - filePath = path.join(_this.outputPath, filePath); - } - var destDirPath = path.dirname(filePath); - fse.mkdirsSync(destDirPath); - fs.writeFileSync(filePath, _this.fixSourceMapSources(o.text), FS_OPTS); - }); - } - }); + entries.forEach(function (entry) { + const tsFilePath = path.join(_this.inputPaths[0], entry.relativePath); + // const entry = entries.filter(e => e.relativePath == tsFilePath)[0]; + if (!tsFilePath.match(/\.ts$/)) { + return; + } + if (!_this.fileRegistry[tsFilePath]) { + _this.fileRegistry[tsFilePath] = { version: entry.mtime }; + } else if (_this.fileRegistry[tsFilePath].version >= entry.mtime) { + // Nothing to do for this file. Just reoutput. + } else { + _this.fileRegistry[tsFilePath].version = entry.mtime; + } + pathsEmitted.push(tsFilePath); - if (pathsWithErrors.length) { - this.previousRunFailed = true; - var error = new Error('Typescript found the following errors:\n' + errorMessages.join('\n')); - error['showStack'] = false; - throw error; + var output = _this.tsService.getEmitOutput(tsFilePath); + if (output.emitSkipped) { + var errorFound = _this.collectErrors(tsFilePath); + if (errorFound) { + pathsWithErrors.push(tsFilePath); + errorMessages.push(errorFound); } - else if (this.previousRunFailed) { - this.doFullBuild(); - } - else if (this.genInternalTypings) { - // serialize the .d.ts files containing @internal symbols - tsEmitInternal = true; - pathsEmitted.forEach(function (tsFilePath) { - var output = _this.tsService.getEmitOutput(tsFilePath); - if (!output.emitSkipped) { - output.outputFiles.forEach(function (o) { - var filePath = o.name; - if (path.isAbsolute(filePath)) { - filePath = filePath.replace(_this.inputPaths[0], _this.outputPath); - } else { - filePath = path.join(_this.outputPath, filePath); - } - console.log(4, filePath) - if (endsWith(filePath, '.d.ts')) { - var destDirPath = path.dirname(filePath); - fse.mkdirsSync(destDirPath); - fs.writeFileSync(filePath, _this.fixSourceMapSources(o.text), FS_OPTS); - } - }); - } - }); - tsEmitInternal = false; - } - } + } else { + output.outputFiles.forEach(function (o) { + var filePath = o.name; + if (path.isAbsolute(filePath)) { + filePath = filePath.replace(_this.inputPaths[0], _this.outputPath); + } else { + filePath = path.join(_this.outputPath, filePath); + } + var destDirPath = path.dirname(filePath); + fse.mkdirsSync(destDirPath); + fs.writeFileSync(filePath, _this.fixSourceMapSources(o.text), FS_OPTS); + }); + } + }); - collectErrors(tsFilePath) { - var allDiagnostics = this.tsService.getCompilerOptionsDiagnostics() - .concat(this.tsService.getSyntacticDiagnostics(tsFilePath)) - .concat(this.tsService.getSemanticDiagnostics(tsFilePath)); - var errors = []; - allDiagnostics.forEach(function (diagnostic) { - var message = ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n"); - if (diagnostic.file) { - var _a = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start), line = _a.line, character = _a.character; - errors.push(" " + diagnostic.file.fileName + " (" + (line + 1) + "," + (character + 1) + "): " + message); + if (pathsWithErrors.length) { + this.previousRunFailed = true; + var error = new Error('Typescript found the following errors:\n' + errorMessages.join('\n')); + error['showStack'] = false; + throw error; + } else if (this.previousRunFailed) { + this.doFullBuild(); + } else if (this.genInternalTypings) { + // serialize the .d.ts files containing @internal symbols + tsEmitInternal = true; + pathsEmitted.forEach(function (tsFilePath) { + var output = _this.tsService.getEmitOutput(tsFilePath); + if (!output.emitSkipped) { + output.outputFiles.forEach(function (o) { + var filePath = o.name; + if (path.isAbsolute(filePath)) { + filePath = filePath.replace(_this.inputPaths[0], _this.outputPath); + } else { + filePath = path.join(_this.outputPath, filePath); } - else { - errors.push(" Error: " + message); + console.log(4, filePath); + if (endsWith(filePath, '.d.ts')) { + var destDirPath = path.dirname(filePath); + fse.mkdirsSync(destDirPath); + fs.writeFileSync(filePath, _this.fixSourceMapSources(o.text), FS_OPTS); } - }); - if (errors.length) { - return errors.join('\n'); + }); } + }); + tsEmitInternal = false; } + } - doFullBuild() { - var _this = this; - var program = this.tsService.getProgram(); - tsEmitInternal = false; - var emitResult = program.emit(undefined, (absoluteFilePath, fileContent) => { - absoluteFilePath = path.resolve(this.outputPath, absoluteFilePath); - // Replace the input path by the output. - absoluteFilePath = absoluteFilePath.replace(this.inputPaths[0], this.outputPath); - fse.mkdirsSync(path.dirname(absoluteFilePath)); - fs.writeFileSync(absoluteFilePath, _this.fixSourceMapSources(fileContent), FS_OPTS); - }); - if (this.genInternalTypings) { - // serialize the .d.ts files containing @internal symbols - tsEmitInternal = true; - program.emit(undefined, function (absoluteFilePath, fileContent) { - absoluteFilePath = path.resolve(this.outputPath, absoluteFilePath); - // Replace the input path by the output. - absoluteFilePath = absoluteFilePath.replace(this.inputPaths[0], this.outputPath); - if (endsWith(absoluteFilePath, '.d.ts')) { - fse.mkdirsSync(path.dirname(absoluteFilePath)); - fs.writeFileSync(absoluteFilePath, fileContent, FS_OPTS); - } - }); - tsEmitInternal = false; - } - if (emitResult.emitSkipped) { - var allDiagnostics = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics); - var errorMessages_1 = []; - allDiagnostics.forEach(function (diagnostic) { - var pos = ''; - if (diagnostic.file) { - var _a = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start), line = _a.line, character = _a.character; - pos = diagnostic.file.fileName + " (" + (line + 1) + ", " + (character + 1) + "): "; - } - var message = ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n'); - errorMessages_1.push(" " + pos + message); - }); - if (errorMessages_1.length) { - this.previousRunFailed = true; - var error = new Error('Typescript found the following errors:\n' + errorMessages_1.join('\n')); - error['showStack'] = false; - throw error; - } - else { - this.previousRunFailed = false; - } - } + collectErrors(tsFilePath) { + var allDiagnostics = this.tsService.getCompilerOptionsDiagnostics() + .concat(this.tsService.getSyntacticDiagnostics(tsFilePath)) + .concat(this.tsService.getSemanticDiagnostics(tsFilePath)); + var errors = []; + allDiagnostics.forEach(function (diagnostic) { + var message = ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n'); + if (diagnostic.file) { + var _a = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start), line = _a.line, character = _a.character; + errors.push(' ' + diagnostic.file.fileName + ' (' + (line + 1) + ',' + (character + 1) + '): ' + message); + } else { + errors.push(' Error: ' + message); + } + }); + if (errors.length) { + return errors.join('\n'); } + } - /** - * There is a bug in TypeScript 1.6, where the sourceRoot and inlineSourceMap properties - * are exclusive. This means that the sources property always contains relative paths - * (e.g, ../../../../angular2/src/di/injector.ts). - * - * Here, we normalize the sources property and remove the ../../../ - * - * This issue is fixed in https://github.com/Microsoft/TypeScript/pull/5620. - * Once we switch to TypeScript 1.8, we can remove this method. - */ - fixSourceMapSources(content) { - try { - var marker = "//# sourceMappingURL=data:application/json;base64,"; - var index = content.indexOf(marker); - if (index == -1) - return content; - var base = content.substring(0, index + marker.length); - var sourceMapBit = new Buffer(content.substring(index + marker.length), 'base64').toString("utf8"); - var sourceMaps = JSON.parse(sourceMapBit); - var source = sourceMaps.sources[0]; - sourceMaps.sources = [source.substring(source.lastIndexOf("../") + 3)]; - return "" + base + new Buffer(JSON.stringify(sourceMaps)).toString('base64'); + doFullBuild() { + var _this = this; + var program = this.tsService.getProgram(); + tsEmitInternal = false; + var emitResult = program.emit(undefined, (absoluteFilePath, fileContent) => { + absoluteFilePath = path.resolve(this.outputPath, absoluteFilePath); + // Replace the input path by the output. + absoluteFilePath = absoluteFilePath.replace(this.inputPaths[0], this.outputPath); + fse.mkdirsSync(path.dirname(absoluteFilePath)); + fs.writeFileSync(absoluteFilePath, _this.fixSourceMapSources(fileContent), FS_OPTS); + }); + if (this.genInternalTypings) { + // serialize the .d.ts files containing @internal symbols + tsEmitInternal = true; + program.emit(undefined, function (absoluteFilePath, fileContent) { + absoluteFilePath = path.resolve(this.outputPath, absoluteFilePath); + // Replace the input path by the output. + absoluteFilePath = absoluteFilePath.replace(this.inputPaths[0], this.outputPath); + if (endsWith(absoluteFilePath, '.d.ts')) { + fse.mkdirsSync(path.dirname(absoluteFilePath)); + fs.writeFileSync(absoluteFilePath, fileContent, FS_OPTS); } - catch (e) { - return content; + }); + tsEmitInternal = false; + } + if (emitResult.emitSkipped) { + var allDiagnostics = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics); + var errorMessages_1 = []; + allDiagnostics.forEach(function (diagnostic) { + var pos = ''; + if (diagnostic.file) { + var _a = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start), line = _a.line, character = _a.character; + pos = diagnostic.file.fileName + ' (' + (line + 1) + ', ' + (character + 1) + '): '; } + var message = ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n'); + errorMessages_1.push(' ' + pos + message); + }); + if (errorMessages_1.length) { + this.previousRunFailed = true; + var error = new Error('Typescript found the following errors:\n' + errorMessages_1.join('\n')); + error['showStack'] = false; + throw error; + } else { + this.previousRunFailed = false; + } } + } - removeOutputFor(tsFilePath) { - var absoluteJsFilePath = path.join(this.outputPath, tsFilePath.replace(/\.ts$/, '.js')); - var absoluteMapFilePath = path.join(this.outputPath, tsFilePath.replace(/.ts$/, '.js.map')); - var absoluteDtsFilePath = path.join(this.outputPath, tsFilePath.replace(/\.ts$/, '.d.ts')); - if (fs.existsSync(absoluteJsFilePath)) { - fs.unlinkSync(absoluteJsFilePath); - if (fs.existsSync(absoluteMapFilePath)) { - // source map could be inline or not generated - fs.unlinkSync(absoluteMapFilePath); - } - fs.unlinkSync(absoluteDtsFilePath); - } + /** + * There is a bug in TypeScript 1.6, where the sourceRoot and inlineSourceMap properties + * are exclusive. This means that the sources property always contains relative paths + * (e.g, ../../../../angular2/src/di/injector.ts). + * + * Here, we normalize the sources property and remove the ../../../ + * + * This issue is fixed in https://github.com/Microsoft/TypeScript/pull/5620. + * Once we switch to TypeScript 1.8, we can remove this method. + */ + fixSourceMapSources(content) { + try { + var marker = '//# sourceMappingURL=data:application/json;base64,'; + var index = content.indexOf(marker); + if (index == -1) + return content; + var base = content.substring(0, index + marker.length); + var sourceMapBit = new Buffer(content.substring(index + marker.length), 'base64').toString('utf8'); + var sourceMaps = JSON.parse(sourceMapBit); + var source = sourceMaps.sources[0]; + sourceMaps.sources = [source.substring(source.lastIndexOf('../') + 3)]; + return '' + base + new Buffer(JSON.stringify(sourceMaps)).toString('base64'); + } catch (e) { + return content; + } + } + + removeOutputFor(tsFilePath) { + var absoluteJsFilePath = path.join(this.outputPath, tsFilePath.replace(/\.ts$/, '.js')); + var absoluteMapFilePath = path.join(this.outputPath, tsFilePath.replace(/.ts$/, '.js.map')); + var absoluteDtsFilePath = path.join(this.outputPath, tsFilePath.replace(/\.ts$/, '.d.ts')); + if (fs.existsSync(absoluteJsFilePath)) { + fs.unlinkSync(absoluteJsFilePath); + if (fs.existsSync(absoluteMapFilePath)) { + // source map could be inline or not generated + fs.unlinkSync(absoluteMapFilePath); + } + fs.unlinkSync(absoluteDtsFilePath); } + } } var CustomLanguageServiceHost = (function () { - function CustomLanguageServiceHost(compilerOptions, fileNames, fileRegistry, treeInputPath) { - this.compilerOptions = compilerOptions; - this.fileNames = fileNames; - this.fileRegistry = fileRegistry; - this.treeInputPath = treeInputPath; - this.currentDirectory = treeInputPath; - this.defaultLibFilePath = ts.getDefaultLibFilePath(compilerOptions).replace(/\\/g, '/'); + function CustomLanguageServiceHost(compilerOptions, fileNames, fileRegistry, treeInputPath) { + this.compilerOptions = compilerOptions; + this.fileNames = fileNames; + this.fileRegistry = fileRegistry; + this.treeInputPath = treeInputPath; + this.currentDirectory = treeInputPath; + this.defaultLibFilePath = ts.getDefaultLibFilePath(compilerOptions).replace(/\\/g, '/'); + } + + CustomLanguageServiceHost.prototype.getScriptFileNames = function () { + return this.fileNames; + }; + CustomLanguageServiceHost.prototype.getScriptVersion = function (fileName) { + return this.fileRegistry[fileName] && this.fileRegistry[fileName].version.toString(); + }; + /** + * This method is called quite a bit to lookup 3 kinds of paths: + * 1/ files in the fileRegistry + * - these are the files in our project that we are watching for changes + * - in the future we could add caching for these files and invalidate the cache when + * the file is changed lazily during lookup + * 2/ .d.ts and library files not in the fileRegistry + * - these are not our files, they come from tsd or typescript itself + * - these files change only rarely but since we need them very rarely, it's not worth the + * cache invalidation hassle to cache them + * 3/ bogus paths that typescript compiler tries to lookup during import resolution + * - these paths are tricky to cache since files come and go and paths that was bogus in the + * past might not be bogus later + * + * In the initial experiments the impact of this caching was insignificant (single digit %) and + * not worth the potential issues with stale cache records. + */ + CustomLanguageServiceHost.prototype.getScriptSnapshot = function (tsFilePath) { + var absoluteTsFilePath; + if (tsFilePath == this.defaultLibFilePath || path.isAbsolute(tsFilePath)) { + absoluteTsFilePath = tsFilePath; + } else if (this.compilerOptions.moduleResolution === 2 /* NodeJs */ && + tsFilePath.match(/^node_modules/)) { + absoluteTsFilePath = path.resolve(tsFilePath); + } else if (tsFilePath.match(/^rxjs/)) { + absoluteTsFilePath = path.resolve('node_modules', tsFilePath); + } else { + absoluteTsFilePath = path.join(this.treeInputPath, tsFilePath); } - CustomLanguageServiceHost.prototype.getScriptFileNames = function () { return this.fileNames; }; - CustomLanguageServiceHost.prototype.getScriptVersion = function (fileName) { - return this.fileRegistry[fileName] && this.fileRegistry[fileName].version.toString(); - }; - /** - * This method is called quite a bit to lookup 3 kinds of paths: - * 1/ files in the fileRegistry - * - these are the files in our project that we are watching for changes - * - in the future we could add caching for these files and invalidate the cache when - * the file is changed lazily during lookup - * 2/ .d.ts and library files not in the fileRegistry - * - these are not our files, they come from tsd or typescript itself - * - these files change only rarely but since we need them very rarely, it's not worth the - * cache invalidation hassle to cache them - * 3/ bogus paths that typescript compiler tries to lookup during import resolution - * - these paths are tricky to cache since files come and go and paths that was bogus in the - * past might not be bogus later - * - * In the initial experiments the impact of this caching was insignificant (single digit %) and - * not worth the potential issues with stale cache records. - */ - CustomLanguageServiceHost.prototype.getScriptSnapshot = function (tsFilePath) { - var absoluteTsFilePath; - if (tsFilePath == this.defaultLibFilePath || path.isAbsolute(tsFilePath)) { - absoluteTsFilePath = tsFilePath; - } - else if (this.compilerOptions.moduleResolution === 2 /* NodeJs */ && - tsFilePath.match(/^node_modules/)) { - absoluteTsFilePath = path.resolve(tsFilePath); - } - else if (tsFilePath.match(/^rxjs/)) { - absoluteTsFilePath = path.resolve('node_modules', tsFilePath); - } - else { - absoluteTsFilePath = path.join(this.treeInputPath, tsFilePath); - } - if (!fs.existsSync(absoluteTsFilePath)) { - // TypeScript seems to request lots of bogus paths during import path lookup and resolution, - // so we we just return undefined when the path is not correct. - return undefined; - } - return ts.ScriptSnapshot.fromString(fs.readFileSync(absoluteTsFilePath, FS_OPTS)); - }; - CustomLanguageServiceHost.prototype.getCurrentDirectory = function () { return this.currentDirectory; }; - CustomLanguageServiceHost.prototype.getCompilationSettings = function () { return this.compilerOptions; }; - CustomLanguageServiceHost.prototype.getDefaultLibFileName = function (options) { - // ignore options argument, options should not change during the lifetime of the plugin - return this.defaultLibFilePath; - }; - return CustomLanguageServiceHost; + if (!fs.existsSync(absoluteTsFilePath)) { + // TypeScript seems to request lots of bogus paths during import path lookup and resolution, + // so we we just return undefined when the path is not correct. + return undefined; + } + return ts.ScriptSnapshot.fromString(fs.readFileSync(absoluteTsFilePath, FS_OPTS)); + }; + CustomLanguageServiceHost.prototype.getCurrentDirectory = function () { + return this.currentDirectory; + }; + CustomLanguageServiceHost.prototype.getCompilationSettings = function () { + return this.compilerOptions; + }; + CustomLanguageServiceHost.prototype.getDefaultLibFileName = function () { + // ignore options argument, options should not change during the lifetime of the plugin + return this.defaultLibFilePath; + }; + return CustomLanguageServiceHost; }()); exports.__esModule = true; -exports["default"] = DiffingTSCompiler; +exports['default'] = DiffingTSCompiler; function clone(object) { - var result = {}; - for (var id in object) { - result[id] = object[id]; - } - return result; + var result = {}; + for (var id in object) { + result[id] = object[id]; + } + return result; } function endsWith(str, substring) { - return str.indexOf(substring, str.length - substring.length) !== -1; + return str.indexOf(substring, str.length - substring.length) !== -1; } -//# sourceMappingURL=broccoli-typescript.js.map \ No newline at end of file +//# sourceMappingURL=broccoli-typescript.js.map diff --git a/lib/broccoli/service-worker-manifest.js b/lib/broccoli/service-worker-manifest.js index 1e14b2103ef3..7e8026011c25 100644 --- a/lib/broccoli/service-worker-manifest.js +++ b/lib/broccoli/service-worker-manifest.js @@ -1,4 +1,4 @@ -"use strict"; +'use strict'; const Plugin = require('broccoli-caching-writer'); var path = require('path'); @@ -24,8 +24,8 @@ class DiffingSWManifest extends Plugin { const files = this.listFiles(); // Removed files from the manifest that aren't part of the files. Object.keys(manifest) - .filter((f) => files.indexOf(f) == -1) - .forEach((file) => delete manifest[file]); + .filter((f) => files.indexOf(f) == -1) + .forEach((file) => delete manifest[file]); // Merge the lists of added and changed paths and update their hashes in the manifest. files @@ -91,5 +91,5 @@ ${contents} } } -Object.defineProperty(exports, "__esModule", { value: true }); +Object.defineProperty(exports, '__esModule', { value: true }); exports.default = DiffingSWManifest; diff --git a/lib/cli/index.js b/lib/cli/index.js index f619f8412159..3dbe261cb92b 100644 --- a/lib/cli/index.js +++ b/lib/cli/index.js @@ -1,3 +1,5 @@ +/*eslint-disable no-console */ + const cli = require('ember-cli/lib/cli'); const path = require('path'); @@ -7,7 +9,7 @@ const fs = require('fs'); const ts = require('typescript'); const old = require.extensions['.ts']; -require.extensions['.ts'] = function(m, filename) { +require.extensions['.ts'] = function (m, filename) { // If we're in node module, either call the old hook or simply compile the // file without transpilation. We do not touch node_modules/**. if (!filename.match(/angular-cli/) && filename.match(/node_modules/)) { @@ -23,7 +25,7 @@ require.extensions['.ts'] = function(m, filename) { try { const result = ts.transpile(source, { target: ts.ScriptTarget.ES5, - module: ts.ModuleKind.CommonJs, + module: ts.ModuleKind.CommonJs }); // Send it to node to execute. @@ -36,23 +38,23 @@ require.extensions['.ts'] = function(m, filename) { }; -module.exports = function(options) { +module.exports = function (options) { const oldStdoutWrite = process.stdout.write; - process.stdout.write = function(line) { + process.stdout.write = function (line) { line = line.toString(); if (line.match(/version:|WARNING:/)) { return; } line = line.replace(/ember-cli(?!.com)/g, 'angular-cli') - .replace(/ember(?!-cli.com)/g, 'ng'); + .replace(/ember(?!-cli.com)/g, 'ng'); return oldStdoutWrite.apply(process.stdout, arguments); }; const oldStderrWrite = process.stderr.write; - process.stderr.write = function(line) { + process.stderr.write = function (line) { line = line.toString() - .replace(/ember-cli(?!.com)/g, 'angular-cli') - .replace(/ember(?!-cli.com)/g, 'ng'); + .replace(/ember-cli(?!.com)/g, 'angular-cli') + .replace(/ember(?!-cli.com)/g, 'ng'); return oldStderrWrite.apply(process.stdout, arguments); }; @@ -61,9 +63,9 @@ module.exports = function(options) { root: path.join(__dirname, '..', '..'), npmPackage: 'angular-cli' }; - + // ensure the environemnt variable for dynamic paths process.env.PWD = process.env.PWD || process.cwd(); - + return cli(options); } diff --git a/package.json b/package.json index 6789b06b31c9..c6fb8ce5e2ed 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ }, "keywords": [], "scripts": { - "test": "node tests/runner" + "test": "eslint -c eslint.json './**/*.js' " }, "repository": { "type": "git", @@ -56,12 +56,15 @@ }, "devDependencies": { "chai": "^3.5.0", + "clang-format": "^1.0.37", + "eslint": "^2.4.0", "exists-sync": "0.0.3", "glob": "^7.0.3", "minimatch": "^3.0.0", "mocha": "^2.4.5", "rewire": "^2.5.1", "through": "^2.3.8", + "tslint": "^3.6.0", "walk-sync": "^0.2.6" } } diff --git a/tests/acceptance/dynamic-path-parser.spec.js b/tests/acceptance/dynamic-path-parser.spec.js index 3674172901bf..e262d7d8e122 100644 --- a/tests/acceptance/dynamic-path-parser.spec.js +++ b/tests/acceptance/dynamic-path-parser.spec.js @@ -2,57 +2,55 @@ var expect = require('chai').expect; var path = require('path'); - var dynamicPathParser = require('../../addon/ng2/utilities/dynamic-path-parser'); describe('dynamic path parser', () => { var project; var entityName = 'temp-name'; beforeEach(() => { - project = { - root: process.cwd() - } + project = { root: process.cwd() } }); - - it(`parse from proj root dir`, () => { + + it('parse from proj root dir', () => { process.env.PWD = process.cwd(); var result = dynamicPathParser(project, entityName); expect(result.dir).to.equal(''); expect(result.name).to.equal(entityName); }); - - it(`parse from proj src dir`, () => { + + it('parse from proj src dir', () => { process.env.PWD = path.join(process.cwd(), 'src'); var result = dynamicPathParser(project, entityName); expect(result.dir).to.equal(''); expect(result.name).to.equal(entityName); }); - + it(`parse from proj src${path.sep}app dir`, () => { process.env.PWD = path.join(process.cwd(), 'src', 'app'); var result = dynamicPathParser(project, entityName); expect(result.dir).to.equal(''); expect(result.name).to.equal(entityName); }); - + it(`parse from proj src${path.sep}app${path.sep}child-dir`, () => { process.env.PWD = path.join(process.cwd(), 'src', 'app', 'child-dir'); var result = dynamicPathParser(project, entityName); expect(result.dir).to.equal(`${path.sep}child-dir`); expect(result.name).to.equal(entityName); }); - + it(`parse from proj src${path.sep}app${path.sep}child-dir w/ ..${path.sep}`, () => { process.env.PWD = path.join(process.cwd(), 'src', 'app', 'child-dir'); var result = dynamicPathParser(project, '..' + path.sep + entityName); - expect(result.dir).to.equal(``); - expect(result.name).to.equal(entityName); - }); - - it(`parse from proj src${path.sep}app${path.sep}child-dir${path.sep}grand-child-dir w/ ..${path.sep}`, () => { - process.env.PWD = path.join(process.cwd(), 'src', 'app', 'child-dir', 'grand-child-dir'); - var result = dynamicPathParser(project, '..' + path.sep + entityName); - expect(result.dir).to.equal(`${path.sep}child-dir`); + expect(result.dir).to.equal(''); expect(result.name).to.equal(entityName); }); -}); \ No newline at end of file + + it(`parse from proj src${path.sep}app${path.sep}child-dir${path.sep}grand-child-dir w/ ..${path.sep}`, + () => { + process.env.PWD = path.join(process.cwd(), 'src', 'app', 'child-dir', 'grand-child-dir'); + var result = dynamicPathParser(project, '..' + path.sep + entityName); + expect(result.dir).to.equal(`${path.sep}child-dir`); + expect(result.name).to.equal(entityName); + }); +}); diff --git a/tests/acceptance/generate-component.spec.js b/tests/acceptance/generate-component.spec.js index 74f53aa63222..f7b1ddfa3ee2 100644 --- a/tests/acceptance/generate-component.spec.js +++ b/tests/acceptance/generate-component.spec.js @@ -1,176 +1,136 @@ +/*eslint-disable no-console */ 'use strict'; var fs = require('fs-extra'); var ng = require('../helpers/ng'); var existsSync = require('exists-sync'); var expect = require('chai').expect; -var forEach = require('lodash/forEach'); -var walkSync = require('walk-sync'); -var Blueprint = require('ember-cli/lib/models/blueprint'); var path = require('path'); var tmp = require('../helpers/tmp'); var root = process.cwd(); -var util = require('util'); var conf = require('ember-cli/tests/helpers/conf'); -var EOL = require('os').EOL; -var path = require('path'); var Promise = require('ember-cli/lib/ext/promise'); -describe('Acceptance: ng generate component', function() { +describe('Acceptance: ng generate component', function () { before(conf.setup); after(conf.restore); - beforeEach(function() { - return tmp.setup('./tmp') - .then(function() { - process.chdir('./tmp'); - }) - .then(function(){ - return ng([ - 'new', - 'foo', - '--skip-npm', - '--skip-bower' - ]); - }); + beforeEach(function () { + return tmp.setup('./tmp').then(function () { + process.chdir('./tmp'); + }).then(function () { + return ng(['new', 'foo', '--skip-npm', '--skip-bower']); + }); }); - afterEach(function() { + afterEach(function () { this.timeout(10000); - // return tmp.teardown('./tmp'); + return tmp.teardown('./tmp'); }); - it('ng generate component my-comp', function() { - return ng([ - 'generate', - 'component', - 'my-comp' - ]) - .then(_ => { + it('ng generate component my-comp', function () { + return ng(['generate', 'component', 'my-comp']).then(() => { var testPath = path.join(root, 'tmp', 'foo', 'src', 'app', 'my-comp', 'my-comp.ts'); expect(existsSync(testPath)).to.equal(true); }); }); - it('ng generate component test' + path.sep + 'my-comp', function() { - return ng([ - 'generate', - 'component', - 'test' + path.sep + 'my-comp' - ]) - .then(_ => { + it('ng generate component test' + path.sep + 'my-comp', function () { + return ng(['generate', 'component', 'test' + path.sep + 'my-comp']).then(() => { var testPath = path.join(root, 'tmp', 'foo', 'src', 'app', 'test', 'my-comp', 'my-comp.ts'); expect(existsSync(testPath)).to.equal(true); }); }); - it('ng generate component test' + path.sep + '..' + path.sep + 'my-comp', function() { - return ng([ - 'generate', - 'component', - 'test' + path.sep + '..' + path.sep + 'my-comp' - ]) - .then(_ => { - var testPath = path.join(root, 'tmp', 'foo', 'src', 'app', 'my-comp', 'my-comp.ts'); - expect(existsSync(testPath)).to.equal(true); - }); + it('ng generate component test' + path.sep + '..' + path.sep + 'my-comp', function () { + return ng(['generate', 'component', 'test' + path.sep + '..' + path.sep + 'my-comp']) + .then(() => { + var testPath = path.join(root, 'tmp', 'foo', 'src', 'app', 'my-comp', 'my-comp.ts'); + expect(existsSync(testPath)).to.equal(true); + }); }); - + it('ng generate component my-comp from a child dir', () => { - return new Promise(function (resolve, reject) { - process.chdir('./src'); - resolve(); + return new Promise(function (resolve) { + process.chdir('./src'); + resolve(); + }) + .then(() => process.chdir('./app')) + .then(() => fs.mkdirsSync('./1')) + .then(() => process.chdir('./1')) + .then(() => { + return ng(['generate', 'component', 'my-comp']) }) - .then(_ => process.chdir('./app')) - .then(_ => fs.mkdirsSync('./1')) - .then(_ => process.chdir('./1')) - .then(_ => { - return ng([ - 'generate', - 'component', - 'my-comp' - ]) - }) - .then(_ => { + .then(() => { var testPath = path.join(root, 'tmp', 'foo', 'src', 'app', '1', 'my-comp', 'my-comp.ts'); expect(existsSync(testPath)).to.equal(true); }, err => console.log('ERR: ', err)); }); - + it('ng generate component child-dir' + path.sep + 'my-comp from a child dir', () => { - return new Promise(function (resolve, reject) { - process.chdir('./src'); - resolve(); + return new Promise(function (resolve) { + process.chdir('./src'); + resolve(); + }) + .then(() => process.chdir('./app')) + .then(() => fs.mkdirsSync('./1')) + .then(() => process.chdir('./1')) + .then(() => { + return ng(['generate', 'component', 'child-dir' + path.sep + 'my-comp']) }) - .then(_ => process.chdir('./app')) - .then(_ => fs.mkdirsSync('./1')) - .then(_ => process.chdir('./1')) - .then(_ => { - return ng([ - 'generate', - 'component', - 'child-dir' + path.sep + 'my-comp' - ]) - }) - .then(_ => { - var testPath = path.join(root, 'tmp', 'foo', 'src', 'app', '1', 'child-dir', 'my-comp', 'my-comp.ts'); + .then(() => { + var testPath = path.join( + root, 'tmp', 'foo', 'src', 'app', '1', 'child-dir', 'my-comp', 'my-comp.ts'); expect(existsSync(testPath)).to.equal(true); }, err => console.log('ERR: ', err)); }); - - it('ng generate component child-dir' + path.sep + '..' + path.sep + 'my-comp from a child dir', () => { - return new Promise(function (resolve, reject) { + + it('ng generate component child-dir' + path.sep + '..' + path.sep + 'my-comp from a child dir', + () => { + return new Promise(function (resolve) { process.chdir('./src'); resolve(); }) - .then(_ => process.chdir('./app')) - .then(_ => fs.mkdirsSync('./1')) - .then(_ => process.chdir('./1')) - .then(_ => { - return ng([ - 'generate', - 'component', - 'child-dir' + path.sep + '..' + path.sep + 'my-comp' - ]) - }) - .then(_ => { - var testPath = path.join(root, 'tmp', 'foo', 'src', 'app', '1', 'my-comp', 'my-comp.ts'); - expect(existsSync(testPath)).to.equal(true); - }, err => console.log('ERR: ', err)); - }); - - it('ng generate component ' + path.sep + 'my-comp from a child dir, gens under ' + path.join('src', 'app'), () => { - return new Promise(function (resolve, reject) { + .then(() => process.chdir('./app')) + .then(() => fs.mkdirsSync('./1')) + .then(() => process.chdir('./1')) + .then(() => { + return ng([ + 'generate', 'component', 'child-dir' + path.sep + '..' + path.sep + 'my-comp' + ]) + }) + .then(() => { + var testPath = + path.join(root, 'tmp', 'foo', 'src', 'app', '1', 'my-comp', 'my-comp.ts'); + expect(existsSync(testPath)).to.equal(true); + }, err => console.log('ERR: ', err)); + }); + + it('ng generate component ' + path.sep + 'my-comp from a child dir, gens under ' + + path.join('src', 'app'), + () => { + return new Promise(function (resolve) { process.chdir('./src'); resolve(); }) - .then(_ => process.chdir('./app')) - .then(_ => fs.mkdirsSync('./1')) - .then(_ => process.chdir('./1')) - .then(_ => { - return ng([ - 'generate', - 'component', - path.sep + 'my-comp' - ]) - }) - .then(_ => { - var testPath = path.join(root, 'tmp', 'foo', 'src', 'app', 'my-comp', 'my-comp.ts'); - expect(existsSync(testPath)).to.equal(true); - }, err => console.log('ERR: ', err)); - }); - + .then(() => process.chdir('./app')) + .then(() => fs.mkdirsSync('./1')) + .then(() => process.chdir('./1')) + .then(() => { + return ng(['generate', 'component', path.sep + 'my-comp']) + }) + .then(() => { + var testPath = path.join(root, 'tmp', 'foo', 'src', 'app', 'my-comp', 'my-comp.ts'); + expect(existsSync(testPath)).to.equal(true); + }, err => console.log('ERR: ', err)); + }); + it('ng generate component ..' + path.sep + 'my-comp from root dir will fail', () => { - return ng([ - 'generate', - 'component', - '..' + path.sep + 'my-comp' - ]) - .then(_ => { + return ng(['generate', 'component', '..' + path.sep + 'my-comp']).then(() => { var testPath = path.join(root, 'tmp', 'foo', 'src', 'app', '..', 'my-comp', 'my-comp.ts'); expect(existsSync(testPath)).to.equal(false); }); }); -}); \ No newline at end of file +}); diff --git a/tests/acceptance/generate-directive.spec.js b/tests/acceptance/generate-directive.spec.js index b8d8acfd7b00..645760c93f68 100644 --- a/tests/acceptance/generate-directive.spec.js +++ b/tests/acceptance/generate-directive.spec.js @@ -1,180 +1,139 @@ +/*eslint-disable no-console */ 'use strict'; var fs = require('fs-extra'); var ng = require('../helpers/ng'); var existsSync = require('exists-sync'); var expect = require('chai').expect; -var forEach = require('lodash/forEach'); -var walkSync = require('walk-sync'); -var Blueprint = require('ember-cli/lib/models/blueprint'); var path = require('path'); var tmp = require('../helpers/tmp'); var root = process.cwd(); -var util = require('util'); var conf = require('ember-cli/tests/helpers/conf'); -var EOL = require('os').EOL; -var path = require('path'); var Promise = require('ember-cli/lib/ext/promise'); -describe('Acceptance: ng generate directive', function() { +describe('Acceptance: ng generate directive', function () { before(conf.setup); after(conf.restore); - beforeEach(function() { - return tmp.setup('./tmp') - .then(function() { - process.chdir('./tmp'); - }) - .then(function(){ - return ng([ - 'new', - 'foo', - '--skip-npm', - '--skip-bower' - ]); - }); + beforeEach(function () { + return tmp.setup('./tmp').then(function () { + process.chdir('./tmp'); + }).then(function () { + return ng(['new', 'foo', '--skip-npm', '--skip-bower']); + }); }); - afterEach(function() { + afterEach(function () { this.timeout(10000); - // return tmp.teardown('./tmp'); + return tmp.teardown('./tmp'); }); - it('ng generate directive my-comp', function() { - return ng([ - 'generate', - 'directive', - 'my-comp' - ]) - .then(_ => { + it('ng generate directive my-comp', function () { + return ng(['generate', 'directive', 'my-comp']).then(() => { var testPath = path.join(root, 'tmp', 'foo', 'src', 'app', 'my-comp', 'my-comp.ts'); expect(existsSync(testPath)).to.equal(true); }); }); - it('ng generate directive test' + path.sep + 'my-comp', function() { - return ng([ - 'generate', - 'directive', - 'test' + path.sep + 'my-comp' - ]) - .then(_ => { + it('ng generate directive test' + path.sep + 'my-comp', function () { + return ng(['generate', 'directive', 'test' + path.sep + 'my-comp']).then(() => { var testPath = path.join(root, 'tmp', 'foo', 'src', 'app', 'test', 'my-comp', 'my-comp.ts'); expect(existsSync(testPath)).to.equal(true); }); }); - it('ng generate directive test' + path.sep + '..' + path.sep + 'my-comp', function() { - return ng([ - 'generate', - 'directive', - 'test' + path.sep + '..' + path.sep + 'my-comp' - ]) - .then(_ => { - var testPath = path.join(root, 'tmp', 'foo', 'src', 'app', 'my-comp', 'my-comp.ts'); - expect(existsSync(testPath)).to.equal(true); - }); + it('ng generate directive test' + path.sep + '..' + path.sep + 'my-comp', function () { + return ng(['generate', 'directive', 'test' + path.sep + '..' + path.sep + 'my-comp']) + .then(() => { + var testPath = path.join(root, 'tmp', 'foo', 'src', 'app', 'my-comp', 'my-comp.ts'); + expect(existsSync(testPath)).to.equal(true); + }); }); - + it('ng generate directive my-comp from a child dir', () => { - return new Promise(function (resolve, reject) { - process.chdir('./src'); - resolve(); - }) - .then(_ => process.chdir('./app')) - .then(_ => fs.mkdirsSync('./1')) - .then(_ => process.chdir('./1')) - .then(_ => { + return new Promise(function (resolve) { + process.chdir('./src'); + resolve(); + }) + .then(() => process.chdir('./app')) + .then(() => fs.mkdirsSync('./1')) + .then(() => process.chdir('./1')) + .then(() => { process.env.CWD = process.cwd(); - return ng([ - 'generate', - 'directive', - 'my-comp' - ]) + return ng(['generate', 'directive', 'my-comp']) }) - .then(_ => { + .then(() => { var testPath = path.join(root, 'tmp', 'foo', 'src', 'app', '1', 'my-comp', 'my-comp.ts'); expect(existsSync(testPath)).to.equal(true); }, err => console.log('ERR: ', err)); }); - + it('ng generate directive child-dir' + path.sep + 'my-comp from a child dir', () => { - return new Promise(function (resolve, reject) { - process.chdir('./src'); - resolve(); - }) - .then(_ => process.chdir('./app')) - .then(_ => fs.mkdirsSync('./1')) - .then(_ => process.chdir('./1')) - .then(_ => { + return new Promise(function (resolve) { + process.chdir('./src'); + resolve(); + }) + .then(() => process.chdir('./app')) + .then(() => fs.mkdirsSync('./1')) + .then(() => process.chdir('./1')) + .then(() => { process.env.CWD = process.cwd(); - return ng([ - 'generate', - 'directive', - 'child-dir' + path.sep + 'my-comp' - ]) + return ng(['generate', 'directive', 'child-dir' + path.sep + 'my-comp']) }) - .then(_ => { - var testPath = path.join(root, 'tmp', 'foo', 'src', 'app', '1', 'child-dir', 'my-comp', 'my-comp.ts'); + .then(() => { + var testPath = path.join( + root, 'tmp', 'foo', 'src', 'app', '1', 'child-dir', 'my-comp', 'my-comp.ts'); expect(existsSync(testPath)).to.equal(true); }, err => console.log('ERR: ', err)); }); - - it('ng generate directive child-dir' + path.sep + '..' + path.sep + 'my-comp from a child dir', () => { - return new Promise(function (resolve, reject) { + + it('ng generate directive child-dir' + path.sep + '..' + path.sep + 'my-comp from a child dir', + () => { + return new Promise(function (resolve) { process.chdir('./src'); resolve(); }) - .then(_ => process.chdir('./app')) - .then(_ => fs.mkdirsSync('./1')) - .then(_ => process.chdir('./1')) - .then(_ => { - process.env.CWD = process.cwd(); - return ng([ - 'generate', - 'directive', - 'child-dir' + path.sep + '..' + path.sep + 'my-comp' - ]) - }) - .then(_ => { - var testPath = path.join(root, 'tmp', 'foo', 'src', 'app', '1', 'my-comp', 'my-comp.ts'); - expect(existsSync(testPath)).to.equal(true); - }, err => console.log('ERR: ', err)); - }); - - it('ng generate directive ' + path.sep + 'my-comp from a child dir, gens under ' + path.join('src', 'app'), () => { - return new Promise(function (resolve, reject) { + .then(() => process.chdir('./app')) + .then(() => fs.mkdirsSync('./1')) + .then(() => process.chdir('./1')) + .then(() => { + process.env.CWD = process.cwd(); + return ng( + ['generate', 'directive', 'child-dir' + path.sep + '..' + path.sep + 'my-comp']) + }) + .then(() => { + var testPath = + path.join(root, 'tmp', 'foo', 'src', 'app', '1', 'my-comp', 'my-comp.ts'); + expect(existsSync(testPath)).to.equal(true); + }, err => console.log('ERR: ', err)); + }); + + it('ng generate directive ' + path.sep + 'my-comp from a child dir, gens under ' + + path.join('src', 'app'), + () => { + return new Promise(function (resolve) { process.chdir('./src'); resolve(); }) - .then(_ => process.chdir('./app')) - .then(_ => fs.mkdirsSync('./1')) - .then(_ => process.chdir('./1')) - .then(_ => { - process.env.CWD = process.cwd(); - return ng([ - 'generate', - 'directive', - path.sep + 'my-comp' - ]) - }) - .then(_ => { - var testPath = path.join(root, 'tmp', 'foo', 'src', 'app', 'my-comp', 'my-comp.ts'); - expect(existsSync(testPath)).to.equal(true); - }, err => console.log('ERR: ', err)); - }); - + .then(() => process.chdir('./app')) + .then(() => fs.mkdirsSync('./1')) + .then(() => process.chdir('./1')) + .then(() => { + process.env.CWD = process.cwd(); + return ng(['generate', 'directive', path.sep + 'my-comp']) + }) + .then(() => { + var testPath = path.join(root, 'tmp', 'foo', 'src', 'app', 'my-comp', 'my-comp.ts'); + expect(existsSync(testPath)).to.equal(true); + }, err => console.log('ERR: ', err)); + }); + it('ng generate directive ..' + path.sep + 'my-comp from root dir will fail', () => { - return ng([ - 'generate', - 'directive', - '..' + path.sep + 'my-comp' - ]) - .then(_ => { + return ng(['generate', 'directive', '..' + path.sep + 'my-comp']).then(() => { var testPath = path.join(root, 'tmp', 'foo', 'src', 'app', '..', 'my-comp', 'my-comp.ts'); expect(existsSync(testPath)).to.equal(false); }); }); -}); \ No newline at end of file +}); diff --git a/tests/acceptance/generate-pipe.spec.js b/tests/acceptance/generate-pipe.spec.js index bbeccdb4b975..e87d25b71442 100644 --- a/tests/acceptance/generate-pipe.spec.js +++ b/tests/acceptance/generate-pipe.spec.js @@ -1,180 +1,135 @@ +/*eslint-disable no-console */ 'use strict'; var fs = require('fs-extra'); var ng = require('../helpers/ng'); var existsSync = require('exists-sync'); var expect = require('chai').expect; -var forEach = require('lodash/forEach'); -var walkSync = require('walk-sync'); -var Blueprint = require('ember-cli/lib/models/blueprint'); var path = require('path'); var tmp = require('../helpers/tmp'); var root = process.cwd(); -var util = require('util'); var conf = require('ember-cli/tests/helpers/conf'); -var EOL = require('os').EOL; -var path = require('path'); var Promise = require('ember-cli/lib/ext/promise'); -describe('Acceptance: ng generate pipe', function() { +describe('Acceptance: ng generate pipe', function () { before(conf.setup); after(conf.restore); - beforeEach(function() { - return tmp.setup('./tmp') - .then(function() { - process.chdir('./tmp'); - }) - .then(function(){ - return ng([ - 'new', - 'foo', - '--skip-npm', - '--skip-bower' - ]); - }); + beforeEach(function () { + return tmp.setup('./tmp').then(function () { + process.chdir('./tmp'); + }).then(function () { + return ng(['new', 'foo', '--skip-npm', '--skip-bower']); + }); }); - afterEach(function() { + afterEach(function () { this.timeout(10000); - // return tmp.teardown('./tmp'); + return tmp.teardown('./tmp'); }); - it('ng generate pipe my-comp', function() { - return ng([ - 'generate', - 'pipe', - 'my-comp' - ]) - .then(_ => { + it('ng generate pipe my-comp', function () { + return ng(['generate', 'pipe', 'my-comp']).then(() => { var testPath = path.join(root, 'tmp', 'foo', 'src', 'app', 'my-comp', 'my-comp.ts'); expect(existsSync(testPath)).to.equal(true); }); }); - it('ng generate pipe test' + path.sep + 'my-comp', function() { - return ng([ - 'generate', - 'pipe', - 'test' + path.sep + 'my-comp' - ]) - .then(_ => { + it('ng generate pipe test' + path.sep + 'my-comp', function () { + return ng(['generate', 'pipe', 'test' + path.sep + 'my-comp']).then(() => { var testPath = path.join(root, 'tmp', 'foo', 'src', 'app', 'test', 'my-comp', 'my-comp.ts'); expect(existsSync(testPath)).to.equal(true); }); }); - it('ng generate pipe test' + path.sep + '..' + path.sep + 'my-comp', function() { - return ng([ - 'generate', - 'pipe', - 'test' + path.sep + '..' + path.sep + 'my-comp' - ]) - .then(_ => { + it('ng generate pipe test' + path.sep + '..' + path.sep + 'my-comp', function () { + return ng(['generate', 'pipe', 'test' + path.sep + '..' + path.sep + 'my-comp']).then(() => { var testPath = path.join(root, 'tmp', 'foo', 'src', 'app', 'my-comp', 'my-comp.ts'); expect(existsSync(testPath)).to.equal(true); }); }); - + it('ng generate pipe my-comp from a child dir', () => { - return new Promise(function (resolve, reject) { - process.chdir('./src'); - resolve(); - }) - .then(_ => process.chdir('./app')) - .then(_ => fs.mkdirsSync('./1')) - .then(_ => process.chdir('./1')) - .then(_ => { + return new Promise(function (resolve) { + process.chdir('./src'); + resolve(); + }) + .then(() => process.chdir('./app')) + .then(() => fs.mkdirsSync('./1')) + .then(() => process.chdir('./1')) + .then(() => { process.env.CWD = process.cwd(); - return ng([ - 'generate', - 'pipe', - 'my-comp' - ]) + return ng(['generate', 'pipe', 'my-comp']) }) - .then(_ => { + .then(() => { var testPath = path.join(root, 'tmp', 'foo', 'src', 'app', '1', 'my-comp', 'my-comp.ts'); expect(existsSync(testPath)).to.equal(true); }, err => console.log('ERR: ', err)); }); - + it('ng generate pipe child-dir' + path.sep + 'my-comp from a child dir', () => { - return new Promise(function (resolve, reject) { - process.chdir('./src'); - resolve(); - }) - .then(_ => process.chdir('./app')) - .then(_ => fs.mkdirsSync('./1')) - .then(_ => process.chdir('./1')) - .then(_ => { + return new Promise(function (resolve) { + process.chdir('./src'); + resolve(); + }) + .then(() => process.chdir('./app')) + .then(() => fs.mkdirsSync('./1')) + .then(() => process.chdir('./1')) + .then(() => { process.env.CWD = process.cwd(); - return ng([ - 'generate', - 'pipe', - 'child-dir' + path.sep + 'my-comp' - ]) + return ng(['generate', 'pipe', 'child-dir' + path.sep + 'my-comp']) }) - .then(_ => { - var testPath = path.join(root, 'tmp', 'foo', 'src', 'app', '1', 'child-dir', 'my-comp', 'my-comp.ts'); + .then(() => { + var testPath = path.join( + root, 'tmp', 'foo', 'src', 'app', '1', 'child-dir', 'my-comp', 'my-comp.ts'); expect(existsSync(testPath)).to.equal(true); }, err => console.log('ERR: ', err)); }); - + it('ng generate pipe child-dir' + path.sep + '..' + path.sep + 'my-comp from a child dir', () => { - return new Promise(function (resolve, reject) { - process.chdir('./src'); - resolve(); - }) - .then(_ => process.chdir('./app')) - .then(_ => fs.mkdirsSync('./1')) - .then(_ => process.chdir('./1')) - .then(_ => { + return new Promise(function (resolve) { + process.chdir('./src'); + resolve(); + }) + .then(() => process.chdir('./app')) + .then(() => fs.mkdirsSync('./1')) + .then(() => process.chdir('./1')) + .then(() => { process.env.CWD = process.cwd(); - return ng([ - 'generate', - 'pipe', - 'child-dir' + path.sep + '..' + path.sep + 'my-comp' - ]) + return ng(['generate', 'pipe', 'child-dir' + path.sep + '..' + path.sep + 'my-comp']) }) - .then(_ => { + .then(() => { var testPath = path.join(root, 'tmp', 'foo', 'src', 'app', '1', 'my-comp', 'my-comp.ts'); expect(existsSync(testPath)).to.equal(true); }, err => console.log('ERR: ', err)); }); - - it('ng generate pipe ' + path.sep + 'my-comp from a child dir, gens under ' + path.join('src', 'app'), () => { - return new Promise(function (resolve, reject) { + + it('ng generate pipe ' + path.sep + 'my-comp from a child dir, gens under ' + + path.join('src', 'app'), + () => { + return new Promise(function (resolve) { process.chdir('./src'); resolve(); }) - .then(_ => process.chdir('./app')) - .then(_ => fs.mkdirsSync('./1')) - .then(_ => process.chdir('./1')) - .then(_ => { - process.env.CWD = process.cwd(); - return ng([ - 'generate', - 'pipe', - path.sep + 'my-comp' - ]) - }) - .then(_ => { - var testPath = path.join(root, 'tmp', 'foo', 'src', 'app', 'my-comp', 'my-comp.ts'); - expect(existsSync(testPath)).to.equal(true); - }, err => console.log('ERR: ', err)); - }); - + .then(() => process.chdir('./app')) + .then(() => fs.mkdirsSync('./1')) + .then(() => process.chdir('./1')) + .then(() => { + process.env.CWD = process.cwd(); + return ng(['generate', 'pipe', path.sep + 'my-comp']) + }) + .then(() => { + var testPath = path.join(root, 'tmp', 'foo', 'src', 'app', 'my-comp', 'my-comp.ts'); + expect(existsSync(testPath)).to.equal(true); + }, err => console.log('ERR: ', err)); + }); + it('ng generate pipe ..' + path.sep + 'my-comp from root dir will fail', () => { - return ng([ - 'generate', - 'pipe', - '..' + path.sep + 'my-comp' - ]) - .then(_ => { + return ng(['generate', 'pipe', '..' + path.sep + 'my-comp']).then(() => { var testPath = path.join(root, 'tmp', 'foo', 'src', 'app', '..', 'my-comp', 'my-comp.ts'); expect(existsSync(testPath)).to.equal(false); }); }); -}); \ No newline at end of file +}); diff --git a/tests/acceptance/generate-route.spec.js b/tests/acceptance/generate-route.spec.js index c5eda98d5b6f..be760b6d3a98 100644 --- a/tests/acceptance/generate-route.spec.js +++ b/tests/acceptance/generate-route.spec.js @@ -4,19 +4,17 @@ var fs = require('fs-extra'); var ng = require('../helpers/ng'); var existsSync = require('exists-sync'); var expect = require('chai').expect; -var forEach = require('lodash/forEach'); var path = require('path'); var tmp = require('../helpers/tmp'); var root = process.cwd(); -var util = require('util'); var conf = require('ember-cli/tests/helpers/conf'); var testPath = path.join(root, 'tmp', 'foo', 'src', 'app', 'my-route'); var appPath = path.join(root, 'tmp', 'foo', 'src', 'app'); var routeRegex = /name: 'MyRouteRoot'/g; var route = { - routePath: `/my-route/...`, - component: `MyRouteRoot`, - componentPath: `./my-route/my-route-root.component` + routePath: '/my-route/...', + component: 'MyRouteRoot', + componentPath: './my-route/my-route-root.component' }; var fileExpectations = function (expectation) { @@ -27,7 +25,8 @@ var fileExpectations = function (expectation) { expect(existsSync(path.join(testPath, 'my-route-list.component.html'))).to.equal(expectation); expect(existsSync(path.join(testPath, 'my-route-list.component.css'))).to.equal(expectation); expect(existsSync(path.join(testPath, 'my-route-detail.component.ts'))).to.equal(expectation); - expect(existsSync(path.join(testPath, 'my-route-detail.component.spec.ts'))).to.equal(expectation); + expect(existsSync(path.join(testPath, 'my-route-detail.component.spec.ts'))) + .to.equal(expectation); expect(existsSync(path.join(testPath, 'my-route-detail.component.html'))).to.equal(expectation); expect(existsSync(path.join(testPath, 'my-route-detail.component.css'))).to.equal(expectation); expect(existsSync(path.join(testPath, 'my-route-root.component.ts'))).to.equal(expectation); @@ -39,18 +38,11 @@ describe('Acceptance: ng generate route', function () { after(conf.restore); beforeEach(function () { - return tmp.setup('./tmp') - .then(function () { - process.chdir('./tmp'); - }) - .then(function () { - return ng([ - 'new', - 'foo', - '--skip-npm', - '--skip-bower' - ]); - }); + return tmp.setup('./tmp').then(function () { + process.chdir('./tmp'); + }).then(function () { + return ng(['new', 'foo', '--skip-npm', '--skip-bower']); + }); }); afterEach(function () { @@ -60,59 +52,49 @@ describe('Acceptance: ng generate route', function () { }); it('ng generate route my-route', function () { - return ng([ - 'generate', - 'route', - 'my-route' - ]) - .then(_ => { - var ngCliConfig = JSON.parse(fs.readFileSync(path.join(root, 'tmp', 'foo', 'angular-cli.json'), 'utf-8')); - var routeConfigString = fs.readFileSync(path.join(appPath, 'route-config.ts'), 'utf-8').toString(); - expect(routeConfigString.match(routeRegex).length).to.equal(1); + return ng(['generate', 'route', 'my-route']).then(() => { + var ngCliConfig = + JSON.parse(fs.readFileSync(path.join(root, 'tmp', 'foo', 'angular-cli.json'), 'utf-8')); + var routeConfigString = + fs.readFileSync(path.join(appPath, 'route-config.ts'), 'utf-8').toString(); + expect(routeConfigString.match(routeRegex).length).to.equal(1); - fileExpectations(true); + fileExpectations(true); - expect(ngCliConfig.routes[0]).to.deep.equal(route); - }); + expect(ngCliConfig.routes[0]).to.deep.equal(route); + }); }); - it('ng generate route my-route with skip-router-generation flag does not generate router config', function () { - return ng([ - 'generate', - 'route', - 'my-route', - '--skip-router-generation' - ]) - .then(_ => { - var ngCliConfig = JSON.parse(fs.readFileSync(path.join(root, 'tmp', 'foo', 'angular-cli.json'), 'utf-8')); + it('ng generate route my-route with skip-router-generation flag does not generate router config', + function () { + return ng(['generate', 'route', 'my-route', '--skip-router-generation']).then(() => { + var ngCliConfig = JSON.parse( + fs.readFileSync(path.join(root, 'tmp', 'foo', 'angular-cli.json'), 'utf-8')); fileExpectations(true); expect(ngCliConfig.routes.length).to.equal(0); }); - }); + }); it('ng generate route my-route then destroy', function () { - return ng([ - 'generate', - 'route', - 'my-route' - ]) + return ng(['generate', 'route', 'my-route']) .then(() => { - var ngCliConfig = JSON.parse(fs.readFileSync(path.join(root, 'tmp', 'foo', 'angular-cli.json'), 'utf-8')); - var routeConfigString = fs.readFileSync(path.join(appPath, 'route-config.ts'), 'utf-8').toString(); + var ngCliConfig = JSON.parse( + fs.readFileSync(path.join(root, 'tmp', 'foo', 'angular-cli.json'), 'utf-8')); + var routeConfigString = + fs.readFileSync(path.join(appPath, 'route-config.ts'), 'utf-8').toString(); expect(routeConfigString.match(routeRegex).length).to.equal(1); fileExpectations(true); expect(ngCliConfig.routes.length).to.equal(1); expect(ngCliConfig.routes[0]).to.deep.equal(route); - }).then(() => { - return ng([ - 'destroy', - 'route', - 'my-route' - ]).then(() => { - var ngCliConfig = JSON.parse(fs.readFileSync(path.join(root, 'tmp', 'foo', 'angular-cli.json'), 'utf-8')); - var routeConfigString = fs.readFileSync(path.join(appPath, 'route-config.ts'), 'utf-8').toString(); + }) + .then(() => { + return ng(['destroy', 'route', 'my-route']).then(() => { + var ngCliConfig = JSON.parse( + fs.readFileSync(path.join(root, 'tmp', 'foo', 'angular-cli.json'), 'utf-8')); + var routeConfigString = + fs.readFileSync(path.join(appPath, 'route-config.ts'), 'utf-8').toString(); expect(routeConfigString.match(routeRegex)).to.equal(null); fileExpectations(false); @@ -121,4 +103,4 @@ describe('Acceptance: ng generate route', function () { }) }); }); -}); \ No newline at end of file +}); diff --git a/tests/acceptance/generate-service.spec.js b/tests/acceptance/generate-service.spec.js index 436adad492b9..58e77a047e59 100644 --- a/tests/acceptance/generate-service.spec.js +++ b/tests/acceptance/generate-service.spec.js @@ -1,180 +1,138 @@ +/*eslint-disable no-console */ 'use strict'; var fs = require('fs-extra'); var ng = require('../helpers/ng'); var existsSync = require('exists-sync'); var expect = require('chai').expect; -var forEach = require('lodash/forEach'); -var walkSync = require('walk-sync'); -var Blueprint = require('ember-cli/lib/models/blueprint'); var path = require('path'); var tmp = require('../helpers/tmp'); var root = process.cwd(); -var util = require('util'); var conf = require('ember-cli/tests/helpers/conf'); -var EOL = require('os').EOL; -var path = require('path'); var Promise = require('ember-cli/lib/ext/promise'); -describe('Acceptance: ng generate service', function() { +describe('Acceptance: ng generate service', function () { before(conf.setup); after(conf.restore); - beforeEach(function() { - return tmp.setup('./tmp') - .then(function() { - process.chdir('./tmp'); - }) - .then(function(){ - return ng([ - 'new', - 'foo', - '--skip-npm', - '--skip-bower' - ]); - }); + beforeEach(function () { + return tmp.setup('./tmp').then(function () { + process.chdir('./tmp'); + }).then(function () { + return ng(['new', 'foo', '--skip-npm', '--skip-bower']); + }); }); - afterEach(function() { + afterEach(function () { this.timeout(10000); - // return tmp.teardown('./tmp'); + return tmp.teardown('./tmp'); }); - it('ng generate service my-comp', function() { - return ng([ - 'generate', - 'service', - 'my-comp' - ]) - .then(_ => { + it('ng generate service my-comp', function () { + return ng(['generate', 'service', 'my-comp']).then(() => { var testPath = path.join(root, 'tmp', 'foo', 'src', 'app', 'my-comp', 'my-comp.ts'); expect(existsSync(testPath)).to.equal(true); }); }); - it('ng generate service test' + path.sep + 'my-comp', function() { - return ng([ - 'generate', - 'service', - 'test' + path.sep + 'my-comp' - ]) - .then(_ => { + it('ng generate service test' + path.sep + 'my-comp', function () { + return ng(['generate', 'service', 'test' + path.sep + 'my-comp']).then(() => { var testPath = path.join(root, 'tmp', 'foo', 'src', 'app', 'test', 'my-comp', 'my-comp.ts'); expect(existsSync(testPath)).to.equal(true); }); }); - it('ng generate service test' + path.sep + '..' + path.sep + 'my-comp', function() { - return ng([ - 'generate', - 'service', - 'test' + path.sep + '..' + path.sep + 'my-comp' - ]) - .then(_ => { + it('ng generate service test' + path.sep + '..' + path.sep + 'my-comp', function () { + return ng(['generate', 'service', 'test' + path.sep + '..' + path.sep + 'my-comp']).then(() => { var testPath = path.join(root, 'tmp', 'foo', 'src', 'app', 'my-comp', 'my-comp.ts'); expect(existsSync(testPath)).to.equal(true); }); }); - + it('ng generate service my-comp from a child dir', () => { - return new Promise(function (resolve, reject) { - process.chdir('./src'); - resolve(); - }) - .then(_ => process.chdir('./app')) - .then(_ => fs.mkdirsSync('./1')) - .then(_ => process.chdir('./1')) - .then(_ => { + return new Promise(function (resolve) { + process.chdir('./src'); + resolve(); + }) + .then(() => process.chdir('./app')) + .then(() => fs.mkdirsSync('./1')) + .then(() => process.chdir('./1')) + .then(() => { process.env.CWD = process.cwd(); - return ng([ - 'generate', - 'service', - 'my-comp' - ]) + return ng(['generate', 'service', 'my-comp']) }) - .then(_ => { + .then(() => { var testPath = path.join(root, 'tmp', 'foo', 'src', 'app', '1', 'my-comp', 'my-comp.ts'); expect(existsSync(testPath)).to.equal(true); }, err => console.log('ERR: ', err)); }); - + it('ng generate service child-dir' + path.sep + 'my-comp from a child dir', () => { - return new Promise(function (resolve, reject) { - process.chdir('./src'); - resolve(); - }) - .then(_ => process.chdir('./app')) - .then(_ => fs.mkdirsSync('./1')) - .then(_ => process.chdir('./1')) - .then(_ => { + return new Promise(function (resolve) { + process.chdir('./src'); + resolve(); + }) + .then(() => process.chdir('./app')) + .then(() => fs.mkdirsSync('./1')) + .then(() => process.chdir('./1')) + .then(() => { process.env.CWD = process.cwd(); - return ng([ - 'generate', - 'service', - 'child-dir' + path.sep + 'my-comp' - ]) + return ng(['generate', 'service', 'child-dir' + path.sep + 'my-comp']) }) - .then(_ => { - var testPath = path.join(root, 'tmp', 'foo', 'src', 'app', '1', 'child-dir', 'my-comp', 'my-comp.ts'); + .then(() => { + var testPath = path.join( + root, 'tmp', 'foo', 'src', 'app', '1', 'child-dir', 'my-comp', 'my-comp.ts'); expect(existsSync(testPath)).to.equal(true); }, err => console.log('ERR: ', err)); }); - - it('ng generate service child-dir' + path.sep + '..' + path.sep + 'my-comp from a child dir', () => { - return new Promise(function (resolve, reject) { + + it('ng generate service child-dir' + path.sep + '..' + path.sep + 'my-comp from a child dir', + () => { + return new Promise(function (resolve) { process.chdir('./src'); resolve(); }) - .then(_ => process.chdir('./app')) - .then(_ => fs.mkdirsSync('./1')) - .then(_ => process.chdir('./1')) - .then(_ => { - process.env.CWD = process.cwd(); - return ng([ - 'generate', - 'service', - 'child-dir' + path.sep + '..' + path.sep + 'my-comp' - ]) - }) - .then(_ => { - var testPath = path.join(root, 'tmp', 'foo', 'src', 'app', '1', 'my-comp', 'my-comp.ts'); - expect(existsSync(testPath)).to.equal(true); - }, err => console.log('ERR: ', err)); - }); - - it('ng generate service ' + path.sep + 'my-comp from a child dir, gens under ' + path.join('src', 'app'), () => { - return new Promise(function (resolve, reject) { + .then(() => process.chdir('./app')) + .then(() => fs.mkdirsSync('./1')) + .then(() => process.chdir('./1')) + .then(() => { + process.env.CWD = process.cwd(); + return ng( + ['generate', 'service', 'child-dir' + path.sep + '..' + path.sep + 'my-comp']) + }) + .then(() => { + var testPath = + path.join(root, 'tmp', 'foo', 'src', 'app', '1', 'my-comp', 'my-comp.ts'); + expect(existsSync(testPath)).to.equal(true); + }, err => console.log('ERR: ', err)); + }); + + it('ng generate service ' + path.sep + 'my-comp from a child dir, gens under ' + + path.join('src', 'app'), + () => { + return new Promise(function (resolve) { process.chdir('./src'); resolve(); }) - .then(_ => process.chdir('./app')) - .then(_ => fs.mkdirsSync('./1')) - .then(_ => process.chdir('./1')) - .then(_ => { - process.env.CWD = process.cwd(); - return ng([ - 'generate', - 'service', - path.sep + 'my-comp' - ]) - }) - .then(_ => { - var testPath = path.join(root, 'tmp', 'foo', 'src', 'app', 'my-comp', 'my-comp.ts'); - expect(existsSync(testPath)).to.equal(true); - }, err => console.log('ERR: ', err)); - }); - + .then(() => process.chdir('./app')) + .then(() => fs.mkdirsSync('./1')) + .then(() => process.chdir('./1')) + .then(() => { + process.env.CWD = process.cwd(); + return ng(['generate', 'service', path.sep + 'my-comp']) + }) + .then(() => { + var testPath = path.join(root, 'tmp', 'foo', 'src', 'app', 'my-comp', 'my-comp.ts'); + expect(existsSync(testPath)).to.equal(true); + }, err => console.log('ERR: ', err)); + }); + it('ng generate service ..' + path.sep + 'my-comp from root dir will fail', () => { - return ng([ - 'generate', - 'service', - '..' + path.sep + 'my-comp' - ]) - .then(_ => { + return ng(['generate', 'service', '..' + path.sep + 'my-comp']).then(() => { var testPath = path.join(root, 'tmp', 'foo', 'src', 'app', '..', 'my-comp', 'my-comp.ts'); expect(existsSync(testPath)).to.equal(false); }); }); -}); \ No newline at end of file +}); diff --git a/tests/acceptance/init.spec.js b/tests/acceptance/init.spec.js index 24aeb92e6dd6..2bcd968b2eaf 100644 --- a/tests/acceptance/init.spec.js +++ b/tests/acceptance/init.spec.js @@ -1,235 +1,185 @@ 'use strict'; -var ng = require('../helpers/ng'); -var expect = require('chai').expect; -var walkSync = require('walk-sync'); -var glob = require('glob'); +var ng = require('../helpers/ng'); +var expect = require('chai').expect; +var walkSync = require('walk-sync'); +var glob = require('glob'); var Blueprint = require('ember-cli/lib/models/blueprint'); -var path = require('path'); -var tmp = require('../helpers/tmp'); -var root = process.cwd(); -var util = require('util'); -var conf = require('ember-cli/tests/helpers/conf'); +var path = require('path'); +var tmp = require('../helpers/tmp'); +var root = process.cwd(); +var util = require('util'); +var conf = require('ember-cli/tests/helpers/conf'); var minimatch = require('minimatch'); var intersect = require('lodash/intersection'); -var remove = require('lodash/remove'); -var forEach = require('lodash/forEach'); -var any = require('lodash/some'); -var EOL = require('os').EOL; +var remove = require('lodash/remove'); +var forEach = require('lodash/forEach'); +var any = require('lodash/some'); +var EOL = require('os').EOL; var defaultIgnoredFiles = Blueprint.ignoredFiles; -describe('Acceptance: ng init', function() { - this.timeout(20000); +describe('Acceptance: ng init', function () { + this.timeout(20000); - before(function() { - conf.setup(); - }); + before(function () { + conf.setup(); + }); - after(function() { - conf.restore(); - }); + after(function () { + conf.restore(); + }); - beforeEach(function() { - Blueprint.ignoredFiles = defaultIgnoredFiles; + beforeEach(function () { + Blueprint.ignoredFiles = defaultIgnoredFiles; - return tmp.setup('./tmp') - .then(function() { - process.chdir('./tmp'); - }); + return tmp.setup('./tmp').then(function () { + process.chdir('./tmp'); }); + }); - afterEach(function() { - return tmp.teardown('./tmp'); - }); + afterEach(function () { + return tmp.teardown('./tmp'); + }); - function confirmBlueprinted() { - var blueprintPath = path.join(root, 'addon', 'ng2', 'blueprints', 'ng2', 'files'); - var expected = walkSync(blueprintPath).sort(); - var actual = walkSync('.').sort(); - - forEach(Blueprint.renamedFiles, function(destFile, srcFile) { - expected[expected.indexOf(srcFile)] = destFile; - }); - - expected.forEach(function (file, index) { - expected[index] = file.replace(/__name__/g, 'tmp'); - }); - - removeIgnored(expected); - removeIgnored(actual); - - expected.sort(); - - expect(expected).to.deep.equal(actual, EOL + ' expected: ' + util.inspect(expected) + - EOL + ' but got: ' + util.inspect(actual)); - } - - function confirmGlobBlueprinted(pattern) { - var blueprintPath = path.join(root, 'addon', 'ng2', 'blueprints', 'ng2', 'files'); - var actual = pickSync('.', pattern); - var expected = intersect(pickSync(blueprintPath, pattern), actual); - - removeIgnored(expected); - removeIgnored(actual); - - expected.sort(); - - expect(expected).to.deep.equal(actual, EOL + ' expected: ' + util.inspect(expected) + - EOL + ' but got: ' + util.inspect(actual)); - } - - function pickSync(filePath, pattern) { - return glob.sync(path.join('**', pattern), { - cwd: filePath, - dot: true, - mark: true, - strict: true - }).sort(); - } - function removeIgnored(array) { - remove(array, function(fn) { - return any(Blueprint.ignoredFiles, function(ignoredFile) { - return minimatch(fn, ignoredFile, { - matchBase: true - }); - }); - }); - } - - it('ng init', function() { - return ng([ - 'init', - '--skip-npm', - '--skip-bower' - ]).then(confirmBlueprinted); + function confirmBlueprinted() { + var blueprintPath = path.join(root, 'addon', 'ng2', 'blueprints', 'ng2', 'files'); + var expected = walkSync(blueprintPath).sort(); + var actual = walkSync('.').sort(); + + forEach(Blueprint.renamedFiles, function (destFile, srcFile) { + expected[expected.indexOf(srcFile)] = destFile; }); - it('ng init can run in created folder', function() { - return tmp.setup('./tmp/foo') - .then(function() { - process.chdir('./tmp/foo'); - }) - .then(function() { - return ng([ - 'init', - '--skip-npm', - '--skip-bower', - '--name', - 'tmp' - ]); - }) - .then(confirmBlueprinted) - .then(function() { - return tmp.teardown('./tmp/foo'); - }); + expected.forEach(function (file, index) { + expected[index] = file.replace(/__name__/g, 'tmp'); }); - it('init an already init\'d folder', function() { - return ng([ - 'init', - '--skip-npm', - '--skip-bower' - ]) - .then(function(){ - // ignore the favicon file for the the unit test since it breaks at ember-cli level - // when trying to re-init - Blueprint.ignoredFiles.push('favicon.ico'); + removeIgnored(expected); + removeIgnored(actual); + + expected.sort(); + + expect(expected).to.deep.equal( + actual, + EOL + ' expected: ' + util.inspect(expected) + EOL + ' but got: ' + util.inspect(actual)); + } + + function confirmGlobBlueprinted(pattern) { + var blueprintPath = path.join(root, 'addon', 'ng2', 'blueprints', 'ng2', 'files'); + var actual = pickSync('.', pattern); + var expected = intersect(pickSync(blueprintPath, pattern), actual); + + removeIgnored(expected); + removeIgnored(actual); + + expected.sort(); + + expect(expected).to.deep.equal( + actual, + EOL + ' expected: ' + util.inspect(expected) + EOL + ' but got: ' + util.inspect(actual)); + } + + function pickSync(filePath, pattern) { + return glob.sync(path.join('**', pattern), { cwd: filePath, dot: true, mark: true, strict: true }) + .sort(); + } + + function removeIgnored(array) { + remove(array, function (fn) { + return any(Blueprint.ignoredFiles, function (ignoredFile) { + return minimatch(fn, ignoredFile, { matchBase: true }); + }); + }); + } + + it('ng init', function () { + return ng([ + 'init', + '--skip-npm', + '--skip-bower' + ]).then(confirmBlueprinted); + }); + + it('ng init can run in created folder', function () { + return tmp.setup('./tmp/foo') + .then(function () { + process.chdir('./tmp/foo'); }) - .then(function() { + .then(function () { return ng([ 'init', '--skip-npm', - '--skip-bower' + '--skip-bower', + '--name', + 'tmp' ]); }) + .then(confirmBlueprinted) + .then(function () { + return tmp.teardown('./tmp/foo'); + }); + }); + + it('init an already init\'d folder', function () { + return ng(['init', '--skip-npm', '--skip-bower']) + .then(function () { + // ignore the favicon file for the the unit test since it breaks at ember-cli level + // when trying to re-init + Blueprint.ignoredFiles.push('favicon.ico'); + }) + .then(function () { + return ng(['init', '--skip-npm', '--skip-bower']); + }) .then(confirmBlueprinted); - }); + }); - it('init a single file', function() { - return ng([ - 'init', - 'package.json', - '--skip-npm', - '--skip-bower' - ]) - .then(function() { return 'package.json'; }) - .then(confirmGlobBlueprinted); - }); + it('init a single file', function () { + return ng(['init', 'package.json', '--skip-npm', '--skip-bower']) + .then(function () { + return 'package.json'; + }) + .then(confirmGlobBlueprinted); + }); - it('init a single file on already init\'d folder', function() { - return ng([ - 'init', - '--skip-npm', - '--skip-bower' - ]) - .then(function() { - return ng([ - 'init', - 'package.json', - '--skip-npm', - '--skip-bower' - ]); - }) - .then(confirmBlueprinted); - }); + it('init a single file on already init\'d folder', function () { + return ng(['init', '--skip-npm', '--skip-bower']) + .then(function () { + return ng(['init', 'package.json', '--skip-npm', '--skip-bower']); + }) + .then(confirmBlueprinted); + }); - it('init multiple files by glob pattern', function() { - return ng([ - 'init', - 'src/**', - '--skip-npm', - '--skip-bower' - ]) - .then(function() { return 'src/**'; }) - .then(confirmGlobBlueprinted); - }); + it('init multiple files by glob pattern', function () { + return ng(['init', 'src/**', '--skip-npm', '--skip-bower']) + .then(function () { + return 'src/**'; + }) + .then(confirmGlobBlueprinted); + }); - it('init multiple files by glob pattern on already init\'d folder', function() { - return ng([ - 'init', - '--skip-npm', - '--skip-bower' - ]) - .then(function() { - return ng([ - 'init', - 'src/**', - '--skip-npm', - '--skip-bower' - ]); - }) - .then(confirmBlueprinted); - }); + it('init multiple files by glob pattern on already init\'d folder', function () { + return ng(['init', '--skip-npm', '--skip-bower']) + .then(function () { + return ng(['init', 'src/**', '--skip-npm', '--skip-bower']); + }) + .then(confirmBlueprinted); + }); - it('init multiple files by glob patterns', function() { - return ng([ - 'init', - 'src/**', - 'package.json', - '--skip-npm', - '--skip-bower' - ]) - .then(function() { return '{src/**,package.json}'; }) - .then(confirmGlobBlueprinted); - }); + it('init multiple files by glob patterns', function () { + return ng(['init', 'src/**', 'package.json', '--skip-npm', '--skip-bower']) + .then(function () { + return '{src/**,package.json}'; + }) + .then(confirmGlobBlueprinted); + }); - it('init multiple files by glob patterns on already init\'d folder', function() { - return ng([ - 'init', - '--skip-npm', - '--skip-bower' - ]) - .then(function() { - return ng([ - 'init', - 'src/**', - 'package.json', - '--skip-npm', - '--skip-bower' - ]); - }) - .then(confirmBlueprinted); - }); + it('init multiple files by glob patterns on already init\'d folder', function () { + return ng(['init', '--skip-npm', '--skip-bower']) + .then(function () { + return ng(['init', 'src/**', 'package.json', '--skip-npm', '--skip-bower']); + }) + .then(confirmBlueprinted); + }); }); diff --git a/tests/acceptance/new.spec.js b/tests/acceptance/new.spec.js index e73f4ccd3cd2..315b0c1dde85 100644 --- a/tests/acceptance/new.spec.js +++ b/tests/acceptance/new.spec.js @@ -1,206 +1,159 @@ 'use strict'; -var fs = require('fs-extra'); -var ng = require('../helpers/ng'); +var fs = require('fs-extra'); +var ng = require('../helpers/ng'); var existsSync = require('exists-sync'); -var expect = require('chai').expect; -var forEach = require('lodash/forEach'); -var walkSync = require('walk-sync'); -var Blueprint = require('ember-cli/lib/models/blueprint'); -var path = require('path'); -var tmp = require('../helpers/tmp'); -var root = process.cwd(); -var util = require('util'); -var conf = require('ember-cli/tests/helpers/conf'); -var EOL = require('os').EOL; - -describe('Acceptance: ng new', function() { - before(conf.setup); - - after(conf.restore); - - beforeEach(function() { - return tmp.setup('./tmp') - .then(function() { - process.chdir('./tmp'); - }); +var expect = require('chai').expect; +var forEach = require('lodash/forEach'); +var walkSync = require('walk-sync'); +var Blueprint = require('ember-cli/lib/models/blueprint'); +var path = require('path'); +var tmp = require('../helpers/tmp'); +var root = process.cwd(); +var util = require('util'); +var conf = require('ember-cli/tests/helpers/conf'); +var EOL = require('os').EOL; + +describe('Acceptance: ng new', function () { + before(conf.setup); + + after(conf.restore); + + beforeEach(function () { + return tmp.setup('./tmp').then(function () { + process.chdir('./tmp'); }); + }); - afterEach(function() { - this.timeout(10000); + afterEach(function () { + this.timeout(10000); - return tmp.teardown('./tmp'); - }); + return tmp.teardown('./tmp'); + }); - function confirmBlueprintedForDir(dir) { - return function() { - var blueprintPath = path.join(root, dir, 'files'); - var expected = walkSync(blueprintPath); - var actual = walkSync('.').sort(); - var directory = path.basename(process.cwd()); - - forEach(Blueprint.renamedFiles, function(destFile, srcFile) { - expected[expected.indexOf(srcFile)] = destFile; - }); - - expected.forEach(function (file, index) { - expected[index] = file.replace(/__name__/g, 'angular-cli'); - }); - - expected.sort(); - - expect(directory).to.equal('foo'); - expect(expected).to.deep.equal(actual, EOL + ' expected: ' + util.inspect(expected) + - EOL + ' but got: ' + util.inspect(actual)); - - }; - } - - function confirmBlueprinted() { - return confirmBlueprintedForDir('addon/ng2/blueprints/ng2'); - } - - it('ng new foo, where foo does not yet exist, works', function() { - return ng([ - 'new', - 'foo', - '--skip-npm', - '--skip-bower' - ]).then(confirmBlueprinted); - }); + function confirmBlueprintedForDir(dir) { + return function () { + var blueprintPath = path.join(root, dir, 'files'); + var expected = walkSync(blueprintPath); + var actual = walkSync('.').sort(); + var directory = path.basename(process.cwd()); - it('ng new with empty app name doesnt throw exception', function() { - return ng([ - 'new', - '' - ]); - }); + forEach(Blueprint.renamedFiles, function (destFile, srcFile) { + expected[expected.indexOf(srcFile)] = destFile; + }); - it('ng new without app name doesnt throw exception', function() { - return ng([ - 'new' - ]); - }); + expected.forEach(function (file, index) { + expected[index] = file.replace(/__name__/g, 'angular-cli'); + }); - it('ng new with app name creates new directory and has a dasherized package name', function() { - return ng([ - 'new', - 'FooApp', - '--skip-npm', - '--skip-bower', - '--skip-git' - ]).then(function() { - expect(!existsSync('FooApp')); - - var pkgJson = JSON.parse(fs.readFileSync('package.json', 'utf8')); - expect(pkgJson.name).to.equal('foo-app'); - }); - }); + expected.sort(); - it('Cannot run ng new, inside of ember-cli project', function() { - return ng([ - 'new', - 'foo', - '--skip-npm', - '--skip-bower', - '--skip-git' - ]).then(function() { - return ng([ - 'new', - 'foo', - '--skip-npm', - '--skip-bower', - '--skip-git' - ]).then(function() { - expect(!existsSync('foo')); - }); - }).then(confirmBlueprinted); - }); + expect(directory).to.equal('foo'); + expect(expected).to.deep.equal( + actual, + EOL + ' expected: ' + util.inspect(expected) + EOL + ' but got: ' + util.inspect(actual)); - it('ng new with blueprint uses the specified blueprint directory with a relative path', function() { - return tmp.setup('./tmp/my_blueprint') - .then(function() { - return tmp.setup('./tmp/my_blueprint/files'); - }) - .then(function() { - fs.writeFileSync('./tmp/my_blueprint/files/gitignore'); - process.chdir('./tmp'); - - return ng([ - 'new', - 'foo', - '--skip-npm', - '--skip-bower', - '--skip-git', - '--blueprint=./my_blueprint' - ]); - }) - .then(confirmBlueprintedForDir('tmp/my_blueprint')); - }); + }; + } - it('ng new with blueprint uses the specified blueprint directory with an absolute path', function() { - return tmp.setup('./tmp/my_blueprint') - .then(function() { - return tmp.setup('./tmp/my_blueprint/files'); - }) - .then(function() { - fs.writeFileSync('./tmp/my_blueprint/files/gitignore'); - process.chdir('./tmp'); - - return ng([ - 'new', - 'foo', - '--skip-npm', - '--skip-bower', - '--skip-git', - '--blueprint=' + path.resolve(process.cwd(), './my_blueprint') - ]); - }) - .then(confirmBlueprintedForDir('tmp/my_blueprint')); + function confirmBlueprinted() { + return confirmBlueprintedForDir('addon/ng2/blueprints/ng2'); + } + + it('ng new foo, where foo does not yet exist, works', function () { + return ng(['new', 'foo', '--skip-npm', '--skip-bower']).then(confirmBlueprinted); + }); + + it('ng new with empty app name doesnt throw exception', function () { + return ng(['new', '']); + }); + + it('ng new without app name doesnt throw exception', function () { + return ng(['new']); + }); + + it('ng new with app name creates new directory and has a dasherized package name', function () { + return ng(['new', 'FooApp', '--skip-npm', '--skip-bower', '--skip-git']).then(function () { + expect(!existsSync('FooApp')); + + var pkgJson = JSON.parse(fs.readFileSync('package.json', 'utf8')); + expect(pkgJson.name).to.equal('foo-app'); }); + }); - it('ng new without skip-git flag creates .git dir', function(){ - return ng([ - 'new', - 'foo', - '--skip-npm', - '--skip-bower' - ]).then(function() { - expect(existsSync('.git')); + it('Cannot run ng new, inside of ember-cli project', function () { + return ng(['new', 'foo', '--skip-npm', '--skip-bower', '--skip-git']) + .then(function () { + return ng(['new', 'foo', '--skip-npm', '--skip-bower', '--skip-git']).then(function () { + expect(!existsSync('foo')); }); + }) + .then(confirmBlueprinted); + }); + + it('ng new with blueprint uses the specified blueprint directory with a relative path', + function () { + return tmp.setup('./tmp/my_blueprint') + .then(function () { + return tmp.setup('./tmp/my_blueprint/files'); + }) + .then(function () { + fs.writeFileSync('./tmp/my_blueprint/files/gitignore'); + process.chdir('./tmp'); + + return ng([ + 'new', 'foo', '--skip-npm', '--skip-bower', '--skip-git', + '--blueprint=./my_blueprint' + ]); + }) + .then(confirmBlueprintedForDir('tmp/my_blueprint')); }); - it('ng new with --dry-run does not create new directory', function(){ - return ng([ - 'new', - 'foo', - '--dry-run' - ]).then(function(){ - var cwd = process.cwd(); - expect(cwd).to.not.match(/foo/, 'does not change cwd to foo in a dry run'); - expect(!existsSync(path.join(cwd, 'foo')), 'does not create new directory'); - expect(!existsSync(path.join(cwd, '.git')), 'does not create git in current directory'); - }); + it('ng new with blueprint uses the specified blueprint directory with an absolute path', + function () { + return tmp.setup('./tmp/my_blueprint') + .then(function () { + return tmp.setup('./tmp/my_blueprint/files'); + }) + .then(function () { + fs.writeFileSync('./tmp/my_blueprint/files/gitignore'); + process.chdir('./tmp'); + + return ng([ + 'new', 'foo', '--skip-npm', '--skip-bower', '--skip-git', + '--blueprint=' + path.resolve(process.cwd(), './my_blueprint') + ]); + }) + .then(confirmBlueprintedForDir('tmp/my_blueprint')); }); - it('ng new with --directory uses given directory name and has correct package name', function() { - return ng([ - 'new', - 'foo', - '--skip-npm', - '--skip-bower', - '--skip-git', - '--directory=bar' - ]).then(function() { - var cwd = process.cwd(); - expect(cwd).to.not.match(/foo/, 'does not use app name for directory name'); - expect(!existsSync(path.join(cwd, 'foo')), 'does not create new directory with app name'); - - expect(cwd).to.match(/bar/, 'uses given directory name'); - expect(existsSync(path.join(cwd, 'bar')), 'creates new directory with specified name'); - - var pkgJson = JSON.parse(fs.readFileSync('package.json', 'utf8')); - expect(pkgJson.name).to.equal('foo', 'uses app name for package name'); - }); + it('ng new without skip-git flag creates .git dir', function () { + return ng(['new', 'foo', '--skip-npm', '--skip-bower']).then(function () { + expect(existsSync('.git')); + }); + }); + + it('ng new with --dry-run does not create new directory', function () { + return ng(['new', 'foo', '--dry-run']).then(function () { + var cwd = process.cwd(); + expect(cwd).to.not.match(/foo/, 'does not change cwd to foo in a dry run'); + expect(!existsSync(path.join(cwd, 'foo')), 'does not create new directory'); + expect(!existsSync(path.join(cwd, '.git')), 'does not create git in current directory'); }); -}); \ No newline at end of file + }); + + it('ng new with --directory uses given directory name and has correct package name', function () { + return ng(['new', 'foo', '--skip-npm', '--skip-bower', '--skip-git', '--directory=bar']) + .then(function () { + var cwd = process.cwd(); + expect(cwd).to.not.match(/foo/, 'does not use app name for directory name'); + expect(!existsSync(path.join(cwd, 'foo')), 'does not create new directory with app name'); + + expect(cwd).to.match(/bar/, 'uses given directory name'); + expect(existsSync(path.join(cwd, 'bar')), 'creates new directory with specified name'); + + var pkgJson = JSON.parse(fs.readFileSync('package.json', 'utf8')); + expect(pkgJson.name).to.equal('foo', 'uses app name for package name'); + }); + }); +}); diff --git a/tests/e2e/e2e_workflow.spec.js b/tests/e2e/e2e_workflow.spec.js index 0ba2a4109135..21d7c36d5c8c 100644 --- a/tests/e2e/e2e_workflow.spec.js +++ b/tests/e2e/e2e_workflow.spec.js @@ -1,14 +1,14 @@ 'use strict'; -var fs = require('fs'); -var path = require('path'); -var tmp = require('../helpers/tmp'); -var chai = require('chai'); -var expect = chai.expect; -var conf = require('ember-cli/tests/helpers/conf'); -var sh = require('shelljs'); -var ng = require('../helpers/ng'); -var root = path.join(process.cwd(), 'tmp'); +var fs = require('fs'); +var path = require('path'); +var tmp = require('../helpers/tmp'); +var chai = require('chai'); +var expect = chai.expect; +var conf = require('ember-cli/tests/helpers/conf'); +var sh = require('shelljs'); +var ng = require('../helpers/ng'); +var root = path.join(process.cwd(), 'tmp'); function existsSync(path) { try { @@ -24,11 +24,7 @@ describe('Basic end-to-end Workflow', function () { after(conf.restore); - var testArgs = [ - 'test', - '--watch', - 'false' - ]; + var testArgs = ['test', '--watch', 'false']; // In travis CI only run tests in Chrome_travis_ci if (process.env.TRAVIS) { @@ -36,82 +32,70 @@ describe('Basic end-to-end Workflow', function () { testArgs.push('Chrome_travis_ci'); } - it('Installs angular-cli correctly', function() { + it('Installs angular-cli correctly', function () { this.timeout(300000); - sh.exec('npm link', {silent: true}); - return tmp.setup('./tmp') - .then(function () { - process.chdir('./tmp'); - expect(existsSync(path.join(process.cwd(), 'bin', 'ng'))); - }); + sh.exec('npm link', { silent: true }); + return tmp.setup('./tmp').then(function () { + process.chdir('./tmp'); + expect(existsSync(path.join(process.cwd(), 'bin', 'ng'))); + }); }); - it('Can create new project using `ng new test-project`', function() { + it('Can create new project using `ng new test-project`', function () { this.timeout(420000); - return ng([ - 'new', - 'test-project', - '--silent' - ]).then(function() { + return ng(['new', 'test-project', '--silent']).then(function () { expect(existsSync(path.join(root, 'test-project'))); }); }); - it('Can change current working directory to `test-project`', function() { + it('Can change current working directory to `test-project`', function () { this.timeout(420000); process.chdir(path.join(root, 'test-project')); - sh.exec('npm link angular-cli', {silent: true}); + sh.exec('npm link angular-cli', { silent: true }); expect(path.basename(process.cwd())).to.equal('test-project'); }); - it('Can run `ng build` in created project', function() { + it('Can run `ng build` in created project', function () { this.timeout(420000); - return ng([ - 'build', - '--silent' - ]).then(function() { - expect(existsSync(path.join(process.cwd(), 'dist'))).to.be.equal(true); - }).then(function() { - // Also does not create new things in GIT. - expect(sh.exec('git status --porcelain').output).to.be.equal(''); - }).catch((err) => { - throw new Error('Build failed.'); - }); + return ng(['build', '--silent']) + .then(function () { + expect(existsSync(path.join(process.cwd(), 'dist'))).to.be.equal(true); + }) + .then(function () { + // Also does not create new things in GIT. + expect(sh.exec('git status --porcelain').output).to.be.equal(''); + }) + .catch(() => { + throw new Error('Build failed.'); + }); }); - it('Produces a service worker manifest after initial build', function() { + it('Produces a service worker manifest after initial build', function () { var manifestPath = path.join(process.cwd(), 'dist', 'manifest.appcache'); expect(existsSync(manifestPath)).to.be.equal(true); // Read the worker. - var lines = fs - .readFileSync(manifestPath, {encoding: 'utf8'}) - .trim() - .split('\n'); + //TODO: Commenting this out because it makes eslint fail(need to figure out why this expect was commented out) + // var lines = fs.readFileSync(manifestPath, {encoding: 'utf8'}).trim().split('\n'); // Check that a few critical files have been detected. - //expect(lines).to.include(`${path.sep}index.html`); + // expect(lines).to.include(`${path.sep}index.html`); }); - it('Perform `ng test` after initial build', function() { + it('Perform `ng test` after initial build', function () { this.timeout(420000); - return ng(testArgs) - .then(function(result) { + return ng(testArgs).then(function (result) { const exitCode = typeof result === 'object' ? result.exitCode : result; expect(exitCode).to.be.equal(0); }); }); - it('Can create a test component using `ng generate component test-component`', function() { + it('Can create a test component using `ng generate component test-component`', function () { this.timeout(10000); - return ng([ - 'generate', - 'component', - 'test-component' - ]).then(function() { + return ng(['generate', 'component', 'test-component']).then(function () { var componentDir = path.join(process.cwd(), 'src', 'app', 'components', 'test-component'); expect(existsSync(componentDir)); expect(existsSync(path.join(componentDir, 'test-component.ts'))); @@ -120,22 +104,17 @@ describe('Basic end-to-end Workflow', function () { }); }); - it('Perform `ng test` after adding a component', function() { + it('Perform `ng test` after adding a component', function () { this.timeout(420000); - return ng(testArgs) - .then(function(result) { + return ng(testArgs).then(function (result) { const exitCode = typeof result === 'object' ? result.exitCode : result; expect(exitCode).to.be.equal(0); }); }); - it('Can create a test service using `ng generate service test-service`', function() { - return ng([ - 'generate', - 'service', - 'test-service' - ]).then(function() { + it('Can create a test service using `ng generate service test-service`', function () { + return ng(['generate', 'service', 'test-service']).then(function () { var serviceDir = path.join(process.cwd(), 'src', 'app', 'services', 'test-service'); expect(existsSync(serviceDir)); expect(existsSync(path.join(serviceDir, 'test-service.ts'))); @@ -143,22 +122,17 @@ describe('Basic end-to-end Workflow', function () { }); }); - it('Perform `ng test` after adding a service', function() { + it('Perform `ng test` after adding a service', function () { this.timeout(420000); - return ng(testArgs) - .then(function(result) { + return ng(testArgs).then(function (result) { const exitCode = typeof result === 'object' ? result.exitCode : result; expect(exitCode).to.be.equal(0); }); }); - it('Can create a test pipe using `ng generate pipe test-pipe`', function() { - return ng([ - 'generate', - 'pipe', - 'test-pipe' - ]).then(function() { + it('Can create a test pipe using `ng generate pipe test-pipe`', function () { + return ng(['generate', 'pipe', 'test-pipe']).then(function () { var pipeDir = path.join(process.cwd(), 'src', 'app', 'pipes', 'test-pipe'); expect(existsSync(pipeDir)); expect(existsSync(path.join(pipeDir, 'test-pipe.ts'))); @@ -166,22 +140,17 @@ describe('Basic end-to-end Workflow', function () { }); }); - it('Perform `ng test` after adding a pipe', function() { + it('Perform `ng test` after adding a pipe', function () { this.timeout(420000); - return ng(testArgs) - .then(function(result) { + return ng(testArgs).then(function (result) { const exitCode = typeof result === 'object' ? result.exitCode : result; expect(exitCode).to.be.equal(0); }); }); - it('Can create a test route using `ng generate route test-route`', function() { - return ng([ - 'generate', - 'route', - 'test-route' - ]).then(function() { + it('Can create a test route using `ng generate route test-route`', function () { + return ng(['generate', 'route', 'test-route']).then(function () { var routeDir = path.join(process.cwd(), 'src', 'app', 'test-route'); expect(existsSync(routeDir)); expect(existsSync(path.join(routeDir, 'test-pipe-detail.component.css'))); @@ -198,11 +167,10 @@ describe('Basic end-to-end Workflow', function () { }); }); - it('Perform `ng test` after adding a route', function() { + it('Perform `ng test` after adding a route', function () { this.timeout(420000); - return ng(testArgs) - .then(function(result) { + return ng(testArgs).then(function (result) { const exitCode = typeof result === 'object' ? result.exitCode : result; expect(exitCode).to.be.equal(0); }); @@ -219,18 +187,17 @@ describe('Basic end-to-end Workflow', function () { sh.rm('-rf', path.join(process.cwd(), 'dist')); - return ng([ - 'build', - '--silent' - ]).then(function() { - expect(existsSync(path.join(process.cwd(), 'dist'))).to.be.equal(true); - }).catch((err) => { + return ng(['build', '--silent']) + .then(function () { + expect(existsSync(path.join(process.cwd(), 'dist'))).to.be.equal(true); + }) + .catch(() => { throw new Error('Build failed.'); }) - .finally(function(){ + .finally(function () { // Clean `tmp` folder process.chdir(path.resolve(root, '..')); - sh.rm('-rf', './tmp'); // tmp.teardown takes too long + sh.rm('-rf', './tmp'); // tmp.teardown takes too long done(); }); }); diff --git a/tests/helpers/mock-analytics.js b/tests/helpers/mock-analytics.js index d0564d42a87f..114540256f0d 100644 --- a/tests/helpers/mock-analytics.js +++ b/tests/helpers/mock-analytics.js @@ -2,22 +2,22 @@ module.exports = MockAnalytics; function MockAnalytics() { - this.tracks = []; - this.trackTimings = []; - this.trackErrors = []; + this.tracks = []; + this.trackTimings = []; + this.trackErrors = []; } MockAnalytics.prototype = Object.create({}); MockAnalytics.prototype.track = function(arg) { - this.tracks.push(arg); + this.tracks.push(arg); }; MockAnalytics.prototype.trackTiming = function(arg) { - this.trackTimings.push(arg); + this.trackTimings.push(arg); }; MockAnalytics.prototype.trackError = function(arg) { - this.trackErrors.push(arg); + this.trackErrors.push(arg); }; MockAnalytics.prototype.constructor = MockAnalytics; diff --git a/tests/helpers/mock-ui.js b/tests/helpers/mock-ui.js index ca55f3c38036..fbfd941cb9fb 100644 --- a/tests/helpers/mock-ui.js +++ b/tests/helpers/mock-ui.js @@ -1,46 +1,46 @@ 'use strict'; -var UI = require('ember-cli/lib/ui'); +var UI = require('ember-cli/lib/ui'); var through = require('through'); var Promise = require('ember-cli/lib/ext/promise'); module.exports = MockUI; function MockUI() { - this.output = ''; + this.output = ''; - UI.call(this, { - inputStream: through(), - outputStream: through(function(data) { - this.output += data; - }.bind(this)), - errorStream: through(function(data) { - this.errors += data; - }.bind(this)) - }); + UI.call(this, { + inputStream: through(), + outputStream: through(function (data) { + this.output += data; + }.bind(this)), + errorStream: through(function (data) { + this.errors += data; + }.bind(this)) + }); } MockUI.prototype = Object.create(UI.prototype); MockUI.prototype.constructor = MockUI; -MockUI.prototype.clear = function(){ - this.output = ''; +MockUI.prototype.clear = function () { + this.output = ''; }; -MockUI.prototype.waitForPrompt = function() { - if (!this._waitingForPrompt) { - var promise, resolver; - promise = new Promise(function(resolve){ - resolver = resolve; - }); - this._waitingForPrompt = promise; - this._promptResolver = resolver; - } - return this._waitingForPrompt; +MockUI.prototype.waitForPrompt = function () { + if (!this._waitingForPrompt) { + var promise, resolver; + promise = new Promise(function (resolve) { + resolver = resolve; + }); + this._waitingForPrompt = promise; + this._promptResolver = resolver; + } + return this._waitingForPrompt; }; -MockUI.prototype.prompt = function(opts, cb) { - if (this._waitingForPrompt) { - this._waitingForPrompt = null; - this._promptResolver(); - } - return UI.prototype.prompt.call(this, opts, cb); +MockUI.prototype.prompt = function (opts, cb) { + if (this._waitingForPrompt) { + this._waitingForPrompt = null; + this._promptResolver(); + } + return UI.prototype.prompt.call(this, opts, cb); }; diff --git a/tests/helpers/ng.js b/tests/helpers/ng.js index 954d169cb517..f69c045c2c48 100644 --- a/tests/helpers/ng.js +++ b/tests/helpers/ng.js @@ -1,22 +1,22 @@ 'use strict'; -var MockUI = require('./mock-ui'); +var MockUI = require('./mock-ui'); var MockAnalytics = require('./mock-analytics'); -var Cli = require('../../lib/cli'); +var Cli = require('../../lib/cli'); module.exports = function ng(args) { - var cli; - - process.env.PWD = process.cwd(); - - cli = new Cli({ - inputStream: [], - outputStream: [], - cliArgs: args, - Leek: MockAnalytics, - UI: MockUI, - testing: true - }); + var cli; - return cli; + process.env.PWD = process.cwd(); + + cli = new Cli({ + inputStream: [], + outputStream: [], + cliArgs: args, + Leek: MockAnalytics, + UI: MockUI, + testing: true + }); + + return cli; }; diff --git a/tests/helpers/tmp.js b/tests/helpers/tmp.js index dadd0589eba1..f9ae335b22c3 100644 --- a/tests/helpers/tmp.js +++ b/tests/helpers/tmp.js @@ -1,26 +1,25 @@ 'use strict'; -var fs = require('fs-extra'); -var existsSync = require('exists-sync'); +var fs = require('fs-extra'); +var existsSync = require('exists-sync'); var Promise = require('ember-cli/lib/ext/promise'); -var remove = Promise.denodeify(fs.remove); -var root = process.cwd(); +var remove = Promise.denodeify(fs.remove); +var root = process.cwd(); -module.exports.setup = function(path) { - process.chdir(root); +module.exports.setup = function (path) { + process.chdir(root); - return remove(path) - .then(function() { - fs.mkdirsSync(path); - }); + return remove(path).then(function () { + fs.mkdirsSync(path); + }); }; -module.exports.teardown = function(path) { - process.chdir(root); +module.exports.teardown = function (path) { + process.chdir(root); - if (existsSync(path)) { - return remove(path); - } else { - return Promise.resolve(); - } + if (existsSync(path)) { + return remove(path); + } else { + return Promise.resolve(); + } }; diff --git a/tests/runner.js b/tests/runner.js index 5958c74fda28..4b89bf271ca6 100644 --- a/tests/runner.js +++ b/tests/runner.js @@ -5,14 +5,11 @@ var glob = require('glob'); var root = 'tests/{unit,acceptance,e2e}'; var specFiles = glob.sync(root + '/**/*.spec.js'); -var mocha = new Mocha({ - timeout: 5000, - reporter: 'spec' -}); +var mocha = new Mocha({ timeout: 5000, reporter: 'spec' }); specFiles.forEach(mocha.addFile.bind(mocha)); -mocha.run(function(failures){ +mocha.run(function (failures) { process.on('exit', function () { process.exit(failures); }); diff --git a/tslint.json b/tslint.json new file mode 100644 index 000000000000..f5d2ac212a52 --- /dev/null +++ b/tslint.json @@ -0,0 +1,63 @@ +{ + "rules": { + "max-line-length": [true, 100], + "no-inferrable-types": true, + "class-name": true, + "comment-format": [ + true, + "check-space" + ], + "indent": [ + true, + "spaces" + ], + "eofline": true, + "no-duplicate-variable": true, + "no-eval": true, + "no-arg": true, + "no-internal-module": true, + "no-trailing-whitespace": true, + "no-bitwise": true, + "no-shadowed-variable": true, + "no-unused-expression": true, + "no-unused-variable": true, + "one-line": [ + true, + "check-catch", + "check-else", + "check-open-brace", + "check-whitespace" + ], + "quotemark": [ + true, + "single", + "avoid-escape" + ], + "semicolon": [true, "always"], + "typedef-whitespace": [ + true, + { + "call-signature": "nospace", + "index-signature": "nospace", + "parameter": "nospace", + "property-declaration": "nospace", + "variable-declaration": "nospace" + } + ], + "curly": true, + "variable-name": [ + true, + "ban-keywords", + "check-format", + "allow-trailing-underscore" + ], + "whitespace": [ + true, + "check-branch", + "check-decl", + "check-operator", + "check-separator", + "check-type" + ] + } +}