Skip to content

Commit 933e588

Browse files
committed
uses promises for options.cname also sets up CI
1 parent e12bef4 commit 933e588

File tree

8 files changed

+380
-25
lines changed

8 files changed

+380
-25
lines changed

.angulardoc.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"repoId": "edad02a0-d76e-46a2-a4cc-8f9dc389b3b9",
3+
"lastSync": 0
4+
}

.circleci/config.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
version: 2
2+
3+
jobs:
4+
5+
deploy:
6+
7+
environment:
8+
GITHUB_ORG: https://[email protected]/angular-schule
9+
GITHUB_NAME: The Buildbot
10+
GITHUB_EMAIL: [email protected]
11+
NAME: angular-cli-ghpages
12+
13+
docker:
14+
- image: circleci/node:10-browsers
15+
steps:
16+
- checkout
17+
18+
19+
- restore_cache:
20+
key: dependency-cache-{{ checksum "package.json" }}
21+
- run: npm i --silent
22+
- save_cache:
23+
key: dependency-cache-{{ checksum "package.json" }}
24+
paths:
25+
- node_modules
26+
27+
28+
- run: cd angular-testdrive
29+
- restore_cache:
30+
key: dependency-cache-{{ checksum "package.json" }}
31+
- run: npm i --silent
32+
- save_cache:
33+
key: dependency-cache-{{ checksum "package.json" }}
34+
paths:
35+
- node_modules
36+
- run: npm run build
37+
- run: ../bin/angular-cli-ghpages --repo "$GITHUB_ORG/$NAME.git" --name "$GITHUB_NAME" --email "$GITHUB_EMAIL" --dir=dist/angular-testdrive --cname=angular-cli-ghpages.angular.schule
38+

.vscode/launch.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"type": "node",
9+
"request": "launch",
10+
"name": "Launch Program",
11+
"cwd": "${workspaceRoot}/angular-testdrive",
12+
"program": "${workspaceFolder}/bin/angular-cli-ghpages",
13+
"args": [
14+
"--dir=dist/angular-testdrive",
15+
"--cname=angular-cli-ghpages.angular.schule"
16+
]
17+
}
18+
]
19+
}

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ ng build --prod --base-href "/REPOSITORY_NAME/"
5656
npx ngh [OPTIONS]
5757
```
5858

59-
or (`<base href="">` stays untouched)
59+
or (`<base href="/">` stays untouched)
6060

6161
```bash
6262
ng build --prod
@@ -73,7 +73,7 @@ Please take a look at the `dist` folder to see whether there is a subfolder with
7373
If yes, you need to specify the deploy directory manually then when using this tool:
7474

7575
```bash
76-
npx ngh --dir dist/[PROJECTNAME]
76+
npx ngh --dir=dist/[PROJECTNAME]
7777
```
7878

7979
I most cases, the `[PROJECTNAME]` can be found in the `angular.json` file at `defaultProject`.
@@ -200,7 +200,7 @@ With `--no-dotfiles` files starting with `.` are ignored.
200200

201201
Run through without making any changes. This can be very usefull, because it outputs what would happend without doing anything.
202202

203-
#### <a id="cname">--cname</a> (will be released soon with v0.5.3)
203+
#### <a id="cname">--cname</a>
204204
* __optional__
205205
* Default: `No CNAME file is generated`
206206
* Example:

angular-testdrive/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"scripts": {
55
"ng": "ng",
66
"start": "ng serve",
7-
"build": "ng build",
7+
"build": "ng build --prod",
88
"test": "ng test",
99
"lint": "ng lint",
1010
"e2e": "ng e2e"

index.js

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ exports.run = function (options) {
99
options = options || {};
1010

1111
if (options.dryRun) {
12-
console.log('*** Dry-run: No changes are applied at all. ***')
12+
console.log('*** Dry-run: No changes are applied at all.')
1313
}
1414

1515
if (options.name && options.email) {
@@ -44,7 +44,7 @@ exports.run = function (options) {
4444
// always clean the cache directory.
4545
// avoids "Error: Remote url mismatch."
4646
if (options.dryRun) {
47-
console.info('Dry-run / SKIPPED: cleaning of the cache directory');
47+
console.info('*** Dry-run / SKIPPED: cleaning of the cache directory');
4848
} else {
4949
ghpages.clean();
5050
}
@@ -61,13 +61,13 @@ exports.run = function (options) {
6161
return access(dir, fs.F_OK)
6262
})
6363
.catch(function handleMissingDistFolder(error) {
64-
console.error('Dist folder does not exist. Check the dir --dir parameter or build the project first!\n');
64+
console.error('*** Dist folder does not exist. Check the dir --dir parameter or build the project first!\n');
6565
return Promise.reject(error);
6666
})
6767
.then(function createNotFoundPage() {
6868

6969
if (options.dryRun) {
70-
console.info('Dry-run / SKIPPED: copying of index.html to 404.html');
70+
console.info('*** Dry-run / SKIPPED: copying of index.html to 404.html');
7171
return;
7272
}
7373

@@ -78,14 +78,37 @@ exports.run = function (options) {
7878
const notFoundPage = path.join(dir, '404.html');
7979

8080
return fse.copy(indexHtml, notFoundPage).
81-
catch(function () {
81+
catch(function (err) {
8282
console.info('index.html could not be copied to 404.html. Continuing without an error.');
83+
console.info('(Hint: are you sure that you have setup the --dir parameter correctly?)');
84+
console.dir(err);
8385
return;
8486
})
8587
})
88+
.then(function createCnameFile() {
89+
90+
if (!options.cname) {
91+
return;
92+
}
93+
94+
const cnameFile = path.join(dir, 'CNAME');
95+
if (options.dryRun) {
96+
console.info('*** Dry-run / SKIPPED: creating of CNAME file with content: ' + options.cname);
97+
return;
98+
}
99+
100+
return fse.writeFile(cnameFile, options.cname)
101+
.then(function () {
102+
console.log('*** CNAME file created');
103+
})
104+
.catch(function (err) {
105+
console.info('*** CNAME file could not be created. Stopping execution.');
106+
throw err;
107+
})
108+
})
86109
.then(function publishViaGhPages() {
87110
if (options.dryRun) {
88-
console.info('Dry-run / SKIPPED: publishing to "' + dir + '" with the following options:', {
111+
console.info('*** Dry-run / SKIPPED: publishing to "' + dir + '" with the following options:', {
89112
dir: dir,
90113
repo: options.repo || 'undefined: current working directory (which must be a git repo in this case) will be used to commit & push',
91114
message: options.message,
@@ -99,24 +122,14 @@ exports.run = function (options) {
99122
return;
100123
}
101124

102-
if (options.cname) {
103-
console.log('CNAME option is present with value: ' + options.cname);
104-
fs.writeFile(path.join(dir, 'CNAME'), options.cname, function (err) {
105-
if (err) {
106-
console.log(err);
107-
} else {
108-
console.log('CNAME file created');
109-
}
110-
})
111-
}
112-
113125
return publish(dir, options)
114126
})
115127
.then(function showSuccess() {
116-
console.log('Successfully published!\n');
128+
console.log('*** Successfully published!\n');
117129
})
118130
.catch(function showError(error) {
119-
console.error('An error occurred!\n', error);
131+
console.error('*** An error occurred!\n');
132+
console.dir(error);
120133
return Promise.reject(error);
121134
});
122135
};

0 commit comments

Comments
 (0)