Created
October 9, 2016 19:41
-
-
Save jamlfy/11c6db354762787d6d627ef6760625d6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var gulp = require('gulp'); | |
var replace = require('gulp-replace'); | |
var del = require('del'); | |
var vinylPaths = require('vinyl-paths'); | |
var runSequence = require('run-sequence'); | |
var shell = require('gulp-shell'); | |
var imageResize = require('gulp-image-resize'); | |
var rename = require("gulp-rename"); | |
var SRC = { | |
java : './src/java/*.java', | |
config : './src/config/**/*', | |
images : './src/image/', | |
consts : './src/const.js' | |
}; | |
var BUILD = { | |
android : './android/app/', | |
app : './app/image', | |
consts : './app/' | |
}; | |
var TYPE = { | |
free : '.free', | |
pro : '' | |
}; | |
var NAME = { | |
free : ' - Free', | |
pro : '', | |
domain : [ 'com' , 'myDomain' ] | |
}; | |
var NAME_PATH = '/' + ( TYPE.domain.join('/') ) + '/myApp/'; | |
function change (name){ | |
return function (){ | |
return gulp | |
.src(SRC.consts) | |
.pipe(replace('|*IS*|', (name == 'free').toString())) | |
.pipe(replace('|*DOMAIN*|', TYPE.domain.join('.') )) | |
.pipe(gulp.dest(BUILD.consts)); | |
} | |
} | |
function createJavas (name){ | |
return function (){ | |
return gulp | |
.src(SRC.java) | |
.pipe(replace('|*TYPE*|', TYPE[name] )) | |
.pipe(replace('|*DOMAIN*|', TYPE.domain.join('.') )) | |
.pipe(gulp.dest(BUILD.android + 'src/main/java/' + NAME_PATH + TYPE[name].replace('.', ''))); | |
} | |
} | |
function createConfig (name){ | |
return function (){ | |
return gulp | |
.src(SRC.config) | |
.pipe(replace('|*TYPE*|', TYPE[name] )) | |
.pipe(replace('|*NAME*|', NAME[name] )) | |
.pipe(replace('|*DOMAIN*|', TYPE.domain.join('.') )) | |
.pipe(gulp.dest(BUILD.android)); | |
} | |
} | |
function createImages (name){ | |
return function (){ | |
return gulp | |
.src(SRC.images + name + '/*.png') | |
.pipe(gulp.dest(BUILD.app)); | |
} | |
} | |
function createIcons (name){ | |
return function (){ | |
return gulp | |
.src( SRC.images + 'icon-' + name + '.png' ) | |
.pipe(rename({ | |
basename: "ic_launcher", | |
extname: ".png" | |
})) | |
.pipe(imageResize({ | |
width : 144, | |
height : 144, | |
crop : false, | |
upscale : true | |
})) | |
.pipe(gulp.dest(BUILD.android + 'src/main/res/mipmap-xxhdpi/')) | |
.pipe(imageResize({ | |
width : 96, | |
height : 96, | |
crop : false, | |
upscale : true | |
})) | |
.pipe(gulp.dest(BUILD.android + 'src/main/res/mipmap-xhdpi/')) | |
.pipe(imageResize({ | |
width : 72, | |
height : 72, | |
crop : false, | |
upscale : true | |
})) | |
.pipe(gulp.dest(BUILD.android + 'src/main/res/mipmap-hdpi/')) | |
.pipe(imageResize({ | |
width : 48, | |
height : 48, | |
crop : false, | |
upscale : true | |
})) | |
.pipe(gulp.dest(BUILD.android + 'src/main/res/mipmap-mdpi/')); | |
} | |
} | |
function run (name){ | |
return function (cb){ | |
runSequence('clean', | |
['java' + name, 'config' + name, 'images' + name, 'icons' + name], | |
'const' + name, cb); | |
} | |
} | |
function clean (name){ | |
return function (){ | |
return gulp | |
.src(BUILD.android + name) | |
.pipe(vinylPaths(del)); | |
} | |
} | |
gulp.task('constFree', change('free')); | |
gulp.task('constPro', change('pro')); | |
gulp.task('javaFree', createJavas('free')); | |
gulp.task('javaPro', createJavas('pro')); | |
gulp.task('configFree', createConfig('free')); | |
gulp.task('configPro', createConfig('pro')); | |
gulp.task('imagesFree', createImages('free')); | |
gulp.task('imagesPro', createImages('pro')); | |
gulp.task('iconsFree', createIcons('free')); | |
gulp.task('iconsPro', createIcons('pro')); | |
gulp.task('clean-images', clean('src/res/**/*.png')); | |
gulp.task('clean-java', clean('src/main/java/**/*.java')); | |
gulp.task('clean', ['clean-images', 'clean-java']); | |
gulp.task('apk', shell.task([ './gradlew assembleRelease' ],{ cwd : './android' })); | |
gulp.task('free', run('Free')); | |
gulp.task('default', run('Pro')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment