Skip to content

Commit b6f11e4

Browse files
committed
Replaced stage-release by a gulp task instead
1 parent d2999d5 commit b6f11e4

File tree

5 files changed

+58
-114
lines changed

5 files changed

+58
-114
lines changed

gulpfile.js

Lines changed: 55 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,23 @@
33
* This file needs to be JavaScript and is read by gulp.
44
*/
55
// Global imports.
6+
const child_process = require('child_process');
67
const fs = require('fs');
78
const gulp = require('gulp');
89
const path = require('path');
10+
const resolveBin = require('resolve-bin');
911

1012
// Other imports.
1113
const inlineResources = require('./scripts/release/inline-resources');
1214

1315
// Gulp plugins.
1416
const gulpClean = require('gulp-clean');
15-
const gulpTs = require('gulp-typescript');
17+
const gulpLiveServer = require('gulp-live-server');
1618
const gulpMerge = require('merge2');
19+
const gulpRunSequence = require('run-sequence');
1720
const gulpSass = require('gulp-sass');
1821
const gulpSourcemaps = require('gulp-sourcemaps');
19-
const gulpLiveServer = require('gulp-live-server');
22+
const gulpTs = require('gulp-typescript');
2023

2124

2225
// Directories.
@@ -48,15 +51,12 @@ function makeTsBuildTask(options) {
4851
.pipe(gulpTs(tsProject));
4952
let dts = pipe.dts.pipe(gulp.dest(dest));
5053

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))]);
54+
return gulpMerge([
55+
dts,
56+
pipe
57+
.pipe(gulpSourcemaps.write('.'))
58+
.pipe(gulp.dest(dest))
59+
]);
6060
};
6161
}
6262

@@ -108,6 +108,24 @@ gulp.task('build:components', [
108108
], function() {
109109
inlineResources([outLibDir]);
110110
});
111+
gulp.task('build:components:ngc', ['build:components'], function(done) {
112+
resolveBin('@angular/compiler-cli', { executable: 'ngc' }, function(err, cliPath) {
113+
if (err) {
114+
console.error(err);
115+
process.exit(1);
116+
}
117+
118+
child_process.exec(`${cliPath} -p ${path.relative(__dirname, componentsDir)}`, function(error) {
119+
console.log(arguments);
120+
if (error) {
121+
console.error(error);
122+
process.exit(1);
123+
}
124+
125+
done();
126+
});
127+
});
128+
});
111129

112130
/***************************************************************************************************
113131
* DevApp Build Tasks.
@@ -189,12 +207,24 @@ gulp.task('build:e2eapp', [
189207
/***************************************************************************************************
190208
* Global tasks.
191209
*/
210+
gulp.task('default', function() {
211+
console.log(`You're probably looking for "build" or "serve:devapp".`);
212+
});
213+
192214
gulp.task('build', ['build:devapp']);
193215

194-
gulp.task('clean', function () {
216+
gulp.task('clean', function() {
195217
return gulp.src('dist', { read: false })
196218
.pipe(gulpClean());
197219
});
220+
gulp.task('clean:spec', function() {
221+
return gulp.src('dist/**/*.spec.*', { read: false })
222+
.pipe(gulpClean());
223+
});
224+
gulp.task('clean:assets', function() {
225+
return gulp.src('dist/**/*+(.html|.css)', { read: false })
226+
.pipe(gulpClean());
227+
});
198228

199229

200230
/***************************************************************************************************
@@ -243,3 +273,16 @@ gulp.task('serve:e2eapp', ['build:e2eapp'], function() {
243273
gulp.watch(path.join(e2eAppDir, '**/*.scss'), ['build:e2eapp:scss'], reload);
244274
gulp.watch(path.join(e2eAppDir, '**/*.html'), ['build:e2eapp:assets'], reload);
245275
});
276+
277+
/***************************************************************************************************
278+
* Release builds.
279+
*/
280+
gulp.task('build:release', function(done) {
281+
// Synchronously run those tasks.
282+
gulpRunSequence(
283+
'clean',
284+
'build:components:ngc',
285+
['clean:spec', 'clean:assets'],
286+
done
287+
);
288+
});

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
"@angular/compiler-cli": "^0.4.1",
4444
"@types/hammerjs": "^2.0.30",
4545
"@types/jasmine": "^2.2.31",
46-
"add-stream": "^1.0.0",
4746
"browserstacktunnel-wrapper": "^1.4.2",
4847
"conventional-changelog": "^1.1.0",
4948
"ember-cli-inject-live-reload": "^1.4.0",
@@ -71,6 +70,8 @@
7170
"node-sass": "^3.4.2",
7271
"protractor": "^3.3.0",
7372
"protractor-accessibility-plugin": "0.1.1",
73+
"resolve-bin": "^0.4.0",
74+
"run-sequence": "^1.2.2",
7475
"sass": "^0.5.0",
7576
"strip-ansi": "^3.0.0",
7677
"stylelint": "^6.9.0",

