Skip to content

Commit c664505

Browse files
committed
Update to angular 2.3.1
1 parent 837027d commit c664505

File tree

5 files changed

+239
-108
lines changed

5 files changed

+239
-108
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,6 @@ build/Release
2626
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
2727
node_modules
2828
/dist
29+
/.vscode
30+
/.idea
31+
/*.iml

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ node_js:
33
- "0.12"
44
before_script:
55
- npm install -g gulp
6-
script: gulp
6+
script: npm prepublish

gulpfile.js

Lines changed: 212 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,229 @@
11
'use strict';
22
var gulp = require('gulp');
3-
var tscConfig = require('./src/tsconfig.json');
4-
var mxtBuilder = require("@maxxton/gulp-builder");
3+
var gutil = require('gulp-util');
4+
var htmlExtender = require('gulp-html-extend');
5+
var rimraf = require('gulp-rimraf');
6+
var typescript = require('gulp-typescript');
7+
var async = require('async');
8+
var merge = require('merge2');
9+
var replace = require('gulp-replace');
10+
var fs = require('fs');
11+
var Gaze = require('gaze').Gaze;
12+
var mocha = require('gulp-mocha');
13+
var tsConfig = require('./src/tsconfig.json');
514

6-
mxtBuilder.setSettings({
15+
var settings = {
716
distFolder: 'dist',
817
projectName: 'angular2-rest',
9-
tsConfig: tscConfig
10-
});
18+
tsConfig: tsConfig
19+
};
1120

1221
gulp.task('default', ['prepublish'], function (cb) {
13-
mxtBuilder.watch(cb);
22+
watch(cb);
1423
});
1524

16-
// TEMPORARY SOLUTION FOR LINKING NPM MODULES TO DEVELOPMENT
17-
gulp.task('link', function (cb) {
18-
mxtBuilder.link(cb);
25+
gulp.task('test', function (cb) {
26+
test(cb);
1927
});
2028

21-
gulp.task('lint', function (cb) {
22-
mxtBuilder.lint(cb);
29+
gulp.task('prepublish', function (cb) {
30+
prepublish(cb);
2331
});
2432

25-
gulp.task('bundle-javascript', function (cb) {
26-
mxtBuilder.bundleJavascript(cb);
27-
});
33+
// ------------------- TASKS ---------------------
2834

29-
gulp.task('test', function (cb) {
30-
mxtBuilder.test(cb);
31-
});
35+
function prepublish(cb) {
36+
async.series([
37+
function (next) {
38+
_clean(next);
39+
},
40+
function (next) {
41+
_build(next);
42+
},
43+
function (next) {
44+
_prepublishPackage(next);
45+
}
46+
], cb);
47+
};
48+
49+
function _clean(cb) {
50+
gulp.src(settings.distFolder, { read: false })
51+
.pipe(rimraf())
52+
.on('finish', function () {
53+
cb();
54+
});
55+
}
56+
57+
function _build(cb) {
58+
async.series([
59+
function (next) {
60+
_deployMisc(next);
61+
},
62+
function (next) {
63+
_compileTypescript(next);
64+
}
65+
], cb);
66+
}
67+
68+
function _deployMisc(cb) {
69+
gutil.log('Starting ', gutil.colors.cyan('_deployMisc'));
70+
gulp.src(['src/test/*.js']).pipe(gulp.dest(settings.distFolder + '/test'));
71+
72+
gulp.src(['package.json', 'LICENSE', 'README.md', 'src/systemjs.config.js', 'src/build.js'])
73+
.pipe(htmlExtender({ annotations: false, verbose: false }))
74+
.pipe(gulp.dest(settings.distFolder))
75+
.on('finish', function () {
76+
gutil.log('Finished ', gutil.colors.cyan('_deployMisc'));
77+
cb();
78+
});
79+
80+
}
81+
82+
function _compileTypescript(cb) {
83+
_compileTypescriptFromSrc(['src/**/*.ts', '!src/**/*spec.ts', '!src/config/**/*.ts'], cb);
84+
}
85+
86+
function watch(cb) {
87+
gutil.log('Starting ', gutil.colors.cyan('_watch'));
88+
_watchTypescript();
89+
gulp.watch(['package.json', 'LICENSE', 'README.md', 'src/test/*.js'], ['_deployMisc']);
90+
gulp.watch(['src/**/*.spec.ts'], ['_compileSpecs']);
91+
gulp.watch(['src/**/*e2e*.ts'], ['_compileE2e']);
92+
gutil.log(gutil.colors.cyan('Watchers started'));
93+
cb();
94+
}
95+
96+
function _watchTypescript() {
97+
gutil.log('Watching', gutil.colors.cyan('Typescript'));
98+
var gaze = new Gaze(['src/**/*.ts', 'src/**/*.html', '!src/**/*spec.ts']);
99+
gaze.on('all', function (event, filepath) {
100+
_compileChangedTypescript(event, filepath);
101+
});
102+
gaze.on('error', function (error) {
103+
gaze.close();
104+
gutil.log('error occured during', gutil.colors.cyan('typescript'), 'watch. Compiling and re-watching', gutil.colors.cyan('typescript'), 'in a few seconds...');
105+
setTimeout(function () {
106+
_compileTypescript(function () {
107+
_watchTypescript();
108+
});
109+
}, 3000);
110+
});
111+
}
112+
113+
function _compileChangedTypescript(event, src) {
114+
if (event == 'changed') {
115+
src = src.substring(src.lastIndexOf("/"));
116+
src = src.substring(src.lastIndexOf("\\"));
117+
118+
_compileTypescriptFromSrc(["src/**" + src], function () {
119+
}, true);
120+
}
121+
else if (event == 'added') {
122+
_compileTypescript(function () {
123+
});
124+
}
125+
else if (event == 'deleted') {
126+
var jsDistFileLoc = src.replace("\\src\\", '\\' + settings.distFolder + '\\').replace('.ts', '.js');
127+
var dTsDistFileLoc = src.replace("\\src\\", '\\' + settings.distFolder + '\\').replace('.ts', '.d.ts');
128+
gutil.log("Deleting", gutil.colors.magenta(jsDistFileLoc));
129+
return gulp.src([jsDistFileLoc, dTsDistFileLoc], {read: false})
130+
.pipe(rimraf());
131+
}
132+
}
133+
134+
function _compileTypescriptFromSrc(srcArray, cb) {
135+
gutil.log("Starting", gutil.colors.cyan('_compileTypescriptFromSrc'), "for file(s)", gutil.colors.magenta(srcArray));
136+
137+
var compilerOptions = Object.assign({}, settings.tsConfig.compilerOptions);
138+
139+
//if we changed 1 file its not needed to compile the whole source code
140+
if (srcArray.length == 1 && srcArray[0].slice(-2) == "ts") {
141+
compilerOptions['isolatedModules'] = true;
142+
}
143+
144+
var tsProject = typescript.createProject(compilerOptions);
145+
var tsResult = gulp.src(srcArray)
146+
.pipe(tsProject());
147+
merge([
148+
tsResult.dts.pipe(gulp.dest(settings.distFolder)),
149+
tsResult.js.pipe(gulp.dest(settings.distFolder))
150+
]).on('finish', function () {
151+
gutil.log('Finished ', gutil.colors.cyan('_compileTypescriptFromSrc'));
152+
cb();
153+
});
154+
}
32155

