Skip to content

Commit

Permalink
bugfix: params --no-notfound and --no-nojekyll were broken for the st…
Browse files Browse the repository at this point in the history
…andalone version

@fmalcher
  • Loading branch information
JohannesHoppe committed Jan 27, 2024
1 parent 07f6635 commit 95d8603
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 26 deletions.
8 changes: 5 additions & 3 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
"program": "${workspaceFolder}/src/dist/angular-cli-ghpages",
"outFiles": ["${workspaceFolder}/src/dist/**/*.js"],
"args": [
//"--dry-run",
"--dry-run",
"--no-notfound",
"--no-dotfiles",
"--no-nojekyll",
"--dir=mini-testdrive",
"--cname=angular-cli-ghpages.angular.schule"
],
Expand All @@ -31,8 +34,7 @@
],
"cwd": "${workspaceFolder}/src",
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"port": 9229
"internalConsoleOptions": "neverOpen"
}
]
}
17 changes: 15 additions & 2 deletions src/angular-cli-ghpages
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ commander
)
.option(
'-T, --no-dotfiles',
'Includes dotfiles by default. Otherwise files starting with `.` are ignored.'
'Includes dotfiles by default. Otherwise files starting with `.` are ignored.',
)
.option(
'--no-notfound',
'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!',
)
.option(
'--no-nojekyll',
'By default a .nojekyll file is created, because we assume you don\'t want to compile the build again with Jekyll.'
'By default a .nojekyll file is created, because we assume you don\'t want to compile the build again with Jekyll.',
)
.option(
'-c, --cname <domain>',
Expand All @@ -82,6 +82,19 @@ var consoleLogger = {
fatal: console.error
};

// !! Important: Commander is renaming the vars here !!
//
// adding no param becomes dotfiles: true
// adding no param becomes notfound: true
// adding no param becomes nojekyll: true
// --no-dotfiles becomes dotfiles: false
// --no-notfound becomes notfound: false
// --no-nojekyll becomes nojekyll: false

// console.log('*** dotfiles', commander.dotfiles)
// console.log('*** notfound', commander.notfound)
// console.log('*** nojekyll', commander.nojekyll)

var dir = path.join(process.cwd(), commander.dir);

engine.run(dir, commander, consoleLogger).catch(function (error) {
Expand Down
4 changes: 2 additions & 2 deletions src/engine/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ export const defaults = {
name: undefined,
email: undefined,
dotfiles: true,
noNotfound: false,
noNojekyll: false,
notfound: true,
nojekyll: true,
cname: undefined,
dryRun: false,
remote: 'origin',
Expand Down
73 changes: 54 additions & 19 deletions src/engine/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ import Git from 'gh-pages/lib/git';

export async function run(
dir: string,
options: Schema,
options: Schema & {
dotfiles: boolean,
notfound: boolean,
nojekyll: boolean
},
logger: logging.LoggerApi
) {
options = await prepareOptions(options, logger);
Expand Down Expand Up @@ -42,14 +46,22 @@ export async function run(
export async function prepareOptions(
origOptions: Schema,
logger: logging.LoggerApi
) {
const options = {
): Promise<Schema & {
dotfiles: boolean,
notfound: boolean,
nojekyll: boolean
}> {
const options: Schema & {
dotfiles: boolean,
notfound: boolean,
nojekyll: boolean
} = {
...defaults,
...origOptions
};

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

// !! Important: Angular-CLI is NOT renaming the vars here !!
// so noDotfiles, noNotfound, and noNojekyll come in with no change
// we map this to dotfiles, notfound, nojekyll to have a consistent pattern
// between Commander and Angular-CLI
if (origOptions.noDotfiles) {
options.dotfiles = !origOptions.noDotfiles;
}
if (origOptions.noNotfound) {
options.notfound = !origOptions.noNotfound;
}
if (origOptions.noNojekyll) {
options.nojekyll = !origOptions.noNojekyll;
}

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

async function createNotFoundFile(
dir: string,
options: Schema,
options: {
notfound: boolean,
dryRun?: boolean
},
logger: logging.LoggerApi
) {
if (options.noNotfound) {
if (!options.notfound) {
return;
}

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

async function createCnameFile(
dir: string,
options: Schema,
options: {
cname?: string,
dryRun?: boolean
},
logger: logging.LoggerApi
) {
if (!options.cname) {
Expand All @@ -228,16 +256,19 @@ async function createCnameFile(

async function createNojekyllFile(
dir: string,
options: Schema,
options: {
nojekyll: boolean,
dryRun?: boolean
},
logger: logging.LoggerApi
) {
if (options.noNojekyll) {
if (!options.nojekyll) {
return;
}

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

Expand All @@ -252,24 +283,28 @@ async function createNojekyllFile(
async function publishViaGhPages(
ghPages: GHPages,
dir: string,
options: Schema,
options: Schema & {
dotfiles: boolean,
notfound: boolean,
nojekyll: boolean
},
logger: logging.LoggerApi
) {
if (options.dryRun) {
logger.info(
`Dry-run / SKIPPED: publishing folder "${dir}" with the following options: ` +
`Dry-run / SKIPPED: publishing folder '${dir}' with the following options: ` +
JSON.stringify(
{
dir,
repo: options.repo || 'falsy: current working directory (which must be a git repo in this case) will be used to commit & push',
repo: options.repo || 'current working directory (which must be a git repo in this case) will be used to commit & push',
message: options.message,
branch: options.branch,
name: options.name || 'falsy: local or global git username will be used',
email: options.email || 'falsy: local or global git user email will be used',
dotfiles: options.dotfiles || 'falsy: dotfiles are included by default',
noNotfound: options.noNotfound || 'falsy: a 404.html file will be created by default',
noNojekyll: options.noNojekyll || 'falsy: a .nojekyll file will be created by default',
cname: options.cname || 'falsy: no CNAME file will be created'
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',
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',
dotfiles: options.dotfiles ? `files starting with dot ('.') will be included` : `files starting with dot ('.') will be ignored`,
notfound: options.notfound ? 'a 404.html file will be created' : 'a 404.html file will NOT be created',
nojekyll: options.nojekyll ? 'a .nojekyll file will be created' : 'a .nojekyll file will NOT be created',
cname: options.cname ? `a CNAME file with the content '${options.cname}' will be created` : 'a CNAME file will NOT be created'
},
null,
' '
Expand Down

0 comments on commit 95d8603

Please sign in to comment.