Typespace
Converts import/require-style TypeScript directories into a unified namespace output.
Why?
AMD, CommonJS, UMD, and the like are wonderful dependency managers that you should strongly consider using in your project.
However, in some browser applications, it's useful to have a single smaller file without the overhead of exports
or require
.
- Video games that require extremely rapid startup times
- Older applications that haven't moved to something like require.js
That's where Typespace comes in.
It takes a full set of directories containing TypeScript files that reference each other using import
and/or require
, and combines them into a single .ts
output file.
Sources:
// src/Foo.ts;
// src/Bar.ts;console.log`Value: `;
Output:
(in the future, these will be combined and optimized for a reduced file size)
Usage
You can use Typespace via require
/import
or on the command-line. There's also a gulp plugin.
Required arguments/flags:
namespace
(-n
/--namespace
) - name of the root namespace
Optional arguments/flags:
config
(-c
/--config
) - input tsconfig.json file path to load files fromoutFile
(-o
/--outFile
) - output .ts file pathpathPrefix
(-p
/--pathPrefix
) - directory root to ignore from module pathsroot
(-r
/--root
) - root path to search for files undertarget
(-t
/--target
) - module resolution target, as"none"
or"commonjs"
CLI
First install Typespace with npm install typespace
.
You can then specify files from a TypeScript config file:
typespace --directory . --root src --outFile dist/combined.ts --config tsconfig.json
Code
const Typespace = ; const settings = config: "tsconfig.json" directory: "." outFile: "dist/combined.ts" root: "src"; const converter = settings;converter ;
Building
Typespace is built using Gulp.
npm install -g gulp-clinpm installgulp
The primary Gulp tasks are:
tslint
- lints source code with TSLinttsc
- compiles source code with TypeScripttest
- runs testswatch
- runs Gulp whenever a source or test file changes
Compilation
Source files are in TypeScript and primarly rely on async
/await
programming.
Babel is used for Node compatibility.
Tests
Tests files are in JavaScript and run with Mocha. Test coverage for unit tests is computed with Istanbul.