Skip to content

Commit

Permalink
Merge pull request #19 from fs-webdev/master
Browse files Browse the repository at this point in the history
handle creating empty assembly.json
  • Loading branch information
intervalia committed Feb 23, 2016
2 parents a922d76 + eca54bd commit e5526b5
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 19 deletions.
5 changes: 5 additions & 0 deletions src/globArray.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ var minimatch = require("minimatch");

function globArray(patterns, options) {
var i, list = [];

if (!patterns) {
return list;
}

if (!Array.isArray(patterns)) {
patterns = [patterns];
}
Expand Down
52 changes: 33 additions & 19 deletions src/watcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,15 @@ var assemblyRegex = /\/assembly.json$/;
* @private
* @param {string} assemblyPath - Path to the assembly file.
* @param {object} [assembly] - Assembly to be watched.
* @param {function} callback - Callback function.
*/
function getAssemblyDetails(assemblyPath, assembly) {
assembly = assembly || JSON.parse(fs.readFileSync(assemblyPath, 'utf-8'));
function getAssemblyDetails(assemblyPath, assembly, callback) {
try {
assembly = assembly || JSON.parse(fs.readFileSync(assemblyPath, 'utf-8'));
}
catch (err) {
return callback(err);
}

var projectPath = path.dirname(assemblyPath);

Expand All @@ -56,13 +62,13 @@ function getAssemblyDetails(assemblyPath, assembly) {
localeFiles = globArray(["./" + localePathName + "/" + localeFileName + "_*.json"], {cwd: projectPath, root: process.cwd()});
}

return {
return callback(null, {
projectPath: projectPath,
localeFileName: localeFileName,
localePathName: localePathName,
localeFiles: localeFiles,
assembly: assembly
};
});
}

/**
Expand All @@ -73,16 +79,20 @@ function getAssemblyDetails(assemblyPath, assembly) {
* @returns {object}
*/
function getPluginParameters(assemblyPath, assembly) {
var details = getAssemblyDetails(assemblyPath, assembly);

return {
"projectPath": details.projectPath,
"hasTranslations": details.localeFiles.length > 0,
"options": {},
"assembly": details.assembly,
"assemblyName": assemblyPath,
"assemblyFileName": path.basename(details.projectPath),
};
return getAssemblyDetails(assemblyPath, assembly, function(err, details) {
if (err) {
return {};
}

return {
"projectPath": details.projectPath,
"hasTranslations": details.localeFiles.length > 0,
"options": {},
"assembly": details.assembly,
"assemblyName": assemblyPath,
"assemblyFileName": path.basename(details.projectPath),
};
});
}

/**
Expand All @@ -93,15 +103,19 @@ function getPluginParameters(assemblyPath, assembly) {
* @returns {string[]}
*/
function getAssemblyFiles(assemblyPath, assembly) {
var details = getAssemblyDetails(assemblyPath, assembly);
var files = [];

files = files.concat(globArray(details.assembly.files, {cwd: details.projectPath, root: process.cwd()}));
files = files.concat(details.localeFiles);
files = files.concat(globArray(details.assembly.templates || ["./templates/*.html"], {cwd: details.projectPath, root: process.cwd()}));
return getAssemblyDetails(assemblyPath, assembly, function(err, details) {
if (err) {
return files;
}

files = files.concat(globArray(details.assembly.files, {cwd: details.projectPath, root: process.cwd()}));
files = files.concat(details.localeFiles);
files = files.concat(globArray(details.assembly.templates || ["./templates/*.html"], {cwd: details.projectPath, root: process.cwd()}));

return files;
return files;
});
}

/**
Expand Down

0 comments on commit e5526b5

Please sign in to comment.