Skip to content
This repository has been archived by the owner on Sep 15, 2024. It is now read-only.

feature: add blox init --starter #71

Merged
merged 2 commits into from
Apr 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions cmd/blox_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@ package cmd
import (
// import go:embed
_ "embed"
"fmt"
"io/ioutil"
"os"
"os/exec"
"path"
"strings"

"github.com/pterm/pterm"
"github.com/spf13/cobra"
Expand All @@ -16,6 +20,7 @@ var (
dataDir string
buildDir string
schemataDir string
starter string
skipConfig bool
)

Expand All @@ -26,6 +31,13 @@ var initCmd = &cobra.Command{
Long: `Create a group of folders to store your content. A directory for your data,
schemata, and build output will be created.`,
Run: func(cmd *cobra.Command, args []string) {

if starter != "" {
cobra.CheckErr(installStarter(starter))
pterm.Info.Println("Starter initialized.")
return
}
// not a starter
err := createDirectories()
cobra.CheckErr(err)
pterm.Info.Println("Initialized folder structures.")
Expand Down Expand Up @@ -64,4 +76,68 @@ func init() {
initCmd.Flags().StringVarP(&schemataDir, "schemata", "s", "schemata", "where the schemata will be stored")
initCmd.Flags().BoolVarP(&skipConfig, "skip", "c", false, "don't write a configuration file")

initCmd.Flags().StringVarP(&starter, "starter", "t", "", "use a pre-defined starter in the CURRENT directory")

}

func installStarter(starter string) error {

pterm.Info.Printf("Installing starter %s\n", starter)
// kinda hacky, look for things that make a url or domain name
// if it's internal, it'll just be one word
internal := !strings.ContainsAny(starter, "/,.")
var repo string
if internal {
repo = fmt.Sprintf("https://github.com/cueblox/starter-%s", starter)
} else {
repo = starter
}

// git init in the existing directory
cmd := exec.Command("git", "init")
pterm.Info.Println("git init...")
err := cmd.Run()
if err != nil {
pterm.Info.Printf("git init error: %s\n", err)
return err
}

// add the starter as a remote
cmd = exec.Command("git", "remote", "add", "origin", repo)
pterm.Info.Println("git remote add...")
err = cmd.Run()
if err != nil {
pterm.Info.Printf("git remote error: %s\n", err)
return err
}
// git fetch on the remote
cmd = exec.Command("git", "fetch")
pterm.Info.Println("git fetch...")
err = cmd.Run()
if err != nil {
pterm.Info.Printf("git fetch error: %s\n", err)
return err
}

// checkout main
cmd = exec.Command("git", "checkout", "origin/main", "-ft")
pterm.Info.Println("git checkout...")
err = cmd.Run()
if err != nil {
pterm.Info.Printf("git checkout error: %s\n", err)
return err
}
here, err := os.Getwd()
if err != nil {
return err
}

// now remove all traces of the git checkout
err = os.RemoveAll(path.Join(here, ".git"))

if err != nil {
return err
}
pterm.Info.Println(repo)
return nil
}
2 changes: 1 addition & 1 deletion dogfood/repository/_build/manifest.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"Root":"repository","Namespace":"schemas.cueblox.com","Output":"_build","Schemas":[{"Namespace":"schemas.cueblox.com","Name":"article","Versions":[{"Namespace":"schemas.cueblox.com","Name":"v1","Schema":"article","Definition":"{\n\t_schema: {\n\t\tname: \"Article\"\n\t\tnamespace: \"schemas.cueblox.com\"\n\t}\n\n\t#Article: {\n\t\t_model: {\n\t\t\tplural: \"articles\"\n\t\t\tsupportedExtensions: [\"yaml\", \"yml\", \"md\", \"mdx\"]\n\t\t}\n\n\ttitle: string\n\texcerpt: string\n featured: bool | *false\n draft: bool | *false\n publish_date: string\n image?: string\n last_edit_date?: string\n edit_description?: string\n\tbody?: string\n\ttags?: [...string]\n category_id?: string\n profile_id?: string\n\t}\n\n}\n"}]},{"Namespace":"schemas.cueblox.com","Name":"category","Versions":[{"Namespace":"schemas.cueblox.com","Name":"v1","Schema":"category","Definition":"{\n\t_schema: {\n\t\tname: \"Category\"\n\t\tnamespace: \"schemas.cueblox.com\"\n\t}\n\n\t#Category: {\n\t\t_model: {\n\t\t\tplural: \"categories\"\n\t\t\tsupportedExtensions: [\"yaml\", \"yml\", \"md\", \"mdx\"]\n\t\t}\n\n\tname: string\n\tdescription: string\n body?: string\n\t}\n\n\n}\n"}]},{"Namespace":"schemas.cueblox.com","Name":"page","Versions":[{"Namespace":"schemas.cueblox.com","Name":"v1","Schema":"page","Definition":"{\n\t_schema: {\n\t\tname: \"Page\"\n\t\tnamespace: \"schemas.cueblox.com\"\n\t}\n\n\t#Page: {\n\t\t_model: {\n\t\t\tplural: \"pages\"\n\t\t\tsupportedExtensions: [\"yaml\", \"yml\", \"md\", \"mdx\"]\n\t\t}\n\n\ttitle: string\n\texcerpt: string\n draft: bool | *false\n publish_date: string\n image?: string\n\tbody?: string\n\ttags?: [...string]\n\tsection_id?: string\n\tweight?: int\n\t}\n\n}\n"}]},{"Namespace":"schemas.cueblox.com","Name":"profile","Versions":[{"Namespace":"schemas.cueblox.com","Name":"v1","Schema":"profile","Definition":"{\n\t_schema: {\n\t\tname: \"Profile\"\n\t\tnamespace: \"schemas.cueblox.com\"\n\t}\n\n\t#Profile: {\n\t\t_model: {\n\t\t\tplural: \"profiles\"\n\t\t\tsupportedExtensions: [\"yaml\", \"yml\", \"md\", \"mdx\"]\n\t\t}\n\n\t\tfirst_name: string\n\t\tlast_name: string\n\t\tage?: int\n\t\tcompany?: string\n\t\ttitle?: string\n\t\tbody?: string\n\t\tsocial_accounts?: [...#TwitterAccount | #GitHubAccount | #MiscellaneousAccount]\n\t}\n\n\t#TwitterAccount: {\n\t\tnetwork: \"twitter\"\n\t\tusername: string\n\t\turl: *\"https://twitter.com/\\(username)\" | string\n\t}\n\n\t#GitHubAccount: {\n\t\tnetwork: \"github\"\n\t\tusername: string\n\t\turl: *\"https://github.com/\\(username)\" | string\n\t}\n\n\t#MiscellaneousAccount: {\n\t\tnetwork: string\n\t\turl: string\n\t}\n}\n"}]},{"Namespace":"schemas.cueblox.com","Name":"section","Versions":[{"Namespace":"schemas.cueblox.com","Name":"v1","Schema":"section","Definition":"{\n\t_schema: {\n\t\tname: \"Section\"\n\t\tnamespace: \"schemas.cueblox.com\"\n\t}\n\n\t#Section: {\n\t\t_model: {\n\t\t\tplural: \"sections\"\n\t\t\tsupportedExtensions: [\"yaml\", \"yml\", \"md\", \"mdx\"]\n\t\t}\n\n\tname: string\n\tdescription: string\n body?: string\n\tweight?: int\n\t}\n\n\n}\n"}]},{"Namespace":"schemas.cueblox.com","Name":"website","Versions":[{"Namespace":"schemas.cueblox.com","Name":"v1","Schema":"website","Definition":"{\n\t_schema: {\n\t\tname: \"Profile\"\n\t\tnamespace: \"schemas.cueblox.com\"\n\t}\n\n\t#Website: {\n\t\t_model: {\n\t\t\tplural: \"websites\"\n\t\t\tsupportedExtensions: [\"yaml\", \"yml\"]\n\t\t}\n\n\t\turl: string\n\t\tprofile_id?: string\n\t\tbody?: string\n\t}\n}\n"}]}]}
{"Root":"repository","Namespace":"schemas.cueblox.com","Output":"_build","Schemas":[{"Namespace":"schemas.cueblox.com","Name":"article","Versions":[{"Namespace":"schemas.cueblox.com","Name":"v1","Schema":"article","Definition":"{\n\t_schema: {\n\t\tname: \"Article\"\n\t\tnamespace: \"schemas.cueblox.com\"\n\t}\n\n\t#Article: {\n\t\t_dataset: {\n\t\t\tplural: \"articles\"\n\t\t\tsupportedExtensions: [\"yaml\", \"yml\", \"md\", \"mdx\"]\n\t\t}\n\n\t\ttitle: string @template(\"My New Article\")\n\t\texcerpt: string @template(\"Small Description\")\n\t\tfeatured: bool | *false\n\t\tdraft: bool | *false\n\t\tpublish_date: string @template(\"2020-01-01\")\n\t\timage?: string\n\t\tlast_edit_date?: string\n\t\tedit_description?: string\n\t\tbody?: string @template(\"My Awesome Article\")\n\t\ttags?: [...string]\n\t\tcategory_id?: string\n\t\tprofile_id?: string\n\t}\n\n}\n"}]},{"Namespace":"schemas.cueblox.com","Name":"category","Versions":[{"Namespace":"schemas.cueblox.com","Name":"v1","Schema":"category","Definition":"{\n\t_schema: {\n\t\tname: \"Category\"\n\t\tnamespace: \"schemas.cueblox.com\"\n\t}\n\n\t#Category: {\n\t\t_dataset: {\n\t\t\tplural: \"categories\"\n\t\t\tsupportedExtensions: [\"yaml\", \"yml\", \"md\", \"mdx\"]\n\t\t}\n\n\t\tname: string @template(\"Name\")\n\t\tdescription: string @template(\"Description\")\n\t\tbody?: string @template(\"This is my category for ...\")\n\t}\n\n}\n"}]},{"Namespace":"schemas.cueblox.com","Name":"page","Versions":[{"Namespace":"schemas.cueblox.com","Name":"v1","Schema":"page","Definition":"{\n\t_schema: {\n\t\tname: \"Page\"\n\t\tnamespace: \"schemas.cueblox.com\"\n\t}\n\n\t#Page: {\n\t\t_dataset: {\n\t\t\tplural: \"pages\"\n\t\t\tsupportedExtensions: [\"yaml\", \"yml\", \"md\", \"mdx\"]\n\t\t}\n\n\t\ttitle: string @template(\"My New Page\")\n\t\texcerpt: string @template(\"Small description about my page\")\n\t\tdraft: bool | *false\n\t\tpublish_date: string @template(\"2020-01-01\")\n\t\timage?: string\n\t\tbody?: string\n\t\ttags?: [...string]\n\t\tsection_id?: string\n\t\tweight?: int\n\t}\n\n}\n"}]},{"Namespace":"schemas.cueblox.com","Name":"profile","Versions":[{"Namespace":"schemas.cueblox.com","Name":"v1","Schema":"profile","Definition":"{\n\t_schema: {\n\t\tname: \"Profile\"\n\t\tnamespace: \"schemas.cueblox.com\"\n\t}\n\n\t#Profile: {\n\t\t_dataset: {\n\t\t\tplural: \"profiles\"\n\t\t\tsupportedExtensions: [\"yaml\", \"yml\", \"md\", \"mdx\"]\n\t\t}\n\n\t\tfirst_name: string @template(\"Forename\")\n\t\tlast_name: string @template(\"Surname\")\n\t\tage?: int @template(21)\n\t\tcompany?: string @template(\"CueBlox\")\n\t\ttitle?: string @template(\"Cue Slinger\")\n\t\tbody?: string @template(\"☕️ Required\")\n\t\tsocial_accounts?: [...#TwitterAccount | #GitHubAccount | #MiscellaneousAccount]\n\t}\n\n\t#TwitterAccount: {\n\t\tnetwork: \"twitter\"\n\t\tusername: string @template(\"twitter-handle\")\n\t\turl: *\"https://twitter.com/\\(username)\" | string\n\t}\n\n\t#GitHubAccount: {\n\t\tnetwork: \"github\"\n\t\tusername: string @template(\"github-handle\")\n\t\turl: *\"https://github.com/\\(username)\" | string\n\t}\n\n\t#MiscellaneousAccount: {\n\t\tnetwork: string @template(\"some_network\")\n\t\turl: string @template(\"https://some_url\")\n\t}\n}\n"}]},{"Namespace":"schemas.cueblox.com","Name":"section","Versions":[{"Namespace":"schemas.cueblox.com","Name":"v1","Schema":"section","Definition":"{\n\t_schema: {\n\t\tname: \"Section\"\n\t\tnamespace: \"schemas.cueblox.com\"\n\t}\n\n\t#Section: {\n\t\t_dataset: {\n\t\t\tplural: \"sections\"\n\t\t\tsupportedExtensions: [\"yaml\", \"yml\", \"md\", \"mdx\"]\n\t\t}\n\n\t\tname: string @template(\"Name\")\n\t\tdescription: string @template(\"Small description\")\n\t\tbody?: string @template(\"All about this section\")\n\t\tweight?: int | *0\n\t}\n\n}\n"}]},{"Namespace":"schemas.cueblox.com","Name":"website","Versions":[{"Namespace":"schemas.cueblox.com","Name":"v1","Schema":"website","Definition":"{\n\t_schema: {\n\t\tname: \"Profile\"\n\t\tnamespace: \"schemas.cueblox.com\"\n\t}\n\n\t#Website: {\n\t\t_dataset: {\n\t\t\tplural: \"websites\"\n\t\t\tsupportedExtensions: [\"yaml\", \"yml\"]\n\t\t}\n\n\t\turl: string @template(\"https://google.com\")\n\t\tprofile_id?: string\n\t\tbody?: string\n\t}\n}\n"}]}]}
26 changes: 13 additions & 13 deletions dogfood/repository/article/v1/schema.cue
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,23 @@
}

#Article: {
_model: {
_dataset: {
plural: "articles"
supportedExtensions: ["yaml", "yml", "md", "mdx"]
}

title: string
excerpt: string
featured: bool | *false
draft: bool | *false
publish_date: string
image?: string
last_edit_date?: string
edit_description?: string
body?: string
tags?: [...string]
category_id?: string
profile_id?: string
title: string @template("My New Article")
excerpt: string @template("Small Description")
featured: bool | *false
draft: bool | *false
publish_date: string @template("2020-01-01")
image?: string
last_edit_date?: string
edit_description?: string
body?: string @template("My Awesome Article")
tags?: [...string]
category_id?: string
profile_id?: string
}

}
9 changes: 4 additions & 5 deletions dogfood/repository/category/v1/schema.cue
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@
}

#Category: {
_model: {
_dataset: {
plural: "categories"
supportedExtensions: ["yaml", "yml", "md", "mdx"]
}

name: string
description: string
body?: string
name: string @template("Name")
description: string @template("Description")
body?: string @template("This is my category for ...")
}


}
20 changes: 10 additions & 10 deletions dogfood/repository/page/v1/schema.cue
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@
}

#Page: {
_model: {
_dataset: {
plural: "pages"
supportedExtensions: ["yaml", "yml", "md", "mdx"]
}

title: string
excerpt: string
draft: bool | *false
publish_date: string
image?: string
body?: string
tags?: [...string]
section_id?: string
weight?: int
title: string @template("My New Page")
excerpt: string @template("Small description about my page")
draft: bool | *false
publish_date: string @template("2020-01-01")
image?: string
body?: string
tags?: [...string]
section_id?: string
weight?: int
}

}
22 changes: 11 additions & 11 deletions dogfood/repository/profile/v1/schema.cue
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,34 @@
}

#Profile: {
_model: {
_dataset: {
plural: "profiles"
supportedExtensions: ["yaml", "yml", "md", "mdx"]
}

first_name: string
last_name: string
age?: int
company?: string
title?: string
body?: string
first_name: string @template("Forename")
last_name: string @template("Surname")
age?: int @template(21)
company?: string @template("CueBlox")
title?: string @template("Cue Slinger")
body?: string @template("☕️ Required")
social_accounts?: [...#TwitterAccount | #GitHubAccount | #MiscellaneousAccount]
}

#TwitterAccount: {
network: "twitter"
username: string
username: string @template("twitter-handle")
url: *"https://twitter.com/\(username)" | string
}

#GitHubAccount: {
network: "github"
username: string
username: string @template("github-handle")
url: *"https://github.com/\(username)" | string
}

#MiscellaneousAccount: {
network: string
url: string
network: string @template("some_network")
url: string @template("https://some_url")
}
}
11 changes: 5 additions & 6 deletions dogfood/repository/section/v1/schema.cue
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@
}

#Section: {
_model: {
_dataset: {
plural: "sections"
supportedExtensions: ["yaml", "yml", "md", "mdx"]
}

name: string
description: string
body?: string
weight?: int
name: string @template("Name")
description: string @template("Small description")
body?: string @template("All about this section")
weight?: int | *0
}


}
4 changes: 2 additions & 2 deletions dogfood/repository/website/v1/schema.cue
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
}

#Website: {
_model: {
_dataset: {
plural: "websites"
supportedExtensions: ["yaml", "yml"]
}

url: string
url: string @template("https://google.com")
profile_id?: string
body?: string
}
Expand Down