Skip to content

Commit 48627ea

Browse files
committed
build: move from angular-cli to gulp
1 parent 0b17cd3 commit 48627ea

File tree

212 files changed

+423
-298
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

212 files changed

+423
-298
lines changed

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ matrix:
5151

5252
install:
5353
- npm install
54-
- npm run typings
5554

5655
before_script:
5756
- mkdir -p $LOGS_DIR

angular-cli-build.js

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

angular-cli.json

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

gulpfile.js

Lines changed: 245 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,245 @@
1+
'use strict';
2+
/**
3+
* This file needs to be JavaScript and is read by gulp.
4+
*/
5+
// Global imports.
6+
const fs = require('fs');
7+
const gulp = require('gulp');
8+
const path = require('path');
9+
10+
// Other imports.
11+
const inlineResources = require('./scripts/release/inline-resources');
12+
13+
// Gulp plugins.
14+
const gulpClean = require('gulp-clean');
15+
const gulpTs = require('gulp-typescript');
16+
const gulpMerge = require('merge2');
17+
const gulpSass = require('gulp-sass');
18+
const gulpSourcemaps = require('gulp-sourcemaps');
19+
const gulpLiveServer = require('gulp-live-server');
20+
21+
22+
// Directories.
23+
const srcDir = path.join(__dirname, 'src');
24+
const componentsDir = path.join(srcDir, 'lib');
25+
const devAppDir = path.join(srcDir, 'demo-app');
26+
const e2eAppDir = path.join(srcDir, 'e2e-app');
27+
28+
const outDir = 'dist';
29+
const outLibDir = path.join(outDir, '@angular2-material');
30+
31+
32+
/**
33+
* Create a TS Build Task, based on the options.
34+
*/
35+
function makeTsBuildTask(options) {
36+
const tsConfigDir = options.tsConfigPath;
37+
const tsConfigPath = path.join(tsConfigDir, 'tsconfig.json');
38+
const tsConfig = JSON.parse(fs.readFileSync(tsConfigPath, 'utf-8'));
39+
const dest = path.join(tsConfigDir, tsConfig.compilerOptions.outDir);
40+
41+
return function() {
42+
const tsProject = gulpTs.createProject(tsConfigPath, {
43+
typescript: require('typescript')
44+
});
45+
46+
let pipe = tsProject.src()
47+
.pipe(gulpSourcemaps.init())
48+
.pipe(gulpTs(tsProject));
49+
let dts = pipe.dts.pipe(gulp.dest(dest));
50+
51+
if (tsConfig.compilerOptions.sourceMap) {
52+
if (!tsConfig.compilerOptions.inlineSources) {
53+
pipe = pipe.pipe(gulpSourcemaps.write(dest));
54+
} else {
55+
pipe = pipe.pipe(gulpSourcemaps.write());
56+
}
57+
}
58+
59+
return gulpMerge([dts, pipe.pipe(gulp.dest(dest))]);
60+
};
61+
}
62+
63+
/**
64+
* Create a SASS Build Task.
65+
*/
66+
function makeSassBuildTask(options) {
67+
const dest = options.dest;
68+
const glob = path.join(options.root, '**/*.scss');
69+
const sassOptions = {
70+
includePaths: options.includePaths
71+
};
72+
73+
return function() {
74+
return gulp.src(glob)
75+
.pipe(gulpSourcemaps.init())
76+
.pipe(gulpSass(sassOptions).on('error', gulpSass.logError))
77+
.pipe(gulpSourcemaps.write(dest))
78+
.pipe(gulp.dest(dest));
79+
};
80+
}
81+
82+
83+
/***************************************************************************************************
84+
* Components Build Tasks.
85+
*/
86+
gulp.task('build:components:ts', makeTsBuildTask({ tsConfigPath: componentsDir }));
87+
gulp.task('build:components:assets', function() {
88+
return gulp.src(path.join(componentsDir, '*/**/*.!(ts|spec.ts)'))
89+
.pipe(gulp.dest(outLibDir));
90+
});
91+
gulp.task('build:components:scss', function() {
92+
const cssTask = makeSassBuildTask({
93+
dest: outLibDir,
94+
root: componentsDir,
95+
includePaths: path.join(componentsDir, 'core/style')
96+
});
97+
// Also copy over the SCSS for the components.
98+
return gulpMerge([
99+
cssTask(),
100+
gulp.src(path.join(componentsDir, '**/*.scss'))
101+
.pipe(gulp.dest(outLibDir))
102+
]);
103+
});
104+
gulp.task('build:components', [
105+
'build:components:ts',
106+
'build:components:assets',
107+
'build:components:scss'
108+
], function() {
109+
inlineResources([outLibDir]);
110+
});
111+
112+
/***************************************************************************************************
113+
* DevApp Build Tasks.
114+
*/
115+
gulp.task('build:devapp:ts', ['build:components:ts'], makeTsBuildTask({ tsConfigPath: devAppDir }));
116+
gulp.task('build:devapp:scss', ['build:components:scss'], makeSassBuildTask({
117+
dest: outDir,
118+
root: devAppDir,
119+
// Change this once we have a better strategy for releasing SCSS files.
120+
includePaths: [
121+
path.join(componentsDir, 'core/style'),
122+
componentsDir
123+
]
124+
}));
125+
gulp.task('build:devapp:assets', function() {
126+
return gulp.src(path.join(devAppDir, '**/*'))
127+
.pipe(gulp.dest(outDir));
128+
});
129+
gulp.task('build:devapp:vendor', function() {
130+
const npmVendorFiles = [
131+
'core-js/client', 'zone.js/dist', 'hammerjs', 'systemjs/dist', 'rxjs', '@angular', 'hammerjs'
132+
];
133+
134+
return gulpMerge(
135+
npmVendorFiles.map(function(root) {
136+
const glob = path.join(root, '**/*.+(js|js.map)');
137+
return gulp.src(path.join('node_modules', glob))
138+
.pipe(gulp.dest(path.join('dist/vendor', root)));
139+
}));
140+
});
141+
142+
gulp.task('build:devapp', [
143+
'build:components',
144+
'build:devapp:vendor',
145+
'build:devapp:ts',
146+
'build:devapp:scss',
147+
'build:devapp:assets'
148+
]);
149+
150+
/***************************************************************************************************
151+
* DevApp Build Tasks.
152+
*/
153+
gulp.task('build:e2eapp:ts', ['build:components:ts'], makeTsBuildTask({ tsConfigPath: e2eAppDir }));
154+
gulp.task('build:e2eapp:scss', ['build:components:scss'], makeSassBuildTask({
155+
dest: outDir,
156+
root: e2eAppDir,
157+
// Change this once we have a better strategy for releasing SCSS files.
158+
includePaths: [
159+
path.join(componentsDir, 'core/style'),
160+
componentsDir
161+
]
162+
}));
163+
gulp.task('build:e2eapp:assets', function() {
164+
return gulp.src(path.join(e2eAppDir, '**/*'))
165+
.pipe(gulp.dest(outDir));
166+
});
167+
gulp.task('build:e2eapp:vendor', function() {
168+
const npmVendorFiles = [
169+
'core-js/client', 'zone.js/dist', 'hammerjs', 'systemjs/dist', 'rxjs', '@angular', 'hammerjs'
170+
];
171+
172+
return gulpMerge(
173+
npmVendorFiles.map(function(root) {
174+
const glob = path.join(root, '**/*.+(js|js.map)');
175+
return gulp.src(path.join('node_modules', glob))
176+
.pipe(gulp.dest(path.join('dist/vendor', root)));
177+
}));
178+
});
179+
180+
gulp.task('build:e2eapp', [
181+
'build:components',
182+
'build:e2eapp:vendor',
183+
'build:e2eapp:ts',
184+
'build:e2eapp:scss',
185+
'build:e2eapp:assets'
186+
]);
187+
188+
189+
/***************************************************************************************************
190+
* Global tasks.
191+
*/
192+
gulp.task('build', ['build:devapp']);
193+
194+
gulp.task('clean', function () {
195+
return gulp.src('dist', { read: false })
196+
.pipe(gulpClean());
197+
});
198+
199+
200+
/***************************************************************************************************
201+
* Watch Tasks.
202+
*/
203+
gulp.task('watch:components', ['build:components'], function() {
204+
gulp.watch(path.join(componentsDir, '**/*'), ['build:components']);
205+
});
206+
207+
gulp.task('watch:devapp', ['watch:components', 'build:devapp'], function() {
208+
gulp.watch(path.join(devAppDir, '**/*'), ['build:devapp']);
209+
});
210+
211+
212+
/***************************************************************************************************
213+
* Serve Tasks.
214+
*/
215+
gulp.task('serve:devapp', ['build:devapp'], function() {
216+
const server = gulpLiveServer('scripts/serve-dist.js');
217+
218+
server.start();
219+
function reload(file) {
220+
server.notify(file);
221+
}
222+
223+
gulp.watch(path.join(componentsDir, '**/*.ts'), ['build:components:ts'], reload);
224+
gulp.watch(path.join(componentsDir, '**/*.scss'), ['build:components:scss'], reload);
225+
gulp.watch(path.join(componentsDir, '**/*.html'), ['build:components:assets'], reload);
226+
gulp.watch(path.join(devAppDir, '**/*.ts'), ['build:devapp:ts'], reload);
227+
gulp.watch(path.join(devAppDir, '**/*.scss'), ['build:devapp:scss'], reload);
228+
gulp.watch(path.join(devAppDir, '**/*.html'), ['build:devapp:assets'], reload);
229+
});
230+
231+
gulp.task('serve:e2eapp', ['build:e2eapp'], function() {
232+
const server = gulpLiveServer('scripts/serve-dist.js');
233+
234+
server.start();
235+
function reload(file) {
236+
server.notify.apply(server, [file]);
237+
}
238+
239+
gulp.watch(path.join(componentsDir, '**/*.ts'), ['build:components:ts'], reload);
240+
gulp.watch(path.join(componentsDir, '**/*.scss'), ['build:components:scss'], reload);
241+
gulp.watch(path.join(componentsDir, '**/*.html'), ['build:components:assets'], reload);
242+
gulp.watch(path.join(e2eAppDir, '**/*.ts'), ['build:e2eapp:ts'], reload);
243+
gulp.watch(path.join(e2eAppDir, '**/*.scss'), ['build:e2eapp:scss'], reload);
244+
gulp.watch(path.join(e2eAppDir, '**/*.html'), ['build:e2eapp:assets'], reload);
245+
});

0 commit comments

Comments
 (0)