Skip to content

Commit

Permalink
Merge pull request #63 from osstotalsoft/add-prisma-option
Browse files Browse the repository at this point in the history
Added Prisma infrastructure, allow choosing between Prisma and Knex
  • Loading branch information
alexandra-c authored Dec 17, 2021
2 parents adf591e + 51637e9 commit 5b422ba
Show file tree
Hide file tree
Showing 27 changed files with 17,069 additions and 3,346 deletions.
232 changes: 146 additions & 86 deletions README.md

Large diffs are not rendered by default.

172 changes: 112 additions & 60 deletions __tests__/answers.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ describe('test package installers', () => {
const defaultAnswers = {
projectName,
gqlPort,
dataLayer: 'knex',
withMultiTenancy: false,
addSubscriptions: false,
addMessaging: false,
Expand Down Expand Up @@ -50,69 +51,120 @@ describe('test package installers', () => {
})
})

it('does not contain subscriptions', () => helpers
.create(path.join(__dirname, '../generators/app'))
.inDir(path.join(__dirname, tempRoot))
.withPrompts({
...defaultAnswers,
addSubscriptions: false
})
.run()
.then(() => {
assert.noFile(path.join(__dirname, `${tempRoot}/${projectName}/src/pubSub/redisPubSub.js`))
})
)
it('does not contain subscriptions', () =>
helpers
.create(path.join(__dirname, '../generators/app'))
.inDir(path.join(__dirname, tempRoot))
.withPrompts({
...defaultAnswers,
addSubscriptions: false
})
.run()
.then(() => {
assert.noFile(path.join(__dirname, `${tempRoot}/${projectName}/src/pubSub/redisPubSub.js`))
}))

it('does not contain messaging', () => helpers
.create(path.join(__dirname, '../generators/app'))
.inDir(path.join(__dirname, tempRoot))
.withPrompts({
...defaultAnswers,
addMessaging: false
})
.run()
.then(() => {
assert.noFile(path.join(__dirname, `${tempRoot}/${projectName}/src/messaging`))
})
)
it('does not contain messaging', () =>
helpers
.create(path.join(__dirname, '../generators/app'))
.inDir(path.join(__dirname, tempRoot))
.withPrompts({
...defaultAnswers,
addMessaging: false
})
.run()
.then(() => {
assert.noFile(path.join(__dirname, `${tempRoot}/${projectName}/src/messaging`))
}))

it('does not contain message-bus package', () => helpers
.create(path.join(__dirname, '../generators/app'))
.inDir(path.join(__dirname, tempRoot))
.withPrompts({
...defaultAnswers
})
.run()
.then(_gen => {
assert.jsonFileContent(path.join(__dirname, `${tempRoot}/${projectName}/package.json`), {
dependencies: messageBus
it('does not contain message-bus package', () =>
helpers
.create(path.join(__dirname, '../generators/app'))
.inDir(path.join(__dirname, tempRoot))
.withPrompts({
...defaultAnswers
})
})
)
.run()
.then(_gen => {
assert.jsonFileContent(path.join(__dirname, `${tempRoot}/${projectName}/package.json`), {
dependencies: messageBus
})
}))

it('does not contain middleware in messaging', () => helpers
.create(path.join(__dirname, '../generators/app'))
.inDir(path.join(__dirname, tempRoot))
.withPrompts({
...defaultAnswers,
addMessaging: false
})
.run()
.then(() => {
assert.noFile(path.join(__dirname, `${tempRoot}/${projectName}/src/messaging/middleware`))
})
)
it('does not contain middleware in messaging', () =>
helpers
.create(path.join(__dirname, '../generators/app'))
.inDir(path.join(__dirname, tempRoot))
.withPrompts({
...defaultAnswers,
addMessaging: false
})
.run()
.then(() => {
assert.noFile(path.join(__dirname, `${tempRoot}/${projectName}/src/messaging/middleware`))
}))

it('does not contain helm files', () => helpers
.create(path.join(__dirname, '../generators/app'))
.inDir(path.join(__dirname, tempRoot))
.withPrompts({
...defaultAnswers,
addHelm: false
})
.run()
.then(() => {
assert.noFile(path.join(__dirname, `${tempRoot}/${projectName}/helm`))
})
)
it('does not contain helm files', () =>
helpers
.create(path.join(__dirname, '../generators/app'))
.inDir(path.join(__dirname, tempRoot))
.withPrompts({
...defaultAnswers,
addHelm: false
})
.run()
.then(() => {
assert.noFile(path.join(__dirname, `${tempRoot}/${projectName}/helm`))
}))

it('does not contain knex config files and db associated files', async () => {
const files = [
path.join(__dirname, `${tempRoot}/${projectName}/src/db`),
path.join(__dirname, `${tempRoot}/${projectName}/src/middleware/db`),
path.join(__dirname, `${tempRoot}/${projectName}/src/middleware/tenantIdentification`),
path.join(__dirname, `${tempRoot}/${projectName}/src/middleware/messaging/multiTenancy`),
path.join(__dirname, `${tempRoot}/${projectName}/src/messaging/middleware/dbInstance.js`),
path.join(__dirname, `${tempRoot}/${projectName}/src/startup/dataLoaders.js`),
path.join(__dirname, `${tempRoot}/${projectName}/src/features/common/dbGenerators.js`),
path.join(__dirname, `${tempRoot}/${projectName}/src/features/tenant`),
path.join(__dirname, `${tempRoot}/${projectName}/src/features/user/dataLoaders.js`),
path.join(__dirname, `${tempRoot}/${projectName}/src/features/user/dataSources/userDb.js`),
path.join(__dirname, `${tempRoot}/${projectName}/src/tracing/knexTracer.js`),
path.join(__dirname, `${tempRoot}/${projectName}/src/utils/sqlDataSource.js`)
]

await helpers
.create(path.join(__dirname, '../generators/app'))
.inDir(path.join(__dirname, tempRoot))
.withPrompts({
...defaultAnswers,
dataLayer: 'prisma'
})
.run()
.then(() => {
assert.noFile(files)
})
})

it('initializes prisma', async () => {
const files = [
path.join(__dirname, `${tempRoot}/${projectName}/prisma`),
path.join(__dirname, `${tempRoot}/${projectName}/src/utils/prisma.js`)
]
await helpers
.create(path.join(__dirname, '../generators/app'))
.inDir(path.join(__dirname, tempRoot))
.withPrompts({
...defaultAnswers,
dataLayer: 'prisma'
})
.run()
.then(() => {
assert.file(files)
assert.fileContent(
path.join(__dirname, `${tempRoot}/${projectName}/.env`),
`DATABASE_URL="sqlserver://serverName:1433;database=databaseName;user=userName;password=password;trustServerCertificate=true"`
)
})
})
})
4 changes: 0 additions & 4 deletions __tests__/installers.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,4 @@ describe('test package installers', () => {
assert.fileContent(path.join(__dirname, `${tempRoot}/${projectName}/Dockerfile`),"yarn")
assert.noFileContent(path.join(__dirname, `${tempRoot}/${projectName}/Dockerfile`),"npm")
}))

