Skip to content

Commit

Permalink
replacing grunt-template and associated tasks with grunt-ng-constant …
Browse files Browse the repository at this point in the history
…for environment config
  • Loading branch information
dharmamike committed Mar 10, 2015
1 parent dfb009d commit 1f34f97
Show file tree
Hide file tree
Showing 13 changed files with 55 additions and 59 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ dist
.sass-cache
bower_components
app/scripts/directives/templates.js
app/scripts/app.js
app/scripts/config.js
46 changes: 28 additions & 18 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,39 @@ module.exports = function (grunt) {
dist: 'dist'
};

var env = process.env.LORRY_ENV || 'development';

// Define the configuration for all the tasks
grunt.initConfig({

// Project settings
yeoman: appConfig,

template: {
test: {
ngconstant: {
options: {
space: ' ',
wrap: '"use strict";\n\n {%= __ngModule %}',
name: 'config'
},
// Environment targets
development: {
options: {
data: require('./config/' + env + '.json')
dest: '<%= yeoman.app %>/scripts/config.js'
},
files: {
'<%= yeoman.app %>/scripts/app.js': ['<%= yeoman.app %>/scripts/app.js.tpl']
constants: {
ENV: {
REGISTRY_API_ENDPOINT: 'https://index.docker.io',
LORRY_API_ENDPOINT: 'http://localhost:9292'
}
}
},
dist: {
production: {
options: {
data: require('./config/' + env + '.json')
dest: '<%= yeoman.dist %>/scripts/config.js'
},
files: {
'.tmp/scripts/app.js': ['<%= yeoman.app %>/scripts/app.js.tpl']
constants: {
ENV: {
REGISTRY_API_ENDPOINT: 'https://index.docker.io',
LORRY_API_ENDPOINT: process.env.LORRY_API_ENDPOINT
}
}
}
},
Expand Down Expand Up @@ -135,7 +145,8 @@ module.exports = function (grunt) {
jshint: {
options: {
jshintrc: '.jshintrc',
reporter: require('jshint-stylish')
reporter: require('jshint-stylish'),
ignores: ['<%= yeoman.app %>/scripts/FileSaver.js']
},
all: {
src: [
Expand All @@ -159,12 +170,11 @@ module.exports = function (grunt) {
src: [
'.tmp',
'<%= yeoman.dist %>/{,*/}*',
'!<%= yeoman.dist %>/.git{,*/}*',
'<%= yeoman.app %>/scripts/app.js'
'!<%= yeoman.dist %>/.git{,*/}*'
]
}]
},
server: ['.tmp', '<%= yeoman.app %>/scripts/app.js']
server: ['.tmp']
},

// Add vendor prefixed styles
Expand Down Expand Up @@ -452,7 +462,7 @@ module.exports = function (grunt) {

grunt.task.run([
'clean:server',
'configure:test',
'ngconstant:development',
'wiredep',
'html2js',
'concurrent:server',
Expand All @@ -469,7 +479,7 @@ module.exports = function (grunt) {

grunt.registerTask('test', [
'clean:server',
'configure:test',
'ngconstant:development',
'wiredep:test',
'concurrent:test',
'autoprefixer',
Expand All @@ -480,7 +490,7 @@ module.exports = function (grunt) {

grunt.registerTask('build', [
'clean:dist',
'configure:dist',
'ngconstant:production',
'wiredep',
'html2js',
'useminPrepare',
Expand Down
1 change: 1 addition & 0 deletions app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
<script src="scripts/FileSaver.js"></script>
<script src="scripts/directives/templates.js"></script>
<script src="scripts/app.js"></script>
<script src="scripts/config.js"></script>
<script src="scripts/controllers/main.js"></script>
<script src="scripts/controllers/search.js"></script>
<script src="scripts/controllers/document.js"></script>
Expand Down
7 changes: 2 additions & 5 deletions app/scripts/app.js.tpl → app/scripts/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,9 @@ angular
'ngSanitize',
'ngLodash',
'ngDialog',
'config',
'directive-templates',
'angular.filter',
'docker-registry',
'720kb.tooltips'
])
.constant('appConfig', {
'REGISTRY_API_ENDPOINT': '<%= REGISTRY_API_ENDPOINT %>',
'LORRY_API_ENDPOINT' : '<%= LORRY_API_ENDPOINT %>'
});
]);
10 changes: 5 additions & 5 deletions app/scripts/services/docker-registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
// This is the main entry point to interact with the Docker Registry API.

angular.module('docker-registry', ['ngResource'])
.factory('Repository', ['$resource', 'appConfig', function($resource, appConfig){
return $resource(appConfig.REGISTRY_API_ENDPOINT + '/v1/search?q=:searchTerm', {searchTerm:'@term'}, {
.factory('Repository', ['$resource', 'ENV', function($resource, ENV){
return $resource(ENV.REGISTRY_API_ENDPOINT + '/v1/search?q=:searchTerm', {searchTerm:'@term'}, {
'query': {
method:'GET',
isArray: true,
Expand All @@ -19,8 +19,8 @@ angular.module('docker-registry', ['ngResource'])
}
});
}])
.factory('Tag', ['$resource', 'appConfig', function($resource, appConfig){
return $resource(appConfig.REGISTRY_API_ENDPOINT + '/v1/repositories/:repoUser/:repoName/tags', {}, {
.factory('Tag', ['$resource', 'ENV', function($resource, ENV){
return $resource(ENV.REGISTRY_API_ENDPOINT + '/v1/repositories/:repoUser/:repoName/tags', {}, {
'query': {
method:'GET',
isArray: true,
Expand All @@ -30,7 +30,7 @@ angular.module('docker-registry', ['ngResource'])
}
},
'exists': {
url: appConfig.REGISTRY_API_ENDPOINT + '/v1/repositories/:repoUser/:repoName/tags/:tagName',
url: ENV.REGISTRY_API_ENDPOINT + '/v1/repositories/:repoUser/:repoName/tags/:tagName',
method: 'GET',
transformResponse: function(data, headers){
// data will be the image ID if successful or an error object.
Expand Down
4 changes: 2 additions & 2 deletions app/scripts/services/yaml-validator.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
'use strict';

angular.module('lorryApp')
.factory('yamlValidator', ['$http', '$log', 'appConfig', function ($http, $log, appConfig) {
.factory('yamlValidator', ['$http', '$log', 'ENV', function ($http, $log, ENV) {
return {
validate: function(yamlDocument) {
return $http.post(appConfig.LORRY_API_ENDPOINT + '/validation', { 'document': yamlDocument });
return $http.post(ENV.LORRY_API_ENDPOINT + '/validation', { 'document': yamlDocument });
}
};
}]);
4 changes: 0 additions & 4 deletions config/development.json

This file was deleted.

4 changes: 0 additions & 4 deletions config/production.json

This file was deleted.

4 changes: 0 additions & 4 deletions config/qa.json

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
"grunt-karma": "^0.10.1",
"grunt-newer": "^0.8.0",
"grunt-ng-annotate": "^0.10.0",
"grunt-ng-constant": "^1.1.0",
"grunt-svgmin": "^2.0.0",
"grunt-template": "^0.2.3",
"grunt-usemin": "^2.6.2",
"grunt-wiredep": "^2.0.0",
"jasmine-core": "^2.2.0",
Expand Down
2 changes: 1 addition & 1 deletion test/spec/controllers/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ describe('Controller: SearchCtrl', function () {
beforeEach(module('lorryApp'));

beforeEach(module(function($provide) {
$provide.constant('appConfig', {'REGISTRY_API_ENDPOINT': 'https://foobar.io'});
$provide.constant('ENV', {'REGISTRY_API_ENDPOINT': 'https://foobar.io'});
}));

var $controller, httpBackend, SearchCtrl, Repository, Tag, scope;
Expand Down
20 changes: 10 additions & 10 deletions test/spec/services/docker-registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ describe('Service: docker-registry', function () {
beforeEach(module('docker-registry'));

beforeEach(module(function($provide) {
$provide.constant('appConfig', {'REGISTRY_API_ENDPOINT': 'https://foobar.io'});
$provide.constant('ENV', {'REGISTRY_API_ENDPOINT': 'https://foobar.io'});
}));

// Repository factory
describe('Factory: Repository', function () {

var Repository, httpBackend, appConfig;
var Repository, httpBackend, ENV;
var searchResults = {
"results": [{
"name": "baruser/foo",
Expand All @@ -24,15 +24,15 @@ describe('Service: docker-registry', function () {
};

// Initialize the service and a mock scope
beforeEach(inject(function (_Repository_, _appConfig_, _$httpBackend_) {
beforeEach(inject(function (_Repository_, _ENV_, _$httpBackend_) {
Repository = _Repository_;
appConfig = _appConfig_;
ENV = _ENV_;
httpBackend = _$httpBackend_;
}));

describe('search', function() {
beforeEach(function() {
httpBackend.expectGET(appConfig.REGISTRY_API_ENDPOINT + "/v1/search?q=foo").respond(searchResults);
httpBackend.expectGET(ENV.REGISTRY_API_ENDPOINT + "/v1/search?q=foo").respond(searchResults);
});

it("should search for repositories", function () {
Expand Down Expand Up @@ -62,7 +62,7 @@ describe('Service: docker-registry', function () {
// Tag factory
describe('Factory: Tag', function () {

var Tag, httpBackend, appConfig;
var Tag, httpBackend, ENV;
var queryResults = [
{
"layer": "11111111",
Expand All @@ -77,16 +77,16 @@ describe('Service: docker-registry', function () {
];

// Initialize the service and a mock scope
beforeEach(inject(function (_Tag_, _appConfig_, _$httpBackend_) {
beforeEach(inject(function (_Tag_, _ENV_, _$httpBackend_) {
Tag = _Tag_;
appConfig = _appConfig_;
ENV = _ENV_;
httpBackend = _$httpBackend_;
}));

describe('tags', function() {

it("should get tags for repository", function () {
httpBackend.expectGET(appConfig.REGISTRY_API_ENDPOINT + "/v1/repositories/baruser/foo/tags").respond(queryResults);
httpBackend.expectGET(ENV.REGISTRY_API_ENDPOINT + "/v1/repositories/baruser/foo/tags").respond(queryResults);
var results = Tag.query({
repoUser: 'baruser',
repoName: 'foo'
Expand All @@ -98,7 +98,7 @@ describe('Service: docker-registry', function () {
});

it("should check if a tag exists for repository", function () {
httpBackend.expectGET(appConfig.REGISTRY_API_ENDPOINT + "/v1/repositories/baruser/foo/tags/latest").respond(existsResults);
httpBackend.expectGET(ENV.REGISTRY_API_ENDPOINT + "/v1/repositories/baruser/foo/tags/latest").respond(existsResults);
var result = Tag.exists({
repoUser: 'baruser',
repoName: 'foo',
Expand Down
8 changes: 4 additions & 4 deletions test/spec/services/yaml-validator.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
'use strict';

describe('Service: yamlValidator', function () {
var $httpBackend, yamlValidator, appConfig;
var $httpBackend, yamlValidator, ENV;

beforeEach(module('lorryApp'));

beforeEach(inject(function (_yamlValidator_, _$httpBackend_, _appConfig_) {
beforeEach(inject(function (_yamlValidator_, _$httpBackend_, _ENV_) {
yamlValidator = _yamlValidator_;
$httpBackend = _$httpBackend_;
appConfig = _appConfig_;
ENV = _ENV_;
}));

it('posts the document to the Lorry API validation endpoint', function () {
$httpBackend.expectPOST(
appConfig.LORRY_API_ENDPOINT + '/validation',
ENV.LORRY_API_ENDPOINT + '/validation',
{'document': 'some document'}
).respond();
yamlValidator.validate('some document');
Expand Down

0 comments on commit 1f34f97

Please sign in to comment.