Skip to content

Commit 0b8a5d4

Browse files
committed
Add readme
1 parent f184c45 commit 0b8a5d4

File tree

6 files changed

+77
-21
lines changed

6 files changed

+77
-21
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ app/bower_components
66
.bash_history
77
*.swp
88
*.swo
9+
*.d.ts
910

1011
*.classpath
1112
*.project
@@ -21,4 +22,3 @@ nvim/doc
2122
nvim/swaps
2223
nvim/colors
2324
dist
24-

README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Angular CLI Deployment to GitHub Pages
2+
3+
Deploy your Angular app to GitHub pages directly from the Angular CLI! 🚀
4+
5+
## How to use?
6+
7+
```
8+
ng add ngx-gh
9+
ng run [PROJECT_NAME]:deploy
10+
```
11+
12+
## Options
13+
14+
If you're deploying your application to `https://[USERNAME].github.io/[PROJECT_NAME]`, you'd have to set the following options:
15+
16+
- `--deployUrl` - specifies the URL you're deploying your application to. For example `https://mgechev.github.io/codelyzer/`.
17+
- `--baseHref` - specifies the `baseHref` and used by the Angular router. For the example above, the `baseHref` would be `/codelyzer/`.
18+
19+
Sample invocation:
20+
21+
```
22+
ng run codelyzer:deploy --baseHref /codelyzer/ --deployUrl https://mgechev.github.io/codelyzer/
23+
```
24+
25+
Deployment to the root of a custom domain may not require any of the listed flags below.
26+
27+
## Configuring the build
28+
29+
Since `ng deploy` will automatically invoke the production build of your app, you can configure it using the workspace configuration file `angular.json`. You can find the build config under: `projects.[PROJECT_NAME].architect.build.configuration.production`.
30+
31+
## License
32+
33+
MIT

deploy/actions.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,35 @@
11
import { BuilderContext } from '@angular-devkit/architect';
22
import { GHPages } from '../interfaces';
3+
import { Schema as RealDeployOptions } from './schema';
4+
import { json } from '@angular-devkit/core';
5+
type DeployOptions = RealDeployOptions & json.JsonObject;
36

47
export default async function deploy(
58
ghPages: GHPages,
69
context: BuilderContext,
7-
projectRoot: string
10+
projectRoot: string,
11+
options: DeployOptions
812
) {
913
if (!context.target) {
1014
throw new Error('Cannot execute the build target');
1115
}
1216

1317
context.logger.info(`📦 Building "${context.target.project}"`);
1418

15-
const run = await context.scheduleTarget({
16-
target: 'build',
17-
project: context.target.project,
18-
configuration: 'production'
19-
});
19+
const run = await context.scheduleTarget(
20+
{
21+
target: 'build',
22+
project: context.target.project,
23+
configuration: 'production'
24+
},
25+
options
26+
);
2027
await run.result;
2128

2229
try {
2330
await ghPages.publish(projectRoot, {});
2431
context.logger.info(
25-
`🚀 Your application is now available at https://${''}.firebaseapp.com/`
32+
`🚀 Your application is now available at ${options.deployUrl}`
2633
);
2734
} catch (e) {
2835
context.logger.error(e);

deploy/builder.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,19 @@ import {
55
} from '@angular-devkit/architect';
66
import { NodeJsSyncHost } from '@angular-devkit/core/node';
77
import deploy from './actions';
8-
import { experimental, join, normalize } from '@angular-devkit/core';
8+
import { experimental, join, normalize, json } from '@angular-devkit/core';
9+
import { Schema as RealDeployOptions } from './schema';
10+
type DeployOptions = RealDeployOptions & json.JsonObject;
11+
912
const ghpages = require('gh-pages');
1013

1114
// Call the createBuilder() function to create a builder. This mirrors
1215
// createJobHandler() but add typings specific to Architect Builders.
1316
export default createBuilder<any>(
14-
async (_: any, context: BuilderContext): Promise<BuilderOutput> => {
17+
async (
18+
options: DeployOptions,
19+
context: BuilderContext
20+
): Promise<BuilderOutput> => {
1521
// The project root is added to a BuilderContext.
1622
const root = normalize(context.workspaceRoot);
1723
const workspace = new experimental.workspace.Workspace(
@@ -41,11 +47,11 @@ export default createBuilder<any>(
4147
await deploy(
4248
ghpages,
4349
context,
44-
join(workspace.root, targets.build.options.outputPath)
50+
join(workspace.root, targets.build.options.outputPath),
51+
options
4552
);
4653
} catch (e) {
47-
console.error('Error when trying to deploy: ');
48-
console.error(e.message);
54+
console.error('Error when trying to deploy: ', e.message);
4955
return { success: false };
5056
}
5157

deploy/schema.json

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
{
2-
"id": "GHPagesDeploySchema",
3-
"title": "GH pages deploy",
4-
"description": "TBD",
5-
"properties": {}
2+
"id": "Schema",
3+
"title": "schema",
4+
"description": "Deployment of Angular CLI applications to GitHub pages",
5+
"properties": {
6+
"baseHref": {
7+
"type": "string",
8+
"description": "Base url for the application being built."
9+
},
10+
"deployUrl": {
11+
"type": "string",
12+
"description": "URL where files will be deployed."
13+
}
14+
}
615
}

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "Deployment from the Angular CLI to GitHub pages",
55
"main": "index.js",
66
"scripts": {
7-
"build": "rm -rf dist && tsc && cp builders.json collection.json package.json dist && cp deploy/schema.json dist/deploy",
7+
"build": "rm -rf dist && json2ts deploy/schema.json > deploy/schema.d.ts && tsc && cp README.md builders.json collection.json package.json dist && cp deploy/schema.json dist/deploy",
88
"test": "jest"
99
},
1010
"schematics": "./collection.json",
@@ -34,13 +34,14 @@
3434
"@types/jest": "^24.0.15",
3535
"@types/node": "^12.0.10",
3636
"jest": "^24.8.0",
37+
"json-schema-to-typescript": "^6.1.3",
3738
"ts-jest": "^24.0.2",
3839
"typescript": "^3.5.2"
3940
},
4041
"peerDependencies": {
41-
"@angular-devkit/architect": "^0.800.6",
42-
"@angular-devkit/core": "^8.0.6",
43-
"@angular-devkit/schematics": "^8.0.6"
42+
"@angular-devkit/architect": ">=0.800.0",
43+
"@angular-devkit/core": ">=8.0.0",
44+
"@angular-devkit/schematics": ">=8.0.0"
4445
},
4546
"dependencies": {
4647
"gh-pages": "^2.0.1"

0 commit comments

Comments
 (0)