Skip to content

Commit

Permalink
Merge pull request #31 from marmelab/build-app
Browse files Browse the repository at this point in the history
[RFR] Add build process
  • Loading branch information
manuquentin committed Sep 23, 2014
2 parents 4c45156 + 000748e commit b0969a6
Show file tree
Hide file tree
Showing 38 changed files with 460 additions and 416 deletions.
24 changes: 24 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,26 @@ module.exports = function (grunt) {
requirejs: grunt.file.readJSON('grunt/grunt-requirejs.json'),
compass: grunt.file.readJSON('grunt/grunt-compass.json'),

ngAnnotate: {
ngadmin: {
files: {
'src/build/ng-admin.min.js': ['src/build/ng-admin.min.js']
}
}
},

uglify: {
ngadmin: {
files: {
'src/build/ng-admin.min.js': ['src/build/ng-admin.min.js']
}
}
},

clean: {
build: ["src/build/app", "src/build/bower_components", "src/build/*.js", "!src/build/*.min.js"]
},

connect: {
server: {
options: {
Expand Down Expand Up @@ -72,13 +92,17 @@ module.exports = function (grunt) {
grunt.loadNpmTasks('grunt-contrib-compass');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-ng-annotate');
grunt.loadNpmTasks('grunt-concurrent');
grunt.loadNpmTasks('grunt-karma');

// register tasks
grunt.registerTask('assets:js', ['requirejs:dev']);
grunt.registerTask('assets:css', ['compass:dev']);
grunt.registerTask('test', ['karma']);
grunt.registerTask('build', ['requirejs:prod', 'ngAnnotate', 'uglify']);

// register default task
grunt.registerTask('default', ['concurrent:assets_all_dev', 'concurrent:connect_watch']);
Expand Down
4 changes: 2 additions & 2 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"jquery": "~1.11.0",
"requirejs": "~2.1.14",
"requirejs-text": "~2.0.12",
"requirejs-domready": "~2.0.1",
"bootstrap-sass-official": "~3.1.0",
"restangular": "~1.4.0",
"angular-ui-router": "~0.2.10",
Expand All @@ -24,7 +23,8 @@
},
"devDependencies": {
"angular-mocks": "1.2.15",
"angular-scenario": "1.2.15"
"angular-scenario": "1.2.15",
"almond": "~0.3.0"
},
"resolutions": {
"angular": "~1.2.16"
Expand Down
28 changes: 13 additions & 15 deletions grunt/grunt-requirejs.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,27 @@
"generateSourceMaps": true,
"skipDirOptimize": true,
"removeCombined": true,

"mainConfigFile": [
"src/scripts/common.js",
"src/scripts/ng-admin.js"
]
"mainConfigFile": "src/scripts/app.js"
}
},
"prod": {
"options": {
"appDir": "src/scripts",
"fileExclusionRegExp": "^(build)",
"baseUrl": "./",
"dir": "src/require",
"optimize": "uglify2",
"baseUrl": "src/scripts",
"mainConfigFile": "src/scripts/app.js",
"include": ["app"],
"name": "bower_components/almond/almond",
"out": "./src/build/ng-admin.min.js",

"optimize": "none",
"preserveLicenseComments": false,
"findNestedDependencies": true,
"generateSourceMaps": false,
"skipDirOptimize": true,
"removeCombined": true,

"mainConfigFile": [
"src/scripts/common.js",
"src/scripts/ng-admin.js"
]
"wrap": {
"startFile": "build/start.frag",
"endFile": "build/end.frag"
}
}
}
}
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,19 @@
"requirejs": "~2.1.14"
},
"devDependencies": {
"grunt-contrib-clean": "^0.6.0",
"grunt-contrib-watch": "~0.5.2",
"grunt-karma": "^0.8.3",
"grunt-ng-annotate": "^0.3.2",
"jshint-stylish": "~0.1.3",
"karma": "~0.12.14",
"karma-chrome-launcher": "^0.1.4",
"karma-jasmine": "~0.1.5",
"karma-ng-html2js-preprocessor": "~0.1.0",
"karma-ng-scenario": "~0.1.0",
"karma-phantomjs-launcher": "^0.1.4",
"karma-requirejs": "~0.2.2"
"karma-requirejs": "~0.2.2",
"grunt-contrib-uglify": "~0.6.0"
},
"engines": {
"node": ">=0.10.0"
Expand Down
3 changes: 3 additions & 0 deletions sass/screen.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ $icon-font-path: "/scripts/bower_components/bootstrap-sass-official/vendor/asset
// bower:scss
@import "../src/scripts/bower_components/bootstrap-sass-official/vendor/assets/stylesheets/bootstrap.scss";
@import "/scripts/bower_components/nprogress/nprogress.css";
@import "/scripts/bower_components/fontawesome/css/font-awesome.css";
@import "/scripts/bower_components/humane/themes/flatty.css";
@import "/scripts/bower_components/bootstrap/dist/css/bootstrap.css";
// endbower

@import "sb-admin.scss";
Expand Down
12 changes: 4 additions & 8 deletions src/index.html
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
<!doctype html>
<html class="no-js">
<html>
<head>
<meta charset="utf-8">
<title>Angular admin</title>
<meta name="viewport" content="width=device-width">

<link rel="stylesheet" href="scripts/bower_components/bootstrap/dist/css/bootstrap.css" />
<link rel="stylesheet" href="scripts/bower_components/fontawesome/css/font-awesome.css" />
<link rel="stylesheet" href="scripts/bower_components/humane/themes/flatty.css" />

<link rel="stylesheet" href="css/screen.css">

<script data-main="scripts/app" src="scripts/bower_components/requirejs/require.js"></script>
<script src="build/ng-admin.min.js" type="text/javascript"></script>
<script src="scripts/config.js" type="text/javascript"></script>
</head>
<body>
<body ng-app="myApp">
<div ui-view></div>
<div id="loader"></div>
</body>
</html>
66 changes: 54 additions & 12 deletions src/scripts/app.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,61 @@
require.config({
waitSeconds: 30
paths: {
'angular': 'bower_components/angular/angular',
'angular-resource': 'bower_components/angular-resource/angular-resource',
'angular-sanitize': 'bower_components/angular-sanitize/angular-sanitize',
'angular-route': 'bower_components/angular-route/angular-route',
'angular-ui-router': 'bower_components/angular-ui-router/release/angular-ui-router',
'lodash': 'bower_components/lodash/dist/lodash.min',
'text' : 'bower_components/requirejs-text/text',
'angular-bootstrap': 'bower_components/angular-bootstrap/ui-bootstrap.min',
'angular-bootstrap-tpls': 'bower_components/angular-bootstrap/ui-bootstrap-tpls.min',
'restangular': 'bower_components/restangular/dist/restangular',
'humane': 'bower_components/humane/humane',
'nprogress': 'bower_components/nprogress/nprogress',

'MainModule': 'app/Main/MainModule',
'CrudModule': 'app/Crud/CrudModule'
},
shim: {
'angular': {
exports: 'angular'
},
'restangular': {
deps: ['angular', 'lodash']
},
'angular-ui-router': {
deps: ['angular']
},
'angular-bootstrap': {
deps: ['angular']
},
'angular-bootstrap-tpls': {
deps: ['angular', 'angular-bootstrap']
},
'jquery': {
exports: '$'
},
'angular-resource': {
deps: ['angular']
},
'angular-sanitize': {
deps: ['angular']
},
'angular-route': {
deps: ['angular']
},
'nprogress': {
exports: 'NProgress'
}
}
});

require(['common', 'ng-admin'], function () {
define(function(require) {
"use strict";

require(['angular', 'MainModule', 'CrudModule'], function (angular) {

angular.module('ng-admin', ['main', 'crud']);

// we add the ng-app attribute for pure debugging purposes
// historically, it was needed in case angular scenario was used for e2e tests
document.body.setAttribute('ng-app', 'ng-admin');
var angular = require('angular');
require('MainModule');
require('CrudModule');

// async resource download implies async angular app bootstrap
angular.bootstrap(document.body, ['ng-admin']);
});
angular.module('ng-admin', ['main', 'crud']);
});
89 changes: 36 additions & 53 deletions src/scripts/app/Crud/CrudModule.js
Original file line number Diff line number Diff line change
@@ -1,68 +1,51 @@
define(
[
'angular',
'config',
define(function (require) {
"use strict";

'app/Crud/component/controller/ListController',
'app/Crud/component/controller/FormController',
'app/Crud/component/controller/DeleteController',
var angular = require('angular'),
ListController = require('app/Crud/component/controller/ListController'),
FormController = require('app/Crud/component/controller/FormController'),
DeleteController = require('app/Crud/component/controller/DeleteController'),

'app/Crud/component/directive/InfinitePagination',
InfinitePagination = require('app/Crud/component/directive/InfinitePagination'),

'app/Crud/component/service/CrudManager',
CrudManager = require('app/Crud/component/service/CrudManager'),

'app/Crud/config/routing',
routing = require('app/Crud/config/routing');

'angular-ui-router', 'angular-sanitize', 'angular-bootstrap-tpls'
],
function (
angular,
config,
require('angular-ui-router');
require('angular-sanitize');
require('angular-bootstrap-tpls');

ListController,
FormController,
DeleteController,
var CrudModule = angular.module('crud', ['ui.router', 'ui.bootstrap', 'ngSanitize']);

InfinitePagination,
CrudModule.controller('ListController', ListController);
CrudModule.controller('FormController', FormController);
CrudModule.controller('DeleteController', DeleteController);

CrudManager,
CrudModule.service('CrudManager', CrudManager);

routing
) {
"use strict";
CrudModule.directive('infinitePagination', InfinitePagination);

var CrudModule = angular.module('crud', ['ui.router', 'ui.bootstrap', 'ngSanitize']);
CrudModule.constant('config', config);
/**
* Date Picker patch
* https://github.com/angular-ui/bootstrap/commit/42cc3f269bae020ba17b4dcceb4e5afaf671d49b
*/
CrudModule.config(function($provide){
$provide.decorator('dateParser', function($delegate){

CrudModule.controller('ListController', ListController);
CrudModule.controller('FormController', FormController);
CrudModule.controller('DeleteController', DeleteController);
var oldParse = $delegate.parse;
$delegate.parse = function(input, format) {
if ( !angular.isString(input) || !format ) {
return input;
}
return oldParse.apply(this, arguments);
};

CrudModule.service('CrudManager', CrudManager);

CrudModule.directive('infinitePagination', InfinitePagination);

/**
* Date Picker patch
* https://github.com/angular-ui/bootstrap/commit/42cc3f269bae020ba17b4dcceb4e5afaf671d49b
*/
CrudModule.config(function($provide){
$provide.decorator('dateParser', function($delegate){

var oldParse = $delegate.parse;
$delegate.parse = function(input, format) {
if ( !angular.isString(input) || !format ) {
return input;
}
return oldParse.apply(this, arguments);
};

return $delegate;
});
return $delegate;
});
});

CrudModule.config(routing);
CrudModule.config(routing);

return CrudModule;
}
);
return CrudModule;
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
define([], function() {
define(function() {
'use strict';

var DeleteController = function($scope, $location, CrudManager, params) {
Expand Down
8 changes: 4 additions & 4 deletions src/scripts/app/Crud/component/controller/FormController.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
define([
'humane',
'nprogress'
], function(humane, NProgress) {
define(function() {
'use strict';

var humane = require('humane'),
NProgress = require('nprogress');

var FormController = function($scope, $location, $filter, CrudManager, Validator, data) {
var isNew = typeof(data.entityId) === 'undefined';
this.$scope = $scope;
Expand Down
6 changes: 3 additions & 3 deletions src/scripts/app/Crud/component/controller/ListController.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
define([
'nprogress'
], function(NProgress) {
define(function(require) {
'use strict';

var NProgress = require('nprogress');

var ListController = function($scope, $location, $anchorScroll, data, CrudManager) {
this.$scope = $scope;
this.$location = $location;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
define([
'angular'
], function(angular) {
define(function(require) {
'use strict';

var angular = require('angular');

function InfinitePagination($window, $document) {
return {
link:function (scope, element, attrs) {
Expand Down
Loading

0 comments on commit b0969a6

Please sign in to comment.