Comparing version 1.0.1 to 1.1.2
@@ -1,11 +0,16 @@ | ||
// What grunt adds to stirng | ||
// What grunt adds to string | ||
// https://github.com/marak/colors.js/ | ||
interface String { | ||
yellow: string; | ||
cyan: string; | ||
white: string; | ||
magenta: string; | ||
green: string; | ||
red: string; | ||
red: string; | ||
grey: string; | ||
blue: string; | ||
} | ||
interface ITask{ | ||
interface ITask { | ||
// options from user point : http://gruntjs.com/configuring-tasks#options | ||
@@ -18,2 +23,3 @@ // options from plugin dev point: http://gruntjs.com/api/inside-tasks#this.options | ||
src: any; | ||
html: any; // SPECIFIC TO GRUNT-TS | ||
} | ||
@@ -63,3 +69,3 @@ } | ||
// Options https://github.com/gruntjs/grunt/wiki/grunt.option | ||
option: { (key: string):any; init: Function; flags:Function}; | ||
option: { (key: string): any; init: Function; flags: Function }; | ||
// Template | ||
@@ -115,4 +121,4 @@ template: any; | ||
// Globbing patterns | ||
expand(patterns):string[]; | ||
expand(options, patterns):string[]; | ||
expand(patterns): string[]; | ||
expand(options, patterns): string[]; | ||
expandMapping(patterns, dest, options?); | ||
@@ -119,0 +125,0 @@ match(patterns, filepaths); |
@@ -9,2 +9,3 @@ module.exports = function (grunt) { | ||
"test/**/*.js", | ||
"test/**/*.html.ts", | ||
] | ||
@@ -24,4 +25,3 @@ }, | ||
src: ["test/work/**/*.ts"], // The source typescript files, See : http://gruntjs.com/configuring-tasks#files | ||
out: 'test/work/out.js', // If specified, generate an out.js file which is the merged js file | ||
watch: 'test/work', // If specified, configures this target to watch the specified director for ts changes and reruns itself. | ||
out: 'test/work/out.js', // If specified, generate an out.js file which is the merged js file | ||
options: { // override the main options, See : http://gruntjs.com/configuring-tasks#options | ||
@@ -32,21 +32,26 @@ sourcemap: true, | ||
}, | ||
fail: { // another target | ||
src: ["test/fail/*.ts"], | ||
options: { // overide the main options for this target | ||
sourcemap: false, | ||
} | ||
}, | ||
abtest: { | ||
src: ['test/abtest/**/*.ts'], | ||
reference: 'test/abtest/reference.ts', | ||
out: 'test/abtest/out.js', | ||
watch: 'test/abtest' | ||
out: 'test/abtest/out.js', | ||
}, | ||
amdtest: { | ||
src: ['test/amdtest/**/*.ts'], | ||
watch: 'test/amdtest', | ||
src: ['test/amdtest/**/*.ts'], | ||
options: { | ||
module: 'amd' | ||
} | ||
} | ||
}, | ||
htmltest: { | ||
src: ['test/html/**/*.ts'], | ||
html: ['test/html/**/*.tpl.html'], | ||
reference: 'test/html/reference.ts', | ||
out: 'test/html/out.js', | ||
}, | ||
fail: { // a designed to fail target | ||
src: ["test/fail/**/*.ts"], | ||
watch: 'test', | ||
options: { // overide the main options for this target | ||
sourcemap: false, | ||
} | ||
}, | ||
}, | ||
@@ -60,6 +65,7 @@ }); | ||
grunt.loadNpmTasks("grunt-contrib-clean"); | ||
grunt.registerTask("test", ["clean", "ts"]); | ||
grunt.loadNpmTasks("grunt-contrib-clean"); | ||
grunt.registerTask("test", ["clean", "ts:htmltest"]); | ||
grunt.registerTask("default", ["test"]); | ||
}; |
@@ -5,3 +5,3 @@ { | ||
"description": "Compile and manage your TypeScript project", | ||
"version": "1.0.1", | ||
"version": "1.1.2", | ||
"homepage": "https://github.com/basarat/grunt-ts", | ||
@@ -26,7 +26,5 @@ "repository": { | ||
"dependencies": { | ||
"grunt": "~0.4.0", | ||
"typescript": "0.9.1", | ||
"grunt-lib-contrib": "0.5.2", | ||
"chokidar": "0.6.2", | ||
"shelljs": "0.1.4", | ||
"chokidar": "0.6.2", | ||
"underscore": "1.5.1", | ||
@@ -40,7 +38,5 @@ "underscore.string": "2.3.3" | ||
"grunt": "~0.4.0", | ||
"typescript": "0.9.1", | ||
"grunt-contrib-clean": "~0.4.0", | ||
"grunt-contrib-nodeunit": "~0.1.2", | ||
"shelljs":"0.1.4", | ||
"matchdep": "0.1.1" | ||
"grunt-contrib-watch": "~0.5.1", | ||
"grunt-contrib-nodeunit": "~0.1.2" | ||
}, | ||
@@ -47,0 +43,0 @@ "optionalDependencies": {}, |
@@ -25,7 +25,6 @@ grunt-ts | ||
- comments | ||
- nolib | ||
Can also do js *file concatenation* using `--out` | ||
Can also do js *file concatenation* using `--out`. For file ordering look at Javascript Generation below. | ||
###Reference file generation | ||
@@ -63,2 +62,16 @@ Can generate a reference.ts file for you which contains a reference to all your ts files. | ||
``` | ||
###Html 2 TypeScript support | ||
Can reencode html files into typescript and makes them available as a variable. e.g. | ||
a file called `test.html` containing | ||
```html | ||
<div> Some Content </div> | ||
``` | ||
is compiled to a typescript file `test.html.ts` containing: | ||
```typescript | ||
module test { export var html = '<div> Some content </div>' } | ||
``` | ||
so that you can use use the variable `test.html` within your typescript to get the content of test.html | ||
as a string :) | ||
###Live file watching and building | ||
@@ -68,2 +81,3 @@ Can watch a directory for you and recompile your typescript files when any typescript file changes, gets added, gets removed. | ||
npm install | ||
@@ -98,4 +112,3 @@ ====================== | ||
reference: "./test/reference.ts", // If specified, generate this file that you can use for your reference management | ||
out: 'test/out.js', // If specified, generate an out.js file which is the merged js file | ||
watch: 'test', // If specified, configures this target to watch the specified director for ts changes and reruns itself. | ||
out: 'test/out.js', // If specified, generate an out.js file which is the merged js file | ||
options: { // override the main options, http://gruntjs.com/configuring-tasks#options | ||
@@ -107,3 +120,3 @@ sourcemap: true, | ||
build: { // another target | ||
src: ["test/fail/*.ts"], | ||
src: ["test/work/**/*.ts"], | ||
options: { // overide the main options for this target | ||
@@ -110,0 +123,0 @@ sourcemap: false, |
141
tasks/ts.js
@@ -32,2 +32,5 @@ // General util functions | ||
function pluginFn(grunt) { | ||
///////////////////////////////////////////////////////////////////// | ||
// tsc handling. | ||
//////////////////////////////////////////////////////////////////// | ||
function resolveTypeScriptBinPath(currentPath, depth) { | ||
@@ -44,7 +47,5 @@ var targetPath = path.resolve(__dirname, (new Array(depth + 1)).join("../../"), "../node_modules/typescript/bin"); | ||
} | ||
function getTsc(binPath) { | ||
return '"' + binPath + '/' + 'tsc" '; | ||
} | ||
var exec = shell.exec; | ||
@@ -80,4 +81,7 @@ var cwd = path.resolve("."); | ||
///////////////////////////////////////////////////////////////////// | ||
// Reference file logic | ||
//////////////////////////////////////////////////////////////////// | ||
// Updates the reference file | ||
function updateReferenceFile(files, referenceFile, referencePath) { | ||
function updateReferenceFile(files, generatedFiles, referenceFile, referencePath) { | ||
var referenceIntro = '/// <reference path="'; | ||
@@ -101,4 +105,5 @@ var referenceEnd = '" />'; | ||
// By default at end of file | ||
// By default our signature goes at end of file | ||
signatureSectionPosition = lines.length; | ||
for (var i = 0; i < lines.length; i++) { | ||
@@ -131,6 +136,17 @@ var line = _str.trim(lines[i]); | ||
var contents = [ourSignatureStart]; | ||
// The path string within a single reference | ||
function makeReferencePath(filename) { | ||
return path.relative(referencePath, filename).split('\\').join('/'); | ||
} | ||
// the generated files: | ||
generatedFiles = _.map(generatedFiles, function (file) { | ||
return referenceIntro + makeReferencePath(file) + referenceEnd; | ||
}); | ||
// the new / observed missing files: | ||
var contents = insertArrayAt([ourSignatureStart], 1, generatedFiles); | ||
files.forEach(function (filename) { | ||
// The file we are about to add | ||
var filepath = path.relative(referencePath, filename).split('\\').join('/'); | ||
var filepath = makeReferencePath(filename); | ||
@@ -153,2 +169,39 @@ if (origFileReferences.length) { | ||
///////////////////////////////////////////////////////////////////// | ||
// HTML -> TS | ||
//////////////////////////////////////////////////////////////////// | ||
//html -> js processing functions: | ||
// Originally from karma-html2js-preprocessor | ||
// Refactored nicely in html2js grunt task | ||
// https://github.com/karlgoldstein/grunt-html2js/blob/master/tasks/html2js.js | ||
var escapeContent = function (content, quoteChar, indentString) { | ||
if (typeof quoteChar === "undefined") { quoteChar = "'"; } | ||
if (typeof indentString === "undefined") { indentString = ' '; } | ||
var quoteRegexp = new RegExp('\\' + quoteChar, 'g'); | ||
var nlReplace = '\\n' + quoteChar + ' +\n' + indentString + indentString + quoteChar; | ||
return content.replace(quoteRegexp, '\\' + quoteChar).replace(/\r?\n/g, nlReplace); | ||
}; | ||
var htmlTemplate = _.template("module <%= modulename %> { export var <%= varname %> = '<%= content %>' } "); | ||
// Compile an HTML file to a TS file | ||
// Return the filename. This filename will be required by reference.ts | ||
function compileHTML(filename) { | ||
var htmlContent = escapeContent(fs.readFileSync(filename).toString()); | ||
// TODO: place a minification pipeline here if you want. | ||
var ext = path.extname(filename); | ||
var extFreename = path.basename(filename, ext); | ||
var fileContent = htmlTemplate({ modulename: extFreename, varname: ext.replace('.', ''), content: htmlContent }); | ||
// Write the content to a file | ||
var outputfile = filename + ".ts"; | ||
fs.writeFileSync(outputfile, fileContent); | ||
return outputfile; | ||
} | ||
///////////////////////////////////////////////////////////////////// | ||
// The grunt task | ||
//////////////////////////////////////////////////////////////////// | ||
// Note: this funciton is called once for each target | ||
@@ -209,10 +262,12 @@ // so task + target options are a bit blurred inside this function | ||
// Time the whole process | ||
function runCompilation(files) { | ||
var starttime; | ||
var endtime; | ||
function runCompilation(files, generatedHtmlFiles) { | ||
grunt.log.writeln('Compiling.'.yellow); | ||
// Time the task and go | ||
var starttime = new Date().getTime(); | ||
starttime = new Date().getTime(); | ||
if (!!referencePath) { | ||
updateReferenceFile(files, referenceFile, referencePath); | ||
updateReferenceFile(files, generatedHtmlFiles, referenceFile, referencePath); | ||
} | ||
@@ -235,2 +290,6 @@ | ||
var result = compileAllFiles(filesToCompile, target, options); | ||
// End the timer | ||
endtime = new Date().getTime(); | ||
if (result.code != 0) { | ||
@@ -241,3 +300,2 @@ var msg = "Compilation failed"/*+result.output*/ ; | ||
} else { | ||
var endtime = new Date().getTime(); | ||
var time = (endtime - starttime) / 1000; | ||
@@ -252,5 +310,20 @@ grunt.log.writeln(('Success: ' + time.toFixed(2) + 's for ' + files.length + ' typescript files').green); | ||
function filterFilesAndCompile() { | ||
// Html files: | ||
// Note: | ||
// compile html files before reference file creation. Which is done in runCompilation | ||
// compile html files before globbing the file system again | ||
var generatedHtmlFiles = []; | ||
if (currenttask.data.html) { | ||
var htmlFiles = grunt.file.expand(currenttask.data.html); | ||
generatedHtmlFiles = _.map(htmlFiles, function (filename) { | ||
return compileHTML(filename); | ||
}); | ||
} | ||
// Reexpand the original file glob: | ||
var files = grunt.file.expand(currenttask.data.src); | ||
// remove the generated files from files: | ||
files = _.difference(files, generatedHtmlFiles); | ||
// Clear the files of output.d.ts and reference.ts | ||
@@ -261,6 +334,6 @@ files = _.filter(files, function (filename) { | ||
// compile | ||
runCompilation(files); | ||
if (files.length > 0) | ||
runCompilation(files, generatedHtmlFiles); else | ||
grunt.log.writeln('No files to compile'.red); | ||
} | ||
var debouncedCompile = _.debounce(filterFilesAndCompile, 150); | ||
@@ -270,27 +343,22 @@ // Initial compilation: | ||
// Watches all the files | ||
// Watch a folder? | ||
watch = target.watch; | ||
if (!!watch) { | ||
// get path | ||
watch = path.resolve(watch); | ||
// make async | ||
var done = currenttask.async(); | ||
var watchpath = watch; | ||
grunt.log.writeln(('Watching all Typescript files under : ' + watchpath).cyan); | ||
// A debounced version of compile | ||
var debouncedCompile = _.debounce(filterFilesAndCompile, 150); | ||
// create a gaze instance for path | ||
var chokidar = require('chokidar'); | ||
var watcher = chokidar.watch(watchpath, { ignoreInitial: true, persistent: true }); | ||
// local event to handle file event | ||
function handleFileEvent(filepath, displaystr) { | ||
if (isOutFile(filepath) || isReferenceFile(filepath)) { | ||
if (!endsWith(filepath.toLowerCase(), '.ts') && !endsWith(filepath.toLowerCase(), '.html')) | ||
return; | ||
} | ||
if (!endsWith(filepath, '.ts')) { | ||
if ((new Date().getTime() - endtime) <= 100) { | ||
//grunt.log.writeln((' ///' + ' >>' + filepath).grey); | ||
return; | ||
} | ||
// Log and run the debounced version. | ||
grunt.log.writeln((displaystr + ' >>' + filepath).yellow); | ||
@@ -300,11 +368,21 @@ debouncedCompile(); | ||
// get path | ||
var watchpath = path.resolve(watch); | ||
// create a file watcher for path | ||
var chokidar = require('chokidar'); | ||
var watcher = chokidar.watch(watchpath, { ignoreInitial: true, persistent: true }); | ||
// Log what we are doing | ||
grunt.log.writeln(('Watching all TypeScript / Html files under : ' + watchpath).cyan); | ||
// A file has been added/changed/deleted has occurred | ||
watcher.on('add', function (path) { | ||
handleFileEvent(path, '+++ added '); | ||
handleFileEvent(path, '+++ added '); | ||
}).on('change', function (path) { | ||
handleFileEvent(path, '### changed'); | ||
handleFileEvent(path, '### changed '); | ||
}).on('unlink', function (path) { | ||
handleFileEvent(path, '--- removed'); | ||
handleFileEvent(path, '--- removed '); | ||
}).on('error', function (error) { | ||
console.error('Error happened', error); | ||
console.error('Error happened in chokidar: ', error); | ||
}); | ||
@@ -314,4 +392,5 @@ } | ||
if (!watch) | ||
if (!watch) { | ||
return success; | ||
} | ||
}); | ||
@@ -318,0 +397,0 @@ } |
178
tasks/ts.ts
@@ -25,4 +25,5 @@ /// <reference path="../defs/node/node.d.ts"/> | ||
reference: string; // path to a reference.ts e.g. './approot/' | ||
out: string; // if sepecified e.g. 'single.js' all output js files are merged into single.js using tsc --out command | ||
watch: string; // if specified e.g. './appdir/' will watch the directory for changes. Note that specifing this makes the grunt task async (i.e. it keep running) | ||
out: string; // if sepecified e.g. 'single.js' all output js files are merged into single.js using tsc --out command | ||
html: string[]; // if specified this is used to generate typescript files with a single variable which contains the content of the html | ||
watch: string; | ||
} | ||
@@ -55,3 +56,2 @@ | ||
// Typescript imports | ||
@@ -69,2 +69,6 @@ import _ = require('underscore'); | ||
///////////////////////////////////////////////////////////////////// | ||
// tsc handling. | ||
//////////////////////////////////////////////////////////////////// | ||
function resolveTypeScriptBinPath(currentPath, depth): string { | ||
@@ -83,7 +87,5 @@ var targetPath = path.resolve(__dirname, | ||
} | ||
function getTsc(binPath: string): string { | ||
return '"' + binPath + '/' + 'tsc" '; | ||
} | ||
var exec = shell.exec; | ||
@@ -123,4 +125,8 @@ var cwd = path.resolve("."); | ||
///////////////////////////////////////////////////////////////////// | ||
// Reference file logic | ||
//////////////////////////////////////////////////////////////////// | ||
// Updates the reference file | ||
function updateReferenceFile(files: string[], referenceFile: string, referencePath: string) { | ||
function updateReferenceFile(files: string[], generatedFiles:string[], referenceFile: string, referencePath: string) { | ||
var referenceIntro = '/// <reference path="'; | ||
@@ -137,3 +143,3 @@ var referenceEnd = '" />'; | ||
// By default at start of file | ||
var signatureSectionPosition = 0; | ||
var signatureSectionPosition = 0; | ||
@@ -145,4 +151,6 @@ // Read the original file if it exists | ||
var inSignatureSection = false; | ||
// By default at end of file | ||
// By default our signature goes at end of file | ||
signatureSectionPosition = lines.length; | ||
for (var i = 0; i < lines.length; i++) { | ||
@@ -176,7 +184,16 @@ | ||
} | ||
// The path string within a single reference | ||
function makeReferencePath(filename:string) { | ||
return path.relative(referencePath, filename).split('\\').join('/'); | ||
} | ||
var contents = [ourSignatureStart]; | ||
// the generated files: | ||
generatedFiles = _.map(generatedFiles, (file) => referenceIntro + makeReferencePath(file) + referenceEnd); | ||
// the new / observed missing files: | ||
var contents = insertArrayAt([ourSignatureStart],1,generatedFiles); | ||
files.forEach((filename: string) => { | ||
// The file we are about to add | ||
var filepath = path.relative(referencePath, filename).split('\\').join('/'); | ||
var filepath = makeReferencePath(filename); | ||
@@ -200,2 +217,39 @@ // If there are orig references | ||
///////////////////////////////////////////////////////////////////// | ||
// HTML -> TS | ||
//////////////////////////////////////////////////////////////////// | ||
//html -> js processing functions: | ||
// Originally from karma-html2js-preprocessor | ||
// Refactored nicely in html2js grunt task | ||
// https://github.com/karlgoldstein/grunt-html2js/blob/master/tasks/html2js.js | ||
var escapeContent = function (content: string, quoteChar="'",indentString=' '):string { | ||
var quoteRegexp = new RegExp('\\' + quoteChar, 'g'); | ||
var nlReplace = '\\n' + quoteChar + ' +\n' + indentString + indentString + quoteChar; | ||
return content.replace(quoteRegexp, '\\' + quoteChar).replace(/\r?\n/g, nlReplace); | ||
}; | ||
var htmlTemplate = _.template("module <%= modulename %> { export var <%= varname %> = '<%= content %>' } "); | ||
// Compile an HTML file to a TS file | ||
// Return the filename. This filename will be required by reference.ts | ||
function compileHTML(filename: string):string { | ||
var htmlContent = escapeContent(fs.readFileSync(filename).toString()); | ||
// TODO: place a minification pipeline here if you want. | ||
var ext = path.extname(filename); | ||
var extFreename = path.basename(filename,ext); | ||
var fileContent = htmlTemplate({ modulename: extFreename, varname: ext.replace('.',''), content: htmlContent}); | ||
// Write the content to a file | ||
var outputfile = filename + ".ts"; | ||
fs.writeFileSync(outputfile, fileContent); | ||
return outputfile; | ||
} | ||
///////////////////////////////////////////////////////////////////// | ||
// The grunt task | ||
//////////////////////////////////////////////////////////////////// | ||
// Note: this funciton is called once for each target | ||
@@ -217,4 +271,4 @@ // so task + target options are a bit blurred inside this function | ||
// Was the whole process successful | ||
var success = true; | ||
var watch; | ||
var success = true; | ||
var watch; | ||
@@ -261,11 +315,13 @@ // Some interesting logs: | ||
// Time the whole process | ||
function runCompilation(files) { | ||
var starttime; | ||
var endtime; | ||
function runCompilation(files:string[],generatedHtmlFiles:string[]) { | ||
grunt.log.writeln('Compiling.'.yellow); | ||
// Time the task and go | ||
var starttime = new Date().getTime(); | ||
starttime = new Date().getTime(); | ||
// Create a reference file if specified | ||
if (!!referencePath) { | ||
updateReferenceFile(files, referenceFile, referencePath); | ||
if (!!referencePath) { | ||
updateReferenceFile(files,generatedHtmlFiles, referenceFile, referencePath); | ||
} | ||
@@ -285,2 +341,7 @@ | ||
var result = compileAllFiles(filesToCompile, target, options); | ||
// End the timer | ||
endtime = new Date().getTime(); | ||
// Evaluate the result | ||
if (result.code != 0) { | ||
@@ -291,4 +352,3 @@ var msg = "Compilation failed"/*+result.output*/; | ||
} | ||
else { | ||
var endtime = new Date().getTime(); | ||
else { | ||
var time = (endtime - starttime) / 1000; | ||
@@ -303,5 +363,19 @@ grunt.log.writeln(('Success: ' + time.toFixed(2) + 's for ' + files.length + ' typescript files').green); | ||
function filterFilesAndCompile() { | ||
// Html files: | ||
// Note: | ||
// compile html files before reference file creation. Which is done in runCompilation | ||
// compile html files before globbing the file system again | ||
var generatedHtmlFiles = []; | ||
if (currenttask.data.html) { | ||
var htmlFiles = grunt.file.expand(currenttask.data.html); | ||
generatedHtmlFiles = _.map(htmlFiles, (filename) => compileHTML(filename)); | ||
} | ||
// Reexpand the original file glob: | ||
var files = grunt.file.expand(currenttask.data.src); | ||
// remove the generated files from files: | ||
files = _.difference(files, generatedHtmlFiles); | ||
// Clear the files of output.d.ts and reference.ts | ||
@@ -312,52 +386,64 @@ files = _.filter(files, (filename) => { | ||
// compile | ||
runCompilation(files); | ||
} | ||
var debouncedCompile = _.debounce(filterFilesAndCompile, 150); // randomly chosen 150. Choice was made because chokidar looks at file system every 100ms | ||
// compile, If there are any files to compile! | ||
if (files.length > 0) | ||
runCompilation(files,generatedHtmlFiles); | ||
else | ||
grunt.log.writeln('No files to compile'.red); | ||
} | ||
// Initial compilation: | ||
filterFilesAndCompile(); | ||
// Watches all the files | ||
// Watch a folder? | ||
watch = target.watch; | ||
if (!!watch) { | ||
// get path | ||
watch = path.resolve(watch); | ||
// make async | ||
var done = currenttask.async(); | ||
// A debounced version of compile | ||
var debouncedCompile = _.debounce(filterFilesAndCompile, 150); | ||
var watchpath = watch; | ||
grunt.log.writeln(('Watching all Typescript files under : ' + watchpath).cyan); | ||
// create a gaze instance for path | ||
var chokidar = require('chokidar'); | ||
var watcher = chokidar.watch(watchpath, { ignoreInitial: true, persistent: true }); | ||
// local event to handle file event | ||
function handleFileEvent(filepath: string, displaystr: string) { | ||
// Ignore the special cases for files we generate | ||
if (isOutFile(filepath) || isReferenceFile(filepath)) { | ||
// 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) { | ||
//grunt.log.writeln((' ///' + ' >>' + filepath).grey); | ||
return; | ||
} | ||
if (!endsWith(filepath, '.ts')) { // should not happen | ||
return; | ||
} | ||
grunt.log.writeln((displaystr + ' >>' + filepath).yellow); | ||
// Log and run the debounced version. | ||
grunt.log.writeln((displaystr + ' >>' + filepath).yellow); | ||
debouncedCompile(); | ||
} | ||
// get path | ||
var watchpath = path.resolve(watch); | ||
// create a file watcher for path | ||
var chokidar = require('chokidar'); | ||
var watcher = chokidar.watch(watchpath, { ignoreInitial: true, persistent: true }); | ||
// Log what we are doing | ||
grunt.log.writeln(('Watching all TypeScript / Html files under : ' + watchpath).cyan); | ||
// A file has been added/changed/deleted has occurred | ||
watcher.on('add', function (path) { handleFileEvent(path, '+++ added '); }) | ||
.on('change', function (path) { handleFileEvent(path, '### changed'); }) | ||
.on('unlink', function (path) { handleFileEvent(path, '--- removed'); }) | ||
.on('error', function (error) { console.error('Error happened', error); }); | ||
watcher.on('add', function (path) { handleFileEvent(path, '+++ added '); }) | ||
.on('change', function (path) { handleFileEvent(path, '### changed '); }) | ||
.on('unlink', function (path) { handleFileEvent(path, '--- removed '); }) | ||
.on('error', function (error) { console.error('Error happened in chokidar: ', error); }); | ||
} | ||
}); | ||
if (!watch) | ||
return success; | ||
if (!watch) { | ||
return success; | ||
} | ||
}); | ||
}; | ||
export = pluginFn; |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
122332
6
4
2156
135
- Removedgrunt@~0.4.0
- Removedgrunt-lib-contrib@0.5.2
- Removedcrc32@0.2.2(transitive)
- Removeddeflate-js@0.2.3(transitive)
- Removedgrunt-lib-contrib@0.5.2(transitive)
- Removedgzip-js@0.3.2(transitive)