diff --git a/commands/init.go b/commands/init.go index 9a15786e051bdaa74041a356dfb41cd106bd8215..c22afcd99d0f854fc3a10330152cdc3d359361e3 100644 --- a/commands/init.go +++ b/commands/init.go @@ -37,6 +37,12 @@ func InitProject(name string, dbType string) { // Create datasmith.yaml file from template createConfigFile(slug, name, dbType) + // Create an empty database.dbml file + createDBMLFile(slug) + + // Create LICENSE.md file from template + createLicenseFile(slug, name) + // TODO: copy base files fmt.Printf("Initialized new project structure in '%s'\n", slug) @@ -92,6 +98,34 @@ func createConfigFile(projectDir, projectName, dbType string) { } } +// createDBMLFile creates an empty database.dbml file in the project directory +func createDBMLFile(projectDir string) { + dbmlFilePath := filepath.Join(projectDir, "database.dbml") + file, err := os.Create(dbmlFilePath) + if err != nil { + fmt.Printf("Error creating database.dbml file: %v\n", err) + return + } + defer file.Close() + + fmt.Printf("Created file: %s/database.dbml\n", projectDir) +} + +// createLicenseFile creates the LICENSE.md file from template +func createLicenseFile(projectDir, projectName string) { + data := map[string]interface{}{ + "Name": projectName, + "Year": time.Now().Year(), + } + + err := templates.CreateFileFromTemplate(projectDir, "", "LICENSE.md", "LICENSE.md", data) + if err != nil { + fmt.Printf("Error creating LICENSE.md file: %v\n", err) + } else { + fmt.Printf("Created file: %s/LICENSE.md\n", projectDir) + } +} + // Help returns the help information for the init command func InitHelp() string { return "init [name] [--type mysql|postgres] : Create a new project with the specified name and database type." diff --git a/templates/LICENSE.md.tmpl b/templates/LICENSE.md.tmpl new file mode 100644 index 0000000000000000000000000000000000000000..02c00994487ba790b4ebc7fa2baf3febdfdda931 --- /dev/null +++ b/templates/LICENSE.md.tmpl @@ -0,0 +1,21 @@ +# MIT License + +Copyright (c) {{ .Year }} {{ .Name }} + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE.