Compare commits

...

23 Commits

Author SHA1 Message Date
KZacharski 2b5ee11af0 add an option to disable commiting after initializing in the config file or with an argument 2023-09-02 03:19:39 +02:00
KZacharski 39598ad4db Make the default gitignore modifiable with a file in the config folder 2023-09-02 03:03:07 +02:00
KZacharski b4696f63bb deprecated debug mode 2023-09-01 01:00:55 +02:00
KZacharski a17a27d74d Add an ability to disable adding a favicon with a config.txt line or an argument 2023-08-31 22:59:47 +02:00
KZacharski 5b55424b7f diji-build: Created a script for automatic building 2023-08-31 02:38:24 +02:00
KZacharski 00720e8842 Merge remote-tracking branch 'refs/remotes/origin/main' 2023-08-31 01:55:33 +02:00
KZacharski c9574be651 started working on diji-build 2023-08-31 01:53:39 +02:00
KZacharski 5b565b4803 1.2 2023-08-20 22:34:13 +02:00
KZacharski dcec5f3b1c add release to gitignore 2023-08-18 19:15:06 +02:00
KZacharski 3eb0963b97 1.1 2023-08-18 18:58:49 +02:00
KZacharski dd027f777b Made the config folder visible 2023-08-18 18:57:43 +02:00
KZacharski 7da442fad5 space 2023-08-18 18:25:35 +02:00
KZacharski 563b29def7 finished (i hope at least) 2023-08-18 18:02:00 +02:00
KZacharski 5cd904f076 idk what probably finished 2023-08-18 13:36:52 +02:00
KZacharski 2aa4cd10e2 config readme 2023-08-18 12:14:11 +02:00
KZacharski ae76df7649 debug mode 2023-08-18 12:08:31 +02:00
KZacharski bd305cd65d slowly becoming real 2023-08-18 11:40:46 +02:00
KZacharski 88413e616e basic html structure jasfljdsafksdkfsdafjadlfkjsakfd 2023-08-18 10:39:29 +02:00
Kacper Zacharski 7452c4f1a7 ironic 2023-08-18 09:59:30 +02:00
Kacper Zacharski 5ecba4b45a Just in case my hdd fails because I'm writing this on the thinkpad 2023-08-18 09:52:58 +02:00
Kacper Zacharski 03d449f033
Update README.md 2023-08-18 01:24:28 +02:00
Kacper Zacharski cfda33236f
Update README.md 2023-08-17 18:51:08 +02:00
Kacper Zacharski 7ebe6bfb0a
Update README.md 2023-08-17 18:47:15 +02:00
9 changed files with 431 additions and 2 deletions

4
.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
.DS_Store
*.test
diji
release

View File

@ -1,2 +1,7 @@
# diji <div align=center>
Create a vanilla js project in seconds <img src="https://github.com/KZacharski/diji/blob/github-files/banner.png?raw=true" width="60%">
<br>
<h1>diji</h1>
<p>Create a vanilla JS project in seconds</p>
</div>

47
diji-build.sh Executable file
View File

@ -0,0 +1,47 @@
#!/bin/bash
echo "diji-build 1.0"
version=$(go run . -- --buildversion)
echo "Building diji $version"
rldir="release"
if [ -f "$rldir" ] ; then
rm -rf "$rldir"
echo "Removed files from the previous build"
fi
mkdir release
mkdir release/diji
cp -r diji-config release/diji
echo "diji-config prepared"
GOOS=linux GOARCH=amd64 go build -o release/diji/diji
(cd release; zip -r diji-$version-linux-amd64.zip diji; rm -rf diji/diji)
echo "linux/amd64 built"
GOOS=linux GOARCH=386 go build -o release/diji/diji
(cd release; zip -r diji-$version-linux-i386.zip diji; rm -rf diji/diji)
echo "linux/386 built"
GOOS=linux GOARCH=arm64 go build -o release/diji/diji
(cd release; zip -r diji-$version-linux-arm64.zip diji; rm -rf diji/diji)
echo "linux/arm64 built"
GOOS=linux GOARCH=arm go build -o release/diji/diji
(cd release; zip -r diji-$version-linux-arm.zip diji; rm -rf diji/diji)
echo "linux/arm built"
GOOS=darwin GOARCH=amd64 go build -o release/diji/diji
(cd release; zip -r diji-$version-macos-amd64.zip diji; rm -rf diji/diji)
echo "darwin/amd64 built"
GOOS=darwin GOARCH=arm64 go build -o release/diji/diji
(cd release; zip -r diji-$version-macos-arm64.zip diji; rm -rf diji/diji)
echo "darwin/arm64 built"
GOOS=windows GOARCH=amd64 go build -o release/diji/diji.exe
(cd release; zip -r diji-$version-windows-amd64.zip diji; rm -rf diji/diji.exe)
echo "windows/amd64 built"
GOOS=windows GOARCH=386 go build -o release/diji/diji.exe
(cd release; zip -r diji-$version-windows-i386.zip diji; rm -rf diji/diji.exe)
echo "windows/386 built"
GOOS=windows GOARCH=arm64 go build -o release/diji/diji.exe
(cd release; zip -r diji-$version-windows-arm64.zip diji; rm -rf diji/diji.exe)
echo "windows/arm64 built"
GOOS=windows GOARCH=arm go build -o release/diji/diji.exe
(cd release; zip -r diji-$version-windows-arm.zip diji; rm -rf diji/diji.exe)
echo "windows/arm built"
rm -rf release/diji
echo "Cleaned up"
echo "Done, the zips are ready in the release directory"

6
diji-config/README.txt Normal file
View File

@ -0,0 +1,6 @@
diji config
----------------
This folder has to be in the same directory as the diji binary (or source file in development environments).
You can either move it together with the binary to your projects folder (for example Documents), where you'll create all of your projects or add the diji folder to your path.
You can also replace defaultfav.png with a favicon you want to set as default, like your logo. It can be any png image.

8
diji-config/config.txt Normal file
View File

@ -0,0 +1,8 @@
// Quick mode skips all the questions besides project name and always uses the default option.
quick-mode = false
// Should a favicon be added by default
favicon = true
// Create a commit after initializing the repo
commit = true

BIN
diji-config/defaultfav.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 177 KiB

View File

@ -0,0 +1 @@
.DS_Store

355
diji.go Normal file
View File

@ -0,0 +1,355 @@
package main
import (
"errors"
"fmt"
"io"
"log"
"os"
"os/exec"
"path/filepath"
"strings"
)
func check(e error) {
if e != nil {
panic(e)
}
}
func copy(src, dst string) (int64, error) {
sourceFileStat, err := os.Stat(src)
if err != nil {
return 0, err
}
if !sourceFileStat.Mode().IsRegular() {
return 0, fmt.Errorf("%s is not a regular file", src)
}
source, err := os.Open(src)
if err != nil {
return 0, err
}
defer source.Close()
destination, err := os.Create(dst)
if err != nil {
return 0, err
}
defer destination.Close()
nBytes, err := io.Copy(destination, source)
return nBytes, err
}
func main() {
var ver string = "1.3"
// var version int = 4
argsar := os.Args[1:]
var quickelement string = "-q"
var buildelement string = "--buildversion"
var addfavelement string = "-f"
var commitelement string = "-c"
var quickargument bool = false
var buildargument bool = false
var addfavargument bool = false
var commitargument bool = false
for i := 0; i < len(argsar); i++ {
// checking if the array contains the given value
if argsar[i] == quickelement {
// changing the boolean variable
quickargument = true
break
}
}
for i := 0; i < len(argsar); i++ {
// checking if the array contains the given value
if argsar[i] == buildelement {
// changing the boolean variable
buildargument = true
break
}
}
for i := 0; i < len(argsar); i++ {
// checking if the array contains the given value
if argsar[i] == addfavelement {
// changing the boolean variable
addfavargument = true
break
}
}
if buildargument == true {
fmt.Print(ver)
os.Exit(0)
}
for i := 0; i < len(argsar); i++ {
// checking if the array contains the given value
if argsar[i] == commitelement {
// changing the boolean variable
commitargument = true
break
}
}
var projname string
fmt.Println("地基")
fmt.Println("diji " + ver)
fmt.Println("by KZacharski")
fmt.Print("Project name: ")
fmt.Scanln(&projname)
var createcss bool = true
var createjs bool = true
var createsample bool = false
var initgit bool = true
var creategitignore bool = true
var configlocation string
var configfile string
var exPath string
if _, err := os.Stat("diji-config"); err == nil {
configlocation = "diji-config"
} else if errors.Is(err, os.ErrNotExist) {
ex, err := os.Executable()
if err != nil {
panic(err)
}
exPath = filepath.Dir(ex)
configlocation = exPath + "/diji-config"
}
configfile = configlocation + "/config.txt"
configbytes, err := os.ReadFile(configfile)
if err != nil {
fmt.Print(err)
}
configtext := string(configbytes)
var gitemplatelocation string
gitemplatelocation = configlocation + "/gitignore.txt"
gibytes, err := os.ReadFile(gitemplatelocation)
if err != nil {
fmt.Print(err)
}
gitemplatetext := string(gibytes)
var quickmode bool = strings.Contains(configtext, "quick-mode = true")
var addfav bool = strings.Contains(configtext, "favicon = true")
var commitinit bool = strings.Contains(configtext, "commit = true")
if quickargument == true {
if quickmode == true {
quickmode = false
} else if quickmode == false {
quickmode = true
}
}
if addfavargument == true {
if addfav == true {
addfav = false
} else if addfav == false {
addfav = true
}
}
if commitargument == true {
if commitinit == true {
commitinit = false
} else if commitinit == false {
commitinit = true
}
}
var cssstr string
var jsstr string
var samplestr string
var langstr string = "en"
var gitstr string
var gitignorestr string
var gifiles string
if quickmode == false {
fmt.Print("Create a css file (y/n, default y): ")
fmt.Scanln(&cssstr)
fmt.Print("Create a js file (y/n, default y): ")
fmt.Scanln(&jsstr)
fmt.Print("Website language (default en): ")
fmt.Scanln(&langstr)
fmt.Print("Insert sample content (y/n, default n): ")
fmt.Scanln(&samplestr)
fmt.Print("Initialize a git repo (y/n, default y): ")
fmt.Scanln(&gitstr)
if gitstr == "n" {
initgit = false
}
if initgit == true {
fmt.Print("Create .gitignore (y/n, default y): ")
fmt.Scanln(&gitignorestr)
if gitignorestr == "n" {
creategitignore = false
}
if creategitignore == true {
fmt.Print("Add files/file types to .gitignore: ")
fmt.Scanln(&gifiles)
}
}
if cssstr == "n" {
createcss = false
}
if jsstr == "n" {
createjs = false
}
if samplestr == "y" {
createsample = true
}
}
if initgit == false {
creategitignore = false
}
if err := os.Mkdir(projname, os.ModePerm); err != nil {
log.Fatal(err)
}
var indname string = projname + "/index.html"
index, err := os.Create(indname)
if err != nil {
log.Fatal(err)
}
if addfav == true {
var assetspath string = projname + "/assets"
if err := os.Mkdir(assetspath, os.ModePerm); err != nil {
log.Fatal(err)
}
var favpath string = assetspath + "/favicon.png"
copy(configlocation+"/defaultfav.png", favpath)
fmt.Println(favpath + " created.")
}
var indexcontent1 string = `<!DOCTYPE html>
<html lang="` + langstr + `">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>` + projname + `</title>
`
var csstag string = `<link rel="stylesheet" type="text/css" href="style.css">
`
var jstag string = `<script src="script.js"></script>
`
var indexcontent2 string = `</head>
<body>
</body>
</html>`
var samplecontent string = `<h1>` + projname + `</h1>
<h3>Generated with diji ` + ver + `</h3>
<p>Website content</p>`
if createsample == true {
indexcontent2 = `</head>
<body>
` + samplecontent + `
</body>`
}
var favtag string = `<link rel="icon" type="image" href="./assets/favicon.png">
`
if addfav == true {
indexcontent1 = indexcontent1 + favtag
}
if createcss == true {
indexcontent1 = indexcontent1 + csstag
}
if createjs == true {
indexcontent1 = indexcontent1 + jstag
}
var indexcontent string = indexcontent1 + indexcontent2
_, err2 := index.WriteString(indexcontent)
check(err2)
defer index.Close()
fmt.Println(indname + " created.")
var cssname string
var csscontent string
if createcss == true {
cssname = projname + "/style.css"
csscontent = `body {
font-family: sans-serif;
}`
style, err := os.Create(cssname)
if err != nil {
log.Fatal(err)
}
_, err2 := style.WriteString(csscontent)
check(err2)
defer style.Close()
fmt.Println(cssname + " created.")
}
var jsname string
if createjs == true {
jsname = projname + "/script.js"
script, err := os.Create(jsname)
if err != nil {
log.Fatal(err)
}
defer script.Close()
fmt.Println(jsname + " created.")
}
var giname string
var gicontent string
if creategitignore == true {
giname = projname + "/.gitignore"
gicontent = gitemplatetext + gifiles
gignore, err := os.Create(giname)
if err != nil {
log.Fatal(err)
}
_, err2 := gignore.WriteString(gicontent)
check(err2)
defer gignore.Close()
fmt.Println(giname + " created.")
}
if initgit == true {
cmd := exec.Command("git", "init", projname)
if err := cmd.Run(); err != nil {
log.Fatal(err)
}
if commitinit == true {
cmd1 := exec.Command("git", "add", ".")
cmd1.Dir = "./" + projname
if err := cmd1.Run(); err != nil {
log.Fatal(err)
}
cmd2 := exec.Command("git", "commit", "-a", "-m", `"Initial commit"`)
cmd2.Dir = "./" + projname
if err := cmd2.Run(); err != nil {
log.Fatal(err)
}
}
fmt.Println("Git repo initialized.")
}
fmt.Println("Project created in ./" + projname + ".")
fmt.Println("Thanks for using diji.")
}

3
go.mod Normal file
View File

@ -0,0 +1,3 @@
module KZacharski/diji
go 1.21.0