@stugotech/module-init
TypeScript icon, indicating that this package has built-in type declarations

1.6.0 • Public • Published

module-init

Initialisation system for easy module loading.

Get it

Download from NPM:

npm install --save @stugotech/module-init

Use it

Define a module

Use the define function to define a new module.

import { define } from 'module-init';
import * as dependency from './dependency';
import * as after from './after';


export const definition = define('modulename', [dependency.definition], [after.definition], async () => {
  // init code here
});

This makes dependency a dependency of the current module, and the current module a dependency of after.

Load a directory of modules

Use require-all:

import * as requireAll from 'require-all';
import { ModuleCollection, getDefinition } from 'module-init';

// load an object like { module1: module2.definition, module2: module2.definition }
const moduleMap = requireAll({
  dirname: 'modules',
  recursive: true, 
  filter: /^(.*).ts$/,
  excludeDirs: options.excludeDirs,
  resolve: getDefinition,
});

const modules = new ModuleCollection<string>(Object.values(moduleMap));
await modules.init('hello world');

Readme

Keywords

none

Package Sidebar

Install

npm i @stugotech/module-init

Weekly Downloads

4

Version

1.6.0

License

ISC

Last publish

Collaborators

  • gordonmleigh
  • stewartml