shanepadgett / gicreator Goto Github PK
View Code? Open in Web Editor NEWCreate custom gitignore files from Github templates.
License: MIT License
Create custom gitignore files from Github templates.
License: MIT License
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(', ')}]`)
}
In the following code block, you can take advantage of promise chaining by returning the fetch calls to avoid nesting promise chains:
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)
})
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)
}
})
The macOS request returns a 404. Likely to do with the difference in capitalization.
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.
After research, Axios looks to be the simpler library to use which also supports promises.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.