1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00
node-red/Gruntfile.js

442 lines
15 KiB
JavaScript
Raw Normal View History

2014-06-28 22:40:46 +02:00
/**
* Copyright 2013, 2016 IBM Corp.
2014-06-28 22:40:46 +02:00
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
2015-04-02 00:24:47 +02:00
var path = require("path");
2015-04-16 12:53:39 +02:00
2014-03-31 14:31:31 +02:00
module.exports = function(grunt) {
2015-04-16 12:53:39 +02:00
var nodemonArgs = ["-v"];
var flowFile = grunt.option('flowFile');
if (flowFile) {
nodemonArgs.push(flowFile);
}
2014-03-31 14:31:31 +02:00
grunt.initConfig({
2015-04-02 00:24:47 +02:00
pkg: grunt.file.readJSON('package.json'),
paths: {
dist: ".dist"
},
simplemocha: {
options: {
globals: ['expect'],
timeout: 3000,
ignoreLeaks: false,
ui: 'bdd',
reporter: 'spec'
},
all: { src: ['test/**/*_spec.js'] },
core: { src: ["test/_spec.js","test/red/**/*_spec.js"]},
nodes: { src: ["test/nodes/**/*_spec.js"]}
},
jshint: {
options: {
2015-04-16 12:53:39 +02:00
jshintrc:true
2015-04-02 00:24:47 +02:00
// http://www.jshint.com/docs/options/
2015-04-16 12:53:39 +02:00
//"asi": true, // allow missing semicolons
//"curly": true, // require braces
//"eqnull": true, // ignore ==null
//"forin": true, // require property filtering in "for in" loops
//"immed": true, // require immediate functions to be wrapped in ( )
//"nonbsp": true, // warn on unexpected whitespace breaking chars
////"strict": true, // commented out for now as it causes 100s of warnings, but want to get there eventually
//"loopfunc": true, // allow functions to be defined in loops
//"sub": true // don't warn that foo['bar'] should be written as foo.bar
2015-04-02 00:24:47 +02:00
},
all: [
'Gruntfile.js',
'red.js',
'red/**/*.js',
'nodes/core/*/*.js',
2015-04-02 00:24:47 +02:00
'editor/js/**/*.js'
],
core: {
files: {
src: [
'Gruntfile.js',
'red.js',
'red/**/*.js'
]
}
},
nodes: {
files: {
src: [ 'nodes/core/*/*.js' ]
2015-04-02 00:24:47 +02:00
}
},
editor: {
files: {
src: [ 'editor/js/**/*.js' ]
}
},
tests: {
files: {
src: ['test/**/*.js']
2014-03-31 14:31:31 +02:00
},
2015-04-02 00:24:47 +02:00
options: {
2016-05-18 12:11:59 +02:00
"expr": true
2015-04-02 00:24:47 +02:00
}
}
},
concat: {
options: {
separator: ";",
2014-06-28 22:40:46 +02:00
},
2015-04-02 00:24:47 +02:00
build: {
2016-05-18 12:11:59 +02:00
src: [
// Ensure editor source files are concatenated in
// the right order
"editor/js/main.js",
"editor/js/events.js",
"editor/js/i18n.js",
"editor/js/settings.js",
"editor/js/user.js",
"editor/js/comms.js",
Rework bidi file structure Closes #1026,#983,#982,#978 PR #1026 contains the full history of the changes made herein. Due to the volume of commits with no meaningful comment, they have been squashed down to this one. Adding bidi Files Tuning code style Adding rest of bidi files and its dependencies Tuning code style editing numeric shaping value Tuning Code style adding bidi support Adding Bidi Support for the rest of files Adding Bidi support Editing Bidi menu adding mirroring enablement handeling code style Addinng Bidi Support Adding Bidi Support Adding locale settings to national calendar support Adding Numeric Shaping Support scss files after adding rtl direction part 1 adding rtl direction at scss files part2 adding right directionality at comman typeInput correcting some comments editing spaces applying code style editing code style editing code style editing code style editing code style adding right directionality adding right directionality adding style in case of right directionality adding style in case of right directionality adding style in case of right directionality create a global variable for ui direction to call it once need Update main.js Update typedInput.js Update 10-switch.html manage palette mirroring adding RTL directionality to Tabs and Manage palette Style Editing Adding mirroring to subflow workspace handle mirroring defects at manage palette Handle Mirroring defects at sidebar seperator Numeric Shaping Updates Editing code style Handling mirroring defects Handling mirroring defects Fixing mirroring defects editing code style fixing mirroring defects at deploy dialog editing code style Updating Bidi Support handling some reviewing comments handling chicks Update base-text-dir.js Update bidi-util.js Update bidi-util.js Handling reviewing comment Fixing Popover mirroring defect Handling namespace structure for bidi features reflecting new namespace structure for bidi features at editorfiles Handling comments that related to css moving bidi.js under js/bidi folder
2016-10-18 11:26:51 +02:00
"editor/js/bidi/bidi.js",
"editor/js/bidi/base-text-dir.js",
"editor/js/bidi/format.js",
"editor/js/bidi/numeric-shaping.js",
2016-05-18 12:11:59 +02:00
"editor/js/ui/state.js",
"editor/js/nodes.js",
"editor/js/history.js",
"editor/js/validators.js",
"editor/js/ui/common/editableList.js",
"editor/js/ui/common/menu.js",
"editor/js/ui/common/popover.js",
"editor/js/ui/common/searchBox.js",
"editor/js/ui/common/tabs.js",
"editor/js/ui/common/typedInput.js",
2016-05-18 12:11:59 +02:00
"editor/js/ui/deploy.js",
"editor/js/ui/keyboard.js",
"editor/js/ui/workspaces.js",
"editor/js/ui/view.js",
"editor/js/ui/sidebar.js",
"editor/js/ui/palette.js",
"editor/js/ui/tab-info.js",
"editor/js/ui/tab-config.js",
2016-08-04 17:49:36 +02:00
"editor/js/ui/palette-editor.js",
2016-05-18 12:11:59 +02:00
"editor/js/ui/editor.js",
"editor/js/ui/tray.js",
"editor/js/ui/clipboard.js",
"editor/js/ui/library.js",
"editor/js/ui/notifications.js",
2016-09-30 00:46:29 +02:00
"editor/js/ui/search.js",
2016-05-18 12:11:59 +02:00
"editor/js/ui/subflow.js",
"editor/js/ui/touch/radialMenu.js"
2016-05-18 12:11:59 +02:00
],
dest: "public/red/red.js"
},
vendor: {
files: {
"public/vendor/vendor.js": [
2016-01-08 15:41:37 +01:00
"editor/vendor/jquery/js/jquery-1.11.3.min.js",
"editor/vendor/bootstrap/js/bootstrap.min.js",
"editor/vendor/jquery/js/jquery-ui-1.10.3.custom.min.js",
"editor/vendor/jquery/js/jquery.ui.touch-punch.min.js",
"editor/vendor/marked/marked.min.js",
2015-04-15 21:59:39 +02:00
"editor/vendor/d3/d3.v3.min.js",
"editor/vendor/i18next/i18next.min.js"
],
"public/vendor/vendor.css": [
// TODO: resolve relative resource paths in
// bootstrap/FA/jquery
]
}
2015-04-02 00:24:47 +02:00
}
},
uglify: {
build: {
files: {
'public/red/red.min.js': 'public/red/red.js'
}
}
},
sass: {
build: {
2014-06-28 22:40:46 +02:00
options: {
2015-04-02 00:24:47 +02:00
outputStyle: 'compressed'
2014-06-28 22:40:46 +02:00
},
2015-04-02 00:24:47 +02:00
files: [{
dest: 'public/red/style.min.css',
src: 'editor/sass/style.scss'
2015-07-13 12:26:29 +02:00
},
{
dest: 'public/vendor/bootstrap/css/bootstrap.min.css',
src: 'editor/vendor/bootstrap/css/bootstrap.css'
2015-04-02 00:24:47 +02:00
}]
}
},
2015-05-28 16:28:17 +02:00
jsonlint: {
messages: {
src: [
'nodes/core/locales/en-US/messages.json',
'red/api/locales/en-US/editor.json',
'red/runtime/locales/en-US/runtime.json'
2015-05-28 16:28:17 +02:00
]
}
},
attachCopyright: {
js: {
src: [
'public/red/red.min.js'
]
},
css: {
src: [
'public/red/style.min.css'
]
}
},
2015-04-02 00:24:47 +02:00
clean: {
build: {
src: [
"public/red",
"public/index.html",
"public/favicon.ico",
"public/icons",
"public/vendor"
]
},
release: {
src: [
'<%= paths.dist %>'
]
}
},
watch: {
js: {
files: [
'editor/js/**/*.js'
2014-06-28 22:40:46 +02:00
],
tasks: ['concat','uglify','attachCopyright:js']
2015-04-02 00:24:47 +02:00
},
sass: {
files: [
'editor/sass/**/*.scss'
],
tasks: ['sass','attachCopyright:css']
2015-05-28 16:28:17 +02:00
},
json: {
files: [
'nodes/core/locales/en-US/messages.json',
'red/api/locales/en-US/editor.json',
'red/runtime/locales/en-US/runtime.json'
2015-05-28 16:28:17 +02:00
],
tasks: ['jsonlint:messages']
},
misc: {
files: [
'CHANGELOG.md'
],
tasks: ['copy:build']
2015-04-02 00:24:47 +02:00
}
},
2015-04-16 12:53:39 +02:00
2015-04-02 00:24:47 +02:00
nodemon: {
/* uses .nodemonignore */
dev: {
script: 'red.js',
options: {
args: nodemonArgs,
2015-05-28 16:28:17 +02:00
ext: 'js,html,json',
2015-04-09 23:18:37 +02:00
watch: [
'red','nodes'
2015-04-09 23:18:37 +02:00
]
2015-04-02 00:24:47 +02:00
}
}
},
2015-04-16 12:53:39 +02:00
2015-04-02 00:24:47 +02:00
concurrent: {
dev: {
tasks: ['nodemon', 'watch'],
options: {
logConcurrentOutput: true
}
}
},
2015-04-16 12:53:39 +02:00
2015-04-02 00:24:47 +02:00
copy: {
build: {
files:[{
cwd: 'editor/images',
src: '**',
expand: true,
dest: 'public/red/images/'
2014-07-02 00:46:25 +02:00
},
2015-04-02 00:24:47 +02:00
{
cwd: 'editor/vendor',
src: [
'ace/**',
2015-07-13 12:26:29 +02:00
//'bootstrap/css/**',
'bootstrap/img/**',
'jquery/css/**',
'font-awesome/**'
],
2015-04-02 00:24:47 +02:00
expand: true,
dest: 'public/vendor/'
2014-07-02 00:46:25 +02:00
},
2015-04-02 00:24:47 +02:00
{
cwd: 'editor/icons',
src: '**',
expand: true,
dest: 'public/icons/'
2014-07-02 00:46:25 +02:00
},
2015-04-02 00:24:47 +02:00
{
expand: true,
src: ['editor/index.html','editor/favicon.ico'],
dest: 'public/',
flatten: true
},
{
src: 'CHANGELOG.md',
dest: 'public/red/about'
}
]
2015-04-02 00:24:47 +02:00
},
release: {
files: [{
mode: true,
2015-04-02 00:24:47 +02:00
expand: true,
src: [
'*.md',
'LICENSE',
'package.json',
'settings.js',
'red.js',
'lib/.gitignore',
'nodes/*.demo',
'nodes/core/**',
'red/**',
'public/**',
2015-06-17 00:39:33 +02:00
'editor/templates/**',
'bin/**'
2015-04-02 00:24:47 +02:00
],
dest: path.resolve('<%= paths.dist %>/node-red-<%= pkg.version %>')
}]
}
},
chmod: {
options: {
mode: '755'
},
release: {
// Target-specific file/dir lists and/or options go here.
src: [
path.resolve('<%= paths.dist %>/node-red-<%= pkg.version %>/nodes/core/hardware/nrgpio*')
]
}
},
2015-04-02 00:24:47 +02:00
compress: {
release: {
options: {
archive: '<%= paths.dist %>/node-red-<%= pkg.version %>.zip'
},
expand: true,
cwd: '<%= paths.dist %>/',
src: ['node-red-<%= pkg.version %>/**']
2014-03-31 14:31:31 +02:00
}
2015-04-02 00:24:47 +02:00
}
2014-03-31 14:31:31 +02:00
});
2015-04-16 12:53:39 +02:00
2014-03-31 14:31:31 +02:00
grunt.loadNpmTasks('grunt-simple-mocha');
2014-06-28 22:40:46 +02:00
grunt.loadNpmTasks('grunt-contrib-jshint');
2015-04-02 00:24:47 +02:00
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-concurrent');
grunt.loadNpmTasks('grunt-sass');
grunt.loadNpmTasks('grunt-nodemon');
grunt.loadNpmTasks('grunt-contrib-compress');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-chmod');
2015-05-28 16:28:17 +02:00
grunt.loadNpmTasks('grunt-jsonlint');
grunt.registerMultiTask('attachCopyright', function() {
var files = this.data.src;
var copyright = "/**\n"+
" * Copyright 2013, 2015 IBM Corp.\n"+
" *\n"+
" * Licensed under the Apache License, Version 2.0 (the \"License\");\n"+
" * you may not use this file except in compliance with the License.\n"+
" * You may obtain a copy of the License at\n"+
" *\n"+
" * http://www.apache.org/licenses/LICENSE-2.0\n"+
" *\n"+
" * Unless required by applicable law or agreed to in writing, software\n"+
" * distributed under the License is distributed on an \"AS IS\" BASIS,\n"+
" * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n"+
" * See the License for the specific language governing permissions and\n"+
" * limitations under the License.\n"+
" **/\n";
2015-04-16 12:53:39 +02:00
if (files) {
for (var i=0;i<files.length;i++) {
var file = files[i];
if (!grunt.file.exists(file)) {
grunt.log.warn('File '+ file + ' not found');
return false;
} else {
var content = grunt.file.read(file);
if (content.indexOf(copyright) == -1) {
content = copyright+content;
if (!grunt.file.write(file, content)) {
return false;
}
grunt.log.writeln("Attached copyright to "+file);
} else {
grunt.log.writeln("Copyright already on "+file);
}
}
}
}
});
grunt.registerTask('setDevEnv',
'Sets NODE_ENV=development so non-minified assets are used',
function () {
process.env.NODE_ENV = 'development';
});
2015-04-02 00:24:47 +02:00
grunt.registerTask('default',
'Builds editor content then runs code style checks and unit tests on all components',
['build','test-core','test-editor','test-nodes']);
2015-04-16 12:53:39 +02:00
2015-04-02 00:24:47 +02:00
grunt.registerTask('test-core',
'Runs code style check and unit tests on core runtime code',
['jshint:core','simplemocha:core']);
2015-04-16 12:53:39 +02:00
2015-04-02 00:24:47 +02:00
grunt.registerTask('test-editor',
'Runs code style check on editor code',
['jshint:editor']);
2015-04-16 12:53:39 +02:00
2015-04-02 00:24:47 +02:00
grunt.registerTask('test-nodes',
'Runs unit tests on core nodes',
['simplemocha:nodes']);
2015-04-16 12:53:39 +02:00
2015-04-02 00:24:47 +02:00
grunt.registerTask('build',
'Builds editor content',
2015-05-28 16:28:17 +02:00
['clean:build','concat:build','concat:vendor','uglify:build','sass:build','jsonlint:messages','copy:build','attachCopyright']);
2015-04-16 12:53:39 +02:00
2015-04-02 00:24:47 +02:00
grunt.registerTask('dev',
'Developer mode: run node-red, watch for source changes and build/restart',
['build','setDevEnv','concurrent:dev']);
2015-04-16 12:53:39 +02:00
2015-04-02 00:24:47 +02:00
grunt.registerTask('release',
'Create distribution zip file',
['build','clean:release','copy:release','chmod:release','compress:release']);
2015-04-02 00:24:47 +02:00
2014-03-31 14:31:31 +02:00
};