-
-
Save piraveen/52b7aea36f06f02b17064969fadca00f to your computer and use it in GitHub Desktop.
Sample gulp config task for typescript using gulp ng-constant, creates a Angular constant typescript file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
var gulp = require('gulp'); | |
var $ = require('gulp-load-plugins')(); | |
gulp.task('config', function () { | |
var config = require('../config.json'), | |
envConfig = config.development; | |
[process.env.NODE_ENV === 'production' ? 'production' : 'development'] | |
if(process.env.NODE_ENV === 'production'){ | |
console.log('loading production config'); | |
envConfig = config.production; | |
} else{ | |
console.log('loading dev config'); | |
} | |
return $.ngConstant({ | |
constants: envConfig, | |
templatePath: 'constant.tpl.ejs', | |
stream: true | |
}) | |
.pipe($.rename('config.ts')) | |
.pipe(gulp.dest('src/app/')); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"development": { | |
"apiBase": "http://localhost:3000/api" | |
}, | |
"production": { | |
"apiBase": "https:/someurl.net/api" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export interface IConstants {<% constants.forEach(function(constant) {%> | |
<%= constant.name.replace(/"/g, "'") %>: string;<% }) %> | |
} | |
export default {<% constants.forEach(function(constant) {%> | |
<%= constant.name.replace(/"/g, "'") %>: <%= constant.value.replace(/"/g, "'")%>,<% }) %> | |
}; | |
export var Constants = {<% constants.forEach(function(constant) {%> | |
<%= constant.name.replace(/"/g, "'") %>: <%= constant.value.replace(/"/g, "'")%>,<% }) %> | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Constants from './config'; | |
module appName { | |
'use strict'; | |
angular.module('appName', [ | |
'ngAnimate', | |
'ngCookies', | |
'ngTouch', | |
'ngSanitize', | |
'ngMessages', | |
'ngAria', | |
'ui.router', | |
'ngMaterial', | |
'ngResource', | |
'formly' | |
]) | |
.constant('constants', Constants) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Constants } from './config'; | |
export class MainController { | |
public apiBase: string; | |
/* @ngInject */ | |
constructor (constants: Constants) { | |
this.apiBase = constants.apiBase | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment