Giter Site home page Giter Site logo

gicreator's People

Contributors

dependabot-preview[bot] avatar shanepadgett avatar

Stargazers

 avatar  avatar

gicreator's Issues

Length Checking Can be Simplified

    if (added.proj.length > 0 || added.global.length > 0) {
      let types = added.proj.concat(added.global)
      console.log(`Created .gitignore for [${types.join(', ')}]`)
    }

You can drop the >0 as the zero value is falsy:

    if (added.proj.length || added.global.length) {
      let types = added.proj.concat(added.global)
      console.log(`Created .gitignore for [${types.join(', ')}]`)
    }

Also not necessary to set an intermediary variable here (depending on your preference):

    if (added.proj.length || added.global.length) {
      console.log(`Created .gitignore for [${added.proj.concat(added.global).join(', ')}]`)
    }

Take Advantage of Promise Chaining

In the following code block, you can take advantage of promise chaining by returning the fetch calls to avoid nesting promise chains:

screen shot 2018-04-30 at 11 08 32 pm

fetch("https://api.github.com/repos/github/gitignore/contents", props)
    .then(res => res.json())
    .then(json => {
        types.projectTypes = extractResponseNames(json)

        return fetch(
            "https://api.github.com/repos/github/gitignore/contents/Global",
            props
        )
    })
    .then(res => res.json())
    .then(json => {
        types.globalTypes = extractResponseNames(json)
        resolve(types)
    })

Take Advantage of Higher-Order Functions for Atomic Changes

    reqTypes.forEach(item => {
      item = item.toLowerCase()
      let lowerCaseProjectTypes = availableTypes.projectTypes.map(value => value.toLowerCase())
      let lowerCaseGlobalTypes = availableTypes.globalTypes.map(value => value.toLowerCase())
      
      if (lowerCaseProjectTypes.indexOf(item) !== -1) {
        added.proj.push(availableTypes.projectTypes[lowerCaseProjectTypes.indexOf(item)])
      } else if (lowerCaseGlobalTypes.indexOf(item) !== -1) {
        added.global.push(availableTypes.globalTypes[lowerCaseGlobalTypes.indexOf(item)])
      } else {
        missing.push(item)
      }
    })

This is totally up to you depending on how you prefer to structure things, but it seems like you're embracing the functional style and using higher order functions where available. You can use a .map() here to handle the atomic change (toLowerCase) on each option. You can also use the ES6 Array.includes to clean up some of the messy !== -1 checking.

This is definitely more of a preference kind of thing so feel free to just close this one if you prefer. The (very small) changes I'd recommend are the following:

    reqTypes
     .map(item => item.toLowerCase())
     .forEach(item => {
      let lowerCaseProjectTypes = availableTypes.projectTypes.map(value => value.toLowerCase())
      let lowerCaseGlobalTypes = availableTypes.globalTypes.map(value => value.toLowerCase())
      
      if (lowerCaseProjectTypes.includes(item)) {
        added.proj.push(availableTypes.projectTypes[lowerCaseProjectTypes.indexOf(item)])
      } else if (lowerCaseGlobalTypes.includes(item)) {
        added.global.push(availableTypes.globalTypes[lowerCaseGlobalTypes.indexOf(item)])
      } else {
        missing.push(item)
      }
    })

Take Advantage of Explicit Return

screen shot 2018-04-30 at 11 04 11 pm

The above functions (map and filter) can be simplified to take advantage of ES6 implicit return, e.g:

    const extractResponseNames = data => data.map(obj => obj.name.substr(0, obj.name.indexOf(".")))
        .filter(elm => elm)

Don't write to file on 404 Not Found

screen shot 2018-04-30 at 10 59 44 pm

I'm not certain what your preferred way of handling unfound ignore packages is, but for these that are dumping "404 not found" it would probably be best to leave them blank instead of pushing the 404 message into the template.

The Mac one should at minimum (and probably only) blacklist .DS_Store's in every directory.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.