1.6.0 • Published 7 years ago

@stugotech/module-init v1.6.0

Weekly downloads
-
License
ISC
Repository
github
Last release
7 years ago

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');
1.6.0

7 years ago

1.5.0

7 years ago

1.4.4

7 years ago

1.4.3

7 years ago

1.4.2

7 years ago

1.4.1

7 years ago

1.4.0

7 years ago

1.3.0

7 years ago

1.2.2

7 years ago

1.2.1

7 years ago

1.2.0

7 years ago

1.1.0

7 years ago

1.0.0

7 years ago