Skip to content

Commit

Permalink
feat: updating installation config to use the flags for tests and git…
Browse files Browse the repository at this point in the history
…hub actions
  • Loading branch information
AnthonyLzq committed Jul 5, 2022
1 parent 734e53b commit 6b6c47f
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 34 deletions.
10 changes: 5 additions & 5 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const argv = yargs(hideBin(process.argv))
'"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]"
"simba -N 'Project Name' -D 'Project description' -a Anthony -e [email protected] -l mit -F --tests --ghat"
)
.alias('N', 'projectName')
.nargs('N', 1)
Expand Down Expand Up @@ -74,8 +74,8 @@ const argv = yargs(hideBin(process.argv))
q: false,
F: false,
g: false,
t: true,
ghat: true
t: false,
ghat: false
})
.boolean(['H', 'n', 'q', 'F', 'g', 't'])
.help('h')
Expand Down Expand Up @@ -319,9 +319,9 @@ const main = async () => {
if (!argv.mainFile) console.log('Using src/index.ts as default main file')
else config.mainFile = argv.mainFile

if (!argv.tests) config.tests = false
if (argv.tests) config.tests = true

if (!argv.ghat) config.ghat = false
if (argv.ghat) config.ghat = true

if (!config.tests && argv.ghat)
return console.log(
Expand Down
File renamed without changes.
13 changes: 10 additions & 3 deletions lib/src/functions/packageJson.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ module.exports = async ({
projectDescription,
projectVersion,
license,
mainFile
mainFile,
tests
}) => {
const data = {
content: '',
Expand All @@ -31,9 +32,14 @@ module.exports = async ({
"lint": "eslint src/* --ext .ts --fix",
"service": "nodemon",
"start": "node dist/index.js",
"release": "standard-version",
"release": "standard-version"\
${
tests
? `,
"test:ci": "jest --ci -i",
"test:local": "NODE_ENV=local jest --ci -i"
"test:local": "NODE_ENV=local jest --ci -i"`
: ''
}
},
"author": "${author}",${
license !== 'unlicensed'
Expand All @@ -55,4 +61,5 @@ module.exports = async ({
* @property {String} projectVersion
* @property {'unlicensed'|'mit'|'apache-2.0'|'mpl-2.0'|'lgpl-3.0'|'gpl-3.0'|'agpl-3.0'} license
* @property {String} mainFle
* @property {Boolean} tests
*/
46 changes: 23 additions & 23 deletions lib/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ const webpack = require('./functions/webpack')
const docker = require('./functions/docker')
const herokuF = require('./functions/heroku')
const api = require('./functions/api')
const test = require('./functions/tests')
const ga = require('./functions/ga')
const testsF = require('./functions/tests')
const ghatF = require('./functions/ghat')

/**
* @param {Number} process number of process
Expand Down Expand Up @@ -49,40 +49,33 @@ module.exports = async ({
manager,
mainFile,
fastify,
graphql
graphql,
tests,
ghat
}) => {
const process = 4
let i = 0

const options = setOptions(process)
const bar = new cliProgress.SingleBar(
options,
cliProgress.Presets.shades_classic
)

const expressProdPackages = `express swagger-ui-express cors express-pino-logger ${
graphql ? 'apollo-server-express' : ''
}`

const fastifyProdPackages = `fastify@^3 @fastify/swagger@^6 @fastify/cors@^7 ${
graphql ? 'apollo-server-fastify apollo-server-plugin-base' : ''
}`

const prodPackages = `${manager} @sinclair/typebox http-errors mongoose pino-pretty ${
graphql
? '@graphql-tools/schema ajv ajv-formats apollo-server-core graphql'
: 'ajv@^6'
} ${fastify ? fastifyProdPackages : expressProdPackages}`

const expressDevPackages =
'@types/express @types/swagger-ui-express @types/cors @types/express-pino-logger'

const fastifyDevPackages = ''

const devPackages = `${manager} -D \
@jest/types \
let devPackages = `${manager} -D \
@types/http-errors \
@types/jest \
@types/node \
@typescript-eslint/eslint-plugin \
@typescript-eslint/parser \
Expand All @@ -92,26 +85,28 @@ eslint \
eslint-config-prettier \
eslint-config-standard \
eslint-plugin-import \
eslint-plugin-jest \
eslint-plugin-node \
eslint-plugin-prettier \
eslint-plugin-promise \
jest \
jest-unit \
nodemon \
prettier \
standard-version \
ts-jest \
ts-loader \
ts-node \
tsconfig-paths \
tsconfig-paths-webpack-plugin \
typescript \
webpack \
webpack-cli \
webpack-node-externals \
${fastify ? fastifyDevPackages : expressDevPackages} \
${manager === 'yarn add' ? 'eslint-plugin-n' : ''}`
webpack-node-externals`

if (fastify)
devPackages += ` ${fastify ? fastifyDevPackages : expressDevPackages}`

if (tests)
devPackages += ` @jest/types @types/jest eslint-plugin-jest jest jest-unit ts-jest`

if (manager === 'yarn add') devPackages += ` eslint-plugin-n`

bar.start(process, i)

Expand All @@ -126,7 +121,8 @@ ${manager === 'yarn add' ? 'eslint-plugin-n' : ''}`
projectDescription,
projectVersion: version,
license,
mainFile
mainFile,
tests
}),
readme(projectName, projectDescription),
changelog(projectName),
Expand All @@ -136,8 +132,6 @@ ${manager === 'yarn add' ? 'eslint-plugin-n' : ''}`
eslint(projectName),
webpack(projectName),
docker(projectName),
ga(projectName),
test(projectName),
api({ projectName, version, email, fastify, graphql }),
exec('git init', { cwd: `./${projectName}` })
]
Expand All @@ -155,6 +149,10 @@ ${manager === 'yarn add' ? 'eslint-plugin-n' : ''}`

if (heroku) functions.push(herokuF(projectName))

if (tests) functions.push(testsF(projectName))

if (ghat) functions.push(ghatF(projectName))

await Promise.all(functions)
bar.update(++i)

Expand Down Expand Up @@ -185,6 +183,8 @@ ${manager === 'yarn add' ? 'eslint-plugin-n' : ''}`
* @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 {Boolean} tests true means that the project will have a basic suit of tests with Jest
* @property {Boolean} ghat true means that the project will have a GitHub Action for the suit of tests
*/

/**
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"release": "standard-version",
"test": "if [ ! -d \"example\" ]; then npm run build; fi && npm run test-fastify",
"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 && npm run rm-git-express",
"build-fastify": "npm run rm-fastify && npm run cd-mv-example && node -r dotenv/config ./bin -N example/fastify -D 'This is a test using fastify' -a AnthonyLzq -e [email protected] -l mit -H -F && npm run rm-git-fastify",
"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",
"build-fastify": "npm run rm-fastify && npm run cd-mv-example && node -r dotenv/config ./bin -N example/fastify -D 'This is a test using fastify' -a AnthonyLzq -e [email protected] -l mit -H -F --tests --ghat && npm run rm-git-fastify",
"build-express-graphql": "npm run rm-express-graphql && npm run cd-mv-example && node -r dotenv/config ./bin -N example/express-graphql -D 'This is a test using express with GraphQL' -a AnthonyLzq -e [email protected] -l mit -H -g && npm run rm-git-express-graphql",
"build-fastify-graphql": "npm run rm-fastify-graphql && npm run cd-mv-example && node -r dotenv/config ./bin -N example/fastify-graphql -D 'This is a test using fastify with GraphQL' -a AnthonyLzq -e [email protected] -l mit -H -F -g && npm run rm-git-fastify-graphql",
"lint": "eslint --ext js lib/ --fix",
Expand All @@ -23,7 +23,7 @@
"rm-git-fastify": "if [ -d \"example/fastify/.git\" ]; then rm -rf example/fastify/.git; fi",
"rm-git-express-graphql": "if [ -d \"example/express-graphql/.git\" ]; then rm -rf example/express-graphql/.git; fi",
"rm-git-fastify-graphql": "if [ -d \"example/fastify-graphql/.git\" ]; then rm -rf example/fastify-graphql/.git; fi",
"test-fastify": "if [ -d \"example/express-graphql\" ]; then npm run test:local --prefix example/fastify; fi",
"test-fastify": "if [ -d \"example/fastify\" ]; then npm run test:local --prefix example/fastify; fi",
"cd-mv-example": "if [ ! -d \"example\" ]; then mkdir example && cd example; fi",
"version": "npm run release && git add CHANGELOG.md"
},
Expand Down

0 comments on commit 6b6c47f

Please sign in to comment.