From 4ced4d5272e4c2ff1688110c3171eeceacae9d85 Mon Sep 17 00:00:00 2001 From: Joey Trapp Date: Wed, 3 Sep 2014 08:59:49 -0500 Subject: [PATCH 1/5] Compiling less files in dev mode --- Gruntfile.js | 76 ++++++++++++++++++------------------------- package.json | 17 +++++----- webroot/less/app.less | 0 3 files changed, 40 insertions(+), 53 deletions(-) create mode 100644 webroot/less/app.less diff --git a/Gruntfile.js b/Gruntfile.js index 547ce75..3b25175 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -4,31 +4,41 @@ module.exports = function(grunt) { var includePaths = [ 'webroot/js', 'webroot/css' ]; grunt.loadNpmTasks('grunt-contrib-watch'); + grunt.loadNpmTasks('grunt-contrib-less'); grunt.initConfig({ pkg: grunt.file.readJSON('package.json'), - watch: { - files: [ - '!Lib/Cake/**', - '!Vendor/**', - '!tmp/**', - '!.git/**/*.php', - '**/*.php' - ], - tasks: 'null' - }, - server: { + + less: { dev: { - port: 3333, - path: '/assets', - include: includePaths + options: { + paths: ["webroot/css"] // Include more paths here + }, + files: { + "webroot/css/app.css": "webroot/less/app.less" + } } - }, - build: { - prod: { - include: includePaths, - files: ['application.css', 'application.js'], - dest: 'webroot/assets' + } + + watch: { + php: { + files: [ + '!Lib/Cake/**', + '!Vendor/**', + '!tmp/**', + '!.git/**/*.php', + '**/*.php' + ], + tasks: 'null' + } + less: { + styles: { + files: ['webroot/less/**/*.{css,less}'], + tasks: ['build:css'], + /*options: { + livereload: false + }*/ + }, } } }); @@ -44,30 +54,6 @@ module.exports = function(grunt) { file.exists(function() { file.run(); }); }); - grunt.registerTask('dev', ['server', 'watch']); - grunt.registerTask('null', function() {}); - - grunt.registerMultiTask('server', 'Run a development asset compilation server.', function() { - var assetServer = require('./Console/node/asset_server'); - assetServer(this.data.port, this.data.path, this.data.include); - }); - - grunt.registerMultiTask('build', 'Build assets to static files.', function() { - var assetBuilder = require('./Console/node/asset_builder'); - assetBuilder(this.data.dest, this.data.files, this.data.include, this.async()); - }); - - grunt.registerTask('test', 'Run the browser tests in command line', function(protocol, url) { - var path = require('path'), - runTests = require('./Console/node/run_tests'); - if (!protocol && !url) { - url = 'localhost/' + path.basename(__dirname) + '/testjs'; - } else if (/http/.test(protocol)) { - url = url.replace('//', ''); - } else { - url = protocol; - } - runTests('http://' + url, this.async()); - }); + grunt.registerTask('default', ['watch']); }; diff --git a/package.json b/package.json index 9c0fe05..fa5365f 100644 --- a/package.json +++ b/package.json @@ -4,15 +4,16 @@ "start": "grunt dev" }, "dependencies": { - "grunt": "~0.4.1", - "grunt-contrib-watch": "~0.3.1", - "mincer": "~0.4.5", - "connect": "~2.7.4", + "async": "~0.2.6", "coffee-script": "~1.6.2", - "less": "~1.3.3", + "connect": "~2.7.4", "csso": "~1.3.7", - "uglify-js": "~2.2.5", - "async": "~0.2.6", - "mocha-phantomjs": "~2.0.1" + "grunt": "~0.4.5", + "grunt-contrib-less": "~0.11.4", + "grunt-contrib-watch": "~0.3.1", + "less": "~1.3.3", + "mincer": "~0.4.5", + "mocha-phantomjs": "~2.0.1", + "uglify-js": "~2.2.5" } } diff --git a/webroot/less/app.less b/webroot/less/app.less new file mode 100644 index 0000000..e69de29 From 3aef070b996b74e8e28292356d1930be3a1e4488 Mon Sep 17 00:00:00 2001 From: Joey Trapp Date: Wed, 3 Sep 2014 09:06:57 -0500 Subject: [PATCH 2/5] Removed unused node files for asset compilation and server --- Console/node/asset_builder.js | 53 ------------------------------- Console/node/asset_environment.js | 16 ---------- Console/node/asset_server.js | 12 ------- Console/node/run_tests.js | 9 ------ 4 files changed, 90 deletions(-) delete mode 100644 Console/node/asset_builder.js delete mode 100644 Console/node/asset_environment.js delete mode 100644 Console/node/asset_server.js delete mode 100644 Console/node/run_tests.js diff --git a/Console/node/asset_builder.js b/Console/node/asset_builder.js deleted file mode 100644 index 9af0017..0000000 --- a/Console/node/asset_builder.js +++ /dev/null @@ -1,53 +0,0 @@ -module.exports = function(output, files, paths, done) { - var fs = require('fs'), - path = require('path'), - exec = require('child_process').exec, - async = require('async'), - env = require('./asset_environment').call(this, paths), - assets = path.join(path.dirname(path.dirname(__dirname)), output); - - env.jsCompressor = function(context, data, callback) { - var UglifyJS = require('uglify-js'), - ast = UglifyJS.parse(data), - compressor = UglifyJS.Compressor(); - try { - ast.figure_out_scope(); - ast = ast.transform(compressor); - ast.figure_out_scope(); - ast.compute_char_frequency(); - ast.mangle_names(); - callback(null, ast.print_to_string()); - } catch (err) { - console.log('Error with jsCompressor'); - callback(err); - } - }; - - env.cssCompressor = function(context, data, callback) { - try { - callback(null, require('csso').justDoIt(data)); - } catch (err) { - callback(err); - } - }; - - exec('rm -rf ' + assets, function(err) { - var methods = files.map(function(file, index, arr) { - return function(callback) { - env.findAsset(file).compile(function(err, asset) { - var bits = asset.pathname.split(path.sep), - filepath = path.join(assets, bits[bits.length - 1]); - fs.writeFile(filepath, asset.toString(), function(err) { - callback(err); - }); - }); - }; - }); - fs.mkdirSync(assets, 0777); - async.waterfall(methods, function(err) { - if (err) throw err; - console.log('Build completed successfully'); - done(); - }); - }); -}; \ No newline at end of file diff --git a/Console/node/asset_environment.js b/Console/node/asset_environment.js deleted file mode 100644 index 1673b87..0000000 --- a/Console/node/asset_environment.js +++ /dev/null @@ -1,16 +0,0 @@ -module.exports = function(paths) { - var path = require('path'), - Mincer = require('mincer'), - base = path.dirname(path.dirname(__dirname)), - env; - - Mincer.logger.use(console); - - env = new Mincer.Environment(base); - - paths.forEach(function(includePath) { - env.appendPath(includePath); - }); - - return env; -}; \ No newline at end of file diff --git a/Console/node/asset_server.js b/Console/node/asset_server.js deleted file mode 100644 index df79c6b..0000000 --- a/Console/node/asset_server.js +++ /dev/null @@ -1,12 +0,0 @@ -module.exports = function(port, assetPath, paths) { - var path = require('path'), - connect = require('connect'), - Mincer = require('mincer'), - env = require('./asset_environment').call(this, paths), - app = connect(); - - app.use(assetPath, Mincer.createServer(env)); - - app.listen(port); - console.log('dev server running at localhost:3333'); -}; \ No newline at end of file diff --git a/Console/node/run_tests.js b/Console/node/run_tests.js deleted file mode 100644 index 8894d5b..0000000 --- a/Console/node/run_tests.js +++ /dev/null @@ -1,9 +0,0 @@ -module.exports = function(url, done) { - var spawn = require('child_process').spawn, - command = './node_modules/mocha-phantomjs/bin/mocha-phantomjs', - runner; - - runner = spawn(command, [url, '-R', 'dot']); - runner.stdout.pipe(process.stdout); - runner.on('close', done); -}; \ No newline at end of file From 21f741d46f5527225a9cfdac386701dd2e48ad0d Mon Sep 17 00:00:00 2001 From: Brian Porter Date: Wed, 3 Sep 2014 14:46:22 -0500 Subject: [PATCH 3/5] Adds TODO marker. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index fa5365f..f353753 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "_PROJECT_NAME_", + "name": "@TODO:_PROJECT_NAME_", "scripts": { "start": "grunt dev" }, From c5ac4af4d2c4ede7115bb0c8a9bb995dd214c748 Mon Sep 17 00:00:00 2001 From: Brian Porter Date: Wed, 3 Sep 2014 14:48:47 -0500 Subject: [PATCH 4/5] Syntax corrections, more accurate defaults. --- Gruntfile.js | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index 3b25175..aa4bdbb 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -1,8 +1,6 @@ var fs = require('fs'); module.exports = function(grunt) { - var includePaths = [ 'webroot/js', 'webroot/css' ]; - grunt.loadNpmTasks('grunt-contrib-watch'); grunt.loadNpmTasks('grunt-contrib-less'); @@ -12,13 +10,15 @@ module.exports = function(grunt) { less: { dev: { options: { - paths: ["webroot/css"] // Include more paths here + paths: ["webroot/css"] }, files: { - "webroot/css/app.css": "webroot/less/app.less" + "webroot/css/global.css": "webroot/less/global.less", + "webroot/css/public.css": "webroot/less/public.less", + "webroot/css/admin.css": "webroot/less/admin.less" } } - } + }, watch: { php: { @@ -30,15 +30,12 @@ module.exports = function(grunt) { '**/*.php' ], tasks: 'null' - } + }, less: { - styles: { - files: ['webroot/less/**/*.{css,less}'], - tasks: ['build:css'], - /*options: { - livereload: false - }*/ - }, + files: [ + 'webroot/less/**/*.{css,less}' + ], + tasks: 'less' } } }); From c2fca2ff29a1931938b2c05db1fdcd60bd0dd3fc Mon Sep 17 00:00:00 2001 From: Brian Porter Date: Wed, 22 Oct 2014 08:38:43 -0500 Subject: [PATCH 5/5] WIP gruntfile tests. The PHP test runner should really be a MultiTask so it fires tests sequentially (they clobber each other inside the VM otherwise.) This would also allow us to have the individual filenames available in the Gruntfile. --- Gruntfile.js | 40 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index aa4bdbb..a0f0233 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -1,6 +1,7 @@ var fs = require('fs'); module.exports = function(grunt) { + var changedFiles = {}; grunt.loadNpmTasks('grunt-contrib-watch'); grunt.loadNpmTasks('grunt-contrib-less'); @@ -29,7 +30,11 @@ module.exports = function(grunt) { '!.git/**/*.php', '**/*.php' ], - tasks: 'null' + tasks: 'null', +// tasks: 'phptestfile', + options: { + spawn: false + } }, less: { files: [ @@ -40,7 +45,14 @@ module.exports = function(grunt) { } }); + grunt.registerTask('null', function() {}); + grunt.registerTask('default', ['watch']); + grunt.event.on('watch', function(action, filepath) { +// console.log(action, filepath, this); +// if (this.name != 'watch:php') { +// return false; +// } var CakeTestRunner = require('./Console/node/cake_test_runner'), file = new CakeTestRunner(filepath); @@ -51,6 +63,28 @@ module.exports = function(grunt) { file.exists(function() { file.run(); }); }); - grunt.registerTask('null', function() {}); - grunt.registerTask('default', ['watch']); + + + + +// grunt.event.on('watch', function(action, filepath) { +// if (this.name === 'watch:php') { +// changedFiles[filepath] = action; +// } +// }); +// +// grunt.registerMultiTask('phptestfile', function() { +// console.log(changedFiles); +// return true; +// +// var filepath = '?'; +// var CakeTestRunner = require('./Console/node/cake_test_runner'); +// var file = new CakeTestRunner(filepath); +// +// if (fs.existsSync('.vagrant')) { //@TODO: This doesn't work because the folder shows up inside the VM too. +// file.vagrantHost = true; +// } +// +// file.exists(function() { file.run(); }); +// }); };