server-private
TypeScript icon, indicating that this package has built-in type declarations

1.6.3 • Public • Published

Server-private

  • Fast mode development and build for production!
  • Make in typescript! :D
  • Use ejs templates for pages and components!

Table of Contents

How get?

Run:

  npm install server-private

Server-private cli

Use server-private cli.

$ server-private help
Usage: server-private [options] [command]

Options:
  -v, --version    output the version number
  -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            Starting build of your project for production
  start [options]  Start your application for production
  help [command]   display help for command

Concepts basics

There is a concepts basics for use server-private

Structure your directorys

Server private use a structure for your pages, styles, javascripts

Use a structure similar to this

📦src
 ┣ 📂components
 ┃ ┗ 📜header.ejs
 ┣ 📂css
 ┃ ┣ 📜styles.css
 ┣ 📂[Directory of your templates]
 ┃ ┗ 📜post.ejs
 ┣ 📂js
 ┃ ┣ 📜index.js
 ┣ 📂pages
 ┃ ┣ 📂dashboard
 ┃ ┃ ┗ 📜settings.ejs
 ┃ ┣ 📜index.ejs

Routes

Server-private 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.

Index

The router will automatically routes files named index to the root of the directory pages.

  • pages/index.ejs/
  • pages/blog/index.ejs/blog

Nested routes

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

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:

With commonJS

  exports.[page] = {
    [variable: string]: // Function, string, object, any
  }

With module/exports Ecmascript 6+

  export const [page] = {
    [variable: string]: // Function, string, object, any
  }

Examples

// This variable is available on the index page
export const index = {
  mode: "development",
};
// With commonJs
exports.index = {
  mode: "development",
};

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

// With plugins and module/exports Ecmascript 6+
import Plugins from "server-private/@plugins";

export default function createPage({ action, listenTemplate }) {
  // This is plugins of server-private
  const { json } = new Plugins().setFilesJson("./src/posts");
  // This for the server watch this directory
  listenTemplate("./src/templates");
  // This is implemantion
  json.forEach(({ data, name }) => {
    action({
      data,
      path: name,
      template: "./src/templates/post.ejs",
    });
  });
}
// With Custom data and commonJS
// If you want use plugins
// const { default: Plugins } = require('server-private/@plugins');

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",
    });
  });
};

API

Plugins

This is a class where you can initialize the plugins, like json

Parameters

  • param Object is a configuration object (optional, default {promise:false,test:false})
    • param.promise boolean this attribute converte all methods to promise (optional, default false)

setFilesJson

This method is for set path of your files json

Parameters

  • params (string | {dist: string, id: string}) This is the relative path where are your files json (optional, default ./src/jsons)
  • id string? This id save a instance json

Examples

// returns a array of your data
// In create.pages.js
const functionCreatePage = () => {
const jsons = new Plugins().setFilesJson('./src/jsons', 'id').getJson();
// or
const jsons = new Plugins().setFilesJson({
 dist: './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 | {dist: string}) This is the relative path where are your files json (optional, default ./src/jsons)

Examples

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

Returns Promise<{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

Examples

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

getJsonPromise

This method return all data of your json files

Examples

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

Returns Promise<{id: string, dir: string, data: Array<{name: String, pathRelative: String, data: Object}>}> is a promise that return all your data of json files

isPromise

This method return if your methods are promises

Examples

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

Returns boolean A boolean if your methods Plugins are promises

Package Sidebar

Install

npm i server-private

Weekly Downloads

13

Version

1.6.3

License

IMT

Unpacked Size

218 kB

Total Files

134

Last publish

Collaborators

  • alejandro_1428