gulp-kc-config-ts
v0.1.0
Published
Typescript configuration generator
Downloads
1
Maintainers
Readme
gulp-ts-config
It's often useful to generate a file of constants, usually as environment variables, for your Angular apps. This Gulp plugin will allow you to provide an object of properties and will generate an Angular module of constants.
To Install:
npm install gulp-kc-config-ts
How it works
It's pretty simple:
gulpTsConfig(moduleName)
Example Usage
We start with our task. Our source file is a JSON file containing our configuration. We will pipe this through gulpTsConfig
and out will come an angular module of constants.
var gulp = require('gulp');
var gulpTsConfig = require('kc-gulp-ts-config');
gulp.task('test', function () {
gulp.src('appsettings.json')
.pipe(gulpTsConfig('AppSettings'))
.pipe(gulp.dest('.'))
});
Assume that appsettings.json
contains:
{
"ApiEndpoint": "http://localhost:5000/api"
}
Running gulp test
will take appsettings.json
and produce appsettings.ts
with the following content:
export class AppSettings {
public static get ApiEndpoint(): string {
return "http://localhost:5000/api";
}
}
We now can include this configuration module in our main app and access the constants
import { AppSettings } from 'appsettings';
Configuration
Currently there are a few configurable options to control the output of your configuration file:
- options.environment
- options.constants
- options.createModule
- options.type
- options.wrap
- options.parser
- options.pretty
This is copy from Atticus White @robinpowered
Thanks