Skip to content
This repository was archived by the owner on Jan 26, 2024. It is now read-only.

Commit da8f87b

Browse files
feat: add support for Angular v11 (#25)
plus various backported changes from angular-cli-ghpages by @beeman & @JohannesHoppe
1 parent 1cc1937 commit da8f87b

18 files changed

+2792
-3012
lines changed

.github/workflows/main.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Build and test
2+
3+
on: [push]
4+
5+
jobs:
6+
build-and-deploy:
7+
runs-on: ubuntu-latest
8+
9+
steps:
10+
- name: Checkout
11+
uses: actions/checkout@v2
12+
13+
- name: Use Node.js 10.x
14+
uses: actions/setup-node@v1
15+
with:
16+
node-version: 10.x
17+
18+
- name: Prepare
19+
run: |
20+
cd src
21+
npm install --silent
22+
npm run build
23+
npm run test
24+
cd dist
25+
npm link
26+
cd ..
27+
cd ..
28+
npm install -g @angular/cli@next
29+
ng new your-angular-project --defaults
30+
cd your-angular-project
31+
npm link @angular-schule/ngx-deploy-starter
32+
ng add @angular-schule/ngx-deploy-starter
33+
34+
- name: Deploy
35+
run: |
36+
mkdir /example-folder
37+
cd your-angular-project
38+
ng deploy

LICENSE

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

3-
Copyright (c) 2019 Minko Gechev, Johannes Hoppe
3+
Copyright (c) 2019-2020 Johannes Hoppe
4+
Copyright (c) 2019 Minko Gechev
45

56
Permission is hereby granted, free of charge, to any person obtaining a copy of
67
this software and associated documentation files (the "Software"), to deal in

docs/README_contributors.md

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,19 @@ This may be useful when you want to try the latest non-published version of this
2828

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

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

33-
1. Install the next version of the Angular CLI.
33+
This builder requires the method `getTargetOptions()` from the Angular DevKit which was introduced [here](https://github.com/angular/angular-cli/pull/13825/files).
34+
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?)
35+
Execute the next three steps, if your test project is still older.
36+
37+
1. Install the latest version of the Angular CLI.
3438

3539
```sh
3640
npm install -g @angular/cli
3741
```
3842

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

4145
3. Update your existing project using the command:
4246

@@ -105,13 +109,11 @@ Once you have completed the previous steps to `npm link` the local copy of `@ang
105109
ng deploy
106110
```
107111

108-
````
109-
110-
Or with the old builder syntax:
112+
Or with the old builder syntax:
111113

112-
```sh
113-
ng run your-angular-project:deploy
114-
````
114+
```sh
115+
ng run your-angular-project:deploy
116+
```
115117

116118
5. You can remove the link later by running `npm unlink`
117119

@@ -169,15 +171,19 @@ To debug your deployer you need to:
169171

170172
```
171173
cd ngx-deploy-starter/src
172-
npx prettier --write '**/*'
174+
npm run prettier
173175
npm run build
174176
npm run test
175177
npm publish dist --access public
176178
```
177179

178-
## Usage of Prettier Formatter
180+
## Keeping track of all the forks
181+
182+
[ngx-deploy-starter](https://github.com/angular-schule/ngx-deploy-starter/) and
183+
[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).
184+
This project was a follow-up of the deploy schematics from the [angularfire](https://github.com/angular/angularfire/) project.
179185

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

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

package-lock.json

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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/README.md

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,36 @@ ng deploy [options]
2727

2828
The following options are also available.
2929

30-
#### --configuration
30+
#### --build-target <a name="build-target"></a>
3131

3232
- **optional**
33-
- Default: `production` (string)
33+
- Default: `undefined` (string)
3434
- Example:
35-
- `ng deploy` – Angular project is build in production mode
36-
- `ng deploy --configuration=test` – Angular project is using the configuration `test` (this configuration must exist in the `angular.json` file)
35+
- `ng deploy` – Angular project is built in `production` mode
36+
- `ng deploy --build-target=test` – Angular project is using the build configuration `test` (this configuration must exist in the `angular.json` file)
37+
38+
If no `buildTarget` is set, the `production` build of the default project will be chosen.
39+
The `buildTarget` simply points to an existing build configuration for your project, as specified in the `configurations` section of `angular.json`.
40+
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.
41+
42+
This is equivalent to calling the command `ng build --configuration=XXX`.
43+
This command has no effect if the option `--no-build` is active.
44+
45+
**⚠️ BREAKING CHANGE (v1)**
46+
47+
This option was called `--configuration` in previous versions.
48+
49+
BEFORE (_does not work_):
50+
51+
```
52+
ng deploy --configuration=test
53+
```
3754

38-
A named build target, as specified in the `configurations` section of `angular.json`.
39-
Each named target is accompanied by a configuration of option defaults for that target.
40-
Same as `ng build --configuration=XXX`.
41-
This command has no effect if the option `--no-build` option is active.
55+
NOW:
4256

43-
> **This is a proposal from [RFC #1](https://github.com/angular-schule/ngx-deploy-starter/issues/1).**
57+
```
58+
ng deploy --build-target=test
59+
```
4460

4561
#### --no-build
4662

@@ -52,9 +68,7 @@ This command has no effect if the option `--no-build` option is active.
5268

5369
Skip build process during deployment.
5470
This can be used when you are sure that you haven't changed anything and want to deploy with the latest artifact.
55-
This command causes the `--configuration` setting to have no effect.
56-
57-
> **This is a proposal from [RFC #1](https://github.com/angular-schule/ngx-deploy-starter/issues/1).**
71+
This command causes the `--build-target` setting to have no effect.
5872

5973
#### --target-dir
6074

@@ -66,7 +80,7 @@ This command causes the `--configuration` setting to have no effect.
6680

6781
> **This is one of the options you can freely choose according to your needs.**
6882
69-
#### --base-href <a name="base-href"></a>
83+
#### --base-href
7084

7185
- **optional**
7286
- Default: `undefined` (string)
@@ -78,3 +92,11 @@ Specifies the base URL for the application being built.
7892
Same as `ng build --base-href=/XXX/`
7993

8094
> **This is an example how to override the workspace set of options.**
95+
96+
## License <a name="license"></a>
97+
98+
Code released under the [MIT license](LICENSE).
99+
100+
<hr>
101+
102+
## 🚀 Powered by [ngx-deploy-starter](https://github.com/angular-schule/ngx-deploy-starter)

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: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
import { BuilderContext } from '@angular-devkit/architect';
1+
import {
2+
BuilderContext,
3+
targetFromTargetString
4+
} from '@angular-devkit/architect';
25
import { json, logging } from '@angular-devkit/core';
36

47
import { Schema } from './schema';
8+
import { BuildTarget } from '../interfaces';
59

610
export default async function deploy(
711
engine: {
@@ -12,39 +16,30 @@ export default async function deploy(
1216
) => Promise<void>;
1317
},
1418
context: BuilderContext,
15-
projectRoot: string,
19+
buildTarget: BuildTarget,
1620
options: Schema
1721
) {
22+
// 1. BUILD
1823
if (options.noBuild) {
1924
context.logger.info(`📦 Skipping build`);
2025
} else {
2126
if (!context.target) {
2227
throw new Error('Cannot execute the build target');
2328
}
2429

25-
const configuration = options.configuration
26-
? options.configuration
27-
: 'production';
2830
const overrides = {
29-
// this is an example how to override the workspace set of options
3031
...(options.baseHref && { baseHref: options.baseHref })
3132
};
3233

33-
context.logger.info(
34-
`📦 Building "${
35-
context.target.project
36-
}". Configuration: "${configuration}".${
37-
options.baseHref ? ' Your base-href: "' + options.baseHref + '"' : ''
38-
}`
39-
);
34+
context.logger.info(`� Building "${context.target.project}"`);
35+
context.logger.info(`� Build target "${buildTarget.name}"`);
4036

4137
const build = await context.scheduleTarget(
38+
targetFromTargetString(buildTarget.name),
4239
{
43-
target: 'build',
44-
project: context.target.project,
45-
configuration
46-
},
47-
overrides as json.JsonObject
40+
...buildTarget.options,
41+
...overrides
42+
}
4843
);
4944
const buildResult = await build.result;
5045

@@ -53,8 +48,18 @@ export default async function deploy(
5348
}
5449
}
5550

51+
// 2. DEPLOYMENT
52+
const buildOptions = await context.getTargetOptions(
53+
targetFromTargetString(buildTarget.name)
54+
);
55+
if (!buildOptions.outputPath || typeof buildOptions.outputPath !== 'string') {
56+
throw new Error(
57+
`Cannot read the output path option of the Angular project '${buildTarget.name}' in angular.json`
58+
);
59+
}
60+
5661
await engine.run(
57-
projectRoot,
62+
buildOptions.outputPath,
5863
options,
5964
(context.logger as unknown) as logging.LoggerApi
6065
);

0 commit comments

Comments
 (0)