Skip to content

Commit

Permalink
feat(cli): improved info output about new generated files on `herbs u…
Browse files Browse the repository at this point in the history
…pdate`
  • Loading branch information
dalssoft committed Feb 27, 2022
1 parent 0c77153 commit 1b62c9f
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
5 changes: 4 additions & 1 deletion src/generators/src/domain/usecases/unitTests.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const camelCase = require('lodash.camelcase')
const { objToString, requireHerbarium } = require('../../../utils')
const fs = require('fs')
const path = require('path')

function invertObjValues(obj) {
for (const key of Object.keys(obj)) {
Expand Down Expand Up @@ -77,7 +78,7 @@ module.exports = async ({ template: { generate }, filesystem }, command) => asyn

useCases.map(async (action) => {
const useCaseName = `${action} ${name}`
const ucPath = `${filesystem.cwd()}/src/domain/usecases/${camelCase(name)}/${camelCase(useCaseName)}.test.js`
const ucPath = path.normalize(`${filesystem.cwd()}/src/domain/usecases/${camelCase(name)}/${camelCase(useCaseName)}.test.js`)

if (fs.existsSync(ucPath)) return

Expand All @@ -98,6 +99,8 @@ module.exports = async ({ template: { generate }, filesystem }, command) => asyn
mock: objToString(generateMockObj(schema), objOptions)
}
})
process.stdout.write(` New: ${ucPath}\n`)

})
}
}
5 changes: 4 additions & 1 deletion src/generators/src/domain/usecases/useCases.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const { objToString, requireHerbarium } = require('../../../utils')
const pascalCase = require('lodash.startcase')
const camelCase = require('lodash.camelcase')
const fs = require('fs')
const path = require('path')

async function generateRequestschema(schema) {
// schema to plain JSON
Expand All @@ -29,7 +30,7 @@ module.exports = async ({ template: { generate }, filesystem }, command) => asyn
const { name, schema } = entity.entity.prototype.meta
for (const action of useCases) {
const useCaseName = `${action} ${name}`
const ucPath = `${filesystem.cwd()}/src/domain/usecases/${camelCase(name)}/${camelCase(useCaseName)}.js`
const ucPath = path.normalize(`${filesystem.cwd()}/src/domain/usecases/${camelCase(name)}/${camelCase(useCaseName)}.js`)

let type = 'read'
for (const t of ['create', 'update', 'delete']) {
Expand All @@ -52,6 +53,8 @@ module.exports = async ({ template: { generate }, filesystem }, command) => asyn
request: await generateRequestschema(schema)
}
})
process.stdout.write(` New: ${ucPath}\n`)

}
}
}
6 changes: 3 additions & 3 deletions src/generators/src/infra/database/migrations/migrations.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,16 @@ module.exports =
.toISOString()
.replace(/\D/g, '')
.substring(0, 14)
const migrationFile = `${migrationName}_${camelCase(name)}s.js`
const migrationFullPath = path.normalize(`${migrationsPath}/${migrationName}_${camelCase(name)}s.js`)

const columns = createColumns(schema)

await generate({
template: `infra/data/database/${db.toLowerCase()}/migration.ejs`,
target: `${migrationsPath}/${migrationFile}`,
target: migrationFullPath,
props: { table: `${camelCase(name)}s`, columns: columns }
})
process.stdout.write(`New: ${migrationFile}\n`)
process.stdout.write(` New: ${migrationFullPath}\n`)

}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const { requireHerbarium } = require('../../../../utils')
const camelCase = require('lodash.camelcase')
const fs = require('fs')
const path = require('path')

async function generateRepositories(generate, filesystem, db, command) {
const requires = {}
Expand All @@ -11,7 +12,7 @@ async function generateRepositories(generate, filesystem, db, command) {
for (const entity of Array.from(entities.values())) {
const { name } = entity.entity.prototype.meta
const lowCCName = camelCase(name)
const repositoryPath = `${filesystem.cwd()}/src/infra/data/repositories/${lowCCName}Repository.js`
const repositoryPath = path.normalize(`${filesystem.cwd()}/src/infra/data/repositories/${lowCCName}Repository.js`)

requires[`${lowCCName}Repository`] = `await new (require('./${lowCCName}Repository.js'))(conn)`

Expand All @@ -28,6 +29,8 @@ async function generateRepositories(generate, filesystem, db, command) {
table: `${lowCCName}s`
}
})
process.stdout.write(` New: ${repositoryPath}\n`)

}
return requires
}
Expand Down

0 comments on commit 1b62c9f

Please sign in to comment.