Skip to content

Commit

Permalink
Merge pull request #10 from nickpape-msft/nickpape/fix-lint-errors
Browse files Browse the repository at this point in the history
Fix all lint errors
  • Loading branch information
nickpape-msft committed May 24, 2016
2 parents 61fe117 + ba910d1 commit 91746b8
Show file tree
Hide file tree
Showing 11 changed files with 310 additions and 243 deletions.
22 changes: 13 additions & 9 deletions src/CopyTask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,20 @@ export class CopyTask extends GulpTask<ICopyConfig> {

public executeTask(
gulp: gulp.Gulp,
completeCallback: (result?: any) => void
): Promise<any> | NodeJS.ReadWriteStream | void {
let flatten = require('gulp-flatten');
let merge = require('merge2');
let { copyTo } = this.taskConfig;
let allStreams = [];

for (let copyDest in copyTo) {
completeCallback: (result?: Object) => void
): Promise<Object> | NodeJS.ReadWriteStream | void {

/* tslint:disable:typedef */
const flatten = require('gulp-flatten');
const merge = require('merge2');
const { copyTo } = this.taskConfig;
/* tslint:enable:typedef */

const allStreams: NodeJS.ReadWriteStream[] = [];

for (const copyDest in copyTo) {
if (copyTo.hasOwnProperty(copyDest)) {
let sources = copyTo[copyDest];
const sources: string[] = copyTo[copyDest];

sources.forEach(sourceMatch => allStreams.push(
gulp.src(sourceMatch)
Expand Down
4 changes: 2 additions & 2 deletions src/GulpProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import gulp = require('gulp');
export class GulpProxy {
private _gulp: gulp.Gulp;

constructor(gulpInstance: any) {
constructor(gulpInstance: gulp.Gulp) {
this._gulp = gulpInstance;
}

public task(): any {
public task(): void {
throw new Error(
'You should not define gulp tasks, but instead subclass the GulpTask and override the executeTask method.'
);
Expand Down
82 changes: 48 additions & 34 deletions src/GulpTask.ts
Original file line number Diff line number Diff line change
@@ -1,74 +1,81 @@
/* tslint:disable:max-line-length */
import { GulpProxy } from './GulpProxy';
import { IExecutable } from './IExecutable';
import { IBuildConfig } from './IBuildConfig';
import { log, verbose, error, fileError, warn, logEndSubtask, logStartSubtask } from './logging';
import gutil = require('gulp-util');
import gulp = require('gulp');
import through2 = require('through2');
/* tslint:disable:typedef */
const eos = require('end-of-stream');
/* tslint:enable:typedef */

export abstract class GulpTask<TASK_CONFIG> implements IExecutable {
public name: string;
public buildConfig: IBuildConfig;
public taskConfig: TASK_CONFIG;
public nukeMatch: string[];

public setConfig(taskConfig: TASK_CONFIG) {
public setConfig(taskConfig: TASK_CONFIG): void {
/* tslint:disable:typedef */
let merge = require('lodash.merge');
/* tslint:enable:typedef */

this.taskConfig = merge({}, this.taskConfig, taskConfig);
}

public replaceConfig(taskConfig: TASK_CONFIG) {
public replaceConfig(taskConfig: TASK_CONFIG): void {
this.taskConfig = taskConfig;
}

public isEnabled(): boolean {
return true;
}

public abstract executeTask(gulp: gulp.Gulp, completeCallback?: (result?: any) => void): Promise<any> | NodeJS.ReadWriteStream | void;
public abstract executeTask(gulp: gulp.Gulp | GulpProxy, completeCallback?: (result?: Object) => void): Promise<Object> | NodeJS.ReadWriteStream | void;

public log(message: string) {
public log(message: string): void {
log(`[${gutil.colors.cyan(this.name)}] ${message}`);
}

public logVerbose(message: string) {
public logVerbose(message: string): void {
verbose(`[${gutil.colors.cyan(this.name)}] ${message}`);
}

public logWarning(message: string) {
public logWarning(message: string): void {
warn(`[${gutil.colors.cyan(this.name)}] ${message}`);
}

public logError(message: string) {
public logError(message: string): void {
error(`[${gutil.colors.cyan(this.name)}] ${message}`);
}

public fileError(filePath: string, line: number, column: number, errorCode: string, message: string) {
public fileError(filePath: string, line: number, column: number, errorCode: string, message: string): void {
fileError(this.name, filePath, line, column, errorCode, message);
}

public getNukeMatch(): string[] {
return this.nukeMatch;
}

public execute(config: IBuildConfig): Promise<any> {
public execute(config: IBuildConfig): Promise<void> {
this.buildConfig = config;

let startTime = process.hrtime();
const startTime: number[] = process.hrtime();

logStartSubtask(this.name);

return new Promise((resolve, reject) => {
/* tslint:disable:typedef */
let stream;
/* tslint:enable:typedef */

try {
if (!this.executeTask) {
throw new Error('The task subclass is missing the "executeTask" method.');
}

stream = this.executeTask(this.buildConfig.gulp, (result?: any) => {
stream = this.executeTask(this.buildConfig.gulp, (result?: Object) => {
if (!result) {
resolve();
} else {
Expand All @@ -90,7 +97,7 @@ export abstract class GulpTask<TASK_CONFIG> implements IExecutable {
error: true,
readable: stream.readable,
writable: stream.writable && !stream.readable
}, (err: any) => {
}, (err: Object) => {
if (err) {
reject(err);
} else {
Expand All @@ -100,14 +107,13 @@ export abstract class GulpTask<TASK_CONFIG> implements IExecutable {

// Make sure the stream is completly read
stream.pipe(through2.obj(
function(
file: gutil.File,
(file: gutil.File,
encoding: string,
callback: (p?: any) => void) {
'use strict';
callback();
callback: (p?: Object) => void) => {
'use strict';
callback();
},
function(callback: () => void) {
(callback: () => void) => {
'use strict';
callback();
}));
Expand All @@ -129,45 +135,53 @@ export abstract class GulpTask<TASK_CONFIG> implements IExecutable {
}

public resolvePath(localPath: string): string {
let path = require('path');
/* tslint:disable:typedef */
const path = require('path');
/* tslint:enable:typedef */
if (path.isAbsolute(localPath)) {
return path.resolve(localPath);
}
return path.resolve(path.join(this.buildConfig.rootPath, localPath));
}

public fileExists(localPath: string): boolean {
let fs = require('fs');
let doesExist = false;
let fullPath = this.resolvePath(localPath);
/* tslint:disable:typedef */
const fs = require('fs');
/* tslint:enable:typedef */
let doesExist: boolean = false;
const fullPath: string = this.resolvePath(localPath);

try {
let stats = fs.statSync(fullPath);
doesExist = stats.isFile();
doesExist = fs.statSync(fullPath).isFile();
} catch (e) { /* no-op */ }

return doesExist;
}

public copyFile(localSourcePath: string, localDestPath?: string) {
let path = require('path');
let fs = require('fs-extra');
public copyFile(localSourcePath: string, localDestPath?: string): void {
/* tslint:disable:typedef */
const path = require('path');
const fs = require('fs-extra');
/* tslint:enable:typedef */

let fullSourcePath = path.resolve(__dirname, localSourcePath);
let fullDestPath = path.resolve(
const fullSourcePath: string = path.resolve(__dirname, localSourcePath);
const fullDestPath: string = path.resolve(
this.buildConfig.rootPath,
(localDestPath || path.basename(localSourcePath)));

fs.copySync(fullSourcePath, fullDestPath);
}

public readJSONSync(localPath: string): string {
let fullPath = this.resolvePath(localPath);
let result = null;
let fs = require('fs');
public readJSONSync(localPath: string): Object {
const fullPath: string = this.resolvePath(localPath);
let result: Object = undefined;

/* tslint:disable:typedef */
const fs = require('fs');
/* tslint:enable:typedef */

try {
let content = fs.readFileSync(fullPath, 'utf8');
let content: string = fs.readFileSync(fullPath, 'utf8');
result = JSON.parse(content);
} catch (e) { /* no-op */ }

Expand Down
6 changes: 5 additions & 1 deletion src/IBuildConfig.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import * as gulp from 'gulp';
import { GulpProxy } from './GulpProxy';
import { IExecutable } from './IExecutable';

/* tslint:disable:no-any */

export interface IBuildConfig {
/** Proxy gulp instance. */
gulp?: any;
gulp?: GulpProxy | gulp.Gulp;

/** Array of all unique tasks. */
uniqueTasks?: IExecutable[];
Expand Down
15 changes: 9 additions & 6 deletions src/NukeTask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,20 @@ export interface INukeConfig {
}

export class NukeTask extends GulpTask<INukeConfig> {
public name = 'nuke';
public name: string = 'nuke';

public taskConfig: INukeConfig = {
};

public executeTask(
gulp: gulp.Gulp,
completeCallback: (result?: any) => void
): Promise<any> | NodeJS.ReadWriteStream | void {
let del = require('del');
let { distFolder, libFolder, libAMDFolder, tempFolder } = this.buildConfig;
completeCallback: (result?: Object) => void
): void {
/* tslint:disable:typedef */
const del = require('del');
/* tslint:disable:typedef */

const { distFolder, libFolder, libAMDFolder, tempFolder } = this.buildConfig;
let nukePaths = [
distFolder,
libAMDFolder,
Expand All @@ -30,7 +33,7 @@ export class NukeTask extends GulpTask<INukeConfig> {
}
}

let uniquePaths = {};
let uniquePaths: { [key: string]: string } = {};

// Create dictionary of unique paths. (Could be replaced with ES6 set.)
nukePaths.forEach(path => {
Expand Down
10 changes: 5 additions & 5 deletions src/State.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { argv as clArgs } from 'yargs';
import * as path from 'path';

export let root = process.cwd();
export let args = clArgs;
export const root: string = process.cwd();
export const args: { [flat: string]: boolean | string} = clArgs;

export interface IPackageJSON {
name: string;
version: string;
}

export let builtPackage: IPackageJSON = require(path.join(root, 'package.json'));
export let coreBuildPackage: IPackageJSON = require('../package.json');
export let nodeVersion = process.version;
export const builtPackage: IPackageJSON = require(path.join(root, 'package.json'));
export const coreBuildPackage: IPackageJSON = require('../package.json');
export const nodeVersion: string = process.version;
16 changes: 9 additions & 7 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,33 @@
import { args } from './State';

const ENVIRONMENT_VARIABLE_PREFIX = 'GCB_';
const ENVIRONMENT_VARIABLE_PREFIX: string = 'GCB_';

let _defaultValues: Object = {};

export function setConfigDefaults(defaultValues: Object) {
export function setConfigDefaults(defaultValues: Object): void {
_defaultValues = defaultValues;
}

export function getConfigValue(name: string, defaultValue?: string | boolean): string | boolean {

// Try to get config value from environment variable.
let envVariable = ENVIRONMENT_VARIABLE_PREFIX + name.toUpperCase();
let envValue = process.env[envVariable];
let argsValue = args[name.toLowerCase()];
const envVariable: string = ENVIRONMENT_VARIABLE_PREFIX + name.toUpperCase();
const envValue: string = process.env[envVariable];
const argsValue: string | boolean = args[name.toLowerCase()];

return _firstDefinedValue(argsValue, envValue, defaultValue, _defaultValues[name]);
}

export function getFlagValue(name: string, defaultValue?: boolean): boolean {
let configValue = getConfigValue(name, defaultValue);
const configValue: string | boolean = getConfigValue(name, defaultValue);

return configValue === 'true' || configValue === true;
}

/* tslint:disable:no-any */
function _firstDefinedValue(...args: (string | boolean)[]): any {
for (let arg of args) {
/* tslint:enable:no-any */
for (const arg of args) {
if (arg !== undefined) {
return arg;
}
Expand Down
Loading

0 comments on commit 91746b8

Please sign in to comment.