Skip to content

Commit 8f4ab05

Browse files
committed
Linter files
- Related #15
1 parent 8fddabb commit 8f4ab05

File tree

2 files changed

+90
-91
lines changed

2 files changed

+90
-91
lines changed

generators/app/index.js

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -7,52 +7,52 @@ const path = require('path');
77
const templatesFolder = path.join(__dirname, 'templates');
88

99
module.exports = yeoman.Base.extend({
10-
prompting: function() {
11-
return this.prompt([{
12-
type : 'input',
13-
name : 'name',
14-
message : 'Your service name',
15-
default : this.appname.replace(/\s+/g, '-')
16-
},
17-
{
18-
type : 'input',
19-
name : 'description',
20-
message : 'A brief description',
21-
default : ''
22-
}]).then(function (_answers) {
23-
this.props = _answers;
24-
this.props.components = ['app', 'config', 'logging', 'express', 'routes'];
25-
}.bind(this));
26-
},
27-
writing: {
28-
config: function() {
29-
this._copyFiles('config', 'config');
30-
this._copyFiles('root', '.');
31-
},
32-
app: function() {
33-
this._copyAppFiles();
34-
}
35-
},
36-
install: function() {
37-
return this.installDependencies({ npm: true, bower: false });
38-
},
39-
end: function() {
40-
var outputMsg = `\n\nYour service ${this.props.name} has been created.\nnpm run start - start your systemic service`;
41-
this.log(yosay(outputMsg));
42-
},
43-
_copyFiles: function(from, to) {
44-
const configFiles = fs.readdirSync(path.join(templatesFolder, from));
45-
const self = this;
46-
_.forEach(configFiles, function(file) {
47-
self.fs.copyTpl(self.templatePath(`./${from}/${file}`), self.destinationPath(`${to}/${file.replace(/^_/, '')}`), self.props);
48-
});
49-
},
50-
_copyAppFiles: function() {
51-
const self = this;
52-
this.fs.copy(this.templatePath('./test/.eslintrc'), this.destinationPath('./test/.eslintrc'));
53-
this.fs.copy(this.templatePath('./test/*'), this.destinationPath('./test/'));
54-
_.forEach(this.props.components, function(component) {
55-
self.fs.copy(self.templatePath(`./lib/components/${component}/*`), self.destinationPath(`./components/${component}/`));
56-
});
57-
}
10+
prompting() {
11+
return this.prompt([{
12+
type: 'input',
13+
name: 'name',
14+
message: 'Your service name',
15+
default: this.appname.replace(/\s+/g, '-'),
16+
},
17+
{
18+
type: 'input',
19+
name: 'description',
20+
message: 'A brief description',
21+
default: '',
22+
}]).then(_answers => {
23+
this.props = _answers;
24+
this.props.components = ['app', 'config', 'logging', 'express', 'routes'];
25+
});
26+
},
27+
writing: {
28+
config() {
29+
this._copyFiles('config', 'config');
30+
this._copyFiles('root', '.');
31+
},
32+
app() {
33+
this._copyAppFiles();
34+
},
35+
},
36+
install() {
37+
return this.installDependencies({ npm: true, bower: false });
38+
},
39+
end() {
40+
const outputMsg = `\n\nYour service ${this.props.name} has been created.\nnpm run start - start your systemic service`;
41+
this.log(yosay(outputMsg));
42+
},
43+
_copyFiles(from, to) {
44+
const configFiles = fs.readdirSync(path.join(templatesFolder, from));
45+
const self = this;
46+
_.forEach(configFiles, file => {
47+
self.fs.copyTpl(self.templatePath(`./${from}/${file}`), self.destinationPath(`${to}/${file.replace(/^_/, '')}`), self.props);
48+
});
49+
},
50+
_copyAppFiles() {
51+
const self = this;
52+
this.fs.copy(this.templatePath('./test/.eslintrc'), this.destinationPath('./test/.eslintrc'));
53+
this.fs.copy(this.templatePath('./test/*'), this.destinationPath('./test/'));
54+
_.forEach(this.props.components, component => {
55+
self.fs.copy(self.templatePath(`./lib/components/${component}/*`), self.destinationPath(`./components/${component}/`));
56+
});
57+
},
5858
});

test/no-components.tests.js

