Skip to content

Commit dcf158f

Browse files
committed
chore(build): introduced Angular 1.5 component architecture
1 parent 166d94c commit dcf158f

37 files changed

Lines changed: 372 additions & 285 deletions

config.json

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,15 @@
55

66
"paths" : {
77
"scripts": [
8-
"src/+(app|common)/**/*.module.js",
9-
"src/+(app|common)/**/*.js",
10-
"!src/+(app|common)/**/*.spec.js"
8+
"src/app/**/*.module.js",
9+
"src/app/**/*.js",
10+
"!src/app/**/*.spec.js"
1111
],
12-
"templates": [
13-
"src/app/**/*.tpl.html",
14-
"src/common/**/*.tpl.html"
15-
],
16-
"sass" : "src/+(sass|app|common)/**/*.scss",
17-
"assets" : "src/assets/**",
18-
"html" : "src/index.html",
19-
"tests" : "src/+(app|common)/**/*.spec.js"
12+
"templates" : "src/app/**/*.html",
13+
"sass" : "src/+(sass|app)/**/*.scss",
14+
"assets" : "src/assets/**",
15+
"html" : "src/index.html",
16+
"tests" : "src/app/**/*.spec.js"
2017
},
2118

2219
"templateFile": "app.templates.js",

gulpfile.js

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ var gulp = require('gulp'),
55
del = require('del'),
66
minimist = require('minimist'),
77
wiredep = require('wiredep'),
8+
fsPath = require('path'),
89
plugins = require('gulp-load-plugins')(),
910
bs = require('browser-sync').create(),
1011
config = require('./config.json'),
@@ -29,27 +30,26 @@ var args = minimist(process.argv.slice(2), knownOptions);
2930

3031
var processWinPath = function (file) {
3132
// Fix for bug with paths on Windows
32-
var path = require('path');
3333
if (process.platform === 'win32') {
34-
file.path = path.relative('.', file.path);
34+
file.path = fsPath.relative('.', file.path);
3535
file.path = file.path.replace(/\\/g, '/');
3636
}
3737
};
3838

