Skip to content

leduong/gulp-ts-config

Repository files navigation

gulp-ts-config

Paypal Gratipay Team

License NPM version NPM version Build Status Coverage Status dependencies Status

NPM

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-ts-config

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('gulp-ts-config');

gulp.task('test', function () {
  gulp.src('appsettings.json')
  .pipe(gulpTsConfig('AppSettings'))
  .pipe(gulp.dest('.'))
});

Assume that appsettings.json contains:

{
  "ApiEndpoint": "https://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 "https://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:

This is copy from Atticus White @robinpowered

Thanks

About

Typescript configuration generator

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published