Skip to content

Commit

Permalink
refactor: improved typing, readme fixes (#26)
Browse files Browse the repository at this point in the history
* refactor: improved typing, readme fixes

* 1.10.1
  • Loading branch information
sapachev authored Jul 23, 2024
1 parent 54dc06d commit 889b995
Show file tree
Hide file tree
Showing 20 changed files with 41 additions and 41 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,15 @@ In addition to steps from Basic Usage, you can improve results by changing some

The main configuration is stored in the `config.json` file in a root directory and you can change this config file according to your needs:

```
```json
{
"tailwind": true,
"theme": "minimalistic",
"locale": "en"
}
```

There possible to run hot-reload server to develop your own theme with custom markup, styles, and scripts. To start dev-server just run command `npm run dev`. This command will start server on 8080 port ([http://localhost:8080](http://localhost:8080). By default, this address will be opened with a first status code, defined in `src` directory, which corresponds to configured `locale` value. You can choose any other code to continue specific page development. Don't be surprised with injected parts of code in a rendered page, because this is a part of hot-reload mode. Any change of the main configuration will require dev-server restart. The only configured theme and locale directories are watching during development.
There possible to run hot-reload server to develop your own theme with custom markup, styles, and scripts. To start dev-server just run command `npm run dev`. This command will start server on 8080 port ([http://localhost:8080](http://localhost:8080)). By default, this address will be opened with a first status code, defined in `src` directory, which corresponds to configured `locale` value. You can choose any other code to continue specific page development. Don't be surprised with injected parts of code in a rendered page, because this is a part of hot-reload mode. Any change of the main configuration will require dev-server restart. The only configured theme and locale directories are watching during development.


### Templates
Expand Down Expand Up @@ -132,7 +132,7 @@ The config snippet itself I would recommend to place in the `/etc/nginx/snippets

Here is an example of web server configuration with included the error pages snippet:

```
```nginx
server {
server_name example.com;
access_log /var/log/nginx/example.access.log;
Expand Down
2 changes: 1 addition & 1 deletion dev/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { MessagesEnum } from "../messages";
import { pr } from "../path-registry";

import { DEFAULTS } from "../lib/constants";
import { Config, TemplateVariables } from "../lib/interfaces";
import { Config, TemplateVariables } from "../lib/models";
import { DI_TOKENS } from "../lib/tokens";

const STATUS_PATH_REGEX = /^\/([0-9]{3})$/i;
Expand Down
2 changes: 1 addition & 1 deletion index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Main } from "./lib/classes/Main";
import { initContainer } from "./container";
import { pr } from "./path-registry";

import { Config } from "./lib/interfaces";
import { Config } from "./lib/models";
import { Messages } from "./lib/classes/Messages";
import { MessagesEnum } from "./messages";

Expand Down
2 changes: 1 addition & 1 deletion lib/classes/ChildProcessWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export interface IChildProcessWrapper {

@injectable()
export class ChildProcessWrapper implements IChildProcessWrapper {
exec(cmd: string) {
exec(cmd: string): Promise<{ stdout: string; stderr: string }> {
return promisify(exec)(cmd);
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/classes/Compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { ILogger } from "./Logger";
import { Messages } from "./Messages";
import { Renderer } from "./Renderer";

import { Config, SnippetVariables, TemplateVariables } from "../interfaces";
import { Config, SnippetVariables, TemplateVariables } from "../models";
import { DI_TOKENS } from "../tokens";
import { MessagesEnum } from "../../messages";
import { PathRegistry } from "./PathRegistry";
Expand Down
2 changes: 1 addition & 1 deletion lib/classes/FileSystemHelper.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { injectable, inject } from "inversify";

import { Config } from "../interfaces";
import { Config } from "../models";
import { Messages } from "./Messages";
import { Styler } from "./Styler";
import { ILogger } from "./Logger";
Expand Down
16 changes: 8 additions & 8 deletions lib/classes/FileSystemWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,36 +14,36 @@ export interface IFileSystemWrapper {
readDir(path: string): Promise<string[]>;
readFile(path: string): Promise<Buffer>;
rm(path: string, opts?: fs.RmOptions): Promise<void>;
writeFile(path: string, data: string, opts?: WriteOptions);
writeFile(path: string, data: string, opts?: WriteOptions): Promise<void>;
}

@injectable()
export class NodeFS implements IFileSystemWrapper {
access(path: string) {
access(path: string): Promise<void> {
return fsp.access(path);
}

cp(src: string, dest: string, opts?: fs.CopyOptions) {
cp(src: string, dest: string, opts?: fs.CopyOptions): Promise<void> {
return fsp.cp(src, dest, opts);
}

mkdir(path: string, opts?: fs.MakeDirectoryOptions) {
mkdir(path: string, opts?: fs.MakeDirectoryOptions): Promise<string> {
return fsp.mkdir(path, opts);
}

readDir(path: string) {
readDir(path: string): Promise<string[]> {
return fsp.readdir(path);
}

readFile(path: string) {
readFile(path: string): Promise<Buffer> {
return fsp.readFile(path);
}

rm(path: string, opts?: fs.RmOptions) {
rm(path: string, opts?: fs.RmOptions): Promise<void> {
return fsp.rm(path, opts);
}

writeFile(path: string, data: string, opts?: WriteOptions) {
writeFile(path: string, data: string, opts?: WriteOptions): Promise<void> {
return fsp.writeFile(path, data, opts);
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/classes/Logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export interface ILogger {

@injectable()
export class Logger implements ILogger {
print(message: string) {
print(message: string): void {
console.log(message);
}
}
Expand Down
4 changes: 2 additions & 2 deletions lib/classes/Main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { IStyler } from "./Styler";
import { Messages } from "./Messages";
import { PathRegistry } from "./PathRegistry";

import { Config } from "../interfaces";
import { Config } from "../models";
import { DI_TOKENS } from "../tokens";
import { MessagesEnum } from "../../messages";

Expand All @@ -22,7 +22,7 @@ export class Main {
@inject(DI_TOKENS.PATH) private pr: PathRegistry
) {}

async start() {
async start(): Promise<void> {
const startTime = Date.now();

this.logger.print(Messages.info(MessagesEnum.START));
Expand Down
2 changes: 1 addition & 1 deletion lib/classes/Messages.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { render } from "mustache";

import { AnyVariables } from "../interfaces";
import { AnyVariables } from "../models";

export class Messages {
static error(msg: string, vars: AnyVariables = {}): string {
Expand Down
2 changes: 1 addition & 1 deletion lib/classes/PathRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class PathRegistry {
this.init(paths);
}

private init(paths: AnyStringObject) {
private init(paths: AnyStringObject): void {
this.registry = new Map(
Object.entries(paths).map(([key, value]) => {
return [key, this.resolveToCwd(value)];
Expand Down
6 changes: 3 additions & 3 deletions lib/classes/Renderer.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { render } from "mustache";
import Typograf from "typograf";

import { SnippetVariables, TemplateVariables } from "../interfaces";
import { SnippetVariables, TemplateVariables } from "../models";
import { TYPOGRAF_LOCALES } from "../constants";

export class Renderer {
static renderTemplate(template: string, vars: TemplateVariables) {
static renderTemplate(template: string, vars: TemplateVariables): string {
if (TYPOGRAF_LOCALES.has(vars.locale)) {
const tp = new Typograf({ locale: [TYPOGRAF_LOCALES.get(vars.locale)], htmlEntity: { type: "name" } });
for (const prop in vars) {
Expand All @@ -15,7 +15,7 @@ export class Renderer {
return render(template, vars, null, { escape: (str) => str });
}

static renderSnippet(template: string, vars: SnippetVariables) {
static renderSnippet(template: string, vars: SnippetVariables): string {
return render(template, vars);
}
}
4 changes: 2 additions & 2 deletions lib/classes/Styler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class Styler implements IStyler {
@inject(DI_TOKENS.LOGGER) private logger: ILogger
) {}

async buildTailwind(input: string, output: string) {
async buildTailwind(input: string, output: string): Promise<void> {
const cmd = Styler.getTailwindCommand(input, output);

this.logger.print(Messages.info(MessagesEnum.TAILWIND_START));
Expand All @@ -30,7 +30,7 @@ export class Styler implements IStyler {
this.logger.print(Messages.info(MessagesEnum.TAILWIND_DONE));
}

static getTailwindCommand(input: string, output: string) {
static getTailwindCommand(input: string, output: string): string {
return `INPUT="${input}" OUTPUT="${output}" npm run build:tailwind`;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Defaults } from "./interfaces.js";
import { Defaults } from "./models.js";
import { DefaultPaths } from "./_constants.js";

export const DEFAULTS: Defaults = {
Expand Down
16 changes: 8 additions & 8 deletions lib/interfaces.ts → lib/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export type Config = {
theme: string;
};

export interface Defaults {
export type Defaults = {
ASSETS: string;
CONFIG: string;
DIST: string;
Expand All @@ -14,17 +14,17 @@ export interface Defaults {
TAILWIND_IN: string;
TAILWIND_OUT: string;
THEMES: string;
}
};

export interface AnyVariables {
export type AnyVariables = {
[key: string]: string | number;
}
};

export interface TemplateVariables extends AnyVariables {
export type TemplateVariables = {
locale: string;
version: string;
}
} & AnyVariables;

export interface SnippetVariables {
export type SnippetVariables = {
codes: number[];
}
};
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "error-pages",
"version": "1.10.0",
"version": "1.10.1",
"description": "Lightweight tool to create static HTTP Error Pages in minimalistic adaptive and accessible design with customization and localization support",
"main": "index.ts",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion test/Compiler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { IFileSystemHelper, MockFileSystemHelper } from "../lib/classes/FileSyst
import { ILogger, MockLogger } from "../lib/classes/Logger";
import { Messages } from "../lib/classes/Messages";

import { Config } from "../lib/interfaces";
import { Config } from "../lib/models";
import { DI_TOKENS } from "../lib/tokens";
import { MessagesEnum } from "../messages";
import { PathRegistry } from "../lib/classes/PathRegistry";
Expand Down
2 changes: 1 addition & 1 deletion test/FileSystemHelper.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { IFileSystemWrapper, MockFS } from "../lib/classes/FileSystemWrapper";
import { ILogger, MockLogger } from "../lib/classes/Logger";
import { Messages } from "../lib/classes/Messages";

import { Config } from "../lib/interfaces";
import { Config } from "../lib/models";
import { DI_TOKENS } from "../lib/tokens";
import { MessagesEnum } from "../messages";
import { PathRegistry } from "../lib/classes/PathRegistry";
Expand Down
2 changes: 1 addition & 1 deletion test/Renderer.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { assert } from "chai";

import { Renderer } from "../lib/classes/Renderer";
import { SnippetVariables, TemplateVariables } from "../lib/interfaces";
import { SnippetVariables, TemplateVariables } from "../lib/models";

describe("class Renderer", () => {
describe("renderTemplate()", () => {
Expand Down

0 comments on commit 889b995

Please sign in to comment.