<commit_before>package main

import (
	"bytes"
	"errors"
	"fmt"
	"go/build"
	"io"
	"path/filepath"
	"strings"

	"github.com/rainycape/command"

	"gnd.la/internal/gen/genutil"
	"gnd.la/log"
	"gnd.la/util/vfsutil"
)

type bakeOptions struct {
	Dir        string `help:"Root directory with the files to bake"`
	Name       string `help:"Variable name of the baked files. If empty, defaults to <dir>Data for data or <dir>FS for VFS."`
	VFS        bool   `help:"Wheter to generate a vfs.VFS variable or just an string which can be passed to VFS related functions" name:"vfs"`
	Out        string `name:"o" help:"Output filename. If empty, defaults to <dir>_baked.go"`
	Extensions string `name:"ext" help:"Additional extensions (besides html, css and js) to include, separated by commas"`
}

func bakeCommand(_ *command.Args, opts *bakeOptions) error {
	extensions := []string{".html", ".css", ".js"}
	if opts.Dir == "" {
		return errors.New("dir can't be empty")
	}
	if opts.Name == "" {
		base := filepath.Base(opts.Dir)
		if opts.VFS {
			opts.Name = base + "FS"
		} else {
			opts.Name = base + "Data"
		}
	}
	if opts.Out == "" {
		opts.Out = filepath.Base(opts.Dir) + "_baked.go"
	}
	extensions = append(extensions, strings.Split(opts.Extensions, ",")...)
	var buf bytes.Buffer
	odir := filepath.Dir(opts.Out)
	p, err := build.ImportDir(odir, 0)
	if err == nil {
		buf.WriteString(fmt.Sprintf("package %s\n", p.Name))
	}
	buf.WriteString(genutil.AutogenString())
	if err := writeBakedFSCode(&buf, opts, extensions); err != nil {<commit_msg>Remove leading _ from default output filename<commit_after>package main

import (
	"bytes"
	"errors"
	"fmt"
	"go/build"
	"io"
	"path/filepath"
	"strings"

	"github.com/rainycape/command"

	"gnd.la/internal/gen/genutil"
	"gnd.la/log"
	"gnd.la/util/vfsutil"
)

type bakeOptions struct {
	Dir        string `help:"Root directory with the files to bake"`
	Name       string `help:"Variable name of the baked files. If empty, defaults to <dir>Data for data or <dir>FS for VFS."`
	VFS        bool   `help:"Wheter to generate a vfs.VFS variable or just an string which can be passed to VFS related functions" name:"vfs"`
	Out        string `name:"o" help:"Output filename. If empty, defaults to <dir>_baked.go"`
	Extensions string `name:"ext" help:"Additional extensions (besides html, css and js) to include, separated by commas"`
}

func bakeCommand(_ *command.Args, opts *bakeOptions) error {
	extensions := []string{".html", ".css", ".js"}
	if opts.Dir == "" {
		return errors.New("dir can't be empty")
	}
	if opts.Name == "" {
		base := filepath.Base(opts.Dir)
		if opts.VFS {
			opts.Name = base + "FS"
		} else {
			opts.Name = base + "Data"
		}
	}
	if opts.Out == "" {
		opts.Out = filepath.Base(opts.Dir) + "_baked.go"
	}
	// go ignores files starting with _
	opts.Out = strings.TrimLeft(opts.Out, "_")
	extensions = append(extensions, strings.Split(opts.Extensions, ",")...)
	var buf bytes.Buffer
	odir := filepath.Dir(opts.Out)
	p, err := build.ImportDir(odir, 0)
	if err == nil {
		buf.WriteString(fmt.Sprintf("package %s\n", p.Name))
	}
	buf.WriteString(genutil.AutogenString())
	if err := writeBakedFSCode(&buf, opts, extensions); err != nil {
{'fraction_non_alphanumeric': 0.15280828365233762, 'fraction_numerical': 0.0006275494195167869, 'mean_word_length': 3.709010339734121, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '724012', 'n_tokens_mistral': 1171, 'n_tokens_neox': 1128, 'n_words': 316}