comparison default/node_modules/shoestring/Gruntfile.js @ 0:1d038bc9b3d2 default tip

Up:default
author Liny <dev@neowd.com>
date Sat, 31 May 2025 09:21:51 +0800
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:1d038bc9b3d2
1 /* global module:false */
2 module.exports = function(grunt) {
3
4 var fs, files, opts, spawn, builds = {};
5
6 opts = {
7 baseUrl: "src",
8 name: "../build/REPLACE",
9 out: "dist/REPLACE.js",
10 mainConfigFile: "build/config/production.js"
11 };
12
13 fs = require( 'fs' );
14 files = fs.readdirSync( "build/custom/" );
15
16 files.forEach(function( file ) {
17 if( /\.js$/.test(file) ){
18 var name = file.replace(/\.js$/, ""),
19 o = Object.create(opts);
20
21 builds[name] = {
22 options: o
23 };
24
25 builds[name].options.name = o.name.replace("REPLACE", "custom/" + name );
26 builds[name].options.out = o.out.replace("REPLACE", name );
27 }
28 });
29
30 builds.production = {
31 options: {
32 baseUrl: "src",
33 name: "../build/production",
34 out: "dist/production.js",
35 mainConfigFile: "build/config/production.js"
36 }
37 };
38
39 // NOTE config includes development
40 builds.development = {
41 options: {
42 baseUrl: "src",
43 // NOTE uses the same meta-module as production
44 name: "../build/development",
45 out: "dist/development.js",
46 mainConfigFile: "build/config/development.js"
47 }
48 };
49
50 // Project configuration.
51 grunt.initConfig({
52 pkg: grunt.file.readJSON( 'package.json' ),
53
54 meta: {
55 banner: '/*! Shoestring - v<%= pkg.version %> - ' +
56 '<%= grunt.template.today("yyyy-mm-dd") %>\n' +
57 '* http://github.com/filamentgroup/shoestring/\n' +
58 '* Copyright (c) <%= grunt.template.today("yyyy") %> ' +
59 'Scott Jehl, Filament Group, Inc; Licensed MIT & GPLv2 */ \n'
60 },
61
62 qunit: {
63 files: ['test/unit/*.html']
64 },
65
66 requirejs: builds,
67
68 // NOTE purely for the banner
69 concat: {
70 options: {
71 banner: '<%= meta.banner %>',
72 stripBanners: true
73 },
74
75 production: {
76 src: ['dist/production.js'],
77 dest: 'dist/shoestring.js'
78 },
79
80 development: {
81 src: ['dist/development.js'],
82 dest: 'dist/shoestring-dev.js'
83 }
84 },
85
86 uglify: {
87 all: {
88 options: {
89 banner: '<%= meta.banner %>',
90 report: 'gzip'
91 },
92
93 files: {
94 'dist/shoestring.min.js': ['dist/shoestring.js'],
95 'dist/shoestring-dev.min.js': ['dist/shoestring-dev.js']
96 }
97 }
98 },
99
100 jshint: {
101 all: {
102 options: {
103 jshintrc: ".jshintrc",
104 },
105
106 src: ['Gruntfile.js', 'src/**/*.js']
107 }
108 },
109 watch: {
110 js: {
111 files: [
112 'src/**'
113 ],
114 tasks: 'default'
115 }
116 }
117 });
118
119 spawn = require('child_process').spawn;
120
121 grunt.registerTask('docs', function() {
122 var doxx, srcs, args = [], done = this.async();
123
124 for(var i in arguments){
125 args.push(arguments[i]);
126 }
127
128 srcs = args.length ? srcs = args.join(":") : "src";
129
130 doxx = spawn( 'node', ['node_modules/.bin/doxx', '--source', srcs, '--target', 'dist/docs']);
131
132 doxx.on( 'close', function( code ) {
133 console.log( "doxx completed with exit code: " + code );
134 done();
135 });
136 });
137
138 // These plugins provide necessary tasks.
139 grunt.loadNpmTasks('grunt-contrib-concat');
140 grunt.loadNpmTasks('grunt-contrib-uglify');
141 grunt.loadNpmTasks('grunt-contrib-qunit');
142 grunt.loadNpmTasks('grunt-contrib-jshint');
143 grunt.loadNpmTasks('grunt-contrib-requirejs');
144 grunt.loadNpmTasks('grunt-contrib-watch');
145
146 // Default task.
147 grunt.registerTask('build', 'requirejs concat uglify'.split(' ') );
148 grunt.registerTask('test', 'jshint qunit'.split(' ') );
149 grunt.registerTask('default', 'build test'.split(' ') );
150 };