Skip to content

Commit

Permalink
feat: basic config for using multiple relational databases with seque…
Browse files Browse the repository at this point in the history
…lize and mongo with mongoose
  • Loading branch information
AnthonyLzq committed Jul 20, 2022
1 parent 9935139 commit 272907f
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 18 deletions.
64 changes: 47 additions & 17 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,61 +9,70 @@ const argv = yargs(hideBin(process.argv))
.version(false)
// Pending to test it using npx
.usage(
'"simba [options]" (if you it installed globally) or only "simba -q" if you want to be asked for the options one by one'
'"simba [options]" (if you it installed globally) or only "simba -q" if you want to be asked for the options one by one.'
)
.example(
"simba -N 'Project Name' -D 'Project description' -a Anthony -e [email protected] -l mit -F --tests --ghat"
"simba -N 'Project Name' -D 'Project description' -a Anthony -e [email protected] -l mit -F -t -d mongo --ghat"
)
.alias('N', 'projectName')
.nargs('N', 1)
.describe('N', 'Project name')
.alias('D', 'projectDescription')
.nargs('D', 1)
.describe('D', 'Project description')
.describe('D', 'Project description.')
.alias('a', 'author')
.nargs('a', 1)
.describe('a', 'Author of the project')
.describe('a', 'Author of the project.')
.alias('e', 'email')
.nargs('e', 1)
.describe('e', 'Email of the author')
.describe('e', 'Email of the author.')
.alias('H', 'heroku')
.describe('H', 'Whether or not the project will be deployed using Heroku')
.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'
'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')
.describe('v', 'Project initial version.')
.alias('y', 'licenseYear')
.nargs('y', 1)
.describe('y', 'Year when the license starts')
.describe('y', 'Year when the license starts.')
.alias('n', 'npm')
.describe('n', 'Whether or not the project should use npm as package manager')
.describe(
'n',
'Whether or not the project should use npm as package manager.'
)
.alias('f', 'mainFile')
.nargs('f', 1)
.describe('f', 'Main file of the project')
.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'
'Whether or not you want to be asked to answer the questions related to the project one by one.'
)
.alias('F', 'fastify')
.describe('F', 'Whether or not you want to use Fastify for your project')
.describe('F', 'Whether or not you want to use Fastify for your project.')
.alias('g', 'graphql')
.describe('g', 'Whether or not you want to use GraphQL for your project')
.describe('g', 'Whether or not you want to use GraphQL for your project.')
.alias('t', 'tests')
.describe(
't',
'Whether or not you want to have a basic suit of unit tests with Jest'
'Whether or not you want to have a basic suit of unit tests with Jest.'
)
.alias('ghat', 'gh-action-tests')
.describe(
'ghat',
'Whether or not you want to have a GitHub Action with a CI for your tests and linting. If this option is set to true, the tests flag must be set to true.'
)
.describe(
'd',
'Which database you want to use, available databases are: MongoDB, PostgreSQL, MySQL, MariaDB, Sqlite and Microsoft SQL Server.'
)
.alias('d', 'database')
.nargs('d', 1)
.default({
H: false,
n: false,
Expand All @@ -75,7 +84,8 @@ const argv = yargs(hideBin(process.argv))
F: false,
g: false,
t: false,
ghat: false
ghat: false,
d: 'mongo'
})
.boolean(['H', 'n', 'q', 'F', 'g', 't'])
.help('h')
Expand All @@ -98,7 +108,8 @@ const config = {
fastify: false,
graphql: false,
tests: true,
ghat: true
ghat: true,
database: 'mongo'
}
const UNLICENSED = 'unlicensed'
const LICENSES = [
Expand All @@ -109,6 +120,14 @@ const LICENSES = [
'GPL 3.0',
'AGPL 3.0'
]
const DATABASES = {
MongoDB: 'mongo',
PostgreSQL: 'postgres',
MySQL: 'mysql',
MariaDB: 'mariadb',
Sqlite: 'sqlite',
'Microsoft SQL Server': 'sqlServer'
}
const POSSIBLE_LICENSES = ['mit', 'apache', 'mpl', 'lgpl', 'gpl', 'agpl']
const ONE_CHARACTER_REGEXP = /^\w/
const YEAR_REGEXP = /^\d{4}$/
Expand Down Expand Up @@ -245,6 +264,14 @@ const main = async () => {
}
)
else config.ghat = false

config.database = readLineSync.keyInSelect(
Object.keys(DATABASES),
'> Select your database: ',
{
cancel: false
}
)
} else {
if (!argv.author) return console.log('Error! An author is required!')
else config.author = argv.author
Expand Down Expand Up @@ -327,6 +354,8 @@ const main = async () => {
return console.log(
'GitHub Action for tests can not be set to true if the tests flag is set to false'
)

if (argv.database) config.database = argv.database
}

await installation(config)
Expand All @@ -349,4 +378,5 @@ module.exports = main
* @property {String} mainFile main file of the project
* @property {Boolean} fastify true means that the project will be using Fastify
* @property {Boolean} graphql true means that the project will be using GraphQL
* @property {'mongo'|'postgres'|'mysql'|'mariadb'|'sqlite'|'sqlServer'} database project database
*/
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"scripts": {
"service": "node ./bin",
"service:q": "node ./bin -q",
"help": "node ./bin --help",
"help": "node ./bin -h",
"lint": "eslint --ext js lib/ --fix",
"build": "npm run rm && npm run build:express && npm run build:fastify && npm run build:express:graphql && npm run build:fastify:graphql",
"build:express": "npm run rm:express && npm run cd:mv:example && node -r dotenv/config ./bin -N example/express -D 'This is a test using express' -a AnthonyLzq -e [email protected] -l mit -H --tests --ghat && npm run rm:git:express",
Expand Down

0 comments on commit 272907f

Please sign in to comment.