Skip to content

Commit 6f0b8f5

Browse files
committed
first working version :-)
1 parent 5c08218 commit 6f0b8f5

File tree

7 files changed

+217
-132
lines changed

7 files changed

+217
-132
lines changed

README.md

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# angular-cli-ghpages
22
[![NPM version][npm-image]][npm-url]
33
[![CircleCI](https://circleci.com/gh/angular-schule/angular-cli-ghpages.svg?style=svg)](https://circleci.com/gh/angular-schule/angular-cli-ghpages)
4+
[![The MIT License](https://img.shields.io/badge/license-MIT-orange.svg?color=blue&style=flat-square)](http://opensource.org/licenses/MIT)
45

56
<!--
67
TODO: cool screenshot with animated gif
@@ -18,20 +19,23 @@ Deploy your Angular app to GitHub pages directly from the Angular CLI! 🚀
1819
A detailed changelog is available in the [releases](https://github.com/angular-schule/angular-cli-ghpages/releases) section.
1920

2021
In the past this project was a standalone program.
21-
This is still possible.
22-
See the documentation at (https://github.com/angular-schule/angular-cli-ghpages/blob/master/README_standalone.md)[README_standalone].
22+
This is still possible.
23+
See the documentation at [README_standalone](README_standalone).
2324

2425

2526
## ⚠️ Prerequisites <a name="prerequisites"></a>
2627

27-
This action has the following prerequisites:
28+
This command has the following prerequisites:
2829

2930
- Git 1.9 or higher (execute `git --version` to check your version)
3031
- Angular project created via [Angular CLI](https://github.com/angular/angular-cli)
3132

3233

3334
## 🚀 Quick-start <a name="quickstart"></a>
3435

36+
This quickstart assumes that you are starting from scratch.
37+
If you alreay have an existing Angular project on GitHub, skip step 1 and 2.
38+
3539
1. Install the next version of the Angular CLI (v8.3.0-next.0 or greater)
3640
and create a new Angular project.
3741

@@ -41,38 +45,65 @@ This action has the following prerequisites:
4145
cd hello-world
4246
```
4347

44-
2. Add `angular-cli-ghpages` to your project.
48+
2. By default the Angular CLI initializes a git repository for you.
49+
To add a new remote for GitHub, use the `git remote add` command:
50+
51+
```sh
52+
git remote add origin https://github.com/<username>/<repositoryname>.git
53+
```
54+
55+
Hints:
56+
* Create a new empty GithHub repository first.
57+
* Replace `<username>` and `<repositoryname>` with your username from GitHub and the name of your new repository.
58+
* Please enter the URL `https://github.com/<username>/<repositoryname>.git` into your browser – you should see your existing repository on GitHub.
59+
* Please double-check that you have the necessary rights to make changes to the given project!
60+
61+
3. Add `angular-cli-ghpages` to your project.
4562

4663
```sh
4764
ng add angular-cli-ghpages
4865
```
4966

50-
3. Deploy your project to Github pages with all default settings.
67+
4. Deploy your project to Github pages with all default settings.
5168
Your project will be automatically build in production mode.
5269

5370
```sh
5471
ng run hello-world:deploy
5572
```
5673

74+
5. Your project should be available at `http(s)://<username>.github.io/<projectname>`.
75+
Learn more about GitHub pages on the [official website](https://pages.github.com/).
76+
77+
78+
## Options
79+
80+
- `--base-href` - specifies the base url for the application being built. Same as `ng build --base-href=XXX`.
81+
- `--configuration`
82+
- TODO: document all the other options!
83+
84+
5785
## 🏁 Next milestones <a name="milestones"></a>
5886

5987
We are glad that we have an integration into the CLI again.
6088
But we are looking forward to the following features:
6189

62-
* an interactive command-line prompt that guides you through the available options and outputs a `angular-cli-ghpages.json` file
90+
* an interactive command-line prompt that guides you through the available options
91+
* a configuration file (`angular-cli-ghpages.json`) to avoid all these command-line cmd options
6392

64-
We look forward to any help. PRs are welcome!
93+
We look forward to any help. PRs are welcome! 😃
6594

6695
## ⁉️ FAQ <a name="faq"></a>
6796

6897
Before posting any issue, [please read the FAQ first](https://github.com/angular-schule/angular-cli-ghpages/wiki/FAQ).
98+
See the contributors documentation at [README_contributors](README_contributors) if you want to debug and test this project.
99+
69100

70101
## License
71102
Code released under the [MIT license](LICENSE).
72103

73104
<hr>
74105

75-
<img src="http://assets.angular.schule/logo-angular-schule.png" height="60">
106+
<img src="https://assets.angular.schule/logo-angular-schule.png" height="60">
76107

77108
### &copy; 2019 https://angular.schule
78109

README_contributors.md

Lines changed: 103 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,110 @@
11
# angular-cli-ghpages
22

3-
## How to start
3+
## How to start <a name="start"></a>
4+
5+
tl;dr – execute this:
46

57
```
68
npm i
79
npm run build
810
npm test
9-
```
11+
```
12+
13+
14+
## Local development <a name="local-dev"></a>
15+
16+
If you want to try the latest package locally without installing it from npm, use the following instructions.
17+
This may be useful when you want to try the latest non published version of this library or you want to make a contribution.
18+
19+
Follow the instructions for [checking and updating the Angular CLI version](#angular-cli) and then link the package.
20+
21+
22+
### 1. Angular CLI <a name="angular-cli"></a>
23+
24+
1. Install the next version of the Angular CLI.
25+
26+
```sh
27+
npm install -g @angular/cli@next
28+
```
29+
30+
2. Run `ng --version`, make sure you have angular CLI version v8.3.0-next.0 or greater.
31+
32+
3. Update your existing project using the command:
33+
34+
```sh
35+
ng update @angular/cli @angular/core --next=true
36+
```
37+
38+
39+
### 2. npm link
40+
41+
Use the following instructions to make `angular-cli-ghpages` available locally via `npm link`.
42+
43+
1. Clone the project
44+
45+
```sh
46+
git clone https://github.com/angular-schule/angular-cli-ghpages.git
47+
cd angular-cli-ghpages
48+
```
49+
50+
2. Install the dependencies
51+
52+
```sh
53+
npm install
54+
```
55+
56+
3. Build the project:
57+
58+
```sh
59+
npm run build
60+
```
61+
62+
4. Create a local npm link:
63+
64+
```sh
65+
cd dist
66+
npm link
67+
```
68+
69+
70+
### 3. Adding to an Angular project - ng add <a name="local-dev-add"></a>
71+
72+
Once you have completed the previous steps to npm link the local copy of `angular-cli-ghpages`,
73+
follow these steps to use it in a local angular project.
74+
75+
1. Enter the project's directory
76+
77+
```sh
78+
cd your-angular-project
79+
```
80+
81+
2. Add the local version of `angular-cli-ghpages`.
82+
83+
```sh
84+
npm link angular-cli-ghpages
85+
```
86+
87+
3. Now execute the schematic.
88+
89+
```sh
90+
ng add angular-cli-ghpages
91+
```
92+
93+
4. Now you can deploy your angular app to Github pages.
94+
95+
```sh
96+
ng run your-angular-project:deploy
97+
```
98+
99+
5. You can remove the link later by running `npm unlink`
100+
101+
102+
### 4. Testing <a name="testing"></a>
103+
104+
Testing is done with [Jest](https://jestjs.io/).
105+
To run the tests:
106+
107+
```sh
108+
cd angular-cli-ghpages
109+
npm test
110+
```

deploy/actions.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,17 @@ export default async function deploy(
1515
throw new Error('Cannot execute the build target');
1616
}
1717

18-
context.logger.info(`📦 Building "${context.target.project}"`);
18+
const configuration = options.configuration ? options.configuration : 'production'
19+
20+
context.logger.info(`📦 Building "${ context.target.project }". Configuration: "${ configuration }".${ options.baseHref ? ' Your base-href: "' + options.baseHref + '"' : '' }`);
1921

2022
const build = await context.scheduleTarget({
2123
target: 'build',
2224
project: context.target.project,
23-
configuration: 'production'
24-
}, options);
25+
configuration
26+
}, {
27+
baseHref: options.baseHref ? options.baseHref : null
28+
});
2529
await build.result;
2630

2731
await engine.run(

deploy/builder.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ export default createBuilder<any>(
4848
options
4949
);
5050
} catch (e) {
51-
context.logger.error('Error when trying to deploy: ', e.message);
51+
context.logger.error('Error when trying to deploy:', e);
52+
console.error(e);
5253
return { success: false };
5354
}
5455

engine/engine.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export async function run(dir: string, options: RealDeployOptions, logger: loggi
1515
// always clean the cache directory.
1616
// avoids "Error: Remote url mismatch."
1717
if (options.dryRun) {
18-
logger.info('*** Dry-run / SKIPPED: cleaning of the cache directory');
18+
logger.info('Dry-run / SKIPPED: cleaning of the cache directory');
1919
} else {
2020
ghpages.clean();
2121
}
@@ -26,10 +26,10 @@ export async function run(dir: string, options: RealDeployOptions, logger: loggi
2626
await createCnameFile(dir, options, logger);
2727
await publishViaGhPages(ghpages, dir, options, logger);
2828

29-
logger.info('*** 🚀 Successfully published! Have a nice day!');
29+
logger.info('🚀 Successfully published via angular-cli-ghpages! Have a nice day!');
3030
}
3131
catch (error) {
32-
logger.error('*** An error occurred!', error);
32+
logger.error(' An error occurred!');
3333
throw error;
3434
}
3535
};
@@ -51,7 +51,7 @@ function prepareOptions(origOptions: RealDeployOptions, logger: logging.LoggerAp
5151
}
5252

5353
if (options.dryRun) {
54-
logger.info('*** Dry-run: No changes are applied at all.');
54+
logger.info('Dry-run: No changes are applied at all.');
5555
}
5656

5757
if (options.name && options.email) {
@@ -86,14 +86,14 @@ function prepareOptions(origOptions: RealDeployOptions, logger: logging.LoggerAp
8686

8787
async function checkIfDistFolderExists(dir: string) {
8888
if (await !fse.pathExists(dir)) {
89-
throw new Error('*** Dist folder does not exist. Check the dir --dir parameter or build the project first!');
89+
throw new Error('Dist folder does not exist. Check the dir --dir parameter or build the project first!');
9090
}
9191
}
9292

9393
async function createNotFoundPage(dir: string, options: RealDeployOptions, logger: logging.LoggerApi) {
9494

9595
if (options.dryRun) {
96-
logger.info('*** Dry-run / SKIPPED: copying of index.html to 404.html');
96+
logger.info('Dry-run / SKIPPED: copying of index.html to 404.html');
9797
return;
9898
}
9999

@@ -108,7 +108,7 @@ async function createNotFoundPage(dir: string, options: RealDeployOptions, logge
108108
return await fse.copy(indexHtml, notFoundPage);
109109
}
110110
catch (err) {
111-
logger.info('index.html could not be copied to 404.html. This does not look like an angular project?!');
111+
logger.info('index.html could not be copied to 404.html. This does not look like an angular-cli project?!');
112112
logger.info('(Hint: are you sure that you have setup the directory correctly?)');
113113
logger.debug('Diagnostic info', err);
114114
return;
@@ -123,23 +123,23 @@ async function createCnameFile(dir: string, options: RealDeployOptions, logger:
123123

124124
const cnameFile = path.join(dir, 'CNAME');
125125
if (options.dryRun) {
126-
logger.info('*** Dry-run / SKIPPED: creating of CNAME file with content: ' + options.cname);
126+
logger.info('Dry-run / SKIPPED: creating of CNAME file with content: ' + options.cname);
127127
return;
128128
}
129129

130130
try {
131131
await fse.writeFile(cnameFile, options.cname);
132-
logger.info('*** CNAME file created');
132+
logger.info('CNAME file created');
133133
}
134134
catch (err) {
135-
logger.error('*** CNAME file could not be created. Stopping execution.');
135+
logger.error('CNAME file could not be created. Stopping execution.');
136136
throw err;
137137
}
138138
}
139139

140140
async function publishViaGhPages(ghPages: GHPages, dir: string, options: RealDeployOptions, logger: logging.LoggerApi) {
141141
if (options.dryRun) {
142-
logger.info('*** Dry-run / SKIPPED: publishing folder "' + dir + '" with the following options:', {
142+
logger.info(`Dry-run / SKIPPED: publishing folder "${ dir }" with the following options: ` + JSON.stringify({
143143
dir: dir,
144144
repo: options.repo || 'falsy: current working directory (which must be a git repo in this case) will be used to commit & push',
145145
message: options.message,
@@ -148,7 +148,7 @@ async function publishViaGhPages(ghPages: GHPages, dir: string, options: RealDep
148148
silent: options.silent || 'falsy: logging is in silent mode by default',
149149
dotfiles: options.dotfiles || 'falsy: dotfiles are included by default',
150150
cname: options.cname || 'falsy: no CNAME file will be created',
151-
} as any);
151+
}) as any);
152152
return;
153153
}
154154

0 commit comments

Comments
 (0)