Skip to content

Commit f2bc3ad

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

File tree

206 files changed

+306
-254
lines changed

Some content is hidden

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

206 files changed

+306
-254
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: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
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 libDir = path.join(srcDir, 'lib');
25+
const devAppDir = path.join(srcDir, 'demo-app');
26+
27+
const outDir = 'dist';
28+
const outLibDir = path.join(outDir, '@angular2-material');
29+
30+
31+
/**
32+
* Create a TS Build Task, based on the options.
33+
*/
34+
function makeTsBuildTask(options) {
35+
const tsConfigDir = options.tsConfigPath;
36+
const tsConfigPath = path.join(tsConfigDir, 'tsconfig.json');
37+
const tsConfig = JSON.parse(fs.readFileSync(tsConfigPath, 'utf-8'));
38+
const dest = path.join(tsConfigDir, tsConfig.compilerOptions.outDir);
39+
40+
return function() {
41+
const tsProject = gulpTs.createProject(tsConfigPath, {
42+
typescript: require('typescript')
43+
});
44+
45+
let pipe = tsProject.src();
46+
pipe = pipe
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+
* Task section.
85+
*/
86+
gulp.task('build:components:ts', makeTsBuildTask({ tsConfigPath: libDir }));
87+
gulp.task('build:components:assets', function() {
88+
return gulp.src(path.join(libDir, '*/**/*.!(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: libDir,
95+
includePaths: path.join(libDir, 'core/style')
96+
});
97+
// Also copy over the SCSS for the components.
98+
return gulpMerge([
99+
cssTask(),
100+
gulp.src(path.join(libDir, '**/*.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+
gulp.task('build:devapp:ts', ['build:components:ts'], makeTsBuildTask({ tsConfigPath: devAppDir }));
113+
gulp.task('build:devapp:scss', ['build:components:scss'], makeSassBuildTask({
114+
dest: outDir,
115+
root: devAppDir,
116+
// Change this once we have a better strategy for releasing SCSS files.
117+
includePaths: [
118+
path.join(libDir, 'core/style'),
119+
libDir
120+
]
121+
}));
122+
gulp.task('build:devapp:assets', function() {
123+
return gulp.src(path.join(devAppDir, '**/*'))
124+
.pipe(gulp.dest(outDir));
125+
});
126+
gulp.task('build:devapp:vendor', function() {
127+
const npmVendorFiles = [
128+
'core-js/client',
129+
'zone.js/dist',
130+
'hammerjs',
131+
'systemjs/dist',
132+
'rxjs',
133+
'@angular',
134+
'hammerjs'
135+
];
136+
137+
return gulpMerge(
138+
npmVendorFiles.map(function(root) {
139+
const glob = path.join(root, '**/*.+(js|js.map)');
140+
return gulp.src(path.join('node_modules', glob))
141+
.pipe(gulp.dest(path.join('dist/vendor', root)));
142+
}));
143+
});
144+
145+
gulp.task('build:devapp', [
146+
'build:components',
147+
'build:devapp:vendor',
148+
'build:devapp:ts',
149+
'build:devapp:scss',
150+
'build:devapp:assets'
151+
]);
152+
153+
gulp.task('build', [
154+
'build:components',
155+
'build:devapp'
156+
]);
157+
158+
gulp.task('clean', function () {
159+
return gulp.src('dist', { read: false })
160+
.pipe(gulpClean());
161+
});
162+
163+
gulp.task('watch:components', ['build:components'], function() {
164+
gulp.watch(path.join(libDir, '**/*'), ['build:components']);
165+
});
166+
167+
gulp.task('watch:devapp', ['watch:components', 'build:devapp'], function() {
168+
gulp.watch(path.join(devAppDir, '**/*'), ['build:devapp']);
169+
});
170+
171+
gulp.task('serve:devapp', ['build'], function() {
172+
const server = gulpLiveServer.static('dist', 4200);
173+
174+
server.start();
175+
function reload(file) {
176+
server.notify.apply(server, [file]);
177+
}
178+
179+
gulp.watch(path.join(libDir, '**/*.ts'), ['build:components:ts'], reload);
180+
gulp.watch(path.join(libDir, '**/*.scss'), ['build:components:scss'], reload);
181+
gulp.watch(path.join(libDir, '**/*.html'), ['build:components:html'], reload);
182+
gulp.watch(path.join(devAppDir, '**/*.ts'), ['build:devapp:ts'], reload);
183+
gulp.watch(path.join(devAppDir, '**/*.scss'), ['build:devapp:scss'], reload);
184+
gulp.watch(path.join(devAppDir, '**/*.html'), ['build:devapp:html'], reload);
185+
});
186+

0 commit comments

Comments
 (0)