init

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 1, 2025 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Copyright 2025 PRAS

Index

Constants

This section is empty.

Variables

View Source
var CreateConfigFile = func(locales []string) error {
	fullPath := filepath.Join(Config.Path, "prasmoid.config.js")
	RC := types.Config{
		Commands: types.ConfigCommands{
			Dir:    ".prasmoid/commands",
			Ignore: []string{},
		},
		I18n: types.ConfigI18n{
			Dir:     "translations",
			Locales: locales,
		},
	}
	configData, _ := jsonMarshalIndent(RC, "", "  ")
	content := fmt.Sprintf(`/// <reference path="prasmoid.d.ts" />
/** @type {PrasmoidConfig} */
const config = %v;`, string(configData))
	return osWriteFile(fullPath, []byte(content), 0644)
}
View Source
var CreateFileFromTemplate = func(relPath, contentTmpl string) error {
	fullPath := filepath.Join(Config.Path, relPath)
	if err := osMkdirAll(filepath.Dir(fullPath), 0755); err != nil {
		return fmt.Errorf("failed to create directory %s: %w", filepath.Dir(fullPath), err)
	}

	tmpl, err := templateNew(relPath).Parse(contentTmpl)
	if err != nil {
		return fmt.Errorf("failed to parse template for %s: %w", relPath, err)
	}

	var buf bytes.Buffer
	if err := tmpl.Execute(&buf, Config); err != nil {
		return fmt.Errorf("failed to execute template for %s: %w", relPath, err)
	}

	return osWriteFile(fullPath, buf.Bytes(), 0644)
}
View Source
var FileTemplates = map[string]string{
	"contents/ui/main.qml":        consts.MAIN_QML,
	"contents/config/main.xml":    consts.MAIN_XML,
	"contents/icons/prasmoid.svg": consts.PRASMOID_SVG,
	".gitignore":                  consts.GITIGNORE,
	"prasmoid.d.ts":               consts.PRASMOID_DTS,
}
View Source
var InitCmd = &cobra.Command{
	Use:   "init",
	Short: "Initialize a new plasmoid project",
	Run: func(cmd *cobra.Command, args []string) {
		clearLine()
		printHeader()

		if err := gatherProjectConfig(); err != nil {
			fmt.Println(color.RedString("Failed to gather project config: %v", err))
			return
		}

		fmt.Println(color.YellowString("Creating project at: %s", Config.Path))

		if err := InitPlasmoid(); err != nil {
			fmt.Println(color.RedString("Failed to initialize plasmoid: %v", err))
			return
		}

		if Config.InitGit && utilsIsPackageInstalled("git") {
			if err := initializeGitRepo(); err != nil {
				fmt.Println(color.YellowString("Could not initialize git repository: %v", err))
			} else {
				fmt.Println(color.GreenString("Initialized git repository."))
			}
		}

		fmt.Println()
		fmt.Println(color.GreenString("Plasmoid initialized successfully!"))
		fmt.Println()
		printNextSteps()
	},
}
View Source
var InitPlasmoid = func() error {

	for relPath, content := range FileTemplates {
		if err := CreateFileFromTemplate(relPath, content); err != nil {
			return err
		}
	}

	if err := createMetadataFile(); err != nil {
		return err
	}

	if err := CreateConfigFile(Config.Locales); err != nil {
		return err
	}

	_ = osMkdirAll(filepath.Join(Config.Path, ".prasmoid/commands"), 0755)

	plasmoidDir := filepath.Join(os.Getenv("HOME"), ".local/share/plasma/plasmoids")

	if _, err := osStat(plasmoidDir); os.IsNotExist(err) {
		_ = osMkdirAll(plasmoidDir, 0755)
	}

	dest := filepath.Join(plasmoidDir, Config.ID)

	_ = osRemoveAll(dest)

	cwd, err := osGetwd()
	if err != nil {
		return err
	}

	if err := osSymlink(filepath.Join(cwd, Config.Name), dest); err != nil {
		return fmt.Errorf("failed to create symlink: %w", err)
	}
	return nil
}

Functions

This section is empty.

Types

type Author

type Author struct {
	Name  string `json:"Name,omitempty"`
	Email string `json:"Email,omitempty"`
}

type KPlugin

type KPlugin struct {
	Authors          []Author `json:"Authors,omitempty"`
	Description      string   `json:"Description"`
	EnabledByDefault bool     `json:"EnabledByDefault"`
	FormFactors      []string `json:"FormFactors"`
	Id               string   `json:"Id"`
	License          string   `json:"License"`
	Name             string   `json:"Name"`
	Version          string   `json:"Version"`
}

type Metadata

type Metadata struct {
	KPackageStructure        string   `json:"KPackageStructure"`
	KPlugin                  KPlugin  `json:"KPlugin"`
	XPlasmaAPIMinimumVersion string   `json:"X-Plasma-API-Minimum-Version"`
	XPlasmaProvides          []string `json:"X-Plasma-Provides"`
}

type ProjectConfig

type ProjectConfig struct {
	Name        string
	Path        string
	ID          string
	Description string
	AuthorName  string
	AuthorEmail string
	License     string
	InitGit     bool
	Locales     []string
}
var Config ProjectConfig

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL