Skip to content

Commit

Permalink
oasp#80: Multiple configuration adaptions enabling development with T…
Browse files Browse the repository at this point in the history
…ypeScript
  • Loading branch information
maybeec committed Dec 8, 2015
1 parent e8093fe commit 6bebfe1
Show file tree
Hide file tree
Showing 21 changed files with 604 additions and 345 deletions.
37 changes: 37 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"rules": {
"quotes": [
2,
"single"
],
"semi": [
2,
"always"
],
"strict": 2
},
"env": {
"browser": true,
"node": true,
"es6": true
},
"ecmaFeatures": {
"modules": true
},
"globals": {
"angular": true,
// Angular Mocks
"inject": false,
// JASMINE
"describe": false,
"it": false,
"before": false,
"beforeEach": false,
"after": false,
"afterEach": false,
"expect": false,
"jasmine": false,
"spyOn": false
},
"extends": "eslint:recommended"
}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ java/target
.sonar
*.bak
docs/
typings/
.vscode/
tsd.json
165 changes: 1 addition & 164 deletions gulp/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,171 +30,8 @@ gulp.task('build:ci', gulpsync.sync(['test', 'build:dist']));

gulp.task('build:dist', ['env:prod', 'build']);

gulp.task('build', ['indexHtml', 'styles', 'img', 'fonts', 'i18n', 'html']);
gulp.task('build', ['indexHtml', 'scripts', 'styles', 'img', 'fonts', 'i18n', 'html']);

gulp.task('clean', function (done) {
return $.del(config.outputs(), done);
});
/** ======================================== styles ======================================== **/
gulp.task('styles', function () {
return gulp.src(config.styles.src())
.pipe($.concat(config.styles.output()))
.pipe($.less({
paths: config.styles.includePaths()
}))
.pipe($.plumber())
.pipe(gulp.dest(config.paths.tmp))
.pipe($.size());
});

gulp.task('style:copy', function () {
return gulp.src(config.styles.allSrc(), { base: config.paths.src})
.pipe(gulp.dest(config.output()))
.pipe($.size());
});

/** ======================================== indexHtml ======================================== **/
gulp.task('indexHtml', gulpsync.sync([
['styles', 'img:sprite', 'ngTemplates'],
'indexHtml:html'
]));

//only build index.html without dependencies
gulp.task('indexHtml:html', function () {
return gulp.src(config.indexHtml.src())
//TODO fix it
.pipe($.wiredep.stream({
directory: 'bower_components',
exclude: ['bootstrap.js']
}))
.pipe($.inject(gulp.src(config.scripts.src(), {read: false}), {
addRootSlash: false,
ignorePath: [config.paths.src, config.paths.tmp]
}))
.pipe($.inject(gulp.src(config.styles.injects(), {read: false}), {
addRootSlash: false,
ignorePath: [config.paths.src, config.paths.tmp, config.paths.dist]
}))
.pipe($.processhtml({commentMarker: 'process',
recursive: true,
includeBase: config.paths.src}))
.pipe($.if(isBuildForProd(), $.usemin({
path: '{' + config.paths.tmp + ',' + config.paths.src + '}',
css: [$.minifyCss(), 'concat', $.rev()],
jsModernizr: [$.ngAnnotate(), $.uglify({preserveComments: $.uglifySaveLicense}), $.rev()],
jsVendor: [$.ngAnnotate(), $.uglify({preserveComments: $.uglifySaveLicense}), $.rev()],
jsApp: [$.ngAnnotate(), $.uglify({preserveComments: $.uglifySaveLicense}), $.rev()]
})))
.pipe(gulp.dest(config.output()))
.pipe($.size());
});

/** ======================================== img ======================================== **/
gulp.task('img', ['img:sprite', 'img:copy']);

gulp.task('img:sprite', function () {
return gulp.src(config.img.sprite.src())
.pipe($.spritesmith({
imgName: config.img.sprite.output.img(),
cssName: config.img.sprite.output.css()
}))
.pipe(gulp.dest(config.paths.tmp))
.pipe($.size());
});

gulp.task('img:sprite:copy', ['img:sprite'], function (done) {
if (isBuildForProd()) {
return gulp.src(config.paths.tmp + '/' + config.img.sprite.output.img(), {base: config.paths.tmp})
.pipe($.imagemin({
optimizationLevel: 3,
progressive: true,
interlaced: true
}))
.pipe(gulp.dest(config.output()))
.pipe($.size());
} else {
done();
}
});

