1
0
mirror of https://github.com/JuanCanham/HackMyResume.git synced 2024-11-22 16:30:11 +00:00

Fix path parsing issue on prev versions of Node.js.

Work around absence of path.parse in Node versions < v0.12. Addresses
#31 and #33.
This commit is contained in:
hacksalot 2015-12-24 16:18:38 -05:00
parent 79637b611a
commit 3d41528059
4 changed files with 18 additions and 14 deletions

View File

@ -49,6 +49,7 @@
"minimist": "^1.2.0", "minimist": "^1.2.0",
"mkdirp": "^0.5.1", "mkdirp": "^0.5.1",
"moment": "^2.10.6", "moment": "^2.10.6",
"parse-filepath": "^0.6.3",
"path-exists": "^2.1.0", "path-exists": "^2.1.0",
"recursive-readdir-sync": "^1.0.6", "recursive-readdir-sync": "^1.0.6",
"simple-html-tokenizer": "^0.2.0", "simple-html-tokenizer": "^0.2.0",

View File

@ -11,6 +11,7 @@ Definition of the Theme class.
, validator = require('is-my-json-valid') , validator = require('is-my-json-valid')
, _ = require('underscore') , _ = require('underscore')
, PATH = require('path') , PATH = require('path')
, parsePath = require('parse-filepath')
, EXTEND = require('../utils/extend') , EXTEND = require('../utils/extend')
, moment = require('moment') , moment = require('moment')
, RECURSIVE_READ_DIR = require('recursive-readdir-sync'); , RECURSIVE_READ_DIR = require('recursive-readdir-sync');
@ -30,8 +31,8 @@ Definition of the Theme class.
// Open the [theme-name].json file; should have the same name as folder // Open the [theme-name].json file; should have the same name as folder
this.folder = themeFolder; this.folder = themeFolder;
var pathInfo = PATH.parse( themeFolder ); var pathInfo = parsePath( themeFolder );
var themeFile = PATH.join( themeFolder, pathInfo.base + '.json' ); var themeFile = PATH.join( themeFolder, pathInfo.basename + '.json' );
var themeInfo = JSON.parse( FS.readFileSync( themeFile, 'utf8' ) ); var themeInfo = JSON.parse( FS.readFileSync( themeFile, 'utf8' ) );
var that = this; var that = this;
@ -59,7 +60,7 @@ Definition of the Theme class.
this.formats = formatsHash; this.formats = formatsHash;
// Set the official theme name // Set the official theme name
this.name = PATH.parse( this.folder ).name; this.name = parsePath( this.folder ).name;
return this; return this;
}; };
@ -96,9 +97,9 @@ Definition of the Theme class.
// If this file lives in a specific format folder within the theme, // If this file lives in a specific format folder within the theme,
// such as "/latex" or "/html", then that format is the output format // such as "/latex" or "/html", then that format is the output format
// for all files within the folder. // for all files within the folder.
var pathInfo = PATH.parse(absPath); var pathInfo = parsePath(absPath);
var outFmt = '', isMajor = false; var outFmt = '', isMajor = false;
var portion = pathInfo.dir.replace(tplFolder,''); var portion = pathInfo.dirname.replace(tplFolder,'');
if( portion && portion.trim() ) { if( portion && portion.trim() ) {
if( portion[1] === '_' ) return; if( portion[1] === '_' ) return;
var reg = /^(?:\/|\\)(html|latex|doc|pdf|partials)(?:\/|\\)?/ig; var reg = /^(?:\/|\\)(html|latex|doc|pdf|partials)(?:\/|\\)?/ig;
@ -135,7 +136,7 @@ Definition of the Theme class.
path: absPath, path: absPath,
major: isMajor, major: isMajor,
orgPath: PATH.relative(tplFolder, absPath), orgPath: PATH.relative(tplFolder, absPath),
ext: pathInfo.ext.slice(1), ext: pathInfo.extname.slice(1),
title: friendlyName( outFmt ), title: friendlyName( outFmt ),
pre: outFmt, pre: outFmt,
// outFormat: outFmt || pathInfo.name, // outFormat: outFmt || pathInfo.name,
@ -186,7 +187,7 @@ Definition of the Theme class.
act = null; act = null;
// If this file is mentioned in the theme's JSON file under "transforms" // If this file is mentioned in the theme's JSON file under "transforms"
var pathInfo = PATH.parse(absPath); var pathInfo = parsePath(absPath);
var absPathSafe = absPath.trim().toLowerCase(); var absPathSafe = absPath.trim().toLowerCase();
var outFmt = _.find( Object.keys( that.formats ), function( fmtKey ) { var outFmt = _.find( Object.keys( that.formats ), function( fmtKey ) {
var fmtVal = that.formats[ fmtKey ]; var fmtVal = that.formats[ fmtKey ];
@ -203,7 +204,7 @@ Definition of the Theme class.
// such as "/latex" or "/html", then that format is the output format // such as "/latex" or "/html", then that format is the output format
// for all files within the folder. // for all files within the folder.
if( !outFmt ) { if( !outFmt ) {
var portion = pathInfo.dir.replace(tplFolder,''); var portion = pathInfo.dirname.replace(tplFolder,'');
if( portion && portion.trim() ) { if( portion && portion.trim() ) {
var reg = /^(?:\/|\\)(html|latex|doc|pdf)(?:\/|\\)?/ig; var reg = /^(?:\/|\\)(html|latex|doc|pdf)(?:\/|\\)?/ig;
var res = reg.exec( portion ); var res = reg.exec( portion );
@ -231,7 +232,7 @@ Definition of the Theme class.
action: act, action: act,
orgPath: PATH.relative(that.folder, absPath), orgPath: PATH.relative(that.folder, absPath),
path: absPath, path: absPath,
ext: pathInfo.ext.slice(1), ext: pathInfo.extname.slice(1),
title: friendlyName( outFmt ), title: friendlyName( outFmt ),
pre: outFmt, pre: outFmt,
// outFormat: outFmt || pathInfo.name, // outFormat: outFmt || pathInfo.name,

View File

@ -13,6 +13,7 @@ Definition of the TemplateGenerator class.
, MD = require( 'marked' ) , MD = require( 'marked' )
, XML = require( 'xml-escape' ) , XML = require( 'xml-escape' )
, PATH = require('path') , PATH = require('path')
, parsePath = require('parse-filepath')
, MKDIRP = require('mkdirp') , MKDIRP = require('mkdirp')
, BaseGenerator = require( './base-generator' ) , BaseGenerator = require( './base-generator' )
, EXTEND = require('../utils/extend') , EXTEND = require('../utils/extend')
@ -127,7 +128,7 @@ Definition of the TemplateGenerator class.
var theme = themeInfo.theme; var theme = themeInfo.theme;
var tFolder = themeInfo.folder; var tFolder = themeInfo.folder;
var tplFolder = PATH.join( tFolder, 'src' ); var tplFolder = PATH.join( tFolder, 'src' );
var outFolder = PATH.parse(f).dir; var outFolder = parsePath(f).dirname;
var curFmt = theme.getFormat( this.format ); var curFmt = theme.getFormat( this.format );
var that = this; var that = this;
@ -176,7 +177,7 @@ Definition of the TemplateGenerator class.
var absLoc = PATH.join(outFolder, loc); var absLoc = PATH.join(outFolder, loc);
var absTarg = PATH.join(PATH.dirname(absLoc), curFmt.symLinks[loc]); var absTarg = PATH.join(PATH.dirname(absLoc), curFmt.symLinks[loc]);
// 'file', 'dir', or 'junction' (Windows only) // 'file', 'dir', or 'junction' (Windows only)
var type = PATH.parse( absLoc ).ext ? 'file' : 'junction'; var type = parsePath( absLoc ).extname ? 'file' : 'junction';
FS.symlinkSync( absTarg, absLoc, type); FS.symlinkSync( absTarg, absLoc, type);
}); });
} }
@ -221,7 +222,7 @@ Definition of the TemplateGenerator class.
function themeFromMoniker() { function themeFromMoniker() {
// Verify the specified theme name/path // Verify the specified theme name/path
var tFolder = PATH.join( var tFolder = PATH.join(
PATH.parse( require.resolve('fluent-themes') ).dir, parsePath( require.resolve('fluent-themes') ).dirname,
this.opts.theme this.opts.theme
); );
var exists = require('path-exists').sync; var exists = require('path-exists').sync;

View File

@ -1,6 +1,7 @@
(function() { (function() {
var PATH = require('path') var PATH = require('path')
, parsePath = require('parse-filepath')
, MKDIRP = require('mkdirp') , MKDIRP = require('mkdirp')
, _opts = require('../core/default-options') , _opts = require('../core/default-options')
, FluentTheme = require('../core/theme') , FluentTheme = require('../core/theme')
@ -70,8 +71,8 @@
( (dst && dst.length && dst) || ['resume.all'] ).forEach( function(t) { ( (dst && dst.length && dst) || ['resume.all'] ).forEach( function(t) {
var to = PATH.resolve(t), var to = PATH.resolve(t),
pa = PATH.parse(to), pa = parsePath(to),
fmat = pa.ext || '.all'; fmat = pa.extname || '.all';
targets.push.apply(targets, fmat === '.all' ? targets.push.apply(targets, fmat === '.all' ?
Object.keys( theTheme.formats ).map(function(k){ Object.keys( theTheme.formats ).map(function(k){