Skip to content

Commit

Permalink
Replaced stage-release by a gulp task instead
Browse files Browse the repository at this point in the history
  • Loading branch information
hansl committed Aug 8, 2016
1 parent d2999d5 commit b6f11e4
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 114 deletions.
67 changes: 55 additions & 12 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,23 @@
* This file needs to be JavaScript and is read by gulp.
*/
// Global imports.
const child_process = require('child_process');
const fs = require('fs');
const gulp = require('gulp');
const path = require('path');
const resolveBin = require('resolve-bin');

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

// Gulp plugins.
const gulpClean = require('gulp-clean');
const gulpTs = require('gulp-typescript');
const gulpLiveServer = require('gulp-live-server');
const gulpMerge = require('merge2');
const gulpRunSequence = require('run-sequence');
const gulpSass = require('gulp-sass');
const gulpSourcemaps = require('gulp-sourcemaps');
const gulpLiveServer = require('gulp-live-server');
const gulpTs = require('gulp-typescript');


// Directories.
Expand Down Expand Up @@ -48,15 +51,12 @@ function makeTsBuildTask(options) {
.pipe(gulpTs(tsProject));
let dts = pipe.dts.pipe(gulp.dest(dest));

if (tsConfig.compilerOptions.sourceMap) {
if (!tsConfig.compilerOptions.inlineSources) {
pipe = pipe.pipe(gulpSourcemaps.write(dest));
} else {
pipe = pipe.pipe(gulpSourcemaps.write());
}
}

return gulpMerge([dts, pipe.pipe(gulp.dest(dest))]);
return gulpMerge([
dts,
pipe
.pipe(gulpSourcemaps.write('.'))
.pipe(gulp.dest(dest))
]);
};
}

Expand Down Expand Up @@ -108,6 +108,24 @@ gulp.task('build:components', [
], function() {
inlineResources([outLibDir]);
});
gulp.task('build:components:ngc', ['build:components'], function(done) {
resolveBin('@angular/compiler-cli', { executable: 'ngc' }, function(err, cliPath) {
if (err) {
console.error(err);
process.exit(1);
}

child_process.exec(`${cliPath} -p ${path.relative(__dirname, componentsDir)}`, function(error) {
console.log(arguments);
if (error) {
console.error(error);
process.exit(1);
}

done();
});
});
});

/***************************************************************************************************
* DevApp Build Tasks.
Expand Down Expand Up @@ -189,12 +207,24 @@ gulp.task('build:e2eapp', [
/***************************************************************************************************
* Global tasks.
*/
gulp.task('default', function() {
console.log(`You're probably looking for "build" or "serve:devapp".`);
});

gulp.task('build', ['build:devapp']);

gulp.task('clean', function () {
gulp.task('clean', function() {
return gulp.src('dist', { read: false })
.pipe(gulpClean());
});
gulp.task('clean:spec', function() {
return gulp.src('dist/**/*.spec.*', { read: false })
.pipe(gulpClean());
});
gulp.task('clean:assets', function() {
return gulp.src('dist/**/*+(.html|.css)', { read: false })
.pipe(gulpClean());
});


/***************************************************************************************************
Expand Down Expand Up @@ -243,3 +273,16 @@ gulp.task('serve:e2eapp', ['build:e2eapp'], function() {
gulp.watch(path.join(e2eAppDir, '**/*.scss'), ['build:e2eapp:scss'], reload);
gulp.watch(path.join(e2eAppDir, '**/*.html'), ['build:e2eapp:assets'], reload);
});

