Last active
October 6, 2015 01:42
-
-
Save jbasinger/b8e095e5648c990e52c1 to your computer and use it in GitHub Desktop.
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
| angular.module('constants',[]) | |
| .constant('ENV',{ | |
| name: 'dev', | |
| baseUrl: 'http://dev.whatever.com', | |
| magicKey: '123-456-789', | |
| someOtherThing: { | |
| id: 1, | |
| arrayOfSomeStuff: [1,2,3,4,5] | |
| } | |
| }); |
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
| //Here we're going to copy our config based on our options. Dev by default | |
| // GOTCHAS - This assumes there will be only one -- style option in the command line. | |
| // More code would have to be added to handle more options. | |
| // Perhaps parse them using this: https://github.com/bcoe/yargs | |
| var fs = require('fs'); | |
| module.exports = function(context){ | |
| //Uncomment this to see other options the context gives you. | |
| //console.log(context); | |
| //This gives us promises! | |
| var Q = context.requireCordovaModule('q'); | |
| var defer = Q.defer(); | |
| var envSelect = context.cmdLine.split('--'); | |
| var envName = 'dev'; | |
| if(envSelect.length > 1){ | |
| envName = envSelect[1]; | |
| } | |
| console.log('Loading environment named: ' + envName); | |
| var projectRoot = context.opts.projectRoot; | |
| var sourceFile = projectRoot + '/www/config/' + envName + '.js'; | |
| var destFile = projectRoot + '/www/js/config.js'; | |
| var readStream = fs.createReadStream(sourceFile); | |
| var writeStream = fs.createWriteStream(destFile); | |
| readStream.on('error', function(err){ | |
| defer.reject('Could not copy\n'+sourceFile +'\nto\n' + destFile); | |
| }); | |
| writeStream.on('error', function(err){ | |
| defer.reject('Could not copy\n'+sourceFile +'\nto\n' + destFile); | |
| }); | |
| writeStream.on('close', function(){ | |
| console.log('Environment ' + envName + ' loaded successfully!'); | |
| defer.resolve(); | |
| }); | |
| readStream.pipe(writeStream); | |
| return defer.promise; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment