Comparing version 1.0.2 to 1.0.3
@@ -7,3 +7,2 @@ #!/usr/bin/env node | ||
const { | ||
generateAll, | ||
generateEntity, | ||
@@ -18,3 +17,3 @@ generateRepo, | ||
program | ||
.description('Move into the directory where your pom.xml is located') | ||
.description('First, move into the directory where your pom.xml is located') | ||
@@ -40,8 +39,2 @@ program | ||
program | ||
.command('all <name>') | ||
.alias('a') | ||
.description('Generate entity, rest controller and repository') | ||
.action(generateAll); | ||
program | ||
.command('prop') | ||
@@ -48,0 +41,0 @@ .alias('p') |
@@ -30,76 +30,57 @@ const { repo, entity, ctrl, prop, swaggerPom, swaggerConfig } = require('./klass'); | ||
const projectSources = () => { | ||
const projectSources = dir => { | ||
dir = dir ? '/' + dir : ''; | ||
const data = fs.readFileSync('./pom.xml'); | ||
const prj = convert.xml2js(data, { compact: true, spaces: 4 }).project; | ||
const path = `${prj.groupId._text}.${prj.artifactId._text}`; | ||
const split = path.split('.'); | ||
return `src/main/java/${split[0]}/${split[1]}/${split[2]}/`; | ||
}; | ||
const package = `${prj.groupId._text}.${prj.artifactId._text}${dir.replaceAll('/', '.')}`; | ||
const split = package.split('.'); | ||
const path = `src/main/java/${split[0]}/${split[1]}/${split[2]}${dir}/`; | ||
const scafold = () => { | ||
const sources = projectSources(); | ||
createIfNotExist(sources + 'controller'); | ||
createIfNotExist(sources + 'entity'); | ||
createIfNotExist(sources + 'repository'); | ||
createIfNotExist(sources + 'config'); | ||
return { package, path }; | ||
}; | ||
const generateAll = name => { | ||
generateEntity(name); | ||
generateRepo(name); | ||
generateRest(name); | ||
const splitParams = params => { | ||
const split = params.split('/'); | ||
return { | ||
path: split.slice(0, split.length - 1).join('/'), | ||
name: split[split.length - 1] | ||
} | ||
}; | ||
const generateRepo = name => { | ||
scafold(); | ||
const generateRepo = input => { | ||
const params = splitParams(input) | ||
const src = projectSources(params.path); | ||
const url = `${src.path}${params.name.capitalize()}Repository.java`; | ||
fs.readFile('./pom.xml', (err, data) => { | ||
createIfNotExist(src.path); | ||
fs.writeFile(url, repo(params.name, src.path), err => { | ||
if (err) throw err; | ||
const prj = convert.xml2js(data, { compact: true, spaces: 4 }).project; | ||
const path = `${prj.groupId._text}.${prj.artifactId._text}`; | ||
const split = path.split('.'); | ||
const fullPath = `src/main/java/${split[0]}/${split[1]}/${split[2]}/repository`; | ||
fs.writeFile(`${fullPath}/${name.capitalize()}Repository.java`, repo(name, path), err => { | ||
if (err) throw err; | ||
display('Repository created in ' + path); | ||
}); | ||
display('Repository created in ' + src.package); | ||
}); | ||
}; | ||
const generateEntity = name => { | ||
scafold(); | ||
const generateEntity = input => { | ||
const params = splitParams(input) | ||
const src = projectSources(params.path); | ||
const url = `${src.path}${params.name.capitalize()}.java`; | ||
fs.readFile('./pom.xml', (err, data) => { | ||
createIfNotExist(src.path); | ||
fs.writeFile(url, entity(params.name, src.path), err => { | ||
if (err) throw err; | ||
const prj = convert.xml2js(data, { compact: true, spaces: 4 }).project; | ||
const path = `${prj.groupId._text}.${prj.artifactId._text}`; | ||
const split = path.split('.'); | ||
const fullPath = `src/main/java/${split[0]}/${split[1]}/${split[2]}/entity`; | ||
fs.writeFile(`${fullPath}/${name.capitalize()}.java`, entity(name, path), err => { | ||
if (err) throw err; | ||
display('Entiy created in ' + path); | ||
}); | ||
display('Entity created in ' + src.package); | ||
}); | ||
}; | ||
const generateRest = name => { | ||
scafold(); | ||
fs.readFile('./pom.xml', (err, data) => { | ||
if (err) throw err; | ||
const generateRest = input => { | ||
const params = splitParams(input) | ||
const src = projectSources(params.path); | ||
const url = `${src.path}${params.name.capitalize()}Controller.java`; | ||
const prj = convert.xml2js(data, { compact: true, spaces: 4 }).project; | ||
const path = `${prj.groupId._text}.${prj.artifactId._text}`; | ||
const split = path.split('.'); | ||
const fullPath = `src/main/java/${split[0]}/${split[1]}/${split[2]}/controller`; | ||
createIfNotExist(src.path); | ||
fs.writeFile(`${fullPath}/${name.capitalize()}Controller.java`, ctrl(name, path), err => { | ||
if (err) throw err; | ||
display('Rest controller created in ' + path); | ||
}); | ||
fs.writeFile(url, ctrl(params.name, src.path), err => { | ||
if (err) throw err; | ||
display('Controller created in ' + src.package); | ||
}); | ||
@@ -109,5 +90,5 @@ }; | ||
const generateProperties = () => { | ||
const root = 'src/main/resources/application.properties'; | ||
const url = 'src/main/resources/application.properties'; | ||
fs.appendFile(root, '\r\n' + prop(), err => { | ||
fs.appendFile(url, '\r\n' + prop(), err => { | ||
if (err) throw err; | ||
@@ -118,3 +99,3 @@ display('Properties updated'); | ||
const importSwagger = () => { | ||
const importSwagger = (input = 'config') => { | ||
fs.readFile('./pom.xml', (err, data) => { | ||
@@ -124,3 +105,2 @@ if (err) throw err; | ||
const pom = convert.xml2js(data, { compact: true, spaces: 4 }); | ||
pom.project.dependencies.dependency.push(...swaggerPom()); | ||
@@ -131,3 +111,3 @@ | ||
createSwaggerConfig().then(display); | ||
createSwaggerConfig(input).then(display); | ||
display('pom.xml updated'); | ||
@@ -138,19 +118,12 @@ }); | ||
const createSwaggerConfig = () => { | ||
scafold(); | ||
const createSwaggerConfig = input => { | ||
return new Promise((resolve) => { | ||
fs.readFile('./pom.xml', (err, data) => { | ||
if (err) throw err; | ||
const src = projectSources(input); | ||
const url = `${src.path}/SwaggerConfig.java`; | ||
const prj = convert.xml2js(data, { compact: true, spaces: 4 }).project; | ||
const path = `${prj.groupId._text}.${prj.artifactId._text}`; | ||
createIfNotExist(src.path); | ||
const split = path.split('.'); | ||
const fullPath = `src/main/java/${split[0]}/${split[1]}/${split[2]}/config`; | ||
fs.writeFile(`${fullPath}/SwaggerConfig.java`, swaggerConfig(path), err => { | ||
if (err) throw err; | ||
resolve('SwaggerConfig.java created in ' + path); | ||
}); | ||
fs.writeFile(url, swaggerConfig(src.path), err => { | ||
if (err) throw err; | ||
resolve('SwaggerConfig.java created in ' + src.package); | ||
}); | ||
@@ -167,2 +140,2 @@ }); | ||
module.exports = { generateAll, generateRepo, generateEntity, generateRest, generateProperties, importSwagger, init } | ||
module.exports = { generateRepo, generateEntity, generateRest, generateProperties, importSwagger, init } |
require('./text.js'); | ||
const repo = (name, path) => ` | ||
package ${path}.repo; | ||
const repo = (name, path) => `package ${path}; | ||
import ${path}.entity.${name.capitalize()}; | ||
import org.springframework.stereotype.Repository; | ||
@@ -16,4 +14,3 @@ import org.springframework.data.jpa.repository.JpaRepository; | ||
const entity = (name, path) => ` | ||
package ${path}.entity; | ||
const entity = (name, path) => `package ${path}; | ||
@@ -47,7 +44,4 @@ import javax.persistence.Entity; | ||
const ctrl = (name, path) => ` | ||
package ${path}.controller; | ||
const ctrl = (name, path) => `package ${path}; | ||
import ${path}.entity.${name.capitalize()}; | ||
import ${path}.repo.${name.capitalize()}Repository; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
@@ -107,3 +101,3 @@ import org.springframework.web.bind.annotation.*; | ||
const swaggerConfig = (path) => `package ${path}.config; | ||
const swaggerConfig = (path) => `package ${path}; | ||
@@ -110,0 +104,0 @@ import org.springframework.context.annotation.Bean; |
String.prototype.capitalize = function() { | ||
return this.charAt(0).toUpperCase() + this.slice(1).toLowerCase(); | ||
} | ||
String.prototype.replaceAll = function(from, to) { | ||
return this.split(from).join(to); | ||
} |
{ | ||
"name": "sboot-gen", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "Spring boot generator", | ||
@@ -19,3 +19,4 @@ "main": "index.js", | ||
"sboot": "./index.js" | ||
} | ||
}, | ||
"devDependencies": {} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9142
6
252