Skip to content

Commit e60ba5d

Browse files
committed
using PR angular-fullstack#637 from generator-angular to add less support
1 parent 7f37f18 commit e60ba5d

File tree

3 files changed

+100
-49
lines changed

3 files changed

+100
-49
lines changed

app/index.js

Lines changed: 68 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ var wiredep = require('wiredep');
1010

1111
var Generator = module.exports = function Generator(args, options) {
1212
yeoman.generators.Base.apply(this, arguments);
13-
this.argument('appname', { type: String, required: false });
13+
this.argument('appname', {
14+
type: String,
15+
required: false
16+
});
1417
this.appname = this.appname || path.basename(process.cwd());
1518
this.appname = this._.camelize(this._.slugify(this._.humanize(this.appname)));
1619

@@ -82,7 +85,7 @@ var Generator = module.exports = function Generator(args, options) {
8285
args: args
8386
});
8487

85-
this.on('end', function () {
88+
this.on('end', function() {
8689
this.installDependencies({
8790
skipInstall: this.options['skip-install'],
8891
callback: this._injectDependencies.bind(this)
@@ -153,13 +156,31 @@ Generator.prototype.askForCompass = function askForCompass() {
153156
name: 'compass',
154157
message: 'Would you like to use Sass (with Compass)?',
155158
default: true
156-
}], function (props) {
159+
}], function(props) {
157160
this.compass = props.compass;
158161

159162
cb();
160163
}.bind(this));
161164
};
162165

166+
Generator.prototype.askForLess = function askForLess() {
167+
var cb = this.async();
168+
169+
this.prompt([{
170+
type: 'confirm',
171+
name: 'less',
172+
message: 'Would you like to use Less?',
173+
default: true,
174+
when: function(props) {
175+
return !this.compass;
176+
}
177+
}], function(props) {
178+
this.less = props.less;
179+
180+
cb();
181+
}.bind(this));
182+
};
183+
163184
Generator.prototype.askForBootstrap = function askForBootstrap() {
164185
var compass = this.compass;
165186
var cb = this.async();
@@ -174,10 +195,10 @@ Generator.prototype.askForBootstrap = function askForBootstrap() {
174195
name: 'compassBootstrap',
175196
message: 'Would you like to use the Sass version of Twitter Bootstrap?',
176197
default: true,
177-
when: function (props) {
198+
when: function(props) {
178199
return props.bootstrap && compass;
179200
}
180-
}], function (props) {
201+
}], function(props) {
181202
this.bootstrap = props.bootstrap;
182203
this.compassBootstrap = props.compassBootstrap;
183204

@@ -211,8 +232,10 @@ Generator.prototype.askForModules = function askForModules() {
211232
}]
212233
}];
213234

