Skip to content

Commit 756852f

Browse files
committed
wip: fixed some issues with double negation
see also tj/commander.js#928
1 parent ebe0daa commit 756852f

File tree

10 files changed

+77
-40
lines changed

10 files changed

+77
-40
lines changed

.vscode/launch.json

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,21 @@
77
{
88
"type": "node",
99
"request": "launch",
10-
"name": "Launch Program",
11-
"cwd": "${workspaceRoot}/angular-testdrive",
12-
"program": "${workspaceFolder}/angular-cli-ghpages",
10+
"name": "Launch Standalone Program",
11+
//"cwd": "${workspaceRoot}",
12+
"program": "${workspaceFolder}/dist/angular-cli-ghpages",
13+
"outFiles": [
14+
"${workspaceFolder}/dist/**/*.js"
15+
],
1316
"args": [
14-
"--dir=dist/angular-testdrive",
17+
//"--no-silent",
18+
//"--dry-run",
19+
"--dir=angular-testdrive",
1520
"--cname=angular-cli-ghpages.angular.schule"
16-
]
21+
],
22+
"stopOnEntry": true,
23+
"sourceMaps": true,
24+
"preLaunchTask": "npm: build",
1725
}
1826
]
19-
}
27+
}

angular-cli-ghpages

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
#!/usr/bin/env node
22

3-
var engine = require('../engine/engine'),
3+
var
4+
path = require('path'),
5+
engine = require('./engine/engine'),
6+
defaults = require('./engine/defaults').defaults,
47
pjson = require('../package.json'),
5-
defaults = require('../engine/defaults'),
68
commander = require('commander');
79

10+
// unfortunately defaults-file is ignored for --no-silent & --no-dotfiles
11+
// according to PR it should work (https://github.com/tj/commander.js/issues/928) but it's still completely foobar!?!
812
commander
913
.version(pjson.version)
1014
.description(pjson.description)
@@ -14,8 +18,8 @@ commander
1418
.option('-b, --branch <branch>', 'The git branch to push your pages to.', defaults.branch)
1519
.option('-n, --name <name>', 'The git user-name which is associated with this commit.', defaults.name)
1620
.option('-e, --email <email>', 'The git user-email which is associated with this commit.', defaults.email)
17-
.option('-S, --no-silent', 'Logging is in silent mode by default. The option enables extended console logging. Keep this untouched if the repository URL or other information passed to git commands is sensitive!', defaults.noSilent)
18-
.option('-T, --no-dotfiles', 'Includes dotfiles by default. When set files starting with `.` are ignored.', defaults.noDotfiles)
21+
.option('-S, --no-silent', 'Logging is in silent mode by default. The option enables extended console logging. Keep this untouched if the repository URL or other information passed to git commands is sensitive!')
22+
.option('-T, --no-dotfiles', 'Includes dotfiles by default. Otherwise files starting with `.` are ignored.')
1923
.option('-c, --cname <domain>', 'Generate a CNAME file for the specified domain.', defaults.cname)
2024
.option('--dry-run', 'For testing: Run through without making any changes.', defaults.dryRun)
2125
.parse(process.argv);
@@ -30,7 +34,7 @@ var consoleLogger = {
3034
fatal: console.error,
3135
};
3236

33-
var dir = path.join(process.cwd(), options.dir);
37+
var dir = path.join(process.cwd(), commander.dir);
3438

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

angular-testdrive/404.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Welcome to angular-cli-ghpages 🏎 testdrive!

angular-testdrive/CNAME

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
angular-cli-ghpages.angular.schule

angular-testdrive/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Welcome to angular-cli-ghpages 🏎 testdrive!

deploy/schema.json

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
"type": "string",
1212
"description": "A named build target, as specified in the `configurations` section of angular.json. Each named target is accompanied by a configuration of option defaults for that target. Same as `ng build --configuration=XXX`."
1313
},
14+
"repo": {
15+
"type": "string",
16+
"description": "Provide the repository URL. If no value is provided, the `origin` remote of the current working directory is used."
17+
},
1418
"message": {
1519
"type": "string",
1620
"description": "The commit message.",
@@ -31,23 +35,23 @@
3135
},
3236
"noSilent": {
3337
"type": "boolean",
34-
"description": "Logging is in silent mode by default. The option enables extended console logging. Keep this untouched if the repository URL or other information passed to git commands is sensitive!",
38+
"description": "Logging is in silent mode by default. Execute with --no-silent to enable extended console logging. Keep this untouched if the repository URL or other information passed to git commands is sensitive!",
3539
"default": false
3640
},
3741
"noDotfiles": {
3842
"type": "boolean",
39-
"description": "Includes dotfiles by default. When set files starting with `.` are ignored.",
43+
"description": "Includes dotfiles by default. Execute with --no-dotfiles to ignore files starting with `.`.",
4044
"default": false
4145
},
4246
"cname": {
4347
"type": "string",
44-
"description": "Includes dotfiles by default. When set files starting with `.` are ignored.",
48+
"description": "Generate a CNAME file for the specified domain.",
4549
"default": false
4650
},
4751
"dryRun": {
4852
"type": "boolean",
49-
"description": "For testing: Run through without making any changes.",
53+
"description": "For testing: Run through without making any changes. Execute with --dry-run and nothing will happen.",
5054
"default": false
5155
}
5256
}
53-
}
57+
}

engine/defaults.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
export const defaults = {
22
dir: 'dist',
33
repo: undefined,
4-
message: 'Auto- generated commit',
4+
message: 'Auto-generated commit',
55
branch: 'gh-pages',
66
name: undefined,
77
email: undefined,
8-
noSilent: false,
9-
noDotfiles: false,
8+
silent: true,
9+
dotfiles: true,
1010
cname: undefined,
1111
dryRun: false
1212
};

engine/engine.ts

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import * as path from 'path';
2-
import * as fs from 'fs';
32
import * as fse from 'fs-extra';
43

54
import { logging } from '@angular-devkit/core';
@@ -22,7 +21,7 @@ export async function run(dir: string, options: RealDeployOptions, logger: loggi
2221
}
2322

2423
try {
25-
checkIfDistFolderExists(dir);
24+
await checkIfDistFolderExists(dir);
2625
await createNotFoundPage(dir, options, logger);
2726
await createCnameFile(dir, options, logger);
2827
await publishViaGhPages(ghpages, dir, options, logger);
@@ -36,26 +35,34 @@ export async function run(dir: string, options: RealDeployOptions, logger: loggi
3635
};
3736

3837

39-
function prepareOptions(options: RealDeployOptions, logger: logging.LoggerApi) {
38+
function prepareOptions(origOptions: RealDeployOptions, logger: logging.LoggerApi) {
4039

41-
options = {
40+
const options = {
4241
...defaults,
43-
options
42+
...origOptions
4443
};
4544

45+
if (origOptions.noSilent) {
46+
options.silent = !origOptions.noSilent
47+
}
48+
49+
if (origOptions.noDotfiles) {
50+
options.dotfiles = !origOptions.noDotfiles
51+
}
52+
4653
if (options.dryRun) {
4754
logger.info('*** Dry-run: No changes are applied at all.');
4855
}
4956

5057
if (options.name && options.email) {
51-
options.user = {
58+
options['user'] = {
5259
name: options.name,
5360
email: options.email
5461
};
5562
};
5663

5764
// gh-pages internal: forwards messages to logger
58-
options.logger = function (message) { logger.info(message); };
65+
options['logger'] = function (message) { logger.info(message); };
5966

6067
if (process.env.TRAVIS) {
6168
options.message += ' -- ' + process.env.TRAVIS_COMMIT_MESSAGE + ' \n\n' +
@@ -77,8 +84,8 @@ function prepareOptions(options: RealDeployOptions, logger: logging.LoggerApi) {
7784
return options;
7885
}
7986

80-
function checkIfDistFolderExists(dir: string) {
81-
if (!fs.existsSync(dir)) {
87+
async function checkIfDistFolderExists(dir: string) {
88+
if (await !fse.pathExists(dir)) {
8289
throw new Error('*** Dist folder does not exist. Check the dir --dir parameter or build the project first!');
8390
}
8491
}
@@ -92,13 +99,13 @@ async function createNotFoundPage(dir: string, options: RealDeployOptions, logge
9299

93100
// Note:
94101
// There is no guarantee that there will be an index.html file,
95-
// as the developer may specify a custom index file.
102+
// as we may may specify a custom index file.
96103
// TODO: respect setting in angular.json
97104
const indexHtml = path.join(dir, 'index.html');
98105
const notFoundPage = path.join(dir, '404.html');
99106

100107
try {
101-
return fse.copy(indexHtml, notFoundPage);
108+
return await fse.copy(indexHtml, notFoundPage);
102109
}
103110
catch (err) {
104111
logger.info('index.html could not be copied to 404.html. This does not look like an angular project?!');
@@ -134,14 +141,13 @@ async function publishViaGhPages(ghPages: GHPages, dir: string, options: RealDep
134141
if (options.dryRun) {
135142
logger.info('*** Dry-run / SKIPPED: publishing folder "' + dir + '" with the following options:', {
136143
dir: dir,
137-
repo: options.repo || 'undefined: current working directory (which must be a git repo in this case) will be used to commit & push',
144+
repo: options.repo || 'falsy: current working directory (which must be a git repo in this case) will be used to commit & push',
138145
message: options.message,
139146
branch: options.branch,
140-
user: options.user || 'undefined: local or global git username & email properties will be taken',
141-
noSilent: options.noSilent || 'undefined: logging is in silent mode by default',
142-
noDotfiles: options.noDotfiles || 'undefined: dotfiles are included by default',
143-
dryRun: options.dryRun,
144-
cname: options.cname || 'undefined: no CNAME file will be created',
147+
user: options.user || 'falsy: local or global git username & email properties will be taken',
148+
silent: options.silent || 'falsy: logging is in silent mode by default',
149+
dotfiles: options.dotfiles || 'falsy: dotfiles are included by default',
150+
cname: options.cname || 'falsy: no CNAME file will be created',
145151
} as any);
146152
return;
147153
}

package-lock.json

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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
"@angular-devkit/schematics": ">=8.0.0"
6565
},
6666
"dependencies": {
67-
"commander": "^2.20.0",
67+
"commander": "^3.0.0-0",
6868
"fs-extra": "^8.1.0",
6969
"gh-pages": "^2.1.0"
7070
},

0 commit comments

Comments
 (0)