Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[Suggestion] Handling relative path when initiating component #941

Merged
merged 1 commit into from
Oct 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/cli/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ module.exports = {
},

init: {
cmd: 'init <componentName> [templateType]',
cmd: 'init <componentPath> [templateType]',
example: {
cmd: '$0 init test-component oc-template-es6'
},
description:
'Create a new empty component of a specific template type in the current folder [templateType default: oc-template-es6]',
usage: 'Usage: $0 init <componentName> [templateType]'
'Create a new empty component of a specific template type in the current folder or in directory indicated by (relative) componentPath [templateType default: oc-template-es6]',
usage: 'Usage: $0 init <componentPath> [templateType]'
},

mock: {
Expand Down
11 changes: 3 additions & 8 deletions src/cli/facade/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ module.exports = function(dependencies) {
logger = dependencies.logger;

return function(opts, callback) {
const componentName = opts.componentName;
const templateType = _.isUndefined(opts.templateType)
? 'oc-template-es6'
: opts.templateType;
const errors = strings.errors.cli;
const messages = strings.messages.cli;
const componentPath = path.join(process.cwd(), componentName);
const componentPath = path.join(process.cwd(), opts.componentPath);
const componentName = path.basename(componentPath);

callback = wrapCliCallback(callback);
local.init(
Expand All @@ -39,12 +39,7 @@ module.exports = function(dependencies) {
}
logger.err(format(errors.INIT_FAIL, err));
} else {
logger.log(
messages.initSuccess(
componentName,
path.join(process.cwd(), componentName)
)
);
logger.log(messages.initSuccess(componentName, componentPath));
}

callback(err, componentName);
Expand Down
27 changes: 25 additions & 2 deletions test/unit/cli-facade-init.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ describe('cli : facade : init', () => {
local = new Local({ logger: { log: () => {} } }),
initFacade = new InitFacade({ local: local, logger: logSpy });

const execute = function(componentName, templateType) {
const execute = function(componentPath, templateType) {
logSpy.err = sinon.spy();
logSpy.ok = sinon.spy();
logSpy.log = sinon.spy();
initFacade(
{ componentName: componentName, templateType: templateType },
{ componentPath: componentPath, templateType: templateType },
() => {}
);
};
Expand Down Expand Up @@ -81,6 +81,29 @@ describe('cli : facade : init', () => {
});
});

describe('when the component has relative path', () => {
beforeEach(() => {
sinon.stub(local, 'init').yields(null, 'yes man');
execute('this/is/relative/path/to/the-best-component', 'jade');
});

afterEach(() => {
local.init.restore();
});

it('should show a correct name in the log message', () => {
expect(logSpy.log.args[0][0]).to.contain(
'Success! Created the-best-component at'
);
});

it('should show a correct path in the log message', () => {
expect(logSpy.log.args[0][0]).to.contain(
'/this/is/relative/path/to/the-best-component'
);
});
});

describe('when succeeds', () => {
beforeEach(() => {
sinon.stub(local, 'init').yields(null, 'yes man');
Expand Down