Skip to content
This repository was archived by the owner on Jan 26, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Build and test

on: [push]

jobs:
build-and-deploy:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Use Node.js 10.x
uses: actions/setup-node@v1
with:
node-version: 10.x

- name: Prepare
run: |
cd src
npm install --silent
npm run build
npm run test
cd dist
npm link
cd ..
cd ..
npm install -g @angular/cli@next
ng new your-angular-project --defaults
cd your-angular-project
npm link @angular-schule/ngx-deploy-starter
ng add @angular-schule/ngx-deploy-starter

- name: Deploy
run: |
mkdir /example-folder
cd your-angular-project
ng deploy
3 changes: 2 additions & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
The MIT License (MIT)

Copyright (c) 2019 Minko Gechev, Johannes Hoppe
Copyright (c) 2019-2020 Johannes Hoppe
Copyright (c) 2019 Minko Gechev

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
Expand Down
34 changes: 20 additions & 14 deletions docs/README_contributors.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,19 @@ This may be useful when you want to try the latest non-published version of this

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

### 1. Angular CLI
### 1. Optional: Latest Angular version

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

1. Install the latest version of the Angular CLI.

```sh
npm install -g @angular/cli
```

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

3. Update your existing project using the command:

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

````

Or with the old builder syntax:
Or with the old builder syntax:

