Skip to content

Commit b0c9a8a

Browse files
committed
Fixes files in src: dest: style.
1 parent 97ad399 commit b0c9a8a

File tree

16 files changed

+159
-33
lines changed

16 files changed

+159
-33
lines changed

Gruntfile.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,14 +178,20 @@ module.exports = function (grunt) {
178178
},
179179
files_testFilesUsedWithDestAsAJSFile: {
180180
test: true,
181-
files: [{ src: ['test/multifile/a/**/*.ts'], dest: 'test/multifile/files_testFilesUsedWithDestAsAJSFile/testDest.js' }],
181+
files: [
182+
{ src: ['test/multifile/a/**/*.ts'],
183+
dest: 'test/multifile/files_testFilesUsedWithDestAsAJSFile/testDest.js' }
184+
],
182185
options: {
183186
fast: 'never'
184187
}
185188
},
186189
files_testFilesUsedWithDestAsAFolder: {
187190
test: true,
188-
files: [{ src: ['test/multifile/a/**/*.ts'], dest: 'test/multifile/files_testFilesUsedWithDestAsAJSFile' }],
191+
files: [
192+
{ src: ['test/multifile/a/**/*.ts'],
193+
dest: 'test/multifile/files_testFilesUsedWithDestAsAJSFolder' }
194+
],
189195
options: {
190196
fast: 'never'
191197
}
@@ -198,6 +204,7 @@ module.exports = function (grunt) {
198204
}
199205
},
200206
files_testWarnIfFilesHasDestArray: {
207+
// TODO: This test is currently broken. grunt-ts does not warn.
201208
test: true,
202209
files: [{ src: ['test/multifile/a/**/*.ts'], dest: ['test/multifile/a', 'test/multifile/b'] }],
203210
options: {

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -968,6 +968,17 @@ The easiest/fastest way to work on grunt-ts is to modify `tasksToTest` toward th
968968

969969
Without using `tasksToTest` while working on grunt-ts, the old grunt-ts remains in memory for successive tasks on the same run. This means you might have to run your grunt commands twice; once to compile grunt-ts and once to see how the new grunt-ts works with your code.
970970

971+
### Quickstart for debugging Grunt plugins with Node Inspector
972+
973+
Install [Node Inspector](https://github.com/node-inspector/node-inspector) via npm:
974+
975+
`npm install -g node-inspector`
976+
977+
Example command-line to debug a grunt-ts task on Windows:
978+
979+
`node-debug --debug-brk %appdata%\npm\node_modules\grunt-cli\bin\grunt ts:files_testFilesUsedWithDestAsAJSFile`
980+
981+
Set breakpoints in the Chrome dev tools, or use `debugger;` where needed.
971982

972983
### Additional commands
973984
Update the current `grunt-ts` to be the last known good version (dogfood). Commit message should be `Update LKG`.

tasks/modules/compile.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,12 @@ function compileAllFiles(targetFiles, target, task, targetName, outFile) {
160160
}
161161
// Target options:
162162
if (outFile) {
163-
args.push('--out', outFile);
163+
if (utils.isJavaScriptFile(outFile)) {
164+
args.push('--out', outFile);
165+
}
166+
else {
167+
args.push('--outDir', outFile);
168+
}
164169
}
165170
else if (target.out) {
166171
args.push('--out', target.out);
@@ -177,13 +182,18 @@ function compileAllFiles(targetFiles, target, task, targetName, outFile) {
177182
}
178183
else {
179184
if (target.dest === 'src') {
180-
console.warn(('WARNING: Destination for target "' + targetName + '" is "src", which is the default. If you have' + ' forgotten to specify a "dest" parameter, please add it. If this is correct, you may wish' + ' to change the "dest" parameter to "src/" or just ignore this warning.').magenta);
185+
console.warn(('WARNING: Destination for target "' + targetName + '" is "src", which is the default. If you have' +
186+
' forgotten to specify a "dest" parameter, please add it. If this is correct, you may wish' +
187+
' to change the "dest" parameter to "src/" or just ignore this warning.').magenta);
181188
}
182189
if (Array.isArray(target.dest)) {
183190
if (target.dest.length === 0) {
184191
}
185192
else if (target.dest.length > 0) {
186-
console.warn((('WARNING: "dest" for target "' + targetName + '" is an array. This is not supported by the' + ' TypeScript compiler or grunt-ts.' + ((target.dest.length > 1) ? ' Only the first "dest" will be used. The' + ' remaining items will be truncated.' : ''))).magenta);
193+
console.warn((('WARNING: "dest" for target "' + targetName + '" is an array. This is not supported by the' +
194+
' TypeScript compiler or grunt-ts.' +
195+
((target.dest.length > 1) ? ' Only the first "dest" will be used. The' +
196+
' remaining items will be truncated.' : ''))).magenta);
187197
args.push('--outDir', target.dest[0]);
188198
}
189199
}
@@ -236,4 +246,3 @@ function compileAllFiles(targetFiles, target, task, targetName, outFile) {
236246
});
237247
}
238248
exports.compileAllFiles = compileAllFiles;
239-
//# sourceMappingURL=compile.js.map

tasks/modules/compile.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import _ = require('lodash');
77
import utils = require('./utils');
88
import cache = require('./cacheUtils');
99

10-
var Promise: typeof Promise = require('es6-promise').Promise;
10+
var Promise = require('es6-promise').Promise;
1111
export var grunt: IGrunt = require('grunt');
1212

1313
export interface ICompileResult {
@@ -201,7 +201,11 @@ export function compileAllFiles(targetFiles: string[],
201201

202202
// Target options:
203203
if (outFile) {
204-
args.push('--out', outFile);
204+
if (utils.isJavaScriptFile(outFile)) {
205+
args.push('--out', outFile);
206+
} else {
207+
args.push('--outDir', outFile);
208+
}
205209
} else if (target.out) {
206210
args.push('--out', target.out);
207211
}

tasks/modules/utils.js

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

tasks/modules/utils.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export function isJavaScriptFile(filePath: string): boolean {
8080
return false;
8181
}
8282

83-
/** function for formatting strings
83+
/** function for formatting strings
8484
* ('{0} says {1}','la','ba' ) => 'la says ba'
8585
*/
8686
export function format(str: string, ...args: any[]) {
@@ -136,7 +136,7 @@ export function getTempFile(prefix?: string, dir: string = '', extension = '.tmp
136136
* Get all files from a directory and all its subdirectories.
137137
* @param {String} dirPath A path to a directory
138138
* @param {RegExp|Function} exclude Defines which files should be excluded.
139-
Can be a RegExp (whole filepath is tested) or a Function which will get the filepath
139+
Can be a RegExp (whole filepath is tested) or a Function which will get the filepath
140140
as an argument and should return true (exclude file) or false (do not exclude).
141141
* @returns {Array} An array of files
142142
*/
@@ -147,8 +147,8 @@ export function getFiles(dirPath, exclude?: (filename: string) => boolean): stri
147147
/**
148148
* Get all directories from a directory and all its subdirectories.
149149
* @param {String} dirPath A path to a directory
150-
* @param {RegExp|Function} exclude Defines which directories should be excluded.
151-
Can be a RegExp (whole dirpath is tested) or a Function which will get the dirpath
150+
* @param {RegExp|Function} exclude Defines which directories should be excluded.
151+
Can be a RegExp (whole dirpath is tested) or a Function which will get the dirpath
152152
as an argument and should return true (exclude dir) or false (do not exclude).
153153
* @returns {Array} An array of directories
154154
*/
@@ -159,8 +159,8 @@ export function getDirs(dirPath, exclude?: (filename: string) => boolean): strin
159159
/**
160160
* Get all files or directories from a directory and all its subdirectories.
161161
* @param {String} dirPath A path to a directory
162-
* @param {RegExp|Function} exclude Defines which files or directories should be excluded.
163-
Can be a RegExp (whole path is tested) or a Function which will get the path
162+
* @param {RegExp|Function} exclude Defines which files or directories should be excluded.
163+
Can be a RegExp (whole path is tested) or a Function which will get the path
164164
as an argument and should return true (exclude) or false (do not exclude).
165165
* @param {Boolean} getFiles Whether to get files (true) or directories (false).
166166
* @returns {Array} An array of files or directories
@@ -252,3 +252,13 @@ export function firstElementWithValue<T>(elements: T[], defaultResult: T = null)
252252
});
253253
return result;
254254
}
255+
256+
export function getOrGetFirst(getFrom: string | string[]) : string {
257+
if (_.isArray(getFrom)) {
258+
if (getFrom.length > 0) {
259+
return getFrom[0];
260+
}
261+
return '';
262+
}
263+
return <string>getFrom;
264+
}

tasks/ts.js

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

tasks/ts.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -317,21 +317,22 @@ function pluginFn(grunt: IGrunt) {
317317
var targetout = target.out;
318318
if (!targetout) {
319319
if (target.dest) {
320-
if (Array.isArray(target.dest)) {
321-
if ((<string[]><any>target.dest).length > 0) {
322-
// A dest array is meaningless in TypeScript, so just take
323-
// the first one.
324-
targetout = (<string[]><any>target.dest)[0];
325-
}
326-
} else if (utils.isJavaScriptFile(target.dest)) {
327-
targetout = target.dest;
328-
}
320+
// A dest array is meaningless in TypeScript, so just take
321+
// the first one.
322+
targetout = utils.getOrGetFirst(target.dest);
329323
}
330324
else if (target.files) {
331325
var filesKeys = _.keys(target.files);
332326
if (filesKeys.length > filesCompilationIndex &&
333327
utils.isJavaScriptFile(filesKeys[filesCompilationIndex])) {
334328
targetout = filesKeys[filesCompilationIndex];
329+
} else if (filesKeys.length > filesCompilationIndex &&
330+
target.files[filesKeys[filesCompilationIndex]].dest) {
331+
targetout = utils.getOrGetFirst(
332+
// A dest array is meaningless in TypeScript, so just take
333+
// the first one.
334+
target.files[filesKeys[filesCompilationIndex]].dest
335+
);
335336
}
336337
}
337338
}

test/expected/multifile/files_testFilesUsedWithDestAsAJSFile/testDest.js

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

test/expected/multifile/files_testFilesUsedWithDestAsAJSFolder/a.js

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

0 commit comments

Comments
 (0)