Skip to content

Commit

Permalink
Ported it from DataClient
Browse files Browse the repository at this point in the history
  • Loading branch information
thehoneymad committed Feb 15, 2017
1 parent 7d60bf7 commit cb7d51f
Show file tree
Hide file tree
Showing 199 changed files with 4,378 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ jspm_packages
.npm

# Optional REPL history
.node_repl_history
.node_repl_history
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2017 NerdCats
Copyright (c) 2016 NerdCats

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
36 changes: 36 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# AppVeyor file
# http://www.appveyor.com/docs/appveyor-yml
# This file: cloned from https://github.com/gruntjs/grunt/blob/master/appveyor.yml

# Build version format
version: "{build}"

# Test against this version of Node.js
environment:
nodejs_version: "5.5.0"

build: off

clone_depth: 10

# Fix line endings on Windows
init:
- git config --global core.autocrlf true

install:
- ps: Install-Product node $env:nodejs_version
- npm install -g npm
- ps: $env:path = $env:appdata + "\npm;" + $env:path
- npm install

test_script:
# Output useful info for debugging.
- node --version && npm --version
- node -e 'console.log(process.env);'
# We test multiple Windows shells because of prior stdout buffering issues
# filed against Grunt. https://github.com/joyent/node/issues/3584
- ps: "npm test # PowerShell" # Pass comment to PS for easier debugging
- cmd: npm test

cache:
- node_modules -> package.json # local npm modules
16 changes: 16 additions & 0 deletions config/env/env.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* THIS FILE IS GENERATED by `gulp env` command from `env.json`
* Generated on <%= new Date() %>
*
* Make sure the keys in `env.model.ts` exist in `env.json`
* otherwise it'll throw message like this
* Property '<missing-key>' is missing in type '{}'
*
* Feel free to modify for direct updates in development
*/

import { AppEnv } from './env.model';

export const ENV: AppEnv = {<% _.forEach(env, function(v, k) { %>
<%= k %>: <%= _.isString(v) ? "\'"+v+"\'" : v %>,<% }) %>
};
121 changes: 121 additions & 0 deletions config/gulp/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
var envConfig = require('./utils/env');

module.exports = function () {
var root = '',
src = root + 'src/',
config = root + 'config/',
app = src + 'app/',
test = src + 'test/',
tmp = src + 'tmp/',
tmpApp = tmp + 'app/',
tmpTest = tmp + 'test/',
testHelper = test + 'test-helpers/',
e2e = root + 'e2e/',
assets = src + 'assets/',
assetsPath = {
styles: assets + 'styles/',
images: assets + 'images/',
fonts: assets + 'fonts/'
},
index = src + 'index.html',
tsFiles = [
app + '**/!(*.spec)+(.ts)'
],
tsTestFiles = {
unit: [app + '**/*.spec.ts'],
e2e: [e2e + '**/*.ts'],
helper: [testHelper + '**/*.ts']
},
build = {
path: 'build/',
app: 'build/app/',
fonts: 'build/fonts',
assetPath: 'build/assets/',
assets: {
lib: {
js: 'lib.js',
css: 'lib.css'
}
}
},
report = {
path: 'report/'
};

var e2eConfig = {
seleniumTarget: 'http://127.0.0.1:3000'
};

var systemJs = {
builder: {
normalize: true,
minify: true,
mangle: true,
runtime: false,
globalDefs: {
DEBUG: false,
ENV: 'production'
}
}
};

var gulpConfig = {
root: root,
config: config,
src: src,
app: app,
test: test,
tmp: tmp,
tmpApp: tmpApp,
tmpTest: tmpTest,
testHelper: testHelper,
e2e: e2e,
e2eConfig: e2eConfig,
assets: assets,
index: index,
build: build,
report: report,
assetsPath: assetsPath,
tsFiles: tsFiles,
tsTestFiles: tsTestFiles,
systemJs: systemJs
};

if (envConfig.ENV === envConfig.ENVS.DEV)
{
var historyApiFallback = require('connect-history-api-fallback');
var browserSync = {
dev: {
port: 3000,
injectChanges: false,
server: {
baseDir: './src/',
middleware: [historyApiFallback()],
routes: {
"/node_modules": "node_modules",
"/src": "src"
}
},
files: [
src + "index.html",
src + "systemjs.conf.js",
assetsPath.styles + "main.css",
tmpApp + "**/*.js",
app + "**/*.css",
app + "**/*.html"
]
},
prod: {
port: 3001,
server: {
baseDir: './' + build.path,
middleware: [historyApiFallback()]
}
}
};

gulpConfig.browserSync = browserSync;
}

return gulpConfig;
};
75 changes: 75 additions & 0 deletions config/gulp/tasks/build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
var gulp = require('gulp');
var util = require('gulp-util');
var runSequence = require('run-sequence');
var config = require('../config')();
var useref = require('gulp-useref');
var gulpif = require('gulp-if');
var rev = require('gulp-rev');
var revReplace = require('gulp-rev-replace');
var uglify = require('gulp-uglify');
var cssnano = require('gulp-cssnano');
var gulpTemplate = require('gulp-template');
var flatten = require('gulp-flatten');