scripts/ci/build-and-test.sh

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@ elif is_e2e; then
3535
echo -n ".."
3636
done
3737

38-
echo "\nInlining resources"
39-
npm run inline-resources
40-
4138
# Run the e2e tests on the served e2e app.
4239
echo "Starting e2e tests"
4340
npm run e2e
@@ -49,7 +46,6 @@ elif is_extract_metadata; then
4946
else
5047
# Unit tests
5148
npm run build
52-
npm run inline-resources
5349

5450
karma start test/karma.conf.js --single-run --no-auto-watch --reporters='dots'
5551
fi

scripts/release/stage-release.bat

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

scripts/release/stage-release.sh

Lines changed: 1 addition & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,4 @@
11
#!/usr/bin/env bash
22
set -xu
33

4-
# Stages a release by putting everything that should be packaged and released
5-
# into the ./deploy folder. This script should be run from the root of the
6-
# material2 repo.
7-
8-
# Make sure you are not running `ng serve` or `ng build --watch` when running this.
9-
10-
11-
# Clear dist/ and deploy/ so that we guarantee there are no stale artifacts.
12-
rm -rf ./dist
13-
rm -rf ./deploy
14-
15-
# deploy/ serves as a working directory to stage the release.
16-
mkdir deploy
17-
18-
# Start off by building normally.
19-
ng build
20-
21-
# `ng build` does not complete synchronously, so wait a moment for it.
22-
sleep 2
23-
24-
# We need to remove moduleId for the ngc build. We do this by simply commenting out with a
25-
# distinguishing marker and then undoing those lines after we've generated the .metadata.json files.
26-
grep -lr "moduleId:" ./src/ | xargs sed -i 's|moduleId:|//MODULE moduleId:|g'
27-
28-
# Run tsc directly first so that the output directories match what ngc is expecting. This is
29-
# different from what the CLI will output for *demo-app*, but we don't care about the output for
30-
# demo-app when we're staging a release (only components/ and core/).
31-
tsc -p ./src/demo-app
32-
33-
# Now run ngc to generate the .metadata.json files. Our tsconfig is configred with
34-
# skipTemplateCodegen, so only the metadata files are actually generated.
35-
./node_modules/.bin/ngc -p ./src/demo-app
36-
37-
# Restore the moduleIds.
38-
grep -lr "//MODULE " ./src/ | xargs sed -i 's|//MODULE ||g'
39-
40-
# At this point, we have all of our .metadata.json files, which is all we care about from ngc.
41-
# Temporarily copy them over to deploy/ so we can cut a clean build.
42-
# Use rsync since we want to preserve the directory structure and `cp --parents` won't work on OSX.
43-
find ./dist/{components,core} -iname "*.metadata.json" | xargs -i rsync -Rq {} ./deploy/
44-
45-
# Wipe away dist and perform a clean build.
46-
rm -rf ./dist
47-
ng build
48-
49-
# Inline the css and html into the component ts files.
50-
npm run inline-resources
51-
52-
# Move the .metadata.json files back to where we want them.
53-
(cd ./deploy ; find ./ -iname "*.metadata.json" | xargs -i rsync -Rq {} ../)
54-
55-
# Clear the deploy/ directory again now that we've pulled the metadata out of it.
56-
rm -rf ./deploy/*
57-
58-
# Copy all components/ to deploy/
59-
cp -R ./dist/components/* ./deploy/
60-
61-
# Copy the core/ directory directly into ./deploy
62-
cp -R ./dist/core/ ./deploy/core/
63-
64-
# Remove css files from src/
65-
find ./src -iname "*.css" | xargs rm
66-
67-
# Remove test files from deploy/
68-
find ./deploy -iname "*.spec.d.ts" | xargs rm
69-
find ./deploy -iname "*.spec.js" | xargs rm
70-
find ./deploy -iname "*.spec.js.map" | xargs rm
71-
72-
# To test the packages, simply `npm install` the package directories.
4+
$(npm bin)/gulp build:release

0 commit comments

Comments
 (0)