Skip to content

Commit

Permalink
HAWKULAR-37: Adding root scripts files
Browse files Browse the repository at this point in the history
  • Loading branch information
Viliam Rockai committed Feb 27, 2015
1 parent 8b65bbe commit 1c3d396
Show file tree
Hide file tree
Showing 5 changed files with 268 additions and 17 deletions.
27 changes: 14 additions & 13 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,31 @@
"dist/hawkular-inventory.js"
],
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"libs",
"test",
"tests",
"plugins"
"*",
"!dist/",
"!dist/*"
],
"dependencies": {
"hawtio-core": "2.0.9",
"angular-bootstrap": "0.11.0",
"bootstrap-select": "1.6",
"hawkular-charts": "0.1.13",
"hawkular-ui-services": "0.1.3",
"hawtio-core-navigation": "2.0.17",
"hawtio-core": "2.0.9",
"hawtio-utilities": "2.0.16",
"hawkular-charts": "~0.1.13",
"hawkular-ui-services": "hawkular/hawkular-ui-services#master",
"d3": "3.4.8",
"event-drops": "0.1.1",
"toastr": "2.1.0",
"angular-bootstrap": "0.11.0",
"angular-ui-select": "0.9.9"
"angular-ui-select": "0.9.9",
"lodash": "2.4.1",
"moment": "2.9.0",
"toastr": "2.1.0"
},
"devDependencies": {
"bootstrap": "3.3.2",
"bootstrap-select": "1.6",
"patternfly": "1.1.3",
"angular-mocks": "1.3.7",
"angular-resource": "1.3.7",
"hawtio-core-dts": "2.0.9"
}
}
166 changes: 166 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
/*
* Copyright 2014-2015 Red Hat, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

var gulp = require('gulp'),
wiredep = require('wiredep').stream,
eventStream = require('event-stream'),
gulpLoadPlugins = require('gulp-load-plugins'),
map = require('vinyl-map'),
fs = require('fs'),
path = require('path'),
s = require('underscore.string'),
tslint = require('gulp-tslint'),
tslintRules = require('./tslint.json');

var plugins = gulpLoadPlugins({});
var pkg = require('./package.json');

var config = {
main: '.',
ts: ['plugins/**/*.ts'],
templates: ['plugins/**/*.html'],
templateModule: pkg.name + '-templates',
dist: './dist/',
rootDist: '../../dist/',
js: pkg.name + '.js',
tsProject: plugins.typescript.createProject({
target: 'ES5',
module: 'commonjs',
declarationFiles: true,
noExternalResolve: false,
removeComments: true
}),
tsLintOptions: {
rulesDirectory: './tslint-rules/'
}
};

gulp.task('bower', function() {
gulp.src('index.html')
.pipe(wiredep({}))
.pipe(gulp.dest('.'));
});

/** Adjust the reference path of any typescript-built plugin this project depends on */
gulp.task('path-adjust', function() {
gulp.src('libs/**/includes.d.ts')
.pipe(map(function(buf, filename) {
var textContent = buf.toString();
var newTextContent = textContent.replace(/"\.\.\/libs/gm, '"../../../libs');
// console.log("Filename: ", filename, " old: ", textContent, " new:", newTextContent);
return newTextContent;
}))
.pipe(gulp.dest('libs'));
});

gulp.task('clean-defs', function() {
return gulp.src('defs.d.ts', { read: false })
.pipe(plugins.clean());
});

gulp.task('tsc', ['clean-defs'], function() {
var cwd = process.cwd();
var tsResult = gulp.src(config.ts)
.pipe(plugins.typescript(config.tsProject))
.on('error', plugins.notify.onError({
message: '#{ error.message }',
title: 'Typescript compilation error'
}));

return eventStream.merge(
tsResult.js
.pipe(plugins.concat('compiled.js'))
.pipe(gulp.dest('.')),
tsResult.dts
.pipe(gulp.dest('d.ts')))
.pipe(map(function(buf, filename) {
if (!s.endsWith(filename, 'd.ts')) {
return buf;
}
var relative = path.relative(cwd, filename);
fs.appendFileSync('defs.d.ts', '/// <reference path="' + relative + '"/>\n');
return buf;
}));
});

gulp.task('tslint', function(){
gulp.src(config.ts)
.pipe(tslint(config.tsLintOptions))
.pipe(tslint.report('verbose'));
});

gulp.task('tslint-watch', function(){
gulp.src(config.ts)
.pipe(tslint(config.tsLintOptions))
.pipe(tslint.report('prose', {
emitError: false
}));
});

gulp.task('template', ['tsc'], function() {
return gulp.src(config.templates)
.pipe(plugins.angularTemplatecache({
filename: 'templates.js',
root: 'plugins/',
standalone: true,
module: config.templateModule,
templateFooter: '}]); hawtioPluginLoader.addModule("' + config.templateModule + '");'
}))
.pipe(gulp.dest('.'));
});

gulp.task('concat', ['template'], function() {
var license = tslintRules.rules['license-header'][1];

return gulp.src(['compiled.js', 'templates.js'])
.pipe(plugins.concat(config.js))
.pipe(plugins.header(license))
.pipe(gulp.dest(config.dist))
.pipe(gulp.dest(config.rootDist));
});

gulp.task('clean', ['concat'], function() {
return gulp.src(['templates.js', 'compiled.js'], { read: false })
.pipe(plugins.clean());
});

gulp.task('watch', ['build'], function() {
plugins.watch(['libs/**/*.js', 'libs/**/*.css', 'index.html', config.dist + '/' + config.js], function() {
gulp.start('reload');
});
plugins.watch(['libs/**/*.d.ts', config.ts, config.templates], function() {
gulp.start(['tslint-watch', 'tsc', 'template', 'concat', 'clean']);
});
});

gulp.task('connect', ['watch'], function() {
plugins.connect.server({
root: '.',
livereload: true,
port: 2772,
fallback: 'index.html'
});
});

gulp.task('reload', function() {
gulp.src('.')
.pipe(plugins.connect.reload());
});

gulp.task('build', ['bower', 'path-adjust', 'tslint', 'tsc', 'template', 'concat', 'clean']);

gulp.task('default', ['connect']);
12 changes: 8 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,22 @@
"private": true,
"devDependencies": {
"bower": "1.3.12",
"event-stream": "3.1.7",
"gulp": "3.8.10",
"event-stream": "3.2.1",
"gulp-angular-templatecache": "1.5.0",
"gulp-clean": "0.3.1",
"gulp-concat": "2.4.2",
"gulp-concat": "2.4.3",
"gulp-connect": "2.2.0",
"gulp-header": "1.2.2",
"gulp-load-plugins": "0.8.0",
"gulp-ng-annotate": "0.5.2",
"gulp-notify": "2.1.0",
"gulp-plumber": "0.6.6",
"gulp-size": "1.2.0",
"gulp-tslint": "1.4.3",
"gulp-typescript": "2.4.2",
"gulp-watch": "3.0.0",
"through2": "0.6.3",
"gulp": "3.8.11",
"through2": "^0.6.3",
"underscore.string": "2.4.0",
"vinyl-map": "1.0.1",
"which": "1.0.8",
Expand Down
28 changes: 28 additions & 0 deletions tslint-rules/licenseHeaderRule.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
function Rule() {
Lint.Rules.AbstractRule.apply(this, arguments);
}

Rule.prototype = Object.create(Lint.Rules.AbstractRule.prototype);
Rule.prototype.apply = function(sourceFile) {
return this.applyWithWalker(new LicenseHeaderWalker(sourceFile, this.getOptions()));
};

function LicenseHeaderWalker() {
Lint.RuleWalker.apply(this, arguments);
}

LicenseHeaderWalker.prototype = Object.create(Lint.RuleWalker.prototype);
LicenseHeaderWalker.prototype.visitSourceFile = function (node) {
// create a failure at the current position
var sourceText = this.getSourceFile().text;

var licenceHeader = this.getOptions()[0];

if ( sourceText.indexOf(licenceHeader) !== 0 ){
this.addFailure(this.createFailure(0, 0, "Missing or incorrect project license header."));
}

Lint.RuleWalker.prototype.visitSourceFile.call(this, node);
};

exports.Rule = Rule;
52 changes: 52 additions & 0 deletions tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"rules": {
"class-name": true,
"curly": true,
"eofline": true,
"forin": true,
"indent": [true, "spaces"],
"label-position": true,
"label-undefined": true,
"_max-line-length": [true, 140],
"no-arg": true,
"no-bitwise": true,
"no-console": [true,
"trace"
],
"no-construct": true,
"no-debugger": false,
"no-duplicate-key": true,
"no-duplicate-variable": true,
"no-empty": true,
"no-eval": true,
"no-string-literal": false,
"no-switch-case-fall-through": true,
"no-trailing-comma": true,
"_no-trailing-whitespace": true,
"no-unused-expression": true,
"no-unused-variable": false,
"no-unreachable": true,
"no-use-before-declare": true,
"one-line": [true,
"check-open-brace",
"check-catch",
"check-else",
"check-whitespace"
],
"_quotemark": [true, "double"],
"radix": true,
"semicolon": true,
"triple-equals": [true, "allow-null-check"],
"variable-name": false,
"whitespace": [false,
"check-branch",
"check-decl",
"check-operator",
"check-separator",
"_check-type"
],
"license-header": [ true,
"/// Copyright 2014-2015 Red Hat, Inc. and/or its affiliates\n/// and other contributors as indicated by the @author tags.\n///\n/// Licensed under the Apache License, Version 2.0 (the \"License\");\n/// you may not use this file except in compliance with the License.\n/// You may obtain a copy of the License at\n///\n/// http://www.apache.org/licenses/LICENSE-2.0\n///\n/// Unless required by applicable law or agreed to in writing, software\n/// distributed under the License is distributed on an \"AS IS\" BASIS,\n/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n/// See the License for the specific language governing permissions and\n/// limitations under the License.\n"
]
}
}

0 comments on commit 1c3d396

Please sign in to comment.