0.6.10 • Published 8 years ago

typescript-middleware v0.6.10

Weekly downloads
3
License
MIT
Repository
github
Last release
8 years ago

What's this

The on the fly typescript compile server for express/connect.

Install

npm install typescript-middleware

Usage

var tscMiddleware = require('typescript-middleware');
var connect = require('connect');
var app = connect();
app.use('typescript', tscMiddleware({
  outDir: 'js/out', // The output directory of compilation result.
  sourceMap: true, // [OPTIONAL] Generate sourceMap file
  sourceRoot: '', // [OPTIONAL] Source root path.
  mapRoot: './ts', // [OPTIONAL] SourceMap root directory
  basePath: './ts', // Typescript root directory
  removeComments: false, // [OPTIONAL] [true/false] Save comments on generated source.
  target: 'es3', // [es3/es5] Target ecmascript environment.
  module: 'amd', // [amd/commonjs] Target javascript module.
  useCaseSensitiveFileResolution: true, // [OPTIONAL] [true/false] To use case sensitive module search.
  locale: 'en', // [OPTIONAL] [en/ja-jp] Locale.
  noImplicitAny: false, // [OPTIONAL] [true/false] Whether allow implicit any or not.
  requirejsPath: 'js/libs/requirejs/require.js', // The path to the requirejs
  requirejsConfigPath: 'js/requirejs.config.js', // The path to the requirejs config file.
  urlRoot: './', // The url root path.
  updateAll: true // [OPTIONAL] [true/false] Whether record all typescript file mtime before server running or not.
  respond: true // [OPTIONAL] [true/false] Respond compilation result as requirejs main.
}));

Compilation

All typescript files are compiled if mtime is updated,
to get mtime value, we use fs.statSync

Options

outDir

The output directory of the compilation results.

sourceMap

OPTIONAL Generate sourceMap files.
values: true/false
default: false

sourceRoot

OPTIONAL The source root path for typescript.

mapRoot

OPTIONAL The source map root path.

basePath

The typescript root path.

removeComments

OPTIONAL Whether remove comments from generated source code or not.
values: true/false
default: true

target

OPTIONAL Target runtime for generated source code.
values: 'es3'/'es5'
default: 'es5'

module

OPTIONAL The module pattern for generated source code.
values: 'amd'/'commonjs'
default: 'amd'

useCaseSensitiveFileResolution

OPTIONAL Whether search referenced module by case sensitive.
value: true/false
default: true

locale

OPTIONAL The locale
value: 'en'/'ja-jp'
default: 'en'

noImplicitAny

OPTIONAL disallow implicit any type.
value: true/false default: false

requirejsPath

OPTIONAL Specify requirejs path for auto running.
This option affect only if respond option is true.

requirejsConfigPath

OPTIONAL Specify requirejs config file path.
This option affect only if respond option is true.

urlRoot

The root path of static files.

updateAll

OPTIONAL Collect mtime of the all modules, before accessed. values: true/false default: false

respond

OPTIONAL Respond compilation result as requirejs main file. values: true/false default: true

usePathname

OPTIONAL Use path name for decide compile target.
If this option is false, compile target is decided by 'path' query parameter. values: true/false default: false

Example(respond = true, usePathname = false)

Server

var connect = require('connect');
var app = connect();
app.use('typescript', tscMiddleware({
  basePath : '../ts/src',
  sourceMap: true,
  target: 'es3',
  module: 'amd',
  sourceMap: true,
  urlRoot: '../',
  outDir: '../js/output',
  requirejsPath: '../js/node_modules/requirejs/require.js',
  requirejsConfigPath: '../js/conf/requirejs.config.js',
  updateAll: true
})
.use(connect.static('../'))
.listen(8080);

HTML

<!doctype html>
<html>
<head>
  <script type="text/javascript" src="//localhost:8080/typescript?path=main/foo/bar/main.ts"></script>
</head>
<body>
</body>
</html>

Response

!function() {
  document.writeln('<script type="text/javascript" src="/js/conf/requirejs.config.js"><' + '/script>');
  document.writeln('<script type="text/javascript" src="/js/node_modules/requirejs/require.js" data-main="/js/output/foo/bar/main.js"><' + '/script>');
}();

Example(respond = false, usePathname = true)

Server

var connect = require('connect');
var app = connect();
app.use(tscMiddleware({
  basePath : '../ts/src',
  sourceMap: true,
  target: 'es3',
  module: 'amd',
  sourceMap: true,
  urlRoot: '../',
  outDir: '../js/output',
  requirejsPath: '../js/node_modules/requirejs/require.js',
  requirejsConfigPath: '../js/conf/requirejs.config.js',
  updateAll: true,
  respond: false,
  usePathname: true
})
.use(connect.static('../'))
.listen(8080);

HTML

<!doctype html>
<html>
<head>
  <!-Specify output file.-->
  <script type="text/javascript" src="//localhost:8080/js/output/main/foo/bar/main.js"></script>
</head>
<body>
</body>
</html>

typescript

class Main {}

export = Main;

Response

var Main = (function () {
    function Main() {
    }
    return Main;
})();

module.exports = Main;
//# sourceMappingURL=main.js.map
0.6.10

8 years ago

0.6.9

9 years ago

0.6.8

9 years ago

0.6.7

9 years ago

0.6.6

9 years ago

0.6.5

9 years ago

0.6.4

9 years ago

0.6.3

9 years ago

0.6.2

9 years ago

0.6.1

9 years ago

0.6.0

9 years ago

0.5.4

9 years ago

0.5.3

9 years ago

0.5.2

9 years ago

0.5.1

9 years ago

0.5.0

9 years ago

0.4.2

10 years ago

0.4.1

10 years ago

0.3.6

10 years ago

0.3.5

10 years ago

0.3.4

10 years ago

0.3.3

10 years ago

0.3.2

10 years ago

0.3.1

10 years ago

0.3.0

10 years ago

0.2.4

10 years ago

0.2.3

10 years ago

0.2.2

10 years ago

0.2.1

10 years ago

0.2.0

10 years ago

0.1.4

10 years ago

0.1.3

10 years ago

0.1.2

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago