From 7c58f0ea965f2969c3fcc2f9d8e42081081948b8 Mon Sep 17 00:00:00 2001 From: devlinjd Date: Tue, 8 Dec 2015 10:13:04 -0500 Subject: [PATCH] Add symlink support. --- src/core/theme.js | 15 +++++------ src/gen/template-generator.js | 50 ++++++++++++++++++++++++++--------- 2 files changed, 44 insertions(+), 21 deletions(-) diff --git a/src/core/theme.js b/src/core/theme.js index ed79ea4..7752774 100644 --- a/src/core/theme.js +++ b/src/core/theme.js @@ -80,6 +80,7 @@ Abstract theme representation. // Set up a hash of formats supported by this theme. var formatsHash = { }; + var that = this; // Establish the base theme folder var tplFolder = PATH.join( this.folder, 'src' ); @@ -110,7 +111,7 @@ Abstract theme representation. // We should have a valid output format now. formatsHash[ outFmt ] = - formatsHash[outFmt] || { outFormat: outFmt, files: [] }; + formatsHash[outFmt] || { outFormat: outFmt, files: [], symLinks: that.formats[ outFmt ].symLinks }; // Create the file representation object. var obj = { @@ -199,7 +200,11 @@ Abstract theme representation. // We should have a valid output format now. formatsHash[ outFmt ] = - formatsHash[outFmt] || { outFormat: outFmt, files: [] }; + formatsHash[ outFmt ] || { + outFormat: outFmt, + files: [], + symLinks: that.formats[ outFmt ].symLinks + }; // Create the file representation object. var obj = { @@ -235,12 +240,6 @@ Abstract theme representation. return fmt.ext !== 'css'; }); - // Object.keys( formatsHash ).forEach(function(k){ - // formatsHash[ k ].files.forEach(function(xhs){ - // console.log(xhs.orgPath); - // }); - // }); - return formatsHash; } diff --git a/src/gen/template-generator.js b/src/gen/template-generator.js index 6ab7016..f11b80e 100644 --- a/src/gen/template-generator.js +++ b/src/gen/template-generator.js @@ -5,7 +5,7 @@ Template-based resume generator base for FluentCV. (function() { - var FS = require( 'fs' ) + var FS = require( 'fs-extra' ) , _ = require( 'underscore' ) , MD = require( 'marked' ) , XML = require( 'xml-escape' ) @@ -19,7 +19,7 @@ Template-based resume generator base for FluentCV. var _defaultOpts = { engine: 'underscore', keepBreaks: true, - freezeBreaks: true, + freezeBreaks: false, nSym: '&newl;', // newline entity rSym: '&retn;', // return entity template: { @@ -87,7 +87,7 @@ Template-based resume generator base for FluentCV. if (!exists( tFolder )) { tFolder = PATH.resolve( this.opts.theme ); if (!exists( tFolder )) { - throw { fluenterror: this.codes.themeNotFound, data: this.opts.theme }; + throw { fluenterror: this.codes.themeNotFound, data: this.opts.theme}; } } @@ -102,19 +102,43 @@ Template-based resume generator base for FluentCV. var that = this; curFmt.files.forEach(function(tplInfo){ - if( tplInfo.action === 'transform' ) { - var cssInfo = { file: tplInfo.css ? tplInfo.cssPath : null, data: tplInfo.css || null }; - var mk = that.single( rez, tplInfo.data, that.format, cssInfo, that.opts ); - that.onBeforeSave && (mk = that.onBeforeSave( { mk: mk, theme: theme, outputFile: f } )); - - var thisFilePath = PATH.join(outFolder, tplInfo.orgPath); - MKDIRP.sync( PATH.dirname(thisFilePath) ); - console.log('Would save to ' + thisFilePath); - - FS.writeFileSync( thisFilePath, mk, { encoding: 'utf8', flags: 'w' } ); + if( tplInfo.action === 'transform' || tplInfo.action === null ) { + if( tplInfo.action === 'transform' ) { + var cssInfo = { file: tplInfo.css ? tplInfo.cssPath : null, data: tplInfo.css || null }; + var mk = that.single( rez, tplInfo.data, that.format, cssInfo, that.opts ); + that.onBeforeSave && (mk = that.onBeforeSave( { mk: mk, theme: theme, outputFile: f } )); + var thisFilePath = PATH.join(outFolder, tplInfo.orgPath); + try { + MKDIRP.sync( PATH.dirname(thisFilePath) ); + FS.writeFileSync( thisFilePath, mk, { encoding: 'utf8', flags: 'w' } ); + } + catch(ex) { + console.log(ex); + } + } + else if( tplInfo.action === null ) { + var thisFilePath = PATH.join(outFolder, tplInfo.orgPath); + try { + MKDIRP.sync( PATH.dirname(thisFilePath) ); + FS.copySync( tplInfo.path, thisFilePath ); + } + catch(ex) { + console.log(ex); + } + } } }); + // Create symlinks + if( curFmt.symLinks ) { + Object.keys( curFmt.symLinks ).forEach( function(loc) { + var absLoc = PATH.join(outFolder, loc); + var absTarg = PATH.join(PATH.dirname(absLoc), curFmt.symLinks[loc]); + var type = PATH.parse( absLoc ).ext ? 'file' : 'junction'; // 'file', 'dir', or 'junction' (Windows only) + FS.symlinkSync( absTarg, absLoc, type); + }); + } + }, /**