```sh
ng run your-angular-project:deploy
````
```sh
ng run your-angular-project:deploy
```

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

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

```
cd ngx-deploy-starter/src
npx prettier --write '**/*'
npm run prettier
npm run build
npm run test
npm publish dist --access public
```

## Usage of Prettier Formatter
## Keeping track of all the forks

[ngx-deploy-starter](https://github.com/angular-schule/ngx-deploy-starter/) and
[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).
This project was a follow-up of the deploy schematics from the [angularfire](https://github.com/angular/angularfire/) project.

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

We are still working on this, see https://github.com/angular-schule/ngx-deploy-starter/issues/10 .
- [builder.ts](https://github.com/angular/angularfire/blob/master/src/schematics/deploy/builder.ts)
- [actions.ts](https://github.com/angular/angularfire/blob/master/src/schematics/deploy/actions.ts)
3 changes: 3 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist
4 changes: 3 additions & 1 deletion src/.prettierrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{
"singleQuote": true
"singleQuote": true,
"trailingComma": "none",
"arrowParens": "avoid"
}
48 changes: 35 additions & 13 deletions src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,36 @@ ng deploy [options]

The following options are also available.

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

- **optional**
- Default: `production` (string)
- Default: `undefined` (string)
- Example:
- `ng deploy` – Angular project is build in production mode
- `ng deploy --configuration=test` – Angular project is using the configuration `test` (this configuration must exist in the `angular.json` file)
- `ng deploy` – Angular project is built in `production` mode
- `ng deploy --build-target=test` – Angular project is using the build configuration `test` (this configuration must exist in the `angular.json` file)

If no `buildTarget` is set, the `production` build of the default project will be chosen.
The `buildTarget` simply points to an existing build configuration for your project, as specified in the `configurations` section of `angular.json`.
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.

This is equivalent to calling the command `ng build --configuration=XXX`.
This command has no effect if the option `--no-build` is active.

**⚠️ BREAKING CHANGE (v1)**

This option was called `--configuration` in previous versions.

BEFORE (_does not work_):

```
ng deploy --configuration=test
```

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

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

#### --no-build

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

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

> **This is a proposal from [RFC #1](https://github.com/angular-schule/ngx-deploy-starter/issues/1).**
This command causes the `--build-target` setting to have no effect.

#### --target-dir

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

> **This is one of the options you can freely choose according to your needs.**

#### --base-href <a name="base-href"></a>
#### --base-href

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

> **This is an example how to override the workspace set of options.**

## License <a name="license"></a>

Code released under the [MIT license](LICENSE).

<hr>

## 🚀 Powered by [ngx-deploy-starter](https://github.com/angular-schule/ngx-deploy-starter)
23 changes: 15 additions & 8 deletions src/deploy/actions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,24 @@ import {
Target
} from '@angular-devkit/architect/src';
import { JsonObject, logging } from '@angular-devkit/core';
import { BuildTarget } from 'interfaces';

import deploy from './actions';

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

const PROJECT = 'pirojok-project';
const BUILD_TARGET: BuildTarget = {
name: `${PROJECT}:build:production`
};

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

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

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

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

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

it('should invoke engine.run', async () => {
const spy = spyOn(mockEngine, 'run').and.callThrough();
await deploy(mockEngine, context, 'host', {});
await deploy(mockEngine, context, BUILD_TARGET, {});

expect(spy).toHaveBeenCalledWith('host', {}, context.logger);
expect(spy).toHaveBeenCalledWith('dist/some-folder', {}, context.logger);
});

describe('error handling', () => {
it('throws if there is no target project', async () => {
context.target = undefined;
try {
await deploy(mockEngine, context, 'host', {});
await deploy(mockEngine, context, BUILD_TARGET, {});
fail();
} catch (e) {
expect(e.message).toMatch(/Cannot execute the build target/);
Expand All @@ -73,7 +77,7 @@ describe('Deploy Angular apps', () => {
result: Promise.resolve(createBuilderOutputMock(false))
} as BuilderRun);
try {
await deploy(mockEngine, context, 'host', {});
await deploy(mockEngine, context, BUILD_TARGET, {});
fail();
} catch (e) {
expect(e.message).toEqual('Error while building the app.');
Expand Down Expand Up @@ -102,7 +106,10 @@ const initMocks = () => {
validateOptions: _ => Promise.resolve({} as any),
getBuilderNameForTarget: () => Promise.resolve(''),
analytics: null as any,
getTargetOptions: (_: Target) => Promise.resolve({}),
getTargetOptions: (_: Target) =>
Promise.resolve({
outputPath: 'dist/some-folder'
}),
reportProgress: (_: number, __?: number, ___?: string) => {},
reportStatus: (_: string) => {},
reportRunning: () => {},
Expand All @@ -112,7 +119,7 @@ const initMocks = () => {
Promise.resolve({
result: Promise.resolve(createBuilderOutputMock(true))
} as BuilderRun)
};
} as any;
};

const createBuilderOutputMock = (success: boolean): BuilderOutput => {
Expand Down
43 changes: 24 additions & 19 deletions src/deploy/actions.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { BuilderContext } from '@angular-devkit/architect';
import {
BuilderContext,
targetFromTargetString
} from '@angular-devkit/architect';
import { json, logging } from '@angular-devkit/core';

import { Schema } from './schema';
import { BuildTarget } from '../interfaces';

export default async function deploy(
engine: {
Expand All @@ -12,39 +16,30 @@ export default async function deploy(
) => Promise<void>;
},
context: BuilderContext,
projectRoot: string,
buildTarget: BuildTarget,
options: Schema
) {
// 1. BUILD
if (options.noBuild) {
context.logger.info(`📦 Skipping build`);
} else {
if (!context.target) {
throw new Error('Cannot execute the build target');
}

const configuration = options.configuration
? options.configuration
: 'production';
const overrides = {
// this is an example how to override the workspace set of options
...(options.baseHref && { baseHref: options.baseHref })
};

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

const build = await context.scheduleTarget(
targetFromTargetString(buildTarget.name),
{
target: 'build',
project: context.target.project,
configuration
},
overrides as json.JsonObject
...buildTarget.options,
...overrides
}
);
const buildResult = await build.result;

Expand All @@ -53,8 +48,18 @@ export default async function deploy(
}
}

// 2. DEPLOYMENT
const buildOptions = await context.getTargetOptions(
targetFromTargetString(buildTarget.name)
);
if (!buildOptions.outputPath || typeof buildOptions.outputPath !== 'string') {
throw new Error(
`Cannot read the output path option of the Angular project '${buildTarget.name}' in angular.json`
);
}

await engine.run(
projectRoot,
buildOptions.outputPath,
options,
(context.logger as unknown) as logging.LoggerApi
);
Expand Down
Loading