3939
// Compile SASS
4040
gulp.task('styles:sass', function () {
4141
var files = [
42-
config.app + '/+(sass|app|common)/**/*.scss',
42+
config.paths.sass,
4343
'!' + config.app + '/sass/includes/*.scss',
44-
'!' + config.app + '/+(app|common)/**/_*.scss'
44+
'!' + config.app + '/app/**/_*.scss'
4545
];
4646

4747
return gulp.src(files, { read: false })
4848
.on('data', processWinPath)
4949
.pipe(plugins.plumber())
5050
.pipe(plugins.order([
5151
config.app + '/sass/*.scss',
52-
config.app + '/+(app|common)/*/*.scss'
52+
config.app + '/app/*/*.scss'
5353
], { base: '.' }))
5454
.pipe(plugins.intercept(function (file) {
5555
file.contents = new Buffer('@import \'' + file.path + '\';');
@@ -117,14 +117,13 @@ gulp.task('wiredep', function () {
117117
// Cache AngularJS templates
118118
var fnCacheTpls = function (path) {
119119
return gulp.src(path)
120-
.pipe(plugins.minifyHtml({
121-
empty: true,
122-
spare: true,
123-
quotes: true
124-
}))
120+
.pipe(plugins.htmlmin({ collapseWhitespace: true }))
125121
.pipe(plugins.angularTemplatecache({
126-
module: 'app.templates',
127-
standalone: true
122+
root: 'app',
123+
standalone: true,
124+
transformUrl: function (url) {
125+
return url.replace(fsPath.dirname(url), '.');
126+
}
128127
}))
129128
.pipe(plugins.concat(config.templateFile))
130129
.pipe(gulp.dest(config.build + '/assets'))
@@ -158,21 +157,17 @@ gulp.task('scripts:lint', function () {
158157

159158
var fnScripts = function () {
160159
var files = [
161-
config.app + '/+(app|common)/**/*.module.js',
162-
config.app + '/+(app|common)/**/*.js',
160+
'!' + config.paths.tests,
161+
config.app + '/app/**/*.module.js',
162+
config.app + '/app/**/*.js',
163163
'!' + config.paths.tests
164164
];
165165

166166
return gulp.src(files, { base: config.app })
167167
.pipe(plugins.plumber())
168168
.pipe(plugins.sourcemaps.init())
169-
.pipe(plugins.concatUtil('app.js', {
170-
process: function (src) {
171-
return (src.trim() + '\n').replace(/(^|\n)[ \t]*('use strict'|"use strict");?\s*/g, '$1');
172-
}
173-
}))
174-
.pipe(plugins.concatUtil.header('(function (window, document, undefined) {\n\'use strict\';\n'))
175-
.pipe(plugins.concatUtil.footer('\n}) (window, document);\n'))
169+
.pipe(plugins.ngAnnotate())
170+
.pipe(plugins.concat('app.js'))
176171
.pipe(plugins.sourcemaps.write({ sourceRoot: '/' + config.app }))
177172
.pipe(plugins.size({ showFiles: true, title: '»»»' }))
178173
.pipe(gulp.dest(config.build + '/assets'))
@@ -234,11 +229,7 @@ gulp.task('html:inject', ['styles:sass', 'scripts', 'wiredep'], function () {
234229
gulp.task('html', ['optimize'], function () {
235230
return gulp.src(config.dist + '/index.html')
236231
.pipe(plugins.plumber())
237-
.pipe(plugins.minifyHtml({
238-
empty: true,
239-
spare: true,
240-
quotes: true
241-
}))
232+
.pipe(plugins.htmlmin())
242233
.pipe(gulp.dest(config.dist));
243234
});
244235

@@ -269,9 +260,8 @@ gulp.task('optimize', optimizeTasks, function () {
269260
.pipe(plugins.size({ showFiles: true, title: '»»»' }))
270261
.pipe(__filterCSS.restore)
271262
.pipe(__filterJS)
272-
.pipe(plugins.ngAnnotate())
263+
// .pipe(plugins.ngAnnotate())
273264
.pipe(plugins.uglify({
274-
mangle: false,
275265
compress: {
276266
drop_console: true
277267
}
@@ -364,7 +354,7 @@ gulp.task('watch', function () {
364354
});
365355

366356
// watch AngularJS templates to cache
367-
gulp.watch(config.app + '/+(app|common)/**/*.tpl.html', ['scripts:cacheTpls']);
357+
gulp.watch(config.paths.templates, ['scripts:cacheTpls']);
368358

369359
// watch for SASS changes
370360
gulp.watch(config.paths.sass, ['styles:sass']);

src/app/about/about.config.js

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/app/about/about.controller.js

Lines changed: 0 additions & 6 deletions
This file was deleted.

src/app/about/about.module.js

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/app/app.config.js

Lines changed: 0 additions & 41 deletions
This file was deleted.

src/app/app.controller.js

Lines changed: 0 additions & 17 deletions
This file was deleted.

src/app/app.module.js

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/app/common/common.module.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
(function () {
2+
'use strict';
3+
4+
angular.module('common', [
5+
'ui.router',
6+
'ui.bootstrap'
7+
]);
8+
9+
})();

src/app/common/conf.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
(function () {
2+
'use strict';
3+
4+
angular
5+
.module('common')
6+
.constant('conf', {
7+
api: {
8+
login : '/api/login',
9+
logout : '/api/logout',
10+
signup : '/api/signup',
11+
expiry : '/api/expiry'
12+
}
13+
})
14+
.value('eventEmitter', function (event) {
15+
// mirror Angular 2 and keep consistency inside every component
16+
return {
17+
$event: event
18+
};
19+
});
20+
21+
})();

0 commit comments

Comments
 (0)