forked from angular/components
-
Notifications
You must be signed in to change notification settings - Fork 3
/
stage-release.sh
executable file
·72 lines (51 loc) · 2.58 KB
/
stage-release.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/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.