Comparing version
// Type definitions for Grunt 0.4.x | ||
// Project: http://gruntjs.com | ||
// Definitions by: Jeff May <https://github.com/jeffmay/> | ||
// Definitions by: Jeff May <https://github.com/jeffmay/>, Basarat Ali Syed <https://github.com/basarat/> | ||
// Definitions: https://github.com/jeffmay/DefinitelyTyped | ||
@@ -120,25 +120,12 @@ | ||
module config { | ||
/** | ||
* {@link http://gruntjs.com/sample-gruntfile} | ||
*/ | ||
interface IProjectConfig extends IConfigOptionFormat { | ||
pkg: string | ||
} | ||
interface IProjectConfig{ | ||
[plugin: string]: any | ||
pkg: any; // unfortunate. It is actually a string | ||
} | ||
/** | ||
* @see IProjectConfig | ||
*/ | ||
interface IConfigOptionFormat { | ||
[plugin: string]: IConfigPluginFormat | ||
} | ||
/** | ||
* A map of plugin task names to config objects. | ||
*/ | ||
interface IConfigPluginFormat { | ||
[task: string]: grunt.task.ITaskOptions | ||
} | ||
/** | ||
* {@link http://gruntjs.com/api/grunt.config} | ||
@@ -145,0 +132,0 @@ */ |
@@ -18,6 +18,6 @@ /************************************************ | ||
declare function setTimeout(callback: (...args: any[]) => void , ms: number , ...args: any[]): Timer; | ||
declare function clearTimeout(timeoutId: Timer): void; | ||
declare function setInterval(callback: (...args: any[]) => void , ms: number , ...args: any[]): Timer; | ||
declare function clearInterval(intervalId: Timer): void; | ||
declare function setTimeout(callback: (...args: any[]) => void , ms: number , ...args: any[]): NodeTimer; | ||
declare function clearTimeout(timeoutId: NodeTimer): void; | ||
declare function setInterval(callback: (...args: any[]) => void , ms: number , ...args: any[]): NodeTimer; | ||
declare function clearInterval(intervalId: NodeTimer): void; | ||
declare function setImmediate(callback: (...args: any[]) => void , ...args: any[]): any; | ||
@@ -71,2 +71,9 @@ declare function clearImmediate(immediateId: any): void; | ||
interface ErrnoException extends Error { | ||
errno?: any; | ||
code?: string; | ||
path?: string; | ||
syscall?: string; | ||
} | ||
interface EventEmitter { | ||
@@ -100,3 +107,3 @@ addListener(event: string, listener: Function): EventEmitter; | ||
destroy(): void; | ||
pipe(destination: WritableStream, options?: { end?: boolean; }): void; | ||
pipe<T extends WritableStream>(destination: T, options?: { end?: boolean; }): T; | ||
} | ||
@@ -159,2 +166,5 @@ | ||
hrtime(time?:number[]): number[]; | ||
// Worker | ||
send?(message: any, sendHandle?: any): void; | ||
} | ||
@@ -199,6 +209,5 @@ | ||
fill(value: any, offset?: number, end?: number): void; | ||
INSPECT_MAX_BYTES: number; | ||
} | ||
interface Timer { | ||
interface NodeTimer { | ||
ref() : void; | ||
@@ -617,4 +626,15 @@ unref() : void; | ||
export interface UrlOptions { | ||
protocol?: string; | ||
auth?: string; | ||
hostname?: string; | ||
port?: string; | ||
host?: string; | ||
pathname?: string; | ||
search?: string; | ||
query?: any; | ||
} | ||
export function parse(urlStr: string, parseQueryString?: boolean , slashesDenoteHost?: boolean ): Url; | ||
export function format(url: Url): string; | ||
export function format(url: UrlOptions): string; | ||
export function resolve(from: string, to: string): string; | ||
@@ -742,90 +762,90 @@ } | ||
export function rename(oldPath: string, newPath: string, callback?: Function): void; | ||
export function rename(oldPath: string, newPath: string, callback?: (err?: ErrnoException) => void): void; | ||
export function renameSync(oldPath: string, newPath: string): void; | ||
export function truncate(path: string, callback?: Function): void; | ||
export function truncate(path: string, len: number, callback?: Function): void; | ||
export function truncate(path: string, callback?: (err?: ErrnoException) => void): void; | ||
export function truncate(path: string, len: number, callback?: (err?: ErrnoException) => void): void; | ||
export function truncateSync(path: string, len?: number): void; | ||
export function ftruncate(fd: string, callback?: Function): void; | ||
export function ftruncate(fd: string, len: number, callback?: Function): void; | ||
export function ftruncateSync(fd: string, len?: number): void; | ||
export function chown(path: string, uid: number, gid: number, callback?: Function): void; | ||
export function ftruncate(fd: number, callback?: (err?: ErrnoException) => void): void; | ||
export function ftruncate(fd: number, len: number, callback?: (err?: ErrnoException) => void): void; | ||
export function ftruncateSync(fd: number, len?: number): void; | ||
export function chown(path: string, uid: number, gid: number, callback?: (err?: ErrnoException) => void): void; | ||
export function chownSync(path: string, uid: number, gid: number): void; | ||
export function fchown(fd: string, uid: number, gid: number, callback?: Function): void; | ||
export function fchownSync(fd: string, uid: number, gid: number): void; | ||
export function lchown(path: string, uid: number, gid: number, callback?: Function): void; | ||
export function fchown(fd: number, uid: number, gid: number, callback?: (err?: ErrnoException) => void): void; | ||
export function fchownSync(fd: number, uid: number, gid: number): void; | ||
export function lchown(path: string, uid: number, gid: number, callback?: (err?: ErrnoException) => void): void; | ||
export function lchownSync(path: string, uid: number, gid: number): void; | ||
export function chmod(path: string, mode: number, callback?: Function): void; | ||
export function chmod(path: string, mode: string, callback?: Function): void; | ||
export function chmod(path: string, mode: number, callback?: (err?: ErrnoException) => void): void; | ||
export function chmod(path: string, mode: string, callback?: (err?: ErrnoException) => void): void; | ||
export function chmodSync(path: string, mode: number): void; | ||
export function chmodSync(path: string, mode: string): void; | ||
export function fchmod(fd: string, mode: number, callback?: Function): void; | ||
export function fchmod(fd: string, mode: string, callback?: Function): void; | ||
export function fchmodSync(fd: string, mode: number): void; | ||
export function fchmodSync(fd: string, mode: string): void; | ||
export function lchmod(path: string, mode: number, callback?: Function): void; | ||
export function lchmod(path: string, mode: string, callback?: Function): void; | ||
export function fchmod(fd: number, mode: number, callback?: (err?: ErrnoException) => void): void; | ||
export function fchmod(fd: number, mode: string, callback?: (err?: ErrnoException) => void): void; | ||
export function fchmodSync(fd: number, mode: number): void; | ||
export function fchmodSync(fd: number, mode: string): void; | ||
export function lchmod(path: string, mode: number, callback?: (err?: ErrnoException) => void): void; | ||
export function lchmod(path: string, mode: string, callback?: (err?: ErrnoException) => void): void; | ||
export function lchmodSync(path: string, mode: number): void; | ||
export function lchmodSync(path: string, mode: string): void; | ||
export function stat(path: string, callback?: (err: Error, stats: Stats) => any): void; | ||
export function lstat(path: string, callback?: (err: Error, stats: Stats) => any): void; | ||
export function fstat(fd: string, callback?: (err: Error, stats: Stats) => any): void; | ||
export function stat(path: string, callback?: (err: ErrnoException, stats: Stats) => any): void; | ||
export function lstat(path: string, callback?: (err: ErrnoException, stats: Stats) => any): void; | ||
export function fstat(fd: number, callback?: (err: ErrnoException, stats: Stats) => any): void; | ||
export function statSync(path: string): Stats; | ||
export function lstatSync(path: string): Stats; | ||
export function fstatSync(fd: string): Stats; | ||
export function link(srcpath: string, dstpath: string, callback?: Function): void; | ||
export function fstatSync(fd: number): Stats; | ||
export function link(srcpath: string, dstpath: string, callback?: (err?: ErrnoException) => void): void; | ||
export function linkSync(srcpath: string, dstpath: string): void; | ||
export function symlink(srcpath: string, dstpath: string, type?: string, callback?: Function): void; | ||
export function symlink(srcpath: string, dstpath: string, type?: string, callback?: (err?: ErrnoException) => void): void; | ||
export function symlinkSync(srcpath: string, dstpath: string, type?: string): void; | ||
export function readlink(path: string, callback?: (err: Error, linkString: string) => any): void; | ||
export function readlink(path: string, callback?: (err: ErrnoException, linkString: string) => any): void; | ||
export function readlinkSync(path: string): string; | ||
export function realpath(path: string, callback?: (err: Error, resolvedPath: string) => any): void; | ||
export function realpath(path: string, cache: {[path: string]: string}, callback: (err: Error, resolvedPath: string) =>any): void; | ||
export function realpath(path: string, callback?: (err: ErrnoException, resolvedPath: string) => any): void; | ||
export function realpath(path: string, cache: {[path: string]: string}, callback: (err: ErrnoException, resolvedPath: string) =>any): void; | ||
export function realpathSync(path: string, cache?: {[path: string]: string}): void; | ||
export function unlink(path: string, callback?: Function): void; | ||
export function unlink(path: string, callback?: (err?: ErrnoException) => void): void; | ||
export function unlinkSync(path: string): void; | ||
export function rmdir(path: string, callback?: Function): void; | ||
export function rmdir(path: string, callback?: (err?: ErrnoException) => void): void; | ||
export function rmdirSync(path: string): void; | ||
export function mkdir(path: string, callback?: Function): void; | ||
export function mkdir(path: string, mode: number, callback?: Function): void; | ||
export function mkdir(path: string, mode: string, callback?: Function): void; | ||
export function mkdir(path: string, callback?: (err?: ErrnoException) => void): void; | ||
export function mkdir(path: string, mode: number, callback?: (err?: ErrnoException) => void): void; | ||
export function mkdir(path: string, mode: string, callback?: (err?: ErrnoException) => void): void; | ||
export function mkdirSync(path: string, mode?: number): void; | ||
export function mkdirSync(path: string, mode?: string): void; | ||
export function readdir(path: string, callback?: (err: Error, files: string[]) => void): void; | ||
export function readdir(path: string, callback?: (err: ErrnoException, files: string[]) => void): void; | ||
export function readdirSync(path: string): string[]; | ||
export function close(fd: string, callback?: Function): void; | ||
export function closeSync(fd: string): void; | ||
export function open(path: string, flags: string, callback?: (err: Error, fd: string) => any): void; | ||
export function open(path: string, flags: string, mode: number, callback?: (err: Error, fd: string) => any): void; | ||
export function open(path: string, flags: string, mode: string, callback?: (err: Error, fd: string) => any): void; | ||
export function openSync(path: string, flags: string, mode?: number): void; | ||
export function openSync(path: string, flags: string, mode?: string): void; | ||
export function utimes(path: string, atime: number, mtime: number, callback?: Function): void; | ||
export function close(fd: number, callback?: (err?: ErrnoException) => void): void; | ||
export function closeSync(fd: number): void; | ||
export function open(path: string, flags: string, callback?: (err: ErrnoException, fd: number) => any): void; | ||
export function open(path: string, flags: string, mode: number, callback?: (err: ErrnoException, fd: number) => any): void; | ||
export function open(path: string, flags: string, mode: string, callback?: (err: ErrnoException, fd: number) => any): void; | ||
export function openSync(path: string, flags: string, mode?: number): number; | ||
export function openSync(path: string, flags: string, mode?: string): number; | ||
export function utimes(path: string, atime: number, mtime: number, callback?: (err?: ErrnoException) => void): void; | ||
export function utimesSync(path: string, atime: number, mtime: number): void; | ||
export function futimes(fd: string, atime: number, mtime: number, callback?: Function): void; | ||
export function futimesSync(fd: string, atime: number, mtime: number): void; | ||
export function fsync(fd: string, callback?: Function): void; | ||
export function fsyncSync(fd: string): void; | ||
export function write(fd: string, buffer: NodeBuffer, offset: number, length: number, position: number, callback?: (err: Error, written: number, buffer: NodeBuffer) =>any): void; | ||
export function writeSync(fd: string, buffer: NodeBuffer, offset: number, length: number, position: number): void; | ||
export function read(fd: string, buffer: NodeBuffer, offset: number, length: number, position: number, callback?: (err: Error, bytesRead: number, buffer: NodeBuffer) => void): void; | ||
export function readSync(fd: string, buffer: NodeBuffer, offset: number, length: number, position: number): any[]; | ||
export function readFile(filename: string, options: { encoding?: string; flag?: string; }, callback: (err: Error, data: any) => void): void; | ||
export function readFile(filename: string, callback: (err: Error, data: NodeBuffer) => void ): void; | ||
export function futimes(fd: number, atime: number, mtime: number, callback?: (err?: ErrnoException) => void): void; | ||
export function futimesSync(fd: number, atime: number, mtime: number): void; | ||
export function fsync(fd: number, callback?: (err?: ErrnoException) => void): void; | ||
export function fsyncSync(fd: number): void; | ||
export function write(fd: number, buffer: NodeBuffer, offset: number, length: number, position: number, callback?: (err: ErrnoException, written: number, buffer: NodeBuffer) => void): void; | ||
export function writeSync(fd: number, buffer: NodeBuffer, offset: number, length: number, position: number): number; | ||
export function read(fd: number, buffer: NodeBuffer, offset: number, length: number, position: number, callback?: (err: ErrnoException, bytesRead: number, buffer: NodeBuffer) => void): void; | ||
export function readSync(fd: number, buffer: NodeBuffer, offset: number, length: number, position: number): number; | ||
export function readFile(filename: string, options: { encoding?: string; flag?: string; }, callback: (err: ErrnoException, data: any) => void): void; | ||
export function readFile(filename: string, callback: (err: ErrnoException, data: NodeBuffer) => void ): void; | ||
export function readFileSync(filename: string, options?: { flag?: string; }): NodeBuffer; | ||
export function readFileSync(filename: string, options: { encoding: string; flag?: string; }): string; | ||
export function writeFile(filename: string, data: any, callback?: (err: Error) => void): void; | ||
export function writeFile(filename: string, data: any, options: { encoding?: string; mode?: number; flag?: string; }, callback?: (err: Error) => void): void; | ||
export function writeFile(filename: string, data: any, options: { encoding?: string; mode?: string; flag?: string; }, callback?: (err: Error) => void): void; | ||
export function writeFile(filename: string, data: any, callback?: (err: ErrnoException) => void): void; | ||
export function writeFile(filename: string, data: any, options: { encoding?: string; mode?: number; flag?: string; }, callback?: (err: ErrnoException) => void): void; | ||
export function writeFile(filename: string, data: any, options: { encoding?: string; mode?: string; flag?: string; }, callback?: (err: ErrnoException) => void): void; | ||
export function writeFileSync(filename: string, data: any, options?: { encoding?: string; mode?: number; flag?: string; }): void; | ||
export function writeFileSync(filename: string, data: any, options?: { encoding?: string; mode?: string; flag?: string; }): void; | ||
export function appendFile(filename: string, data: any, options: { encoding?: string; mode?: number; flag?: string; }, callback?: (err: Error) => void): void; | ||
export function appendFile(filename: string, data: any, options: { encoding?: string; mode?: string; flag?: string; }, callback?: (err: Error) => void): void; | ||
export function appendFile(filename: string, data: any, callback?: (err: Error) => void): void; | ||
export function appendFile(filename: string, data: any, options: { encoding?: string; mode?: number; flag?: string; }, callback?: (err: ErrnoException) => void): void; | ||
export function appendFile(filename: string, data: any, options: { encoding?: string; mode?: string; flag?: string; }, callback?: (err: ErrnoException) => void): void; | ||
export function appendFile(filename: string, data: any, callback?: (err: ErrnoException) => void): void; | ||
export function appendFileSync(filename: string, data: any, options?: { encoding?: string; mode?: number; flag?: string; }): void; | ||
export function appendFileSync(filename: string, data: any, options?: { encoding?: string; mode?: string; flag?: string; }): void; | ||
export function watchFile(filename: string, listener: (curr: Stats, prev: Stats)=>void): void; | ||
export function watchFile(filename: string, options: { persistent?: boolean; interval?: number; }, listener: (curr: Stats, prev: Stats)=>void): void; | ||
export function unwatchFile(filename: string, listener?: (curr: Stats, prev: Stats)=>void): void; | ||
export function watch(filename: string, listener?: (event: string, filename: string) =>any): FSWatcher; | ||
export function watch(filename: string, options: { persistent?: boolean; }, listener?: (event: string, filename: string) =>any): FSWatcher; | ||
export function watchFile(filename: string, listener: (curr: Stats, prev: Stats) => void): void; | ||
export function watchFile(filename: string, options: { persistent?: boolean; interval?: number; }, listener: (curr: Stats, prev: Stats) => void): void; | ||
export function unwatchFile(filename: string, listener?: (curr: Stats, prev: Stats) => void): void; | ||
export function watch(filename: string, listener?: (event: string, filename: string) => any): FSWatcher; | ||
export function watch(filename: string, options: { persistent?: boolean; }, listener?: (event: string, filename: string) => any): FSWatcher; | ||
export function exists(path: string, callback?: (exists: boolean) => void): void; | ||
@@ -1070,2 +1090,9 @@ export function existsSync(path: string): boolean; | ||
declare module "util" { | ||
export interface InspectOptions { | ||
showHidden?: boolean; | ||
depth?: number; | ||
colors?: boolean; | ||
customInspect?: boolean; | ||
} | ||
export function format(format: any, ...param: any[]): string; | ||
@@ -1078,2 +1105,3 @@ export function debug(string: string): void; | ||
export function inspect(object: any, showHidden?: boolean, depth?: number, color?: boolean): string; | ||
export function inspect(object: any, options: InspectOptions): string; | ||
export function isArray(object: any): boolean; | ||
@@ -1087,6 +1115,17 @@ export function isRegExp(object: any): boolean; | ||
declare module "assert" { | ||
function internal (booleanValue: boolean, message?: string): void; | ||
function internal (value: any, message?: string): void; | ||
module internal { | ||
export function fail(actual: any, expected: any, message: string, operator: string): void; | ||
export function assert(value: any, message: string): void; | ||
export class AssertionError implements Error { | ||
name: string; | ||
message: string; | ||
actual: any; | ||
expected: any; | ||
operator: string; | ||
generatedMessage: boolean; | ||
constructor(options?: {message?: string; actual?: any; expected?: any; | ||
operator?: string; stackStartFunction?: Function}); | ||
} | ||
export function fail(actual?: any, expected?: any, message?: string, operator?: string): void; | ||
export function ok(value: any, message?: string): void; | ||
@@ -1099,4 +1138,16 @@ export function equal(actual: any, expected: any, message?: string): void; | ||
export function notStrictEqual(actual: any, expected: any, message?: string): void; | ||
export function throws(block: any, error?: any, messsage?: string): void; | ||
export function doesNotThrow(block: any, error?: any, messsage?: string): void; | ||
export var throws: { | ||
(block: Function, message?: string): void; | ||
(block: Function, error: Function, message?: string): void; | ||
(block: Function, error: RegExp, message?: string): void; | ||
(block: Function, error: (err: any) => boolean, message?: string): void; | ||
} | ||
export var doesNotThrow: { | ||
(block: Function, message?: string): void; | ||
(block: Function, error: Function, message?: string): void; | ||
(block: Function, error: RegExp, message?: string): void; | ||
(block: Function, error: (err: any) => boolean, message?: string): void; | ||
} | ||
export function ifError(value: any): void; | ||
@@ -1111,3 +1162,3 @@ } | ||
export function isatty(fd: string): boolean; | ||
export function isatty(fd: number): boolean; | ||
export interface ReadStream extends net.NodeSocket { | ||
@@ -1126,11 +1177,18 @@ isRaw: boolean; | ||
export interface Domain extends events.NodeEventEmitter { } | ||
export class Domain extends events.EventEmitter { | ||
run(fn: Function): void; | ||
add(emitter: events.NodeEventEmitter): void; | ||
remove(emitter: events.NodeEventEmitter): void; | ||
bind(cb: (err: Error, data: any) => any): any; | ||
intercept(cb: (data: any) => any): any; | ||
dispose(): void; | ||
addListener(event: string, listener: Function): Domain; | ||
on(event: string, listener: Function): Domain; | ||
once(event: string, listener: Function): Domain; | ||
removeListener(event: string, listener: Function): Domain; | ||
removeAllListeners(event?: string): Domain; | ||
} | ||
export function create(): Domain; | ||
export function run(fn: Function): void; | ||
export function add(emitter: events.NodeEventEmitter): void; | ||
export function remove(emitter: events.NodeEventEmitter): void; | ||
export function bind(cb: (er: Error, data: any) =>any): any; | ||
export function intercept(cb: (data: any) => any): any; | ||
export function dispose(): void; | ||
} |
@@ -33,3 +33,3 @@ // Type definitions for underscore.string | ||
*/ | ||
function chop(str: string, step: number): Array; | ||
function chop(str: string, step: number): any[]; | ||
@@ -56,3 +56,3 @@ /** | ||
*/ | ||
function chars(str: string): Array; | ||
function chars(str: string): any[]; | ||
@@ -132,3 +132,3 @@ /** | ||
*/ | ||
function lines(str: string): Array; | ||
function lines(str: string): any[]; | ||
@@ -285,3 +285,3 @@ /** | ||
*/ | ||
function words(str: string, delimiter?: string): Array; | ||
function words(str: string, delimiter?: string): any[]; | ||
@@ -442,3 +442,3 @@ /** | ||
*/ | ||
function toSentence(array: Array, separator?: string, lastSeparator?: string, serial?: boolean): string; | ||
function toSentence(array: any[], separator?: string, lastSeparator?: string, serial?: boolean): string; | ||
@@ -451,3 +451,3 @@ /** | ||
*/ | ||
function toSentenceSerial(array: Array, separator?: string, lastSeparator?: string): string; | ||
function toSentenceSerial(array: any[], separator?: string, lastSeparator?: string): string; | ||
@@ -532,4 +532,4 @@ /** | ||
*/ | ||
function toBoolean(str: string, trueValues?: Array, falseValues?: Array): boolean; | ||
function toBoolean(str: string, trueValues?: any[], falseValues?: any[]): boolean; | ||
} |
@@ -76,9 +76,17 @@ module.exports = function (grunt) { | ||
}, | ||
amdloadersrc: { | ||
src: ['test/amdloader/ts/app/**/*.ts'], | ||
html: ['test/amdloader/ts/app/**/*.tpl.html'], | ||
reference: 'test/amdloader/ts/app/reference.ts', | ||
outDir: 'test/amdloader/js/app', | ||
amdloader: 'test/amdloader/js/app/loader.js', | ||
// watch: 'test/amdloader/app' | ||
}, | ||
amdloadertest: { | ||
src: ['test/amdloader/**/*.ts'], | ||
html: ['test/amdloader/**/*.tpl.html'], | ||
reference: 'test/amdloader/ts/reference.ts', | ||
outDir: 'test/amdloader/js', | ||
amdloader: 'test/amdloader/js/loader.js', | ||
// watch: 'test/amdloader' | ||
src: ['test/amdloader/ts/test/**/*.ts'], | ||
html: ['test/amdloader/ts/test/**/*.tpl.html'], | ||
reference: 'test/amdloader/ts/test/reference.ts', | ||
outDir: 'test/amdloader/js/test', | ||
amdloader: 'test/amdloader/js/test/loader.js', | ||
// watch: 'test/amdloader' | ||
}, | ||
@@ -85,0 +93,0 @@ sourceroottest: { |
@@ -5,3 +5,3 @@ { | ||
"description": "Compile and manage your TypeScript project", | ||
"version": "1.5.1", | ||
"version": "1.6.0", | ||
"homepage": "https://github.com/basarat/grunt-ts", | ||
@@ -8,0 +8,0 @@ "repository": { |
156
tasks/ts.js
@@ -5,2 +5,4 @@ /// <reference path="../defs/node/node.d.ts"/> | ||
/// <reference path="../defs/underscore.string/underscore.string.d.ts"/> | ||
/** | ||
@@ -11,3 +13,4 @@ * Returns the result of an array inserted into another, starting at the given index. | ||
var updated = array.slice(0); | ||
Array.prototype.splice.apply(updated, [index, 0].concat(arrayToInsert)); | ||
var spliceAt = [index, 0]; | ||
Array.prototype.splice.apply(updated, spliceAt.concat(arrayToInsert)); | ||
return updated; | ||
@@ -50,7 +53,5 @@ } | ||
var fs = require('fs'); | ||
var os = require('os'); | ||
// plain vanilla imports | ||
var shell = require('shelljs'); | ||
var eol = os.EOL; | ||
var pathSeperator = path.sep; | ||
@@ -82,4 +83,5 @@ | ||
function getTsc(binPath) { | ||
return '"' + binPath + '/' + 'tsc" '; | ||
return '"' + binPath + '/' + 'tsc"'; | ||
} | ||
var eol = grunt.util.linefeed; | ||
var exec = shell.exec; | ||
@@ -91,7 +93,5 @@ var cwd = path.resolve("."); | ||
function compileAllFiles(files, target, task) { | ||
var filepath = files.join(' '); | ||
var tscExecCommand = 'node ' + tsc; | ||
var cmd = files.join(' '); | ||
var cmd = filepath; | ||
// boolean options | ||
if (task.sourceMap) | ||
@@ -112,2 +112,3 @@ cmd = cmd + ' --sourcemap'; | ||
// Target options: | ||
if (target.out) { | ||
@@ -129,4 +130,9 @@ cmd = cmd + ' --out ' + target.out; | ||
var tscExecCommand = 'node ' + tsc + ' ' + cmd; | ||
// To debug the tsc command | ||
if (task.verbose) { | ||
console.log(cmd); | ||
console.log(tscExecCommand.yellow); | ||
} else { | ||
grunt.log.verbose.writeln(cmd.yellow); | ||
} | ||
@@ -168,2 +174,3 @@ | ||
// Read the original file if it exists | ||
if (fs.existsSync(referenceFile)) { | ||
@@ -180,2 +187,3 @@ lines = fs.readFileSync(referenceFile).toString().split('\n'); | ||
// Skip logic for our generated section | ||
if (_str.include(line, ourSignatureStart)) { | ||
@@ -197,2 +205,3 @@ //Wait for the end signature: | ||
// Fetch the existing reference's filename if any: | ||
if (_str.include(line, referenceIntro)) { | ||
@@ -217,2 +226,3 @@ var match = line.match(referenceMatch); | ||
// If there are orig references | ||
if (origFileReferences.length) { | ||
@@ -233,2 +243,3 @@ if (_.contains(origFileReferences, filepath)) { | ||
// Return whether the file was changed | ||
if (lines.length == updatedFileLines.length) { | ||
@@ -253,2 +264,3 @@ var updated = false; | ||
var toreturn = { | ||
all: [], | ||
before: [], | ||
@@ -277,3 +289,3 @@ generated: [], | ||
// Which of the three sections we are in | ||
var loopState = referenceFileLoopState.before; | ||
var loopState = 0 /* before */; | ||
@@ -285,8 +297,9 @@ for (var i = 0; i < lines.length; i++) { | ||
//Wait for the end signature: | ||
loopState = referenceFileLoopState.unordered; | ||
loopState = 1 /* unordered */; | ||
} | ||
if (_str.include(line, ourSignatureEnd)) { | ||
loopState = referenceFileLoopState.after; | ||
loopState = 2 /* after */; | ||
} | ||
// Fetch the existing reference's filename if any: | ||
if (_str.include(line, referenceIntro)) { | ||
@@ -296,6 +309,6 @@ var match = line.match(referenceMatch); | ||
switch (loopState) { | ||
case referenceFileLoopState.before: | ||
case 0 /* before */: | ||
toreturn.before.push(filename); | ||
break; | ||
case referenceFileLoopState.unordered: | ||
case 1 /* unordered */: | ||
if (endsWith(line, generatedSignature)) { | ||
@@ -307,3 +320,3 @@ toreturn.generated.push(filename); | ||
break; | ||
case referenceFileLoopState.after: | ||
case 2 /* after */: | ||
toreturn.after.push(filename); | ||
@@ -328,2 +341,3 @@ break; | ||
}); | ||
toreturn.all = Array.prototype.concat.call([], toreturn.before, toreturn.generated, toreturn.unordered, toreturn.after); | ||
@@ -336,6 +350,16 @@ return toreturn; | ||
function sharedStart(array) { | ||
var A = array.slice(0).sort(), word1 = A[0], word2 = A[A.length - 1], i = 0; | ||
while (word1.charAt(i) == word2.charAt(i)) | ||
++i; | ||
return word1.substring(0, i); | ||
if (array.length == 0) | ||
throw "Cannot find common root of empty array."; | ||
var A = array.slice(0).sort(), firstWord = A[0], lastWord = A[A.length - 1]; | ||
if (firstWord === lastWord) | ||
return firstWord; | ||
else { | ||
var i = -1; | ||
do { | ||
i += 1; | ||
var firstWordChar = firstWord.charAt(i); | ||
var lastWordChar = lastWord.charAt(i); | ||
} while(firstWordChar == lastWordChar); | ||
return firstWord.substring(0, i); | ||
} | ||
} | ||
@@ -355,25 +379,61 @@ | ||
function updateAmdLoader(referenceFile, referencePath, loaderFile, loaderPath, outDir) { | ||
// Read the original file if it exists | ||
if (fs.existsSync(referenceFile)) { | ||
grunt.log.verbose.writeln('Generating amdloader from reference file ' + referenceFile); | ||
var files = getReferencesInOrder(referenceFile, referencePath); | ||
// Filter.d.ts, | ||
files.before = _.filter(files.before, function (file) { | ||
return !endsWith(file, '.d.ts'); | ||
}); | ||
files.generated = _.filter(files.generated, function (file) { | ||
return !endsWith(file, '.d.ts'); | ||
}); | ||
files.unordered = _.filter(files.unordered, function (file) { | ||
return !endsWith(file, '.d.ts'); | ||
}); | ||
files.after = _.filter(files.after, function (file) { | ||
return !endsWith(file, '.d.ts'); | ||
}); | ||
if (files.all.length > 0) { | ||
grunt.log.verbose.writeln('Files: ' + files.all.map(function (f) { | ||
return f.cyan; | ||
}).join(', ')); | ||
} else { | ||
grunt.warn("No files in reference file: " + referenceFile); | ||
} | ||
if (files.before.length > 0) { | ||
files.before = _.filter(files.before, function (file) { | ||
return !endsWith(file, '.d.ts'); | ||
}); | ||
grunt.log.verbose.writeln('Before: ' + files.before.map(function (f) { | ||
return f.cyan; | ||
}).join(', ')); | ||
} | ||
if (files.generated.length > 0) { | ||
files.generated = _.filter(files.generated, function (file) { | ||
return !endsWith(file, '.d.ts'); | ||
}); | ||
grunt.log.verbose.writeln('Generated: ' + files.generated.map(function (f) { | ||
return f.cyan; | ||
}).join(', ')); | ||
} | ||
if (files.unordered.length > 0) { | ||
files.unordered = _.filter(files.unordered, function (file) { | ||
return !endsWith(file, '.d.ts'); | ||
}); | ||
grunt.log.verbose.writeln('Unordered: ' + files.unordered.map(function (f) { | ||
return f.cyan; | ||
}).join(', ')); | ||
} | ||
if (files.after.length > 0) { | ||
files.after = _.filter(files.after, function (file) { | ||
return !endsWith(file, '.d.ts'); | ||
}); | ||
grunt.log.verbose.writeln('After: ' + files.after.map(function (f) { | ||
return f.cyan; | ||
}).join(', ')); | ||
} | ||
// If target has outDir we need to make adjust the path | ||
// c:/somefolder/ts/a , c:/somefolder/ts/inside/b + c:/somefolder/build/js => c:/somefolder/build/js/a , c:/somefolder/build/js/inside/b | ||
// Logic: | ||
// find the common structure in the source files ,and remove it | ||
// Finally: outDir path + remainder section | ||
if (outDir) { | ||
// Find common path | ||
var commonPath = findCommonPath(files.before.concat(files.generated.concat(files.unordered.concat(files.after)))); | ||
grunt.log.verbose.writeln('Found common path: ' + commonPath); | ||
// Make sure outDir is absolute: | ||
outDir = path.resolve(outDir); | ||
grunt.log.verbose.writeln('Using outDir: ' + outDir); | ||
@@ -398,2 +458,3 @@ function makeRelativeToOutDir(files) { | ||
} | ||
grunt.log.verbose.writeln("Making files relative to outDir..."); | ||
files.before = makeRelativeToOutDir(files.before); | ||
@@ -421,3 +482,5 @@ files.generated = makeRelativeToOutDir(files.generated); | ||
var loaderFileWithoutExtension = path.dirname(loaderFile) + pathSeperator + path.basename(loaderFile, '.js'); | ||
fs.writeFileSync(loaderFileWithoutExtension + binFileExtension, binaryContent); | ||
var binFilename = loaderFileWithoutExtension + binFileExtension; | ||
fs.writeFileSync(binFilename, binaryContent); | ||
grunt.log.verbose.writeln('Binary AMD loader written ' + binFilename.cyan); | ||
@@ -430,3 +493,3 @@ // | ||
// Build the subitem for ordered after items | ||
files.after = files.after.reverse(); | ||
files.after = files.after.reverse(); // Important to build inside out | ||
_.forEach(files.after, function (file) { | ||
@@ -438,4 +501,6 @@ subitem = singleRequireTemplate({ filename: '"' + file + '"', subitem: subitem }); | ||
// For these we will use just one require call | ||
var unorderFileNames = files.unordered.join('",' + eol + '\t\t "'); | ||
subitem = singleRequireTemplate({ filename: '"' + unorderFileNames + '"', subitem: subitem }); | ||
if (files.unordered.length > 0) { | ||
var unorderFileNames = files.unordered.join('",' + eol + '\t\t "'); | ||
subitem = singleRequireTemplate({ filename: '"' + unorderFileNames + '"', subitem: subitem }); | ||
} | ||
@@ -459,2 +524,3 @@ // Next the generated files | ||
fs.writeFileSync(loaderFile, output); | ||
grunt.log.verbose.writeln('AMD loader written ' + loaderFile.cyan); | ||
} | ||
@@ -542,4 +608,3 @@ } else { | ||
fileNameVariableSection: fileNameVariableSection, | ||
templateCachePut: templateCachePut | ||
}); | ||
templateCachePut: templateCachePut }); | ||
fs.writeFileSync(dest, fileContent); | ||
@@ -579,2 +644,3 @@ } | ||
// Remove comments based on the removeComments flag first then based on the comments flag, otherwise true | ||
if (options.removeComments === null) { | ||
@@ -654,2 +720,4 @@ options.removeComments = !options.comments; | ||
// If reference and out are both specified. | ||
// Then only compile the udpated reference file as that contains the correct order | ||
if (!!referencePath && target.out) { | ||
@@ -670,4 +738,5 @@ filesToCompile = [referenceFile]; | ||
// Evaluate the result | ||
if (result.code != 0) { | ||
var msg = "Compilation failed"/*+result.output*/ ; | ||
var msg = "Compilation failed"; | ||
grunt.log.error(msg.red); | ||
@@ -698,2 +767,4 @@ return false; | ||
// The template cache files do not go into generated files. | ||
// You are free to generate a `ts OR js` file, both should just work | ||
if (currenttask.data.templateCache) { | ||
@@ -728,2 +799,4 @@ if (!currenttask.data.templateCache.src || !currenttask.data.templateCache.dest || !currenttask.data.templateCache.baseUrl) { | ||
// Generate the reference file | ||
// Create a reference file if specified | ||
if (!!referencePath) { | ||
@@ -738,5 +811,7 @@ var result = timeIt(function () { | ||
// compile, If there are any files to compile! | ||
if (files.length > 0) { | ||
success = runCompilation(files, target, options); | ||
// Create the loader if specified & compiliation succeeded | ||
if (success && !!amdloaderPath) { | ||
@@ -765,5 +840,8 @@ updateAmdLoader(referenceFile, referencePath, amdloaderFile, amdloaderPath, target.outDir); | ||
function handleFileEvent(filepath, displaystr) { | ||
// Only ts and html : | ||
if (!endsWith(filepath.toLowerCase(), '.ts') && !endsWith(filepath.toLowerCase(), '.html')) | ||
return; | ||
// Do not run if just ran, behaviour same as grunt-watch | ||
// These are the files our run modified | ||
if ((new Date().getTime() - endtime) <= 100) { | ||
@@ -807,5 +885,3 @@ //grunt.log.writeln((' ///' + ' >>' + filepath).grey); | ||
} | ||
module.exports = pluginFn; | ||
//# sourceMappingURL=ts.js.map |
228
tasks/ts.ts
@@ -67,9 +67,10 @@ /// <reference path="../defs/node/node.d.ts"/> | ||
*/ | ||
function insertArrayAt(array: string[], index: number, arrayToInsert: string[]): string[] { | ||
function insertArrayAt<T>(array: T[], index: number, arrayToInsert: T[]): T[] { | ||
var updated = array.slice(0); | ||
Array.prototype.splice.apply(updated, [index, 0].concat(arrayToInsert)); | ||
var spliceAt: any[] = [index, 0]; | ||
Array.prototype.splice.apply(updated, spliceAt.concat(arrayToInsert)); | ||
return updated; | ||
} | ||
// Useful string functions | ||
// used to make sure string ends with a slash | ||
// Useful string functions | ||
// used to make sure string ends with a slash | ||
function endsWith(str: string, suffix: string) { | ||
@@ -95,7 +96,7 @@ return str.indexOf(suffix, str.length - suffix.length) !== -1; | ||
*/ | ||
it: R | ||
it: R | ||
/** | ||
* Time in milliseconds. | ||
*/ | ||
time: number | ||
time: number | ||
} { | ||
@@ -111,3 +112,3 @@ var starttime = new Date().getTime(); | ||
// Typescript imports | ||
// Typescript imports | ||
import _ = require('underscore'); | ||
@@ -117,6 +118,4 @@ import _str = require('underscore.string'); | ||
import fs = require('fs'); | ||
import os = require('os'); | ||
// plain vanilla imports | ||
var shell = require('shelljs'); | ||
var eol = os.EOL; | ||
var pathSeperator = path.sep; | ||
@@ -129,3 +128,3 @@ | ||
///////////////////////////////////////////////////////////////////// | ||
// tsc handling. | ||
// tsc handling. | ||
//////////////////////////////////////////////////////////////////// | ||
@@ -147,4 +146,5 @@ | ||
function getTsc(binPath: string): string { | ||
return '"' + binPath + '/' + 'tsc" '; | ||
return '"' + binPath + '/' + 'tsc"'; | ||
} | ||
var eol = grunt.util.linefeed; | ||
var exec = shell.exec; | ||
@@ -154,10 +154,7 @@ var cwd = path.resolve("."); | ||
// Blindly runs the tsc task using provided options | ||
// Blindly runs the tsc task using provided options | ||
function compileAllFiles(files: string[], target: ITargetOptions, task: ITaskOptions): ICompileResult { | ||
var filepath: string = files.join(' '); | ||
var tscExecCommand = 'node ' + tsc; | ||
var cmd = filepath; | ||
// boolean options | ||
var cmd: string = files.join(' '); | ||
// boolean options | ||
if (task.sourceMap) | ||
@@ -178,3 +175,3 @@ cmd = cmd + ' --sourcemap'; | ||
// Target options: | ||
// Target options: | ||
if (target.out) { | ||
@@ -196,8 +193,13 @@ cmd = cmd + ' --out ' + target.out; | ||
var tscExecCommand = 'node ' + tsc + ' ' + cmd; | ||
// To debug the tsc command | ||
if (task.verbose) { | ||
console.log(cmd); | ||
console.log(tscExecCommand.yellow); | ||
} | ||
else { | ||
grunt.log.verbose.writeln(cmd.yellow); | ||
} | ||
// Create a temp last command file | ||
// Create a temp last command file | ||
var tempfilename = 'tscommand.tmp.txt'; | ||
@@ -211,7 +213,7 @@ fs.writeFileSync(tempfilename, cmd); | ||
///////////////////////////////////////////////////////////////////// | ||
///////////////////////////////////////////////////////////////////// | ||
// Reference file logic | ||
//////////////////////////////////////////////////////////////////// | ||
// Converts "C:\boo" , "C:\boo\foo.ts" => "./foo.ts"; Works on unix as well. | ||
// Converts "C:\boo" , "C:\boo\foo.ts" => "./foo.ts"; Works on unix as well. | ||
function makeReferencePath(folderpath: string, filename: string) { | ||
@@ -221,3 +223,3 @@ return path.relative(folderpath, filename).split('\\').join('/'); | ||
// Updates the reference file | ||
// Updates the reference file | ||
function updateReferenceFile(files: string[], generatedFiles: string[], referenceFile: string, referencePath: string): boolean { | ||
@@ -233,3 +235,3 @@ var referenceIntro = '/// <reference path="'; | ||
var origFileLines = []; // The lines we do not modify and send out as is. Lines will we reach grunt-ts generated | ||
var origFileReferences = []; // The list of files already there that we do not need to manage | ||
var origFileReferences = []; // The list of files already there that we do not need to manage | ||
@@ -240,3 +242,3 @@ // Location of our generated references | ||
// Read the original file if it exists | ||
// Read the original file if it exists | ||
if (fs.existsSync(referenceFile)) { | ||
@@ -254,5 +256,5 @@ lines = fs.readFileSync(referenceFile).toString().split('\n'); | ||
// Skip logic for our generated section | ||
// Skip logic for our generated section | ||
if (_str.include(line, ourSignatureStart)) { | ||
//Wait for the end signature: | ||
//Wait for the end signature: | ||
signatureSectionPosition = i; | ||
@@ -268,6 +270,6 @@ inSignatureSection = true; | ||
// store the line | ||
// store the line | ||
origFileLines.push(line); | ||
// Fetch the existing reference's filename if any: | ||
// Fetch the existing reference's filename if any: | ||
if (_str.include(line, referenceIntro)) { | ||
@@ -281,12 +283,12 @@ var match = line.match(referenceMatch); | ||
// Put in the generated files | ||
// Put in the generated files | ||
generatedFiles = _.map(generatedFiles, (file) => referenceIntro + makeReferencePath(referencePath, file) + referenceEnd + generatedSignature); | ||
var contents = insertArrayAt([ourSignatureStart], 1, generatedFiles); | ||
// Put in the new / observed missing files: | ||
// Put in the new / observed missing files: | ||
files.forEach((filename: string) => { | ||
// The file we are about to add | ||
// The file we are about to add | ||
var filepath = makeReferencePath(referencePath, filename); | ||
// If there are orig references | ||
// If there are orig references | ||
if (origFileReferences.length) { | ||
@@ -298,3 +300,3 @@ if (_.contains(origFileReferences, filepath)) { | ||
// Finally add the filepath | ||
// Finally add the filepath | ||
contents.push(referenceIntro + filepath + referenceEnd); | ||
@@ -324,9 +326,10 @@ }); | ||
///////////////////////////////////////////////////////////////////// | ||
// AMD Loader, creates a js file that loads a few files in order | ||
///////////////////////////////////////////////////////////////////// | ||
// AMD Loader, creates a js file that loads a few files in order | ||
// and the rest un orderded, based on the reference.ts spec | ||
//////////////////////////////////////////////////////////////////// | ||
function getReferencesInOrder(referenceFile: string, referencePath: string): { before: string[]; generated: string[]; unordered: string[]; after: string[]; } { | ||
function getReferencesInOrder(referenceFile: string, referencePath: string): { all: string[]; before: string[]; generated: string[]; unordered: string[]; after: string[]; } { | ||
var toreturn = { | ||
all: [], | ||
before: [], | ||
@@ -338,14 +341,14 @@ generated: [], | ||
// When reading | ||
// When reading | ||
var referenceMatch = /\/\/\/ <reference path=\"(.*?)\"/; | ||
// When writing | ||
// When writing | ||
var referenceIntro = '/// <reference path="'; | ||
var referenceEnd = '" />'; | ||
// The section of unordered files | ||
// The section of unordered files | ||
var ourSignatureStart = '//grunt-start'; | ||
var ourSignatureEnd = '//grunt-end'; | ||
// The generated files. These must go on top | ||
// The generated files. These must go on top | ||
var generatedSignature = "// generated"; | ||
@@ -355,3 +358,3 @@ | ||
// Which of the three sections we are in | ||
// Which of the three sections we are in | ||
var loopState = referenceFileLoopState.before; | ||
@@ -364,3 +367,3 @@ | ||
if (_str.include(line, ourSignatureStart)) { | ||
//Wait for the end signature: | ||
//Wait for the end signature: | ||
loopState = referenceFileLoopState.unordered; | ||
@@ -373,3 +376,3 @@ } | ||
// Fetch the existing reference's filename if any: | ||
// Fetch the existing reference's filename if any: | ||
if (_str.include(line, referenceIntro)) { | ||
@@ -397,3 +400,3 @@ var match = line.match(referenceMatch); | ||
// Fix the references to be absolute: | ||
// Fix the references to be absolute: | ||
toreturn.before = _.map(toreturn.before, (relativepath) => { return path.resolve(referencePath, relativepath); }); | ||
@@ -403,2 +406,3 @@ toreturn.generated = _.map(toreturn.generated, (relativepath) => { return path.resolve(referencePath, relativepath); }); | ||
toreturn.after = _.map(toreturn.after, (relativepath) => { return path.resolve(referencePath, relativepath); }); | ||
toreturn.all = Array.prototype.concat.call([], toreturn.before, toreturn.generated, toreturn.unordered, toreturn.after); | ||
@@ -408,15 +412,24 @@ return toreturn; | ||
// Finds the longest common section of a collection of strings. | ||
// Finds the longest common section of a collection of strings. | ||
// Simply sorting and comparing first and last http://stackoverflow.com/a/1917041/390330 | ||
function sharedStart(array: string[]) { | ||
function sharedStart(array: string[]): string { | ||
if (array.length == 0) throw "Cannot find common root of empty array."; | ||
var A = array.slice(0).sort(), | ||
word1 = A[0], word2 = A[A.length - 1], | ||
i = 0; | ||
while (word1.charAt(i) == word2.charAt(i))++i; | ||
return word1.substring(0, i); | ||
firstWord = A[0], | ||
lastWord = A[A.length - 1]; | ||
if (firstWord === lastWord) return firstWord; | ||
else { | ||
var i = -1; | ||
do { | ||
i += 1; | ||
var firstWordChar = firstWord.charAt(i); | ||
var lastWordChar = lastWord.charAt(i); | ||
} while (firstWordChar == lastWordChar); | ||
return firstWord.substring(0, i); | ||
} | ||
} | ||
// Explanation inline | ||
// Explanation inline | ||
function findCommonPath(paths: string[]) { | ||
// Now for "C:\u\starter" "C:\u\started" => "C:\u\starte" | ||
// Now for "C:\u\starter" "C:\u\started" => "C:\u\starte" | ||
var largetStartSegement = sharedStart(paths); | ||
@@ -429,39 +442,60 @@ | ||
// It updates based on the order of reference files | ||
// It updates based on the order of reference files | ||
function updateAmdLoader(referenceFile: string, referencePath: string, loaderFile: string, loaderPath: string, outDir: string) { | ||
// Read the original file if it exists | ||
// Read the original file if it exists | ||
if (fs.existsSync(referenceFile)) { | ||
grunt.log.verbose.writeln('Generating amdloader from reference file ' + referenceFile); | ||
var files = getReferencesInOrder(referenceFile, referencePath); | ||
// Filter.d.ts, | ||
files.before = _.filter(files.before, (file) => { return !endsWith(file, '.d.ts'); }); | ||
files.generated = _.filter(files.generated, (file) => { return !endsWith(file, '.d.ts'); }); | ||
files.unordered = _.filter(files.unordered, (file) => { return !endsWith(file, '.d.ts'); }); | ||
files.after = _.filter(files.after, (file) => { return !endsWith(file, '.d.ts'); }); | ||
// Filter.d.ts, | ||
if (files.all.length > 0) { | ||
grunt.log.verbose.writeln('Files: ' + files.all.map((f) => f.cyan).join(', ')); | ||
} | ||
else { | ||
grunt.warn("No files in reference file: " + referenceFile); | ||
} | ||
if (files.before.length > 0) { | ||
files.before = _.filter(files.before, (file) => { return !endsWith(file, '.d.ts'); }); | ||
grunt.log.verbose.writeln('Before: ' + files.before.map((f) => f.cyan).join(', ')); | ||
} | ||
if (files.generated.length > 0) { | ||
files.generated = _.filter(files.generated, (file) => { return !endsWith(file, '.d.ts'); }); | ||
grunt.log.verbose.writeln('Generated: ' + files.generated.map((f) => f.cyan).join(', ')); | ||
} | ||
if (files.unordered.length > 0) { | ||
files.unordered = _.filter(files.unordered, (file) => { return !endsWith(file, '.d.ts'); }); | ||
grunt.log.verbose.writeln('Unordered: ' + files.unordered.map((f) => f.cyan).join(', ')); | ||
} | ||
if (files.after.length > 0) { | ||
files.after = _.filter(files.after, (file) => { return !endsWith(file, '.d.ts'); }); | ||
grunt.log.verbose.writeln('After: ' + files.after.map((f) => f.cyan).join(', ')); | ||
} | ||
// If target has outDir we need to make adjust the path | ||
// If target has outDir we need to make adjust the path | ||
// c:/somefolder/ts/a , c:/somefolder/ts/inside/b + c:/somefolder/build/js => c:/somefolder/build/js/a , c:/somefolder/build/js/inside/b | ||
// Logic: | ||
// find the common structure in the source files ,and remove it | ||
// Finally: outDir path + remainder section | ||
// Logic: | ||
// find the common structure in the source files ,and remove it | ||
// Finally: outDir path + remainder section | ||
if (outDir) { | ||
// Find common path | ||
// Find common path | ||
var commonPath = findCommonPath(files.before.concat(files.generated.concat(files.unordered.concat(files.after)))); | ||
grunt.log.verbose.writeln('Found common path: ' + commonPath); | ||
// Make sure outDir is absolute: | ||
// Make sure outDir is absolute: | ||
outDir = path.resolve(outDir); | ||
grunt.log.verbose.writeln('Using outDir: ' + outDir); | ||
function makeRelativeToOutDir(files: string[]) { | ||
files = _.map(files, (file) => { | ||
// Remove common path and replace with absolute outDir | ||
// Remove common path and replace with absolute outDir | ||
file = file.replace(commonPath, outDir); | ||
//remove ts extension '.ts': | ||
//remove ts extension '.ts': | ||
file = file.substr(0, file.length - 3); | ||
// Make relative to amd loader | ||
// Make relative to amd loader | ||
file = makeReferencePath(loaderPath, file); | ||
// Prepend "./" to prevent "basePath" requirejs setting from interferring: | ||
// Prepend "./" to prevent "basePath" requirejs setting from interferring: | ||
file = "./" + file; | ||
@@ -473,2 +507,3 @@ | ||
} | ||
grunt.log.verbose.writeln("Making files relative to outDir..."); | ||
files.before = makeRelativeToOutDir(files.before); | ||
@@ -489,10 +524,10 @@ files.generated = makeRelativeToOutDir(files.generated); | ||
// The final body of the function | ||
// The final body of the function | ||
var body = ''; | ||
// initial sub item | ||
// initial sub item | ||
var subitem = ''; | ||
// Write out a binary file: | ||
// Write out a binary file: | ||
var binaryTemplate = _.template('define(["<%= filenames %>"],function () {});'); | ||
@@ -503,12 +538,14 @@ var binaryFilesNames = files.before.concat(files.generated.concat(files.unordered.concat(files.after))); | ||
var loaderFileWithoutExtension = path.dirname(loaderFile) + pathSeperator + path.basename(loaderFile, '.js'); | ||
fs.writeFileSync(loaderFileWithoutExtension + binFileExtension, binaryContent); | ||
var binFilename = loaderFileWithoutExtension + binFileExtension; | ||
fs.writeFileSync(binFilename, binaryContent); | ||
grunt.log.verbose.writeln('Binary AMD loader written ' + binFilename.cyan); | ||
// | ||
// Notice that we build inside out in the below sections: | ||
// | ||
// Notice that we build inside out in the below sections: | ||
// | ||
// Generate fileTemplate from inside out | ||
// Start with after | ||
// Build the subitem for ordered after items | ||
files.after = files.after.reverse(); // Important to build inside out | ||
// Generate fileTemplate from inside out | ||
// Start with after | ||
// Build the subitem for ordered after items | ||
files.after = files.after.reverse(); // Important to build inside out | ||
_.forEach(files.after, (file) => { | ||
@@ -518,8 +555,10 @@ subitem = singleRequireTemplate({ filename: '"' + file + '"', subitem: subitem }); | ||
// Next up add the unordered items: | ||
// Next up add the unordered items: | ||
// For these we will use just one require call | ||
var unorderFileNames = files.unordered.join('",' + eol + '\t\t "'); | ||
subitem = singleRequireTemplate({ filename: '"' + unorderFileNames + '"', subitem: subitem }); | ||
if (files.unordered.length > 0) { | ||
var unorderFileNames = files.unordered.join('",' + eol + '\t\t "'); | ||
subitem = singleRequireTemplate({ filename: '"' + unorderFileNames + '"', subitem: subitem }); | ||
} | ||
// Next the generated files | ||
// Next the generated files | ||
// For these we will use just one require call | ||
@@ -529,3 +568,3 @@ var generatedFileNames = files.generated.join('",' + eol + '\t\t "'); | ||
// Build the subitem for ordered before items | ||
// Build the subitem for ordered before items | ||
files.before = files.before.reverse(); | ||
@@ -536,8 +575,9 @@ _.forEach(files.before, (file) => { | ||
// The last subitem is now the body | ||
// The last subitem is now the body | ||
body = subitem; | ||
var output = mainTemplate({ body: body }); | ||
// Finally write it out | ||
// Finally write it out | ||
fs.writeFileSync(loaderFile, output); | ||
grunt.log.verbose.writeln('AMD loader written ' + loaderFile.cyan); | ||
} | ||
@@ -621,10 +661,10 @@ } | ||
var templateCachePutTemplate = _.template('$templateCache.put("<%= fileName %>", <%=fileVariableName%>);'); | ||
var templateCachePut = _.map(fileNames, (fileName) => templateCachePutTemplate({ | ||
fileName: fileName, | ||
fileVariableName: fileVarialbeName(fileName) | ||
})).join(eol); | ||
var templateCachePut = _.map(fileNames, (fileName) => templateCachePutTemplate({ | ||
fileName: fileName, | ||
fileVariableName: fileVarialbeName(fileName) | ||
})).join(eol); | ||
var fileContent = templateCacheTemplate({ | ||
relativePathSection: relativePathSection, | ||
fileNameVariableSection: fileNameVariableSection, | ||
var fileContent = templateCacheTemplate({ | ||
relativePathSection: relativePathSection, | ||
fileNameVariableSection: fileNameVariableSection, | ||
templateCachePut: templateCachePut }); | ||
@@ -631,0 +671,0 @@ fs.writeFileSync(dest, fileContent); |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
316509
3.97%6833
2.41%19
-9.52%