metatypescript

3.3.8 • Public • Published

metatypescript

A synchronous Typescript module system. Alternative to CommonJs, AMD and RequireJS.

It is designed to manage big projects with a lot of dependencies between files/modules.

It comes with a bunch of dependencies helpers and JS generations.

The files are separated into submodules and only submodules than require recompilations will be recompiled (determined by their dependencies). Each submodule can be compiled from 0.4s to 1s so instead to have a 20s compilation project you will have a 1s compilation project:)

##Setup

npm -g install metatypescript

###Mac OS X You can install terminal-notifier package to have notifications enabled

brew install terminal-notifier

###Others OS Pynotify is used for others OS but still unstable so maybe after an inactive period you will lost notification support

##How it works Each submodule is compiled one by one and only include .d.ts of others modules.

##Usage

metatypescript [--reset] [--nosound] [--nonotification] [--es5]
  • reset: Will recompile all modules event if they are up to date
  • nosound: Disable sound alert when compilation is done
  • nonotification: Disable notification alert when compilation is done
  • es5: Target ES5 instead of ES3 (see Typescript compiler documentation for this one)

Metatypescript script will search a metatypescript.json file inside the current directory. If no file is found, the script will create an example project and will download the lib folder from https://github.com/borisyankov/DefinitelyTyped

###Example If you launch the command metatypescript inside an empty folder it will create an example project with some basic dependencies to help you understand how it works

###Configuration file metatypescript.json config file example:

 {
 	//list of module's folders
	"folders":[
		"framework/ghost", 
		"framework/browser",
		"game/battle"
	],
	//if you wanted only one JS file from a module and all its dependencies
	"out":
	{
		"battle/main":"../js/main.js"
	},
	//if true will compile for each module a JS file
	"compile_modules":false,
	"concat_sourcemaps":false
}
  • folders: List of modules paths
  • out: Compiles a typescript submodule and all its dependencies into a JS file. Modules not used by the submodule will not be included!
  • compile_modules: If true, for each module a JS file will be generated will all its submodules inside
  • concat_sourcemaps: (not recommended) If true JS files generated by the out parameter will have sourcemaps correctly configured to link JS file files to the original typescripts files. However this feature is currently unstable and add few seconds on each compile time.

###Dependencies helpers Inside a typescript file you can use these keywords to manage dependencies

####File

	#File2.ts
	///<file="File1.ts"/>

Tell the script than File1 comes before File2. When the submodule will be compiled to an unique .ts file its content will be :

///<reference path="File1.ts"/>
///<reference path="File2.ts"/>

####Module

#File1.ts
///<module="folder/module/submodule">

This line will include the folder/module/submodule .d.ts file to this current submodule. The module path can be shorter depending of the File1.ts path

If File1 path is:

  • folder/module/submodule2
#only submodule's name is needed
///<module="submodule"/> 
  • folder/module2/anyname
#module and submodule are needed
///<module="module2/submodule"/> 
  • otherwise
#absolute path is needed
///<module="folder/module2/submodule"/> 

####Lib

In typescript you can include .d.ts files to use existing librairy and still be in a strong typed environment. To use them easily with metatypescript put them into a lib folder and include them will the lib keyword

///<lib="jquery">
#will add /lib/jquery/jquery.d.ts file as dependency 

Theses files can be found at https://github.com/borisyankov/DefinitelyTyped

Readme

Keywords

none

Package Sidebar

Install

npm i metatypescript

Weekly Downloads

5

Version

3.3.8

License

MIT

Last publish

Collaborators

  • mymyoux