I was struggling to get my server to reload so I followed some links and ended up at connect-livereload.
However, when I try to use the grunt code in my grunt file
connect: {
options: {
port: 3000,
hostname: 'localhost'
},
dev: {
options: {
middleware: function (connect) {
return [
require('connect-livereload')(), // <--- here
checkForDownload,
mountFolder(connect, '.tmp'),
mountFolder(connect, 'app')
];
}
}
}
}
I get this error in my grunt console:
Warning: checkForDownload is not defined Use --force to continue.
Aborted due to warnings.
The documentation for connect-livereload is so horrendous, there is no mention of what checkForDownload, or mountFolder is supposed to me.
Does anyone know?
Related
I have a Meteor application that I'm trying to deploy on a VPS. I am using Meteor Up to do this.
By following the instructions I have set up my mup.js file to look like this:
module.exports = {
servers: {
one: {
host: '41.185.27.69',
username: 'root',
// pem:
password: 'secret',
// or leave blank for authenticate from ssh-agent
opts: {
port: 22
}
}
},
meteor: {
name: 'HelderbergLink',
path: '../../HelderbergLink',
servers: {
one: {}
},
buildOptions: {
serverOnly: true,
},
env: {
ROOT_URL: 'http://41.185.27.69',
MONGO_URL: 'mongodb://127.0.0.1:27017/HelderbergLink'
},
dockerImage: 'abernix/meteord:base',
deployCheckWaitTime: 60
},
mongo: {
oplog: true,
port: 27017,
servers: {
one: {},
},
},
};
After this is set up I run the following command in my .deploy directory:
mup.cmd setup
Everything setups successfully here, but then when I need to run the next command:
mup.cmd deploy
It runs through most of the process but then gives me this error:
I'm not sure what to do to resolve this. Any help would be much appreciated!
I'm just toying around with React and have a basic setup using grunt and grunt-browserify, but I'm getting a parse error. Anyone know a solution for this? Side note - the task runs fine when I don't use react/jsx.
With a basic component:
var HelloWorld = React.createClass({
render: function(){
return (
<div>
Hello World!
</div>
)
}
});
React.render(<HelloWorld />, document.getElementById('app'));
I get this error:
>> File "assets/javascripts/app.js" changed.
Running "browserify:dist" (browserify) task
>> /Users/username/www/reactor/assets/javascripts/app.js:4
>> <div>
>> ^
>> ParseError: Unexpected token
Warning: Error running grunt-browserify. Use --force to continue.
And here is the grunt task:
browserify: {
dist: {
files: {
'public/javascripts/app.js' :
[
'assets/javascripts/components/**/*.js',
'assets/javascripts/app.js'
]
}
}
},
I didn't go with Dhiraj's answer, but that led me to using reactify.
browserify: {
options: {
transform: ['reactify'],
extensions: ['.jsx'],
debug: true
},
dist: {
files: {
'public/javascripts/app.js' :
[
'assets/javascripts/components/**/*.jsx',
'assets/javascripts/app.jsx'
]
}
}
},
The HelloWorld class is jsx so grunt-browserify needs to transform jsx to js using transform option.
browserify: {
dist: {
options: {
transform: [ require('grunt-react').browserify ] // <-- this one
},
client: {
src: [assets/javascripts/components/**/*.js, assets/javascripts/app.js], // sources files
dest: 'public/javascripts/app.js' // output file
}
}
}
Here is a reference
Hope this helps.
When I try using Grunt to create a server for me it quickly shuts down and doesn't give me a change to go to my browser and test it.
This is my entire Grunt file:
module.exports = function (grunt) {
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.initConfig({
connect: {
serve: {
options: {
port: 8081,
base: '/',
hostname: '*',
debug: true
}
}
}
});
grunt.registerTask('default', ['connect']);
}
When I run it, it works without errors:
C:\Users\Imray\my-sandbox>grunt
Running "connect:keepalive" (connect) task
Started connect web server on http://0.0.0.0:8000
Running "connect:serve" (connect) task
Started connect web server on http://0.0.0.0:8081
You have the keepalive settings dedicated for this :
grunt.initConfig({
connect: {
serve: {
options: {
keepalive: true,
port: 8081,
base: '/',
hostname: '*',
debug: true
}
}
}
});
Does anyone know the best solution for automatically restarting node and running tests after the restart every time a file changes?
I am currently using grunt-contrib-watch with grunt-develop. I am getting an ECONNREFUSED error on the some restarts. I think it is because my tests are running before the server is fully online.
Any ideas on how best to achieve what I want?
What I want: Restart node and then run all integration tests after each file change.
I am taking a BDD approach to testing (as opposed to regular unit tests) with cucumber.js. I wanted to make sure that each test run against the API I was building started on a fresh boot-up of the application.
I figured it out. Here is what I used:
grunt-contrib-watch to monitor for file changes.
It in turn calls
grunt-develop to restart the application
grunt-cucumberjs to run the cucumber tests
I then modified my index.js (starts the app) so that it doesn't start the app if the NODE_ENV is set to test. That way the cucumber tests actually start the server and can wait till the start process has finished before running the tests.
Here is the GruntFile and Index file:
Gruntfile.js
/*jslint node: true */
"use strict";
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
env: {
dev: {
APP_DIR_FOR_CODE_COVERAGE: 'coverage/instrument/',
NODE_ENV: 'dev',
PORT: 8080
},
test: {
APP_DIR_FOR_CODE_COVERAGE: 'coverage/instrument/',
NODE_ENV: 'test',
PORT: 8081
},
coverage: {
APP_DIR_FOR_CODE_COVERAGE: 'coverage/instrument/',
NODE_ENV: 'test',
PORT: 8081
}
},
watch: {
js: {
files: [
'index.js',
'features/**/*.js',
'server/**/*.js'
],
tasks: ['develop', 'cucumberjs', 'jshint'],
options: {
nospawn: true
}
}
},
jshint: {
all: ['Gruntfile.js', 'index.js', 'server/**/*.js', 'features/**/*.js']
},
nodemon: {
dev: {
script: 'index.js'
}
},
cucumberjs: {
src: './features',
},
develop: {
server: {
file: 'index.js'
}
},
instrument: {
files: ['index.js', 'server/**/*.*'],
options: {
lazy: true,
basePath: 'coverage/instrument/'
}
},
storeCoverage: {
options: {
dir: 'coverage'
}
},
makeReport: {
src: 'coverage/coverage.json',
options: {
type: 'lcov',
dir: 'coverage/reports',
print: 'detail'
}
},
coverage: {
options: {
thresholds: {
'statements': 90,
'branches': 90,
'lines': 90,
'functions': 90
},
dir: 'coverage',
root: ''
}
}
});
grunt.loadNpmTasks('grunt-env');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-develop');
grunt.loadNpmTasks('grunt-cucumber');
grunt.loadNpmTasks('grunt-istanbul');
grunt.loadNpmTasks('grunt-istanbul-coverage');
grunt.loadNpmTasks('grunt-nodemon');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.registerTask('default', ['env:dev', 'nodemon']);
grunt.registerTask('test', ['env:test', 'watch']);
grunt.registerTask('testcoverage', ['env:test', 'jshint', 'instrument', 'cucumberjs', 'storeCoverage', 'makeReport', 'coverage']);
};
Index.js
/*jslint node: true */
"use strict";
var Hapi = require('hapi');
var Good = require('good');
var server = {};
exports.server = {
start: function(callback) {
/* istanbul ignore next */
var port = process.env.PORT || 8080;
server = new Hapi.Server(port);
var routes = require('./server/routes');
routes.register(server);
var exceptionHandling = require('./server/exceptionHandling');
exceptionHandling.register(server);
server.pack.register(Good, function(err) {
/* istanbul ignore if */
if (err) {
throw err; // something bad happened loading the plugin
}
/* istanbul ignore next */
server.log('info', 'Server starting at ' + server.info.uri);
server.start(callback);
});
},
stop: function(callback) {
server.log('info', 'Server stopping.');
server.stop(null, callback);
},
rootUrl: function() { return server.info.uri; }
};
/* istanbul ignore if */
if (process.env.NODE_ENV != 'test') {
exports.server.start(function() {});
}
I am currently trying to configure grunt-sync to run inside a watch and am running into issues. I've reported the issue to the module's github page but decided to post here to draw upon the general development population rather than wait for a single contributor to come across my issue report.
So, I'm thinking this may just be a gap in my understanding of how to drive grunt tasks through a watch. I've got watches up and running for several tasks already and I'm adding grunt-sync to my workflow to automate publication of my changes to a network directory that blah blah blah...not important; my watch is working for some stuff but not for this. I'm dropping in the relevant config section along with my "concurrent","karma", and "sass" tasks to give you the gist of my overall grunt config.
module.exports = function(grunt){
grunt.initConfig({
pkg: grunt.file.readJSON("package.json"),
project: {
app: 'app',
},
sync:{
main: {
files:
[
{
cwd: 'app/',
src: [
'**/*.js',
'**/*.html',
'**/*.css',
'!app/node_modules/**'
],
dest: ['publish/']
}
],
verbose: true
}
},
karma: {
unit: {
configFile: 'test/karma.conf.js'
},
continuous:{
configFile: 'test/karma.conf.js',
singleRun: true,
browsers: ['PhantomJS']
}
},
sass:{
dev: {
options:{
style: 'expanded',
compass: false
},
files:{
'app/css/app.css':'app/css/app.scss'
}
},
dist: {
options: {
style: 'compressed',
compass: false
},
files:{
'app/css/app.css':'app/css/app.scss'
}
}
},
watch: {
sass: {
files: 'app/css/**/{,*/}*.{scss,sass}',
tasks: ['sass:dev']
},
styles: {
files: ['app/css/app.css'],
tasks: ['autoprefixer']
},
// karma: {
// files: ['test/*.js',
// 'test/**/*.js'
// ],
// tasks: ['karma:unit:run']
// },
livereload:{
options: {livereload: true},
files: ['app/**/*'],
},
sync:{
files: ['app/**'],
tasks: ['sync:main']
}
},
concurrent:
{
target: {
tasks: [
'karma:unit',
'watch'
],
options: {
logConcurrentOutput: true
}
}
}
});
require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);
grunt.registerTask('default', [
'sass:dev',
'concurrent:target'
]
);
};
Currently receiving the following warning when I grunt
Warning: Task "sync:main" not found. Use --force to continue.
Aborted due to warnings.
Since there is only the main subtask, I thought that maybe changing the watch from executing ['sync:main'] to executing ['sync'] would possibly work. The warning goes away but poof nothing happens...so I'm not sure if the issue is with my config or with the module implementation.
Any ideas?
Edit to Add:
From the module's github site, I see the following in sync.json
{
"main": {
"files": [{
"src": ["**"],
"dest": "bin/to",
"cwd": "bin/from"
}]
}
}
so that would lead me to believe that "main" is the name I should be using for the sync subtask. I'm really confused as to why grunt isn't recognizing it in my config, but I am not too terribly familiar with dissecting the code for grunt modules.
Well...turns out I referenced a module in my gruntfile before I ran npm install on it and then decided to come on the internet to tell everybody about it.
Edit:
To partially exonerate myself, I found the console that I used to run npm install grunt-sync --save-dev. I had run it, but I was in the
wrong directory; it added it to the wrong gruntfile.
To answer my own question, the gruntfile packaged with the [grunt-sync] module contains a watch section, so you just have to have grunt-contrib-watch installed; you don't have to do anything special. And that makes sense. A folder synchronization task would be pretty darned worthless without a file system watch, so it is perfectly reasonable to run the task in a very broad watch but with an inherent blacklist (it watches all files in all folders but only operates on files matching a src pattern.
So to get it to syn-down all files on all file changes,
sync: {
main:{
files:[{
src:[
'**'
]
, dest: 'publish'
}
]
,verbose: true
}
},
will copy all files to the publish subdirectory. I run mine inside a concurrent task
concurrent:
{
target: {
tasks: [
'karma:unit',
'sync:main',
'watch'
],
options: {
logConcurrentOutput: true
}
}
}
Personally, I'll probably be swapping this out with grunt-rsync because grunt-sync simply performs the file copy task inside [sync:main] What I want it to do is to only send deltas to the publish folder every time I save a file; that's a task for rsync.