Demand background

Many of the repetitive tasks involved in creating project directories and project files, such as Java generating entity classes from table fields, are readily available. In addition, not only Java, but also other development files, JS, TS and even Vue files have a lot of repetitive work. Of course, many ides have helped us solve many problems, such as using vscode to customize templates and generate the contents of the templates. Two unresolved pain points, first directory-level control, second dynamic data insertion (data can come from interfaces, databases, custom templates)

Implementation effect

A template

public class Result {
  <% _.forEach(tests, function(test) { %> private <%- test.type %> <%- test.name %>; The < %}); % >}Copy the code

generate

public class Result {
  private String name;
  private long id;
}Copy the code

The template 2

export default {
  name: 'componentName'//import components that need to be injected into objects to use components: {},data() {// This is where the data is storedreturn{}}, // Listen on attributes similar to the concept of data, computed: {}, // Monitor changes in data watch: {}, // Set of methods methods: {}, // Lifecycle - Created (you can access the current this instance)created() {}, // Lifecycle - mount complete (DOM elements can be accessed)mounted() {},
  beforeCreate() {}, // Life cycle - before creationbeforeMount() {}, // Lifecycle - before mountbeforeUpdate() {}, // Lifecycle - before updateupdated() {}, // Life cycle - after updatebeforeDestroy() {}, // Lifecycle - before destructiondestroyed() {}, // Lifecycle - Destruction completedactivated() {} // If the page has keep-alive caching, this function will be triggered}Copy the code

Generate (replace a string)

export default {
  name: 'myComponent'//import components that need to be injected into objects to use components: {},data() {// This is where the data is storedreturn{}}, // Listen on attributes similar to the concept of data, computed: {}, // Monitor changes in data watch: {}, // Set of methods methods: {}, // Lifecycle - Created (you can access the current this instance)created() {}, // Lifecycle - mount complete (DOM elements can be accessed)mounted() {},
  beforeCreate() {}, // Life cycle - before creationbeforeMount() {}, // Lifecycle - before mountbeforeUpdate() {}, // Lifecycle - before updateupdated() {}, // Life cycle - after updatebeforeDestroy() {}, // Lifecycle - before destructiondestroyed() {}, // Lifecycle - Destruction completedactivated() {} // If the page has keep-alive caching, this function will be triggered}Copy the code


scenario

Generate project directory structure according to the directory structure of the configuration page, and generate corresponding file modules according to the file type and template of each file

Technology stack

  1. The template of lodash
  2. Nodejs in fs

Git address (project start)

Github.com/fodelf/gene…