Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: adeyahya/regenr
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 1.1
Choose a base ref
...
head repository: adeyahya/regenr
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
  • 12 commits
  • 8 files changed
  • 2 contributors

Commits on May 30, 2017

  1. Copy the full SHA
    9918cd3 View commit details

Commits on Oct 2, 2017

  1. changed back into package.json

    Ade Yahya committed Oct 2, 2017
    Copy the full SHA
    93d6bb4 View commit details
  2. changed version

    Ade Yahya committed Oct 2, 2017
    Copy the full SHA
    af1dfef View commit details
  3. fixed indentation

    Ade Yahya committed Oct 2, 2017
    Copy the full SHA
    7635796 View commit details
  4. Add editorconfig, changed colors

    Ade Yahya committed Oct 2, 2017
    Copy the full SHA
    6e1bca0 View commit details
  5. Changed version

    Ade Yahya committed Oct 2, 2017
    Copy the full SHA
    7f98f8c View commit details

Commits on Nov 7, 2017

  1. configuration driven

    Ade Yahya committed Nov 7, 2017
    Copy the full SHA
    44a9656 View commit details
  2. removed ramda

    Ade Yahya committed Nov 7, 2017
    Copy the full SHA
    2e0becd View commit details
  3. v1.1.5

    Ade Yahya committed Nov 7, 2017
    Copy the full SHA
    684339e View commit details
  4. bug fix

    Ade Yahya committed Nov 7, 2017
    Copy the full SHA
    b6dc587 View commit details
  5. v1.1.6

    Ade Yahya committed Nov 7, 2017
    Copy the full SHA
    72fe5ec View commit details

Commits on Feb 10, 2018

  1. Update README.md

    adeyahya authored Feb 10, 2018
    Copy the full SHA
    0b6d519 View commit details
Showing with 342 additions and 107 deletions.
  1. +3 −0 .editorconfig
  2. +2 −1 .gitignore
  3. +1 −1 LICENSE
  4. +24 −17 README.md
  5. +101 −32 index.js
  6. +4 −3 package.json
  7. +29 −53 template.js
  8. +178 −0 yarn.lock
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[*.{js,html}]
indent_style = space
indent_size = 2
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
node_modules
.DS_Store
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2016 Ade Yahya Prasetyo
Copyright (c) 2017 Ade Yahya Prasetyo

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
41 changes: 24 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -8,28 +8,33 @@ Regenr is a command-line interface that helps Generating ReactJs Components.
`npm install -g regenr`

## Usage
`regenr <path>/<componentName> [options]`
```bash
$ regenr <path>/<componentName> [options]
```

Example:
`regenr src/Components/Header` will provides:
```bash
$ regenr src/Components/Header
```
will provides:

*Header.js*
```javascript
import React from 'react'
import styles from './Header.scss'

class Header extends React.Component {
constructor(props) {
super(props)
this.displayName = 'Header'
}
render() {
return (
<div className={styles.Header}>
{/* Your code here */}
</div>
)
}
constructor(props) {
super(props)
this.displayName = 'Header'
}
render() {
return (
<div className={styles.Header}>
{/* Your code here */}
</div>
)
}
}

export default Header
@@ -38,20 +43,22 @@ export default Header
*Header.scss*
```sass
.Header{
/* Your stylesheet here */
/* Your stylesheet here */
}
```

*index.js*
```javascript
```js
export default './Header.js'
```

# Options
`-c [css preprocessor]` or `--css [css preprocessor]`

Example:
`regenr src/Components/Header -c less`
```bash
$ regenr src/Components/Header -c less
```

Will provide .less integration

@@ -60,4 +67,4 @@ Will provide .less integration
![Screenshot](/ss1.png?raw=true "Screenshot")

### License
MIT
MIT
133 changes: 101 additions & 32 deletions index.js
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,46 +1,115 @@
#!/usr/bin/env node
var program = require('commander'),
filendir = require('filendir'),
colors = require('colors'),
templates = require('./template.js');
const program = require('commander');
const filendir = require('filendir');
const colors = require('colors');
const templates = require('./template.js');
const fs = require('fs');
const inquirer = require("inquirer")
const path = require("path")

var createFile = function(path,css) {
css = css || 'scss'
const createConfig = () => {
const questions = [
{
type: 'list',
name: 'stylesheet',
message: 'Choose your stylesheet',
choices: ['sass', 'scss', 'styled-jsx', 'less', 'stylus', 'css', 'none'],
filter: function (val) {
return val.toLowerCase();
}
},
{
type: 'list',
name: 'typechecker',
message: 'Choose your TypeChecker',
choices: ['flow', 'typescript'],
filter: function (val) {
return val.toLowerCase();
}
}
]

var filename = path.match(/[^\\|\/]*$/)[0]
var dir = path.substring((path.match(/[^\\|\/]*$/).index), -1)
inquirer.prompt(questions).then(function (answers) {
filendir.writeFile("regenr.config.js", templates.config(answers), (err) => {
if (err)
throw new Error(err)

console.log(`\n=====================\n== React Generator ==\n=====================`)
console.log("Config File Created!")
})
});
}

filendir.writeFile(dir + filename + "/" + filename + ".js", templates.getReact(filename, css, true) , function(err) {
if (err) return console.log(err)
const createFile = (file, config) => {
const filename = file.match(/[^\\|\/]*$/)[0]
const dir = file.substring((file.match(/[^\\|\/]*$/).index), -1)
const fullPath = path.join(dir, filename)
const extension = config.typechecker === "typescript" ? "ts" : "js"

console.log("Created " + `${dir}${filename}/` + colors.yellow.underline(`${filename}.js`))
return true;
})
// check is file exist?
fs.readdir(fullPath, (err, files) => {
if (err) {
filendir.writeFile(
path.join(fullPath, "package.json"),
templates.index(filename, extension),
err => {
if (err)
throw new Error(err)

filendir.writeFile(`${dir}${filename}/${filename}.${css}`, templates.getStyle(filename, css) , function(err) {
if (err) return console.log(err)
console.log('Created ' + `${dir}${filename}/` + colors.blue.underline(`${filename}.${css}`))
return true;
})
console.log(`created file ${path.join(fullPath, "package.json")}`)
}
)

filendir.writeFile(dir + filename + "/" + "index.js", templates.getIndex(filename, true) , function(err) {
if (err) return console.log(err)

console.log("Created " + `${dir}${filename}/` + colors.magenta.underline(`index.js`))
return true;
})
filendir.writeFile(
path.join(fullPath, filename + "." + extension),
templates.react(filename, config),
err => {
if (err)
throw new Error(err)

console.log(`created file ${path.join(fullPath, filename + "." + extension)}`)
}
)

if (config.stylesheet != "none") {
console.log(config.stylesheet)
const styleExtension = config.stylesheet === "styled-jsx" ? "js" : config.stylesheet
filendir.writeFile(
path.join(fullPath, "style." + styleExtension),
config.stylesheet === "styled-jsx"
? 'import css from "styled-jsx/css\nexport const style = css\`\`'
: "",
err => {
console.log(`created file ${path.join(fullPath, "style." + styleExtension)}`)
}
)
}
}

if (files) {
return console.log(colors.red(`${fullPath} already exist!`))
}
})
}

const initialize = (file, program) => {
if (file === "init")
return createConfig()

fs.readFile("regenr.config.js", {encoding: "utf8", flag: "r"}, (err, data) => {
if (err)
console.log(colors.red("can't find config file, try to run:") + "\n=> regenr init")

if (data) {
const config = require(path.join(process.cwd(), "regenr.config.js"))
return createFile(file, config)
}
})
}

program
.arguments('<file>')
.option('-c, --css <css>', 'Css preprocessor')
// .option('-c, --config <config>', 'Config File')
.action(function(file) {
if (typeof program.css != 'undefined') {
createFile(file, program.css)
} else {
createFile(file)
}
initialize(file, program)
})
.parse(process.argv)
.parse(process.argv)
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "regenr",
"version": "1.1.0",
"version": "1.1.6",
"description": "ReactJs Generator",
"repository": "adeyahya/regenr",
"author": "Ade Yahya <adeyahyaprasetyo@gmail.com> (http://ihavemind.com/)",
"author": "Ade Yahya <adeyahyaprasetyo@gmail.com> (http://paradork.com/)",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
@@ -15,6 +15,7 @@
"dependencies": {
"colors": "^1.1.2",
"commander": "^2.9.0",
"filendir": "^1.0.0"
"filendir": "^1.0.0",
"inquirer": "^3.3.0"
}
}
82 changes: 29 additions & 53 deletions template.js
Original file line number Diff line number Diff line change
@@ -1,56 +1,32 @@
var template = (() => {
var options = {
css: 'scss',
privateRep: true,
cssModules: false
}

var getIndex = (componentName, privateRep) => {
privateRep = privateRep || options.privateRep

return `export default "./${componentName}.js"`
}

var getReact = (componentName, style, cssModules) => {
cssModules = cssModules || options.cssModules
return `import React from 'react'
${cssModules ? "import styles from './" + componentName + '.' + style + "'" : ''}
class ${componentName} extends React.Component {
constructor(props) {
super(props)
}
render() {
return (
<div ${cssModules ? 'className={ ' + 'styles.' + componentName + ' }' : '' }>
{/* Your code here */}
</div>
)
}
module.exports = {
index: (componentName, extension) => {
return `{
"name": "${componentName}",
"version": "0.0.0",
"private": true,
"main": "./${componentName}.${extension}"
}`
},

react: (componentName, config) => {
return `${config.typechecker === "flow" ? "//@flow" : null}
import React from "react";
class ${componentName} extends React.Component<{}> {
render() {
return (
{/* your code here */}
)
}
}
export default ${componentName}`
}

var getStyle = (componentName,style) => {
style = style || 'scss'

if (style === 'sass') {
return `.${componentName}
/* Your stylesheet here */`
} else {
return `.${componentName} {
/* Your stylesheet here */
export default ${componentName};
`
},
config: config => {
return `module.exports = {
stylesheet: "${config.stylesheet}",
typechecker: "${config.typechecker}",
}`
}
}

return {
getStyle: getStyle,
getReact: getReact,
getIndex: getIndex
}
})()

module.exports = template;
}
}
Loading