Skip to content

Commit

Permalink
feat: implemented eslint rules
Browse files Browse the repository at this point in the history
  • Loading branch information
AnthonyLzq committed Dec 11, 2021
1 parent 6817837 commit 748fb91
Show file tree
Hide file tree
Showing 16 changed files with 5,668 additions and 260 deletions.
63 changes: 63 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"env": {
"node": true
},
"root": true,
"plugins": [
"import",
"prettier"
],
"extends": [
"standard",
"eslint:recommended",
"prettier"
],
"rules": {
"@typescript-eslint/no-var-requires": "off",
"arrow-parens": [
"error",
"as-needed"
],
"import/no-extraneous-dependencies": [
"error",
{
"devDependencies": true
}
],
"max-len": [
"error",
{
"code": 80,
"ignoreComments": true,
"ignoreRegExpLiterals": true,
"ignoreTemplateLiterals": true,
"ignoreTrailingComments": true,
"ignoreStrings": true,
"ignoreUrls": true
}
],
"newline-before-return": "error",
"object-curly-spacing": [
"error",
"always"
],
"prefer-const": "error",
"prettier/prettier": [
"error",
{
"arrowParens": "avoid",
"bracketSpacing": true,
"printWidth": 80,
"quoteProps": "as-needed",
"semi": false,
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "none"
}
],
"radix": [
"error",
"as-needed"
]
}
}
71 changes: 40 additions & 31 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@ const installation = require('./src/installation')
const CURRENT_YEAR = `${new Date().getFullYear()}`
const argv = yargs(hideBin(process.argv))
.version(false)
.usage('Usage: npx simba [options] or simba [options] (if you it installed globally) or only simba if you want to be asked for the options one by one')
.example('simba -a Anthony -e sluzquinosa@uni.pe -N "Project Name" -D "Project description"')
.usage(
'Usage: npx simba [options] or simba [options] (if you it installed globally) or only simba if you want to be asked for the options one by one'
)
.example(
'simba -a Anthony -e sluzquinosa@uni.pe -N "Project Name" -D "Project description"'
)
.alias('a', 'author')
.nargs('a', 1)
.describe('a', 'Author of the project')
Expand All @@ -25,7 +29,10 @@ const argv = yargs(hideBin(process.argv))
.describe('H', 'Whether or not the project will be deployed using Heroku')
.alias('l', 'license')
.nargs('l', 1)
.describe('l', 'Type of license for the project, it can be one of: MIT, Apache 2.0, MPL 2.0, LGPL 3.0, GPL 3.0 and AGPL 3.0, in lowercase without its version')
.describe(
'l',
'Type of license for the project, it can be one of: MIT, Apache 2.0, MPL 2.0, LGPL 3.0, GPL 3.0 and AGPL 3.0, in lowercase without its version'
)
.alias('v', 'version')
.nargs('v', 1)
.describe('v', 'Project initial version')
Expand All @@ -38,7 +45,10 @@ const argv = yargs(hideBin(process.argv))
.nargs('f', 1)
.describe('f', 'Main file of the project')
.alias('q', 'questions')
.describe('q', 'Whether or not you want to be asked to answer the questions related to the project one by one')
.describe(
'q',
'Whether or not you want to be asked to answer the questions related to the project one by one'
)
.default({
H: false,
n: false,
Expand All @@ -51,22 +61,21 @@ const argv = yargs(hideBin(process.argv))
.boolean(['H', 'n', 'q'])
.help('h')
.alias('h', 'help')
.epilog('Developed by AnthonyLzq')
.argv
.epilog('Developed by AnthonyLzq').argv

/** @type {Config} */
const config = {
author : '',
email : '',
projectName : '',
author: '',
email: '',
projectName: '',
projectDescription: '',
heroku : false,
license : 'unlicensed',
version : '0.1.0',
licenseYear : CURRENT_YEAR,
npm : false,
manager : 'yarn add',
mainFile : 'src/index.ts'
heroku: false,
license: 'unlicensed',
version: '0.1.0',
licenseYear: CURRENT_YEAR,
npm: false,
manager: 'yarn add',
mainFile: 'src/index.ts'
}
const UNLICENSED = 'unlicensed'
const LICENSES = [
Expand All @@ -81,7 +90,7 @@ const POSSIBLE_LICENSES = ['mit', 'apache', 'mpl', 'lgpl', 'gpl', 'agpl']
const ONE_CHARACTER_REGEXP = /^\w/
const YEAR_REGEXP = /^\d{4}$/
const EMAIL_REGEXP =
/^(([^<>()[\]\.,;:\s@\"]+(\.[^<>()[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/i
/^(([^<>()[\].,;:\s@"]+(\.[^<>()[\].,;:\s@"]+)*)|(".+"))@(([^<>()[\].,;:\s@"]+\.)+[^<>()[\].,;:\s@"]{2,})$/i

const main = async () => {
if (argv.q) {
Expand All @@ -96,8 +105,8 @@ const main = async () => {
},
{
caseSensitive: false,
limitMessage : 'That is not a valid option',
prompt : '> Yarn or npm? '
limitMessage: 'That is not a valid option',
prompt: '> Yarn or npm? '
}
)

Expand All @@ -110,9 +119,9 @@ const main = async () => {
return config.projectName !== ''
},
{
limit : ONE_CHARACTER_REGEXP,
limit: ONE_CHARACTER_REGEXP,
limitMessage: 'The project must have a name!',
prompt : '> Project name: '
prompt: '> Project name: '
}
)

Expand All @@ -123,9 +132,9 @@ const main = async () => {
return config.projectDescription !== ''
},
{
limit : ONE_CHARACTER_REGEXP,
limit: ONE_CHARACTER_REGEXP,
limitMessage: 'The project must have a description!',
prompt : '> Project description: '
prompt: '> Project description: '
}
)

Expand All @@ -136,14 +145,14 @@ const main = async () => {
return config.author !== ''
},
{
limit : ONE_CHARACTER_REGEXP,
limit: ONE_CHARACTER_REGEXP,
limitMessage: 'The project must have an author!',
prompt : '> Author: '
prompt: '> Author: '
}
)

config.email = readLineSync.questionEMail('> Email: ', {
limit : EMAIL_REGEXP,
limit: EMAIL_REGEXP,
limitMessage: 'That is not a valid email!'
})

Expand All @@ -170,9 +179,9 @@ const main = async () => {
return YEAR_REGEXP.test(config.licenseYear)
},
{
limit : [YEAR_REGEXP, ''],
limit: [YEAR_REGEXP, ''],
limitMessage: 'That is not a valid license year!',
prompt : `> License year (${config.licenseYear}): `
prompt: `> License year (${config.licenseYear}): `
}
)

Expand Down Expand Up @@ -218,16 +227,16 @@ const main = async () => {

switch (argv.license) {
case POSSIBLE_LICENSES[0]:
config.license = arg.license
config.license = argv.license
break
case POSSIBLE_LICENSES[1]:
case POSSIBLE_LICENSES[2]:
config.license = `${arg.license}-2.0`
config.license = `${argv.license}-2.0`
break
case POSSIBLE_LICENSES[3]:
case POSSIBLE_LICENSES[4]:
case POSSIBLE_LICENSES[5]:
config.license = `${arg.license}-3.0`
config.license = `${argv.license}-3.0`
break
}
}
Expand Down
4 changes: 2 additions & 2 deletions lib/src/functions/changelog.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ const writeFile = require('../utils/writeFile')
const titleCase = require('../utils/titleCase')

/**
* @param {String} projectName
* @param {String} projectName
* @returns {Promise<void>}
*/
module.exports = async projectName => {
const data = {
changelogContent: `# ${titleCase(projectName)}`,
changelogFile : 'CHANGELOG.md'
changelogFile: 'CHANGELOG.md'
}

await writeFile(`${projectName}/${data.changelogFile}`, data.changelogContent)
Expand Down
10 changes: 5 additions & 5 deletions lib/src/functions/express.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ const writeFile = require('../utils/writeFile')
*/

/**
* @param {String} projectName
* @param {String} projectVersion
* @param {String} email
* @param {String} projectName
* @param {String} projectVersion
* @param {String} email
*/
module.exports = async (projectName, projectVersion, email) => {
const data = {
Expand Down Expand Up @@ -640,7 +640,7 @@ User.route('/user/:id')
export { User }
`,
file: `${projectName}/src/routes/users.ts`
file: `${projectName}/src/routes/users.ts`
},
index: {
content: `import { Home } from './home'
Expand Down Expand Up @@ -1167,7 +1167,7 @@ export { docs, response }
},
'.env': {
content: 'MONGO_URI = ',
file : `${projectName}/.env`
file: `${projectName}/.env`
},
index: {
content: `import { Server } from './network'
Expand Down
4 changes: 2 additions & 2 deletions lib/src/functions/gitignore.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const writeFile = require('../utils/writeFile')

/**
* @param {String} projectName
* @param {String} projectName
* @returns {Promise<void>}
*/
module.exports = async projectName => {
Expand Down Expand Up @@ -134,7 +134,7 @@ typings/
# End of https://www.toptal.com/developers/gitignore/api/node,yarn
`,
gitignoreFile : '.gitignore'
gitignoreFile: '.gitignore'
}

await writeFile(`${projectName}/${data.gitignoreFile}`, data.gitignoreContent)
Expand Down
6 changes: 3 additions & 3 deletions lib/src/functions/license.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ const getLicense = ({ author, license, year, projectDescription }) => {

resolve(result)
})
res.on('error', error => {
res.on('error', e => {
console.error(e)
reject('error')
reject(e)
})
})
})
Expand All @@ -63,7 +63,7 @@ module.exports = async ({
}) => {
const data = {
content: '',
file : 'LICENSE'
file: 'LICENSE'
}

try {
Expand Down
6 changes: 4 additions & 2 deletions lib/src/functions/packageJson.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module.exports = async ({
}) => {
const data = {
content: '',
file : 'package.json'
file: 'package.json'
}

data.content = `{
Expand All @@ -31,7 +31,9 @@ module.exports = async ({
"release": "standard-version"
},
"author": "${author}",${
license !== 'unlicensed' ? `\n "license": "${license.toUpperCase()}",\n` : ''
license !== 'unlicensed'
? `\n "license": "${license.toUpperCase()}",\n`
: ''
}
"dependencies": {},
"devDependencies": {}
Expand Down
4 changes: 2 additions & 2 deletions lib/src/functions/readme.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ const titleCase = require('../utils/titleCase')

/**
* @param {String} projectName
* @param {String} projectDescription
* @param {String} projectDescription
* @returns {Promise<void>}
*/
module.exports = async (projectName, projectDescription) => {
const data = {
readmeContent: `# ${titleCase(projectName)}\n\n${projectDescription}.\n`,
readmeFile : 'README.md'
readmeFile: 'README.md'
}

await writeFile(`${projectName}/${data.readmeFile}`, data.readmeContent)
Expand Down
2 changes: 1 addition & 1 deletion lib/src/functions/tsconfig.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const writeFile = require('../utils/writeFile')

/**
* @param {String} projectName
* @param {String} projectName
* @returns {Promise<void>}
*/
module.exports = async projectName => {
Expand Down
2 changes: 1 addition & 1 deletion lib/src/functions/webpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module.exports = {
rules: [
{
exclude: /node_modules/,
test : /\.ts$/,
test : /.ts$/,
use : {
loader: 'ts-loader'
},
Expand Down
5 changes: 2 additions & 3 deletions lib/src/installation.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ module.exports = async ({
cliProgress.Presets.shades_classic
)

const prodPackages = `${manager} express mongoose morgan http-errors joi`
const prodPackages = `${manager} express mongoose morgan http-errors joi swagger-ui-express`
const devPackages = `${manager} -D \
@types/node \
@typescript-eslint/eslint-plugin \
Expand All @@ -73,7 +73,6 @@ eslint-plugin-sort-keys-fix \
eslint-plugin-typescript-sort-keys \
nodemon \
prettier \
swagger-ui-express \
ts-loader \
ts-node \
typescript \
Expand Down Expand Up @@ -129,7 +128,7 @@ standard-version`
await exec(prodPackages, { cwd: `./${projectName}` })
bar.update(++i)

await exec(devPackages, { cwd: `./${projectName}` }),
await exec(devPackages, { cwd: `./${projectName}` })
bar.update(++i)

bar.stop()
Expand Down
Loading

0 comments on commit 748fb91

Please sign in to comment.