Skip to content

Commit 95d8603

Browse files
committed
bugfix: params --no-notfound and --no-nojekyll were broken for the standalone version
@fmalcher
1 parent 07f6635 commit 95d8603

File tree

4 files changed

+76
-26
lines changed

4 files changed

+76
-26
lines changed

.vscode/launch.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@
1212
"program": "${workspaceFolder}/src/dist/angular-cli-ghpages",
1313
"outFiles": ["${workspaceFolder}/src/dist/**/*.js"],
1414
"args": [
15-
//"--dry-run",
15+
"--dry-run",
16+
"--no-notfound",
17+
"--no-dotfiles",
18+
"--no-nojekyll",
1619
"--dir=mini-testdrive",
1720
"--cname=angular-cli-ghpages.angular.schule"
1821
],
@@ -31,8 +34,7 @@
3134
],
3235
"cwd": "${workspaceFolder}/src",
3336
"console": "integratedTerminal",
34-
"internalConsoleOptions": "neverOpen",
35-
"port": 9229
37+
"internalConsoleOptions": "neverOpen"
3638
}
3739
]
3840
}

src/angular-cli-ghpages

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,15 @@ commander
5050
)
5151
.option(
5252
'-T, --no-dotfiles',
53-
'Includes dotfiles by default. Otherwise files starting with `.` are ignored.'
53+
'Includes dotfiles by default. Otherwise files starting with `.` are ignored.',
5454
)
5555
.option(
5656
'--no-notfound',
5757
'By default a 404.html file is created, because this is the only known workaround to avoid 404 error messages on GitHub Pages. For Cloudflare Pages we highly recommend to disable the 404.html file by setting this switch to true!',
5858
)
5959
.option(
6060
'--no-nojekyll',
61-
'By default a .nojekyll file is created, because we assume you don\'t want to compile the build again with Jekyll.'
61+
'By default a .nojekyll file is created, because we assume you don\'t want to compile the build again with Jekyll.',
6262
)
6363
.option(
6464
'-c, --cname <domain>',
@@ -82,6 +82,19 @@ var consoleLogger = {
8282
fatal: console.error
8383
};
8484

85+
// !! Important: Commander is renaming the vars here !!
86+
//
87+
// adding no param becomes dotfiles: true
88+
// adding no param becomes notfound: true
89+
// adding no param becomes nojekyll: true
90+
// --no-dotfiles becomes dotfiles: false
91+
// --no-notfound becomes notfound: false
92+
// --no-nojekyll becomes nojekyll: false
93+
94+
// console.log('*** dotfiles', commander.dotfiles)
95+
// console.log('*** notfound', commander.notfound)
96+
// console.log('*** nojekyll', commander.nojekyll)
97+
8598
var dir = path.join(process.cwd(), commander.dir);
8699

87100
engine.run(dir, commander, consoleLogger).catch(function (error) {

src/engine/defaults.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ export const defaults = {
66
name: undefined,
77
email: undefined,
88
dotfiles: true,
9-
noNotfound: false,
10-
noNojekyll: false,
9+
notfound: true,
10+
nojekyll: true,
1111
cname: undefined,
1212
dryRun: false,
1313
remote: 'origin',

src/engine/engine.ts

Lines changed: 54 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ import Git from 'gh-pages/lib/git';
1010

1111
export async function run(
1212
dir: string,
13-
options: Schema,
13+
options: Schema & {
14+
dotfiles: boolean,
15+
notfound: boolean,
16+
nojekyll: boolean
17+
},
1418
logger: logging.LoggerApi
1519
) {
1620
options = await prepareOptions(options, logger);
@@ -42,14 +46,22 @@ export async function run(
4246
export async function prepareOptions(
4347
origOptions: Schema,
4448
logger: logging.LoggerApi
45-
) {
46-
const options = {
49+
): Promise<Schema & {
50+
dotfiles: boolean,
51+
notfound: boolean,
52+
nojekyll: boolean
53+
}> {
54+
const options: Schema & {
55+
dotfiles: boolean,
56+
notfound: boolean,
57+
nojekyll: boolean
58+
} = {
4759
...defaults,
4860
...origOptions
4961
};
5062

5163
// this is the place where the old `noSilent` was enabled
52-
// (which is now always enabled because gh-pages is NOT silent by default)
64+
// (which is now always enabled because gh-pages is NOT silent)
5365
// monkeypatch util.debuglog to get all the extra information
5466
// see https://stackoverflow.com/a/39129886
5567
const util = require('util');
@@ -64,9 +76,19 @@ export async function prepareOptions(
6476
return debuglog(set);
6577
};
6678

79+
// !! Important: Angular-CLI is NOT renaming the vars here !!
80+
// so noDotfiles, noNotfound, and noNojekyll come in with no change
81+
// we map this to dotfiles, notfound, nojekyll to have a consistent pattern
82+
// between Commander and Angular-CLI
6783
if (origOptions.noDotfiles) {
6884
options.dotfiles = !origOptions.noDotfiles;
6985
}
86+
if (origOptions.noNotfound) {
87+
options.notfound = !origOptions.noNotfound;
88+
}
89+
if (origOptions.noNojekyll) {
90+
options.nojekyll = !origOptions.noNojekyll;
91+
}
7092

7193
if (options.dryRun) {
7294
logger.info('Dry-run: No changes are applied at all.');
@@ -173,10 +195,13 @@ async function checkIfDistFolderExists(dir: string) {
173195

174196
async function createNotFoundFile(
175197
dir: string,
176-
options: Schema,
198+
options: {
199+
notfound: boolean,
200+
dryRun?: boolean
201+
},
177202
logger: logging.LoggerApi
178203
) {
179-
if (options.noNotfound) {
204+
if (!options.notfound) {
180205
return;
181206
}
182207

@@ -203,7 +228,10 @@ async function createNotFoundFile(
203228

204229
async function createCnameFile(
205230
dir: string,
206-
options: Schema,
231+
options: {
232+
cname?: string,
233+
dryRun?: boolean
234+
},
207235
logger: logging.LoggerApi
208236
) {
209237
if (!options.cname) {
@@ -228,16 +256,19 @@ async function createCnameFile(
228256

229257
async function createNojekyllFile(
230258
dir: string,
231-
options: Schema,
259+
options: {
260+
nojekyll: boolean,
261+
dryRun?: boolean
262+
},
232263
logger: logging.LoggerApi
233264
) {
234-
if (options.noNojekyll) {
265+
if (!options.nojekyll) {
235266
return;
236267
}
237268

238269
const nojekyllFile = path.join(dir, '.nojekyll');
239270
if (options.dryRun) {
240-
logger.info('Dry-run / SKIPPED: creating an empty .nojekyll file');
271+
logger.info('Dry-run / SKIPPED: creating a .nojekyll file');
241272
return;
242273
}
243274

@@ -252,24 +283,28 @@ async function createNojekyllFile(
252283
async function publishViaGhPages(
253284
ghPages: GHPages,
254285
dir: string,
255-
options: Schema,
286+
options: Schema & {
287+
dotfiles: boolean,
288+
notfound: boolean,
289+
nojekyll: boolean
290+
},
256291
logger: logging.LoggerApi
257292
) {
258293
if (options.dryRun) {
259294
logger.info(
260-
`Dry-run / SKIPPED: publishing folder "${dir}" with the following options: ` +
295+
`Dry-run / SKIPPED: publishing folder '${dir}' with the following options: ` +
261296
JSON.stringify(
262297
{
263298
dir,
264-
repo: options.repo || 'falsy: current working directory (which must be a git repo in this case) will be used to commit & push',
299+
repo: options.repo || 'current working directory (which must be a git repo in this case) will be used to commit & push',
265300
message: options.message,
266301
branch: options.branch,
267-
name: options.name || 'falsy: local or global git username will be used',
268-
email: options.email || 'falsy: local or global git user email will be used',
269-
dotfiles: options.dotfiles || 'falsy: dotfiles are included by default',
270-
noNotfound: options.noNotfound || 'falsy: a 404.html file will be created by default',
271-
noNojekyll: options.noNojekyll || 'falsy: a .nojekyll file will be created by default',
272-
cname: options.cname || 'falsy: no CNAME file will be created'
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'
273308
},
274309
null,
275310
' '

0 commit comments

Comments
 (0)