Skip to content

Commit

Permalink
Hooking into ionic gulpfile directly instead of ionic-app-lib, closes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
lathonez committed Mar 11, 2016
1 parent 874948b commit 6a4b17c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 156 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
## Install & Start

```bash
npm install -g ionic-app-lib
git clone https://github.com/lathonez/clicker.git
cd clicker
npm install # or `npm run reinstall` if you get an error
Expand Down Expand Up @@ -45,4 +44,4 @@ Issues and PRs are welcome, see the [roadmap sticky](https://github.com/lathonez
## Acks

* This project is essential a fork of [Angular 2 Seed](https://github.com/mgechev/angular2-seed) and would not be possible without it
* @ric9176 and @DanielaGSB for E2E tests (#50)
* @ric9176 and @DanielaGSB for E2E tests (#50)
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
"tslint": "3.5.0",
"tslint-eslint-rules": "1.0.1",
"typescript": "1.8.2",
"typings": "0.7.7"
"typings": "0.7.7",
"webpack": "^1.12.14"
},
"name": "clicker",
"description": "clicker: An Ionic project",
Expand All @@ -62,8 +63,8 @@
"android"
],
"scripts": {
"e2e": "./node_modules/protractor/bin/protractor test/protractor.conf.js",
"postinstall": "npm link ionic-app-lib && typings install",
"e2e": "./node_modules/protractor/bin/protractor test/protractor.conf.js",
"postinstall": "typings install",
"start": "ionic serve",
"test": "gulp --gulpfile test/gulpfile.ts --cwd ./ test",
"test.watch": "gulp --gulpfile test/gulpfile.ts --cwd ./ test.watch.build",
Expand Down
158 changes: 7 additions & 151 deletions test/gulpfile.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@
import { APP_DIR, DIST_DIR, E2E_DEST, JS_DEST, TEST_DIR, TYPINGS_DIR, TEST_DEST } from './config';
import * as CONFIG from './config';
import { join, extname } from 'path';
import { join } from 'path';
import * as chalk from 'chalk';
import * as del from 'del';
import * as gulp from 'gulp';
import * as ionicAppLib from 'ionic-app-lib';
import * as karma from 'karma';
import * as loadPlugins from 'gulp-load-plugins';
import * as runSequence from 'run-sequence';
import * as util from 'gulp-util';

let plugins: any = loadPlugins();
let ionicBuild: any = ionicAppLib.v2.build;
let ionicBuildOptions: any = {
appDirectory: process.cwd(),
watch: false,
config: require(join(process.cwd(), 'ionic.config.js')),
};

let srcCounts: any = {};
let destCounts: any = {};
let ionicGulpfile: any = {
gulpfile: require(join(process.cwd(), 'gulpfile.js'))
};

function buildE2E (): any {
'use strict';
Expand All @@ -44,53 +38,6 @@ function buildE2E (): any {
.pipe(gulp.dest(E2E_DEST));
};

// this does the exact same thing as `ionic serve` (wrt building fonts)
function buildFonts(): any {
'use strict';

return ionicBuild.fonts(ionicBuildOptions);
}

// this does the exact same thing as `ionic serve` (wrt building html)
function buildHTML(): any {
'use strict';

return ionicBuild.html(ionicBuildOptions);
}

// ionic's build functions are async but don't give us any callbacks
function buildLocker(done: Function): any {
'use strict';

let unlocked: boolean = true;

let recurse: Function = function(): void {
buildLocker(done);
};

count(null, true)
.then(() => {
if (!compareCounts('html')) unlocked = false;
if (!compareCounts('fonts')) unlocked = false;
if (!compareCounts('sass')) unlocked = false;

if (!unlocked) {
setTimeout(recurse, 100);
return;
}

util.log('test.build.locker:' + chalk.green(' unlocked'));
done();
});
}

// this does the exact same thing as `ionic serve` (wrt building sass)
function buildSass(): any {
'use strict';

return ionicBuild.sass(ionicBuildOptions);
}

// compile typescript into individual files, project directoy structure is replicated under www/build/test
function buildTypescript(): any {
'use strict';
Expand Down Expand Up @@ -122,79 +69,6 @@ function clean(): any {
});
}

// delete everything used in our test cycle here __apart__ from HTML
// -- ionic caches html so we can't delete it when watching
function cleanIgnoreHTML(): any {
'use strict';

// You can use multiple globbing patterns as you would with `gulp.src`
return del([DIST_DIR + '/**/*', '!' + JS_DEST, '!' + DIST_DIR + '/**/*.html'], {'nodir': true}).then((paths: Array<any>) => {
util.log('Deleted', chalk.yellow(paths && paths.length + ' files' || '-'));
});
}

// check that source and dest counts are equal for the given type (html|fonts|sass)
function compareCounts(count: string): boolean {
'use strict';

if (srcCounts[count] !== destCounts[count]) {
util.log('test.build.locker: ' + chalk.yellow(destCounts[count] + '/' + srcCounts[count] + ' ' + count));
return false;
}

return true;
}

// count files in a src pattern, storing results in a global counter
function count(done: Function, dest?: boolean): any {
'use strict';

let countObj: any = srcCounts;
let src: Array<any> = [
ionicBuildOptions.config.paths.html.src[0],
ionicBuildOptions.config.paths.fonts.src[0],
ionicBuildOptions.config.paths.sass.src[0],
];

if (dest) {
// overwrite for dest mode
countObj = destCounts;
src = [
join(ionicBuildOptions.config.paths.html.dest, '**/*.html'),
join(ionicBuildOptions.config.paths.fonts.dest, '**/*.+(ttf|woff|woff2)'),
join(ionicBuildOptions.config.paths.sass.dest, '**/*.css'),
];
}

countObj.html = 0;
countObj.fonts = 0;
countObj.sass = 0;

return new Promise((resolve: Function, reject: Function) => {
gulp.src(src)
.pipe(plugins.tap((file: any, t: any) => {
switch (extname(file.path)) {
case '.html':
countObj.html ++;
break;
case '.ttf':
case '.woff':
case '.woff2':
countObj.fonts ++;
break;
case '.scss':
case '.css':
countObj.sass ++;
break;
default:
throw 'unhandled extension: ' + extname(file.path);
}
}))
.on('error', reject)
.on('end', resolve);
});
}

// run tslint against all typescript
function lint(): any {
'use strict';
Expand Down Expand Up @@ -239,28 +113,22 @@ function watchTest(): any {
'use strict';

plugins.watch(join(APP_DIR, '**/*.ts'), () => {
gulp.start('test.watch.rebuild');
gulp.start('test.watch.build');
});
};

gulp.task('test.build.e2e', buildE2E);
gulp.task('test.build.fonts', buildFonts);
gulp.task('test.build.html', buildHTML);
gulp.task('test.build.locker', buildLocker);
gulp.task('test.build.sass', buildSass);
gulp.task('test.build.typescript', buildTypescript);
gulp.task('test.clean', clean);
gulp.task('test.clean.ignoreHTML', cleanIgnoreHTML);
gulp.task('test.srcCount', count);
gulp.task('test.karma', startKarma);
gulp.task('test.karma.debug', debugKarma);
gulp.task('test.lint', lint);
gulp.task('test.watch', watchTest);

gulp.task('test.build', (done: any) => {
runSequence(
['test.lint', 'test.srcCount'],
['test.build.html', 'test.build.fonts', 'test.build.sass', 'test.build.locker'],
['test.lint', 'test.clean'],
['sass', 'copy.fonts', 'copy.html'],
'test.build.typescript',
done
);
Expand All @@ -269,17 +137,6 @@ gulp.task('test.build', (done: any) => {
// first time round we should nuke everything
gulp.task('test.watch.build', (done: any) => {
runSequence(
'test.clean',
'test.build',
'test.watch',
done
);
});

// subsequent triggers (watch changes), we don't want to delete HTML as Ionic caches it (and it wont be rebuilt!)
gulp.task('test.watch.rebuild', (done: any) => {
runSequence(
'test.clean.ignoreHTML',
'test.build',
'test.watch',
done
Expand All @@ -288,7 +145,6 @@ gulp.task('test.watch.rebuild', (done: any) => {

gulp.task('test', (done: any) => {
runSequence(
'test.clean',
'test.build',
'test.karma',
done
Expand Down

0 comments on commit 6a4b17c

Please sign in to comment.