Skip to content
This repository has been archived by the owner on Jan 23, 2018. It is now read-only.

Commit

Permalink
chore(build): fix app reloading during auto-build
Browse files Browse the repository at this point in the history
  • Loading branch information
nikku committed May 22, 2015
1 parent 2c48e6b commit 8f2812c
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 37 deletions.
93 changes: 57 additions & 36 deletions Gruntfile.js
Expand Up @@ -2,18 +2,17 @@

var path = require('path');

var tmpDir = path.join(__dirname, 'tmp', 'chrome-user-dir');
var CHROME_START_OPTS = [
'--user-data-dir=tmp/chrome-user-dir',
'--no-default-browser-check',
'--no-first-run',
'--enable-apps-file-associations',
'--load-and-launch-app=dist',
'resources/simple.bpmn'
];

var CHROME_START_OPTS =
'--user-data-dir="' + tmpDir + '" ' +
'--no-default-browser-check ' +
'--no-first-run';


// configures browsers to run test against
// any of [ 'PhantomJS', 'Chrome', 'Firefox', 'IE']
var CHROME_BIN = (process.env.CHROME_BIN || 'chrome').replace(/^\s+|\s+$/, '');
var CHROME_OPEN = (process.env.CHROME_OPEN || CHROME_BIN + ' ' + CHROME_START_OPTS +' --load-and-launch-app="' + __dirname + '/dist" resources/simple.bpmn').replace(/^\s+|\s+$/, '');


module.exports = function (grunt) {
Expand All @@ -23,54 +22,58 @@ module.exports = function (grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),

config: {
dist: 'dist',
src: 'app',
less: 'app/less',
chrome_reload: CHROME_OPEN
},

watch: {
dist: {
files: [ '<%= config.dist %>/**/*' ],
files: [ 'dist/**/*' ],
tasks: [ 'open' ]
},

statics: {
files: [
'<%= config.src %>/**/*'
'app/icons/*',
'app/lib/index.html',
'app/manifest.json',
'app/main.js'
],
tasks: [ 'copy:statics' ]
},

less: {
files: [
'app/less/**/*'
],
tasks: [ 'less', 'copy:statics' ]
tasks: [ 'less' ]
}
},

copy: {
statics: {
files: [{
expand: true,
cwd: '<%= config.src %>',
dest: '<%= config.dist %>',
cwd: 'app',
dest: 'dist',
src: [
'icons/*',
'lib/index.html',
'*'
'manifest.json',
'main.js'
]
}]
},

font: {
files: [{
expand: true,
cwd: '<%= config.src %>/font/font',
dest: '<%= config.dist %>/font',
cwd: 'app/font/font',
dest: 'dist/font',
src: [ '*' ]
}]
},

diagram_js: {
files: [{
src: require.resolve('diagram-js/assets/diagram-js.css'),
dest: '<%= config.dist %>/vendor/diagram-js/diagram-js.css'
dest: 'dist/vendor/diagram-js/diagram-js.css'
}]
}
},
Expand All @@ -80,21 +83,17 @@ module.exports = function (grunt) {
app: {
options: {
cleancss: true,
paths: [ '<%= config.less %>', 'node_modules' ]
paths: [ 'app/less', 'node_modules' ]
},

files: {
'<%= config.dist %>/css/app.css': [
'<%= config.less %>/app.less'
'dist/css/app.css': [
'app/less/app.less'
]
}
}
},

exec: {
chrome_reload: '<%= config.chrome_reload %>'
},

browserify: {
options: {
browserifyOptions: {
Expand All @@ -112,23 +111,45 @@ module.exports = function (grunt) {
},
modeler: {
files: {
'<%= config.dist %>/lib/index.js': [ '<%= config.src %>/lib/index.js' ]
'dist/lib/index.js': [ 'app/lib/index.js' ]
}
},
watchModeler: {
options: {
watch: true
},
files: {
'<%= config.dist %>/lib/index.js': [ '<%= config.src %>/lib/index.js' ]
'dist/lib/index.js': [ 'app/lib/index.js' ]
}
}
}
});

grunt.registerTask('test', [ ]);
grunt.registerTask('open', function() {

grunt.registerTask('open', 'exec:chrome_reload');
var fs = require('fs');

var exec = require('child_process').exec;

// create temp dir for log files
try {
fs.mkdirSync('tmp');
} catch (e) {
// already exists? just chill
}

var options = {
detached: true,
stdio: [ 'ignore', fs.openSync('tmp/app.out', 'w'), fs.openSync('tmp/app.err', 'w') ]
};

var chrome = exec(CHROME_BIN + ' ' + CHROME_START_OPTS.join(' '), options);

// do not wait for child
chrome.unref();
});

grunt.registerTask('test', [ ]);

grunt.registerTask('build', [ 'copy', 'less', 'browserify:modeler' ]);

Expand Down
1 change: 0 additions & 1 deletion package.json
Expand Up @@ -17,7 +17,6 @@
"grunt-contrib-copy": "^0.5.0",
"grunt-contrib-less": "^1.0.0",
"grunt-contrib-watch": "^0.6.1",
"grunt-exec": "^0.4.6",
"load-grunt-tasks": "^0.4.0",
"stringify": "^3.1.0"
},
Expand Down

0 comments on commit 8f2812c

Please sign in to comment.