Skip to content

Commit

Permalink
add linting, code coverage and more tests to generators (hyperledger-…
Browse files Browse the repository at this point in the history
…archives#3515)

Signed-off-by: Nick Lincoln <[email protected]>
  • Loading branch information
nklincoln authored Mar 2, 2018
1 parent 80fce09 commit 0fdec3a
Show file tree
Hide file tree
Showing 28 changed files with 666 additions and 131 deletions.
4 changes: 1 addition & 3 deletions packages/generator-hyperledger-composer/.eslintignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
coverage
node_modules
out
chaincode/src/**
lib/parser/parser.js
generators/**/templates/**
generators/angular/**
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';
const Util = require('./../util');
let yeoman = require('yeoman-generator');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

// Karma configuration file, see link for more information
// https://karma-runner.github.io/0.13/config/configuration-file.html

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"@angular/cli": "1.0.1",
"@angular/compiler-cli": "^4.0.0",
"@types/jasmine": "2.5.38",
"@types/node": "~6.0.60",
"@types/node": "7.0.5",
"codelyzer": "~2.0.0",
"jasmine-core": "~2.5.2",
"jasmine-spec-reporter": "~3.2.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

// Protractor configuration file, see link for more information
// https://github.com/angular/protractor/blob/master/lib/config.ts

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,3 @@ if (environment.production) {
}

platformBrowserDynamic().bootstrapModule(AppModule);

38 changes: 17 additions & 21 deletions packages/generator-hyperledger-composer/generators/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,23 @@
'use strict';

let generators = require('yeoman-generator');
let optionOrPrompt = require('yeoman-option-or-prompt');
let Util = require('../util');

module.exports = generators.Base.extend({

_optionOrPrompt: optionOrPrompt,

constructor: function() {
generators.Base.apply(this, arguments);
this.options = this.env.options;
},

/**
* @returns {Object} List of questions to ask
*/
* @returns {Object} List of questions to ask
*/
prompting: function() {
console.log('Welcome to the Hyperledger Composer project generator');
Util.log('Welcome to the Hyperledger Composer project generator');
const questions = [{
type: 'list',
name: 'generatorType',
Expand All @@ -47,35 +51,27 @@ module.exports = generators.Base.extend({
}
],
store: true,
validate: function(input) {
if(input !== null && input !== undefined) {
return true;
} else {
return 'Generator type must be defined';
}
}
validate: Util.validateGeneratorType
}];
return this.prompt(questions).then(answers => {
this.generatorType = answers.generatorType;
});

return this._optionOrPrompt(questions)
.then((answers) => {
this.generatorType = answers.generatorType;
});
},

configuring: function() {
if(this.generatorType === 'Angular'){
console.log('You can run this generator using: \'yo hyperledger-composer:angular\'');
Util.log('You can run this generator using: \'yo hyperledger-composer:angular\'');
this.composeWith(require.resolve('../angular'));
} else if (this.generatorType === 'businessnetwork') {
console.log('You can run this generator using: \'yo hyperledger-composer:businessnetwork\'');
Util.log('You can run this generator using: \'yo hyperledger-composer:businessnetwork\'');
this.composeWith(require.resolve('../businessnetwork'));
} else if (this.generatorType === 'model') {
console.log('You can run this generator using: \'yo hyperledger-composer:model\'');
Util.log('You can run this generator using: \'yo hyperledger-composer:model\'');
this.composeWith(require.resolve('../model'));
} else{
console.log('Generator type not recognised');
Util.log('Generator type not recognised');
}
},




});
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
coverage
node_modules
out
chaincode/src/**
lib/parser/parser.js
generators/**/templates/**
Original file line number Diff line number Diff line change
@@ -1,16 +1,29 @@
'use strict';
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

const Util = require('./../util');
'use strict';

let yeoman = require('yeoman-generator');
let optionOrPrompt = require('yeoman-option-or-prompt');
let Util = require('../util');

module.exports = yeoman.Base.extend({

_optionOrPrompt: optionOrPrompt,

prompting: function() {
console.log('Welcome to the business network generator');
Util.log('Welcome to the business network generator');

let questions = [
{
Expand Down Expand Up @@ -79,6 +92,7 @@ module.exports = yeoman.Base.extend({
this.fs.copyTpl(this.templatePath('**!(models|lib|test)*'), this.destinationPath(), model);
this.fs.copyTpl(this.templatePath('models/namespace.cto'), this.destinationPath('models/'+this.namespace+'.cto'), model);
this.fs.move(this.destinationPath('_dot_eslintrc.yml'), this.destinationPath('.eslintrc.yml'), model);
/* istanbul ignore else */
if (!this.ismodel) {
this.fs.copyTpl(this.templatePath('./test'), this.destinationPath('./test'), model);
this.fs.copyTpl(this.templatePath('./lib'), this.destinationPath('./lib'), model);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';
/**
* Write your transction processor functions here
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';
/**
* Write the unit tests for your transction processor functions here
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
coverage
node_modules
out
chaincode/src/**
lib/parser/parser.js
generators/**/templates/**
76 changes: 29 additions & 47 deletions packages/generator-hyperledger-composer/generators/model/index.js
Original file line number Diff line number Diff line change
@@ -1,105 +1,87 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

let yeoman = require('yeoman-generator');
let optionOrPrompt = require('yeoman-option-or-prompt');
let Util = require('../util');

module.exports = yeoman.Base.extend({

_optionOrPrompt: optionOrPrompt,

constructor: function() {
yeoman.Base.apply(this, arguments);
this.options = this.env.options;
},

prompting: function() {
console.log('Welcome to the model generator');
Util.log('Welcome to the model generator');

let questions = [
{
type: 'input',
name: 'appname',
message: 'Model project name:',
store: true,
validate: function(input) {
if(input !== null && input !== undefined && input !== '' && input.indexOf(' ') === -1 && input === input.toLowerCase()) {
return true;
} else {
return 'Name cannot be null, empty or contain a space or uppercase character.';
}
}
validate: Util.validateBusinessNetworkName
},
{
type: 'input',
name: 'appdescription',
message: 'Description:',
store: true,
validate: function(input) {
if(input !== null && input !== undefined && input !== '') {
return true;
} else {
return 'Description cannot be null or empty.';
}
}
validate: Util.validateDescription
},
{
type: 'input',
name: 'appauthor',
message: 'Author name: ',
store: true,
validate: function(input) {
if(input !== null && input !== undefined && input !== '') {
return true;
} else {
return 'Author name cannot be null or empty.';
}
}
validate: Util.validateAuthorName
},
{
type: 'input',
name: 'appemail',
message: 'Author email:',
store: true,
validate: function(input) {
if(input !== null && input !== undefined && input !== '') {
return true;
}
else {
return 'Author email cannot be null or empty.';
}
}
validate: Util.validateAuthorEmail
},
{
type: 'input',
name: 'applicense',
message: 'License:',
default: 'Apache-2.0',
store: true,
validate: function(input) {
if(input !== null && input !== undefined && input !== '') {
return true;
} else {
return 'Licence cannot be null or empty.';
}
}
validate: Util.validateLicense
},
{
type: 'input',
name: 'namespace',
name: 'ns',
message: 'Namespace:',
default: 'org.acme.biznet',
store: true,
validate: function(input) {
if(input !== null && input !== undefined && input.match(/^(?:[a-z]\d*(?:\.[a-z])?)+$/)) {
return true;
} else {
return 'Name must mactch: ^(?:[a-z]\d*(?:\.[a-z])?)+$';
}
}
validate: Util.validateNamespace
}
];

return this.prompt(questions)
return this._optionOrPrompt(questions)
.then((answers) => {
this.appname = answers.appname;
this.appemail = answers.appemail;
this.namespace = answers.namespace;
this.namespace = answers.ns;
this.appdescription = answers.appdescription;
this.appauthor = answers.appauthor;
this.applicense = answers.applicense;
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# <%= namespace%>
# <%= appname%>

<%= appdescription%>
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ participant User identified by email {
o String email
}

asset Asset identified by assetId {
asset SampleAsset identified by assetId {
o String assetId
o String value
}

transaction ChangeAssetValue {
o String transactionId
o String newValue
--> Asset relatedAsset
}
}
Loading

0 comments on commit 0fdec3a

Please sign in to comment.