Skip to content

Commit 3113a96

Browse files
committed
copies index.html to 404.html by default, fixes #10
1 parent b91b2ab commit 3113a96

File tree

2 files changed

+39
-17
lines changed

2 files changed

+39
-17
lines changed

index.js

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
var path = require('path'),
22
fs = require('fs'),
3+
fse = require('fs-extra'),
34
ghpages = require('gh-pages'),
45
denodeify = require('denodeify');
56

@@ -36,10 +37,10 @@ exports.run = function (options) {
3637

3738
// always clean the cache directory.
3839
// avoids "Error: Remote url mismatch."
39-
if (!options.dryRun) {
40-
ghpages.clean();
41-
} else {
40+
if (options.dryRun) {
4241
console.info('Dry-run / SKIPPED: cleaning of the cache directory');
42+
} else {
43+
ghpages.clean();
4344
}
4445

4546
var access = publish = denodeify(fs.access);
@@ -50,18 +51,35 @@ exports.run = function (options) {
5051
}
5152

5253
return go()
53-
.then(function () {
54+
.then(function checkIfDistFolderExists() {
5455
return access(dir, fs.F_OK)
5556
})
56-
.catch(function (error) {
57+
.catch(function handleMissingDistFolder(error) {
5758
console.error('Dist folder does not exist. Check the dir --dir parameter or build the project first!\n');
5859
return Promise.reject(error);
5960
})
60-
.then(function () {
61-
if (!options.dryRun) {
62-
return publish(dir, options)
63-
} else {
64-
console.info('Dry-run / SKIPPED: publishing to "' + dir+ '" with the following options:', {
61+
.then(function createNotFoundPage() {
62+
63+
if (options.dryRun) {
64+
console.info('Dry-run / SKIPPED: copying of index.html to 404.html');
65+
return;
66+
}
67+
68+
// Note:
69+
// There is no guarantee that there will be an index.html file,
70+
// as the developer may specify a custom index file.
71+
const indexHtml = path.join(dir, 'index.html');
72+
const notFoundPage = path.join(dir, '404.html');
73+
74+
return fse.copy(indexHtml, notFoundPage).
75+
catch(function () {
76+
console.info('index.html could not be copied to 404.html. Continuing without an error.');
77+
return;
78+
})
79+
})
80+
.then(function publishViaGhPages() {
81+
if (options.dryRun) {
82+
console.info('Dry-run / SKIPPED: publishing to "' + dir + '" with the following options:', {
6583
dir: dir,
6684
repo: options.repo || 'undefined: current working directory (which must be a git repo in this case) will be used to commit & push',
6785
message: options.message,
@@ -71,12 +89,15 @@ exports.run = function (options) {
7189
noDotfiles: options.noDotfiles || 'undefined: dotfiles are included by default',
7290
dryRun: options.dryRun
7391
});
92+
return;
7493
}
94+
95+
return publish(dir, options)
7596
})
76-
.then(function () {
97+
.then(function showSuccess() {
7798
console.log('Successfully published!\n');
7899
})
79-
.catch(function (error) {
100+
.catch(function showError(error) {
80101
console.error('An error occurred!\n', error);
81102
return Promise.reject(error);
82103
});

package.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@
1616
},
1717
"author": {
1818
"name": "Angular-Buch Team",
19-
"email": "team@angular2buch.de"
19+
"email": "team@angular-buch.com"
2020
},
2121
"license": "MIT",
2222
"dependencies": {
23-
"gh-pages": "~0.12.0",
24-
"denodeify": "~1.2.1",
25-
"commander": "~2.9.0"
23+
"gh-pages": "0.12.0",
24+
"denodeify": "1.2.1",
25+
"commander": "2.9.0",
26+
"fs-extra": "3.0.1"
2627
},
27-
"keywords": ["angular2", "angular-cli", "git", "github pages", "gh-pages", "ghpages", "angular-cli-ghpages", "angular-cli-github-pages"]
28+
"keywords": ["angular", "angular2", "angular-cli", "git", "github pages", "gh-pages", "ghpages", "angular-cli-ghpages", "angular-cli-github-pages"]
2829
}

0 commit comments

Comments
 (0)