From aac547a54c9d92bb925ef1a1d470712ea293c760 Mon Sep 17 00:00:00 2001 From: Yuya Ochiai Date: Sat, 19 Dec 2015 19:52:29 +0900 Subject: [PATCH] Simple build tasks in order to use React --- .gitignore | 1 + gulpfile.js | 43 +++++++++++++++++++++++++++++++++++-------- package.json | 6 +++++- 3 files changed, 41 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index f74010b0..4b30c3e5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ node_modules/ +build/ release/ npm-debug.log diff --git a/gulpfile.js b/gulpfile.js index 8dd12899..23efe061 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -2,12 +2,16 @@ var gulp = require('gulp'); var prettify = require('gulp-jsbeautifier'); +var babel = require('gulp-babel'); +var changed = require('gulp-changed'); +var del = require('del'); var electron = require('electron-connect').server.create({ - path: './src' + path: './build' }); var packager = require('electron-packager'); -var sources = ['**/*.js', '**/*.css', '**/*.html', '!**/node_modules/**', '!release/**']; +var sources = ['**/*.js', '**/*.css', '**/*.html', '!**/node_modules/**', '!build/**', '!release/**']; +var build_dest = 'build'; gulp.task('prettify', ['sync-meta'], function() { gulp.src(sources) @@ -26,6 +30,29 @@ gulp.task('prettify', ['sync-meta'], function() { .pipe(gulp.dest('.')); }); +gulp.task('build', ['build:copy', 'build:jsx']); + +gulp.task('build:clean', function() { + return del(build_dest + '/**/*'); +}); + +gulp.task('build:copy', ['sync-meta'], function() { + return gulp.src(['src/**', '!**/*.jsx']) + .pipe(changed(build_dest)) + .pipe(gulp.dest(build_dest)); +}); + +gulp.task('build:jsx', function() { + return gulp.src(['src/**/*.jsx', '!src/node_modules/**']) + .pipe(changed(build_dest, { + extension: '.js' + })) + .pipe(babel({ + presets: ['react'] + })) + .pipe(gulp.dest(build_dest)); +}); + gulp.task('serve', function() { var options = ['--livereload']; electron.start(options); @@ -38,7 +65,7 @@ gulp.task('serve', function() { function makePackage(platform, arch) { var packageJson = require('./src/package.json'); packager({ - dir: './src', + dir: './' + build_dest, name: packageJson.name, platform: platform, arch: arch, @@ -67,23 +94,23 @@ function makePackage(platform, arch) { }); }; -gulp.task('package', ['sync-meta'], function() { +gulp.task('package', ['build'], function() { makePackage(process.platform, 'all'); }); -gulp.task('package:all', ['sync-meta'], function() { +gulp.task('package:all', ['build'], function() { makePackage('all', 'all'); }); -gulp.task('package:windows', ['sync-meta'], function() { +gulp.task('package:windows', ['build'], function() { makePackage('win32', 'all'); }); -gulp.task('package:osx', ['sync-meta'], function() { +gulp.task('package:osx', ['build'], function() { makePackage('darwin', 'all'); }); -gulp.task('package:linux', ['sync-meta'], function() { +gulp.task('package:linux', ['build'], function() { makePackage('linux', 'all'); }); diff --git a/package.json b/package.json index c14f51fc..27078be1 100644 --- a/package.json +++ b/package.json @@ -7,15 +7,19 @@ "license": "MIT", "scripts": { "postinstall": "cd src && npm install", - "start": "electron src", + "start": "gulp build && electron build", "test": "mocha" }, "devDependencies": { + "babel-preset-react": "^6.3.13", "chromedriver": "^2.20.0", + "del": "^2.2.0", "electron-connect": "^0.3.3", "electron-packager": "^5.1.0", "electron-prebuilt": "^0.35.1", "gulp": "^3.9.0", + "gulp-babel": "^6.1.1", + "gulp-changed": "^1.3.0", "gulp-jsbeautifier": "^1.0.1", "mocha": "^2.3.4", "should": "^8.0.1",