From 756852f6edf8259653c0f7449b443449b520f070 Mon Sep 17 00:00:00 2001 From: Johannes Hoppe Date: Sat, 3 Aug 2019 00:09:43 +0200 Subject: [PATCH] wip: fixed some issues with double negation see also https://github.com/tj/commander.js/issues/928 --- .vscode/launch.json | 20 ++++++++++++------ angular-cli-ghpages | 14 ++++++++----- angular-testdrive/404.html | 1 + angular-testdrive/CNAME | 1 + angular-testdrive/index.html | 1 + deploy/schema.json | 14 ++++++++----- engine/defaults.ts | 6 +++--- engine/engine.ts | 40 +++++++++++++++++++++--------------- package-lock.json | 18 +++++++++++++--- package.json | 2 +- 10 files changed, 77 insertions(+), 40 deletions(-) create mode 100644 angular-testdrive/404.html create mode 100644 angular-testdrive/CNAME create mode 100644 angular-testdrive/index.html diff --git a/.vscode/launch.json b/.vscode/launch.json index b32d67b..95c2251 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -7,13 +7,21 @@ { "type": "node", "request": "launch", - "name": "Launch Program", - "cwd": "${workspaceRoot}/angular-testdrive", - "program": "${workspaceFolder}/angular-cli-ghpages", + "name": "Launch Standalone Program", + //"cwd": "${workspaceRoot}", + "program": "${workspaceFolder}/dist/angular-cli-ghpages", + "outFiles": [ + "${workspaceFolder}/dist/**/*.js" + ], "args": [ - "--dir=dist/angular-testdrive", + //"--no-silent", + //"--dry-run", + "--dir=angular-testdrive", "--cname=angular-cli-ghpages.angular.schule" - ] + ], + "stopOnEntry": true, + "sourceMaps": true, + "preLaunchTask": "npm: build", } ] -} \ No newline at end of file +} diff --git a/angular-cli-ghpages b/angular-cli-ghpages index 22c14ca..cf512af 100644 --- a/angular-cli-ghpages +++ b/angular-cli-ghpages @@ -1,10 +1,14 @@ #!/usr/bin/env node -var engine = require('../engine/engine'), +var + path = require('path'), + engine = require('./engine/engine'), + defaults = require('./engine/defaults').defaults, pjson = require('../package.json'), - defaults = require('../engine/defaults'), commander = require('commander'); +// unfortunately defaults-file is ignored for --no-silent & --no-dotfiles +// according to PR it should work (https://github.com/tj/commander.js/issues/928) but it's still completely foobar!?! commander .version(pjson.version) .description(pjson.description) @@ -14,8 +18,8 @@ commander .option('-b, --branch ', 'The git branch to push your pages to.', defaults.branch) .option('-n, --name ', 'The git user-name which is associated with this commit.', defaults.name) .option('-e, --email ', 'The git user-email which is associated with this commit.', defaults.email) - .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) - .option('-T, --no-dotfiles', 'Includes dotfiles by default. When set files starting with `.` are ignored.', defaults.noDotfiles) + .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!') + .option('-T, --no-dotfiles', 'Includes dotfiles by default. Otherwise files starting with `.` are ignored.') .option('-c, --cname ', 'Generate a CNAME file for the specified domain.', defaults.cname) .option('--dry-run', 'For testing: Run through without making any changes.', defaults.dryRun) .parse(process.argv); @@ -30,7 +34,7 @@ var consoleLogger = { fatal: console.error, }; -var dir = path.join(process.cwd(), options.dir); +var dir = path.join(process.cwd(), commander.dir); engine.run(dir, commander, consoleLogger) .catch(function (error) { diff --git a/angular-testdrive/404.html b/angular-testdrive/404.html new file mode 100644 index 0000000..a0defe7 --- /dev/null +++ b/angular-testdrive/404.html @@ -0,0 +1 @@ +Welcome to angular-cli-ghpages 🏎 testdrive! diff --git a/angular-testdrive/CNAME b/angular-testdrive/CNAME new file mode 100644 index 0000000..6a631a4 --- /dev/null +++ b/angular-testdrive/CNAME @@ -0,0 +1 @@ +angular-cli-ghpages.angular.schule \ No newline at end of file diff --git a/angular-testdrive/index.html b/angular-testdrive/index.html new file mode 100644 index 0000000..a0defe7 --- /dev/null +++ b/angular-testdrive/index.html @@ -0,0 +1 @@ +Welcome to angular-cli-ghpages 🏎 testdrive! diff --git a/deploy/schema.json b/deploy/schema.json index f7d30b4..f37ec41 100644 --- a/deploy/schema.json +++ b/deploy/schema.json @@ -11,6 +11,10 @@ "type": "string", "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`." }, + "repo": { + "type": "string", + "description": "Provide the repository URL. If no value is provided, the `origin` remote of the current working directory is used." + }, "message": { "type": "string", "description": "The commit message.", @@ -31,23 +35,23 @@ }, "noSilent": { "type": "boolean", - "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!", + "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!", "default": false }, "noDotfiles": { "type": "boolean", - "description": "Includes dotfiles by default. When set files starting with `.` are ignored.", + "description": "Includes dotfiles by default. Execute with --no-dotfiles to ignore files starting with `.`.", "default": false }, "cname": { "type": "string", - "description": "Includes dotfiles by default. When set files starting with `.` are ignored.", + "description": "Generate a CNAME file for the specified domain.", "default": false }, "dryRun": { "type": "boolean", - "description": "For testing: Run through without making any changes.", + "description": "For testing: Run through without making any changes. Execute with --dry-run and nothing will happen.", "default": false } } -} \ No newline at end of file +} diff --git a/engine/defaults.ts b/engine/defaults.ts index 5fb1c65..3747023 100644 --- a/engine/defaults.ts +++ b/engine/defaults.ts @@ -1,12 +1,12 @@ export const defaults = { dir: 'dist', repo: undefined, - message: 'Auto- generated commit', + message: 'Auto-generated commit', branch: 'gh-pages', name: undefined, email: undefined, - noSilent: false, - noDotfiles: false, + silent: true, + dotfiles: true, cname: undefined, dryRun: false }; diff --git a/engine/engine.ts b/engine/engine.ts index 008bb61..18e45ba 100644 --- a/engine/engine.ts +++ b/engine/engine.ts @@ -1,5 +1,4 @@ import * as path from 'path'; -import * as fs from 'fs'; import * as fse from 'fs-extra'; import { logging } from '@angular-devkit/core'; @@ -22,7 +21,7 @@ export async function run(dir: string, options: RealDeployOptions, logger: loggi } try { - checkIfDistFolderExists(dir); + await checkIfDistFolderExists(dir); await createNotFoundPage(dir, options, logger); await createCnameFile(dir, options, logger); await publishViaGhPages(ghpages, dir, options, logger); @@ -36,26 +35,34 @@ export async function run(dir: string, options: RealDeployOptions, logger: loggi }; -function prepareOptions(options: RealDeployOptions, logger: logging.LoggerApi) { +function prepareOptions(origOptions: RealDeployOptions, logger: logging.LoggerApi) { - options = { + const options = { ...defaults, - options + ...origOptions }; + if (origOptions.noSilent) { + options.silent = !origOptions.noSilent + } + + if (origOptions.noDotfiles) { + options.dotfiles = !origOptions.noDotfiles + } + if (options.dryRun) { logger.info('*** Dry-run: No changes are applied at all.'); } if (options.name && options.email) { - options.user = { + options['user'] = { name: options.name, email: options.email }; }; // gh-pages internal: forwards messages to logger - options.logger = function (message) { logger.info(message); }; + options['logger'] = function (message) { logger.info(message); }; if (process.env.TRAVIS) { options.message += ' -- ' + process.env.TRAVIS_COMMIT_MESSAGE + ' \n\n' + @@ -77,8 +84,8 @@ function prepareOptions(options: RealDeployOptions, logger: logging.LoggerApi) { return options; } -function checkIfDistFolderExists(dir: string) { - if (!fs.existsSync(dir)) { +async function checkIfDistFolderExists(dir: string) { + if (await !fse.pathExists(dir)) { throw new Error('*** Dist folder does not exist. Check the dir --dir parameter or build the project first!'); } } @@ -92,13 +99,13 @@ async function createNotFoundPage(dir: string, options: RealDeployOptions, logge // Note: // There is no guarantee that there will be an index.html file, - // as the developer may specify a custom index file. + // as we may may specify a custom index file. // TODO: respect setting in angular.json const indexHtml = path.join(dir, 'index.html'); const notFoundPage = path.join(dir, '404.html'); try { - return fse.copy(indexHtml, notFoundPage); + return await fse.copy(indexHtml, notFoundPage); } catch (err) { 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 if (options.dryRun) { logger.info('*** Dry-run / SKIPPED: publishing folder "' + dir + '" with the following options:', { dir: dir, - repo: options.repo || 'undefined: current working directory (which must be a git repo in this case) will be used to commit & push', + repo: options.repo || 'falsy: current working directory (which must be a git repo in this case) will be used to commit & push', message: options.message, branch: options.branch, - user: options.user || 'undefined: local or global git username & email properties will be taken', - noSilent: options.noSilent || 'undefined: logging is in silent mode by default', - noDotfiles: options.noDotfiles || 'undefined: dotfiles are included by default', - dryRun: options.dryRun, - cname: options.cname || 'undefined: no CNAME file will be created', + user: options.user || 'falsy: local or global git username & email properties will be taken', + silent: options.silent || 'falsy: logging is in silent mode by default', + dotfiles: options.dotfiles || 'falsy: dotfiles are included by default', + cname: options.cname || 'falsy: no CNAME file will be created', } as any); return; } diff --git a/package-lock.json b/package-lock.json index 37affb7..efb8a20 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1240,9 +1240,9 @@ } }, "commander": { - "version": "2.20.0", - "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.0.tgz", - "integrity": "sha512-7j2y+40w61zy6YC2iRNpUe/NwhNyoXrYpHMrSunaMG64nRnaf96zO/KMQR4OyN/UnE5KLyEBnKHd4aG3rskjpQ==" + "version": "3.0.0-0", + "resolved": "https://registry.npmjs.org/commander/-/commander-3.0.0-0.tgz", + "integrity": "sha512-b/YlgJi4Nn53KWvxsOU9Mz1Lr+ZK4tMUyDOk2IvB+Hki5eefYZusNOvLls91HeI2oWLyxJ3KMEU9QeEaRtTPFQ==" }, "component-emitter": { "version": "1.3.0", @@ -2524,6 +2524,11 @@ "rimraf": "^2.6.2" }, "dependencies": { + "commander": { + "version": "2.20.0", + "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.0.tgz", + "integrity": "sha512-7j2y+40w61zy6YC2iRNpUe/NwhNyoXrYpHMrSunaMG64nRnaf96zO/KMQR4OyN/UnE5KLyEBnKHd4aG3rskjpQ==" + }, "fs-extra": { "version": "7.0.1", "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-7.0.1.tgz", @@ -5481,6 +5486,13 @@ "source-map": "~0.6.1" }, "dependencies": { + "commander": { + "version": "2.20.0", + "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.0.tgz", + "integrity": "sha512-7j2y+40w61zy6YC2iRNpUe/NwhNyoXrYpHMrSunaMG64nRnaf96zO/KMQR4OyN/UnE5KLyEBnKHd4aG3rskjpQ==", + "dev": true, + "optional": true + }, "source-map": { "version": "0.6.1", "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", diff --git a/package.json b/package.json index c6d5bca..7060001 100644 --- a/package.json +++ b/package.json @@ -64,7 +64,7 @@ "@angular-devkit/schematics": ">=8.0.0" }, "dependencies": { - "commander": "^2.20.0", + "commander": "^3.0.0-0", "fs-extra": "^8.1.0", "gh-pages": "^2.1.0" },