generator-arc-component
Advanced tools
Comparing version 1.0.1 to 1.0.2
126
app/index.js
var Generator = require('yeoman-generator'); | ||
var slugify = require('slugify'); | ||
const validators = { | ||
notnull : function(input){ | ||
return !!input; | ||
}, | ||
startsWithCaps : function(input){ | ||
return !!input.match(/^[_A-Z]+[A-z_0-9a-z]*$/); | ||
} | ||
} | ||
module.exports = class extends Generator { | ||
@@ -8,8 +16,33 @@ constructor(args,opts){ | ||
} | ||
initializing(){ | ||
return new Promise(function(res,rej){ | ||
this.config.set('author',this.user.git.name() || ''); | ||
this.config.set('email',this.user.git.email() || ''); | ||
this.user.github.username(function(err,username){ | ||
if(err){ | ||
rej(err); | ||
}else{ | ||
this.config.set('github_username',username); | ||
res(username); | ||
} | ||
}.bind(this)); | ||
}.bind(this)); | ||
} | ||
prompting() { | ||
var self = this; | ||
var defaults = { | ||
'appname' : slugify(this.appname), | ||
'description' : 'Accessible react component', | ||
'author' : this.config.get('author') , | ||
'email' : this.config.get('email') , | ||
'github_username' : this.config.get('github_username'), | ||
'root_component_name' : 'MyComponent', | ||
'confirm_generate_license' : true | ||
} | ||
return this.prompt([{ | ||
type : 'input', | ||
name : 'name', | ||
name : 'appname', | ||
message : 'Your project name', | ||
default : slugify(this.appname) // Default to current folder name | ||
default : defaults['appname'] // Default to current folder name | ||
},{ | ||
@@ -19,3 +52,3 @@ type : 'input', | ||
message : 'Your project description', | ||
default : 'Accessible react component'// Default to current folder name | ||
default : defaults['description']// Default to current folder name | ||
},{ | ||
@@ -25,13 +58,40 @@ type : 'input', | ||
message : 'Your name', | ||
default : '' // Default to current folder name | ||
default : defaults['author'], // Default to current folder name, | ||
validate : validators.notnull | ||
},{ | ||
type : 'input', | ||
name : 'license', | ||
message : 'LICENSE', | ||
default : 'IST' // Default to current folder name | ||
name : 'email', | ||
message : 'Your email', | ||
default : defaults['email'], // Default to current folder name, | ||
validate : validators.notnull | ||
},{ | ||
type : 'input', | ||
name : 'github_username', | ||
message : 'Your github username', | ||
default : defaults['github_username'], // Default to current folder name | ||
validate : validators.notnull | ||
},{ | ||
type : 'input', | ||
name : 'root_component_name', | ||
message : 'Class name of the component ', | ||
default : defaults['root_component_name'], // Default to current folder name | ||
validate : validators.startsWithCaps | ||
},{ | ||
type : 'confirm', | ||
name : 'confirm_generate_license', | ||
message : 'Generate MIT license?', | ||
default : defaults['confirm_generate_license'] // Default to current folder name | ||
}]).then((answers) => { | ||
this.config.set('name',answers.name); | ||
this.config.set('appname',answers.appname); | ||
this.config.set('author',answers.author); | ||
this.config.set('license',answers.license); | ||
this.config.set('email',answers.email); | ||
this.config.set('github_username',answers.github_username); | ||
this.config.set('confirm_generate_license',answers.confirm_generate_license); | ||
if(answers.confirm_generate_license){ | ||
this.config.set('license','MIT'); | ||
}else{ | ||
this.config.set('license',''); | ||
} | ||
this.config.set('description',answers.description); | ||
this.config.set('root_component_name',answers.root_component_name); | ||
}); | ||
@@ -60,3 +120,3 @@ } | ||
{ | ||
appname : this.config.get('name'), | ||
appname : this.config.get('appname'), | ||
author : this.config.get('author'), | ||
@@ -71,4 +131,6 @@ license : this.config.get('license'), | ||
{ | ||
appname : this.config.get('name'), | ||
description : this.config.get('description') | ||
appname : this.config.get('appname'), | ||
description : this.config.get('description'), | ||
license : this.config.get('license'), | ||
github_username : this.config.get('github_username') | ||
} | ||
@@ -80,3 +142,3 @@ ); | ||
{ | ||
appname : this.config.get('name') | ||
appname : this.config.get('appname') | ||
} | ||
@@ -86,19 +148,45 @@ ); | ||
this.templatePath('test/index.js'), | ||
this.destinationPath('test/index.js') | ||
this.destinationPath('test/index.js'), | ||
{ | ||
root_component_name : this.config.get('root_component_name') | ||
} | ||
); | ||
this.fs.copyTpl( | ||
this.templatePath('src/index.js'), | ||
this.destinationPath('src/index.js') | ||
this.destinationPath('src/index.js'), | ||
{ | ||
root_component_name : this.config.get('root_component_name') | ||
} | ||
); | ||
this.fs.copyTpl( | ||
this.templatePath('dev/main.js'), | ||
this.destinationPath('dev/main.js') | ||
this.templatePath('playground/main.js'), | ||
this.destinationPath('playground/main.js'), | ||
{ | ||
root_component_name : this.config.get('root_component_name') | ||
} | ||
); | ||
this.fs.copyTpl( | ||
this.templatePath('dev/template.html'), | ||
this.destinationPath('dev/template.html') | ||
this.templatePath('playground/template.html'), | ||
this.destinationPath('playground/template.html'), | ||
{ | ||
root_component_name : this.config.get('root_component_name') | ||
} | ||
); | ||
if(this.config.get('confirm_generate_license')){ | ||
var year = (new Date()).getFullYear(); | ||
var yearStr = year+'-'+(year+1)%100; | ||
this.fs.copyTpl( | ||
this.templatePath('LICENSE'), | ||
this.destinationPath('LICENSE'), | ||
{ | ||
author : this.config.get('author'), | ||
email : this.config.get('email'), | ||
yearStr : yearStr | ||
} | ||
); | ||
} | ||
} | ||
@@ -105,0 +193,0 @@ installingWebpack(){ |
@@ -9,3 +9,2 @@ { | ||
"start": "NODE_ENV=development webpack-dev-server --hot --history-api-fallback", | ||
"start-prod": "npm run clean && NODE_ENV=production webpack", | ||
"build": "NODE_ENV=production npm run clean && webpack", | ||
@@ -12,0 +11,0 @@ "test" : "ava" |
# <%= appname %> | ||
<img src="https://travis-ci.org/<%= github_username %>/<%= appname %>.svg?branch=master" alt="build status"/> | ||
### <%= description %> | ||
### Usage | ||
**Dev** | ||
Runs webpack dev server on the playground | ||
```bash | ||
npm start | ||
``` | ||
**Test** | ||
Runs ava | ||
```bash | ||
npm test | ||
``` | ||
**Build** | ||
Generates build in dist folder | ||
```bash | ||
npm run build | ||
``` | ||
**LICENSE** | ||
<%= license %> |
import React from 'react'; | ||
export default class MyComponent extends React.Component{ | ||
export default class <%= root_component_name %> extends React.Component{ | ||
render(){ | ||
return <p>MyComponent</p>; | ||
return <p><%= root_component_name %></p>; | ||
} | ||
} |
import test from 'ava'; | ||
import MyComponent from '../src'; | ||
import <%= root_component_name %> from '../src'; | ||
import React from 'react' | ||
@@ -7,4 +7,4 @@ import { shallow, mount } from 'enzyme'; | ||
test('component renders correctly',t=>{ | ||
const wrapper = shallow(<MyComponent/>); | ||
const wrapper = shallow(<<%= root_component_name %>/>); | ||
t.is(wrapper.find('p').length,1); | ||
}); |
var path = require('path'); | ||
var webpack = require('webpack'); | ||
var assetsPath = path.join(__dirname, 'src'); | ||
var devPath = path.join(__dirname, 'dev'); | ||
var devPath = path.join(__dirname, 'playground'); | ||
var ExtractTextWebpackPlugin = require('extract-text-webpack-plugin'); | ||
@@ -6,0 +6,0 @@ var HtmlWebpackPlugin = require('html-webpack-plugin'); |
{ | ||
"name": "generator-arc-component", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "Generate accessible react component boilerplate", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "npm test" | ||
"test": "npm test", | ||
"publish": "npm version patch && npm publish && git push origin master --tags" | ||
}, | ||
@@ -9,0 +10,0 @@ "repository": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
50364
17
295