123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192 |
- /*-----------------------------------------------------
- * livereload Default Setting
- *-----------------------------------------------------*/
- 'use strict';
- var path = require('path');
- /*-----------------------------------------------------
- * Module Setting
- *-----------------------------------------------------*/
- module.exports = function(grunt) {
- // These plugins provide necessary tasks.
- /* [Build plugin & task ] ------------------------------------*/
- grunt.loadNpmTasks('grunt-contrib-clean');
- grunt.loadNpmTasks('grunt-contrib-concat');
- grunt.loadNpmTasks('grunt-contrib-uglify');
- grunt.loadNpmTasks('grunt-contrib-copy');
- grunt.loadNpmTasks('grunt-text-replace');
- grunt.loadNpmTasks('grunt-contrib-watch');
- grunt.loadNpmTasks('grunt-contrib-less');
- grunt.loadNpmTasks('grunt-postcss');
- grunt.loadNpmTasks('grunt-autoprefixer');
- var banner = '/*!\n' +
- ' * ====================================================\n' +
- ' * <%= pkg.title || pkg.name %> - v<%= pkg.version %> - ' +
- '<%= grunt.template.today("yyyy-mm-dd") %>\n' +
- '<%= pkg.homepage ? " * " + pkg.homepage + "\\n" : "" %>' +
- ' * GitHub: <%= pkg.repository.url %> \n' +
- ' * Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author.name %>;' +
- ' Licensed <%= _.pluck(pkg.licenses, "type").join(", ") %>\n' +
- ' * ====================================================\n' +
- ' */\n\n';
- var packs = ['index', 'edit', 'share', 'm-share'];
- var sources = require('./import.js');
- var srcPath = 'src/';
- var distPath = 'dist/';
- var distPages = ['index', 'edit', 'viewshare', 'm-share'].map(function(name) {
- return distPath + name + '.html';
- });
- var concatConfigs = {};
- packs.forEach(function(pack) {
- concatConfigs[pack] = {
- options: {
- banner: banner + '(function(window) {\n\n',
- footer: '\n\n})(window)',
- sourceMap: true,
- sourceMapStyle: 'link'
- },
- src: sources.filter(function(source) {
- return source.pack == '*' || source.pack.split('|').indexOf(pack) !== -1;
- }).map(function(source) {
- return source.path;
- }),
- dest: distPath + 'kityminder.' + pack + '.js'
- };
- });
- // Project configuration.
- grunt.initConfig({
- // Metadata.
- pkg: grunt.file.readJSON('package.json'),
- clean: ['dist', 'native-support/upload/', 'native-support/src/tmp/'],
- concat: concatConfigs,
- uglify: {
- minimize: {
- options: {
- banner: banner,
- sourceMap: true
- },
- files: (function() {
- var files = {};
- packs.forEach(function(pack) {
- files[distPath + 'kityminder.' + pack + '.min.js'] = distPath + 'kityminder.' + pack + '.js';
- });
- return files;
- })()
- }
- },
- copy: {
- dir: {
- files: [{
- src: [
- 'ui/theme/**/css/*.css',
- 'ui/theme/**/css/*.css.map',
- 'ui/theme/**/images/*',
- 'lang/**/*',
- 'static/**/*',
- 'native-support/**/*',
- 'lib/ZeroClipboard.swf',
- 'lib/inflate.js',
- 'lib/source-map.min.js',
- 'index.html',
- 'edit.html',
- 'viewshare.html',
- 'm-share.html',
- 'download.php'
- ],
- dest: distPath
- }]
- },
- km_config: {
- expand: true,
- src: 'kityminder.config.js',
- dest: distPath
- },
- mise: {
- files: [{
- src: ['LICENSE', 'favicon.ico', 'README.md', 'CHANGELOG.md'],
- dest: distPath
- }]
- }
- },
- replace: {
- online: {
- src: distPages,
- overwrite: true,
- replacements: [{
- from: /import\.js\?pack=([\w-]+)\"/,
- to: 'kityminder.$1.min.js"'
- }]
- },
- pageNoCache: {
- src: distPages,
- overwrite: true,
- replacements: [{
- from: /(src|href)=\"(.+?)\.(js|css)\"/ig,
- to: '$1="$2.$3?_=' + (+new Date()) + '"'
- }]
- },
- imageNoCache: {
- src: 'dist/ui/theme/default/css/default.all.css',
- overwrite: true,
- replacements: [{
- from: /\.png/ig,
- to: '.png?_=' + (+new Date())
- }]
- }
- },
- watch: {
- less: {
- files: ['ui/theme/**/*.less'],
- tasks: ['less:compile', 'autoprefixer']
- }
- },
- less: {
- compile: {
- files: {
- 'ui/theme/default/css/default.all.temp.css': [
- 'ui/theme/default/css/import.less'
- ]
- },
- options: {
- sourceMap: true,
- sourceMapFilename: 'ui/theme/default/css/default.all.temp.css.map',
- sourceMapBasepath: 'ui/theme/default/css/'
- }
- }
- },
- autoprefixer: {
- all: {
- options: {
- map: true
- },
- src: 'ui/theme/default/css/default.all.temp.css',
- dest: 'ui/theme/default/css/default.all.css'
- }
- }
- });
- // Build task(s).
- grunt.registerTask('default', ['clean', 'concat', 'uglify', 'less', 'autoprefixer', 'copy', 'replace']);
- grunt.registerTask('dev', ['less', 'autoprefixer', 'watch']);
- };
|