Closed lain-me closed 8 years ago
Actually, I have checked that everything is already in ionic2: https://github.com/driftyco/ionic/blob/v2.0.0-beta.11/gulpfile.js
Sections semver + github.releases + packageJson could be reused.
OK, I have made something for own usage, if somebody needs it:
var gulp = require('gulp'),
gulpWatch = require('gulp-watch'),
del = require('del'),
runSequence = require('run-sequence'),
fs = require("fs"),
rename = require('gulp-regex-rename'),
replace = require('gulp-replace'),
path = require('path'),
debug = require('gulp-debug'),
argv = process.argv,
through2 = require('through2');
bump = require('gulp-cordova-bump'),
prompt = require('gulp-prompt');
/**
* Ionic hooks
* Add ':before' or ':after' to any Ionic project command name to run the specified
* tasks before or after the command.
*/
gulp.task('serve:before', ['watch']);
gulp.task('emulate:before', ['build']);
gulp.task('deploy:before', ['build']);
gulp.task('build:before', ['build']);
gulp.task('build:after', ['copyDebugApk']);
gulp.task('copyDebugApk', function() {
var packageJSON = require('./package.json');
return gulp
.src('./platforms/android/build/outputs/apk/android-debug.apk')
.pipe(rename(/android-debug\.apk/, 'my_app_v' + packageJSON.version + '.apk'))
.pipe(gulp.dest('./build-output'));
});
// we want to 'watch' when livereloading
var shouldWatch = argv.indexOf('-l') > -1 || argv.indexOf('--livereload') > -1;
gulp.task('run:before', [shouldWatch ? 'watch' : 'build']);
/**
* Ionic Gulp tasks, for more information on each see
* https://github.com/driftyco/ionic-gulp-tasks
*
* Using these will allow you to stay up to date if the default Ionic 2 build
* changes, but you are of course welcome (and encouraged) to customize your
* build however you see fit.
*/
var buildBrowserify = require('ionic-gulp-browserify-typescript');
var buildSass = require('ionic-gulp-sass-build');
var copyHTML = require('ionic-gulp-html-copy');
var copyFonts = require('ionic-gulp-fonts-copy');
var copyScripts = require('ionic-gulp-scripts-copy');
var isRelease = argv.indexOf('--release') > -1;
gulp.task('watch', ['clean'], function (done) {
runSequence(
['sass', 'html', 'fonts', 'scripts'],
function () {
gulpWatch('app/**/*.scss', function () { gulp.start('sass'); });
gulpWatch('app/**/*.html', function () { gulp.start('html'); });
buildBrowserify({ watch: true }).on('end', done);
}
);
});
gulp.task('build', ['clean'], function (done) {
runSequence(
['sass', 'html', 'fonts', 'scripts'],
function () {
buildBrowserify({
minify: isRelease,
browserifyOptions: {
debug: !isRelease
},
uglifyOptions: {
mangle: false
}
}).on('end', done);
}
);
});
gulp.task('sass', [], buildSass);
gulp.task('html', [], copyHTML);
gulp.task('fonts', [], copyFonts);
gulp.task('scripts', [], copyScripts);
gulp.task('clean', function () {
return del('www/build');
});
gulp.task('bump', bump);
gulp.task('test', function() {
return console.log(process.env.GH_TOKEN);
});
gulp.task('publish.github', function () {
var GithubApi = require('github')
var packageJSON = require('./package.json');
var github = new GithubApi({
version: '3.0.0'
});
github.authenticate({
type: 'oauth',
token: process.env.GH_TOKEN
});
console.log("***************************************************");
console.log("Starting to make github release v" + packageJSON.version);
console.log("***************************************************");
return gulp.src('package.json')
.pipe(prompt.prompt({
type: 'input',
name: 'msg',
message: 'Enter massage for the release (' + packageJSON.version + ')?'
}, function (reply) {
console.log("***************************************************");
console.log(reply.msg);
console.log("***************************************************");
github.repos.createRelease({
user: 'MyUser',
repo: 'MyRepo',
target_commitish: 'master',
tag_name: 'v' + packageJSON.version,
name: packageJSON.version,
draft: false,
body: reply.msg
});
}));
});
gulp.task('release', ['publish.github']);
The script could benefit from auto apk signing feature (right now I have only debug copy, but work in progress).
I think this is a good option. A feature like this is something we would like to keep in userland. Thanks for supplying this code for others to use!
Ionic is a very advanced tool. Thank you. However, I want to ask yet another feature or your opinion about it.
Many of us who use github for their ionic apps need to maintain versions. In cordova version is kept in config.xml and when compiled to android the same version is used in manifest (unfortunately web apps do not have versions as there is no access to cordova functionality). However, many times a smarter way for version control is needed. For example, if we keep our projects in github we would like to have tags associated with versions. And we need to track independent systems for versions (and also compilation of android app could benefit from compiling to app-name-version.apk
I have first attempt to make versioning a more automatic way: 1 I have created a config.placeholder.xml of the form:
2 Created version file with text: "2.3.10" and 3 Updated gulp file:
However this is first step with three major drawbacks:
git tag --sort=v:refname | tail -1
or even better: libraries that support github releases: https://github.com/Aluxian/gulp-github-releaseionic increase [major,normal,minor]
What do you think about such a feature?