Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions app/files.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@
"bower.json",

"e2e/main.po.js",

"gulpfile.js",
"gulp/build.js",
"gulp/consolidate.js",
"gulp/inject.js",
"gulp/markups.js",
"gulp/scripts.js",
"gulp/styles.js",
"gulp/watch.js",
"gulp/wiredep.js",
"gulp/server.js",
"gulp/unit-tests.js",
"src/app/index.js",
Expand Down
42 changes: 21 additions & 21 deletions app/prompts.json
Original file line number Diff line number Diff line change
Expand Up @@ -378,45 +378,45 @@
]
},
{
"type": "checkbox",
"name": "htmlPreprocessors",
"message": "Which html template engine would you want to have?",
"type": "list",
"name": "htmlPreprocessor",
"message": "Which html template engine would you want?",
"choices": [
{
"value": {
"key": "none",
"extension": "html",
"module": null,
"version": null
},
"name": "None, I like to code in standard HTML."
},
{
"value": {
"key": "jade",
"consolidate": ["jade", {"pretty": " "}],
"extension": "jade",
"npm": {
"jade": "~1.8.1"
}
"module": "jade",
"version": "~1.8.1"
},
"name": "Jade (*.jade)",
"checked": true
"name": "Jade (*.jade)"
},
{
"value": {
"key": "haml",
"consolidate": ["hamljs"],
"extension": "haml",
"npm": {
"hamljs": "~0.6.2"
}
"module": "hamljs",
"version": "~0.6.2"
},
"name": "Haml (*.haml)",
"checked": false
"name": "Haml (*.haml)"
},
{
"value": {
"key": "handlebars",
"consolidate": ["handlebars"],
"extension": "hbs",
"npm": {
"handlebars": "~2.0.0"
}
"module": "handlebars",
"version": "~2.0.0"
},
"name": "Handlebars (*.hbs)",
"checked": false
"name": "Handlebars (*.hbs)"
}
]
}
Expand Down
107 changes: 54 additions & 53 deletions app/src/format.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,19 @@ module.exports = function () {
this.routerJs = '';
}

// inject task dependencies computation
this.injectTaskDeps = [];
if (this.props.cssPreprocessor.key !== 'none') {
this.injectTaskDeps.push('\'styles\'');
}
if (this.props.jsPreprocessor.key !== 'none') {
if (this.props.jsPreprocessor.extension === 'js') {
this.injectTaskDeps.push('\'browserify\'');
} else {
this.injectTaskDeps.push('\'scripts\'');
}
}

// Wiredep exclusions
this.wiredepExclusions = [];
if (this.props.ui.key === 'bootstrap') {
Expand Down Expand Up @@ -176,70 +189,58 @@ module.exports = function () {
}
}

// Template files
this.srcTemplates = {};
files.templates.forEach(function(file) {
var basename = path.basename(file);
var src = file.replace(basename, '_' + basename);
var dest = file;

var isJsPreprocessor = src.match(/\.js$/) && fs.existsSync(this.sourceRoot() + '/' + src.replace(/\.js$/, '.' + this.props.jsPreprocessor.srcExtension));

if(isJsPreprocessor) {
src = src.replace(/\.js$/, '.' + this.props.jsPreprocessor.srcExtension);
}
if(isJsPreprocessor) {
dest = dest.replace(/\.js$/, '.' + this.props.jsPreprocessor.extension);
}

this.srcTemplates[src] = dest;
}, this);

if(this.isVendorStylesPreprocessed && this.props.ui.name !== null) {
var styleVendorSource = 'src/app/__' + this.props.ui.key + '-vendor.' + this.props.cssPreprocessor.extension;
this.srcTemplates[styleVendorSource] = 'src/app/vendor.' + this.props.cssPreprocessor.extension;
this.styleCopies[styleVendorSource] = 'src/app/vendor.' + this.props.cssPreprocessor.extension;
}

