Skip to content

Commit

Permalink
Merge pull request #394 from Windvis/emberNew-extra-arguments
Browse files Browse the repository at this point in the history
Add an `extraCliArgs` option to the `emberNew` helper
  • Loading branch information
NullVoxPopuli authored Jan 13, 2025
2 parents e86b189 + dccf643 commit e224224
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ Create a new Ember.js app or addon in the current working directory.

- `{Object} [options]` optional parameters
- `{String} [options.target='app']` the type of project to create (`app`, `addon` or `in-repo-addon`)
- `{string[]} [options.extraCliArgs=[]]` any extra arguments you want to pass to ember-cli

**Returns:** `{Promise}`

Expand Down
4 changes: 3 additions & 1 deletion lib/ember-new.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const rethrowFromErrorLog = require('./rethrow-from-error-log');
*
* @param {Object} [options] optional parameters
* @param {String} [options.target='app'] the type of project to create (`app`, `addon` or `in-repo-addon`)
* @param {string[]} [options.extraCliArgs] any extra arguments you want to pass to ember-cli
* @returns {Promise}
*/
module.exports = function(options) {
Expand All @@ -22,12 +23,13 @@ module.exports = function(options) {

let projectName = isAddon ? 'my-addon' : 'my-app';
let command = isAddon ? 'addon' : 'new';
let extraCliArgs = Array.isArray(options.extraCliArgs) ? options.extraCliArgs : [];

let cliOptions = {
disableDependencyChecker: true
};

return ember([command, projectName, '--skip-npm', '--skip-bower'], cliOptions)
return ember([command, projectName, '--skip-npm', '--skip-bower', ...extraCliArgs], cliOptions)
.then(generateInRepoAddon(target))
.then(linkAddon)
.catch(rethrowFromErrorLog);
Expand Down
2 changes: 1 addition & 1 deletion tests/acceptance/helpers-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const expect = chai.expect;
const dir = chai.dir;
const file = chai.file;

describe('Acceptance: helpers', function() {
describe('Acceptance: helpers', function () {
setupTestHooks(this);

describe('emberNew', () => {
Expand Down
38 changes: 38 additions & 0 deletions tests/unit/ember-new-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
'use strict';
const setupTestHooks = require('../../lib/helpers/setup');

const chai = require('../../chai');
const expect = chai.expect;
const td = require('testdouble')

let ember;

describe('Unit: emberNew', function () {
setupTestHooks(this);

afterEach(() => {
td.reset();
ember = undefined;
});

it('emberNew - extraCliArgs', () => {
const originalEmber = require('../../lib/helpers/ember.js');
ember = td.replace('../../lib/helpers/ember.js');

// "spy" on the original ember function.
// testdouble.js doesn't have built-in support for this because it considers it a bad practise:
// https://github.com/testdouble/testdouble.js/issues/512#issuecomment-1527511338
td.when(ember(td.matchers.contains('--typescript', '--no-welcome'), td.matchers.anything())).thenDo((...args) => {
return originalEmber(...args);
});

// We require emberNew here so the testdouble dependency replacement works
const emberNew = require('../../lib/ember-new');

return emberNew({ extraCliArgs: ['--typescript', '--no-welcome'] })
.then(() => {
// If we get here that means our testdouble matcher worked and things were called as expected.
expect(true).to.be.true;
});
});
});

0 comments on commit e224224

Please sign in to comment.