11var util = require ( 'util' ) ;
22var path = require ( 'path' ) ;
33var _ = require ( "lodash" ) ;
4+ var ejs = require ( "ejs" ) ;
45
56var fileUtil = require ( "./file-util" ) ;
67var logger = require ( "./logger" ) ;
78var readConfig = require ( "./read-config" ) ;
89var OptimizelyClient = require ( "optimizely-node-client" ) ;
910var OptCLIBase = require ( "./optcli-base" ) ;
11+ var Assets = require ( './assets' ) ;
1012
1113function Variation ( attributes , baseDir ) {
1214 Variation . super_ . call ( this , attributes , baseDir ) ;
@@ -38,10 +40,20 @@ Variation.prototype.getJS = function() {
3840}
3941
4042Variation . prototype . createRemote = function ( client , remote ) {
43+ //assume assets are in experiment.baseDir
44+ var assets = new Assets ( { } , path . normalize ( this . baseDir + "/.." ) ) ;
45+ if ( assets . JSONFileExists ( ) ) {
46+ logger . log ( "info" , "assets file found, loading" ) ;
47+ assets . loadFromFile ( ) ;
48+ }
4149
4250 //create new variation
4351 var varArgs = _ . clone ( this . attributes ) ;
44- varArgs [ 'js_component' ] = this . getJS ( ) ;
52+ varArgs [ 'js_component' ] = String ( ejs . render ( this . getJS ( ) , {
53+ locals : {
54+ assets : assets . attributes
55+ }
56+ } ) ) ;
4557 varArgs [ 'experiment_id' ] = experiment . attributes . id ;
4658
4759 var self = this ;
@@ -58,9 +70,19 @@ Variation.prototype.createRemote = function(client, remote) {
5870}
5971
6072Variation . prototype . updateRemote = function ( client ) {
61- //create new experiment
73+ //assume assets are in experiment.baseDir
74+ var assets = new Assets ( { } , path . normalize ( this . baseDir + "/.." ) ) ;
75+ if ( assets . JSONFileExists ( ) ) {
76+ logger . log ( "info" , "assets file found, loading" ) ;
77+ assets . loadFromFile ( ) ;
78+ }
79+
6280 var varArgs = _ . clone ( this . attributes ) ;
63- varArgs [ 'js_component' ] = this . getJS ( ) ;
81+ varArgs [ 'js_component' ] = String ( ejs . render ( this . getJS ( ) , {
82+ locals : {
83+ assets : assets . attributes
84+ }
85+ } ) ) ;
6486
6587 var self = this ;
6688 return client . updateVariation ( varArgs ) . then ( function ( variationAttrs ) {
0 commit comments