Skip to content

Commit

Permalink
wip: fixed some issues with double negation
Browse files Browse the repository at this point in the history
  • Loading branch information
JohannesHoppe committed Aug 2, 2019
1 parent ebe0daa commit 756852f
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 40 deletions.
20 changes: 14 additions & 6 deletions .vscode/launch.json
Expand Up @@ -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",
}
]
}
}
14 changes: 9 additions & 5 deletions 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)
Expand All @@ -14,8 +18,8 @@ commander
.option('-b, --branch <branch>', 'The git branch to push your pages to.', defaults.branch)
.option('-n, --name <name>', 'The git user-name which is associated with this commit.', defaults.name)
.option('-e, --email <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 <domain>', '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);
Expand All @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions angular-testdrive/404.html
@@ -0,0 +1 @@
Welcome to angular-cli-ghpages 🏎 testdrive!
1 change: 1 addition & 0 deletions angular-testdrive/CNAME
@@ -0,0 +1 @@
angular-cli-ghpages.angular.schule
1 change: 1 addition & 0 deletions angular-testdrive/index.html
@@ -0,0 +1 @@
Welcome to angular-cli-ghpages 🏎 testdrive!
14 changes: 9 additions & 5 deletions deploy/schema.json
Expand Up @@ -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.",
Expand All @@ -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
}
}
}
}
6 changes: 3 additions & 3 deletions 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
};
40 changes: 23 additions & 17 deletions 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';
Expand All @@ -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);
Expand All @@ -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' +
Expand All @@ -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!');
}
}
Expand All @@ -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?!');
Expand Down Expand Up @@ -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;
}
Expand Down
18 changes: 15 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -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"
},
Expand Down

0 comments on commit 756852f

Please sign in to comment.