afterAll(() => {
rimraf.sync(path.join(__dirname, tempRoot))
})
})
31 changes: 27 additions & 4 deletions generators/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,35 @@ module.exports = class extends Generator {
addGqlLogging,
withRights,
packageManager,
helmChartName
helmChartName,
dataLayer
} = this.answers

const templatePath = this.templatePath('infrastructure/**/*')
const destinationPath = this.destinationPath(projectName)

let ignoreFiles = ['**/.npmignore', '**/.gitignore-template', '**/helm/**']

if (dataLayer === 'knex') ignoreFiles = concat(['**/prisma/**', '**/utils/prisma.js'], ignoreFiles)
if (dataLayer === 'prisma')
ignoreFiles = concat(
[
'**/src/db/**',
'**/middleware/db/**',
'**/middleware/tenantIdentification/**',
'**/middleware/messaging/multiTenancy/**',
'**/messaging/middleware/dbInstance.js',
'**/startup/dataLoaders.js',
'**/features/common/dbGenerators.js',
'**/features/tenant/**',
'**/features/user/dataLoaders.js',
'**/features/user/dataSources/userDb.js',
'**/tracing/knexTracer.js',
'**/utils/sqlDataSource.js'
],
ignoreFiles
)

if (!addSubscriptions) ignoreFiles = concat(['**/pubSub/**'], ignoreFiles)
if (!addMessaging) ignoreFiles = append('**/messaging/**', ignoreFiles)
if (!withMultiTenancy)
Expand Down Expand Up @@ -96,13 +117,15 @@ module.exports = class extends Generator {

const { packageManager, projectName } = this.answers

this.log(chalk.greenBright(`All the dependencies will be installed shortly using "${packageManager}" package manager...`))
this.log(
chalk.greenBright(`All the dependencies will be installed shortly using "${packageManager}" package manager...`)
)
// eslint-disable-next-line no-unused-expressions
packageManager === 'npm'
? this.npmInstall(null, {}, { cwd: projectName })
: packageManager === 'yarn'
? this.yarnInstall(null, {}, { cwd: projectName })
: this.npmInstall(null, {}, { cwd: projectName })
? this.yarnInstall(null, {}, { cwd: projectName })
: this.npmInstall(null, {}, { cwd: projectName })
}

end() {
Expand Down
Loading

0 comments on commit 5b422ba

Please sign in to comment.