Skip to content

Instantly share code, notes, and snippets.

@dbankier
Created July 6, 2015 08:27
Show Gist options
  • Save dbankier/2d0b58ebc99dabbc01d0 to your computer and use it in GitHub Desktop.
Save dbankier/2d0b58ebc99dabbc01d0 to your computer and use it in GitHub Desktop.
Nativescript with Jade, SCSS and Babel
// modified from this: https://github.com/emiloberg/nativescript-emulator-reload
// all sources
var babelSrc = [ 'src/**/*.js', '!src/tns_modules', '!src/tns_modules/**', '!src/node_modules', '!src/node_modules/**' ];
var jadeSrc = [ 'src/**/*.jade' ];
var sassSrc = [ 'src/**/*.scss' ];
var resources = [ 'src/{App_Resources,tns_modules,node_modules}/**', 'src/package.json'];
// Which emulator to run?
// iPhone-4s, iPhone-5, iPhone-5s, iPhone-6-Plus, iPhone-6,
// iPad-2, iPad-Retina, iPad-Air, Resizable-iPhone, Resizable-iPa
var emulator = 'iPhone-5';
var gulp = require('gulp');
var spawn = require('child_process').spawn;
var babel = require('gulp-babel');
var jade = require('gulp-jade');
var sass = require('gulp-sass');
var rename = require('gulp-rename');
var mergeStream = require('merge-stream');
var del = require('del');
gulp.task('emulate', function(cb) {
var child = spawn('tns', ['emulate', 'ios', '--device', emulator], {cwd: process.cwd()});
var stdout = '';
var stderr = '';
child.stdout.setEncoding('utf8');
child.stdout.on('data', function (data) {
stdout += data;
console.log(data);
});
child.stderr.setEncoding('utf8');
child.stderr.on('data', function (data) {
stderr += data;
console.log(chalk.red(data));
});
child.on('close', function(code) {
console.log('Done with exit code', code);
});
cb();
});
gulp.task('clean', function(cb) {
del("app/**", cb);
});
function compileBabel(src) {
return gulp.src(src)
.pipe(babel({ stage: 1, blacklist: ["strict"] }))
.pipe(gulp.dest('app'));
}
function compileJade(src) {
return gulp.src(src)
.pipe(jade({pretty: true}))
.pipe(rename({extname:".xml"}))
.pipe(gulp.dest('app'));
}
function compileSass(src) {
return gulp.src(src)
.pipe(sass().on('error', sass.logError))
.pipe(gulp.dest('app'));
}
function moveResources(src) {
return gulp.src(src)
.pipe(gulp.dest('app'));
}
gulp.task('compile', function() {
return mergeStream(
compileBabel(babelSrc),
compileJade(jadeSrc),
compileSass(sassSrc),
moveResources(resources)
);
});
gulp.task('watch', ['compile', 'emulate'], function(callback) {
gulp.watch(babelSrc, function(e) { compileBabel(e.path); gulp.start('emulate');});
gulp.watch(jadeSrc, function(e) { compileJade(e.path); gulp.start('emulate');});
gulp.watch(sassSrc, function(e) { compileSass(e.path); gulp.start('emulate');});
gulp.watch(resources, function(e) { moveResources(e.path); gulp.start('emulate');});
});
gulp.task('default', ['compile'], function() { });
@dbankier
Copy link
Author

dbankier commented Jul 6, 2015

If it is unclear, everything goes in the src directory instead of app.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment