Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sveltekit latest #106

Merged
merged 6 commits into from
Sep 5, 2022
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
15 changes: 7 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ With few commands Sveltin flex the muscles 💪

```bash
# Create a project with TailwindCSS support
sveltin new myBlog --css tailwindcss
sveltin init myBlog --css tailwindcss

# Move to the project folder
cd myBlog
Expand All @@ -90,11 +90,11 @@ sveltin new resource posts

# Add new content to the posts resource
# (http://localhost:5173/posts/getting-started)
sveltin new content posts/getting-started
sveltin add content posts/getting-started

# Add a 'category' metadata
# (http://localhost:5173/posts/category)
sveltin new metadata category --resource posts --type single
sveltin add metadata category --to posts --as single

# Run the server
sveltin server
Expand Down Expand Up @@ -199,15 +199,15 @@ Read more [here][init].

`sveltin new` is the main command to generate pages, resources (routes) and themes for your project.

Alias: `create`
Alias: `n`

<details>
<summary>(Click to expand the list of avilable subcommands)</summary>

| Subcommand | Aliases | Description |
| :--------- | :----------: | :--------------------------------------------------------------------- |
| [page] | p | Command to create a new public page. |
| [resource] | r | Command to create a new resource. |
| [resource] | r, route | Command to create a new resource. |

</details>

Expand Down Expand Up @@ -235,7 +235,7 @@ Read more [here][add].

`sveltin generate` is used to generate static files like sitemap, menu structure or rss feed file.

Alias: `g`, `gen`
Alias: `g`

<details>
<summary>(Click to expand the list of avilable subcommands)</summary>
Expand All @@ -254,7 +254,7 @@ Read more [here][generate].

`sveltin install` is used to initialize the Sveltin project getting all depencencies from the `package.json` file.

Alias: `i`, `init`
Alias: `i`

Read more [here][install].

Expand Down Expand Up @@ -308,7 +308,6 @@ Sveltin is free and open-source software licensed under the Apache 2.0 License.
[new]: https://docs.sveltin.io/cli/new/
[resource]: https://docs.sveltin.io/cli/new-resource/
[page]: https://docs.sveltin.io/cli/new-page/
[theme]: https://docs.sveltin.io/cli/new-theme/
[add]: https://docs.sveltin.io/cli/add/
[content]: https://docs.sveltin.io/cli/add-content/
[metadata]: https://docs.sveltin.io/cli/add-metadata/
Expand Down
2 changes: 1 addition & 1 deletion cmd/addMetadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ var (

var addMetadataCmd = &cobra.Command{
Use: "metadata [name] --to [resource] --as [single|list]",
Aliases: []string{"groupedBy"},
Aliases: []string{"m"},
Short: "Command to add a new metadata for your content to an existing Sveltekit resource",
Long: resources.GetASCIIArt() + `
Command to add new metadata for your content to an existing resource.
Expand Down
2 changes: 1 addition & 1 deletion cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (

var generateCmd = &cobra.Command{
Use: "generate",
Aliases: []string{"g, gen"},
Aliases: []string{"g"},
Args: cobra.MinimumNArgs(1),
Short: "Generate static files (sitemap, rss, menu)",
Long: resources.GetASCIIArt() + `
Expand Down
5 changes: 3 additions & 2 deletions cmd/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ const (
//=============================================================================

var newCmd = &cobra.Command{
Use: "new",
Short: "Create new resources, pages and themes",
Use: "new",
Aliases: []string{"n"},
Short: "Create new resources, pages and themes",
Long: `Command to create resources (e.g. blog posts, recipes, ...), pages and themes depending on the subcommand used with it.

Examples:
Expand Down
3 changes: 0 additions & 3 deletions cmd/newResource.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,6 @@ func RunNewResourceCmd(cmd *cobra.Command, args []string) {

// NEXT STEPS
common.PrintHelperTextNewResource(resourceName)
//cfg.log.Plain(utils.Underline("Next Steps"))
//cfg.log.Success("Resource ready to be used. Start by adding content to it.")
//cfg.log.Important(fmt.Sprintf("Eg: sveltin new content %s/getting-started", resourceName))
}

func init() {
Expand Down
1 change: 1 addition & 0 deletions internal/css/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const (
AppCSSFileID string = "app_css"
VariablesFileID string = "variables_scss"
LayoutFileID string = "layout"
LayoutTSFileID string = "layout_ts"
ErrorFileID string = "error"
SvelteConfigFileID string = "svelte_config"
ViteConfigFileID string = "vite_config"
Expand Down
39 changes: 33 additions & 6 deletions internal/css/cssframework.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ func makeSveltinStyled(cssLib *CSSLib) error {
if err := common.MoveFile(cssLib.EFS, cssLib.FS, sourceFile, saveAs, false); err != nil {
return err
}
// Copying vite.config.js file
// Copying vite.config.ts file
sourceFile = embeddedResources[ViteConfigFileID]
template = helpers.BuildTemplate(sourceFile, nil, cssLib.TplData)
content = template.Run(cssLib.EFS)
saveAs = filepath.Join(cssLib.Config.GetProjectRoot(), cssLib.TplData.ProjectName, "vite.config.js")
saveAs = filepath.Join(cssLib.Config.GetProjectRoot(), cssLib.TplData.ProjectName, "vite.config.ts")
if err := helpers.WriteContentToDisk(cssLib.FS, saveAs, content); err != nil {
return err
}
Expand Down Expand Up @@ -103,6 +103,15 @@ func makeSveltinStyled(cssLib *CSSLib) error {
return err
}

// Copying +layout.ts. file
sourceFile = embeddedResources[LayoutTSFileID]
template = helpers.BuildTemplate(sourceFile, nil, cssLib.TplData)
content = template.Run(cssLib.EFS)
saveAs = filepath.Join(cssLib.Config.GetProjectRoot(), cssLib.TplData.ProjectName, "src", "routes", "+layout.ts")
if err := helpers.WriteContentToDisk(cssLib.FS, saveAs, content); err != nil {
return err
}

// Copying +error.svelte. file
sourceFile = embeddedResources[ErrorFileID]
template = helpers.BuildTemplate(sourceFile, nil, cssLib.TplData)
Expand Down Expand Up @@ -148,11 +157,11 @@ func makeUnstyled(cssLib *CSSLib) error {
if err := common.MoveFile(cssLib.EFS, cssLib.FS, sourceFile, saveAs, false); err != nil {
return err
}
// Copying vite.config.js file
// Copying vite.config.ts file
sourceFile = embeddedResources[ViteConfigFileID]
template = helpers.BuildTemplate(sourceFile, nil, cssLib.TplData)
content = template.Run(cssLib.EFS)
saveAs = filepath.Join(cssLib.Config.GetProjectRoot(), cssLib.TplData.ProjectName, "vite.config.js")
saveAs = filepath.Join(cssLib.Config.GetProjectRoot(), cssLib.TplData.ProjectName, "vite.config.ts")
if err := helpers.WriteContentToDisk(cssLib.FS, saveAs, content); err != nil {
return err
}
Expand Down Expand Up @@ -183,6 +192,15 @@ func makeUnstyled(cssLib *CSSLib) error {
return err
}

// Copying +layout.ts. file
sourceFile = embeddedResources[LayoutTSFileID]
template = helpers.BuildTemplate(sourceFile, nil, cssLib.TplData)
content = template.Run(cssLib.EFS)
saveAs = filepath.Join(cssLib.Config.GetProjectRoot(), cssLib.TplData.ProjectName, "src", "routes", "+layout.ts")
if err := helpers.WriteContentToDisk(cssLib.FS, saveAs, content); err != nil {
return err
}

// Copying +error.svelte. file
sourceFile = embeddedResources[ErrorFileID]
template = helpers.BuildTemplate(sourceFile, nil, cssLib.TplData)
Expand Down Expand Up @@ -221,11 +239,11 @@ func makeTheme(cssLib *CSSLib) error {
if err := common.MoveFile(cssLib.EFS, cssLib.FS, sourceFile, saveAs, false); err != nil {
return err
}
// Copying vite.config.js file
// Copying vite.config.ts file
sourceFile = embeddedResources[ViteConfigFileID]
template = helpers.BuildTemplate(sourceFile, nil, cssLib.TplData)
content = template.Run(cssLib.EFS)
saveAs = filepath.Join(cssLib.Config.GetProjectRoot(), cssLib.TplData.ProjectName, "vite.config.js")
saveAs = filepath.Join(cssLib.Config.GetProjectRoot(), cssLib.TplData.ProjectName, "vite.config.ts")
if err := helpers.WriteContentToDisk(cssLib.FS, saveAs, content); err != nil {
return err
}
Expand Down Expand Up @@ -256,6 +274,15 @@ func makeTheme(cssLib *CSSLib) error {
return err
}

// Copying +layout.ts. file
sourceFile = embeddedResources[LayoutTSFileID]
template = helpers.BuildTemplate(sourceFile, nil, cssLib.TplData)
content = template.Run(cssLib.EFS)
saveAs = filepath.Join(cssLib.Config.GetProjectRoot(), cssLib.TplData.ProjectName, "src", "routes", "+layout.ts")
if err := helpers.WriteContentToDisk(cssLib.FS, saveAs, content); err != nil {
return err
}

// Copying +error.svelte. file
sourceFile = embeddedResources[ErrorFileID]
template = helpers.BuildTemplate(sourceFile, nil, cssLib.TplData)
Expand Down
30 changes: 20 additions & 10 deletions resources/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,9 @@ var SveltinXMLFS = map[string]string{
var BootstrapSveltinThemeFS = SveltinFSItem{
"package_json": "internal/templates/themes/sveltin/bootstrap/package.json.gotxt",
"svelte_config": "internal/templates/themes/sveltin/bootstrap/svelte.config.js",
"vite_config": "internal/templates/themes/sveltin/bootstrap/vite.config.js.gotxt",
"vite_config": "internal/templates/themes/sveltin/bootstrap/vite.config.ts.gotxt",
"layout": "internal/templates/themes/sveltin/bootstrap/layout.svelte.gotxt",
"layout_ts": "internal/templates/themes/layout.ts.gotxt",
"app_html": "internal/templates/themes/sveltin/bootstrap/app.html",
"app_css": "internal/templates/themes/sveltin/bootstrap/app.scss",
"variables_scss": "internal/templates/themes/sveltin/bootstrap/variables.scss",
Expand All @@ -122,9 +123,10 @@ var BootstrapSveltinThemeFS = SveltinFSItem{
var BootstrapBlankThemeFS = SveltinFSItem{
"package_json": "internal/templates/themes/blank/bootstrap/package.json.gotxt",
"svelte_config": "internal/templates/themes/blank/bootstrap/svelte.config.js",
"vite_config": "internal/templates/themes/blank/bootstrap/vite.config.js.gotxt",
"vite_config": "internal/templates/themes/blank/bootstrap/vite.config.ts.gotxt",
"app_html": "internal/templates/themes/blank/bootstrap/app.html",
"layout": "internal/templates/themes/blank/bootstrap/layout.svelte.gotxt",
"layout_ts": "internal/templates/themes/layout.ts.gotxt",
"app_css": "internal/templates/themes/blank/bootstrap/app.scss",
"variables_scss": "internal/templates/themes/blank/bootstrap/variables.scss",
"hero": "internal/templates/themes/blank/bootstrap/Hero.svelte",
Expand All @@ -137,8 +139,9 @@ var BootstrapBlankThemeFS = SveltinFSItem{
var BulmaSveltinThemeFS = SveltinFSItem{
"package_json": "internal/templates/themes/sveltin/bulma/package.json.gotxt",
"svelte_config": "internal/templates/themes/sveltin/bulma/svelte.config.js",
"vite_config": "internal/templates/themes/sveltin/bulma/vite.config.js.gotxt",
"vite_config": "internal/templates/themes/sveltin/bulma/vite.config.ts.gotxt",
"layout": "internal/templates/themes/sveltin/bulma/layout.svelte.gotxt",
"layout_ts": "internal/templates/themes/layout.ts.gotxt",
"app_html": "internal/templates/themes/sveltin/bulma/app.html",
"app_css": "internal/templates/themes/sveltin/bulma/app.scss",
"variables_scss": "internal/templates/themes/sveltin/bulma/variables.scss",
Expand All @@ -151,9 +154,10 @@ var BulmaSveltinThemeFS = SveltinFSItem{
var BulmaBlankThemeFS = SveltinFSItem{
"package_json": "internal/templates/themes/blank/bulma/package.json.gotxt",
"svelte_config": "internal/templates/themes/blank/bulma/svelte.config.js",
"vite_config": "internal/templates/themes/blank/bulma/vite.config.js.gotxt",
"vite_config": "internal/templates/themes/blank/bulma/vite.config.ts.gotxt",
"app_html": "internal/templates/themes/blank/bulma/app.html",
"layout": "internal/templates/themes/blank/bulma/layout.svelte.gotxt",
"layout_ts": "internal/templates/themes/layout.ts.gotxt",
"app_css": "internal/templates/themes/blank/bulma/app.scss",
"variables_scss": "internal/templates/themes/blank/bulma/variables.scss",
"hero": "internal/templates/themes/blank/bulma/Hero.svelte",
Expand All @@ -166,9 +170,10 @@ var BulmaBlankThemeFS = SveltinFSItem{
var SCSSSveltinThemeFS = SveltinFSItem{
"package_json": "internal/templates/themes/sveltin/scss/package.json.gotxt",
"svelte_config": "internal/templates/themes/sveltin/scss/svelte.config.js",
"vite_config": "internal/templates/themes/sveltin/scss/vite.config.js.gotxt",
"vite_config": "internal/templates/themes/sveltin/scss/vite.config.ts.gotxt",
"app_html": "internal/templates/themes/sveltin/scss/app.html",
"layout": "internal/templates/themes/sveltin/scss/layout.svelte.gotxt",
"layout_ts": "internal/templates/themes/layout.ts.gotxt",
"app_css": "internal/templates/themes/sveltin/scss/app.scss",
"variables_scss": "internal/templates/themes/sveltin/scss/variables.scss",
"hero": "internal/templates/themes/sveltin/scss/Hero.svelte",
Expand All @@ -180,8 +185,9 @@ var SCSSSveltinThemeFS = SveltinFSItem{
var SCSSBlankThemeFS = SveltinFSItem{
"package_json": "internal/templates/themes/blank/scss/package.json.gotxt",
"svelte_config": "internal/templates/themes/blank/scss/svelte.config.js",
"vite_config": "internal/templates/themes/blank/scss/vite.config.js.gotxt",
"vite_config": "internal/templates/themes/blank/scss/vite.config.ts.gotxt",
"layout": "internal/templates/themes/blank/scss/layout.svelte.gotxt",
"layout_ts": "internal/templates/themes/layout.ts.gotxt",
"app_html": "internal/templates/themes/blank/scss/app.html",
"app_css": "internal/templates/themes/blank/scss/app.scss",
"variables_scss": "internal/templates/themes/blank/scss/variables.scss",
Expand All @@ -195,9 +201,10 @@ var SCSSBlankThemeFS = SveltinFSItem{
var TailwindSveltinThemeFS = SveltinFSItem{
"package_json": "internal/templates/themes/sveltin/tailwindcss/package.json.gotxt",
"svelte_config": "internal/templates/themes/sveltin/tailwindcss/svelte.config.js",
"vite_config": "internal/templates/themes/sveltin/tailwindcss/vite.config.js.gotxt",
"vite_config": "internal/templates/themes/sveltin/tailwindcss/vite.config.ts.gotxt",
"tailwind_css_config": "internal/templates/themes/sveltin/tailwindcss/tailwind.config.cjs",
"layout": "internal/templates/themes/sveltin/tailwindcss/layout.svelte.gotxt",
"layout_ts": "internal/templates/themes/layout.ts.gotxt",
"app_html": "internal/templates/themes/sveltin/tailwindcss/app.html",
"postcss": "internal/templates/themes/sveltin/tailwindcss/postcss.config.cjs",
"app_css": "internal/templates/themes/sveltin/tailwindcss/app.css",
Expand All @@ -210,10 +217,11 @@ var TailwindSveltinThemeFS = SveltinFSItem{
var TailwindBlankThemeFS = SveltinFSItem{
"package_json": "internal/templates/themes/blank/tailwindcss/package.json.gotxt",
"svelte_config": "internal/templates/themes/blank/tailwindcss/svelte.config.js",
"vite_config": "internal/templates/themes/blank/tailwindcss/vite.config.js.gotxt",
"vite_config": "internal/templates/themes/blank/tailwindcss/vite.config.ts.gotxt",
"tailwind_css_config": "internal/templates/themes/blank/tailwindcss/tailwind.config.cjs",
"postcss": "internal/templates/themes/blank/tailwindcss/postcss.config.cjs",
"layout": "internal/templates/themes/blank/tailwindcss/layout.svelte.gotxt",
"layout_ts": "internal/templates/themes/layout.ts.gotxt",
"app_html": "internal/templates/themes/blank/tailwindcss/app.html",
"app_css": "internal/templates/themes/blank/tailwindcss/app.css",
"hero": "internal/templates/themes/blank/tailwindcss/Hero.svelte",
Expand All @@ -226,9 +234,10 @@ var TailwindBlankThemeFS = SveltinFSItem{
var VanillaSveltinThemeFS = SveltinFSItem{
"package_json": "internal/templates/themes/sveltin/vanillacss/package.json.gotxt",
"svelte_config": "internal/templates/themes/sveltin/vanillacss/svelte.config.js",
"vite_config": "internal/templates/themes/sveltin/vanillacss/vite.config.js.gotxt",
"vite_config": "internal/templates/themes/sveltin/vanillacss/vite.config.ts.gotxt",
"app_html": "internal/templates/themes/sveltin/vanillacss/app.html",
"layout": "internal/templates/themes/sveltin/vanillacss/layout.svelte.gotxt",
"layout_ts": "internal/templates/themes/layout.ts.gotxt",
"app_css": "internal/templates/themes/sveltin/vanillacss/app.css",
"hero": "internal/templates/themes/sveltin/vanillacss/Hero.svelte",
"footer": "internal/templates/themes/sveltin/vanillacss/Footer.svelte",
Expand All @@ -239,9 +248,10 @@ var VanillaSveltinThemeFS = SveltinFSItem{
var VanillaBlankThemeFS = SveltinFSItem{
"package_json": "internal/templates/themes/blank/vanillacss/package.json.gotxt",
"svelte_config": "internal/templates/themes/blank/vanillacss/svelte.config.js",
"vite_config": "internal/templates/themes/blank/vanillacss/vite.config.js.gotxt",
"vite_config": "internal/templates/themes/blank/vanillacss/vite.config.ts.gotxt",
"app_html": "internal/templates/themes/blank/vanillacss/app.html",
"layout": "internal/templates/themes/blank/vanillacss/layout.svelte.gotxt",
"layout_ts": "internal/templates/themes/layout.ts.gotxt",
"app_css": "internal/templates/themes/blank/vanillacss/app.css",
"hero": "internal/templates/themes/blank/vanillacss/Hero.svelte",
"error": "internal/templates/themes/error.unstyled.svelte",
Expand Down
2 changes: 1 addition & 1 deletion resources/defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,5 +108,5 @@ func TestVanillaThemeFS(t *testing.T) {
is := is.New(t)
is.Equal("internal/templates/themes/sveltin/vanillacss/package.json.gotxt", VanillaSveltinThemeFS["package_json"])
is.Equal("internal/templates/themes/sveltin/vanillacss/app.css", VanillaSveltinThemeFS["app_css"])
is.Equal("internal/templates/themes/blank/vanillacss/vite.config.js.gotxt", VanillaBlankThemeFS["vite_config"])
is.Equal("internal/templates/themes/blank/vanillacss/vite.config.ts.gotxt", VanillaBlankThemeFS["vite_config"])
}
1 change: 1 addition & 0 deletions resources/internal/templates/resource/api/apiIndex.gotxt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { list } from '$lib/{{ .Name }}/load{{ .Name | ToVariableName | Capitalize }}';
import { error } from '@sveltejs/kit';
export const prerender = true;

/** @type {import('@sveltejs/kit').RequestHandler} */
export async function GET() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { all } from '$lib/{{ .Resource }}/load{{ .Name | ToVariableName | Capitalize }}';
import { error } from '@sveltejs/kit';
export const prerender = true;

/** @type {import('@sveltejs/kit').RequestHandler} */
export async function GET() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { groupedBy } from '$lib/{{ .Resource }}/load{{ .Name | ToVariableName | Capitalize }}';
import { error } from '@sveltejs/kit';
export const prerender = true;

/** @type {import('@sveltejs/kit').RequestHandler} */
export async function GET({ url }) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { groupedBy } from '$lib/{{ .Resource }}/load{{ .Name | ToVariableName | Capitalize }}';
import { error } from '@sveltejs/kit';
export const prerender = true;

/** @type {import('@sveltejs/kit').RequestHandler} */
export async function GET({ url }) {
Expand Down
1 change: 1 addition & 0 deletions resources/internal/templates/resource/api/apiSlug.gotxt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { getSingle } from '$lib/{{ .Name }}/load{{ .Name | ToVariableName | Capitalize }}';
import { error } from '@sveltejs/kit';
export const prerender = true;

/** @type {import('@sveltejs/kit').RequestHandler} */
export async function GET({ url }) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import type { Sveltin } from 'src/sveltin';
{{ $mdName := .Name | ToVariableName | Capitalize}}
import { all } from '$lib/{{ .Resource }}/load{{ $mdName }}';

/** @type {import('./$types').PageServerLoad} */
export async function load() {
const data = await all();
const metadata = data as unknown as Array<Sveltin.ContentMetadata>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import { groupedBy } from '$lib/{{ .Resource }}/load{{ $mdName }}';
import { error } from '@sveltejs/kit';

/** @type {import('./$types').PageLoad} */
export async function load({ params }) {
const metadata = await groupedBy(params.slug);
if (metadata) {
Expand Down
1 change: 0 additions & 1 deletion resources/internal/templates/resource/page.server.ts.gotxt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { Sveltin } from 'src/sveltin';
import { list } from '$lib/{{ .Name }}/load{{ .Name | ToVariableName | Capitalize }}';

/** @type {import('./$types').PageServerLoad} */
export async function load() {
const resourceName = '{{ .Name }}';
const data = await list();
Expand Down
1 change: 0 additions & 1 deletion resources/internal/templates/resource/slug.ts.gotxt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { getSingle } from '$lib/{{ .Name }}/load{{ .Name | ToVariableName | Capitalize }}';
import { error } from '@sveltejs/kit';

/** @type {import('./$types').PageLoad} */
export async function load({ params }) {
const { slug } = params;
const { status, current, previous, next } = await getSingle(slug);
Expand Down
Loading