Lines changed: 42 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -4,50 +4,49 @@ const helpers = require('yeoman-test');
44
const assert = require('yeoman-assert');
55

66
describe('Systemic basic services with no extra components', () => {
7+
const generateService = (components, next) => {
8+
helpers.run(path.join(__dirname, '../generators/app'))
9+
.withPrompts({
10+
name: 'test-service',
11+
description: 'some description',
12+
components,
13+
})
14+
.on('error', next)
15+
.on('end', next);
16+
};
717

8-
const generateService = (components, next) => {
9-
helpers.run(path.join(__dirname, '../generators/app'))
10-
.withPrompts({
11-
name: 'test-service',
12-
description: 'some description',
13-
components: components
14-
})
15-
.on('error', next)
16-
.on('end', next);
17-
};
18+
it('should create a service with proper configuration', done => {
19+
const targetComponents = [];
20+
generateService(targetComponents, () => {
21+
assert.file(['config/default.js', 'config/local.js', 'config/prod.js', 'config/test.js', 'config/build.js']);
22+
assert.fileContent('config/default.js', /service/);
23+
assert.fileContent('config/default.js', /transport: 'console'/);
24+
assert.fileContent('config/default.js', /swaggerOptions/);
25+
assert.fileContent('config/default.js', /swaggerDefinition/);
26+
assert.fileContent('config/local.js', /transport: 'console'/);
27+
assert.noFileContent('config/prod.js', /logger/);
28+
assert.fileContent('config/test.js', /transport: null/);
29+
assert.fileContent('config/build.js', /transport: null/);
30+
done();
31+
});
32+
});
1833

19-
it('should create a service with proper configuration', (done) => {
20-
const targetComponents = [ ];
21-
generateService(targetComponents, () => {
22-
assert.file([ 'config/default.js', 'config/local.js', 'config/prod.js', 'config/test.js', 'config/build.js' ]);
23-
assert.fileContent('config/default.js', /service/);
24-
assert.fileContent('config/default.js', /transport: \'console\'/);
25-
assert.fileContent('config/default.js', /swaggerOptions/);
26-
assert.fileContent('config/default.js', /swaggerDefinition/);
27-
assert.fileContent('config/local.js', /transport: \'console\'/);
28-
assert.noFileContent('config/prod.js', /logger/);
29-
assert.fileContent('config/test.js', /transport: null/);
30-
assert.fileContent('config/build.js', /transport: null/);
31-
done();
32-
});
33-
});
34+
it('should create a service with proper components folder', done => {
35+
const targetComponents = [];
36+
generateService(targetComponents, () => {
37+
assert.file(['components/app/index.js']);
38+
assert.file(['components/config/confabulous.js', 'components/config/index.js']);
39+
assert.file(['components/config/confabulous.js', 'components/config/index.js']);
40+
assert.file(['components/logging/bunyan.js', 'components/logging/console.js', 'components/logging/index.js', 'components/logging/prepper.js']);
41+
done();
42+
});
43+
});
3444

35-
it('should create a service with proper components folder', (done) => {
36-
const targetComponents = [ ];
37-
generateService(targetComponents, () => {
38-
assert.file([ 'components/app/index.js' ]);
39-
assert.file([ 'components/config/confabulous.js', 'components/config/index.js' ]);
40-
assert.file([ 'components/config/confabulous.js', 'components/config/index.js' ]);
41-
assert.file([ 'components/logging/bunyan.js', 'components/logging/console.js', 'components/logging/index.js', 'components/logging/prepper.js' ]);
42-
done();
43-
});
44-
});
45-
46-
it('should create a service with basic files', (done) => {
47-
const targetComponents = [ ];
48-
generateService(targetComponents, () => {
49-
assert.file([ '.dockerignore', '.eslintrc.json', '.gitignore', '.nvmrc', 'Dockerfile', 'index.js', 'package.json', 'README.md', 'system.js' ]);
50-
done();
51-
});
52-
});
45+
it('should create a service with basic files', done => {
46+
const targetComponents = [];
47+
generateService(targetComponents, () => {
48+
assert.file(['.dockerignore', '.eslintrc.json', '.gitignore', '.nvmrc', 'Dockerfile', 'index.js', 'package.json', 'README.md', 'system.js']);
49+
done();
50+
});
51+
});
5352
});

0 commit comments

Comments
 (0)