|
| 1 | +const gulp = require('gulp'); |
| 2 | +const rename = require('gulp-rename'); |
| 3 | +const replace = require('gulp-string-replace') |
| 4 | +const debug = require('gulp-debug'); |
| 5 | +const del = require('del'); |
| 6 | + |
| 7 | +//Paths |
| 8 | +const SRC = 'src/'; |
| 9 | +const DEST = 'app/'; |
| 10 | + |
| 11 | +function removeTns (path) { |
| 12 | + path.basename = path.basename.replace('.tns', ''); |
| 13 | +} |
| 14 | + |
| 15 | +function removePhone (path) { |
| 16 | + path.basename = path.basename.replace('.phone', ''); |
| 17 | +} |
| 18 | + |
| 19 | +gulp.task('clean.Dist', () => { |
| 20 | + return del([ |
| 21 | + 'app/**/*', |
| 22 | + '!**/vendor.ts', |
| 23 | + '!**/vendor-platform.android.ts', |
| 24 | + '!**/vendor-platform.ios.ts' |
| 25 | + ]); |
| 26 | +}); |
| 27 | + |
| 28 | +gulp.task('resources.App_Resources', () => { |
| 29 | + return gulp.src(['App_Resources/**/*'], {follow: true}) |
| 30 | + .pipe(gulp.dest(`${DEST}App_Resources`)); |
| 31 | +}); |
| 32 | + |
| 33 | +gulp.task('resources.Assets', () => { |
| 34 | + return gulp.src([`${SRC}**/*`, `!${SRC}app/`, `!${SRC}test/`, '!**/*.spec.*', '!**/*.js', '!**/*.ts', '!**/*.scss', '!**/*.html'], {follow: true}) |
| 35 | + // .pipe(debug({title: 'resources.Assets'})) |
| 36 | + .pipe(gulp.dest(DEST)); |
| 37 | +}); |
| 38 | + |
| 39 | +gulp.task('project.Typescript', () => { |
| 40 | + return gulp.src([`${SRC}**/*.ts`, '!**/*.tns.*', '!**/*.spec.*'], {follow: true}) |
| 41 | + // .pipe(debug({title: 'project.Typescript'})) |
| 42 | + .pipe(gulp.dest(DEST)); |
| 43 | +}); |
| 44 | + |
| 45 | +gulp.task('project.Styles', () => { |
| 46 | + return gulp.src([`${SRC}**/*.scss`, '!**/*.tns.*'], {follow: true}) |
| 47 | + .pipe(gulp.dest(DEST)); |
| 48 | +}); |
| 49 | + |
| 50 | +gulp.task('tns.Typescript', () => { |
| 51 | + return gulp.src([`${SRC}**/*.tns.ts`], {follow: true}) |
| 52 | + .pipe(rename(removeTns)) |
| 53 | + // .pipe(debug({title: 'tns.Typescript'})) |
| 54 | + .pipe(gulp.dest(DEST, {overwrite: true})); |
| 55 | +}); |
| 56 | + |
| 57 | +gulp.task('tns.Templates', () => { |
| 58 | + return gulp.src([`${SRC}**/*.tns.html`, `${SRC}**/*.tns.ios.html`, `${SRC}**/*.tns.android.html`], {follow: true}) |
| 59 | + .pipe(rename(removeTns)) |
| 60 | + // .pipe(debug({title: 'tns.Templates'})) |
| 61 | + .pipe(gulp.dest(DEST, {overwrite: true})); |
| 62 | +}); |
| 63 | + |
| 64 | +gulp.task('tns.Styles', () => { |
| 65 | + return gulp.src([`${SRC}**/*.tns.scss`, `${SRC}**/*.tns.ios.scss`, `${SRC}**/*.tns.android.scss`], {follow: true}) |
| 66 | + .pipe(rename(removeTns)) |
| 67 | + // .pipe(debug({title: 'tns.Styles'})) |
| 68 | + .pipe(gulp.dest(DEST, {overwrite: true})); |
| 69 | +}); |
| 70 | + |
| 71 | +gulp.task('phone.Typescript', () => { |
| 72 | + return gulp.src([`${SRC}**/*.tns.phone.ts`], {follow: true}) |
| 73 | + .pipe(rename(removeTns)) |
| 74 | + .pipe(rename(removePhone)) |
| 75 | + // .pipe(debug({title: 'phone.Typescript'})) |
| 76 | + .pipe(gulp.dest(DEST, {overwrite: true})); |
| 77 | +}); |
| 78 | + |
| 79 | +gulp.task('phone.Templates', () => { |
| 80 | + return gulp.src([`${SRC}**/*.tns.phone.html`, `${SRC}**/*.tns.ios.phone.html`, `${SRC}**/*.tns.android.phone.html`], {follow: true}) |
| 81 | + .pipe(rename(removeTns)) |
| 82 | + .pipe(rename(removePhone)) |
| 83 | + // .pipe(debug({title: 'phone.Templates'})) |
| 84 | + .pipe(gulp.dest(DEST, {overwrite: true})); |
| 85 | +}); |
| 86 | + |
| 87 | +gulp.task('phone.Styles', () => { |
| 88 | + return gulp.src([`${SRC}**/*.tns.phone.scss`, `${SRC}**/*.tns.ios.phone.scss`, `${SRC}**/*.tns.android.phone.scss`], {follow: true}) |
| 89 | + .pipe(rename(removeTns)) |
| 90 | + .pipe(rename(removePhone)) |
| 91 | + // .pipe(debug({title: 'phone.Styles'})) |
| 92 | + .pipe(gulp.dest(DEST, {overwrite: true})); |
| 93 | +}); |
| 94 | + |
| 95 | +gulp.task( |
| 96 | + 'build.Default', |
| 97 | + gulp.series( |
| 98 | + 'clean.Dist', |
| 99 | + 'resources.App_Resources', |
| 100 | + 'resources.Assets', |
| 101 | + 'project.Typescript', |
| 102 | + 'project.Styles', |
| 103 | + 'tns.Templates', |
| 104 | + 'tns.Styles', |
| 105 | + 'tns.Typescript' |
| 106 | + ) |
| 107 | +); |
| 108 | + |
| 109 | +gulp.task( |
| 110 | + 'build.Phone', |
| 111 | + gulp.series( |
| 112 | + 'build.Default', |
| 113 | + 'phone.Typescript', |
| 114 | + 'phone.Templates', |
| 115 | + 'phone.Styles' |
| 116 | + ) |
| 117 | +); |
| 118 | + |
| 119 | +/** |
| 120 | + * For non webpack builds, scss needs to be converted to css |
| 121 | + */ |
| 122 | +gulp.task('tns.ComponentStyles', () => { |
| 123 | + return gulp.src([`${DEST}/**/*.component.ts`], {follow: true}) |
| 124 | + .pipe(replace('.scss\'', '.css\'', { logs: { enabled: false }})) |
| 125 | + // .pipe(debug({title: 'tns.ComponentStyles'})) |
| 126 | + .pipe(gulp.dest(DEST, {overwrite: true})); |
| 127 | +}); |
| 128 | + |
| 129 | +gulp.task( |
| 130 | + 'build.cli.Default', |
| 131 | + gulp.series( |
| 132 | + 'build.Default', |
| 133 | + 'tns.ComponentStyles' |
| 134 | + ) |
| 135 | +); |
| 136 | + |
| 137 | +gulp.task( |
| 138 | + 'build.cli.Phone', |
| 139 | + gulp.series( |
| 140 | + 'build.Phone', |
| 141 | + 'tns.ComponentStyles' |
| 142 | + ) |
| 143 | +); |
| 144 | + |
| 145 | +gulp.task('tns.Livesync', () => { |
| 146 | + return gulp.watch([`${SRC}**/*.tns.html`, `${SRC}/**/*.tns.scss`, `${SRC}/**/*.component.ts`]) |
| 147 | + .on('change', (file) => { |
| 148 | + var outputDest = file.replace(SRC, DEST); |
| 149 | + outputDest = outputDest.substring(0, outputDest.lastIndexOf('/')); |
| 150 | + gulp.src([file]) |
| 151 | + .pipe(rename(removeTns)) |
| 152 | + .pipe(replace('.scss\'', '.css\'', { logs: { enabled: false }})) |
| 153 | + .pipe(debug({title: 'tns.Livesync'})) |
| 154 | + .pipe(gulp.dest(outputDest, {overwrite: true})); |
| 155 | + }); |
| 156 | +}); |
| 157 | + |
| 158 | +gulp.task('tns.Livesync.Phone', () => { |
| 159 | + return gulp.watch([`${SRC}**/*.tns.phone.html`, `${SRC}/**/*.tns.phone.scss`, `${SRC}/**/*.component.ts`]) |
| 160 | + .on('change', (file) => { |
| 161 | + var outputDest = file.replace(SRC, DEST); |
| 162 | + outputDest = outputDest.substring(0, outputDest.lastIndexOf('/')); |
| 163 | + gulp.src([file]) |
| 164 | + .pipe(rename(removeTns)) |
| 165 | + .pipe(rename(removePhone)) |
| 166 | + .pipe(replace('.scss\'', '.css\'', { logs: { enabled: false }})) |
| 167 | + .pipe(debug({title: 'tns.Livesync.Phone'})) |
| 168 | + .pipe(gulp.dest(outputDest, {overwrite: true})); |
| 169 | + }); |
| 170 | +}); |
0 commit comments