Parcourir la source

update build setup

Evan You il y a 12 ans
Parent
commit
d704fb52d5
8 fichiers modifiés avec 36 ajouts et 54 suppressions
  1. 1 13
      .jshintrc
  2. 5 3
      Gruntfile.js
  3. 4 3
      package.json
  4. 6 1
      tasks/build.js
  5. 3 3
      tasks/dev.js
  6. 10 6
      tasks/instrument.js
  7. 7 6
      tasks/release.js
  8. 0 19
      tasks/size.js

+ 1 - 13
.jshintrc

@@ -10,18 +10,6 @@
     "node": true,
     "laxbreak": true,
     "globals": {
-        "console": true,
-        "it": true,
-        "describe": true,
-        "before": true,
-        "after": true,
-        "assert": true,
-        "mock": true,
-        "Vue": true,
-        "$": true,
-        "mockHTMLEvent": true,
-        "mockMouseEvent": true,
-        "mockKeyEvent": true,
-        "casper": true
+        "console": true
     }
 }

+ 5 - 3
Gruntfile.js

@@ -9,7 +9,10 @@ module.exports = function( grunt ) {
                 reporter: require('jshint-stylish'),
                 jshintrc: true
             },
-            dev: {
+            build: {
+                src: ['Gruntfile.js', 'tasks/*.js']
+            },
+            src: {
                 src: 'src/**/*.js'
             },
             test: {
@@ -61,8 +64,7 @@ module.exports = function( grunt ) {
     grunt.registerTask( 'default', [
         'jshint',
         'build',
-        'test',
-        'size'
+        'test'
     ])
     
 }

+ 4 - 3
package.json

@@ -24,14 +24,15 @@
   "devDependencies": {
     "grunt": "~0.4.2",
     "grunt-contrib-watch": "~0.5.3",
-    "grunt-component-build": "~0.4.1",
     "grunt-contrib-jshint": "~0.8.0",
-    "grunt-contrib-uglify": "~0.2.7",
     "grunt-mocha": "~0.4.6",
     "jscoverage": "~0.3.8",
     "jshint-stylish": "~0.1.4",
     "semver": "~2.2.1",
     "shell-task": "~0.1.1",
-    "load-grunt-tasks": "~0.2.1"
+    "map-stream": "0.0.4",
+    "uglify-js": "~2.4.8",
+    "vinyl-fs": "git://github.com/wearefractal/vinyl-fs",
+    "gulp-component": "~0.1.3"
   }
 }

+ 6 - 1
tasks/build.js

@@ -60,11 +60,16 @@ function uglify (file, cb) {
 function gzip (file, cb) {
     zlib.gzip(file.contents, function (err, buf) {
         file.contents = buf
+        file.path = file.path + '.gz'
         cb(err, file)
     })
 }
 
 function size (file, cb) {
-    console.log(file.relative + ': ' + (file.contents.length / 1024).toFixed(2) + 'kb')
+    console.log(blue(file.relative + ': ') + (file.contents.length / 1024).toFixed(2) + 'kb')
     cb(null, file)
+}
+
+function blue (str) {
+    return '\x1b[1m\x1b[34m' + str + '\x1b[39m\x1b[22m'
 }

+ 3 - 3
tasks/dev.js

@@ -1,14 +1,14 @@
-var gulp = require('vinyl-fs'),
+var fs = require('vinyl-fs'),
     component = require('gulp-component')
 
 module.exports = function (grunt) {
     grunt.registerTask('dev', function () {
-        gulp.src('./component.json')
+        fs.src('./component.json')
             .pipe(component.scripts({
                 standalone: 'Vue',
                 name: 'vue'
             }))
-            .pipe(gulp.dest('./dist'))
+            .pipe(fs.dest('./dist'))
             .on('end', this.async())
     })
 }

+ 10 - 6
tasks/instrument.js

@@ -1,15 +1,19 @@
-var gulp = require('vinyl-fs'),
+var fs = require('vinyl-fs'),
     component = require('gulp-component'),
-    jsc = require('gulp-jscoverage')
+    jsc = require('jscoverage'),
+    map = require('map-stream')
 
 module.exports = function (grunt) {
     grunt.registerTask('instrument', function () {
-        gulp.src('./component.json')
+        fs.src('./component.json')
             .pipe(component.scripts({
-                name: 'vue.test'
+                name: 'vue.test-cov'
             }))
-            .pipe(jsc())
-            .pipe(gulp.dest('./test'))
+            .pipe(map(function (file, cb) {
+                file.contents = new Buffer(jsc.process(file.path, file.contents.toString()))
+                cb(null, file)
+            }))
+            .pipe(fs.dest('./test'))
             .on('end', this.async())
     })
 }

+ 7 - 6
tasks/release.js

@@ -6,10 +6,11 @@ module.exports = function (grunt) {
 
     grunt.registerTask('version', function (version) {
         ;['package', 'bower', 'component'].forEach(function (file) {
-            file = './' + file + '.json'
+            file = file + '.json'
             var json = grunt.file.read(file)
             json = json.replace(/"version"\s*:\s*"(.+?)"/, '"version": "' + version + '"')
             grunt.file.write(file, json)
+            console.log('updated ' + blue(file))
         })
     })
 
@@ -42,11 +43,7 @@ module.exports = function (grunt) {
             output: process.stdout
         }).question('Releasing version v' + next + '. Continue? (Y/n)', function (answer) {
             if (!answer || answer.toLowerCase() === 'y') {
-                console.log(
-                    '\n\x1b[1m\x1b[34m' +
-                    'Releasing: v' + next +
-                    '\x1b[39m\x1b[22m'
-                )
+                console.log(blue('Releasing: v' + next))
                 grunt.task.run([
                     'jshint',
                     'build:' + next,
@@ -58,4 +55,8 @@ module.exports = function (grunt) {
             done()
         })
     })
+}
+
+function blue (str) {
+    return '\x1b[1m\x1b[34m' + str + '\x1b[39m\x1b[22m'
 }

+ 0 - 19
tasks/size.js

@@ -1,19 +0,0 @@
-var fs = require('fs'),
-    min = 'dist/vue.min.js',
-    gz = 'dist/vue.min.js.gz'
-
-module.exports = function (grunt) {
-
-    grunt.registerTask('size', function () {
-        var minSize = (fs.statSync(min).size / 1024).toFixed(2),
-            gzSize = (fs.statSync(gz).size / 1024).toFixed(2)
-        console.log(
-            '\n\x1b[1m\x1b[34m' +
-            'File Sizes:'+
-            '\x1b[39m\x1b[22m'
-        )
-        console.log('Min  : ' + minSize + 'kb')
-        console.log('Gzip : ' + gzSize + 'kb')
-    })
-
-}