// Static files
this.staticFiles = {};
files.staticFiles.forEach(function(file) {
var src = file;
var dest = file;
var templateFiles = files.templates;

var isJsPreprocessor = src.match(/\.js$/) && fs.existsSync(this.sourceRoot() + '/' + src.replace(/\.js$/, '.' + this.props.jsPreprocessor.srcExtension));
if(this.props.cssPreprocessor.key === 'none') {
templateFiles = _.reject(templateFiles, function(path) {
return /styles\.js/.test(path);
});
}
if(this.props.jsPreprocessor.key === 'none') {
templateFiles = _.reject(templateFiles, function(path) {
return /scripts\.js/.test(path);
});
}
if(this.props.htmlPreprocessor.key === 'none') {
templateFiles = _.reject(templateFiles, function(path) {
return /markups\.js/.test(path);
});
}

if(isJsPreprocessor) {
src = src.replace(/\.js$/, '.' + this.props.jsPreprocessor.srcExtension);
}
if(isJsPreprocessor) {
dest = dest.replace(/\.js$/, '.' + this.props.jsPreprocessor.extension);
}
//JS Preprocessor files
function resolvePaths(template) {
return function(filesObject, file) {
var src = file, dest = file;

this.staticFiles[src] = dest;
}, this);
if(template) {
var basename = path.basename(file);
src = file.replace(basename, '_' + basename);
}

this.lintConfCopies = [];
if(this.props.jsPreprocessor.key === 'coffee') {
this.lintConfCopies.push('coffeelint.json');
}
if(src.match(/\.js$/)) {
var preprocessorFile = this.sourceRoot() + '/' + src.replace(/\.js$/, '.' + this.props.jsPreprocessor.srcExtension);
if(fs.existsSync(preprocessorFile)) {
src = src.replace(/\.js$/, '.' + this.props.jsPreprocessor.srcExtension);
dest = dest.replace(/\.js$/, '.' + this.props.jsPreprocessor.extension);
}
}

function dependencyString(dep, version) {
return '"' + dep + '": ' + '"' + version + '"';
filesObject[src] = dest;
return filesObject;
};
}

this.consolidateExtensions = [];
this.srcTemplates = templateFiles.reduce(resolvePaths(true).bind(this), {});

this.npmDevDependencies = [];
this.consolidateParameters = [];
this.staticFiles = files.staticFiles.reduce(resolvePaths(false).bind(this), {});

// Adding npm dev dependencies
_.forEach(this.props.htmlPreprocessors, function(preprocessor) {
_.forEach(preprocessor.npm, function(version, dep) {
this.npmDevDependencies.push(dependencyString(dep, version));
}.bind(this));
this.consolidateParameters.push(
JSON.stringify(preprocessor.consolidate).
replace(/"/g,'\'')); // Replace " with ' and assume this won't break anything.
this.consolidateExtensions.push(preprocessor.extension);
}.bind(this));
this.lintConfCopies = [];
if(this.props.jsPreprocessor.key === 'coffee') {
this.lintConfCopies.push('coffeelint.json');
}
};
10 changes: 6 additions & 4 deletions app/src/mock-prompts.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var questions = [
'foundationComponents',
'cssPreprocessor',
'jsPreprocessor',
'htmlPreprocessors'
'htmlPreprocessor'
];

var model = {};
Expand Down Expand Up @@ -90,6 +90,10 @@ model.jsPreprocessor.choices.forEach(function(choice) {
model.jsPreprocessor.values[choice.value.key] = choice.value;
});

model.htmlPreprocessor.choices.forEach(function(choice) {
model.htmlPreprocessor.values[choice.value.key] = choice.value;
});

module.exports = {
prompts: model,
defaults: {
Expand All @@ -103,9 +107,7 @@ module.exports = {
foundationComponents: model.foundationComponents.values.none,
cssPreprocessor: model.cssPreprocessor.values['node-sass'],
jsPreprocessor: model.jsPreprocessor.values.none,
htmlPreprocessors: _.filter(_.pluck(model.htmlPreprocessors.choices, 'value'), function(v) {
return v.key === 'jade';
})
htmlPreprocessor: model.htmlPreprocessor.values.none
},
libRegexp: function(name, version) {
return new RegExp('"' + name + '": "' + version + '"');
Expand Down
63 changes: 42 additions & 21 deletions app/src/write.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,54 @@
'use strict';

var utils = require('./utils');
var files = require('../files.json');

/* Process files */
module.exports = function () {
var _ = this._;
var data = this;

function process(content) {
return _.template(content.toString().replace(/\n<%/g, '<%'), data);
}

var copy = function copy(src, dest, processing) {
dest = utils.replacePrefix(dest, this.props.paths);
try {
if(processing) {
this.fs.copy(this.templatePath(src), this.destinationPath(dest), { process: process });
} else {
this.fs.copy(this.templatePath(src), this.destinationPath(dest));
}
} catch (error) {
console.error('Template processing error on file', src);
throw error;
}
}.bind(this);

// Copy dot files
_.forEach(files.dotFiles, function(src) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think dotfiles is gone so this can be removed.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right but I think I'll keep this waiting for a further refactoring PR...

This one is too big already

copy(src, '.' + src);
});

// Copy files formatted (format.js) with options selected in prompt
_.forEach(this.staticFiles, function(value, key) {
var dest = utils.replacePrefix(value, this.props.paths);
this.fs.copy(this.templatePath(key), this.destinationPath(dest));
}.bind(this));
_.forEach(this.staticFiles, function(dest, src) {
copy(src, dest);
});

_.forEach(this.technologiesLogoCopies, function(src) {
var dest = utils.replacePrefix(src, this.props.paths);
this.fs.copy(this.templatePath(src), this.destinationPath(dest));
}.bind(this));
_.forEach(this.partialCopies, function(value, key) {
var dest = utils.replacePrefix(value, this.props.paths);
this.fs.copy(this.templatePath(key), this.destinationPath(dest));
}.bind(this));
_.forEach(this.styleCopies, function(value, key) {
var dest = utils.replacePrefix(value, this.props.paths);
this.fs.copy(this.templatePath(key), this.destinationPath(dest));
}.bind(this));
_.forEach(this.srcTemplates, function(value, key) {
var dest = utils.replacePrefix(value, this.props.paths);
this.template(key, dest);
}.bind(this));
copy(src, src);
});
_.forEach(this.partialCopies, function(dest, src) {
copy(src, dest);
});
_.forEach(this.styleCopies, function(dest, src) {
copy(src, dest, true);
});
_.forEach(this.srcTemplates, function(dest, src) {
copy(src, dest, true);
});
_.forEach(this.lintConfCopies, function(src) {
this.fs.copy(this.templatePath(src), this.destinationPath(src));
}.bind(this));
copy(src, src);
});
};
35 changes: 23 additions & 12 deletions app/templates/_package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
"gulp-consolidate": "~0.1.2",
"gulp-csso": "~0.2.9",
"gulp-filter": "~1.0.2",
"gulp-flatten": "~0.0.4",<% if (imageMin) { %>
"gulp-imagemin": "~2.0.0",<% } %>
"gulp-flatten": "~0.0.4",
<% if (imageMin) { %>
"gulp-imagemin": "~2.0.0",
<% } %>
"gulp-jshint": "~1.9.0",
"gulp-load-plugins": "~0.7.1",
"gulp-size": "~1.1.0",
Expand All @@ -25,12 +27,20 @@
"gulp-minify-html": "~0.1.7",
"gulp-inject": "~1.0.2",
"gulp-protractor": "~0.0.11",
"gulp-karma": "~0.0.4",<% if (props.cssPreprocessor.key !== 'none') { %>
"<%= props.cssPreprocessor.module %>": "<%= props.cssPreprocessor.version %>",<% } if (props.jsPreprocessor.key !== 'none') { %>
"<%= props.jsPreprocessor.module %>": "<%= props.jsPreprocessor.version %>",<% } if (props.jsPreprocessor.srcExtension === 'es6') { %>
"gulp-browserify": "~0.5.0",<% } else { %>
"gulp-angular-filesort": "~1.0.4",<% } if(props.jsPreprocessor.key === 'coffee') { %>
"gulp-coffeelint": "~0.4.0",<% } %>
"gulp-karma": "~0.0.4",
<% if (props.cssPreprocessor.key !== 'none') { %>
"<%= props.cssPreprocessor.module %>": "<%= props.cssPreprocessor.version %>",
<% } if (props.jsPreprocessor.key !== 'none') { %>
"<%= props.jsPreprocessor.module %>": "<%= props.jsPreprocessor.version %>",
<% } if (props.jsPreprocessor.srcExtension === 'es6') { %>
"gulp-browserify": "~0.5.0",
<% } else { %>
"gulp-angular-filesort": "~1.0.4",
<% } if (props.jsPreprocessor.key === 'coffee') { %>
"gulp-coffeelint": "~0.4.0",
<% } if (props.htmlPreprocessor.key !== 'none') { %>
"<%= props.htmlPreprocessor.module %>": "<%= props.htmlPreprocessor.version %>",
<% } %>
"main-bower-files": "~2.4.0",
"jshint-stylish": "~1.0.0",
"wiredep": "~2.2.0",
Expand All @@ -40,10 +50,11 @@
"browser-sync": "~1.7.1",
"http-proxy": "~1.7.0",
"chalk": "~0.5.1",
"protractor": "~1.4.0",<% if (qrCode) { %>
"qrcode-terminal": "~0.9.5",<% } %>
"uglify-save-license": "~0.4.1"<% if(npmDevDependencies.length > 0) { %>,<% } %>
<%= npmDevDependencies.join(',\n ') %>
"protractor": "~1.4.0",
<% if (qrCode) { %>
"qrcode-terminal": "~0.9.5",
<% } %>
"uglify-save-license": "~0.4.1"
},
"engines": {
"node": ">=0.10.0"
Expand Down
Loading