Skip to content

Commit

Permalink
Feature/support for vendor prefix (#70)
Browse files Browse the repository at this point in the history
* Added support for vendor prefix

You can now enter an optional vendor prefix. This way it looks like : /Project|Feature|Foundation/[optional vendor prefix/]/Projectname.

* Updated README.md. Now it also lists vendorprefix variable.

* Added tests for the vendorprefix functionality
The empty vendorprefix issue should be handled correctly. And the vendorprefix now actually is a prefix. ;)
  • Loading branch information
saberone authored and Saturate committed Feb 27, 2017
1 parent 0aa3692 commit 862f719
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 5 deletions.
4 changes: 2 additions & 2 deletions generators/add/Templates/_Serialization.config
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
singleInstance="true"
/>
<predicate type="Unicorn.Predicates.SerializationPresetPredicate, Unicorn" singleInstance="true">
<include name="Templates" database="master" path="/sitecore/templates/<%= layer %>/<%= projectname %>"/>
<include name="Renderings" database="master" path="/sitecore/layout/Renderings/<%= layer %>/<%= projectname %>"/>
<include name="Templates" database="master" path="/sitecore/templates/<% if (vendorprefix) { %><%= vendorprefix %>/<% } %><%= layer %>/<%= projectname %>"/>
<include name="Renderings" database="master" path="/sitecore/layout/Renderings/<% if (vendorprefix) { %><%= vendorprefix %>/<% } %><%= layer %>/<%= projectname %>"/>
</predicate>
</configuration>
</configurations>
Expand Down
19 changes: 17 additions & 2 deletions generators/add/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module.exports = class extends yeoman {
constructor(args, opts) {
super(args, opts);
this.argument('ProjectName', { type: String, required: false, desc: 'Name of the project' });
this.argument('VendorPrefix', { type: String, required: false, desc: 'Vendor prefix used in the creation of project structure' });
}

init() {
Expand All @@ -37,7 +38,14 @@ module.exports = class extends yeoman {
name:'sourceFolder',
message:'Source code folder name',
default: 'src'
}];
},
{
type:'input',
name:'VendorPrefix',
message:'Enter optional vendor prefix',
default: this.options.VendorPrefix
}
];

this.prompt(questions).then((answers) => {
this.settings = answers;
Expand Down Expand Up @@ -66,7 +74,13 @@ module.exports = class extends yeoman {

this.prompt(questions).then((answers) => {
this.layer = answers.layer;
this.settings.LayerPrefixedProjectName = this.layer + '.' + this.settings.ProjectName;

if (this.settings.VendorPrefix === '' || this.settings.VendorPrefix === undefined ) {
this.settings.LayerPrefixedProjectName = `${this.layer}.${this.settings.ProjectName}`
} else {
this.settings.LayerPrefixedProjectName = `${this.settings.VendorPrefix}.${this.layer}.${this.settings.ProjectName}`
}

done();
});
}
Expand Down Expand Up @@ -100,6 +114,7 @@ module.exports = class extends yeoman {
_buildTemplateData() {
this.templatedata.layerprefixedprojectname = this.settings.LayerPrefixedProjectName;
this.templatedata.projectname = this.settings.ProjectName;
this.templatedata.vendorprefix = this.settings.VendorPrefix;
this.templatedata.projectguid = guid.v4();
this.templatedata.layer = this.layer;
this.templatedata.lowercasedlayer = this.layer.toLowerCase();;
Expand Down
3 changes: 2 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ To create a Helix solution run the following command in an empty root folder whe
To add a new project to an existing run the following command in the root directory, that contains the VS solution file.
You can call with the Project Name, if you do not you will be prompted to enter it.

> yo helix:add [ProjectName]
> yo helix:add [ProjectName] [VendorPrefix]
### Extending the add generator

Expand All @@ -52,6 +52,7 @@ This means that if you need to inject the data from the generator to your files
* projectguid
* layer
* target
* vendorprefix

The one special case is that if you have a file called _project.csproj in the folder it will copy it and then rename it to the correct Project name.
This way you can create your own project file that matches your specific needs.
Expand Down
58 changes: 58 additions & 0 deletions test/test-add.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,62 @@ describe('yo helix:add', function () {
done();
});
});

it('Can add on a emptyhelix solution with vendorprefix', function checkFiles (done) {
helpers.run(path.join(__dirname, '../generators/add'))
.inTmpDir(function () {
var doneParent = this.async(); // `this` is the RunContext object.
helpers.run(path.join(__dirname, '../generators/app'))
.withPrompts({
SolutionType: 'emptyhelix',
SolutionName: 'UnitTest',
target: 'v4.6.1'
}).then(() => {
doneParent();
});
})
.withPrompts({
ProjectName: 'AddedProjectFeatureName',
VendorPrefix: 'Acme',
layer: 'Feature'
}).then(() => {

assert.file([
'./src/Feature/AddedProjectFeatureName/code/Acme.Feature.AddedProjectFeatureName.csproj'
]);

done();
});

});

it('Can add on a emptyhelix solution with empty vendorprefix', function checkFiles (done) {
// This test might seem unnecessary. But when you run the code normally an empty value from the prompt is an empty string,
// but in a test context it's 'undefined'
helpers.run(path.join(__dirname, '../generators/add'))
.inTmpDir(function () {
var doneParent = this.async(); // `this` is the RunContext object.
helpers.run(path.join(__dirname, '../generators/app'))
.withPrompts({
SolutionType: 'emptyhelix',
SolutionName: 'UnitTest',
target: 'v4.6.1'
}).then(() => {
doneParent();
});
})
.withPrompts({
ProjectName: 'AddedProjectFeatureName',
VendorPrefix: '',
layer: 'Feature'
}).then(() => {

assert.file([
'./src/Feature/AddedProjectFeatureName/code/Feature.AddedProjectFeatureName.csproj'
]);

done();
});

});
});

0 comments on commit 862f719

Please sign in to comment.