@lamnhan/seminjecto

Simple dependency injection for Typescript modules.

Usage no npm install needed!

<script type="module">
  import lamnhanSeminjecto from 'https://cdn.skypack.dev/@lamnhan/seminjecto';
</script>

README

Introduction

Dependency injection is a common method for structuring modules. It is native in frontend frameworks like Angular and can be used for any JS modules in the same manner using library like InversifyJS, tsyringe, ...

But you can also manually apply DI to any module using this simple method. There is a central class (Lib for library, Cli for cli app, App for app, ...) that acts as a DI container and injector.

// the service 1
export class Service1Service {}

// the service 2 is depends on the service 1
export class Service2Service {
  constructor(private service1Service: Service1Service) {}
}

// the container for all services and also the injetor
export class Lib {
  service1Service: Service1Service;
  service2Service: Service2Service;

  constructor() {
    this.service1Service = new Service1Service();
    this.service2Service = new Service2Service(
      this.service1Service // injects the service 1
    );
  }
}

Benefits

  • One approaching for any project
  • Clean project structure
  • No need for extra IOC libraries
  • Easy to test (using @lamnhan/testea)
  • Easy to generate documentation (using @lamnhan/ayedocs)

Installation

Install as glocal CLI app.

npm install -g @lamnhan/seminjecto

Skeletons

These skeletons can be use to faster setup a project. You can either clone them manually or using the command semidi new <name>:

Convention

This standalization is applied to any project unders Seminjecto convention.

Helpers

VSCode

The file settings.json unders .vscode folder provides configuration for excluding certain content in VSCode (and other configs you may need):

See .vscode/settings.json

GIT

Files are ignored by GIT:

See .gitignore

Linter/prettier

Linter and prettier using @google/gts:

  • The .eslintrc.json: the Eslint config file
  • The .prettierrc.js: the Prettier config file
  • Lint by: npm run lint

Documentation

Automatic document generation using @lamnhan/ayedocs:

  • The file .ayedocsrc.js provides configuration
  • Output will be found in the docs folder
  • Generate docs by: npm run docs

Testing

Testing using @lamnhan/testea:

  • Generate spec files by: testea generate
  • All specs files are under test folder
  • Run test by: npm run test

Continuous integration

See .travis.yml

Vendor code

When you want to include code from other projects, put them into src/lib/vendors/name.vendor.ts. For example, a function from lodash.

Add // @ts-nocheck at the top of the files to disable Typescript.

Vendor files also excluded from linting.

Special deployment

Libraries for Node projects are deployed with the src/ folder that contains all the content.

Special project will be deployed from the .deploy/ folder:

  • Refer using a script (... deploy) to generate .deploy/, then deploy, then remove .deploy/.
  • Pass --dry-run to the script to generate .deploy/ only.

Project types

Seminjecto supports these types of Node project, where source code is hosted under src folder.

Library

A library is a project that can using in other projects.

A library is organized into a pair of file and folder:

  • The public-api.ts file: where you export anything you want other project to access
  • The lib folder: the lirary home, contains index.ts (class Lib) and groups of source code by type (services, ...)

See package.json for properties and scripts.

CLI

A CLI project is an extended of library, a pair of file and folder added:

  • The bin.ts file: the cli logic
  • The cli folder: the CLI home, contains index.ts (class Cli) and groups of source code by type (commands, ...)

See bin property in package.json for CLI app registration.

Express

A ExpressJS project is an extended of library, a pair of file and folder added:

  • The www.ts file: the app logic
  • The app folder: the app home, contains index.ts (class App) and groups of source code by type (routes, ...)

Sheetbase

A Sheetbase project is an extended of library, a pair of file and folder added:

  • The www.ts file: the app logic
  • The app folder: the app home, contains index.ts (class App) and groups of source code by type (routes, ...)

Workspace

A Workspace project is an extended of library, a pair of file and folder added:

  • The hook.ts file: the addon logic
  • The addon folder: the addon home, contains index.ts (class Addon) and groups of source code by type (sidebars, modals, ...)

Command overview

Simple dependency injection for Typescript modules.

Command reference

