Skip to content

Commit 6e492b9

Browse files
feat: add support for Angular v11 (follow up) (#120)
* work in progress * docs: keeping track of all the forks * chore: migrate from `configuration` to `buildTarget` - only unit tests are evaluated right now - no real tests were done yet * ci: bump node version to see if this fixes the break cause it works on my machine (tm) * Revert "ci: bump node version to see if this fixes the break" This reverts commit b300026. * tweaking dependencies / peerDependencies as seen in angularfire: https://github.com/angular/angularfire/blob/2ce41aa0af8c5f42df65f5ac5b2b5a50fb6f4300/package.json#L41-L68 commander has some breaking changes, so let's risk nothing here and rollback * fixing build and tests, cleanup see angular-schule/ngx-deploy-starter#10 * minor: docs + removes astronaut emoij ... since 👨‍🚀 emoij is combined (🧑‍🚀) and breaks on some cmds * docs: breaking change, 1.0.0-rc.1 * docs: suggestion from @fmalcher * Apply suggestions from code review many thanks to @fmalcher Co-authored-by: Ferdinand Malcher <ferdinand@malcher.media> Co-authored-by: Ferdinand Malcher <ferdinand@malcher.media>
1 parent 24d9922 commit 6e492b9

15 files changed

+200
-339
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2017-2019 Johannes Hoppe
3+
Copyright (c) 2017-2020 Johannes Hoppe
44
Copyright (c) 2019 Minko Gechev
55

66
Permission is hereby granted, free of charge, to any person obtaining a copy of

README.md

Lines changed: 59 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
4. [🚀 Continuous Delivery](#continuous-delivery)
1717
5. [📦 Options](#options)
1818
- [--base-href](#base-href)
19-
- [--configuration](#configuration)
19+
- [--build-target](#build-target)
2020
- [--no-build](#no-build)
2121
- [--repo](#repo)
2222
- [--message](#message)
@@ -36,7 +36,29 @@
3636

3737
A detailed changelog is available in the [releases](https://github.com/angular-schule/angular-cli-ghpages/releases) section.
3838

39-
With this latest release, **GitHub Actions** becomes a first citizen alongside Travis CI and CircleCi. The token `GITHUB_TOKEN` is now supported. Learn everything you need to know in the following article.
39+
**⚠️ BREAKING CHANGE (v1)**
40+
41+
Starting with version 1 the option `--configuration` was renamed to `--build-target`.
42+
43+
BEFORE (_does not work_):
44+
45+
```
46+
ng deploy --configuration=test
47+
```
48+
49+
NOW:
50+
51+
```
52+
ng deploy --build-target=test
53+
```
54+
55+
If you use the old syntax, you will probably receive the following error:
56+
57+
> An unhandled exception occurred: Configuration 'test' is not set in the workspace.
58+
59+
<br>
60+
61+
**🐙 GitHub Actions** is now properly supported alongside Travis CI and CircleCi. The token `GITHUB_TOKEN` is also supported. Learn everything you need to know in the following article.
4062

4163
[![Banner](https://angular-schule.github.io/website-articles/blog/2020-01-everything-github/everything-github.png)](https://angular.schule/blog/2020-01-everything-github)
4264

@@ -49,15 +71,15 @@ In this article we show several tools from the GitHub universe to launch a websi
4971
This command has the following prerequisites:
5072

5173
- Git 1.9 or higher (execute `git --version` to check your version)
52-
- Angular project created via [Angular CLI](https://github.com/angular/angular-cli) v8.3.0 or greater (execute `ng update @angular/cli @angular/core` to upgrade your project if necessary)
74+
- Angular project created via [Angular CLI](https://github.com/angular/angular-cli) v9.0.0 or greater (execute `ng update` to upgrade your project if necessary)
5375
- older Angular projects can still use the standalone program. See the documentation at [README_standalone](https://github.com/angular-schule/angular-cli-ghpages/blob/master/docs/README_standalone.md).
5476

5577
## 🚀 Quick Start (local development) <a name="quickstart-local"></a>
5678

5779
This quick start assumes that you are starting from scratch.
5880
If you already have an existing Angular project on GitHub, skip step 1 and 2.
5981

60-
1. Install the latest version of the Angular CLI (v8.3.0 or greater) globally
82+
1. Install the latest version of the Angular CLI globally
6183
and create a new Angular project.
6284

6385
```sh
@@ -98,7 +120,7 @@ If you already have an existing Angular project on GitHub, skip step 1 and 2.
98120
```sh
99121
ng deploy your-angular-project --base-href=/<repositoryname>/
100122
```
101-
123+
102124
Please be aware of the `--base-href` option. It is necessary when your project will be deployed to a non-root folder. See more details below.
103125

104126
5. Your project should be available at `https://<username>.github.io/<repositoryname>`.
@@ -172,19 +194,36 @@ ng deploy --cname=example.org
172194

173195
See the option [--cname](#cname) for more information!
174196

175-
#### --configuration <a name="configuration"></a>
197+
#### --build-target <a name="build-target"></a>
176198

177199
- **optional**
178-
- Alias: `-c`
179-
- Default: `production` (string)
200+
- Default: `undefined` (string)
180201
- Example:
181-
- `ng deploy` – Angular project is build in production mode
182-
- `ng deploy --configuration=test` – Angular project is using the configuration `test` (this configuration must exist in the `angular.json` file)
202+
- `ng deploy` – Angular project is built in `production` mode
203+
- `ng deploy --build-target=test` – Angular project is using the build configuration `test` (this configuration must exist in the `angular.json` file)
204+
205+
If no `buildTarget` is set, the `production` build of the default project will be chosen.
206+
The `buildTarget` simply points to an existing build configuration for your project, as specified in the `configurations` section of `angular.json`.
207+
Most projects have a default configuration and a production configuration (commonly activated by using the `--prod` flag) but it is possible to specify as many build configurations as needed.
208+
209+
This is equivalent to calling the command `ng build --configuration=XXX`.
210+
This command has no effect if the option `--no-build` is active.
211+
212+
**⚠️ BREAKING CHANGE (v1)**
213+
214+
This option was called `--configuration` in previous versions.
215+
216+
BEFORE (_does not work_):
183217

184-
A named build target, as specified in the `configurations` section of `angular.json`.
185-
Each named target is accompanied by a configuration of option defaults for that target.
186-
Same as `ng build --configuration=XXX`.
187-
This command has no effect if the option `--no-build` option is active.
218+
```
219+
ng deploy --configuration=test
220+
```
221+
222+
NOW:
223+
224+
```
225+
ng deploy --build-target=test
226+
```
188227

189228
#### --no-build <a name="no-build"></a>
190229

@@ -196,7 +235,7 @@ This command has no effect if the option `--no-build` option is active.
196235

197236
Skip build process during deployment.
198237
This can be used when you are sure that you haven't changed anything and want to deploy with the latest artifact.
199-
This command causes the `--configuration` setting to have no effect.
238+
This command causes the `--build-target` setting to have no effect.
200239

201240
#### --repo <a name="repo"></a>
202241

@@ -313,7 +352,7 @@ This can be very useful because it outputs what would happen without doing anyth
313352
To avoid all these command-line cmd options, you can write down your configuration in the `angular.json` file in the `options` attribute of your deploy project's architect. Just change the kebab-case to lower camel case. This is the notation of all options in lower camel case:
314353

315354
- baseHref
316-
- configuration
355+
- buildTarget
317356
- noBuild
318357
- repo
319358
- message
@@ -346,20 +385,21 @@ becomes
346385
}
347386
```
348387

349-
And just run `ng deploy` 😄.
388+
Now you can just run `ng deploy` without all the options in the command line! 😄
350389

351390
> **ℹ️ Hint**
352391
>
353392
> You can always use the [--dry-run](#dry-run) option to verify if your configuration is right.
393+
> The project will build but not deploy.
354394
355395
## 🌍 Environments <a name="environments"></a>
356396

357397
We have seen `angular-cli-ghpages` running on various environments, like Travis CI, CircleCi or Github Actions.
358398
Please share your knowledge by writing an article about how to set up the deployment.
359399

360400
1. [GitHub Actions](https://github.com/angular-schule/angular-cli-ghpages/blob/master/docs/README_environment_github_actions.md) by [Dharmen Shah](https://github.com/shhdharmen)
361-
2. TODO: Travis CI
362-
3. TODO: CircleCI
401+
2. Travis CI
402+
3. CircleCI
363403

364404
## ⁉️ FAQ <a name="faq"></a>
365405

docs/README_contributors.md

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
- [4. Testing](#4-testing)
99
- [Testing the standalone CLI](#testing-the-standalone-cli)
1010
- [Publish to NPM](#publish-to-npm)
11-
- [Usage of Prettier Formatter](#usage-of-prettier-formatter)
1211

1312
## How to start
1413

@@ -28,15 +27,19 @@ This may be useful when you want to try the latest non-published version of this
2827

2928
Follow the instructions for [checking and updating the Angular CLI version](#angular-cli) and then link the package.
3029

31-
### 1. Angular CLI
30+
### 1. Optional: Latest Angular version
3231

33-
1. Install the next version of the Angular CLI.
32+
This builder requires the method `getTargetOptions()` from the Angular DevKit which was introduced [here](https://github.com/angular/angular-cli/pull/13825/files).
33+
All Angular projects with Angular 9 and greater are supposed to be compatible. (Actually it works with some versions of 8.x too, but you want to be up to date anyway, don't you?)
34+
Execute the next three steps, if your test project is still older.
35+
36+
1. Install the latest version of the Angular CLI.
3437

3538
```sh
3639
npm install -g @angular/cli
3740
```
3841

39-
2. Run `ng version`, make sure you have installed Angular CLI v8.3.0 or greater.
42+
2. Run `ng version`, to make sure you have installed Angular v9.0.0 or greater.
4043

4144
3. Update your existing project using the command:
4245

@@ -154,16 +157,20 @@ Use VSCode and debug the task `Launch Standalone Program`.
154157

155158
```
156159
cd angular-cli-ghpages/src
157-
npx prettier --write '**/*'
160+
npm run prettier
158161
npm run build
159162
npm run test
160163
npm publish dist
161164
npm dist-tag add angular-cli-ghpages@0.6.0-rc.0 next
162165
```
163166

164-
## Usage of Prettier Formatter
167+
## Keeping track of all the forks
168+
169+
[ngx-deploy-starter](https://github.com/angular-schule/ngx-deploy-starter/) and
170+
[angular-cli-ghpages](https://github.com/angular-schule/angular-cli-ghpages/) (both developed by Johannes Hoppe) are follow-up projects of the deprecated [ngx-gh demo](https://github.com/mgechev/ngx-gh).
171+
This project was a follow-up of the deploy schematics from the [angularfire](https://github.com/angular/angularfire/) project.
165172

166-
Just execute `npx prettier --write '**/*'` and the code is formated automatically.
167-
Please ignore the errors for now. ([error] No parser could be inferred for file)
173+
To stay in sync with the stuff the Angular team is doing, you might want to keep an eye on the following files:
168174

169-
We are still working on this, see https://github.com/angular-schule/ngx-deploy-starter/issues/10 .
175+
- [builder.ts](https://github.com/angular/angularfire/blob/master/src/schematics/deploy/builder.ts)
176+
- [actions.ts](https://github.com/angular/angularfire/blob/master/src/schematics/deploy/actions.ts)

src/.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dist

src/.prettierrc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
{
2-
"singleQuote": true
2+
"singleQuote": true,
3+
"trailingComma": "none",
4+
"arrowParens": "avoid"
35
}

src/angular-cli-ghpages

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ var consoleLogger = {
7474

7575
var dir = path.join(process.cwd(), commander.dir);
7676

77-
engine.run(dir, commander, consoleLogger).catch(function(error) {
77+
engine.run(dir, commander, consoleLogger).catch(function (error) {
7878
consoleLogger.error('❌ An error occurred when trying to deploy:');
7979
consoleLogger.error(error.message);
8080
process.exit(1);

src/deploy/actions.spec.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,24 @@ import {
66
Target
77
} from '@angular-devkit/architect/src';
88
import { JsonObject, logging } from '@angular-devkit/core';
9+
import { BuildTarget } from 'interfaces';
910

1011
import deploy from './actions';
1112

1213
let context: BuilderContext;
1314
const mockEngine = { run: (_: string, __: any, __2: any) => Promise.resolve() };
1415

1516
const PROJECT = 'pirojok-project';
17+
const BUILD_TARGET: BuildTarget = {
18+
name: `${PROJECT}:build:production`
19+
};
1620

1721
describe('Deploy Angular apps', () => {
1822
beforeEach(() => initMocks());
1923

2024
it('should invoke the builder', async () => {
2125
const spy = spyOn(context, 'scheduleTarget').and.callThrough();
22-
await deploy(mockEngine, context, 'host', {});
26+
await deploy(mockEngine, context, BUILD_TARGET, {});
2327

2428
expect(spy).toHaveBeenCalledWith(
2529
{
@@ -33,7 +37,7 @@ describe('Deploy Angular apps', () => {
3337

3438
it('should invoke the builder with the baseHref', async () => {
3539
const spy = spyOn(context, 'scheduleTarget').and.callThrough();
36-
await deploy(mockEngine, context, 'host', { baseHref: '/folder' });
40+
await deploy(mockEngine, context, BUILD_TARGET, { baseHref: '/folder' });
3741

3842
expect(spy).toHaveBeenCalledWith(
3943
{
@@ -47,16 +51,16 @@ describe('Deploy Angular apps', () => {
4751

4852
it('should invoke engine.run', async () => {
4953
const spy = spyOn(mockEngine, 'run').and.callThrough();
50-
await deploy(mockEngine, context, 'host', {});
54+
await deploy(mockEngine, context, BUILD_TARGET, {});
5155

52-
expect(spy).toHaveBeenCalledWith('host', {}, context.logger);
56+
expect(spy).toHaveBeenCalledWith('dist/some-folder', {}, context.logger);
5357
});
5458

5559
describe('error handling', () => {
5660
it('throws if there is no target project', async () => {
5761
context.target = undefined;
5862
try {
59-
await deploy(mockEngine, context, 'host', {});
63+
await deploy(mockEngine, context, BUILD_TARGET, {});
6064
fail();
6165
} catch (e) {
6266
expect(e.message).toMatch(/Cannot execute the build target/);
@@ -73,7 +77,7 @@ describe('Deploy Angular apps', () => {
7377
result: Promise.resolve(createBuilderOutputMock(false))
7478
} as BuilderRun);
7579
try {
76-
await deploy(mockEngine, context, 'host', {});
80+
await deploy(mockEngine, context, BUILD_TARGET, {});
7781
fail();
7882
} catch (e) {
7983
expect(e.message).toEqual('Error while building the app.');
@@ -102,7 +106,10 @@ const initMocks = () => {
102106
validateOptions: _ => Promise.resolve({} as any),
103107
getBuilderNameForTarget: () => Promise.resolve(''),
104108
analytics: null as any,
105-
getTargetOptions: (_: Target) => Promise.resolve({}),
109+
getTargetOptions: (_: Target) =>
110+
Promise.resolve({
111+
outputPath: 'dist/some-folder'
112+
}),
106113
reportProgress: (_: number, __?: number, ___?: string) => {},
107114
reportStatus: (_: string) => {},
108115
reportRunning: () => {},
@@ -112,7 +119,7 @@ const initMocks = () => {
112119
Promise.resolve({
113120
result: Promise.resolve(createBuilderOutputMock(true))
114121
} as BuilderRun)
115-
};
122+
} as any;
116123
};
117124

118125
const createBuilderOutputMock = (success: boolean): BuilderOutput => {

src/deploy/actions.ts

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {
22
BuilderContext,
3-
targetFromTargetString,
3+
targetFromTargetString
44
} from '@angular-devkit/architect';
55
import { json, logging } from '@angular-devkit/core';
66

@@ -19,35 +19,32 @@ export default async function deploy(
1919
buildTarget: BuildTarget,
2020
options: Schema
2121
) {
22+
// 1. BUILD
2223
if (options.noBuild) {
2324
context.logger.info(`📦 Skipping build`);
2425
} else {
2526
if (!context.target) {
2627
throw new Error('Cannot execute the build target');
2728
}
2829

29-
const configuration = options.configuration
30-
? options.configuration
31-
: 'production';
30+
// baseHref (from @angular-devkit/build-angular:browser)
31+
// can be overriden here directly from the deployment builder options,
32+
// since this feature is the most important switch when deploying the github
3233
const overrides = {
33-
...(options.baseHref && { baseHref: options.baseHref }),
34+
...(options.baseHref && { baseHref: options.baseHref })
3435
};
3536

36-
context.logger.info(
37-
`📦 Building "${
38-
context.target.project
39-
}". Configuration: "${configuration}".${
40-
options.baseHref ? ' Your base-href: "' + options.baseHref + '"' : ''
41-
}`
42-
);
37+
context.logger.info(`📦 Building "${context.target.project}"`);
38+
context.logger.info(`📦 Build target "${buildTarget.name}"`);
39+
40+
// options.baseHref ? ' Your base-href: "' + options.baseHref + '"' : ''
4341

4442
const build = await context.scheduleTarget(
43+
targetFromTargetString(buildTarget.name),
4544
{
46-
target: 'build',
47-
project: context.target.project,
48-
configuration,
49-
},
50-
overrides as json.JsonObject
45+
...buildTarget.options,
46+
...overrides
47+
}
5148
);
5249
const buildResult = await build.result;
5350

@@ -56,6 +53,7 @@ export default async function deploy(
5653
}
5754
}
5855

56+
// 2. DEPLOYMENT
5957
const buildOptions = await context.getTargetOptions(
6058
targetFromTargetString(buildTarget.name)
6159
);

0 commit comments

Comments
 (0)