Permalink
Browse files

feat(angluarjs) ground work to add angularjs template cache

  • Loading branch information...
1 parent 94b6cf5 commit 69e5c8a857075a377eb01120e5f649468761f087 @basarat basarat committed Oct 25, 2013
View
@@ -0,0 +1,2 @@
+v 1.4.0:
+Added support for generating angularJS template cache
View
@@ -62,6 +62,17 @@ module.exports = function (grunt) {
amdloader: 'test/amdloader/js/loader.js',
// watch: 'test/amdloader'
},
+ templatecache: {
+ src: ['test/templatecache/**/*.ts'],
+ reference: 'test/templatecache/ts/reference.ts',
+ amdloader: 'test/templatecache/js/loader.js',
+ outDir: 'test/templatecache/js',
+ templateCache: {
+ baseUrl : 'test/templatecache/js/',
+ src: ['test/templatecache/ts/**/*.html'],
+ dest: 'test/templatecache/ts/templateCache.ts',
+ },
+ },
fail: { // a designed to fail target
src: ["test/fail/**/*.ts"],
watch: 'test',
View
@@ -1,2 +1,2 @@
tsc "./tasks/ts.ts" --sourcemap --module commonjs
-grunt ts:amdloadertest
+grunt ts:templatecache
View
@@ -21,6 +21,11 @@ interface ITask {
data: {
src: any;
html: any; // SPECIFIC TO GRUNT-TS
+ templateCache: {
+ src: any;
+ dest:any;
+ baseUrl:any;
+ }
}
}
View
@@ -2,7 +2,7 @@
"author": "basarat",
"name": "grunt-ts",
"description": "Compile and manage your TypeScript project",
- "version": "1.3.0",
+ "version": "1.4.0",
"homepage": "https://github.com/basarat/grunt-ts",
"repository": {
"type": "git",
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -21,6 +21,11 @@ interface ITargetOptions {
html: string[]; // if specified this is used to generate typescript files with a single variable which contains the content of the html
watch: string; // if specified watches all files in this directory for changes.
amdloader: string; // if specified creates a js file to load all the generated typescript files in order using requirejs + order
+ templateCache: { // if specified search thought all the html file at this location
+ src: string[];
+ dest: string;
+ baseUrl: string;
+ }
}
interface ITaskOptions {
@@ -474,6 +479,19 @@ function pluginFn(grunt: IGrunt) {
fs.writeFileSync(outputfile, fileContent);
return outputfile;
}
+
+ /////////////////////////////////////////////////////////////////////
+ // AngularJS templateCache
+ ////////////////////////////////////////////////////////////////////
+
+ // templateCache processing function
+ function generateTemplateCache(src: string[], dest:string, basePath: string) {
+ console.log('compiling ', src, dest, basePath);
+
+ // Resolve the relative path from basePath to each src file
+ var relativePaths: string[] = _.map(src, (anHtmlFile) => path.relative(anHtmlFile, basePath));
+ console.log(relativePaths);
+ }
/////////////////////////////////////////////////////////////////////
// The grunt task
@@ -505,6 +523,9 @@ function pluginFn(grunt: IGrunt) {
//console.log(this.files[0]); // An array of target files ( only one in our case )
//console.log(this.files[0].src); // a getter for a resolved list of files
//console.log(this.files[0].orig.src); // The original glob / array / !array / <% array %> for files. Can be very fancy :)
+
+ // NOTE: to access the specified src files we use
+ // currenttaks.data as that is the raw (non interpolated) string that we reinterpolate ourselves in case the file system as changed since this task was started
// this.files[0] is actually a single in our case as we gave examples of one source / out per target
this.files.forEach(function (target: ITargetOptions) {
@@ -608,6 +629,19 @@ function pluginFn(grunt: IGrunt) {
var htmlFiles = grunt.file.expand(currenttask.data.html);
generatedHtmlFiles = _.map(htmlFiles, (filename) => compileHTML(filename));
}
+ // 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) {
+ if (!currenttask.data.templateCache.src || !currenttask.data.templateCache.dest || !currenttask.data.templateCache.baseUrl) {
+ grunt.log.writeln('templateCache : src, dest, baseUrl must be specified if templateCache option is used'.red);
+ }
+ else{
+ var templateCacheSrc = grunt.file.expand(currenttask.data.templateCache.src); // manual reinterpolation
+ var templateCacheDest = path.resolve(target.templateCache.dest);
+ var templateCacheBasePath = path.resolve(target.templateCache.baseUrl);
+ generateTemplateCache(templateCacheSrc, templateCacheDest, templateCacheBasePath);
+ }
+ }
// Reexpand the original file glob:
var files = grunt.file.expand(currenttask.data.src);
@@ -0,0 +1 @@
+<script src="./vendor/requirejs/require.js" data-main="main.js"></script>
Oops, something went wrong.

0 comments on commit 69e5c8a

Please sign in to comment.