Skip to content

Commit

Permalink
Merge pull request #20 from robertoachar/develop
Browse files Browse the repository at this point in the history
v3.0.0
  • Loading branch information
robertoachar authored May 7, 2019
2 parents 31c00d4 + d654496 commit 091b123
Show file tree
Hide file tree
Showing 18 changed files with 210 additions and 143 deletions.
3 changes: 3 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": ["@babel/preset-env"]
}
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ logs
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
Expand Down
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
# Changelog

## v3.0.0

### Template Updates

- **feature**: add esm
- **refactor**: update .gitignore
- **style**: add module

### Generator Updates

- **build**: update dependencies
- **docs**: update README
- **feature**: add esm
- **fix**: change generator entry point
- **refactor**: update .gitignore

## v2.3.1

### Template Updates
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
This generator provides the following features:

- **src** and **test** folder as a starter point to build your project.
- **esm** as a simple, babel-less, bundle-less ECMAScript module loader.
- **EditorConfig** to help you define and maintain consistent coding styles between different editors.
- **ESLint** to provide a pluggable linting utility for JavaScript.
- **Prettier** as an opinionated code formatter.
Expand Down Expand Up @@ -43,6 +44,7 @@ This generator provides the following features:
|--- CHANGELOG.md
|--- circle.yml
|--- LICENSE
|--- main.js
|--- package.json
|--- README.md
```
Expand Down
6 changes: 5 additions & 1 deletion generators/app/files.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
module.exports = [
const files = [
{ template: 'src/index.js.template', destination: 'src/index.js' },
{ template: 'test/test.js.template', destination: 'test/test.js' },
{ template: 'appveyor.yml.template', destination: 'appveyor.yml' },
{ template: 'babelrc.template', destination: '.babelrc' },
{ template: 'CHANGELOG.md.template', destination: 'CHANGELOG.md' },
{ template: 'circle.yml.template', destination: 'circle.yml' },
{ template: 'editorconfig.template', destination: '.editorconfig' },
Expand All @@ -11,8 +12,11 @@ module.exports = [
{ template: 'gitignore.template', destination: '.gitignore' },
{ template: 'LICENSE.template', destination: 'LICENSE' },
{ template: 'npmrc.template', destination: '.npmrc' },
{ template: 'main.js.template', destination: 'main.js' },
{ template: 'package.json.template', destination: 'package.json' },
{ template: 'prettierrc.template', destination: '.prettierrc' },
{ template: 'README.md.template', destination: 'README.md' },
{ template: 'travis.yml.template', destination: '.travis.yml' }
];

export default files;
107 changes: 3 additions & 104 deletions generators/app/index.js
Original file line number Diff line number Diff line change
@@ -1,106 +1,5 @@
const Generator = require('yeoman-generator');
/* eslint no-global-assign: 0 */

const files = require('./files');
const validate = require('./validate');
require = require('esm')(module);

module.exports = class extends Generator {
initializing() {
this.log('OSS Project Generator');
this.log('❤️ Made with love by Roberto Achar');
this.log();
}

prompting() {
const done = this.async();

const prompts = [
{
type: 'input',
name: 'project',
message: 'What is the name of your project?',
default: 'awesome-project'
},
{
type: 'input',
name: 'description',
message: 'What is the description of your project?',
default: 'An awesome project'
},
{
type: 'input',
name: 'name',
message: 'What is your name?',
validate: validate.validateName,
store: true
},
{
type: 'input',
name: 'email',
message: 'What is your email?',
validate: validate.validateEmail,
store: true
},
{
type: 'input',
name: 'username',
message: 'What is your GitHub username?',
validate: validate.validateUsername,
store: true
}
];

this.prompt(prompts).then((props) => {
this.props = props;
done();
});
}

writing() {
this.log();
this.log('🚀 Generating project...');
this.log();

const { project, description, name, email, username } = this.props;

const templates = {
project,
description,
name,
email,
username,
year: new Date().getFullYear()
};

files.forEach((file) => {
this.fs.copyTpl(
this.templatePath(file.template),
this.destinationPath(file.destination),
templates
);
});
}

install() {
this.log();
this.log('📦 Installing dependencies...');
this.log();

this.npmInstall(
[
'@types/jest',
'coveralls',
'eslint',
'eslint-config-prettier',
'eslint-plugin-prettier',
'jest',
'prettier'
],
{ 'save-dev': true }
);
}

end() {
this.log();
this.log('🎉 Successfully generated!');
}
};
module.exports = require('./main');
111 changes: 111 additions & 0 deletions generators/app/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
import Generator from 'yeoman-generator';

import files from './files';
import { validateEmail, validateName, validateUsername } from './validate';

class OSSGenerator extends Generator {
initializing() {
this.log('OSS Project Generator');
this.log('❤️ Made with love by Roberto Achar');
this.log();
}

prompting() {
const done = this.async();

const prompts = [
{
type: 'input',
name: 'project',
message: 'What is the name of your project?',
default: 'awesome-project'
},
{
type: 'input',
name: 'description',
message: 'What is the description of your project?',
default: 'An awesome project'
},
{
type: 'input',
name: 'name',
message: 'What is your name?',
validate: validateName,
store: true
},
{
type: 'input',
name: 'email',
message: 'What is your email?',
validate: validateEmail,
store: true
},
{
type: 'input',
name: 'username',
message: 'What is your GitHub username?',
validate: validateUsername,
store: true
}
];

this.prompt(prompts).then((props) => {
this.props = props;
done();
});
}

writing() {
this.log();
this.log('🚀 Generating project...');
this.log();

const { project, description, name, email, username } = this.props;

const templates = {
project,
description,
name,
email,
username,
year: new Date().getFullYear()
};

files.forEach((file) => {
this.fs.copyTpl(
this.templatePath(file.template),
this.destinationPath(file.destination),
templates
);
});
}

install() {
this.log();
this.log('📦 Installing dependencies...');
this.log();

this.npmInstall(['esm']);

this.npmInstall(
[
'@babel/preset-env',
'@types/jest',
'coveralls',
'eslint',
'eslint-config-prettier',
'eslint-plugin-prettier',
'jest',
'prettier'
],
{ 'save-dev': true }
);
}

end() {
this.log();
this.log('🎉 Successfully generated!');
}
}

export default OSSGenerator;
3 changes: 3 additions & 0 deletions generators/app/templates/babelrc.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": ["@babel/preset-env"]
}
3 changes: 3 additions & 0 deletions generators/app/templates/eslintrc.json.template
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@
"env": {
"es6": true,
"jest": true
},
"parserOptions": {
"sourceType": "module"
}
}
4 changes: 4 additions & 0 deletions generators/app/templates/gitignore.template
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ logs
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
Expand Down
5 changes: 5 additions & 0 deletions generators/app/templates/main.js.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/* eslint no-global-assign: 0 */

require = require('esm')(module);

module.exports = require('./src');
6 changes: 3 additions & 3 deletions generators/app/templates/package.json.template
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
"keywords": [
"node"
],
"main": "src/index.js",
"main": "main.js",
"files": [
"src"
],
"scripts": {
"coverage": "jest --colors --coverage",
"coveralls": "npm run coverage && cat ./coverage/lcov.info | coveralls",
"jest": "jest --colors --verbose",
"lint": "eslint src/**/*.js test/**/*.js",
"start": "node src/index.js",
"lint": "eslint 'src/**/*.js' 'test/**/*.js'",
"start": "node main.js",
"test": "npm run lint && npm run jest"
},
"repository": {
Expand Down
4 changes: 3 additions & 1 deletion generators/app/templates/src/index.js.template
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
module.exports.hello = () => new Promise((resolve) => resolve('It works!'));
const hello = () => new Promise((resolve) => resolve('Hello!'));

export default hello;
6 changes: 3 additions & 3 deletions generators/app/templates/test/test.js.template
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const lib = require('../src');
import hello from '../src';

describe('TESTS', () => {
test('Basic test', (done) => {
lib.hello().then((message) => {
expect(message).toBe('It works!');
hello().then((message) => {
expect(message).toBe('Hello!');
done();
});
});
Expand Down
14 changes: 8 additions & 6 deletions generators/app/validate.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
module.exports.validateName = (value) => {
const validateName = (value) => {
if (value.length === 0) {
return 'You need to enter your name';
return 'Enter your name';
}

return true;
};

module.exports.validateEmail = (value) => {
const validateEmail = (value) => {
if (value.length === 0) {
return 'You need to enter your email';
return 'Enter your email';
}

return true;
};

module.exports.validateUsername = (value) => {
const validateUsername = (value) => {
if (value.length === 0) {
return 'You need to enter your username';
return 'Enter your username';
}

return true;
};

export { validateEmail, validateName, validateUsername };
Loading

0 comments on commit 091b123

Please sign in to comment.