var envVars = require('../utils/env-vars');

require('@ngstarter/systemjs-extension')(config);

gulp.task('build', function (done) {
runSequence('test', 'build-systemjs', 'build-assets', done);
});

/* Concat and minify/uglify all css, js, and copy fonts */
gulp.task('build-assets', function (done) {
runSequence('clean-build', ['sass', 'fonts'], function () {
gulp.src(config.app + '**/*.html')
.pipe(flatten())
.pipe(gulp.dest(config.build.path));

gulp.src(config.app + '**/*.css')
.pipe(cssnano({zindex: false}))
.pipe(flatten())
.pipe(gulp.dest(config.build.path));

gulp.src(config.src + 'favicon.ico')
.pipe(gulp.dest(config.build.path));

gulp.src(config.assetsPath.images + '**/*.*', {
base: config.assetsPath.images
})
.pipe(gulp.dest(config.build.assetPath + 'images'));

gulp.src(config.index)
.pipe(useref())
.pipe(gulpif('assets/lib.js', uglify()))
.pipe(gulpif('*.css', cssnano()))
.pipe(gulpif('!*.html', rev()))
.pipe(revReplace())
.pipe(gulp.dest(config.build.path))
.on('finish', done);
});
});

/* Copy fonts in packages */
gulp.task('fonts', function () {
gulp.src(config.assetsPath.fonts + '**/*.*', {
base: config.assetsPath.fonts
})
.pipe(gulp.dest(config.build.fonts));

gulp.src([
'node_modules/font-awesome/fonts/*.*'
])
.pipe(gulp.dest(config.build.fonts));
});

gulp.task('env', function () {
return gulp.src(config.config + 'env/env.ts')
.pipe(gulpTemplate({
env: envVars || {}
}))
.pipe(gulp.dest(config.app + 'shared/constant'))
.on('finish', function () {
util.log(config.app + 'shared/constant/env.ts is generated successfully');
});
});
29 changes: 29 additions & 0 deletions config/gulp/tasks/clean.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
var gulp = require('gulp');
var config = require('../config')();
var del = require('del');

/* Run all clean tasks */
gulp.task('clean', ['clean-build', 'clean-report', 'clean-ts']);

/* Clean build folder */
gulp.task('clean-build', function () {
return del([config.build.path]);
});

/* Clean report folder */
gulp.task('clean-report', function () {
return del([config.report.path]);
});

/* Clean js and map */
gulp.task('clean-ts', function () {
return del([config.tmp]);
});

gulp.task('clean-ts-app', function () {
return del([config.tmpApp]);
});

gulp.task('clean-ts-test', function () {
return del([config.tmpTest]);
});
37 changes: 37 additions & 0 deletions config/gulp/tasks/component.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
var gulp = require('gulp');
var path = require('path');

var config = require('../config')();

gulp.task('html', function () {
return gulp.src(config.app + '**/*.html')
.pipe(gulp.dest(config.tmpApp));
});

gulp.task('watch-html', function () {
gulp.watch(config.app + '**/*.html', function(file) {
var des = convertToTmpPath(file);

return gulp.src(file.path)
.pipe(gulp.dest(path.dirname(des)));
});
});

gulp.task('css', function () {
return gulp.src(config.app + '**/*.css')
.pipe(gulp.dest(config.tmpApp));
});

gulp.task('watch-css', function () {
gulp.watch(config.app + '**/*.css', function(file) {
var des = convertToTmpPath(file);

return gulp.src(file.path)
.pipe(gulp.dest(path.dirname(des)));
});
});

function convertToTmpPath(file) {
var unixPath = file.path.replace(/\\/g, "/");
return unixPath.replace(/src\/app\//, config.tmpApp);
}
13 changes: 13 additions & 0 deletions config/gulp/tasks/sass.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
var gulp = require('gulp');
var sass = require('gulp-sass');
var config = require('../config')();

gulp.task('sass', function () {
return gulp.src(config.assetsPath.styles + 'main.scss')
.pipe(sass().on('error', sass.logError))
.pipe(gulp.dest(config.assetsPath.styles));
});

gulp.task('watch-sass', function () {
gulp.watch(config.assetsPath.styles + '**/*.scss', ['sass']);
});
34 changes: 34 additions & 0 deletions config/gulp/tasks/serve.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
var runSequence = require('run-sequence');

var envConfig = require('../utils/env');

if (envConfig.ENV === envConfig.ENVS.DEV)
{
var gulp = require('gulp');
var config = require('../config')();
var bs = require("browser-sync");

function startBrowsersync (config)
{
bsIns = bs.create();
bsIns.init(config);
bsIns.reload();
}

/* Start live server dev mode */
gulp.task('serve-dev', function ()
{
runSequence(
['sass', 'tsc-app'],
['html', 'css'],
['watch-sass', 'watch-ts', 'watch-html', 'watch-css'], function() {
startBrowsersync(config.browserSync.dev);
});
});

/* Start live server production mode */
gulp.task('serve-build', ['build'], function ()
{
startBrowsersync(config.browserSync.prod);
});
}
Loading

0 comments on commit cb7d51f

Please sign in to comment.