gulp.task('img:copy', ['img:sprite:copy'], function (done) {
if (isBuildForProd()) {
return gulp.src(config.img.src(), {base: config.paths.src})
.pipe($.imagemin({
optimizationLevel: 3,
progressive: true,
interlaced: true
}))
.pipe(gulp.dest(config.output()))
.pipe($.size());
} else {
done();
}
});

/** ======================================== fonts ======================================== **/
gulp.task('fonts', function (done) {
//TODO check font awesome
if (isBuildForProd()) {
return gulp.src('bower_components/**/*.{eot,svg,ttf,woff,woff2}')
.pipe($.flatten())
.pipe(gulp.dest(config.output() + '/fonts/'));
} else {
done();
}
});

/** ======================================== i18n ======================================== **/
gulp.task('i18n', function (done) {
if (isBuildForProd()) {
return gulp.src(config.i18n.src(), {base: config.paths.src})
.pipe(gulp.dest(config.output()));
} else {
done();
}
});

/** ======================================== html ======================================== **/
gulp.task('html', function () {
return gulp.src(config.html.src(), { base: config.paths.src })
.pipe($.newer(config.paths.tmp))
.pipe($.processhtml({commentMarker: 'process',
recursive: true,
includeBase: config.paths.src}))
.pipe($.if(isBuildForProd(), $.minifyHtml({
empty: true,
spare: true,
quotes: true
})))
.pipe(gulp.dest(config.output()))
.pipe($.size());
});

