Skip to content

Instantly share code, notes, and snippets.

@naosim
Created May 13, 2018 07:47
Show Gist options
  • Save naosim/ec748a69a646592b76a892019680d2ef to your computer and use it in GitHub Desktop.
Save naosim/ec748a69a646592b76a892019680d2ef to your computer and use it in GitHub Desktop.
バリューオブジェクト生成 (String)
const template = `
package __PACKAGE__;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
@AllArgsConstructor
@EqualsAndHashCode
public class __CLASS__ {
private final String value;
}
`.trim();
var fs = require('fs');
function mkdirs(path) {
try {
fs.mkdirSync(path);
} catch(e) {
if(e.code != 'EEXIST') {
var parent = path.split('/').slice(0, -1).join('/');
mkdirs(parent);
fs.mkdirSync(path);
}
}
}
if(process.argv.length < 4) {
console.log('node vo_string.js PACKAGE CLASS [SOURCE_ROOT_PATH]');
throw 'node vo_string.js PACKAGE CLASS [SOURCE_ROOT_PATH]'
}
const package = process.argv[2];
const clazz = process.argv[3];
const rootPath = process.argv[4] || './src/main/java';
const dir = rootPath + '/' + package.split('.').join('/');
const file = `${dir}/${clazz}.java`;
const text = template.split('__PACKAGE__').join(package).split('__CLASS__').join(clazz);
mkdirs(dir);
fs.writeFileSync(file, text);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment