diff --git a/.travis.yml b/.travis.yml index 035b89d14753..5aafb9687986 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,7 +10,6 @@ before_install: - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.30.1/install.sh | bash; fi - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then source ~/.nvm/nvm-exec; fi - nvm install $NODE_VERSION - - npm link npm - npm config set spin false install: - node --version diff --git a/addon/ng2/tasks/lib-install.js b/addon/ng2/tasks/lib-install.js index af58f8b4a20e..b23f8e14f3ff 100644 --- a/addon/ng2/tasks/lib-install.js +++ b/addon/ng2/tasks/lib-install.js @@ -3,7 +3,7 @@ var Promise = require('ember-cli/lib/ext/promise'); var Task = require('ember-cli/lib/models/task'); -var npm = require('ember-cli/lib/utilities/npm'); +var shellPromise = require ('../utilities/shell-promise'); var existsSync = require('exists-sync'); var chalk = require('chalk'); var path = require('path'); @@ -18,36 +18,30 @@ module.exports = Task.extend({ completionOKMessage: '', completionErrorMessage: 'Error installing packages. Did you misspelt it?', - init: function() { - this.npm = this.npm || require('npm'); - }, run: function(options) { this.packages = options.packages || []; this.skipInjection = options.skipInjection || false; this.autoInjection = options.autoInjection || false; this.disableLogger(); - this.ui.startProgress(chalk.green('Installing 3rd party package:', + this.ui.startProgress(chalk.green('Installing 3rd party package:', this.packages.join(', ')), chalk.green('.')); - this.npmOptions = { - logLevel: 'error', - logstream: this.ui.outputStream, - color: 'always', - optional: true, - 'save-dev': true, - 'save-exact': !!options['save-exact'] - }; - - return npm('install', this.packages, this.npmOptions, this.npm) - .then(function(npmresp) { + this.npmOptions = ' --loglevel error --color always --optional --save-dev ' + + '--save-exact ' + !!options['save-exact']; + + var npmCommand = 'npm install ' + this.packages.join(' ') + this.npmOptions; + + return shellPromise(npmCommand) + .then(function (npmresp) { + if (this.skipInjection) { return this.announceOKCompletion(); } if (this.autoInjection) { var pkg = this.packages[0]; - + if (existsSync(path.resolve(process.cwd(), 'src', 'app.ts'))) { var entryPoint = path.resolve(process.cwd(), 'src', 'app.ts'); var packageData = this.parseFile(pkg); @@ -57,10 +51,10 @@ module.exports = Task.extend({ return this.announceOKCompletion(); } - return this.installProcedure() - .then(function(resp) { - return this.announceOKCompletion(); - }.bind(this)); + return this.installProcedure(); + }.bind(this)) + .then(function(resp) { + return this.announceOKCompletion(); }.bind(this)); }, @@ -83,12 +77,14 @@ module.exports = Task.extend({ 'as authentic: ' + allPackages.toUninstall.join(', '); this.ui.writeLine(chalk.yellow(msg)); - return npm('uninstall', allPackages.toUninstall, this.npmOptions, this.npm) + var npmCommand = 'npm uninstall ' + allPackages.toUninstall.join(' ') + this.npmOptions; + + return shellPromise(npmCommand) .then(function() { return this.processPackages(allPackages.toProcess) - .then(function(resp) { - return resolve(resp); - }); + .then(function(resp) { + return resolve(resp); + }); }.bind(this)); } else { @@ -133,7 +129,7 @@ module.exports = Task.extend({ return new Promise(function(resolve, reject) { var packageData; - var msg = 'Customize the injection of ' + + var msg = 'Customize the injection of ' + chalk.yellow(path.basename(packageName)) + '? (Y/n)'; return this.ui.prompt({ @@ -226,7 +222,7 @@ module.exports = Task.extend({ type: 'input', name: 'sel', message: msg, - filter: function (val) { return val.trim(); }, + filter: function (val) { return val.trim(); }, validate: function(value) { return value > 0 && value <= packageData[componentKey].length ? true : 'Enter a valid value'; } @@ -260,8 +256,8 @@ module.exports = Task.extend({ packageName, packageData[componentKey][componentIndex]); - this.injectItem(componentKey.toLowerCase(), - packageData[componentKey][componentIndex], + this.injectItem(componentKey.toLowerCase(), + packageData[componentKey][componentIndex], possibleFiles[fileIndex]); this.ui.writeLine(chalk.green('Successfully injected.')); @@ -336,8 +332,8 @@ module.exports = Task.extend({ if (removeNextLine) { arr.splice(index, 1); - if (/;/.test(line)) { - removeNextLine = false; + if (/;/.test(line)) { + removeNextLine = false; } } }); @@ -348,12 +344,12 @@ module.exports = Task.extend({ function generateFlatImportLine(arr, fromIndex) { var lineArr = []; var lastIndex; - + arr.forEach(function(line, index) { if (index >= fromIndex && !lastIndex) { lineArr.push(line); - if (/;/.test(line)) { - lastIndex = true; + if (/;/.test(line)) { + lastIndex = true; } } }); @@ -443,7 +439,7 @@ module.exports = Task.extend({ if (/\)/.test(line)) { replace = line.match(/\((.*?)\)/)[0]; - } + } else { replace = contentsArr.splice(index, contentsArr.length - 1).join('\n').replace(/\n/g, ''); replace = replace.match(/\((.*?)\)/)[0]; @@ -495,7 +491,7 @@ module.exports = Task.extend({ match = match.replace(/[\[\]]/g, ''); match = match.split(','); match.push(name); - match = match.filter(function(n) { return n !== ''; } ); + match = match.filter(function(n) { return n !== ''; } ); contentsArr[index] = contentsArr[index].replace(replace, '[' + match.join(',') + ']'); } }.bind(this)); @@ -505,14 +501,14 @@ module.exports = Task.extend({ parseFile: function (packageName) { var packagePath = path.join(process.cwd(), 'node_modules', packageName, packageName + '.ts'); - + if (!existsSync(packagePath)) { return false; } var contents = fs.readFileSync(packagePath, 'utf8'); var data = {}; - + data.Component = []; data.Directive = []; data.Pipe = []; diff --git a/addon/ng2/tasks/lib-uninstall.js b/addon/ng2/tasks/lib-uninstall.js index 6771ba6758ec..d4f68e2ee6ed 100644 --- a/addon/ng2/tasks/lib-uninstall.js +++ b/addon/ng2/tasks/lib-uninstall.js @@ -3,7 +3,7 @@ var Promise = require('ember-cli/lib/ext/promise'); var Task = require('ember-cli/lib/models/task'); -var npm = require('ember-cli/lib/utilities/npm'); +var shellPromise = require ('../utilities/shell-promise'); var existsSync = require('exists-sync'); var chalk = require('chalk'); var path = require('path'); @@ -19,34 +19,27 @@ module.exports = Task.extend({ completionOKMessage: '', completionErrorMessage: 'Error uninstalling packages. Did you misspelt it?', - init: function() { - this.npm = this.npm || require('npm'); - }, run: function(options) { this.packages = options.packages || []; this.autoRemove = options.autoRemove || false; this.disableLogger(); - this.ui.startProgress(chalk.green('Uninstalling 3rd party package:', + this.ui.startProgress(chalk.green('Uninstalling 3rd party package:', this.packages.join(', ')), chalk.green('.')); - this.npmOptions = { - logLevel: 'error', - logstream: this.ui.outputStream, - color: 'always', - optional: true, - 'save-dev': true, - 'save-exact': !!options['save-exact'] - }; - this.getPackagesDataBeforeRemoved(this.packages); - return npm('uninstall', this.packages, this.npmOptions, this.npm) + this.npmOptions = ' --loglevel error --color always --optional --save-dev ' + + '--save-exact ' + !!options['save-exact']; + + var npmCommand = 'npm uninstall ' + this.packages.join(' ') + this.npmOptions; + + return shellPromise(npmCommand) .then(function(npmresp) { if (!npmresp.length) { this.completionErrorMessage = 'No packages uninstalled.'; return this.announceErrorCompletion(); - } + } else { if (this.autoRemove) { this.removePackagesFromApp(); @@ -60,7 +53,6 @@ module.exports = Task.extend({ } } }.bind(this)); - }, uninstallProcedure: function() { @@ -86,14 +78,14 @@ module.exports = Task.extend({ parseFile: function (packageName) { var packagePath = path.resolve(process.cwd(), 'node_modules', packageName, packageName + '.ts'); - + if (!existsSync(packagePath)) { return false; } var contents = fs.readFileSync(packagePath, 'utf8'); var data = {}; - + data.Directive = []; data.Pipe = []; data.Provider = []; @@ -170,7 +162,7 @@ module.exports = Task.extend({ cleanAfterRemoval: function(contents) { var bootstrap = false; - contents = contents.filter(function(line) { + contents = contents.filter(function(line) { if (/bootstrap\(/.test(line)) { bootstrap = true; } @@ -227,4 +219,4 @@ module.exports = Task.extend({ console.log = this.oldLog; // Hack, see above } -}); \ No newline at end of file +}); diff --git a/addon/ng2/utilities/shell-promise.js b/addon/ng2/utilities/shell-promise.js new file mode 100644 index 000000000000..5b74717cbe55 --- /dev/null +++ b/addon/ng2/utilities/shell-promise.js @@ -0,0 +1,16 @@ +/* jshint node: true */ +'use strict'; + +var Promise = require('ember-cli/lib/ext/promise'); +var sh = require('shelljs'); + +module.exports = function shellPromise(command) { + return new Promise(function(resolve, reject) { + return sh.exec(command, { + silent: true + }, function(code, stdout, stderr) { + if (code !== 0) reject(stderr); + else resolve(stdout); + }); + }); +}; diff --git a/package.json b/package.json index 31191b8bd455..66e3af806de6 100644 --- a/package.json +++ b/package.json @@ -43,6 +43,7 @@ "node-notifier": "^4.4.0", "resolve": "^1.0.0", "silent-error": "^1.0.0", + "shelljs": "^0.5.3", "symlink-or-copy": "^1.0.1", "typescript": "~1.7.3", "typings": "^0.6.2" @@ -60,7 +61,6 @@ "minimatch": "^2.0.10", "mocha": "^2.2.5", "rewire": "^2.3.4", - "shelljs": "^0.5.3", "through": "^2.3.8", "walk-sync": "^0.2.6" } diff --git a/tests/e2e/e2e_workflow.spec.js b/tests/e2e/e2e_workflow.spec.js index 00a81ca039d2..658ff68224bc 100644 --- a/tests/e2e/e2e_workflow.spec.js +++ b/tests/e2e/e2e_workflow.spec.js @@ -18,11 +18,10 @@ describe('Basic end-to-end Workflow', 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'); - - sh.exec('npm i angular-cli -g -C ' + process.cwd(), { silent: true }); expect(fs.existsSync(path.join(process.cwd(), 'bin', 'ng'))); }); }); @@ -40,7 +39,9 @@ describe('Basic end-to-end Workflow', function () { }); it('Can change current working directory to `test-project`', function() { + this.timeout(300000); process.chdir(path.join(root, 'test-project')); + sh.exec('npm link angular-cli', {silent: true}); expect(path.basename(process.cwd())).to.equal('test-project'); });