214-
this.prompt(prompts, function (props) {
215-
var hasMod = function (mod) { return props.modules.indexOf(mod) !== -1; };
235+
this.prompt(prompts, function(props) {
236+
var hasMod = function(mod) {
237+
return props.modules.indexOf(mod) !== -1;
238+
};
216239
this.resourceModule = hasMod('resourceModule');
217240
this.cookiesModule = hasMod('cookiesModule');
218241
this.sanitizeModule = hasMod('sanitizeModule');
@@ -236,7 +259,7 @@ Generator.prototype.askForModules = function askForModules() {
236259
}
237260

238261
if (angMods.length) {
239-
this.env.options.angularDeps = "\n " + angMods.join(",\n ") +"\n";
262+
this.env.options.angularDeps = "\n " + angMods.join(",\n ") + "\n";
240263
}
241264

242265
cb();
@@ -256,10 +279,10 @@ Generator.prototype.askForMongo = function askForMongo() {
256279
name: 'mongoPassportUser',
257280
message: 'Would you like to include a Passport authentication boilerplate?',
258281
default: false,
259-
when: function (props) {
282+
when: function(props) {
260283
return props.mongo;
261284
}
262-
}], function (props) {
285+
}], function(props) {
263286
this.mongo = props.mongo;
264287
this.mongoPassportUser = props.mongoPassportUser;
265288

@@ -271,7 +294,7 @@ Generator.prototype.readIndex = function readIndex() {
271294
this.ngRoute = this.env.options.ngRoute;
272295
this.jade = this.env.options.jade;
273296

274-
if(this.jade) {
297+
if (this.jade) {
275298
this.indexFile = this.engine(this.read('../../templates/views/jade/index.jade'), this);
276299
} else {
277300
this.indexFile = this.engine(this.read('../../templates/views/html/index.html'), this);
@@ -281,6 +304,9 @@ Generator.prototype.readIndex = function readIndex() {
281304
Generator.prototype.bootstrapFiles = function bootstrapFiles() {
282305
var sass = this.compass;
283306
var mainFile = 'main.' + (sass ? 's' : '') + 'css';
307+
if (this.less) {
308+
mainFile = 'main.less';
309+
}
284310

285311
if (this.bootstrap && !sass) {
286312
this.copy('fonts/glyphicons-halflings-regular.eot', 'app/fonts/glyphicons-halflings-regular.eot');
@@ -300,25 +326,25 @@ function generateJadeBlock(blockType, optimizedPath, filesBlock, searchPath, pre
300326
if (util.isArray(searchPath)) {
301327
searchPath = '{' + searchPath.join(',') + '}';
302328
}
303-
blockSearchPath = '(' + searchPath + ')';
329+
blockSearchPath = '(' + searchPath + ')';
304330
}
305331

306332
blockStart = '\n' + prefix + '<!-- build:' + blockType + blockSearchPath + ' ' + optimizedPath + ' -->\n';
307333
blockEnd = prefix + '<!-- endbuild -->\n' + prefix;
308334
return blockStart + filesBlock + blockEnd;
309335
}
310336

311-
function appendJade(jade, tag, blocks){
337+
function appendJade(jade, tag, blocks) {
312338
var mark = "//- build:" + tag,
313-
position = jade.indexOf(mark);
339+
position = jade.indexOf(mark);
314340
return [jade.slice(0, position), blocks, jade.slice(position)].join('');
315341
}
316342

317343
function appendFilesToJade(jadeOrOptions, fileType, optimizedPath, sourceFileList, attrs, searchPath) {
318344
var blocks, updatedContent,
319-
jade = jadeOrOptions,
320-
prefix = ' ',
321-
files = '';
345+
jade = jadeOrOptions,
346+
prefix = ' ',
347+
files = '';
322348

323349
if (typeof jadeOrOptions === 'object') {
324350
jade = jadeOrOptions.html;
@@ -330,14 +356,14 @@ function appendFilesToJade(jadeOrOptions, fileType, optimizedPath, sourceFileLis
330356
}
331357

332358
if (fileType === 'js') {
333-
sourceFileList.forEach(function (el) {
334-
files += prefix + '<script ' + (attrs||'') + 'src="' + el + '"></script>\n';
359+
sourceFileList.forEach(function(el) {
360+
files += prefix + '<script ' + (attrs || '') + 'src="' + el + '"></script>\n';
335361
});
336362
blocks = generateJadeBlock('js', optimizedPath, files, searchPath, prefix);
337363
updatedContent = appendJade(jade, 'body', blocks);
338364
} else if (fileType === 'css') {
339-
sourceFileList.forEach(function (el) {
340-
files += prefix + '<link ' + (attrs||'') + 'rel="stylesheet" href="' + el + '">\n';
365+
sourceFileList.forEach(function(el) {
366+
files += prefix + '<link ' + (attrs || '') + 'rel="stylesheet" href="' + el + '">\n';
341367
});
342368
blocks = generateJadeBlock('css', optimizedPath, files, searchPath, prefix);
343369
updatedContent = appendJade(jade, 'head', blocks);
@@ -350,12 +376,12 @@ var copyScriptWithEnvOptions = function copyScriptWithEnvOptions(that, fileToCop
350376
minsafe = '',
351377
sourceFolder = 'javascript';
352378

353-
if(that.env.options.coffee) {
379+
if (that.env.options.coffee) {
354380
ext = 'coffee';
355381
sourceFolder = 'coffeescript';
356382
}
357383

358-
if(that.env.options.minsafe) {
384+
if (that.env.options.minsafe) {
359385
minsafe = '-min';
360386
}
361387
that.copy('../../templates/' + sourceFolder + minsafe + '/' + fileToCopy + '.' + ext, destinationFolder + fileToCopy + '.' + ext);
@@ -402,10 +428,10 @@ Generator.prototype.createIndex = function createIndex() {
402428
};
403429

404430
Generator.prototype.addJadeViews = function addHtmlJade() {
405-
if(this.jade) {
431+
if (this.jade) {
406432
this.copy('../../templates/views/jade/partials/main.jade', 'app/views/partials/main.jade');
407433
this.copy('../../templates/views/jade/partials/navbar.jade', 'app/views/partials/navbar.jade');
408-
if(this.mongoPassportUser) {
434+
if (this.mongoPassportUser) {
409435
this.copy('../../templates/views/jade/partials/login.jade', 'app/views/partials/login.jade');
410436
this.copy('../../templates/views/jade/partials/signup.jade', 'app/views/partials/signup.jade');
411437
this.copy('../../templates/views/jade/partials/settings.jade', 'app/views/partials/settings.jade');
@@ -415,10 +441,10 @@ Generator.prototype.addJadeViews = function addHtmlJade() {
415441
};
416442

417443
Generator.prototype.addHtmlViews = function addHtmlViews() {
418-
if(!this.jade) {
444+
if (!this.jade) {
419445
this.copy('../../templates/views/html/partials/main.html', 'app/views/partials/main.html');
420446
this.copy('../../templates/views/html/partials/navbar.html', 'app/views/partials/navbar.html');
421-
if(this.mongoPassportUser) {
447+
if (this.mongoPassportUser) {
422448
this.copy('../../templates/views/html/partials/login.html', 'app/views/partials/login.html');
423449
this.copy('../../templates/views/html/partials/signup.html', 'app/views/partials/signup.html');
424450
this.copy('../../templates/views/html/partials/settings.html', 'app/views/partials/settings.html');
@@ -427,14 +453,14 @@ Generator.prototype.addHtmlViews = function addHtmlViews() {
427453
}
428454
};
429455

430-
Generator.prototype.packageFiles = function () {
456+
Generator.prototype.packageFiles = function() {
431457
this.coffee = this.env.options.coffee;
432458
this.template('../../templates/common/_bower.json', 'bower.json');
433459
this.template('../../templates/common/_package.json', 'package.json');
434460
this.template('../../templates/common/Gruntfile.js', 'Gruntfile.js');
435461
};
436462

437-
Generator.prototype.imageFiles = function () {
463+
Generator.prototype.imageFiles = function() {
438464
this.sourceRoot(path.join(__dirname, 'templates'));
439465
this.directory('images', 'app/images', true);
440466
};
@@ -469,7 +495,7 @@ Generator.prototype._injectDependencies = function _injectDependencies() {
469495
}
470496
};
471497

472-
Generator.prototype.serverFiles = function () {
498+
Generator.prototype.serverFiles = function() {
473499
this.template('../../templates/express/server.js', 'server.js');
474500
this.copy('../../templates/express/jshintrc', 'lib/.jshintrc');
475501
this.template('../../templates/express/controllers/api.js', 'lib/controllers/api.js');
@@ -485,29 +511,29 @@ Generator.prototype.serverFiles = function () {
485511
this.template('../../templates/express/config/env/test.js', 'lib/config/env/test.js');
486512
};
487513

488-
Generator.prototype.mongoFiles = function () {
514+
Generator.prototype.mongoFiles = function() {
489515

490516
if (!this.mongo) {
491-
return; // Skip if disabled.
517+
return; // Skip if disabled.
492518
}
493519
this.env.options.mongo = this.mongo;
494520

495521
this.template('../../templates/express/config/dummydata.js', 'lib/config/dummydata.js');
496522
this.template('../../templates/express/models/thing.js', 'lib/models/thing.js');
497523

498-
if(!this.mongoPassportUser) {
499-
return; // Skip if disabled.
524+
if (!this.mongoPassportUser) {
525+
return; // Skip if disabled.
500526
}
501527
this.env.options.mongoPassportUser = this.mongoPassportUser;
502528

503529
// frontend
504-
copyScriptWithEnvOptions(this, 'controllers/login', 'app/scripts/');
505-
copyScriptWithEnvOptions(this, 'controllers/signup', 'app/scripts/');
506-
copyScriptWithEnvOptions(this, 'controllers/settings', 'app/scripts/');
530+
copyScriptWithEnvOptions(this, 'controllers/login', 'app/scripts/');
531+
copyScriptWithEnvOptions(this, 'controllers/signup', 'app/scripts/');
532+
copyScriptWithEnvOptions(this, 'controllers/settings', 'app/scripts/');
507533

508-
copyScriptWithEnvOptions(this, 'services/auth', 'app/scripts/');
509-
copyScriptWithEnvOptions(this, 'services/session', 'app/scripts/');
510-
copyScriptWithEnvOptions(this, 'services/user', 'app/scripts/');
534+
copyScriptWithEnvOptions(this, 'services/auth', 'app/scripts/');
535+
copyScriptWithEnvOptions(this, 'services/session', 'app/scripts/');
536+
copyScriptWithEnvOptions(this, 'services/user', 'app/scripts/');
511537

512538
copyScriptWithEnvOptions(this, 'directives/mongooseError', 'app/scripts/');
513539

@@ -521,5 +547,5 @@ Generator.prototype.mongoFiles = function () {
521547
this.template('../../templates/express/controllers/session.js', 'lib/controllers/session.js');
522548
this.template('../../templates/express/controllers/users.js', 'lib/controllers/users.js');
523549
// tests
524-
this.template('../../templates/express/test/user/model.js', 'test/server/user/model.js');
525-
};
550+
this.template('../../templates/express/test/user/model.js', 'test/server/user/model.js');
551+
};

templates/common/Gruntfile.js

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ module.exports = function (grunt) {
7676
compass: {
7777
files: ['<%%= yeoman.app %>/styles/{,*/}*.{scss,sass}'],
7878
tasks: ['compass:server', 'autoprefixer']
79+
},<% } else if (less) { %>
80+
less: {
81+
files: ['<%%= yeoman.app %>/styles/{,*/}*.less'],
82+
tasks: ['less:dist', 'autoprefixer']
7983
},<% } else { %>
8084
styles: {
8185
files: ['<%%= yeoman.app %>/styles/{,*/}*.css'],
@@ -270,7 +274,24 @@ module.exports = function (grunt) {
270274
debugInfo: true
271275
}
272276
}
273-
},<% } %>
277+
},<% } else if (less) { %>
278+
// Compiles Less to CSS and generates necessary files if requested
279+
less: {
280+
options: {
281+
compile: true,
282+
paths: ['<%%= yeoman.app %>/bower_components', '<%%= yeoman.app %>/libs']
283+
},
284+
dist: {
285+
files: [{
286+
expand: true,
287+
cwd: '<%%= yeoman.app %>/styles',
288+
src: '{,*/}*.less',
289+
dest: '.tmp/styles/',
290+
ext: '.css'
291+
}]
292+
}
293+
},
294+
<% } %>
274295

275296
// Renames files for browser caching purposes
276297
rev: {
@@ -418,12 +439,14 @@ module.exports = function (grunt) {
418439
concurrent: {
419440
server: [<% if (coffee) { %>
420441
'coffee:dist',<% } %><% if (compass) { %>
421-
'compass:server'<% } else { %>
442+
'compass:server'<% } else if (less) { %>
443+
'less:dist' <% } else { %>
422444
'copy:styles'<% } %>
423445
],
424446
test: [<% if (coffee) { %>
425447
'coffee',<% } %><% if (compass) { %>
426-
'compass'<% } else { %>
448+
'compass'<% } else if (less) { %>
449+
'less' <% } else { %>
427450
'copy:styles'<% } %>
428451
],
429452
debug: {
@@ -437,7 +460,8 @@ module.exports = function (grunt) {
437460
},
438461
dist: [<% if (coffee) { %>
439462
'coffee',<% } %><% if (compass) { %>
440-
'compass:dist',<% } else { %>
463+
'compass:dist',<% } else if (less) { %>
464+
'less:dist',<% } else { %>
441465
'copy:styles',<% } %>
442466
'imagemin',
443467
'svgmin',

templates/common/_package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@
1616
"grunt-autoprefixer": "~0.4.0",
1717
"grunt-bower-install": "~0.7.0",
1818
"grunt-concurrent": "~0.4.1",
19-
"grunt-contrib-clean": "~0.5.0",
20-
"grunt-contrib-coffee": "~0.7.0",
21-
"grunt-contrib-compass": "~0.6.0",
19+
"grunt-contrib-clean": "~0.5.0",<% if (coffee) { %>
20+
"grunt-contrib-coffee": "~0.7.0",<% } %><% if (compass) { %>
21+
"grunt-contrib-compass": "~0.7.2",<% } else { %>
22+
"grunt-contrib-less": "^0.10.0", <% } %>
2223
"grunt-contrib-concat": "~0.3.0",
2324
"grunt-contrib-copy": "~0.4.1",
2425
"grunt-contrib-cssmin": "~0.7.0",

0 commit comments

Comments
 (0)