Skip to content

Commit

Permalink
file handling fix #239 #232 #145
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisbutler committed Jan 12, 2017
1 parent 9b5c689 commit 533cc8b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
5 changes: 5 additions & 0 deletions History.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
1.8.0 / 2017-1-12
==================
* Add verbose mode with IRON_DEBUG
* Fix file/path handling

1.7.0 / 2017-1-12
==================
* fix command proxying (debug, shell, mongo, etc)
Expand Down
29 changes: 21 additions & 8 deletions lib/tools/file_system.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ module.exports = {};
* needed.
*/
module.exports.createFile = function createFile(filepath, data, opts) {
this.logDebug('createFile', filepath, opts);

opts = opts || {};
try {
var pathParts = path.normalize(filepath).split(path.sep);
Expand Down Expand Up @@ -144,12 +146,13 @@ module.exports.pathFromNpmModule = function pathFromNpmModule(/* path parts */)
* For example, given foo.bar.baz, returns { type: 'bar', engine: 'baz' }
*/
module.exports.engineAndTypeFromFilepath = function engineAndTypeFromFilepath(srcpath) {
var re = /\.([A-Za-z0-9]+)/g;
var re = /\.([A-Za-z0-9.]+)$/g;
var matches = srcpath.match(re);
matches = matches && matches[0].split('.', 3);

if (!matches) return { type: undefined, engine: undefined };

// matches can be an array of n length. I'll assume the last entry is the
// matches can be an array of length 2. I'll assume the last entry is the
// engine, and the one before that the type. If there's only one entry I'll
// assume the engine and type are the same. For example, template.js.js is
// equivalent to template.js
Expand All @@ -162,6 +165,8 @@ module.exports.engineAndTypeFromFilepath = function engineAndTypeFromFilepath(sr
if (type)
type = type.replace('.', '');

this.logDebug('engineAndTypeFromFilepath', matches, srcpath, engine, type);

return {
type: type,
engine: engine
Expand Down Expand Up @@ -197,12 +202,14 @@ module.exports.rewriteSourcePathForEngine = function rewriteSourcePathForEngine(
return srcpath;

var engine = config.engines[engineAndType.type];
var findTypeRe = new RegExp(fileType + '\\S*$');
var findTypeRe = new RegExp('\\.' + fileType + '\\S*$');

this.logDebug('rewriteSourcePathForEngine', engineAndType, findTypeRe, engine, fileType);

if (engine === fileType)
return srcpath.replace(findTypeRe, fileType);
return srcpath.replace(findTypeRe, '.' + fileType);
else
return srcpath.replace(findTypeRe, fileType + '.' + engine);
return srcpath.replace(findTypeRe, '.' + fileType + '.' + engine);

return ret;
};
Expand All @@ -223,12 +230,14 @@ module.exports.rewriteDestinationPathForEngine = function rewriteDestinationPath

// replace everything after the file type with the new
// engine extensions
var replaceTypeWithEngineRe = new RegExp(fileType + '\\S*$');
var replaceTypeWithEngineRe = new RegExp('\\.' + fileType + '\\S*$');

this.logDebug('rewriteDestinationPathForEngine', destpath, fileType, engine, replaceTypeWithEngineRe);

if (!fileType || !engine)
return destpath;
else
return destpath.replace(replaceTypeWithEngineRe, engine);
return destpath.replace(replaceTypeWithEngineRe, '.' + engine);
};

/**
Expand Down Expand Up @@ -297,6 +306,8 @@ module.exports.pathFromProject = function pathFromProject(/* path parts */) {
module.exports.pathFromApp = function pathFromApp(/* path parts */) {
var srcpath = this.rewriteSourcePathForEngine.apply(this, arguments);
var appDirectory = this.findAppDirectory();

this.logDebug('pathFromApp', appDirectory, srcpath);
return appDirectory ? path.join(appDirectory, srcpath) : false;
};

Expand Down Expand Up @@ -365,7 +376,9 @@ module.exports.templateContent = function templateContent(srcpath, context) {
module.exports.template = function template(srcpath, destpath, context) {
var renderedTemplate = this.templateContent(srcpath, context) + '\n';
destpath = this.rewriteDestinationPathForEngine(destpath);
var ret = this.createFile(destpath, renderedTemplate)
var ret = this.createFile(destpath, renderedTemplate);

this.logDebug('template', destpath);
return ret;
};

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "iron-meteor",
"version": "1.7.0",
"version": "1.8.0",
"description": "A command line tool for scaffolding Meteor applications.",
"homepage": "https://github.com/iron-meteor/iron-cli",
"bugs": {
Expand Down

0 comments on commit 533cc8b

Please sign in to comment.