Skip to content

Commit

Permalink
improve builder
Browse files Browse the repository at this point in the history
  • Loading branch information
damienklinnert committed Feb 9, 2014
1 parent c89c622 commit 3322038
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 5 deletions.
43 changes: 38 additions & 5 deletions src/builder/service/file-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
FileBuilder.prototype.build = function (project) {
var content = [];

content.push(buildHeader(project));
content.push(buildDependencies(project));
content.push(buildTasks(project));
content.push(buildReload(project));
Expand All @@ -20,6 +21,10 @@
return content.join(LINEBREAK);
};

function buildHeader(project) {
return '// ' + project.name + ' - created with Gulp Fiction';
}

function buildDependencies(project) {
var stepNames = getStepNames(project), content = [];

Expand All @@ -31,7 +36,9 @@
}

stepNames.forEach(function (stepName) {
content.push('var ' + normalizeStepName(stepName) + ' = require("gulp-' + stepName + '");');
if (stepName) {
content.push('var ' + normalizeStepName(stepName) + ' = require("gulp-' + stepName + '");');
}
});

// prepend project module
Expand Down Expand Up @@ -88,6 +95,23 @@
}

function buildTask(task) {

// ensure correct input glob to export
// and correct dst
if (task.inputGlob && task.inputGlob.length === 1 && task.inputGlob[0].path === '') {
return LINEBREAK;
}

if (task.outputDir === '') {
return LINEBREAK;
}



if (task.steps.filter(filterEmptySteps).length === 0) {
return LINEBREAK;
}

var taskContent = [], preTasks = buildPreTasks(task);
taskContent.push('gulp.task("' + task.name + '", [' + preTasks + '], {');
taskContent.push(buildTaskContent(task));
Expand All @@ -96,22 +120,30 @@
return taskContent.join(LINEBREAK);
}

function filterEmptySteps(step) {
return (!step.justAdded);
}

function buildPreTasks(task) {
return task.preTasks.map(function (content) {
return '"' + content + '"';
return JSON.stringify(content);
}).join(', ');
}

function buildTaskContent(task) {
var content = [];

content.push('gulp.src(' + JSON.stringify(task.inputGlob) + ')');
function filterEmptySrc(src) {
return src.path !== '';
}

content.push('gulp.src(' + JSON.stringify(task.inputGlob.filter(filterEmptySrc)) + ')');

task.steps.forEach(function (step) {
task.steps.filter(filterEmptySteps).forEach(function (step) {
content.push(INDENT + buildStep(step));
});

content.push(INDENT + '.pipe(gulp.dest("' + task.outputDir + '"));');
content.push(INDENT + '.pipe(gulp.dest(' + JSON.stringify(task.outputDir) + '));');

return content.map(function (line) {
return INDENT + line;
Expand All @@ -123,6 +155,7 @@
}

function buildStepOptions(step) {
if (typeof step.options === 'string') { return step.options; }
return JSON.stringify(step.options);
}

Expand Down
6 changes: 6 additions & 0 deletions src/store/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@
saveProject: function (project) {
if (!project) { return; }
var saveCopy = exports.angular.copy(project);
// dont save empty steps
saveCopy.tasks.forEach(function (task) {
task.steps = task.steps.filter(function (step) {
return !step.justAdded;
});
});
localStorage.set(PROJECT_PREFIX + project.id, saveCopy);
},
removeProject: function (project) {
Expand Down

0 comments on commit 3322038

Please sign in to comment.