Skip to content

Commit accfd97

Browse files
authored
"feat: add support for "add" parameter in angular-cli-ghpages" (#188)
1 parent 97271a9 commit accfd97

File tree

8 files changed

+75
-38
lines changed

8 files changed

+75
-38
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ node_modules
66
*.swp
77
*.swo
88
*.d.ts
9+
.idea
910

1011
*.classpath
1112
*.project

README.md

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
- [--no-notfound](#no-notfound)
2828
- [--no-nojekyll](#no-nojekyll)
2929
- [--cname](#cname)
30+
- [--add](#add)
3031
- [--dry-run](#dry-run)
3132
7. [📁 Configuration File](#configuration-file)
3233
8. [🌍 Environments](#environments)
@@ -77,9 +78,9 @@ You can also and modify your `angular.json` to archive the same:
7778
```
7879

7980
For your convenience, you can also use `prerenderTarget` (which adds the suffix `:prerender:production`).
80-
There is no support for `universalBuildTarget` or `serverTarget` because Github Pages only supports static assets and no Server-Side Rendering!
81+
There is no support for `universalBuildTarget` or `serverTarget` because GitHub Pages only supports static assets and no Server-Side Rendering!
8182

82-
We will then try to deploy the `dist/test/browser` folder to Github Pages.
83+
We will then try to deploy the `dist/test/browser` folder to GitHub Pages.
8384
If this is not the folder that you want to serve, you should explicitly specify the directory with the `--dir` option:
8485

8586
```bash
@@ -111,7 +112,7 @@ If you already have an existing Angular project on GitHub, skip step 1 and 2.
111112
cd your-angular-project
112113
```
113114

114-
2. By default the Angular CLI initializes a Git repository for you.
115+
2. By default, the Angular CLI initializes a Git repository for you.
115116
To add a new remote for GitHub, use the `git remote add` command:
116117

117118
```sh
@@ -167,8 +168,8 @@ ng add angular-cli-ghpages --project MYPROJECTNAME
167168
## 🚀 Continuous Delivery <a name="continuous-delivery"></a>
168169

169170
If you run this command from a CI/CD environment, the deployment will most likely not work out of the box.
170-
For security reasons, those environments usually have read-only privileges or you haven't set up Git correctly.
171-
Therefore you should take a look at ["personal access tokens" `GH_TOKEN`](https://help.github.com/articles/creating-an-access-token-for-command-line-use/) (which works everywhere) and the ["installation access token" `GITHUB_TOKEN`](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/authenticating-with-the-github_token) (which is exclusively provided by GitHub actions).
171+
For security reasons, those environments usually have read-only privileges, or you haven't set up Git correctly.
172+
Therefore, you should take a look at ["personal access tokens" `GH_TOKEN`](https://help.github.com/articles/creating-an-access-token-for-command-line-use/) (which works everywhere) and the ["installation access token" `GITHUB_TOKEN`](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/authenticating-with-the-github_token) (which is exclusively provided by GitHub actions).
172173
In short: a token replaces username and password and is a safer choice because a token can be revoked at any time.
173174

174175
All you need to do is to set an environment variable called `GH_TOKEN` (or `PERSONAL_TOKEN`) in your CI/CD environment.
@@ -201,7 +202,7 @@ ng deploy --repo=https://github.com/<username>/<repositoryname>.git --name="Your
201202
- `ng deploy` – The tag `<base href="/">` remains unchanged in your `index.html`
202203
- `ng deploy --base-href=/the-repositoryname/` – The tag `<base href="/the-repositoryname/">` is added to your `index.html`
203204

204-
Specifies the base URL for the application being built.
205+
Specify the base URL for the application being built.
205206
Same as `ng build --base-href=/XXX/`
206207

207208
**ℹ️ Please read the next lines carefully, or you will get 404 errors in case of a wrong configuration!**
@@ -266,7 +267,7 @@ ng deploy --build-target=test
266267
- `ng deploy` – Angular project is build in production mode before the deployment
267268
- `ng deploy --no-build` – Angular project is NOT build
268269

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

@@ -280,7 +281,7 @@ This specifies the target repository. If none is given as an option, the reposit
280281

281282
By default, this command assumes that the current working directory is a Git repository,
282283
and that you want to push changes to the `origin` remote.
283-
If instead your files are not in a git repository, or if you want to push to another repository,
284+
If instead, your files are not in a git repository, or if you want to push to another repository,
284285
you can provide the repository URL in the `repo` option.
285286

286287
> **ℹ️ Hint**
@@ -340,8 +341,9 @@ With `--no-dotfiles` files starting with `.` are ignored.
340341
- `ng deploy` – A `404.html` file is created by default.
341342
- `ng deploy --no-notfound` – No `404.html` file is created.
342343

343-
By default a `404.html` file is created, because this is the only known workaround to avoid 404 error messages on GitHub Pages.
344-
For Cloudflare Pages we highly recommend to disable the `404.html` file by setting this switch to true! see [#178](https://github.com/angular-schule/angular-cli-ghpages/issues/178)
344+
By default, a `404.html` file is created, because this is the only known workaround to avoid 404 error messages on GitHub Pages.
345+
For Cloudflare Pages we highly recommend to disable the `404.html` file by setting this switch to true!
346+
See [#178](https://github.com/angular-schule/angular-cli-ghpages/issues/178)
345347

346348
#### --no-nojekyll <a name="no-nojekyll"></a>
347349

@@ -351,7 +353,7 @@ For Cloudflare Pages we highly recommend to disable the `404.html` file by setti
351353
- `ng deploy` – A `.nojekyll` file is created by default.
352354
- `ng deploy --no-nojekyll` – No `.nojekyll` file is created.
353355

354-
By default a `.nojekyll` file is created, because we assume you don't want to compile the build again with Jekyll.
356+
By default, a `.nojekyll` file is created, because we assume you don't want to compile the build again with Jekyll.
355357

356358
**Explanation:**
357359
By creating such a file in the root of your pages repo, you will bypass the Jekyll static site generator on GitHub Pages.
@@ -370,6 +372,17 @@ The same applies to `.txt` files in your assets folder: They will just disappear
370372
A CNAME file will be created enabling you to use a custom domain.
371373
[More information on GitHub Pages using a custom domain](https://help.github.com/articles/using-a-custom-domain-with-github-pages/).
372374

375+
#### --add <a name="add"></a>
376+
377+
- **optional**
378+
- Default: `false` (boolean) – The existing files will be removed from the branch you'll be pushing to as expected.
379+
- Example:
380+
- `ng deploy --add=true`
381+
382+
If is set to `true`, it will only add, and never remove existing files.
383+
By default, existing files in the target branch are removed before adding the ones.
384+
[More information](https://www.npmjs.com/package/gh-pages#optionsadd).
385+
373386
#### --dir <a name="dir"></a>
374387

375388
- **optional**
@@ -439,7 +452,7 @@ Now you can just run `ng deploy` without all the options in the command line!
439452
440453
## 🌍 Environments <a name="environments"></a>
441454

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

445458
1. [GitHub Actions](https://angular.schule/blog/2020-01-everything-github)

docs/README_standalone.md

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# angular-cli-ghpages: README for the standalone program
22

3-
In the past this project was a standalone program.
3+
In the past, this project was a standalone program.
44
This is still possible.
55

66
## Installation & Setup
@@ -85,7 +85,7 @@ Output the version number. Please provide the version number on any bug report!
8585
8686
By default, **gh-pages** assumes that the current working directory is a git repository,
8787
and that you want to push changes to the `origin` remote.
88-
If instead your files are not in a git repository, or if you want to push to another repository,
88+
If instead, your files are not in a git repository, or if you want to push to another repository,
8989
you can provide the repository URL in the `repo` option.
9090
9191
#### --message <a name="message"></a>
@@ -125,7 +125,7 @@ In this case provide both `name` and `email` string values to identify the commi
125125
- Default: `dist`
126126
127127
Directory for all published sources, relative to the current working directory.
128-
**Starting with Angular CLI 6 the build artifacts will be put in a subfolder under `dist`.
128+
**Starting with Angular CLI 6, the build artifacts will be put in a subfolder under `dist`.
129129
Please take a look at the `dist` folder to see whether there is a subfolder with your project's name or not.**
130130

131131
This option can be used to deploy completely different folders,
@@ -139,7 +139,7 @@ which are not related at all to angular.
139139
- `npx angular-cli-ghpages` -- Dotfiles are included by default.
140140
- `npx angular-cli-ghpages --no-dotfiles` -- Dotfiles are ignored.
141141

142-
The command includes dotfiles by default (e.g `.htaccess` will be committed)
142+
The command includes dotfiles by default (e.g. `.htaccess` will be committed)
143143
With `--no-dotfiles` files starting with `.` are ignored.
144144

145145
#### --dry-run <a name="dry-run"></a>
@@ -161,6 +161,17 @@ Run through without making any changes. This can be very usefull, because it out
161161

162162
A CNAME file will be created enabling you to use a custom domain. [More information on Github Pages using a custom domain](https://help.github.com/articles/using-a-custom-domain-with-github-pages/).
163163

164+
#### --add <a name="add"></a>
165+
166+
- **optional**
167+
- Default: `false` (boolean) – The existing files will be removed from the branch you'll be pushing to as expected.
168+
- Example:
169+
- `npx angular-cli-ghpages --add=true`
170+
171+
If is set to `true`, it will only add, and never remove existing files.
172+
By default, existing files in the target branch are removed before adding the ones.
173+
[More information](https://www.npmjs.com/package/gh-pages#optionsadd).
174+
164175
## FAQ
165176
166177
Before posting any issue, [please read the FAQ first](https://github.com/angular-schule/angular-cli-ghpages/wiki/FAQ).

src/angular-cli-ghpages

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ commander
6565
'Generate a CNAME file for the specified domain.',
6666
defaults.cname
6767
)
68+
.option(
69+
'-a, --add',
70+
'Only add, and never remove existing files from the GitHub pages branch.',
71+
defaults.add
72+
)
6873
.option(
6974
'--dry-run',
7075
'For testing: Run through without making any changes.',

src/deploy/schema.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@
7171
"description": "Generate a CNAME file for the specified domain.",
7272
"default": ""
7373
},
74+
"add": {
75+
"type": "boolean",
76+
"description": "Only add, and never remove existing files from the GitHub pages branch.",
77+
"default": false
78+
},
7479
"dir": {
7580
"type": "string",
7681
"description": "Overrides the directory for all published sources, relative to the current working directory.",

src/engine/defaults.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export const defaults = {
99
notfound: true,
1010
nojekyll: true,
1111
cname: undefined,
12+
add: false,
1213
dryRun: false,
1314
remote: 'origin',
1415
git: 'git'

src/engine/engine.ts

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { logging } from '@angular-devkit/core';
1+
import {logging} from '@angular-devkit/core';
22
import * as fse from 'fs-extra';
33
import * as path from 'path';
44

5-
import { Schema } from '../deploy/schema';
6-
import { GHPages } from '../interfaces';
7-
import { defaults } from './defaults';
5+
import {Schema} from '../deploy/schema';
6+
import {GHPages} from '../interfaces';
7+
import {defaults} from './defaults';
88

99
import Git from 'gh-pages/lib/git';
1010

@@ -293,22 +293,23 @@ async function publishViaGhPages(
293293
if (options.dryRun) {
294294
logger.info(
295295
`Dry-run / SKIPPED: publishing folder '${dir}' with the following options: ` +
296-
JSON.stringify(
297-
{
298-
dir,
299-
repo: options.repo || 'current working directory (which must be a git repo in this case) will be used to commit & push',
300-
message: options.message,
301-
branch: options.branch,
302-
name: options.name ? `the name '${options.username} will be used for the commit` : 'local or global git user name will be used for the commit',
303-
email: options.email ? `the email '${options.cname} will be used for the commit` : 'local or global git user email will be used for the commit',
304-
dotfiles: options.dotfiles ? `files starting with dot ('.') will be included` : `files starting with dot ('.') will be ignored`,
305-
notfound: options.notfound ? 'a 404.html file will be created' : 'a 404.html file will NOT be created',
306-
nojekyll: options.nojekyll ? 'a .nojekyll file will be created' : 'a .nojekyll file will NOT be created',
307-
cname: options.cname ? `a CNAME file with the content '${options.cname}' will be created` : 'a CNAME file will NOT be created'
308-
},
309-
null,
310-
' '
311-
)
296+
JSON.stringify(
297+
{
298+
dir,
299+
repo: options.repo || 'current working directory (which must be a git repo in this case) will be used to commit & push',
300+
message: options.message,
301+
branch: options.branch,
302+
name: options.name ? `the name '${options.username} will be used for the commit` : 'local or global git user name will be used for the commit',
303+
email: options.email ? `the email '${options.cname} will be used for the commit` : 'local or global git user email will be used for the commit',
304+
dotfiles: options.dotfiles ? `files starting with dot ('.') will be included` : `files starting with dot ('.') will be ignored`,
305+
notfound: options.notfound ? 'a 404.html file will be created' : 'a 404.html file will NOT be created',
306+
nojekyll: options.nojekyll ? 'a .nojekyll file will be created' : 'a .nojekyll file will NOT be created',
307+
cname: options.cname ? `a CNAME file with the content '${options.cname}' will be created` : 'a CNAME file will NOT be created',
308+
add: options.add ? 'all files will be added to the branch. Existing files will not be removed' : 'existing files will be removed from the branch before adding the new ones',
309+
},
310+
null,
311+
' '
312+
)
312313
);
313314
return;
314315
}

src/package-lock.json

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

0 commit comments

Comments
 (0)