gulpjs / gulp

A toolkit to automate & enhance your workflow
https://gulpjs.com
MIT License
32.98k stars 4.23k forks source link

Issue when copy fnt (bitmap font for Phaser) file #1370

Closed zhouhao27 closed 8 years ago

zhouhao27 commented 8 years ago

Here is my gulp file:

gulp.task('assets', function() {    
    return gulp.src(srcs.assets)
        .pipe(changed(dests.assets))
        .pipe(gulp.dest(dests.assets))
        .pipe(browserSync.reload({stream : true}));
});

Basically it just copy assets folder to my build folder. The structure of assets folder is:

assets -- |--- images |--- sounds |--- fonts

There is no problem if I remove the fonts folder. But I got the following error message when I added the fonts folder with the .fnt file.

events.js:85 throw er; // Unhandled 'error' event ^ SyntaxError: Unexpected token < at Function (native) at template (/usr/local/lib/node_modules/slush-phaser-typescript-scss/node_modules/gulp-template/node_modules/lodash/dist/lodash.js:6306:22) at Transform._transform (/usr/local/lib/node_modules/slush-phaser-typescript-scss/node_modules/gulp-template/index.js:19:31) at Transform._read (/usr/local/lib/node_modules/slush-phaser-typescript-scss/node_modules/gulp-template/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:184:10) at Transform._write (/usr/local/lib/node_modules/slush-phaser-typescript-scss/node_modules/gulp-template/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:172:12) at doWrite (/usr/local/lib/node_modules/slush-phaser-typescript-scss/node_modules/gulp-template/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:237:10) at writeOrBuffer (/usr/local/lib/node_modules/slush-phaser-typescript-scss/node_modules/gulp-template/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:227:5) at Transform.Writable.write (/usr/local/lib/node_modules/slush-phaser-typescript-scss/node_modules/gulp-template/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:194:11) at write (/usr/local/lib/node_modules/slush-phaser-typescript-scss/node_modules/gulp/node_modules/vinyl-fs/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:623:24) at flow (/usr/local/lib/node_modules/slush-phaser-typescript-scss/node_modules/gulp/node_modules/vinyl-fs/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:632:7)

The fnt file is:

<font>
  <info face="font" size="72" bold="0" italic="0" charset="" unicode="" stretchH="100" smooth="1" aa="1" padding="2,2,2,2" spacing="0,0" outline="0"/>
  <common lineHeight="80" base="57" scaleW="361" scaleH="512" pages="1" packed="0"/>
  <pages>
    <page id="0" file="font.png"/>
  </pages>
  <chars count="80">
    <char id="32" x="0" y="0" width="0" height="0" xoffset="1" yoffset="5" xadvance="20" page="0" chnl="15"/>
  </chars>
  <kernings count="96">
    <kerning first="32" second="65" amount="-4"/>
    <kerning first="121" second="46" amount="-5"/>
  </kernings>
</font>

Can anybody suggest what the problem is? Thanks.

yocontra commented 8 years ago

This is coming from an invalid template being passed to gulp-template, all of the info is in the stacktrace

at Transform._transform (/usr/local/lib/node_modules/slush-phaser-typescript-scss/node_modules/gulp-template/index.js:19:31)
zhouhao27 commented 8 years ago

But I didn't use gulp-template in my generated gulpfile. Why got this error message?

Here is my complete gulpfile.js:

 var gulp = require('gulp');

// plug-ins
var tslint      = require('gulp-tslint');
var changed     = require('gulp-changed');
var minifyHtml  = require('gulp-minify-html');
var concat      = require('gulp-concat');
var stripDebug  = require('gulp-strip-debug');
var uglify      = require('gulp-uglify');
var autoprefix  = require('gulp-autoprefixer');
var minifyCSS   = require('gulp-minify-css');
var sass        = require('gulp-sass');
var typescript  = require('gulp-typescript');
var browserSync = require('browser-sync');
var del         = require('del');
var runSequence = require('run-sequence');

// definition of source paths
var srcs = {
  scripts : 'src/scripts/**/*.ts',
  html  : ['src/*.html','src/templates/*.html'],
  styles    : 'src/styles/**/*.scss',
  assets    : 'src/assets/**/*',
  libs  : ['src/libs/phaser/build/phaser.min.js']
};

var dests = {
  base  : 'build',
  libs  : 'build/libs/',
  assets    : 'build/assets/',
  scripts : 'build/scripts/',
  styles    : 'build/styles/'
};

// browser sychnoization
gulp.task('browserSync', function() {
  browserSync({
    server: {
      baseDir: dests.base
    }
  });
});

// clean
gulp.task('clean', function() {
  return del([dests.base]);
});

// copy files needed
gulp.task('copy', function() {
  return gulp.src(srcs.libs)
    .pipe(gulp.dest(dests.libs))
    .pipe(browserSync.reload({stream: true}));
});

// TS lint task
gulp.task('tslint', function(){
      return gulp.src(srcs.scripts)
        .pipe(tslint())
        .pipe(tslint.report('verbose'));
});

// copy assets
gulp.task('assets', function() {    
  return gulp.src(srcs.assets)
    .pipe(changed(dests.assets))
    .pipe(gulp.dest(dests.assets))
    .pipe(browserSync.reload({stream : true}));
});

// minify html
gulp.task('html', function() {
  var htmlDest = './build';

  return gulp.src(srcs.html)
    .pipe(changed(dests.base))
    .pipe(minifyHtml())
    .pipe(gulp.dest(htmlDest))
    .pipe(browserSync.reload({stream : true}));
});

// JS concat, strip debugging and minify
gulp.task('scripts', function() {
  return gulp.src(srcs.scripts)
    .pipe(typescript({
      declarationFiles: true,
      noExternalResolve: false,
      sortOutput: true
    }))
    .pipe(concat('script.min.js'))
    .pipe(stripDebug())
    .pipe(uglify())
    .pipe(gulp.dest(dests.scripts))
    .pipe(browserSync.reload({stream : true}));
});

// CSS concat, auto-prefix and minify
gulp.task('styles', function() {
    return gulp.src(srcs.styles)
      .pipe(sass())
      .pipe(concat('styles.min.css'))
      .pipe(autoprefix('last 2 versions'))
      .pipe(minifyCSS())
      .pipe(gulp.dest(dests.styles))
      .pipe(browserSync.reload({stream : true}));
});

// build only
gulp.task('build', ['tslint', 'copy', 'assets','html','scripts','styles','browserSync'], function() {
});

// default task
gulp.task('default', function(done) {
    runSequence('clean', 'build', function() {
    gulp.watch(srcs.html,   ['html']);
    gulp.watch(srcs.assets, ['assets']);
    gulp.watch(srcs.scripts,['scripts']);
    gulp.watch(srcs.styles, ['styles']);
        done();
    });
});