# @sv-cd/core

> This a sv's core. Sv is a group of plugins and utilities that you help when work in a proyect of frontend. Loads your data before the build and compiles your code(javascript, css, .ejs(template)). Using Static site generation concepts, and others strategi

Latest version **0.1.3** (published 2023-07-13) · Mozilla Public License 2.0 license · 0 weekly downloads

## Install

```sh
npm install @sv-cd/core
pnpm add @sv-cd/core
yarn add @sv-cd/core
bun add @sv-cd/core
```

Provides the command `sv`.

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.3 |
| Published | 2023-07-13 |
| First published | 2022-02-16 |
| Weekly downloads | 0 |
| License | Mozilla Public License 2.0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 24 |
| Unpacked size | 932.9 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | yes |
| GitHub stars | 2 |
| Author | alejooroncoy |
| Maintainers | alejandro_1428, crokepy, yugi |
| Keywords | server, ssg, static site generator, server-private, sv |

## Links

- npm: https://www.npmjs.com/package/@sv-cd/core
- Repository: https://github.com/code-doctors-team/serVer
- Homepage: https://github.com/code-doctors-team/serVer#readme
- Issues: https://github.com/code-doctors-team/serVer/issues
- npm.io page: https://npm.io/package/@sv-cd/core

## Dependencies (24)