[

Usage:

semidi [         [ ' n e w   < t y p e >   < n a m e >   [ d e s c r i p t i o n ] ' ,   ' s t a r t ' ,   ' n ' ] ,
         ' C r e a t e   a   n e w   p r o j e c t . ' ,
         [
             ' - s ,   - - s o u r c e   [ v a l u e ] ' ,
             ' C u s t o m   s o u r c e :   { i n n e r _ r e p o } @ { t a g } ,   { o r g } / { r e p o } ,   { o r g } / { r e p o } @ { t a g }   o r   u r l . ' ,
         ] ,
         [ ' - i ,   - - s k i p - i n s t a l l ' ,   ' D o e s   n o t   i n s t a l l   d e p e n d e n c y   p a c k a g e s . ' ] ,
         [ ' - g ,   - - s k i p - g i t ' ,   ' D o e s   n o t   i n i t i a l i z e   a   g i t   r e p o s i t o r y . ' ] ,
     ]

Options:

  • :
  • :
  • :
  • :
  • [:
  • ':
  • n:
  • e:
  • w:
  • :
  • <:
  • t:
  • y:
  • p:
  • e:
  • >:
  • :
  • <:
  • n:
  • a:
  • m:
  • e:
  • >:
  • :
  • [:
  • d:
  • e:
  • s:
  • c:
  • r:
  • i:
  • p:
  • t:
  • i:
  • o:
  • n:
  • ]:
  • ':
  • ,:
  • :
  • ':
  • s:
  • t:
  • a:
  • r:
  • t:
  • ':
  • ,:
  • :
  • ':
  • n:
  • ':
  • ]:
  • ,:
  • :
  • :
  • :
  • :
  • :
  • ':
  • C:
  • r:
  • e:
  • a:
  • t:
  • e:
  • :
  • a:
  • :
  • n:
  • e:
  • w:
  • :
  • p:
  • r:
  • o:
  • j:
  • e:
  • c:
  • t:
  • .:
  • ':
  • ,:
  • :
  • :
  • :
  • :
  • :
  • [:
  • :
  • :
  • :
  • :
  • :
  • :
  • :
  • ':
  • -:
  • s:
  • ,:
  • :
  • -:
  • -:
  • s:
  • o:
  • u:
  • r:
  • c:
  • e:
  • :
  • [:
  • v:
  • a:
  • l:
  • u:
  • e:
  • ]:
  • ':
  • ,:
  • :
  • :
  • :
  • :
  • :
  • :
  • :
  • ':
  • C:
  • u:
  • s:
  • t:
  • o:
  • m:
  • :
  • s:
  • o:
  • u:
  • r:
  • c:
  • e:
  • ::
  • :
  • {:
  • i:
  • n:
  • n:
  • e:
  • r:
  • _:
  • r:
  • e:
  • p:
  • o:
  • }:
  • @:
  • {:
  • t:
  • a:
  • g:
  • }:
  • ,:
  • :
  • {:
  • o:
  • r:
  • g:
  • }:
  • /:
  • {:
  • r:
  • e:
  • p:
  • o:
  • }:
  • ,:
  • :
  • {:
  • o:
  • r:
  • g:
  • }:
  • /:
  • {:
  • r:
  • e:
  • p:
  • o:
  • }:
  • @:
  • {:
  • t:
  • a:
  • g:
  • }:
  • :
  • o:
  • r:
  • :
  • u:
  • r:
  • l:
  • .:
  • ':
  • ,:
  • :
  • :
  • :
  • :
  • :
  • ]:
  • ,:
  • :
  • :
  • :
  • :
  • :
  • [:
  • ':
  • -:
  • i:
  • ,:
  • :
  • -:
  • -:
  • s:
  • k:
  • i:
  • p:
  • -:
  • i:
  • n:
  • s:
  • t:
  • a:
  • l:
  • l:
  • ':
  • ,:
  • :
  • ':
  • D:
  • o:
  • e:
  • s:
  • :
  • n:
  • o:
  • t:
  • :
  • i:
  • n:
  • s:
  • t:
  • a:
  • l:
  • l:
  • :
  • d:
  • e:
  • p:
  • e:
  • n:
  • d:
  • e:
  • n:
  • c:
  • y:
  • :
  • p:
  • a:
  • c:
  • k:
  • a:
  • g:
  • e:
  • s:
  • .:
  • ':
  • ]:
  • ,:
  • :
  • :
  • :
  • :
  • :
  • [:
  • ':
  • -:
  • g:
  • ,:
  • :
  • -:
  • -:
  • s:
  • k:
  • i:
  • p:
  • -:
  • g:
  • i:
  • t:
  • ':
  • ,:
  • :
  • ':
  • D:
  • o:
  • e:
  • s:
  • :
  • n:
  • o:
  • t:
  • :
  • i:
  • n:
  • i:
  • t:
  • i:
  • a:
  • l:
  • i:
  • z:
  • e:
  • :
  • a:
  • :
  • g:
  • i:
  • t:
  • :
  • r:
  • e:
  • p:
  • o:
  • s:
  • i:
  • t:
  • o:
  • r:
  • y:
  • .:
  • ':
  • ]:
  • ,:
  • :
  • :
  • :
  • ]:

clean

Clean typescript output files.

Usage:

semidi clean --skip-question --list --includes [value] --excludes [value]
semidi c --skip-question --list --includes [value] --excludes [value]

Options:

  • -y, --skip-question: Does not ask question.
  • -l, --list: Show list of files.
  • -i, --includes [value]: Including files, separated by |.
  • -e, --excludes [value]: Excluding files, separated by |.

generate

Generate a resource.

Usage:

semidi generate <type> <dest> --nested --typing
semidi create <type> <dest> --nested --typing
semidi g <type> <dest> --nested --typing

Parameters:

  • <type>: The resource type
  • <dest>: The resource destination

Options:

  • -n, --nested: Nested under a folder.
  • -t, --typing: Save typing file.

help

Display help.

Usage:

semidi help

*

Any other command is not suppoted.

Usage:

semidi <cmd>

License

@lamnhan/seminjecto is released under the MIT license.


⚡️ This document is generated automatically using @lamnhan/ayedocs.