/***************************************************************************************************
* Release builds.
*/
gulp.task('build:release', function(done) {
// Synchronously run those tasks.
gulpRunSequence(
'clean',
'build:components:ngc',
['clean:spec', 'clean:assets'],
done
);
});
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
"@angular/compiler-cli": "^0.4.1",
"@types/hammerjs": "^2.0.30",
"@types/jasmine": "^2.2.31",
"add-stream": "^1.0.0",
"browserstacktunnel-wrapper": "^1.4.2",
"conventional-changelog": "^1.1.0",
"ember-cli-inject-live-reload": "^1.4.0",
Expand Down Expand Up @@ -71,6 +70,8 @@
"node-sass": "^3.4.2",
"protractor": "^3.3.0",
"protractor-accessibility-plugin": "0.1.1",
"resolve-bin": "^0.4.0",
"run-sequence": "^1.2.2",
"sass": "^0.5.0",
"strip-ansi": "^3.0.0",
"stylelint": "^6.9.0",
Expand Down
4 changes: 0 additions & 4 deletions scripts/ci/build-and-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ elif is_e2e; then
echo -n ".."
done

echo "\nInlining resources"
npm run inline-resources

# Run the e2e tests on the served e2e app.
echo "Starting e2e tests"
npm run e2e
Expand All @@ -49,7 +46,6 @@ elif is_extract_metadata; then
else
# Unit tests
npm run build
npm run inline-resources

karma start test/karma.conf.js --single-run --no-auto-watch --reporters='dots'
fi
Expand Down
28 changes: 0 additions & 28 deletions scripts/release/stage-release.bat

This file was deleted.

70 changes: 1 addition & 69 deletions scripts/release/stage-release.sh
Original file line number Diff line number Diff line change
@@ -1,72 +1,4 @@
#!/usr/bin/env bash
set -xu

# Stages a release by putting everything that should be packaged and released
# into the ./deploy folder. This script should be run from the root of the
# material2 repo.

# Make sure you are not running `ng serve` or `ng build --watch` when running this.


# Clear dist/ and deploy/ so that we guarantee there are no stale artifacts.
rm -rf ./dist
rm -rf ./deploy

# deploy/ serves as a working directory to stage the release.
mkdir deploy

# Start off by building normally.
ng build

# `ng build` does not complete synchronously, so wait a moment for it.
sleep 2

# We need to remove moduleId for the ngc build. We do this by simply commenting out with a
# distinguishing marker and then undoing those lines after we've generated the .metadata.json files.
grep -lr "moduleId:" ./src/ | xargs sed -i 's|moduleId:|//MODULE moduleId:|g'

# Run tsc directly first so that the output directories match what ngc is expecting. This is
# different from what the CLI will output for *demo-app*, but we don't care about the output for
# demo-app when we're staging a release (only components/ and core/).
tsc -p ./src/demo-app

# Now run ngc to generate the .metadata.json files. Our tsconfig is configred with
# skipTemplateCodegen, so only the metadata files are actually generated.
./node_modules/.bin/ngc -p ./src/demo-app

# Restore the moduleIds.
grep -lr "//MODULE " ./src/ | xargs sed -i 's|//MODULE ||g'

# At this point, we have all of our .metadata.json files, which is all we care about from ngc.
# Temporarily copy them over to deploy/ so we can cut a clean build.
# Use rsync since we want to preserve the directory structure and `cp --parents` won't work on OSX.
find ./dist/{components,core} -iname "*.metadata.json" | xargs -i rsync -Rq {} ./deploy/

# Wipe away dist and perform a clean build.
rm -rf ./dist
ng build

# Inline the css and html into the component ts files.
npm run inline-resources

# Move the .metadata.json files back to where we want them.
(cd ./deploy ; find ./ -iname "*.metadata.json" | xargs -i rsync -Rq {} ../)

# Clear the deploy/ directory again now that we've pulled the metadata out of it.
rm -rf ./deploy/*

# Copy all components/ to deploy/
cp -R ./dist/components/* ./deploy/

# Copy the core/ directory directly into ./deploy
cp -R ./dist/core/ ./deploy/core/

# Remove css files from src/
find ./src -iname "*.css" | xargs rm

# Remove test files from deploy/
find ./deploy -iname "*.spec.d.ts" | xargs rm
find ./deploy -iname "*.spec.js" | xargs rm
find ./deploy -iname "*.spec.js.map" | xargs rm

# To test the packages, simply `npm install` the package directories.
$(npm bin)/gulp build:release

0 comments on commit b6f11e4

Please sign in to comment.