- [ejs](https://npm.io/package/ejs.md) ^3.1.6
- [open](https://npm.io/package/open.md) ^8.4.0
- [boxen](https://npm.io/package/boxen.md) ^5.1.2
- [chalk](https://npm.io/package/chalk.md) 4.1.2
- [esbuild](https://npm.io/package/esbuild.md) ^0.14.9
- [resolve](https://npm.io/package/resolve.md) ^1.21.0
- [gifsicle](https://npm.io/package/gifsicle.md) ^5.2.1
- [commander](https://npm.io/package/commander.md) ^8.3.0
- [fast-glob](https://npm.io/package/fast-glob.md) ^3.2.7
- [@types/ejs](https://npm.io/package/@types/ejs.md) ^3.1.0
- [@parcel/css](https://npm.io/package/@parcel/css.md) ^1.3.2
- [@types/node](https://npm.io/package/@types/node.md) ^15.14.9
- [pngquant-bin](https://npm.io/package/pngquant-bin.md) ^6.0.1
- [serve-static](https://npm.io/package/serve-static.md) ^1.14.2
- [@sv-cd/server](https://npm.io/package/@sv-cd/server.md) file:packages/server
- [patch-package](https://npm.io/package/patch-package.md) ^6.4.7
- [@types/express](https://npm.io/package/@types/express.md) ^4.17.13
- [@minify-html/js](https://npm.io/package/@minify-html/js.md) ^0.8.0
- [compress-images](https://npm.io/package/compress-images.md) ^2.0.4
- [@sv-cd/cli-loader](https://npm.io/package/@sv-cd/cli-loader.md) file:packages/cli-loader
- [@sv-cd/css-injector](https://npm.io/package/@sv-cd/css-injector.md) file:packages/css-injector
- [require-from-string](https://npm.io/package/require-from-string.md) ^2.0.2
- [@sv-cd/html-injector](https://npm.io/package/@sv-cd/html-injector.md) file:packages/html-injector
- [@sv-cd/server-reload](https://npm.io/package/@sv-cd/server-reload.md) file:packages/server-reload

## Alternatives

- [csv-to-markdown-table](https://npm.io/package/csv-to-markdown-table.md) — 47.0K weekly downloads
- [@sapphire/ratelimits](https://npm.io/package/@sapphire/ratelimits.md) — 4.4K weekly downloads
- [js-csvparser](https://npm.io/package/js-csvparser.md) — 2.0K weekly downloads
- [@adadapted/js-sdk](https://npm.io/package/@adadapted/js-sdk.md) — 251 weekly downloads
- [@grapecity/spread-sheets-sparklines](https://npm.io/package/@grapecity/spread-sheets-sparklines.md) — 103 weekly downloads

## Recent versions

- 0.1.3 (latest) — 2023-07-13
- 0.1.2 — 2022-02-22
- 0.1.1 — 2022-02-18
- 0.1.0 — 2022-02-17
- 0.0.9 — 2022-02-17
- 0.0.8 — 2022-02-17
- 0.0.6 — 2022-02-17
- 0.0.5 — 2022-02-17
- 0.0.4 — 2022-02-17
- 0.0.3 — 2022-02-16
- 0.0.2 — 2022-02-16
- 0.0.1 — 2022-02-16

## README

<h1 align='center'> SerVer <img align='center' src='https://i.postimg.cc/25XSjsLP/logo-sv.png' width="60" /></h1>

- Fast mode development and build for production!
- Make in typescript! :D
- Use ejs(future more templates) templates for pages and components!

- `Description:` serVer is a group of plugins and utilities that you help when work in a proyect of frontend. Loads your data before the build and compiles your code(javascript, css, .ejs(template)). Using Static site generation concepts, and others strategies.

### Table of Contents

- [How get?][1]
- [Sv-cli][2]
  - [How use sv-cli?][3]
  - [How use sv-cli in mode dev?][4]
  - [How use plugins in sv-cli?][5]
- [Concepts basics][6]
  - [Structure your directorys][7]
  - [Routes][8]
- [Config Files][9]
  - [File config.data.js][10]
- [How to build my project for production?][11]
- [How can I test my project in production?][12]

## How get?

Run:

```sh
  npm install @sv-cd/core -D
```

## Sv-cli

Use serVer cli.

### How use sv-cli?

```sh
$ sv help
Usage: sv [options] [command]

Options:
  -v, --version    sv version
  -h, --help       display help for command

Commands:
  dev [options]    Starting your proyect in mode development
  build [options]  Starting build of your project for production
  start [options]  Start your application for production
  help [command]   display help for command
```

### How use sv-cli in mode dev?

In dev(development) mode, it comes by default, these are the commands in this mode.

```sh
  $ sv dev -h
  Usage: sv dev [options]

  Starting your proyect in mode development

  Options:
    --root <root>                         Select root of pwd (default: ".")
    --open [open_browser]                 Open browser(Select Edge, Firefox, Opera(If you use opera GX  it will automatically open it) or Chrome) (default: false)
    -p,--port <port_number>               This is the port where you will work in development mode (default: "5000")
    --pages <pages_root>                  Select root of pages (default: "./pages")
    --styles <styles_root>                Select root of styles(css) (default: "./src/styles")
    --assets <assets_root>                Select root of assets(images and manifest.json) (default: "./src/assets")
    --scripts <scripts_root>              Select root of javascript(js) (default: "./src/scripts")
    --only-reload [specific_only_reload]  Specific only-reload, in css, html(Specific true, all will use strategy only-reload)) (default: false)
    -h, --help                            display help for command
```

## Concepts basics

There is a concepts basics for use serVer

### Structure your directorys

serVer use a structure for your pages, styles, javascripts and assets.

Use a structure similar to this.

      📦src
      ┣ 📂assets
      ┃ ┣ manifest.json
      ┃ ┗ 📜logo.jpg
      ┣ 📂components
      ┃ ┗ 📜header.ejs
      ┣ 📂styles
      ┃ ┣ 📜styles.css
      ┣ 📂scripts
      ┃ ┣ 📜index.js

      📦pages
      ┃ ┣ 📂dashboard
      ┃ ┃ ┗ 📜settings.ejs
      ┃ ┣ 📜index.ejs

### Routes

SerVer has a **file-system** based router built on the concept of pages.

When added a file `.ejs` in the carpet pages, automatically available as a route.

<h3>Index</h3>

<p>

The router will automatically routes files named index to the root of the directory `pages`.

- `pages/index.ejs` → `/`
- `pages/blog/index.ejs` → `/blog`

</p>

<h3>Nested routes</h3>

<p>

These routes are generated when you create a subfolder within a folder, this in the directory `pages`.

- `pages/user/profile.ejs`--> `/user/profile`
- `pages/posts/html.ejs`--> `/posts/html`

</p>

## Config Files

### File config.data.js

This is a file where you can add variables to your ejs files. With dynamic routes, you can create dynamic pages, start with `:id` and file is `[id]`.

Create a file named `config.data.js`

Accept **module/exports Ecmascript 6+** and **CommonJS**

### Squemas:

<h4>With commonJS</h4>

```typescript
  exports.[page] = {
    [':[dinamycPage]']: {
      [variable: (string | number)]: // Function, string, object, any
    },
    ['/[subPage]']: {
      ['/[subPage]']: {
        // ...
        [variable: (string | number)]: // Function, string, object, any
      }
      [variable: (string | number)]: // Function, string, object, any
    }
    [variable: (string | number)]: // Function, string, object, any
  }
  exports.["notFound"] = {
    [variable: (string | number)]: // Function, string, object, any
  } -> `Data for 404 page`
```

<h4>With module/exports Ecmascript 6+</h4>

```typescript
  export const [page] = {
    [':[dinamycPage]']: {
      [variable: (string | number)]: // Function, string, object, any
    },
    ['/[subPage]']: {
      ['/[subPage]']: {
        // ...
        [variable: (string | number)]: // Function, string, object, any
      }
      [variable: (string | number)]: // Function, string, object, any
    }
    [variable: (string | number)]: // Function, string, object, any
  }
  export const notFound = {
    [variable: (string | number)]: // Function, string, object, any
  } -> `Data for 404 page`
```

### Examples

```javascript
// This variable is available on the index page
export const index = {
  title: "First Proyect with serVer",
};
export const posts = {
  [":post"]: () => {
    const posts = getPosts();
    return posts.map((post) => ({
      name: post.name,
      data: post.data,
    }));
  },
};

// With commonJs
exports.index = {
  title: "First Proyect with serVer",
};
exports.posts = {
  [":post"]: () => {
    const posts = getPosts();
    return posts.map((post) => ({
      name: post.name,
      data: post.data,
    }));
  },
};
```

In files
```
  📦src
    ┣ 📂pages
    ┃ ┣ 📂dashboard
    ┃ ┃ ┗ 📜settings.ejs
    ┃ ┣ 📂posts
    ┃ ┃ ┗ 📜[post].ejs
    ┃ ┣ 📜index.ejs
```

## How to build my project for production?

Is simple, only run this command once.

```sh
  sv build
```

For look options:

```sh
$ sv build -h
  Usage: sv build [options]

  Starting build of your project for production

  Options:
    --root <root>             Select root of pwd (default: ".")
    --dist <dist_proyect>     Is a place where will bundle of your project (default: "public")
    --pages <pages_root>      Select root of pages (default: "./pages")
    --styles <styles_root>    Select root of styles(css) (default: "./src/styles")
    --assets <assets_root>    Select root of assets(images and manifest.json) (default: "./src/assets")
    --scripts <scripts_root>  Select root of javascript(js) (default: "./src/scripts")
    --clear                   Delete the bundle folder before the initialization of the "build"   processes (default: false)
    --info                    Show more information about build process (default: false)
    -h, --help                display help for command
```

After of run this command, creates a carpet of your application's bundle.

## How can I test my project in production?

We can test the project in production, with this simple command.

```sh
  sv start
```

You can change the port with flag `--port` and change your directory build with flag `--dist`

[1]: #how-get
[2]: #sv-cli
[3]: #how-use-sv-cli
[4]: #how-use-sv-cli-in-mode-dev
[5]: #how-use-plugins-in-sv-cli
[6]: #concepts-basics
[7]: #structure-your-directorys
[8]: #routes
[9]: #config-files
[10]: #file-configdatajs
[11]: #how-to-build-my-project-for-production
[12]: #how-can-i-test-my-project-in-production

---
_Source: https://npm.io/package/@sv-cd/core · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
