# @sv-cd/sv

> This a proyect of CD, we hope that enjoy of server.

Latest version **0.0.9** (published 2021-04-03) · IMT license · 0 weekly downloads

## Install

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

Provides the command `sv`.

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.9 |
| Published | 2021-04-03 |
| First published | 2021-02-05 |
| Weekly downloads | 0 |
| License | IMT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 47 |
| Unpacked size | 456.1 KB |
| Known vulnerabilities | 0 (+3 in 3 direct dependencies) |
| Install scripts | yes |
| Author | alejo |
| Maintainers | yugi, crokepy, alejandro_1428 |
| Keywords | javascript, server-private, static-site-generation |

## Links

- npm: https://www.npmjs.com/package/@sv-cd/sv
- npm.io page: https://npm.io/package/@sv-cd/sv

## Dependencies (47)

- [del](https://npm.io/package/del.md) ^6.0.0
- [ejs](https://npm.io/package/ejs.md) ^3.1.5
- [joi](https://npm.io/package/joi.md) ^17.3.0
- [ncp](https://npm.io/package/ncp.md) ^2.0.0
- [ora](https://npm.io/package/ora.md) ^5.1.0
- [glob](https://npm.io/package/glob.md) ^7.1.6
- [boxen](https://npm.io/package/boxen.md) ^5.0.0
- [chalk](https://npm.io/package/chalk.md) ^4.1.0
- [figlet](https://npm.io/package/figlet.md) ^1.5.0
- [lodash](https://npm.io/package/lodash.md) ^4.17.20
- [stylis](https://npm.io/package/stylis.md) ^4.0.8
- [consola](https://npm.io/package/consola.md) ^2.15.2
- [esbuild](https://npm.io/package/esbuild.md) ^0.9.7
- [express](https://npm.io/package/express.md) ^4.17.1
- [postcss](https://npm.io/package/postcss.md) ^8.1.8
- [resolve](https://npm.io/package/resolve.md) ^1.20.0
- [chokidar](https://npm.io/package/chokidar.md) ^3.5.0
- [hidefile](https://npm.io/package/hidefile.md) ^3.0.0
- [imagemin](https://npm.io/package/imagemin.md) ^7.0.1
- [jsonfile](https://npm.io/package/jsonfile.md) ^6.1.0
- [readline](https://npm.io/package/readline.md) ^1.3.0
- [commander](https://npm.io/package/commander.md) ^6.2.0
- [@types/ncp](https://npm.io/package/@types/ncp.md) ^2.0.4
- [node-fetch](https://npm.io/package/node-fetch.md) ^2.6.1
- [@types/node](https://npm.io/package/@types/node.md) ^14.14.31
- [discord-rpc](https://npm.io/package/discord-rpc.md) ^3.1.4
- [exec-buffer](https://npm.io/package/exec-buffer.md) ^3.2.0
- [markdown-it](https://npm.io/package/markdown-it.md) ^12.0.4
- [browser-sync](https://npm.io/package/browser-sync.md) ^2.26.13
- [css-validator](https://npm.io/package/css-validator.md) ^0.10.0
- [html-minifier](https://npm.io/package/html-minifier.md) ^4.0.0
- [patch-package](https://npm.io/package/patch-package.md) ^6.2.2
- [@babel/runtime](https://npm.io/package/@babel/runtime.md) ^7.13.7
- [@types/express](https://npm.io/package/@types/express.md) ^4.17.9
- [update-notifier](https://npm.io/package/update-notifier.md) ^5.1.0
- [bs-html-injector](https://npm.io/package/bs-html-injector.md) ^3.0.3
- [node-html-parser](https://npm.io/package/node-html-parser.md) ^3.1.1
- [imagemin-jpegtran](https://npm.io/package/imagemin-jpegtran.md) ^7.0.0
- [imagemin-pngquant](https://npm.io/package/imagemin-pngquant.md) ^9.0.1
- [@types/browser-sync](https://npm.io/package/@types/browser-sync.md) ^2.26.1
- [@types/glob-watcher](https://npm.io/package/@types/glob-watcher.md) ^5.0.0
- [express-ejs-layouts](https://npm.io/package/express-ejs-layouts.md) ^2.5.0
- [require-from-string](https://npm.io/package/require-from-string.md) ^2.0.2
- [@types/html-minifier](https://npm.io/package/@types/html-minifier.md) ^4.0.0
- [connect-browser-sync](https://npm.io/package/connect-browser-sync.md) ^2.1.0
- [postcss-font-magician](https://npm.io/package/postcss-font-magician.md) ^3.0.0
- [regex-css-media-query](https://npm.io/package/regex-css-media-query.md) ^1.0.0

## Recent versions

- 0.0.9 (latest) — 2021-04-03
- 0.0.8 — 2021-04-03
- 0.0.7 — 2021-03-25
- 0.0.6 — 2021-03-01
- 0.0.5 — 2021-02-18
- 0.0.4 — 2021-02-14
- 0.0.3 — 2021-02-06
- 0.0.1 — 2021-02-05
- 0.0.2 — 2021-02-05

## 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 templates(for default...) for pages and components!


### 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]
    -   [File create.pages.js][11]
    -   [File sv.config.js][12]
-   [How to build my project for production?][13]
-   [How can I test my project in production?][14]
-   [API][15]
    -   [Helpers][16]
        -   [Parameters][17]
    -   [setFilesJson][18]
        -   [Parameters][19]
        -   [Examples][20]
    -   [setFilesJsonPromise][21]
        -   [Parameters][22]
        -   [Examples][23]
    -   [getJson][24]
        -   [Parameters][25]
        -   [Examples][26]
    -   [getJsonPromise][27]
        -   [Parameters][28]
        -   [Examples][29]
    -   [isPromise][30]
        -   [Examples][31]
    -   [setFilesMarkdown][32]
        -   [Parameters][33]
        -   [Examples][34]
    -   [setFilesMarkdownPromise][35]
        -   [Parameters][36]
        -   [Examples][37]
    -   [getMarkdown][38]
        -   [Parameters][39]
        -   [Examples][40]
    -   [getMarkdownPromise][41]
        -   [Parameters][42]
        -   [Examples][43]
-   [Experimental][44]

## How get?

Run:

```sh
  npm install @sv-cd/sv -D
```


## Sv-cli

Use serVer cli.


### ¿How use sv-cli?

```sh
$ sv help
Usage: sv [options] [command]

Options:
  -v, --version    sv version
  -d, --discord    This command is for discord users, active 'Rich presence' (default: false)
  -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:
    -off, --offline                Active offline version (default: false)
    --open                         Open default browser (default: false)
    -p,--port <port_number>        This is the port where you will work in development mode (default:     "5000")
    --root <root_proyect>          Is a root of your proyect (default: "src")
    --plugins <plugins>            Plugins of server
    --d-styles <d-styles>          Style's directory (default: "styles")
    --d-scripts <d-js>             Javascript's directory (default: "js")
    --d-components <d-components>  Components's directory (default: "components")
    --d-assets <d-assets>          Assets's directory (default: "assets")
    -h, --help                     display help for command
```


### ¿How use plugins in sv-cli?

Use `plugins` create for server.

```sh
  $ sv --plugins @sv-cd/plugin-init:withoutComments=false,exclude=css-js --otherPlugin:hisOptions--...
```

To make it easier to understand, we recommend using `sv.config.js`, go to [svConfig][12].


## 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.

You can save time by installing the [@sv-cd/plugin-init][45] plugin which creates all the directories according to your configuration.

      📦src
      ┣ 📂assets
      ┃ ┣ 📜codedoctors.png
      ┃ ┗ 📜html.png
      ┣ 📂components
      ┃ ┗ 📜header.ejs
      ┣ 📂styles
      ┃ ┣ 📜styles.css
      ┣ 📂[Directory of your templates]
      ┃ ┗ 📜post.ejs
      ┣ 📂js
      ┃ ┣ 📜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.

Create a file named `config.data.js`

Accept **module/exports Ecmascript 6+** and **CommonJS**

### Squemas:

<h4>With commonJS</h4>

```typescript
  exports.[page] = {
    [variable: (string | number)]: // Function, string, object, any
  }
```

<h4>With module/exports Ecmascript 6+</h4>

```typescript
  export const [page] = {
    [variable: (string | number)]: // Function, string, object, any
  }
```

### Examples

```javascript
// This variable is available on the index page
export const index = {
  title: "First Proyect with serVer",
};
// With commonJs
exports.index = {
  title: "First Proyect with serVer",
};
```


### File create.pages.js

This is a file where you can create pages programmatically

Create a file named `create.pages.js`

Accept **module/exports Ecmascript 6+** and **CommonJS**

### Examples

```javascript
// With helpers and module/exports Ecmascript 6+
import { Helpers } from "@sv-cd/sv";

export default function createPage({ action, listenTemplate }) {
  // This is helpers of sv
  const { getJson } = new Helpers().setFilesJson("./src/posts", "id");
  // This for the server watch this directory
  listenTemplate("./src/templates");
  // This is implemantion
  getJson().forEach(({ data, name }) => {
    action({
      data,
      path: name,
      template: "./src/templates/post.ejs",
    });
  });
}
```

```javascript
// With Custom data and commonJS
// If you want use helpers
// const { Helpers } = require('@sv-cd/sv');

modules.exports = function createPage({ action, listenTemplate }) {
  const pages = [
    {
      name: "First-page",
      data: {
        mode: "development",
        title: "My first page programmatically",
      },
    },
  ];
  // This for the server watch this directory
  listenTemplate("./src/templates");
  // This is implemantion
  pages.forEach(({ data, name }) => {
    action({
      data,
      path: name,
      template: "./src/templates/post.ejs",
    });
  });
};
```


### File sv.config.js

Used when your options are too many.

For use, you need create a file named `sv.config.js`

## Examples:

```js
// sv.config.js
module.exports = {
  root: "./src",
  devOptions: {
    globalVars: {
      mode: "development",
    },
    port: 5000,
    open: false,
  },
  plugins: [],
  buildOptions: {
    dist: "public",
  },
};
```

## Options

### **_Options.root_**

    @type: string
    Root is a relative path where the main folder of your project is, in case it is the root put
    "."
    @default: "src"

### **_Options.plugins_**

    @type: Array<{
      name: string,
      options: object,
    }>`
    Plugins of serVer
    @default: []

You can some plugins in [https://www.npmjs.com/org/sv-cd][46].

### **_Options.globalVars_**

    @type object
    It is an object with variables that will be available on all your pages
    @default: {}

### **_Options.dirs_**

    @type object
    It is an object with dirs(These paths must be relative to root)
    @default: {
      styles: 'styles',
      scripts: 'js',
      components: 'components',
      assets: 'assets',
    }

#### **_Options.devOptions.styles_**

    @type string
    This path is where your styles are (only `css` by default)
    @default 'styles'

#### **_Options.devOptions.scripts_**

    @type string
    This path is where your scripts are (only `js` by default)
    @default 'scripts'

#### **_Options.devOptions.components_**

    @type string
    This path is where your components ejs(default)
    @default 'components'

#### **_Options.devOptions.assets_**

    @type string
    This path is where your assets, anything files(images, json for PWA, etc)
    @default 'assets'

### **_Options.devOptions_**

    @type: object
    Is a object with your config dev of server.
    @default: {
      port: 5000,
      open: false,
    }

#### **_Options.devOptions.port_**

    @type number
    It is a port where will open server!
    @default: 5000

    #### **_Options.devOptions.open_**

    @type number
    If this option in true, will open your browser.
    @default: false

#### **_Options.devOptions.open_**

    @type number
    If this option in true, will open your browser.
    @default: false

### **_Options.buildOptions_**

    @type: object
    Is a object with your config build of server.
    @default: {
      dist: string
    }

#### **_Options.buildOptions.dist_**

    @type: string
    It is a relative path to where your production directory will be.
    @default "public"


## 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_proyect>          Is a root of your proyect (default: "src")
    --dist <dist_proyect>          Is a place where will bundle of your project (default: "public")
    --plugins <plugins>            Plugins of server
    --d-styles <d-styles>          Style's directory (default: "styles")
    --d-scripts <d-js>             Javascript's directory (default: "js")
    --d-components <d-components>  Components's directory (default: "components")
    --d-assets <d-assets>          Assets's directory (default: "assets")
    -h, --help                     display help for command
```

After of run this command, creates a carpet of your application's bundle.

For default is public but you can change in
[buildConfig][12].


## 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 the --port flag.


## API




### Helpers

This is a class where you can initialize the helpers of serVer, like json, markdown(`experimental`)

#### Parameters

-   `param` **[Object][47]** is a configuration object
    -   `param.promise` **[boolean][48]** this attribute converte all methods to promise (optional, default `false`)
    -   `param.test` **[boolean][48]** this attribute delete watch of your files (optional, default `false`)

### setFilesJson

This method is for set path of your files json

#### Parameters

-   `params` **([string][49] | {dir: [string][49], id: [string][49]})** This is the relative  path where are your files json (optional, default `./src/jsons`)
-   `id` **[string][49]?** This id save a instance json

#### Examples

```javascript
// returns a array of your data
// In create.pages.js
const functionCreatePage = () => {
const jsons = new Helpers().setFilesJson('./src/jsons', 'id').getJson();
// or
const jsons = new Helpers().setFilesJson({
 dir: './src/jsons',
 id: 'id',
}).getJson();
}
export default functionCreatePage;
```

Returns **{getJson}** where is getJson, this method is where you get your data

### setFilesJsonPromise

This method is for set path of your files json

#### Parameters

-   `params` **([string][49] | {dir: [string][49]})** This is the relative  path where are your files json (optional, default `./src/jsons`)

#### Examples

```javascript
// returns a array of your data
// In create.pages.js
const functionCreatePage = async () => {
const { getJsonPromise } = await new Helpers().setFilesJson('./src/jsons', 'id');
// or
const { getJsonPromise } = await  new Helpers().setFilesJson({
 dir: './src/jsons',
 id: 'id',
});
}
export default functionCreatePage;
```

Returns **[Promise][50]&lt;{getJsonPromise}>** is a promise that return in then the objet with the method getJsonPromise(this is for get your data in a promise)

### getJson

This method return all data of your json files

#### Parameters

-   `id` **[string][49]** is a id of your instance files json

#### Examples

```javascript
// In create.pages.js
const functionCreatePage = () => {
new Helpers().setFilesJson('./src/jsons', 'id');
// returns all data
 const dataJson = new Helpers().getJson('id');
};
export default functionCreatePage;
```

### getJsonPromise

This method return all data of your json files wrapped in a promise

#### Parameters

-   `id` **[string][49]** is a id of your instance files json

#### Examples

```javascript
// In create.pages.js
const functionCreatePage = async () => {
await new Helpers().setFilesJsonPromise('./src/jsons', 'id');
// returns all data
 const dataJson = await new Helpers().getJsonPromise('id');
};
export default functionCreatePage;
```

Returns **[Promise][50]&lt;{id: [string][49], dir: [string][49], data: [Array][51]&lt;{name: [String][49], pathRelative: [String][49], data: [Object][47]}>}>** is a promise that return all your data of json files

### isPromise

This method return if your methods are promises

#### Examples

```javascript
const { isPromise } = new Helpers();
console.log(isPromise());
// Output: false
```

Returns **[boolean][48]** A boolean if your methods Helpers are promises

### setFilesMarkdown

This method return all data of your json files

#### Parameters

-   `params` **([string][49] | {dir: [string][49], id: [string][49]})** This is the relative  path where are your files markdown (optional, default `./src/md`)
-   `id` **[string][49]?** This id save a instance markdown

#### Examples

```javascript
// returns a array of your data
// In create.pages.js
const functionCreatePage = () => {
const md = new Helpers().setFilesMarkdown('./src/md', 'id').getMarkdown();
// or
const md = new Helpers().setFilesMarkdown({
 dir: './src/md',
 id: 'id',
}).getMarkdown();
}
export default functionCreatePage;
```

Returns **{getMarkdown}** where is getMarkdown, this method is where you get your data(in parser html)

### setFilesMarkdownPromise

This method return all data of your json files

#### Parameters

-   `params` **([string][49] | {dir: [string][49], id: [string][49]})** This is the relative  path where are your files markdown (optional, default `./src/md`)
-   `id` **[string][49]?** This id save a instance markdown

#### Examples

```javascript
// returns a array of your data
// In create.pages.js
const functionCreatePage = async () => {
 const { getMarkdownPromise } = await new Helpers().setFilesMarkdownPromise('./src/md', 'id');
 // or
 const { getMarkdownPromise } = await new Helpers().setFilesMarkdownPromise({
   dir: './src/md',
   id: 'id',
 });
}
export default functionCreatePage;
```

Returns **{getMarkdownPromise}** where is getMarkdown, this method is where you get your data(in parser html)

### getMarkdown

This method return all data of your markdown files

#### Parameters

-   `id` **[string][49]** is a id of your instance files markdown

#### Examples

```javascript
// In create.pages.js
const functionCreatePage = () => {
new Helpers().setFilesMarkdown('./src/markdown', 'id');
// returns all data
 const dataMarkdown = new Helpers().getMarkdown('id');
};
export default functionCreatePage;
```

Returns **{id: [string][49], data: [Array][51]&lt;[string][49]>, dir: [string][49]}** are all your data and config of markdown files(parsed to html).

### getMarkdownPromise

This method return all data of your markdown files

#### Parameters

-   `id` **[string][49]** is a id of your instance files markdown

#### Examples

```javascript
// In create.pages.js
const functionCreatePage = async () => {
await new Helpers().setFilesMarkdown('./src/markdown', 'id');
// returns all data
 const dataMarkdown = await new Helpers().getMarkdownPromise('id');
};
export default functionCreatePage;
```

Returns **[Promise][50]&lt;{id: [string][49], data: [Array][51]&lt;[string][49]>, dir: [string][49]}>** are all your data and config of markdown files(parsed to html).

## Experimental

In your pages, in dev mode, using [Turbo drive][52] to be able to make it SPA, we recommend reading the documentation of this amazing library to be able to solve some problems with this strategy that we take. We resume, it is **experimental**.


[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]: #file-createpagesjs

[12]: #file-svconfigjs

[13]: #how-to-build-my-project-for-production

[14]: #how-can-i-test-my-project-in-production

[15]: #api

[16]: #helpers

[17]: #parameters

[18]: #setfilesjson

[19]: #parameters-1

[20]: #examples

[21]: #setfilesjsonpromise

[22]: #parameters-2

[23]: #examples-1

[24]: #getjson

[25]: #parameters-3

[26]: #examples-2

[27]: #getjsonpromise

[28]: #parameters-4

[29]: #examples-3

[30]: #ispromise

[31]: #examples-4

[32]: #setfilesmarkdown

[33]: #parameters-5

[34]: #examples-5

[35]: #setfilesmarkdownpromise

[36]: #parameters-6

[37]: #examples-6

[38]: #getmarkdown

[39]: #parameters-7

[40]: #examples-7

[41]: #getmarkdownpromise

[42]: #parameters-8

[43]: #examples-8

[44]: #experimental

[45]: https://www.npmjs.com/package/@sv-cd/plugin-init

[46]: pagePluginsSv

[47]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object

[48]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean

[49]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String

[50]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise

[51]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array

[52]: https://turbo.hotwire.dev/handbook/drive

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