
Security News
CVE Volume Surges Past 48,000 in 2025 as WordPress Plugin Ecosystem Drives Growth
CVE disclosures hit a record 48,185 in 2025, driven largely by vulnerabilities in third-party WordPress plugins.
generator-optcli
Advanced tools
#Optcli
Note: This is an alternative implementation of the Funnel Envy's optcli tool. Rather than being a stand-alone tool, this generator makes use of readily available open source tools.
Optcli is a set of tools used by developers to create and manipulate Optimizely experiments on their local machines in addition to using the Optimizely web interface.
By developing locally, you are free to use whichever tools you want -- text editors, IDEs, and even precompilers.
In addition to developing locally, optcli adds a number of optional features that make test development easier and more efficient.
##Recent ChangeLog ###0.1.1
###0.1.0
##Introduction
Optcli, much like the Yeoman project that inspired it, optcli is built on a set of open source tools.
yo -- yo is a scaffolding tool used to create projects, experiments, and variations on your local machine.
gulp -- gulp is a tasks runner that's used to preform tasks associated with your experiment. It is used to host files locally, and push files to Optimizely. It is also used to facilitate the optional features mentioned above. Support is planned for other task runners including grunt and brocoli.
##Installation
###Prerequesites
To install optcli, first you must download and run the node installer from https://nodejs.org/. Node is a runtime that the optcli application requires.
Second, you'll need npm, a package manager that makes it easy to install runtime components. It's installed alongside node by default, so you can likely ignore this step.
(Note : Some users that have installed node via methods other than the one above have had issues using yo. For best results, please install/update you node installation only via downloading the installer from nodejs.org )
###Components
Once the prerequisites have been installed, on your command line, enter the following command in your terminal to install all necessary components:
npm install -g yo generator-optcli gulp
You now have all the necessary components installed to start working.
yo optcli:<generator>
###Generator -- Project
Create an optcli Project from within any directory. Yo can crate a project in any directory on your system.
yo optcli:project
###Generator -- Experiment
Create an optcli Experiment within a project directory. Ensure that you are within an project directory before using.
yo optcli:experiment
###Generator -- Variation
Create an optcli Variation within an experiment directory Ensure that you are within an experiment directory before using
yo optcli:variation
####Taskrunner The experiment generator allows you to optionally create a taskrunner file. Currently, this is a gulp file, but there are plans to support other taskrunners in the future.
The generated gulpfile's default tag facilitates the following features:
Edit the files within the experiment directory and run the command
gulp
or
gulp default
to transpile them into global.js, global.css, and variation.js files for hosting and pushing to optiizly.
#####Stylesheet Pre-processing You can choose to use less or scss instead of plain css. In addition, files are auto-prefixed to help ensure compatibility.
#####Javascript File Concatination Files in the folder _/includes folder will be incorporated into the mail global.js file.
_/includes/jaycurie.js
window.$ = function(){
alert('this is not jQuery');
return undefined;
}
_/global.js
var crucialDOMObject = $('.pleaseBeThere');
_/global.js
window.$ = function(){
alert('this is not jquery');
return undefined;
}
var crucialDOMObject = $('.pleaseBeThere');
#####Templating Each file script and style is processed as an EJS file. The ejs context contains:
######Template Usage : Incorporate Experiment Data You Experiment data is a often useful. Why not incorporate it into the experiment itself?
These files:
experiment.json
{
"description":"Title Test"
}
0/variation.json
{
"description":"First Title"
}
1/variation.json
{
"description":"Second Title"
}
_global.js
console.log("Experiment Running: <%= experiment.description%>")
0/_variation.js
$('title').text("<%= variation.description%>");
1/_variation.js
$('title').text("<%= variation.description%>");
, once processed will become:
global.js
console.log("Experiment Running: Title Test")
0/variation.js
$('title').text("First Title");
1/variation.js
$('title').text("Second Title");
You can also include custom data from package.json:
The files:
//package.json
{
...
"logo":"logo.png"
}
0/_variation.js
$('img').href("<%= package.logo %>");
, once processed will become:
0/_variation.js
$('img').href("logo.png");
######Template Usage : Build UI Elements Files in the _/assets/templates/ folder are incorporated into the ejs context by passing it's base file name into the template function.
The files:
_/assets/templates/logobox.html
<div>
<img src=\"logo.png\" />
</div>
0/_variation.js
var logobox = <%- JSON.stringify(template('logobox.html')) %>.join('\n');
$('body').append(logobox);
, once processed will become:
0/variation.js
var logobox = ["<div>"," <img src='logo.png' />","</div>"].join('\n');
$('body').append(logobox);
By passing in a locals object as the second argument to template fliles can be processes as ejs files in a separate context:
The files:
_/assets/templates/logobox.html
//package.json { ... "logo":"logo.png" }
<div>
<img src=\"<%= logo %>\" />
</div>
0/_variation.js
var logobox = [''<% template('logobox.html', {logo:package.logo}).forEach(function(line){ %>
,'<%- line %>'<%})%>].join('\n');
$('body').append(logobox);
, once processed will become:
0/variation.js
var logobox = [''
,'<div>',
,' <img src=\'logo.png\' />',
,'</div>',
,''].join('\n');
$('body').append(logobox);
Alternatively, the files:
_/assets/templates/logobox.html
<div>
<img src=\"logo.png\" />
</div>
0/_/variation.js
var logobox = '\
<% template("logobox.html").forEach(function(line){ %>
<%- line + '\\'%><%})%>\';
'
will produce:
0/variation.js
var logobox = '\'
<div>\
<img src=\"logo.png\" />\
</div>';
Important: Note the trailing "'" in the logobox definition 0/_/variation.js. It will cause an error if used in the code, but it's to preserve syntax highlighting in this document -- highlighters may not parse the preceeding content directly. For this reason, you are discouraged from incorporating templates in this way.
Use the hash function in order to ensure unique class names in your style code.
/global.css
.popup .button{
}
/*this may cause issues if something else decides to use the name 'popup'*/
_/global.scss
.cls<%=hx('popup')%> .button{
}
/*this will produce a unique string of characters unique to the experiment,
unlikely to cause collisions*/
Other than the default tasks, we've included a few other tasks for your convinience:
Running this task is exactly like running the default task, except it will recompile your _ folders whenever files are changed. It will also recompile whenever your package.json, experiment.json, or variation.json files are changed.
Example:
gulp watch
This task ensures that your code conforms to good coding practices.
Example:
gulp lint
Gulp push requires exactly one of three flags to work. In order for this to work properly, you must have a project.json file as well as a .token file in your experiment's paren't directory.
The experiment flag will push an experiment from a given directory
Example:
gulp push --experiment .
The variation flag will push a variation from a given directory
gulp push --variation <path to variation>
Using the all flag will push an experiment from a given directory AND variations created in subdirectories
gulp push --all
Run this task to host your local variations. In order for this to work properly, you must have a project.json file in your experiment's paren't directory.
Use the variation flag to specify the directory of the variation being hosted. This flag is mandatory.
gulp host --variation <path to variation>
Using the live flag will cause the browser to refresh whenever the experiment files are changes. This is especially useful in conjunction with gulp watch.
gulp host --live --variation <path to variation>
jQuery 1.6.4 is made automatically available to your experiment and variation script files.
Once you've started hosting, you can visit http://localhost:8080 or (https://localhost:8080 if your experiment's edit url is uses https).
This page will help you to install the userscript associated with optcli
The gulp file is designed to look at your projects edit url and determine if it should be hosted using ssl or not. Hosting changes to a secure site may not initially work. If this happens, visit https://localhost:8080 and tell your browser to allow you to visit the site.
MIT
FAQs
Yeoman generator
We found that generator-optcli demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
CVE disclosures hit a record 48,185 in 2025, driven largely by vulnerabilities in third-party WordPress plugins.

Security News
Socket CEO Feross Aboukhadijeh joins Insecure Agents to discuss CVE remediation and why supply chain attacks require a different security approach.

Security News
Tailwind Labs laid off 75% of its engineering team after revenue dropped 80%, as LLMs redirect traffic away from documentation where developers discover paid products.