33156
/**
34-
* Cleans, moves, and compiles the code
157+
* Copy part of the package.json to the dist folder for publishing.
35158
*/
36-
gulp.task('prepublish', function (cb) {
37-
mxtBuilder.prepublish(cb);
38-
});
159+
function _prepublishPackage(cb) {
160+
var json = JSON.parse(fs.readFileSync('./package.json'));
161+
var publishJson = {
162+
name: json.name,
163+
version: json.version,
164+
description: json.description,
165+
typings: json.typings,
166+
main: json.main,
167+
repository: json.repository,
168+
keywords: json.keywords,
169+
author: json.author,
170+
license: json.license,
171+
bugs: json.bugs,
172+
homepage: json.homepage,
173+
publishConfig: json.publishConfig,
174+
dependencies: json.dependencies
175+
};
176+
177+
var src = require('stream').Readable({ objectMode: true });
178+
src._read = function () {
179+
this.push(new gutil.File({
180+
cwd: "",
181+
base: "",
182+
path: "package.json",
183+
contents: new Buffer(JSON.stringify(publishJson, null, 2))
184+
}));
185+
this.push(null)
186+
};
187+
src.pipe(gulp.dest(settings.distFolder + '/'))
188+
.on('finish', function () {
189+
cb();
190+
});
191+
}
192+
193+
function test(cb) {
194+
async.series([
195+
function (next) {
196+
_clean(next);
197+
},
198+
function (next) {
199+
_buildDeploy(next);
200+
},
201+
function (next) {
202+
_compileSpecs(next);
203+
},
204+
function (next) {
205+
_runMocha(next);
206+
}
207+
], cb);
208+
};
209+
210+
function _buildDeploy(cb) {
211+
async.series([
212+
function (next) {
213+
_deployMisc(next);
214+
},
215+
function (next) {
216+
_compileTypescript(next);
217+
}
218+
], cb);
219+
}
220+
221+
function _compileSpecs(cb) {
222+
_compileTypescriptFromSrc(['src/**/*.spec.ts'], cb);
223+
}
224+
225+
function _runMocha(cb) {
226+
return gulp.src(['dist/**/*.spec.js'], { read: false })
227+
.pipe(mocha({ reporter: 'list' }))
228+
.on('error', gutil.log);
229+
}

