Example #1
0
module.exports = function(grunt) {
    var transport = require('grunt-cmd-transport');
    var style = transport.style.init(grunt);
    var text = transport.text.init(grunt);
    var script = transport.script.init(grunt);
    grunt.initConfig({
        pkg : grunt.file.readJSON("package.json"),
        transport: {
            options : {
                alias: '<%= pkg.spm.alias %>',
                idleading : '/resource/dist/js/', //路径即id
                parsers : {
                    '.js' : [script.jsParser],
                    '.css' : [style.css2jsParser],
                    '.html' : [text.html2jsParser]
                }
            },
            target : {
                files : [
                    {
                        expand: true, 
                        cwd: 'resource/dev/js',
                        src: ['index.js', 'mod.js','ox.js'],
                        dest: 'resource/.build/js'
                    }
                ]
            }
        },
        concat: {
            options: {
                include: 'relative'
            },
            target: {
                expand: true,
                cwd: 'resource/.build/js',
                src: ['*.js'],
                dest: 'resource/dist/js'
            }
        },
        clean: {
            build: ['resource/.build']
        }
    });
    
    grunt.loadNpmTasks('grunt-cmd-transport')
    grunt.loadNpmTasks('grunt-cmd-concat')
    grunt.loadNpmTasks('grunt-contrib-clean')

    grunt.registerTask('build', ['transport', 'concat', 'clean'])
}
Example #2
0
// transport:spm
function transportConfig(buildConfig) {
    var transport = require('grunt-cmd-transport');
    var script = transport.script.init(grunt);
    var style = transport.style.init(grunt);
    var text = transport.text.init(grunt);
    var template = transport.template.init(grunt);

    return {
        options : {
            idleading : buildConfig.family + '/',
            paths : [buildConfig.outputDir],
            alias : buildConfig.alias || {},
            parsers : {
                '.js' : [script.jsParser ],
                '.css' : [style.css2jsParser],
                '.html' : [text.html2jsParser],
                '.handlebars' : [template.handlebarsParser]
            },
            handlebars : {
                id : buildConfig.alias.handlebars || 'handlebars',
                knownHelpers : [],
                knownHelpersOnly : false
            }
        },
        files : [
            {
                cwd : buildConfig.src,
                src : '**/*',
                filter : function (filepath) {
                    // exclude outputDir dir
                    return grunt.file.isFile(filepath) && !grunt.file.doesPathContain(buildConfig.outputDir, filepath);
                },
                dest : '.build/src'
            }
        ]
    };
}
Example #3
0
module.exports = function(grunt) {
    var transport = require('grunt-cmd-transport');
    var style = transport.style.init(grunt);
    var text = transport.text.init(grunt);
    var script = transport.script.init(grunt);

    grunt.initConfig({
        pkg: grunt.file.readJSON('package.json'),

        transport: {
            options: {
                paths:['src'],
                alias: '<%= pkg.spm.alias %>',
                parsers:{
                    '.js' : [script.jsParser],
                    '.tpl' : [text.html2jsParser]
                }
            },
            component: {
                options: {
                    idleading: 'component/'
                },
                files: [{
                    expand: true,
                    cwd: 'src/component/',
                    src: ['**/*.js'],
                    dest: '_build/component/'
                }]
            },
            js: {
                options: {
                    idleading: 'js/'
                },
                files: [{
                    expand: true,
                    cwd: 'src/js/',
                    src: '**/*.js',
                    dest: '_build/js/'
                }]
            },
            tpl: {
                options: {
                    idleading: 'tpl/'
                },
                files: [{
                    expand: true,
                    cwd: 'src/tpl/',
                    src: '**/*.tpl',
                    dest: '_build/tpl/'
                }]
            }
        },
        concat: {
            js: {
                options: {
                    include: 'relative'
                },
                files: [{
                    expand: true,
                    cwd: '_build/js/',
                    src: ['**/*.js'],
                    dest: 'dist/js/',
                    ext: '.js'
                }]
            },
            tpl: {
                options: {
                    include: 'relative'
                },
                files: [{
                    expand: true,
                    cwd: '_build/tpl/',
                    src: ['**/*.tpl.js'],
                    dest: 'dist/tpl/'
                }]
            }
        },
        copy:{
            component: {
                files: [{
                    expand: true,
                    cwd: '_build/component/',
                    src: ['**/*.js'],
                    dest: 'dist/component/',
                    ext: '.js'
                }]
            },
            main: {
                files: [
                    {
                        expand: true, // Enable dynamic expansion
                        cwd: 'src/', // Src matches are relative to this path
                        src: ['gallery/**/*.*','seajs/**/*.*'], // Actual patterns to match
                        dest: 'dist/', // Destination path prefix
                        filter: "isFile"
                    }
                ]
            }
        },
        uglify: {
            main: {
                expand: true,
                cwd: 'dist',
                src: ['**/*.js', '!**/*-debug.js'],
                dest: 'dist'
            }
        },
        cssmin: {
            gallery: {
                expand: true,
                cwd: 'dist',
                src: ['gallery/**/*.css'],
                dest: 'dist'
            },
            component: {
                expand: true,
                cwd: 'src',
                src: ['component/**/*.css'],
                dest: 'dist'
            },
            app: {
                files: {
                    'dist/css/app/app.css': [
                        'src/css/reset.css',
                        'src/css/module/*.css'
                    ]
                }
            }
        },
        imagemin: {
            component: { // Another target
                files: [{
                    expand: true, // Enable dynamic expansion
                    cwd: 'src/component/', // Src matches are relative to this path
                    src: ['**/*.{jpg,png,gif}'], // Actual patterns to match
                    dest: 'dist/component/', // Destination path prefix
                    filter: "isFile"
                }]
            },
            main: { // Another target
                files: [{
                    expand: true, // Enable dynamic expansion
                    cwd: 'src/images/', // Src matches are relative to this path
                    src: ['**/*.{jpg,png,gif}'], // Actual patterns to match
                    dest: 'dist/images/', // Destination path prefix
                    filter: "isFile"
                }]
            }
        },
        clean: {
            "beforeBuild": ['dist'], //构建之前先删除旧版文件
            "build": ['_build'], //transport临时目录
            "noDebugJS": ['dist/**/*-debug.js','dist/**/*-debug.tpl.js'] //删除debug文件
        }
    });

    grunt.loadNpmTasks('grunt-cmd-transport');
    grunt.loadNpmTasks('grunt-cmd-concat');
    grunt.loadNpmTasks('grunt-contrib-uglify');
    grunt.loadNpmTasks('grunt-contrib-clean');
    grunt.loadNpmTasks('grunt-contrib-cssmin');
    grunt.loadNpmTasks('grunt-contrib-imagemin');
    grunt.loadNpmTasks('grunt-contrib-copy');

    grunt.registerTask('default', ['clean:build', 'clean:noDebugJS']);
    grunt.registerTask('build-img', ['imagemin']);
    grunt.registerTask('build-css', ['cssmin']);
    grunt.registerTask('build-js', ['uglify']);
    grunt.registerTask('build-copy', ['copy']);
    grunt.registerTask('build-trans', ['clean:build','transport']);
    grunt.registerTask('build', ['clean:beforeBuild', 'transport','concat', 'copy','uglify', 'cssmin', 'imagemin','clean:build','clean:noDebugJS']);
};
Example #4
0
module.exports = function(grunt) {

    var transport = require('grunt-cmd-transport');
    var style = transport.style.init(grunt);
    var text = transport.text.init(grunt);
    var script = transport.script.init(grunt);

    grunt.initConfig({
        pkg: grunt.file.readJSON('package.json'),

        transport: {
            options:{
                idleading:'/script/compress/',
                alias:'<%= pkg.spm.alias%>',
                parsers : {
                    '.js' : [script.jsParser],
                    '.css' : [style.css2jsParser],
                    '.html' : [text.html2jsParser]
                }
            },
            build: {
                files : [
                    {
                        expand:true,
                        cwd:'script/src/',
                        src : ['**/*.js','**/*.css'],
                        dest : 'script/build/'
                    }
                ]
            }
        },
        concat: {
            options:{
                include:'relative'
            },
            merge: {
                files: [
                    {
                        expand: true,
                        cwd: 'script/build/',
                        src: ['**/*.js','!**/*-debug.js','!**/*-debug.css.js'],
                        dest: 'script/merge/'
                    }
                ]
            }
        },
        uglify: {
            compress: {
                files: [
                    {
                        expand: true,
                        cwd: 'script/merge/',
                        src: ['*/*.js','!mod/*.js'],
                        dest: 'script/compress/',
                        ext: '.js'
                    }
                ]
            }
        },
        clean : ['script/build','script/merge'],
        watch: {
            script:{
                files:['script/src/*/*.js','script/src/*/*css'],
                tasks:['transport','concat','uglify','clean']
            }
        },

        compass: {// compass
            src: {// Another target
                options: {
                    sassDir: 'style/sass',
                    cssDir: 'style/src',
                    outputStyle: 'expanded',
                    debugInfo: true
                },
                files: [
                    {
                        expand: true,
                        cwd: 'style/sass',
                        src: ['***/*//*.scss', '!*//*mod*//***/*//*.scss'],
                        dest: 'style/src',
                        ext: '.css'
                    }
                ]
            },
            dist: {// Target
                options: {// Target options
                    sassDir: 'style/sass',
                    cssDir: 'style/compress',
                    imageDir: 'image/src/',
                    environment: 'production',
                    debugInfo:false
                },
                files: [
                    {
                        expand: true,
                        cwd: 'style/sass',
                        src: ['**/*.scss', '!*/mod/**/*.scss'],
                        dest: 'style/compress',
                        ext: '.css'
                    }
                ]
            }
        }
    });

    grunt.loadNpmTasks('grunt-cmd-transport');
    grunt.loadNpmTasks('grunt-cmd-concat');
    grunt.loadNpmTasks('grunt-contrib-uglify');
    grunt.loadNpmTasks('grunt-contrib-clean');
    grunt.loadNpmTasks('grunt-contrib-watch');

    grunt.registerTask('js', function(){
        grunt.task.run('transport');
        grunt.task.run('concat');
        grunt.task.run('uglify');
        grunt.task.run('clean');
    });


    grunt.loadNpmTasks('grunt-contrib-compass');

    grunt.registerTask('css', ['compass']);
};
Example #5
0
module.exports = function(grunt) {
	var transport = require('grunt-cmd-transport');
	var style = transport.style.init(grunt);
	var text = transport.text.init(grunt);
	var script = transport.script.init(grunt);

	grunt.initConfig({
		pkg : grunt.file.readJSON("package.json"),

		transport : {
			options : {
				paths : [ '.' ],
				alias : '<%= pkg.spm.alias %>'
			},
			common : {
				options : {
					idleading : 'common/'
				},

				files : [ {
					cwd : 'common',
					src : '**/*',
					filter : 'isFile',
					dest : '.build/dist/common'
				} ]
			},
			jplugin : {
				options : {
					idleading : 'jplugin/'
				},

				files : [ {
					cwd : 'jplugin',
					src : '**/*',
					filter : 'isFile',
					dest : '.build/dist/jplugin'
				} ]
			},
			source : {
				options : {
					idleading : 'source/'// 模块化组合时的前缀,默认是 family/name/version
				},

				files : [ {
					cwd : 'source',
					src : '**/*',
					filter : 'isFile',
					dest : '.build/dist/source'
				} ]
			}
		},

		uglify : {
			common : {
				options : {
					banner : '/*! <%= pkg.author %> | <%= pkg.version %>*/',
					beautify : {
						ascii_only : true
					}
				},
				files : [ {
					expand : true,
					cwd : '.build/dist/',
					src : [ 'common/*.js', '!common/*-debug.js' ],
					dest : '../<%= pkg.version %>/',
					ext : '.js'
				} ]
			},
			jplugin : {
				options : {
					banner : '/*! <%= pkg.author %> | <%= pkg.version %>*/',
					beautify : {
						ascii_only : true
					}
				},
				files : [ {
					expand : true,
					cwd : '.build/dist/',
					src : [ 'jplugin/**/*.js', '!jplugin/**/*-debug.js' ],
					dest : '../<%= pkg.version %>/',
					filter : 'isFile',
					ext : '.js'
				} ]
			},
			source : {
				options : {
					banner : '/*! <%= pkg.author %> | <%= pkg.version %>*/',
					beautify : {
						ascii_only : true
					}
				},
				files : [ {
					expand : true,
					cwd : '.build/dist/',
					src : [ 'source/**/*.js', '!source/**/*-debug.js' ],
					dest : '../<%= pkg.version %>/',
					ext : '.js'
				} ]
			},
			seajs : {
				options : {
					banner : '/*! <%= pkg.author %> | <%= pkg.version %>*/',
					beautify : {
						ascii_only : true
					}
				},
				files : [ {
					expand : true,
					src : [ '../<%= pkg.version %>/sea.js' ],
					dest : '../<%= pkg.version %>/',
					ext : '.js'
				} ]
			}
		},

		copy : {
			base : {
				files : [ {
					expand : true,
					src : [ 'sea.js' ],
					dest : '../<%= pkg.version %>/'
				} ]
			}
		},

		clean : {
			build : [ '.build' ]
		}
	});

	grunt.loadNpmTasks('grunt-cmd-transport');
	grunt.loadNpmTasks('grunt-cmd-concat');
	grunt.loadNpmTasks('grunt-contrib-clean');
	grunt.loadNpmTasks('grunt-contrib-uglify');
	grunt.loadNpmTasks('grunt-contrib-copy');

	grunt.registerTask('default', [ 'transport:common', 'transport:jplugin',
			'transport:source', 'uglify:common', 'uglify:jplugin',
			'uglify:source', 'copy:base', 'uglify:seajs', 'clean' ]);
};
Example #6
0
module.exports = function(grunt) {
    // load all grunt tasks
    require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);
    var transport = require('grunt-cmd-transport');
    var style = transport.style.init(grunt);
    var text = transport.text.init(grunt);
    var script = transport.script.init(grunt);
    var template = transport.template.init(grunt);
    // configurable paths
    var yeomanConfig = {
        app: 'js/app',
        css: 'css',
        sea: 'sea-modules',
        dist: 'dist'
    };
    grunt.initConfig({
        pkg: grunt.file.readJSON('package.json'),
        yeoman: yeomanConfig,
        jshint: {
            options: {
                // read jshint options from jshintrc file
                "jshintrc": ".jshintrc"
            },
            app: ['<%= yeoman.app %>/**/*.js']
        },

        open: {
            server: {
                url: 'http://localhost:<%= cfg.server.port %>'
            }
        },

        yuidoc: {
            compile: {
                name: '<%= pkg.name %>',
                description: '<%= pkg.description %>',
                version: '<%= pkg.version %>',
                options: {
                    paths: '<%= yeoman.app %>/',
                    outdir: './doc'
                }
            }
        },

        transport: {
            options: {
                paths: ['<%= yeoman.sea %>'],
                /*handlebars: {
                 id: 'handlebars'
                 },*/
                parsers: {
                    '.js' : [script.jsParser],
                    '.css' : [style.css2jsParser],
                    '.html' : [text.html2jsParser],
                    '.handlebars': [template.handlebarsParser]
                },
                alias: '<%= pkg.spm.alias %>'
            },

            app: {
                options: {
                    idleading: 'app/'
                },

                files: [
                    {
                        expand: true,
                        cwd: '<%= yeoman.app %>/',
                        src: ['**/*', '!**/package.json'],
                        filter: 'isFile',
                        dest: '.build/app'
                    }
                ]
            }
        },
        concat: {
            options: {
                paths: ['<%= yeoman.sea %>'],
                include: 'all'
            },
            app: {
                options: {
                    // 不能用 style.css2js ,不然打包失败
                    // https://github.com/spmjs/grunt-cmd-concat/issues/32
                    css2js: transport.style.css2js
                },
                files: [
                    {
                        expand: true,
                        cwd: '.build/',
                        src: ['app/**/*.js'],
                        dest: '<%= yeoman.dist %>/',
                        ext: '.js'
                    }
                ]
            }
        },
        watch: {
            app: {
                files: ["<%= yeoman.app %>/{,*/}*.js"],
                tasks: ["jshint"],
                options: {
                    nospawn: true,
                    interrupt: false,
                    debounceDelay: 100
                }
            }
        },

        uglify: {
            app: {
                files: [
                    {
                        expand: true,
                        cwd: '<%= yeoman.dist %>/',
                        src: ['app/**/*.js', '!app/**/*-debug.js'],
                        dest: '<%= yeoman.dist %>/',
                        ext: '.js'
                    }
                ]
            }
        },
        clean: {
            build: ['.build']
        },
        fed: {
            server: {
                config: 'fed.json'
            }
        },
        qunit: {
            all: ['test/index.html']
        }
    });

    grunt.registerTask('default', ['fed']);
    grunt.registerTask('server', ['fed']);
    grunt.registerTask('build', [/*'jshint',*/, 'transport', 'concat', 'uglify','clean']);

};
Example #7
0
module.exports = function(grunt) {
	var transport = require('grunt-cmd-transport');
	var style = transport.style.init(grunt);
	var text = transport.text.init(grunt);
	var script = transport.script.init(grunt);

	grunt.initConfig({
		pkg: grunt.file.readJSON("package.json"),

		transport: {
			options: {
				paths: ['.'],
				alias: '<%= pkg.spm.alias %>'
			},
			common: {
				options: {
					idleading: ''
				},

				files: [{
					cwd: 'template/scripts/',
					src: '**/*',
					filter: 'isFile',
					dest: '.build/dist/common'
				}]
			}
		},

		uglify: {
			common: {
				options: {
					banner: '/*! <%= pkg.author %> | <%= pkg.version %>*/',
					beautify: {
						ascii_only: true
					}
				},
				files: [{
					expand: true,
					cwd: 'template/scripts',
					src: ['**/**.js','!*-debug.js','!mobiscroll*.js'],
					dest: 'template/min',
					ext: '.min.js'
				}]
			},
			mobiscroll: {
				options: {
					banner: '/*! <%= pkg.author %> | <%= pkg.version %>*/',
					beautify: {
						ascii_only: true
					}
				},
				files: [{
					expand: true,
					cwd: 'template/scripts/lib/mobiscroll/js',
					src: ['mobiscroll.core.js','mobiscroll.datetime.js','mobiscroll.scroller.android-ics.js','mobiscroll.scroller.js','mobiscroll.zepto.js','mobiscroll.i18n.zh.js'],
					dest: 'template/min/lib/mobiscroll/js/',
					ext: '.min.js'
				}]
			}
		},

		copy: {
			base: {
				files: [{
					expand: true,
					src: ['sea.js'],
					dest: '../<%= pkg.version %>/'
				}, {
					expand: true,
					src: ['sconfig.js'],
					dest: '../<%= pkg.version %>/'
				}]
			}
		},
		cssmin: {
			combine: {
				options: {
					banner: '/* My minified css file */'
				},
				files: {
					'template/styles/base.css': ['template/styles/reset.css',
						'template/styles/app.css', 'template/styles/animation.css',
						'template/styles/units.css', 'template/styles/modules.css',
						'template/styles/page.css', 'template/scripts/lib/mobiscroll/css/mobiscroll.animation.css',
						'template/scripts/lib/mobiscroll/css/mobiscroll.scroller.android-ics.css', 'template/scripts/lib/mobiscroll/css/mobiscroll.scroller.css'
					]
				}
			},
			minify: {
				expand: true,
				cwd: 'template/styles/',
				src: ['base.css', '!*.min.css'],
				dest: 'template/styles/',
				ext: '.min.css'
			}
		},
		clean: {
			build: ['.build']
		}
	});

	grunt.loadNpmTasks('grunt-cmd-transport');
	grunt.loadNpmTasks('grunt-cmd-concat');
	grunt.loadNpmTasks('grunt-contrib-clean');
	grunt.loadNpmTasks('grunt-contrib-uglify');
	grunt.loadNpmTasks('grunt-contrib-copy');
	grunt.loadNpmTasks('grunt-contrib-cssmin');

	//	grunt.registerTask('default', [ 'transport:common','transport:jplugin',
	//	                                'transport:cp', 'transport:mp','uglify:common', 
	//	                                'uglify:jplugin','uglify:cp', 'uglify:mp',
	//	                                'copy:base','uglify:sconfig','clean' ]);
	//	grunt.registerTask('default', ['concat']);
	//grunt.registerTask('default', ['cssmin:combine', 'cssmin:minify']);
	grunt.registerTask('default', ['uglify:common','uglify:mobiscroll']);
};
Example #8
0
function distConfig(grunt, pkg) {

    if (!pkg.spm) {
        process.emit('log.warn', 'missing `spm` in package.json');
        process.emit('log.info', 'read the docs at http://docs.spmjs.org/en/package');
        pkg.spm = {};
    }

    var transport = require('grunt-cmd-transport');
    var style = transport.style.init(grunt);
    var text = transport.text.init(grunt);
    var script = transport.script.init(grunt);
    var template = transport.template.init(grunt);

    var output = pkg.spm.output || {};
    var alias = pkg.spm.alias || [];

    var jsconcats = {};
    var jsmins = [];
    var cssmins = [];
    var copies = [];

    var replaceCSSPic = initCSSPicReplace(grunt, pkg);

    if (Array.isArray(output)) {
        var ret = {};
        output.forEach(function (name) {
            ret[name] = [name];
        });
        output = ret;
    }

    Object.keys(output).forEach(function (name) {
        if (name.indexOf("*") === -1) {

            if (/\.css$/.test(name)) {
                cssmins.push({
                    dest: 'dist/' + name,
                    src: output[name].map(function (key) {
                        return '.build/dist/' + key;
                    })
                })

                name = name.replace(/\.css$/, '-debug.css');
                copies.push({
                    cwd: '.build/dist',
                    src: name,
                    expand: true,
                    dest: 'dist'
                });

            } else if (/\.js$/.test(name)) {
                jsconcats['.build/dist/' + name] = output[name].map(function (key) {
                    return '.build/src/' + key;
                });

                jsmins.push({
                    src: ['.build/dist/' + name],
                    dest: 'dist/' + name
                });

                jsconcats['dist/' + name.replace(/\.js$/, '-debug.js')] = output[name].map(function (key) {
                    return '.build/src/' + key.replace(/\.js$/, '-debug.js');
                });
            } else {
                copies.push({
                    cwd: '.build/src',
                    src: name,
                    expand: true,
                    dest: 'dist'
                });
            }

        } else {
            copies.push({
                cwd: '.build/src',
                src: name,
                filter: function (src) {
                    if (/-debug\.(js|css)$/.test(src)) {
                        return true;
                    };
                    if (/\.(js|css)$/.test(src)) {
                        return false;
                    }
                    return true;
                },
                expand: true,
                dest: 'dist'
            });

            jsmins.push({
                cwd: '.build/src',
                src: name,
                filter: function (src) {
                    if (/-debug.js$/.test(src)) {
                        return false;
                    };
                    if (/\.js$/.test(src)) {
                        return true;
                    }
                    return false;
                },
                expand: true,
                dest: 'dist'
            });

            cssmins.push({
                cwd: '.build/src',
                src: name,
                filter: function (src) {
                    if (/-debug.css$/.test(src)) {
                        return false;
                    };
                    if (/\.css$/.test(src)) {
                        return true;
                    }
                    return false;
                },
                expand: true,
                dest: 'dist'
            });
        }
    });

    // 本地环增执行 transport:hbs 是不需要生成具名模块的
    var clearHbsId = {'clear-hbs-id':{
            files: [{
                cwd: 'src',
                expand: true,
                src: '**/*.handlebars.js',
                filter: 'isFile',
                dest: 'src/'
            }],
            overwrite: true,
            replacements:[{
                from: /^define\((.+)function\(/,
                to:function(matchedWord, index, fullText, regexMatches){
                    return 'define(function(';
                }
            }]

        }
    };

    return {
        concat: {
            options: {
                paths: ["."],
                include: "relative",
                banner: '/*! <%= pkg.name %> <%= pkg.version %> pub <%= grunt.template.today("yyyy-mm-dd HH:MM")%> by <%= pkg.author.name %> */\n'
            },
            css: {
                files: [{
                    cwd: '.build/src/',
                    src: '**/*.css',
                    expand: true,
                    dest: '.build/dist'
                }]
            },
            spm: {
                files: jsconcats
            }
        },
        cssmin: {
            options: {
                banner: '/*! <%= pkg.name %> <%= pkg.version %> pub <%= grunt.template.today("yyyy-mm-dd HH:MM")%> by <%= pkg.author.name %> */\n',
                keepSpecialComments: 0
            },
            offer: {
                files: cssmins
            }
        },
        uglify: {
            js: {
                options: {
                    banner: '/*! <%= pkg.name %> <%= pkg.version %> pub <%= grunt.template.today("yyyy-mm-dd HH:MM")%> by <%= pkg.author.name %> */\n',
                    beautify: {
                        ascii_only: true
                    }
                },
                files: jsmins
            }
        },
        replace: Object.assign({}, replaceCSSPic, clearHbsId),
        copy: {
            spm: {
                files: copies
            }
        },
        clean: {
            spm: ['.build'],
            dist: ['dist']
        },
        transport: {
            options: {
                paths: ["."],
                alias: '<%= pkg.spm.alias %>',
                idleading: "<%=pkg.family%>/<%=pkg.name%>/<%=pkg.version%>/",
                debug: true,
                handlebars: {
                    id: 'handlebars'
                }
            },
            js: {
                files: [{
                    cwd: 'src',
                    src: '**/*',
                    expand: true,
                    filter: 'isFile',
                    dest: '.build/src'
                }]
            },
            css: {
                options: {
                    parsers: {
                        '.js': [script.jsParser],
                        '.css': [style.css2jsParser],
                        '.html': [text.html2jsParser],
                        '.handlebars': [template.handlebarsParser]
                    }
                },
                files: [{
                    cwd: '.build/dist',
                    src: '**/*.css',
                    filter: 'isFile',
                    expand: true,
                    dest: '.build/src'
                }]
            },
            hbs: {
                options: {
                    debug: false
                },
                files: [{
                    cwd: 'src',
                    expand: true,
                    src: '**/*.handlebars',
                    filter: 'isFile',
                    dest: 'src/'
                }]
            }
        }
    };
}
Example #9
0
module.exports = function(grunt) {

  var transport = require('grunt-cmd-transport');
  var style = transport.style.init(grunt);
  var text = transport.text.init(grunt);
  var script = transport.script.init(grunt);

  grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),
    transport : {
      options : {
        paths : ['.'],
        alias: '<%= pkg.spm.alias %>',
        parsers : {
            '.js'   : [script.jsParser],
            '.css'  : [style.css2jsParser],
            '.html' : [text.html2jsParser]
        }
      },
      styles : {
        options : {
            idleading : 'dist/styles/'
        },
        files : [
            {
                cwd : 'styles',
                src : '**/*',
                filter : 'isFile',
                dest : '.build/styles'
            }
        ]
      },
      app : {
          options : {
              idleading : 'dist/app/'
          },
          files : [
              {
                  cwd : 'app',
                  src : '**/*',
                  filter : 'isFile',
                  dest : '.build/app'
              }
          ]
      }
    }, 
    concat : {
      options : {
          paths : ['.'],
          include : 'relative'
      },
      styles : {
          files: [
              {
                  expand: true,
                  cwd: '.build/',
                  src: ['styles/**/*.js'],
                  dest: 'dist/',
                  ext: '.js'
              }
          ]
      },
      app : {
          options : {
              include : 'all'
          },
          files: [
              {
                  expand: true,
                  cwd: '.build/',
                  src: ['app/**/*.js'],
                  dest: 'dist/',
                  ext: '.js'
              }
          ]
      }
    },
    uglify : {
      styles : {
        files: [
            {
                expand: true,
                cwd: 'dist/',
                src: ['styles/**/*.js', '!styles/**/*-debug.js'],
                dest: 'dist/',
                ext: '.js'
            }
          ]
      },
      app : {
          files: [
              {
                  expand: true,
                  cwd: 'dist/',
                  src: ['app/**/*.js', '!app/**/*-debug.js'],
                  dest: 'dist/',
                  ext: '.js'
              }
          ]
      },
      seajs:{
        src :".build/sea-debug.js",
        dest:"dist/sea.js"
      }
    }
  });

  grunt.registerTask("merge-seajs-plugins", "merge the seajs plugins in package.json", function() {
    var plugins = grunt.config("pkg.spm.plugins")
    var seaCode = grunt.file.read("gallery/seajs/sea-debug.js");
    var codes = [seaCode];
    for(var i = 0, len = plugins.length; i < len; i++){
      (function(plug){
        codes.push(grunt.file.read("gallery/seajs/plugin-"+plug+".js"))
      })(plugins[i])
    }
    grunt.log.writeln("merge-seajs-plugins in running:" + plugins);
    grunt.file.write(".build/sea-debug.js", codes.join(";\r\n"));
  })
  
  grunt.loadNpmTasks('grunt-cmd-transport');
  grunt.loadNpmTasks('grunt-cmd-concat');
  grunt.loadNpmTasks('grunt-contrib-uglify');

  grunt.registerTask("build-styles", ['transport:styles','concat:styles','uglify:styles']);
  grunt.registerTask("build-app", ['transport:app','concat:app','uglify:app']);
  grunt.registerTask("build-seajs", ["merge-seajs-plugins", "uglify:seajs"]);

  grunt.registerTask("default", ["build-styles","build-app", "merge-seajs-plugins"])

}
Example #10
0
module.exports = function(grunt, cwd) {
	var path = require("path");

	var EXCLUDE_REG = /((\\|\/)(grunt-tasks|node_modules|sea-modules|build|dist|src)(\\|\/))|((\\|\/)(Gruntfile.js|package.json))/;

	var util = require("./util")(grunt);
	var pkgPath = path.resolve(cwd, "package.json");
	var pkg = require("./pkg")(grunt, pkgPath);
	var extend = require("extend");
	var baseConfig = require("./base-config");

	var transport = require('grunt-cmd-transport');
	var text = transport.text.init(grunt);
	var script = transport.script.init(grunt);
	var style = transport.style.init(grunt);
	var template = transport.template.init(grunt);

	var deployDir = process.env.AMKIT_DEPLOY_HOME || "../../assert/amkit2";

	return extend(baseConfig, {
		pkg: pkg,
		copy: {
			temp: {
				expand: true,
				cwd: path.join(cwd, "src"),
				src: '**/*',
				dest: path.join(cwd, '<%= pkg.version %>/')
			},
			deploy: {
				expand: true,
				cwd: path.join("sea-modules", cwd, '<%= pkg.version %>/'),
				//src: ['**/*', '!**/*-debug.*'],
				src: ['**/*'],
				dest: path.join(deployDir, "sea-modules", cwd, '<%= pkg.version %>/')
			}
		},
		clean: {
			target: [path.join("sea-modules", cwd, "<%= pkg.version %>")],
			temp: [path.join(cwd, "<%= pkg.version %>")],
			deploy: {
				options: {
					force: true
				},
				src: [path.join(deployDir, "sea-modules", cwd, "<%= pkg.version %>")]
			}
		},
		install: {
			target: {
				output: "."
			},
			deploy: {
				output: path.join(deployDir, "sea-modules")
			}
		},
		transport: {
			options: {
				alias: "<%= pkg.spm.alias %>",
				parsers: {
					'.js': [script.jsParser],
					'.css': [style.css2jsParser],
					'.html': [text.html2jsParser],
					'.tpl': [template.tplParser],
					'.handlebars': [template.handlebarsParser]
				}
			},
			target: {
				options: {
					idleading: cwd[cwd.length - 1] === "/" ? cwd : cwd + "/"
				},
				files: [{
					cwd: cwd,
					src: "**/*",
					filter: function(file) {
						var filePath = path.resolve(file);
						if (EXCLUDE_REG.test(filePath)) {
							return false;
						} else {
							if (grunt.file.isFile(filePath)) {
								util.log("config", "transport:", filePath);
								return true;
							} else {
								return false;
							}
						}
					},
					dest: path.join("sea-modules", cwd)
				}]
			}
		},
		concat: {
			options: {
				include: "relative"
			},
			target: {
				files: [{
					expand: true,
					cwd: path.join("sea-modules", cwd),
					src: "**/*.js",
					dest: path.join("sea-modules", cwd),
					ext: ".js"
				}]
			}
		},
		uglify: {
			target: {
				files: [{
					expand: true,
					cwd: path.join("sea-modules", cwd),
					src: ["**/*.js", "!**/*-debug.js"],
					dest: path.join("sea-modules", cwd),
					ext: '.js'
				}]
			}
		},
		cssmin: {
			options: {
				keepSpecialComments: 0
			},
			target: {
				files: [{
					expand: true,
					cwd: path.join("sea-modules", cwd),
					src: ["**/*.css", "!**/*-debug.css"],
					dest: path.join("sea-modules", cwd),
					ext: '.css'
				}]
			}
		}
	});
};
Example #11
0
module.exports = function (grunt) {
    var transport = require('grunt-cmd-transport');
    var style = transport.style.init(grunt);
    var text = transport.text.init(grunt);
    var script = transport.script.init(grunt);

    //http://www.jankerli.com/?p=1658
    //http://gruntjs.com/configuring-tasks#files
    grunt.initConfig({
        pkg:grunt.file.readJSON("package.json"),
        meta: {
            basePath: './'
        },
        transport:{/*解析*/
            options:{
                paths:['.'],
                alias: '<%= pkg.spm.alias %>',
                parsers:{
                    '.js':[script.jsParser],
                    '.css':[style.css2jsParser],
                    '.html':[text.html2jsParser]
                }
            },
            kod:{
                options:{
                    idleading:'app/'//前缀
                },
                files:[{
                    cwd:'_dev/',
                    src:'**/*.js',
                    filter:'isFile',
                    dest:'.build/'
                }]
            }
        },
        concat:{/*合并*/
            options:{
                 paths:['.'],
                 include:'relative'    
            },
            kod:{
                files: [{
                    expand: true,
                    cwd: '.build/',
                    src: ['**/*.js'],
                    dest: 'app/',//输出
                    ext: '.js'
                }]
            }
        },
        uglify:{/*压缩*/
            kod:{
                files: [{
                    expand: true,
                    cwd: 'app',
                    src: ['**/*.js','!**/*-debug.js'],
                    dest: 'app/',
                    ext: '.js'
                }]
            }
        },
        clean:{/*清除.build文件*/
            spm:['.build','app/common','app/tpl','app/**/*.js','!app/**/main.js']
            //spm:['.build']
        }
    });

    grunt.loadNpmTasks('grunt-cmd-transport');
    grunt.loadNpmTasks('grunt-cmd-concat');
    grunt.loadNpmTasks('grunt-contrib-clean');
    grunt.loadNpmTasks('grunt-contrib-uglify');
    grunt.registerTask('build', ['transport:kod', 'concat:kod', 'uglify:kod', 'clean']);
//    grunt.registerTask('default', ['clean']);
};
Example #12
0
module.exports = function (grunt) {
    require('time-grunt')(grunt); // exe time

    var path = require('path');
    var fs = require('fs');
    // 重新设置 grunt 的项目路径,获取当前的 package.json 文件信息
    grunt.file.setBase(__dirname);

    /**
     * 猜测根目录
     */
    function findRootDir() {
        var d = path.join(__dirname);
        var flag = true;
        while (flag) {
            var dir = fs.readdirSync(d).reduce(function (o, key) {
                o[key] = path.join(d, key);
                return o;
            }, {});
            if (dir['node_modules'] && dir['gruntfile.js'] && dir['package.json']) {
                flag = false;
            } else {
                d = path.join(d, '../');
            }
        }
        return d;
    }

    // 获取当前目录相对于共享 node_modules 目录的路径(以windows下面为例)
    var root = path.join(findRootDir());
    var nodepath = path.relative(__dirname, root + 'node_modules');

    var transport = require('grunt-cmd-transport');
    var style = transport.style.init(grunt);
    var text = transport.text.init(grunt);
    var script = transport.script.init(grunt);
    var pkg = grunt.file.readJSON(root + 'package.json');

    // 重新设置路径
    pkg.spm.dist = path.join(root.replace('tags', 'branches'), 'src' + path.sep).replace(/\\/g, '/');
    pkg.spm.src = path.join(root, 'src' + path.sep).replace(/\\/g, '/');

    var __newDirName = path.relative(pkg.spm.src, __dirname).replace(/\\/g, '/') + '/';

    var configMod = {
        pkg: pkg,
        transport: {
            options: {
                paths: [pkg.spm.dist],
                alias: pkg.spm.alias,
                parsers: {
                    '.js': [script.jsParser],
                    '.css': [style.css2jsParser],
                    '.html': [text.html2jsParser]
                },
                idleading: __newDirName
            },
            app: {
                files: [{
                    expand: true,
                    cwd: pkg.spm.src + __newDirName,
                    src: [
                        './**/*',
                        '!./gruntfile.js',
                        '!./**/*-debug.js',
                        '!./**/*-debug.css.js',
                        '!./**/*-debug.html.js',
                        '!./**/*.css.js',
                        '!./**/*.css.js',
                        '!./**/_*.js'
                    ],
                    extDot: 'last',
                    filter: 'isFile',
                    dest: pkg.spm.dist + '/.build/' + __newDirName
                }]
            }
        },
        concat: {
            options: {
                paths: [pkg.spm.dist],
                // 如果压缩插件include:relative,压缩项目为include: all
                include: 'all'
            },
            app: {
                files: [{
                    expand: true,
                    cwd: pkg.spm.dist + '/.build/' + __newDirName,
                    src: [
                        './**/*.js',
                        '!./gruntfile.js',
                        '!./**/*-debug.js',
                        '!./**/*-debug.css.js',
                        '!./**/*-debug.html.js',
                        '!./**/*.css.js',
                        '!./**/*.html.js',
                        '!./**/_*.js'
                    ],
                    extDot: 'last',
                    dest: pkg.spm.dist + __newDirName,
                    ext: '.js'
                }]
            }
        },
        uglify: {
            options: {
                preserveComments: 'some', //不删除注释,还可以为 false(删除全部注释),some(保留@preserve @license @cc_on等注释)
            },
            app: {
                files: [{
                    expand: true,
                    cwd: pkg.spm.dist + __newDirName,
                    src: [
                        './**/*.js'
                    ],
                    dest: pkg.spm.dist + __newDirName,
                    ext: '.js'
                }]
            }
        }
    };
    // console.log(configMod.transport.app.files[0].cwd)
    // 项目配置
    grunt.initConfig(configMod);

    grunt.task.loadTasks(path.join(nodepath, "grunt-cmd-transport", 'tasks'));
    grunt.task.loadTasks(path.join(nodepath, "grunt-cmd-concat", 'tasks'));
    grunt.task.loadTasks(path.join(nodepath, "grunt-contrib-uglify", 'tasks'));

    grunt.registerTask('build-app', ['transport:app', 'concat:app', 'uglify:app']);
    // 默认任务 !一般情况下不要打开
    grunt.registerTask('default', ['transport', 'concat', 'uglify']);
}
Example #13
0
module.exports = function(grunt) {

    var transport = require('grunt-cmd-transport');

    var style = transport.style.init(grunt);
    var text = transport.text.init(grunt);
    var script = transport.script.init(grunt);


    require('time-grunt')(grunt);

    var option = {
        pkg: grunt.file.readJSON("package.json"),
        copy: {
            options: {
                paths: ['src']
            },
            all: {
                files: [{
                    expand: true,
                    cwd: 'src/resources',
                    src: ['**/*', '!css/source/**/*'],
                    dest: 'dist/resources',
                    flatten: false
                }, {
                    expand: true,
                    cwd: 'src/lib',
                    src: ['**/sea.js', '**/jquery*.js'],
                    dest: 'dist/lib'
                }, {
                    expand: true,
                    cwd: 'src/plugins',
                    src: ['**/*', '!**/*.js'],
                    dest: 'dist/plugins',
                    filter: 'isFile'
                }]
            }
        },
        clean: {
            dist: ['dist'], //清除dist目录
            build: ['.build'] //清除build目录
        },
        less: {
            /**
             * [build 编译所有的less文件,按照模板分类]
             */
            build: {
                files: {
                    "src/resources/css/themes-default.css": ["src/resources/css/source/themes/default.less"],
                    "src/resources/css/themes-green.css": ["src/resources/css/source/themes/green.less"],
                    "src/resources/css/themes-blue.css": ["src/resources/css/source/themes/blue.less"],
                    "src/resources/css/themes-purple.css": ["src/resources/css/source/themes/purple.less"],
                    "src/resources/css/themes-orange.css": ["src/resources/css/source/themes/orange.less"],
                    "src/resources/css/themes-red.css": ["src/resources/css/source/themes/red.less"],
                    "src/resources/css/page-login.css": ["src/resources/css/source/page/login.less"]
                }
            }
        },
        cssmin: {
            options: {
                keepSpecialComments: 0
            },
            /**
             * [build 压缩合并Css文件,分为公共css和模板css]
             * @type {Object}
             */
            build: {
                files: {
                    'src/resources/css/public.css': [
                        'src/plugins/bootstrap/css/bootstrap.css',
                        'src/plugins/daterangepicker/bs3.css',
                        'src/plugins/datepicker/datepicker.css',
                        'src/plugins/uniform/css/uniform.default.css',
                        'src/plugins/font-awesome/css/font-awesome.min.css',
                        'src/plugins/datatables/1.9.4/bs.css',
                        'src/resources/css/style-tpl.css',
                        'src/resources/css/style.css',
                        'src/resources/css/style-responsive.css',
                        'src/resources/css/plugins.css',
                    ],
                    'src/resources/css/themes-default.css': ['src/resources/css/themes-default.css'],
                    'src/resources/css/themes-green.css': ['src/resources/css/themes-green.css'],
                    'src/resources/css/themes-blue.css': ['src/resources/css/themes-blue.css'],
                    'src/resources/css/themes-purple.css': ['src/resources/css/themes-purple.css'],
                    'src/resources/css/themes-orange.css': ['src/resources/css/themes-orange.css'],
                    'src/resources/css/themes-red.css': ['src/resources/css/themes-red.css'],
                    'src/resources/css/page-login.css': ['src/resources/css/page-login.css']
                }
            }
        },
        jshint: {
            options: {
                eqeqeq: true,
                trailing: true
            },
            files: ['src/modules/**/*.js']
        },
        transport: {
            options: {
                paths: ['src'],
                alias: '<%= pkg.spm.alias %>',
                parsers: {
                    '.js': [script.jsParser],
                    '.css': [style.css2jsParser],
                    '.html': [text.html2jsParser]
                }
            },
            all: {
                options: {
                    idleading: ""
                },
                files: [{
                    expand: true,
                    cwd: 'src',
                    src: ['**/*', '!**/sea*.js'],
                    filter: 'isFile',
                    dest: '.build'
                }]
            }
        },
        concat: {
            options: {
                paths: ['.'],
                include: 'relative'
            },
            modules: {
                files: [{
                    expand: true,
                    cwd: '.build/',
                    src: ['**/modules/**/app.js'],
                    dest: 'dist/',
                    ext: '.js'
                }]
            }
        },
        uglify: {
            /**
             * [seajs 合并Seajs扩展文件,并混淆压缩]
             */
            seajs: {
                files: {
                    "src/lib/vendor/sea.js": ["src/lib/vendor/seajs/*.js"]
                }
            },
            /**
             * [all 混淆压缩所以的页面模块文件]
             */
            all: {
                files: [{
                    expand: true,
                    cwd: 'dist/',
                    src: ['modules/**/*.js'],
                    dest: 'dist/',
                    ext: '.js'
                }]
            }
        },
        /**
         * [template 编译html 模板引擎handlebars]
         */
        template: {
            dev: {
                engine: 'handlebars',
                cwd: 'src/templates/',
                partials: ['src/templates/fixtures/*.hbs'],
                data: 'src/templates/data.json',
                options: {},
                files: [{
                    expand: true,
                    cwd: 'src/templates/',
                    src: ['*.hbs'],
                    dest: 'dist/templates',
                    ext: '.html'
                }]
            }
        }

    }


    var task_default = [];

    //task_default.push("clean:dist");
    task_default.push("transport:all");
    task_default.push("copy:all");
    task_default.push("concat:modules");
    task_default.push("uglify:all");
    task_default.push("clean:build");
    task_default.push("template");


    grunt.initConfig(option);

    grunt.loadNpmTasks('grunt-contrib-copy');
    grunt.loadNpmTasks('grunt-contrib-cssmin');
    grunt.loadNpmTasks('grunt-contrib-less');
    grunt.loadNpmTasks('grunt-cmd-transport');
    grunt.loadNpmTasks('grunt-cmd-concat');
    grunt.loadNpmTasks('grunt-contrib-uglify');
    grunt.loadNpmTasks('grunt-contrib-jshint');
    grunt.loadNpmTasks('grunt-contrib-clean');
    grunt.loadNpmTasks('grunt-template-html');


    grunt.registerTask('check', ['jshint']);
    grunt.registerTask('css', ['less:build', 'cssmin:build','copy:all']);
    grunt.registerTask('seajs', ['uglify:seajs']);
    grunt.registerTask('tpl', ['template',"copy:all"]);
    grunt.registerTask('cp', ['copy:all']);
    grunt.registerTask('default', task_default);


};
Example #14
0
module.exports = function (grunt) {
    var transport = require('grunt-cmd-transport');
    var style = transport.style.init(grunt);
    var text = transport.text.init(grunt);
    var script = transport.script.init(grunt);

    grunt.initConfig({
        pkg : grunt.file.readJSON("package.json"),

        //公共元数据
        meta : {
            banner: '/* \n'+ 
                    ' * <%= pkg.author %> \n' + 
                    ' * <%= pkg.email %> \n' + 
                    ' * <%= pkg.homepage %>\n' + 
                    ' * <%= grunt.template.today("yyyy-mm-dd") %>\n' +
                    ' */'
        },

        transport : {
            options : {
                paths : ['.'],
                alias: '<%= pkg.spm.alias %>',
                parsers : {
                    '.js' : [script.jsParser],
                    '.css' : [style.css2jsParser],
                    '.html' : [text.html2jsParser]
                }
            },

            widget : {
                options : {
                    idleading : 'dist/component/widget/'
                },

                files : [
                    {
                        cwd : 'component/widget/',
                        src : '**/*',
                        filter : 'isFile',
                        dest : '.build/component/widget'
                    }
                ]
            },

            component : {
                options : {
                    idleading : 'dist/component/'
                },

                files : [
                    {
                        cwd : 'component/',
                        src : '**/*',
                        filter : 'isFile',
                        dest : '.build/component'
                    }
                ]
            },

            component_module : {
                options : {
                    idleading : 'dist/component_module/'
                },

                files : [
                    {
                        cwd : 'component_module/',
                        src : '**/*',
                        filter : 'isFile',
                        dest : '.build/component_module'
                    }
                ]
            },

            app : {
                options : {
                    idleading : 'dist/view/'
                },

                files : [
                    {
                        cwd : 'view/',
                        src : '**/*.js',
                        filter : 'isFile',
                        dest : '.build/view'
                    }
                ]
            }
        },
        concat : {
            options : {
                paths : ['.'],
                include : 'relative'
            },

            widget : {
                files: [
                    {
                        expand: true,
                        cwd: '.build/',
                        src: ['component/widget/**/*.js'],
                        dest: 'dist/',
                        ext: '.js'
                    }
                ]
            },

            component : {
                files: [
                    {
                        expand: true,
                        cwd: '.build/',
                        src: ['component/**/*.js'],
                        dest: 'dist/',
                        ext: '.js'
                    }
                ]
            },

            component_module : {
                files: [
                    {
                        expand: true,
                        cwd: '.build/',
                        src: ['component_module/**/*.js'],
                        dest: 'dist/',
                        ext: '.js'
                    }
                ]
            },

            app : {
                options : {
                    include : 'all'
                },
                files: [
                    {
                        expand: true,
                        cwd: '.build/',
                        src: ['view/**/*.js'],
                        dest: 'dist/',
                        ext: '.js'
                    }
                ]
            }
        },

        uglify : {
            widget : {
                files: [
                    {
                        expand: true,
                        cwd: 'dist/',
                        src: ['component/widget/**/*.js', '!component/widget/**/*-debug.js'],
                        dest: 'dist/',
                        ext: '.js'
                    }
                ]
            },

            component : {
                files: [
                    {
                        expand: true,
                        cwd: 'dist/',
                        src: ['component/**/*.js', '!component/**/*-debug.js'],
                        dest: 'dist/',
                        ext: '.js'
                    }
                ]
            },

            component_module : {
                files: [
                    {
                        expand: true,
                        cwd: 'dist/',
                        src: ['component_module/**/*.js', '!component_module/**/*-debug.js'],
                        dest: 'dist/',
                        ext: '.js'
                    }
                ]
            },

            app : {
                options : {
                    banner : '<%= meta.banner %>\n',   //头部注释
                },

                files: [
                    {
                        expand: true,
                        cwd: 'dist/',
                        src: ['view/**/*.js', '!view/**/*-debug.js'],
                        dest: 'dist/',
                        ext: '.js'
                    }
                ]
            }
        },

        cssmin : {
            appCSS: {
                options : {
                    banner : '<%= meta.banner %>\n',   //头部注释
                },

                files: [{
                    expand: true,
                    cwd: 'view/',
                    src: ['**/*.css', '!**/*-min.css'],
                    dest: 'view/',
                    ext: '-min.css'
                }]
            }
        },

        clean : {
            // spm : ['.build']
            spm : ['.build', "dist/component", "dist/component_module", "dist/view/**/js", "dist/view/**/*-debug.js"]
        }
    });

    grunt.loadNpmTasks('grunt-cmd-transport');
    grunt.loadNpmTasks('grunt-cmd-concat');
    grunt.loadNpmTasks('grunt-contrib-clean');
    grunt.loadNpmTasks('grunt-contrib-uglify');
    grunt.loadNpmTasks('grunt-contrib-cssmin');

    // grunt.registerTask('build-s', ['cssmin']);
    // grunt.registerTask('build-w', ['transport:widget', 'concat:widget', 'uglify:widget', 'clean']);
    // grunt.registerTask('build-c', ['transport:component', 'concat:component', 'uglify:component', 'clean']);
    // grunt.registerTask('build-cm', ['transport:component_module', 'concat:component_module', 'uglify:component_module', 'clean']);
    // grunt.registerTask('build-app', ['transport:app', 'concat:app', 'uglify:app', 'clean']);
    grunt.registerTask('default', [
        'cssmin:appCSS',
        'transport:widget', 'concat:widget', 'uglify:widget',
        'transport:component', 'concat:component', 'uglify:component',
        'transport:component_module', 'concat:component_module', 'uglify:component_module',
        'transport:app', 'concat:app', 'uglify:app', 'clean'
    ]);
};
Example #15
0
module.exports = function (grunt) {
  var transport = require('grunt-cmd-transport');
  var style = transport.style.init(grunt);
  var text = transport.text.init(grunt);
  var script = transport.script.init(grunt);

  grunt.initConfig({
    pkg: grunt.file.readJSON("package.json"),

    transport: {
      options: {
        paths: ['.'],
        include: 'relative',
        alias: '<%= pkg.options.alias %>',
        parsers: {
          '.js': [script.jsParser],
          '.css': [style.css2jsParser],
          '.html': [text.html2jsParser]
        }
      },

      dialog: {
        options: {
          idleading: 'dist/src/'
        },

        files: [
          {
            cwd: 'src/',
            src: '**/*',
            filter: 'isFile',
            dest: '.build/src'
          }
        ]
      },

      app1: {
        options: {
          idleading: 'dist/app/'
        },

        files: [
          {
            cwd: 'app',
            src: '**/*',
            filter: 'isFile',
            dest: '.build/app'
          }
        ]
      }
    },

    concat: {
      options: {
        paths: ['.'],
        include: 'relative',
        stripBanners: true,
        banner: '/*! <%= pkg.name %> - v<%= pkg.version %> - ' +'<%= grunt.template.today("yyyy-mm-dd") %> */\n'
      },

      dialog: {
        files: [
          {
            expand: true,
            cwd: '.build/',
            src: ['src/**/*.js'],
            dest: 'dist/',
            ext: '.js'
          }
        ]
      },

      app1: {
        options: {
          include: 'all'
        },
        files: [
          {
            expand: true,
            cwd: '.build/',
            src: ['app/**/*.js'],
            dest: 'dist/',
            ext: '.js'
          }
        ]
      }
    },

    uglify: {
      dialog: {
        files: [
          {
            expand: true,
            cwd: 'dist/',
            src: ['src/**/*.js', '!src/**/*-debug.js'],
            dest: 'dist/',
            ext: '.js'
          }
        ]
      },

      app1: {
        files: [
          {
            expand: true,
            cwd: 'dist/',
            src: ['app/**/*.js', '!app/**/*-debug.js'],
            dest: 'dist/',
            ext: '.js'
          }
        ]
      }
    },

    clean: {
      spm : ['.build']
    }
  });

  grunt.loadNpmTasks('grunt-cmd-transport');
  grunt.loadNpmTasks('grunt-cmd-concat');
  grunt.loadNpmTasks('grunt-contrib-clean');
  grunt.loadNpmTasks('grunt-contrib-uglify');
  // grunt.registerTask('dialog', ['transport:dialog', 'concat:dialog']);
  // grunt.registerTask('app1', ['transport:app1', 'concat:app1']);
  grunt.registerTask('dialog', ['transport:dialog', 'concat:dialog', 'uglify:dialog', 'clean']);
  grunt.registerTask('app1', ['transport:app1', 'concat:app1', 'uglify:app1', 'clean']);
};
Example #16
0
module.exports = function (grunt) {
    var transport = require('grunt-cmd-transport');
    var style = transport.style.init(grunt);
    var text = transport.text.init(grunt);
    var script = transport.script.init(grunt);

    grunt.initConfig({
        pkg : grunt.file.readJSON("package.json"),

        transport : {
            options : {
                paths : ['.'],
                alias: '<%= pkg.spm.alias %>',
                parsers : {
                    '.js' : [script.jsParser],
                    //'.css' : [style.css2jsParser],
                    '.html' : [text.html2jsParser]
                }
            },

            styles : {
                options : {
                    idleading : 'dist/styles/'
                },

                files : [
                    {
                        cwd : 'styles/',
                        src : '**/*',
                        filter : 'isFile',
                        dest : 'dist/styles'
                    }
                ]
            },

            app1 : {
                options : {
                    idleading : 'app1/'
                },

                files : [
                    {
                        cwd : 'app',
                        src : '**/*',
                        filter : 'isFile',
                        dest : 'dist/app'
                    }
                ]
            }
        },

        uglify : {
            styles : {
                files: [
                    {
                        expand: true,
                        cwd: 'dist/',
                        src: ['styles/**/*.js', '!styles/**/*-debug.js'],
                        dest: 'dist/',
                        ext: '.js'
                    }
                ]
            },
            app1 : {
                files: [
                    {
                        expand: true,
                        cwd: 'dist/',
                        src: ['app/**/*.js', '!app/**/*-debug.js'],
                        dest: 'dist/',
                        ext: '.js'
                    }
                ]
            }
        },

        clean : {
            spm : ['.build']
        }
    });

    grunt.loadNpmTasks('grunt-cmd-transport');
    grunt.loadNpmTasks('grunt-cmd-concat');
    grunt.loadNpmTasks('grunt-contrib-clean');
    grunt.loadNpmTasks('grunt-contrib-uglify');

    grunt.registerTask('build-styles', ['transport:styles', 'uglify:styles', 'clean']);
    grunt.registerTask('build-app1', ['transport:app1', 'uglify:app1','clean']);
//    grunt.registerTask('default', ['clean']);
};
module.exports = function (grunt) {

    //seajs
    var transport = require('grunt-cmd-transport');
    var style = transport.style.init(grunt);
    var text = transport.text.init(grunt);
    var script = transport.script.init(grunt);

    var alias = {
        '$-debug': 'gallery/jquery/2.1.1/jquery-debug',
        '$': 'gallery/jquery/2.1.1/jquery',
        'date': 'gallery/date/0.0.0/index-debug'
    };

    grunt.initConfig({
        pkg : grunt.file.readJSON("package.json"),
        transport : {
            options : {
                paths : ['scripts/'],
                alias: alias,
                parsers : {
                    '.js' : [script.jsParser],
                    '.css' : [style.css2jsParser],
                    '.html' : [text.html2jsParser]
                }
            },
            common: {
                options: {
                    idleading: 'common/'
                },
                files: [
                    {
                        expand: true,
                        cwd: 'scripts/src/common',
                        src: ['**.js', '!**-debug.js'],
                        filter: 'isFile',
                        // dest: '.build/common'
                        dest: 'scripts/common'
                    }
                ]
            },
            app: {
              options: {
                idleading: 'app/'
              },
              files: [
                {
                  expand: true,
                  cwd: 'scripts/src/app',
                  src: '**.js',
                  filter: 'isFile',
                  // dest: '.build/app'
                  dest: 'scripts/app'
                }
              ]
            }
        },
        concat: {
            options: {
               paths: ['scritps'],
               include: 'relative' // default is self, all relative
            },
            app: {
                files: [
                    {
                      expand: true,
                      cwd: 'scripts/app',
                      src: '**.js',
                      filter: 'isFile',
                      // dest: '.build/app'
                      dest: 'scripts/app'
                    }
                ]
            }
        },
        uglify: {
            options: {},
            dist: {
                files: [
                    // {
                    //     expand: true,
                    //     cwd: 'dist',
                    //     src: ['*/*.js', '!*/*-debug.js'],
                    //     // filter: 'isFile',
                    //     dest: 'dist'
                    // }
                    {
                        expand: true,
                        cwd: 'scripts/app',
                        src: ['*.js', '!*-debug.js'],
                        filter: 'isFile',
                        dest:'scripts/app'
                    },
                    {
                        expand: true,
                        cwd: 'scripts/common',
                        src: ['*.js', '!*-debug.js'],
                        filter: 'isFile',
                        dest:'scripts/common'
                    }
                ]
            }
        },
        clean : {
            spm : ['.build']
        }
    });

    grunt.loadNpmTasks('grunt-cmd-transport');
    grunt.loadNpmTasks('grunt-cmd-concat');
    grunt.loadNpmTasks('grunt-contrib-clean');
    grunt.loadNpmTasks('grunt-contrib-uglify');


    //shop模块
    grunt.registerTask('build-app', ['transport:app', 'clean']);
    //seajs 公用模块
    grunt.registerTask('build-common', ['transport:common', 'clean']);

    grunt.registerTask('default', ['transport:app', 'transport:common', 'concat:app', 'uglify:dist', 'clean']);
};
Example #18
0
module.exports = function(grunt) {

    grunt.loadNpmTasks('grunt-contrib-copy');
    grunt.loadNpmTasks('grunt-contrib-cssmin');
    grunt.loadNpmTasks('grunt-contrib-less');
    grunt.loadNpmTasks('grunt-cmd-transport');
    grunt.loadNpmTasks('grunt-cmd-concat');
    grunt.loadNpmTasks('grunt-contrib-uglify');
    grunt.loadNpmTasks('grunt-contrib-jshint');
    grunt.loadNpmTasks('grunt-contrib-clean');
    grunt.loadNpmTasks('grunt-template-html');
    grunt.loadNpmTasks('grunt-postcss');
    grunt.loadNpmTasks('grunt-contrib-connect');
    grunt.loadNpmTasks('grunt-contrib-qunit');

    require('time-grunt')(grunt);

    var transport = require('grunt-cmd-transport');
    var style = transport.style.init(grunt);
    var text = transport.text.init(grunt);
    var script = transport.script.init(grunt);

    //connect端口
    var connectPort = 9000;

    var vendorPath = 'src/lib/vendor/';
    var cssPath = 'src/resources/';
    var cssThemes = ['default','green', 'blue', 'purple', 'orange', 'red'];
    var cssPages = ['home', 'login']

    function getCssFiles() {
        var cssObject = {};
        for (var i = 0; i < cssThemes.length; i++) {
            cssObject[cssPath + 'css/themes-' + cssThemes[i] + '.css'] = [cssPath + 'less/themes/' + cssThemes[i] + '.less'];
        }
        for (var i = 0; i < cssPages.length; i++) {
            cssObject[cssPath + 'css/page-' + cssPages[i] + '.css'] = [cssPath + 'less/pages/' + cssPages[i] + '.less'];
        }
        return cssObject;
    }

    function getMinCssFiles() {
        var cssObject = {},
            file;

        cssObject[cssPath + 'css/public.css'] = [
                vendorPath + 'bootstrap/css/bootstrap.css',
                vendorPath + 'uniform/css/uniform.default.css',
                vendorPath + 'font-awesome/css/font-awesome.min.css'
            ];

        for (var i = 0; i < cssThemes.length; i++) {
            file = cssPath + 'css/themes-' + cssThemes[i] + '.css';
            cssObject[file] = [file];
        }
        for (var i = 0; i < cssPages.length; i++) {
            file = cssPath + 'css/page-' + cssPages[i] + '.css';
            cssObject[file] = [file];
        }

        return cssObject;
    }

    var option = {
        pkg: grunt.file.readJSON("package.json"),
        copy: {
            options: {
                paths: ['src']
            },
            all: {
                files: [{
                    expand: true,
                    cwd: 'src/resources',
                    src: ['**/*', '!less/**/*'],
                    dest: 'dist/resources',
                    flatten: false
                }, {
                    expand: true,
                    cwd: 'src/lib',
                    src: ['**/sea.js', '**/jquery*.js', '**/es5*.*'],
                    dest: 'dist/lib'
                }, {
                    expand: true,
                    cwd: 'src/plugins',
                    src: ['**/**/*.png', '**/**/*.gif', '**/**/*.swf'],
                    dest: 'dist/plugins',
                    filter: 'isFile'
                }]
            }
        },
        clean: {
            dist: ['dist'], //清除dist目录
            build: ['.build'] //清除build目录
        },
        less: {
            /**
             * [build 编译所有的less文件,按照模板分类]
             */
            build: {
                files: getCssFiles()
            }
        },
        cssmin: {
            options: {
                keepSpecialComments: 0
            },
            /**
             * [build 压缩合并Css文件,分为公共css和模板css]
             * @type {Object}
             */
            build: {
                files: getMinCssFiles()
            }
        },
        postcss: {
            options: {
                map: false,
                processors: [
                    require('autoprefixer')({
                        browsers: 'last 2 versions',
                        remove: false
                    })
                ]
            },
            dist: {
                src: 'src/resources/css/*.css'
            }
        },
        jshint: {
            options: {
                jshintrc: true
            },
            files: [
                'src/modules/**/*.js',
                'src/widgets/**/*.js',
                'src/plugins/**/module.js',
                'src/lib/**/*.js',
                '!src/lib/vendor/**/*.js'
            ]
        },
        transport: {
            options: {
                debug: false,
                paths: ['src'],
                alias: '<%= pkg.spm.alias %>',
                parsers: {
                    '.js': [script.jsParser],
                    '.css': [style.css2jsParser],
                    '.tpl': [text.html2jsParser],
                    '.html': [text.html2jsParser]
                }
            },
            all: {
                options: {
                    idleading: ""
                },
                files: [{
                    expand: true,
                    cwd: 'src',
                    src: [
                        '**/*',
                        '!resources/**',
                        '!templates/**',
                        '!**/sea*.js'
                    ],
                    filter: 'isFile',
                    dest: '.build'
                }]
            }
        },
        concat: {
            options: {
                paths: ['.'],
                include: 'relative',
                uglify: true
            },
            modules: {
                files: [{
                    expand: true,
                    cwd: '.build/',
                    src: [
                        '**/modules/**/app.js',
                        '**/echarts/loader.js',
                        '**/echarts/loader-map.js'
                    ],
                    dest: 'dist/',
                    ext: '.js'
                }]
            }
        },
        uglify: {
            /**
             * [seajs 合并Seajs扩展文件,并混淆压缩]
             */
            seajs: {
                files: {
                    "src/lib/vendor/sea.js": ["src/lib/vendor/seajs/*.js"]
                }
            }
        },
        /**
         * [handlebars template]
         */
        template: {
            dev: {
                engine: 'handlebars',
                cwd: 'src/templates/',
                partials: [
                    'src/templates/fixtures/*',
                    'src/templates/codes/*',
                    'src/templates/layouts/*'
                ],
                data: 'src/templates/data.json',
                options: {},
                files: [{
                    expand: true,
                    cwd: 'src/templates/',
                    src: ['*.hbs'],
                    dest: 'dist/templates',
                    ext: '.html'
                }]
            }
        },
        // Create a local web server for testing http:// URIs.
        connect: {
            root_server: {
                options: {
                    port: connectPort,
                    base: '.',
                }
            }
        },
        // Unit tests.
        qunit: {
            allTest: {
                options: {
                    urls: [
                        'http://localhost:' + connectPort + '/test/index.html'
                    ]
                }
            }
        }
    };





    //生产发布的Task
    var task_default = [];

    task_default.push("clean:dist");
    task_default.push("transport:all");
    task_default.push("copy:all");
    task_default.push("concat:modules");
    task_default.push("clean:build");
    task_default.push("template");


    grunt.initConfig(option);


    grunt.registerTask('seajs', ['uglify:seajs']);
    grunt.registerTask('check', ['jshint', 'connect', 'qunit']);
    grunt.registerTask('css', ['less:build', 'cssmin:build', 'postcss', 'copy:all']);
    grunt.registerTask('tpl', ['template', "copy:all"]);
    grunt.registerTask('cp', ['copy:all']);

    grunt.registerTask('default', task_default);

};
Example #19
0
module.exports = function (grunt) {
  var transport = require('grunt-cmd-transport');
  var style = transport.style.init(grunt);
  var text = transport.text.init(grunt);
  var script = transport.script.init(grunt);

  var default_opt = {
    pkg: grunt.file.readJSON("package.json"),
    //定义标示了
    transport: {
      options: {
        paths: ['.'],
        alias: '<%= pkg.spm.alias %>',
        parsers: {
          '.js': [script.jsParser],
          '.css': [style.css2jsParser],
          '.html': [text.html2jsParser]
        }
      },
      //生成一个以当前版本号为基名模块文件
      curfile: {
        options: {
          idleading: '<%= pkg.name %>/<%= pkg.version %>/'
        },
        files: [
          {
            cwd: 'src/<%= pkg.version %>/',
            src: '**/*',
            filter: 'isFile',
            dest: '.build/<%= pkg.version %>/'
          }
        ]
      },
      //当前版本再生产生成一个名为“latest”的基名模块文件
      latestfile: {
        options: {
          idleading: '<%= pkg.name %>/latest/'
        },
        files: [
          {
            cwd: 'src/<%= pkg.version %>/',
            src: '**/*',
            filter: 'isFile',
            dest: '.build/latest/'
          }
        ]
      }
    },
    //对当前版本下的.build文件进行合并
    concat: {
      options: {
        paths: ['.'],
        include: 'relative',
        //文件内容的分隔符
        separator: ';',
        banner: '/*! <%= pkg.name %>(<%= pkg.version %>) - <%= pkg.author %> - <%= grunt.template.today("yyyy-mm-dd H:MM:ss") %>*/\n'
      },
      curfile: {
        files: [
          {
            expand: true,
            cwd: '.build/',
            src: ['<%= pkg.version %>/*.js'],
            dest: 'dist/',
            ext: '.js'
          }
        ]
      },
      latestfile: {
        files: [
          {
            expand: true,
            cwd: '.build/',
            src: ['latest/*.js'],
            dest: 'dist/',
            ext: '.js'
          }
        ]
      }
    },
    uglify: {
      options: {
        banner: '/*! <%= pkg.name %>(<%= pkg.version %>) - <%= pkg.author %> - <%= grunt.template.today("yyyy-mm-dd H:MM:ss") %>*/\n',
        footer: '',
        beautify: {
          ascii_only: true
        }
      },
      curfile: {
        files: [
          {
            expand: true,
            cwd: 'dist/',
            src: ['<%= pkg.version %>/*.js', '!<%= pkg.version %>/*-debug.js'],
            dest: 'dist/',
            ext: '.js'
          }
        ]
      },
      latestfile: {
        files: [
          {
            expand: true,
            cwd: 'dist/',
            src: ['latest/*.js', '!latest/*-debug.js'],
            dest: 'dist/',
            ext: '.js'
          }
        ]
      }
    },
    copy: {
      curfile: {
        files: [
          {
            expand: true,
            cwd: 'dist/',
            src: ['<%= pkg.version %>/**'],
            dest: '../../../../public/assets/js_modules/<%= pkg.name %>',
            filter: 'isFile'
          }
        ]
      },
      latestfile: {
        files: [
          {
            expand: true,
            cwd: 'dist/',
            src: ['latest/**'],
            dest: '../../../../public/assets/js_modules/<%= pkg.name %>',
            filter: 'isFile'
          }
        ]
      }
    },
    clean: {
      spm: ['.build']
    }
  };

  //定义项目
  grunt.initConfig(default_opt);

  //载入grunt插件
  grunt.loadNpmTasks('grunt-cmd-transport');
  grunt.loadNpmTasks('grunt-cmd-concat');
  grunt.loadNpmTasks('grunt-contrib-clean');
  grunt.loadNpmTasks('grunt-contrib-uglify');
  grunt.loadNpmTasks('grunt-contrib-copy');

  //执行开发模式所有任务(开发模式不压缩)
  grunt.registerTask('build', ['transport:curfile','transport:latestfile','concat:curfile','concat:latestfile','copy:curfile','copy:latestfile']);
  //执行发布产品模式所有任务(一条龙服务)
  grunt.registerTask('build-all', ['transport:curfile','transport:latestfile','concat:curfile','concat:latestfile','uglify:curfile','uglify:latestfile','copy:curfile','copy:latestfile']);
  //提取依赖名转换为具名模块
  grunt.registerTask('build-tran', ['transport:curfile','transport:latestfile']);
  //合并
  grunt.registerTask('build-concat', ['concat:curfile','concat:latestfile']);
  //压缩
  grunt.registerTask('build-uglify', ['uglify:curfile','uglify:latestfile']);
  //拷贝至产品目录
  grunt.registerTask('build-copy', ['copy:curfile','copy:latestfile']);
  //清楚临时文件
  grunt.registerTask('build-clean', ['clean']);

};