/** ======================================== ng-templates ======================================== **/
var ngTemplatesTasks = [];
gulp.task('ngTemplates', gulpsync.sync(['ngTemplatesTasksGeneration', 'ngTemplatesTasksExecution']));
gulp.task('ngTemplatesTasksExecution', ngTemplatesTasks);
gulp.task('ngTemplatesTasksGeneration', function () {
config.ngTemplates.conf().forEach(function (ngTemplatesItemConf) {
ngTemplatesTasks.push('ngTemplates[' + ngTemplatesItemConf.file + ']');
gulp.task('ngTemplates[' + ngTemplatesItemConf.file + ']', function () {
return gulp.src(ngTemplatesItemConf.src)
.pipe($.processhtml({commentMarker: 'process',
recursive: true,
includeBase: config.paths.src}))
.pipe($.minifyHtml({
empty: true,
spare: true,
quotes: true
}))
.pipe($.ngTemplates({
module: ngTemplatesItemConf.module,
path: function (path, base) {
return path.replace(base, ngTemplatesItemConf.moduleDir + '/').replace('.tpl.html', '.html');
}
}))
.pipe($.concat(ngTemplatesItemConf.file))
.pipe(gulp.dest(config.paths.tmp));
});
});
});
111 changes: 51 additions & 60 deletions gulp/lib/config-factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,68 +37,81 @@ var configFactory = function (externalConfig) {
return [pathsBuilder.build('{src}/index.html')];
}
},
styles: {
/** include only root files*/
i18n: {
src: function () {
return pathsBuilder.build('{src}/*.' + externalConfig.styles.type);
},
/** include all*/
allSrc: function () {
return pathsBuilder.build('{src}/**/*.' + externalConfig.styles.type);
},
output: function () {
return externalConfig.styles.output;
},
injects: function () {
return [pathsBuilder.build('{tmp}/**/*.css'), pathsBuilder.build('{src}/**/*.css')];
},
includePaths: function () {
return [
externalConfig.paths.src,
bowerConfig.directory
];
return _.flatten([
pathsBuilder.build('{src}/**/i18n/**/*.json')
]);
}
},
scripts: {
html: {
src: function () {
return _.flatten([
pathsBuilder.build('{src}/*.module.js'),
pathsBuilder.buildForTopLevelModules(
'{src}/{moduleFile}', '{src}/{moduleDir}/**/*.module.js', '{src}/{moduleDir}/**/!(*spec|*mock).js', '{tmp}/{moduleDir}/**/*.js')
pathsBuilder.build('{src}/**/*.html'),
pathsBuilder.build('!{src}/index.html'),
pathsBuilder.build('!{src}/**/*.tpl.html')
]);
}
},
scripts: {
src: function () {
return pathsBuilder.build('{src}/*.module.ts');
},
testSrc: function () {
return _.flatten([
pathsBuilder.build('{testSrc}/*.mock.js'),
pathsBuilder.buildForTopLevelModules(
'{testSrc}/{moduleDir}/**/*.mock.js'
),
pathsBuilder.build('{testSrc}/*.spec.js'),
pathsBuilder.buildForTopLevelModules(
'{testSrc}/{moduleDir}/**/*.spec.js'
)
//load main spec to guarantee angular-mock loading
pathsBuilder.build('{testSrc}/app.spec.ts'),
pathsBuilder.build('{src}/*.module.ts'),
pathsBuilder.build('{testSrc}/*.mock.ts'),
pathsBuilder.build('{testSrc}/**/*.mock.ts'),
pathsBuilder.build('{testSrc}/*.spec.ts'),
pathsBuilder.build('{testSrc}/**/*.spec.ts')
]);
},
lintSrc: function () {
return _.flatten([
pathsBuilder.build('{src}/*.module.js'),
pathsBuilder.buildForTopLevelModules(
'{src}/{moduleFile}', '{src}/{moduleDir}/**/*.module.js', '{src}/{moduleDir}/**/!(*spec|*mock).js')
pathsBuilder.build('{src}/*.module.ts'),
pathsBuilder.build('{src}/**/*.ts')
]);
}
},
i18n: {
ngTemplates: {
src: function () {
return pathsBuilder.buildForTopLevelModules('{src}/{moduleDir}/i18n/**/*.json');
return pathsBuilder.build('{src}/**/*.tpl.html');
},
targetModule: function () {
return 'ng';
},
target: function () {
return pathsBuilder.build('app/app.templates.js');
}
},
styles: {
/** include only root files*/
src: function () {
return pathsBuilder.build('{src}/*.' + externalConfig.styles.type);
},
/** include all*/
allSrc: function () {
return pathsBuilder.build('{src}/**/*.' + externalConfig.styles.type);
},
output: function () {
return externalConfig.styles.output;
},
includePaths: function () {
return [
externalConfig.paths.src,
externalConfig.paths.tmp
];
}
},
img: {
src: function () {
return pathsBuilder.buildForTopLevelModules('{src}/{moduleDir}/**/img/**/*.*', '!{src}/{moduleDir}/**/img/sprite/**');
return [pathsBuilder.build('{src}/**/img/**/*.*'), pathsBuilder.build('!{src}/**/img/sprite/**/*.*')];
},
sprite: {
src: function () {
return pathsBuilder.buildForTopLevelModules('{src}/{moduleDir}/**/img/sprite/**/*.png');
return pathsBuilder.build('{src}/**/img/sprite/**/*.png');
},
output: {
css: function () {
Expand All @@ -109,28 +122,6 @@ var configFactory = function (externalConfig) {
}
}
}
},
html: {
src: function () {
return pathsBuilder.buildForTopLevelModules(
'{src}/{moduleDir}/**/*.html',
'!{src}/{moduleDir}/**/*.tpl.html'
);
}
},
ngTemplates: {
conf: function () {
return pathsBuilder.visitTopLevelModules(function (module) {
if (module.ngModule) {
return {
module: module.ngModule + '.templates',
moduleDir: module.moduleDir,
file: pathsBuilder.build('{moduleDir}/{module}.templates.js', module),
src: pathsBuilder.build('{src}/{moduleDir}/**/*.tpl.html', module)
};
}
});
}
}
};
};
Expand Down
2 changes: 1 addition & 1 deletion gulp/lib/module-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module.exports = {
moduleAbsDir: joinFn(basePath, moduleDirectory)
};
if (fs.existsSync(paths.join(basePath, module.moduleFile))) {
module.ngModule = ngParseModule.parse(paths.join(basePath, module.moduleFile)).name;
module.ngModule = 'app';//ngParseModule.parse(paths.join(basePath, module.moduleFile)).name;
}
modules.push(module);
}
Expand Down
14 changes: 14 additions & 0 deletions gulp/parts/fonts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*global config, isBuildForProd, $*/
'use strict';
var gulp = require('gulp');

gulp.task('fonts', function (done) {
//TODO check font awesome
if (isBuildForProd()) {
return gulp.src('bower_components/**/*.{eot,svg,ttf,woff,woff2}')
.pipe($.flatten())
.pipe(gulp.dest(config.output() + '/fonts/'));
} else {
done();
}
});
Loading

0 comments on commit 6bebfe1

Please sign in to comment.