package.json

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
"name": "@maxxton/angular2-rest",
33
"version": "1.0.0",
44
"description": "Angular2 HTTP client to consume RESTful services.",
5-
"typings": "./angular2-rest.d.ts",
6-
"main": "angular2-rest.js",
5+
"typings": "index.d.ts",
6+
"main": "index.js",
77
"scripts": {
88
"test": "node_modules/.bin/gulp test",
9-
"gulp": "node_modules/.bin/gulp"
9+
"watch": "node_modules/.bin/gulp default",
10+
"prepublish": "node_modules/.bin/gulp prepublish"
1011
},
1112
"repository": {
1213
"type": "git",
@@ -19,24 +20,31 @@
1920
"rest",
2021
"client"
2122
],
22-
"author": "Domonkos Pal <Paldom>",
23+
"author": "Steven Hermans <s.hermans@maxxton.com>",
2324
"license": "MIT",
2425
"bugs": {
25-
"url": "https://github.com/Paldom/angular2-rest/issues"
26+
"url": "https://github.com/MaxxtonGroup/angular2-rest/issues"
2627
},
27-
"homepage": "https://github.com/Paldom/angular2-rest#readme",
28+
"homepage": "https://github.com/MaxxtonGroup/angular2-rest#readme",
2829
"dependencies": {
29-
"@angular/common": "2.0.0-rc.4",
30-
"@angular/compiler": "2.0.0-rc.4",
31-
"@angular/core": "2.0.0-rc.4",
32-
"@angular/http": "2.0.0-rc.4",
33-
"@angular/platform-browser": "2.0.0-rc.4",
34-
"reflect-metadata": "0.1.3",
35-
"rxjs": "5.0.0-beta.6",
36-
"zone.js": "0.6.12"
30+
"@angular/core": "2.3.1",
31+
"@angular/http": "2.3.1",
32+
"reflect-metadata": "^0.1.8",
33+
"rxjs": "5.0.2",
34+
"zone.js": "^0.7.2"
3735
},
3836
"devDependencies": {
3937
"gulp": "^3.9.0",
40-
"@maxxton/gulp-builder": "1.3.16"
38+
"gulp-util": "^3.0.7",
39+
"gulp-html-extend": "^1.1.6",
40+
"gulp-typescript": "3.1.3",
41+
"gulp-replace": "^0.5.4",
42+
"gulp-mocha": "^3.0.1",
43+
"gulp-rimraf": "^0.2.0",
44+
"async": "^2.0.1",
45+
"merge2": "^1.0.2",
46+
"gaze": "^1.1.2",
47+
"chai": "^3.5.0",
48+
"typings": "^2.0.0"
4149
}
4250
}

tslint.json

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

0 commit comments

Comments
 (0)