Skip to content

Commit

Permalink
fix #616
Browse files Browse the repository at this point in the history
  • Loading branch information
Aylur committed Nov 14, 2024
1 parent fb47b50 commit 802292e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 23 deletions.
37 changes: 15 additions & 22 deletions cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var initCommand = &cobra.Command{
Short: "Initialize a project directory",
Long: `Initialize a project directory by setting up files needed by TypeScript,
generating types and setting up a basic bar example`,
Args: cobra.MaximumNArgs(1),
Args: cobra.NoArgs,
Run: initConfig,
}

Expand All @@ -47,32 +47,25 @@ func initConfig(cmd *cobra.Command, args []string) {
lib.Err("currently only gtk3 is supported")
}

var configDir string
if len(args) > 0 {
var err error
configDir, err = filepath.Abs(args[0])
if err != nil {
lib.Err(err)
}
} else {
configDir = defaultConfigDir()
_, err := filepath.Abs(initDirectory)
if err != nil {
lib.Err(err)
}

if info, err := os.Stat(configDir); err == nil && info.IsDir() && !force {
lib.Err("could not initialize: " + lib.Cyan(configDir) + " already exists")
if info, err := os.Stat(initDirectory); err == nil && info.IsDir() && !force {
lib.Err("could not initialize: " + lib.Cyan(initDirectory) + " already exists")
}

tsconf := strings.ReplaceAll(getDataFile("tsconfig.json"), "@ASTAL_GJS@", astalGjs)
tsconf = strings.ReplaceAll(tsconf, "@GTK_VERSION@", "gtk3")
lib.Mkdir(configDir + "/widget")
lib.Mkdir(initDirectory + "/widget")

lib.WriteFile(configDir+"/.gitignore", "@girs/\nnode_modules/")
lib.WriteFile(configDir+"/tsconfig.json", tsconf)
lib.WriteFile(configDir+"/env.d.ts", getDataFile("env.d.ts"))
lib.WriteFile(configDir+"/style.scss", getDataFile("style.scss"))
lib.WriteFile(configDir+"/widget/Bar.tsx", getDataFile("gtk3/Bar.tsx"))
lib.WriteFile(configDir+"/app.ts", getDataFile("gtk3/app.ts"))
lib.WriteFile(initDirectory+"/.gitignore", "@girs/\nnode_modules/")
lib.WriteFile(initDirectory+"/tsconfig.json", tsconf)
lib.WriteFile(initDirectory+"/env.d.ts", getDataFile("env.d.ts"))
lib.WriteFile(initDirectory+"/style.scss", getDataFile("style.scss"))
lib.WriteFile(initDirectory+"/widget/Bar.tsx", getDataFile("gtk3/Bar.tsx"))
lib.WriteFile(initDirectory+"/app.ts", getDataFile("gtk3/app.ts"))

genTypes(configDir, "*")
fmt.Println(lib.Green("project ready") + " at " + lib.Cyan(configDir))
genTypes(initDirectory, "*")
fmt.Println(lib.Green("project ready") + " at " + lib.Cyan(initDirectory))
}
2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
welcomeText = ''
# Getting Started
- run `nix develop` to enter the development environment
- run `ags init . -f` to setup an initial ags project
- run `ags init -d . -f` to setup an initial ags project
- run `ags run .` to run the project
'';
};
Expand Down

0 comments on commit 802292e

Please sign in to comment.