fineui是帆软报表和BI产品线所使用的前端框架。
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

438 lines
15 KiB

8 years ago
module.exports = function (grunt) {
function sync(patterns) {
return [...new Set(grunt.file.expand({
filter: function (path) {
return !new RegExp(/__test__/g).test(path);
},
}, patterns))];
}
8 years ago
// Project configuration.
grunt.initConfig({
7 years ago
pkg: grunt.file.readJSON("package.json"),
8 years ago
concat: {
options: {
7 years ago
separator: ""
8 years ago
},
polyfillJs: {
6 years ago
src: ["src/core/foundation.js", "src/polyfill/**/*.js"],
7 years ago
dest: "dist/polyfill.js"
},
8 years ago
coreJs: {
src: sync([
6 years ago
"src/core/foundation.js",
7 years ago
"src/core/lodash.js",
7 years ago
// 'src/core/mvc/**/*.js',
7 years ago
"src/core/base.js",
"src/core/ob.js",
"src/core/widget.js",
7 years ago
// 'src/core/model.js',
// 'src/core/view.js',
7 years ago
"src/core/shortcut.js",
6 years ago
"src/core/utils/**/*.js",
7 years ago
"src/core/behavior/behavior.js",
"src/core/wrapper/layout.js",
7 years ago
"src/core/plugin.js",
7 years ago
"src/core/**/*.js",
"src/data/data.js",
7 years ago
"src/data/**/*.js"
]),
7 years ago
dest: "dist/core.js"
8 years ago
},
8 years ago
7 years ago
// 最基础的控件
8 years ago
baseJs: {
src: sync([
7 years ago
"src/third/**/*.js",
"src/base/pane.js",
"src/base/single/single.js",
"src/base/single/text.js",
"src/base/single/button/button.basic.js",
"src/base/single/button/button.node.js",
"src/base/single/tip/tip.js",
"src/base/combination/group.button.js",
"src/base/combination/tree.button.js",
6 years ago
"src/base/tree/ztree/treeview.js",
"src/base/tree/ztree/asynctree.js",
"src/base/tree/ztree/parttree.js",
"src/base/tree/ztree/list/listtreeview.js",
"src/base/tree/ztree/list/listasynctree.js",
"src/base/tree/ztree/list/listparttree.js",
7 years ago
"src/base/**/*.js"
]),
7 years ago
dest: "dist/base.js"
8 years ago
},
7 years ago
// 实现好的一些基础实例
8 years ago
caseJs: {
src: sync([
7 years ago
"src/case/combo/popup.bubble.js",
"src/case/**/*.js"
]),
7 years ago
dest: "dist/case.js"
8 years ago
},
widgetJs: {
src: sync([
7 years ago
"src/widget/**/*.js",
"src/component/**/*.js"
]),
7 years ago
dest: "dist/widget.js"
},
7 years ago
routerJs: {
src: [
7 years ago
"src/router/**/*.js"
7 years ago
],
7 years ago
dest: "dist/router.js"
7 years ago
},
8 years ago
coreCss: {
7 years ago
src: ["src/css/core/**/*.css", "src/css/theme/**/*.css"],
dest: "dist/core.css"
8 years ago
},
7 years ago
coreWithoutNormalizeCss: {
7 years ago
src: ["src/css/core/**/*.css", "src/css/theme/**/*.css", "!src/css/core/normalize.css", "!src/css/core/normalize2.css"],
dest: "dist/core_without_normalize.css"
7 years ago
},
8 years ago
baseCss: {
7 years ago
src: ["src/css/base/**/*.css"],
dest: "dist/base.css"
8 years ago
},
widgetCss: {
7 years ago
src: ["src/css/widget/**/*.css"],
dest: "dist/widget.css"
},
8 years ago
resourceCss: {
7 years ago
src: ["src/css/resource/**/*.css"],
dest: "dist/resource.css"
8 years ago
},
8 years ago
7 years ago
bundleJs: {
src: ["dist/core.js", "dist/fix/fix.js", "dist/base.js", "dist/case.js", "dist/widget.js", "dist/fix/fix.compact.js", "dist/router.js", "public/js/**/*.js", "public/js/index.js", "i18n/i18n.cn.js"],
dest: "dist/bundle.js",
7 years ago
},
versionFineuiJs: {
src: ["dist/bundle.js"],
dest: "dist/2.0/fineui.js"
},
6 years ago
bundleIEJs: {
src: ["dist/core.js", "dist/fix/fix.ie.js", "dist/base.js", "dist/case.js", "dist/widget.js", "dist/fix/fix.compact.ie.js", "dist/router.js", "public/js/**/*.js", "public/js/index.js", "i18n/i18n.cn.js"],
6 years ago
dest: "dist/bundle.ie.js"
},
versionFineuiIEJs: {
src: ["dist/bundle.ie.js"],
dest: "dist/2.0/fineui.ie.js"
},
7 years ago
bundleCss: {
src: ["dist/core.css", "dist/base.css", "dist/widget.css", "public/css/app.css", "public/css/**/*.css", "fineui.typescript.css"],
7 years ago
dest: "dist/bundle.css"
7 years ago
},
versionFineuiCss: {
src: ["dist/bundle.css"],
dest: "dist/2.0/fineui.css"
},
fineuiJs: {
src: ["dist/es5.polyfill.js","dist/polyfill.js", "dist/core.js", "dist/fix/fix.js", "dist/base.js",
"dist/case.js", "dist/widget.js", "dist/router.js", "dist/fix/fix.compact.js", "ui/js/**/*.js"],
dest: "dist/fineui.js"
},
6 years ago
fineuiIEJs: {
src: ["dist/ie.polyfill.js", "dist/polyfill.js", "dist/core.js", "dist/fix/fix.ie.js", "dist/base.js",
"dist/case.js", "dist/widget.js", "dist/router.js", "dist/fix/fix.compact.ie.js", "ui/js/**/*.js"],
6 years ago
dest: "dist/fineui.ie.js"
},
6 years ago
fineuiWithoutJqueryAndPolyfillJs: {
src: sync(["src/core/foundation.js",
6 years ago
"src/core/lodash.js",
// 'src/core/mvc/**/*.js',
"src/core/base.js",
"src/core/ob.js",
"src/core/widget.js",
// 'src/core/model.js',
// 'src/core/view.js',
"src/core/shortcut.js",
"src/core/utils/*.js",
"src/core/behavior/behavior.js",
"src/core/wrapper/layout.js",
"src/core/plugin.js",
"src/core/**/*.js",
6 years ago
"!src/core/platform/web/**/*.js",
6 years ago
"src/data/data.js",
"src/data/**/*.js",
"dist/fix/fix.js",
"src/base/pane.js",
"src/base/single/single.js",
"src/base/single/text.js",
"src/base/single/button/button.basic.js",
"src/base/single/button/button.node.js",
"src/base/single/tip/tip.js",
"src/base/combination/group.button.js",
"src/base/combination/tree.button.js",
"src/base/combination/map.button.js",
"src/base/**/*.js",
6 years ago
"!src/base/tree/ztree/**/*.js",
6 years ago
"!src/base/single/input/file.js",
"src/case/combo/popup.bubble.js",
"src/case/**/*.js",
"!src/case/colorchooser/**/*.js",
6 years ago
"!src/case/tree/ztree/**/*.js",
6 years ago
"dist/widget.js", "dist/fix/fix.compact.js", "ui/js/**/*.js"]),
6 years ago
dest: "dist/fineui_without_jquery_polyfill.js"
},
7 years ago
fineuiCss: {
src: ["dist/core.css", "dist/base.css", "dist/widget.css", "ui/css/app.css", "ui/css/**/*.css", "fineui.typescript.css"],
7 years ago
dest: "dist/fineui.css"
},
7 years ago
configJs: {
src: ["demo/version.js", "i18n/i18n.cn.js"],
7 years ago
dest: "dist/config.js"
7 years ago
},
8 years ago
demoJs: {
7 years ago
src: ["demo/app.js", "demo/js/**/*.js", "demo/config.js"],
7 years ago
dest: "dist/demo.js"
8 years ago
},
demoCss: {
7 years ago
src: ["demo/css/**/*.css"],
dest: "dist/demo.css"
},
7 years ago
utilsJs: {
src: [
7 years ago
"src/core/foundation.js",
6 years ago
"src/core/lodash.js",
7 years ago
"src/core/var.js",
"src/core/func/array.js",
"src/core/func/number.js",
"src/core/func/string.js",
"src/core/func/date.js",
"src/core/func/function.js",
7 years ago
"src/core/base.js",
"src/core/ob.js",
"src/core/alias.js",
"src/core/inject.js",
"src/core/i18n.js",
7 years ago
"src/core/utils/*.js",
"i18n/i18n.cn.js",
6 years ago
"_mobile/date.i18n.cn.js",
7 years ago
"src/data/data.js",
"src/data/**/*.js"
7 years ago
],
6 years ago
dest: "dist/utils.js"
7 years ago
}
8 years ago
},
8 years ago
less: {
7 years ago
demo: {
8 years ago
expand: true,
7 years ago
cwd: "demo/less",
src: ["**/*.less"],
dest: "demo/css/",
ext: ".css"
8 years ago
},
7 years ago
main: {
expand: true,
cwd: "public/less",
src: ["**/*.less"],
dest: "public/css",
ext: ".css"
},
7 years ago
ui: {
expand: true,
cwd: "ui/less",
src: ["**/*.less"],
dest: "ui/css",
ext: ".css"
},
7 years ago
src: {
expand: true,
cwd: "src/less",
src: ["**/*.less"],
dest: "src/css",
ext: ".css"
},
8 years ago
dev: {
options: {
compress: true,
yuicompress: false
}
}
},
7 years ago
uglify: {
8 years ago
options: {
banner: "/*! <%= pkg.name %> <%= grunt.template.today(\"yyyy-mm-dd HH:MM:ss\") %> */\n",
mangle: false,
sourceMap: true,
sourceMapIncludeSources: true,
compress: {
unused: false,
},
8 years ago
},
dist: {
files: {
7 years ago
"dist/bundle.min.js": ["<%= concat.bundleJs.dest %>"],
6 years ago
"dist/bundle.ie.min.js": ["<%= concat.bundleIEJs.dest %>"],
6 years ago
"dist/utils.min.js": ["<%= concat.utilsJs.dest %>"],
6 years ago
"dist/fineui.min.js": ["<%= concat.fineuiJs.dest %>"],
"dist/fineui.ie.min.js": ["<%= concat.fineuiIEJs.dest %>"],
"dist/2.0/fineui.min.js": ["<%= concat.versionFineuiJs.dest %>"],
"dist/2.0/fineui.ie.min.js": ["<%= concat.versionFineuiIEJs.dest %>"]
8 years ago
}
}
},
cssmin: {
7 years ago
bundleCss: {
8 years ago
7 years ago
src: "<%= concat.bundleCss.dest %>",
8 years ago
7 years ago
dest: "dist/bundle.min.css"
8 years ago
},
7 years ago
fineuiCss: {
src: "<%= concat.fineuiCss.dest %>",
dest: "dist/fineui.min.css"
},
versionFineuiMinCss: {
src: "<%= concat.versionFineuiCss.dest %>",
dest: "dist/2.0/fineui.min.css"
7 years ago
}
8 years ago
},
jshint: {
7 years ago
files: ["Gruntfile.js", "src/**/*.js"],
8 years ago
options: {
globals: {
jQuery: true,
console: true,
module: true,
document: true
}
}
},
6 years ago
copy: {
js: {
files: [
{
expand: true,
cwd: "dist",
src: [
"fineui.js"
],
dest: "dist/",
rename: function (dest, src) {
return dest + src.replace(".js", ".min.js");
}
}
]
}
},
8 years ago
watch: {
scripts: {
files: ["src/**/*.js", "src/**/*.less", "demo/js/**/*.js", "demo/app.js", "demo/version.js", "demo/config.js", "demo/less/**/*.less", "!src/**/__test__/*.js"],
7 years ago
tasks: ["less", "concat"],
8 years ago
options: {
spanw: true,
interrupt: true
}
7 years ago
},
livereload: {
options: {
livereload: "<%= connect.options.livereload %>"
},
files: ["src/**/*.js", "!src/**/__test__/*.js", "src/**/*.less"]
7 years ago
}
},
connect: {
options: {
port: 9000,
open: true,
livereload: 35729,
// Change this to '0.0.0.0' to access the server from outside
6 years ago
hostname: "0.0.0.0"
7 years ago
},
server: {
options: {
port: 9001
7 years ago
}
8 years ago
}
},
clean: ["src/css", "demo/css"]
8 years ago
});
7 years ago
grunt.loadNpmTasks("grunt-contrib-uglify");
grunt.loadNpmTasks("grunt-contrib-jshint");
grunt.loadNpmTasks("grunt-contrib-less");
grunt.loadNpmTasks("grunt-contrib-watch");
grunt.loadNpmTasks("grunt-contrib-concat");
grunt.loadNpmTasks("grunt-contrib-cssmin");
7 years ago
grunt.loadNpmTasks("grunt-contrib-connect");
6 years ago
grunt.loadNpmTasks("grunt-contrib-clean");
6 years ago
grunt.loadNpmTasks("grunt-contrib-copy");
8 years ago
grunt.registerTask("analyze", "code analysis", function () {
const authors = ["test_author_imp", "test_author_teller", "test_author_fay", "test_author_young", "test_author_windy", "test_author_lei.wang", "test_author_Kira", "test_author_Zhenfei.Li"];
const info = [];
authors.forEach(function (auth) {
info.push({
author: auth,
reg: new RegExp(auth, "g"),
count: 0
});
});
const testFiles = grunt.file.expand(["src/**/*.test.js", "test/**/*.test.js"]);
testFiles.forEach(function (el) {
const fileStr = grunt.file.read(el);
authors.forEach(function (auth, idx) {
const res = fileStr.match(info[idx].reg);
if (res != null) {
info[idx].count += res.length;
}
});
});
const todayStat = {};
info.forEach(function (inf) {
todayStat[inf.author] = inf.count;
});
const date = grunt.template.today("yyyy-mm-dd");
const dest = "test/unit.test.statistic.json";
let stat;
try {
stat = grunt.file.readJSON(dest);
} catch (e) {
stat = {};
}
if (!stat.date || stat.date === {}) {
stat[date] = todayStat;
}
grunt.file.write(dest, JSON.stringify(stat));
});
var defaultTask = ["clean", "less", "concat", "watch"];
6 years ago
grunt.registerTask("default", defaultTask);
grunt.registerTask("compile", function () {
grunt.config.set("connect.options.open", false);
grunt.task.run(defaultTask);
});
6 years ago
grunt.registerTask("build", ["clean", "less", "cssmin", "concat", "uglify"]);
6 years ago
grunt.registerTask("fake-build", ["clean", "less", "cssmin", "concat", "copy"]);
6 years ago
};