From ea6746d13445297a481d9e50ca807b0cb81f60d2 Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 16 Aug 2018 22:23:03 +0200 Subject: [PATCH] chore(build): refactor --- gulpfile.js | 33 ++++++++++++----------- karma.conf.js | 29 +++++--------------- scripts/build/publish.js | 21 +++++---------- scripts/ci-tests.js | 26 +++++++++++------- src/@ionic-native/core/decorators.spec.ts | 9 +------ src/@ionic-native/core/decorators.ts | 11 ++------ 6 files changed, 51 insertions(+), 78 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index 95ec30094..673537f1e 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,8 +1,8 @@ -"use strict"; +'use strict'; const gulp = require('gulp'), minimist = require('minimist'), - rename = require("gulp-rename"), + rename = require('gulp-rename'), tslint = require('gulp-tslint'), replace = require('gulp-replace'), _ = require('lodash'); @@ -10,41 +10,44 @@ const gulp = require('gulp'), const flagConfig = { string: ['port', 'version', 'ngVersion', 'animations'], boolean: ['dry-run'], - alias: {'p': 'port', 'v': 'version', 'a': 'ngVersion'}, + alias: { p: 'port', v: 'version', a: 'ngVersion' }, default: { port: 8000 } }, - flags = minimist(process.argv.slice(2), flagConfig); /* Docs tasks */ require('./scripts/docs/gulp-tasks')(gulp, flags); gulp.task('lint', () => { - return gulp.src('src/**/*.ts') - .pipe(tslint({ - formatter: "verbose", - configuration: 'tslint.json' - })) + return gulp + .src('src/**/*.ts') + .pipe( + tslint({ + formatter: 'verbose', + configuration: 'tslint.json' + }) + ) .pipe(tslint.report()); }); gulp.task('plugin:create', () => { - if (flags.n && flags.n !== ''){ - - const src = flags.m ? './scripts/templates/wrap-min.tmpl':'./scripts/templates/wrap.tmpl', + if (flags.n && flags.n !== '') { + const src = flags.m + ? './scripts/templates/wrap-min.tmpl' + : './scripts/templates/wrap.tmpl', pluginName = flags.n, spaced = pluginName.replace(/(?!^)([A-Z])/g, ' $1'), kebabCase = _.kebabCase(pluginName); - return gulp.src(src) + return gulp + .src(src) .pipe(replace('{{ PluginName }}', pluginName)) .pipe(replace('{{ Plugin_Name }}', spaced)) .pipe(replace('{{ pluginName }}', _.lowerFirst(pluginName))) .pipe(replace('{{ plugin-name }}', kebabCase)) .pipe(rename('index.ts')) .pipe(gulp.dest('./src/@ionic-native/plugins/' + kebabCase)); - } else { - console.log("Usage is: gulp plugin:create -n PluginName"); + console.log('Usage is: gulp plugin:create -n PluginName'); } }); diff --git a/karma.conf.js b/karma.conf.js index eb10d4d9c..8ff666afe 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -1,18 +1,10 @@ -"use strict"; +'use strict'; module.exports = config => { - const conf = { - frameworks: [ - 'jasmine', - 'karma-typescript' - ], + frameworks: ['jasmine', 'karma-typescript'], - plugins: [ - 'karma-typescript', - 'karma-jasmine', - 'karma-phantomjs-launcher' - ], + plugins: ['karma-typescript', 'karma-jasmine', 'karma-phantomjs-launcher'], preprocessors: { 'src/**/*.ts': ['karma-typescript'] @@ -21,22 +13,18 @@ module.exports = config => { karmaTypescriptConfig: { bundlerOptions: { entrypoints: /\.spec\.ts$/, - transforms: [ - require("karma-typescript-es6-transform")() - ] + transforms: [require('karma-typescript-es6-transform')()] }, compilerOptions: { lib: ['es2015', 'dom'], paths: { - "@ionic-native/core": ["./src/@ionic-native/core"] + '@ionic-native/core': ['./src/@ionic-native/core'] }, baseUrl: '.' } }, - files: [ - { pattern: 'src/**/*.ts', included: true, watched: true } - ], + files: [{ pattern: 'src/**/*.ts', included: true, watched: true }], reporters: ['progress'], @@ -44,12 +32,9 @@ module.exports = config => { colors: true, logLevel: config.INFO, autoWatch: true, - browsers: [ - 'PhantomJS' - ], + browsers: ['PhantomJS'], singleRun: false }; config.set(conf); - }; diff --git a/scripts/build/publish.js b/scripts/build/publish.js index 184dda82d..114bbb7f0 100644 --- a/scripts/build/publish.js +++ b/scripts/build/publish.js @@ -1,11 +1,10 @@ -"use strict"; +'use strict'; // Node module dependencies const fs = require('fs-extra-promise').useFs(require('fs-extra')), queue = require('queue'), path = require('path'), exec = require('child-process-promise').exec; - const ROOT = path.resolve(path.join(__dirname, '../../')), DIST = path.resolve(ROOT, 'dist', '@ionic-native'); @@ -20,15 +19,16 @@ const QUEUE = queue({ }); PACKAGES.forEach(packageName => { - QUEUE.push(done => { - console.log(`Publishing @ionic-native/${packageName}`); const packagePath = path.resolve(DIST, packageName); exec(`npm publish ${packagePath} ${FLAGS}`) .then(() => done()) - .catch((e) => { - if (e.stderr && e.stderr.indexOf('previously published version') === -1) { + .catch(e => { + if ( + e.stderr && + e.stderr.indexOf('previously published version') === -1 + ) { failedPackages.push({ cmd: e.cmd, stderr: e.stderr @@ -36,13 +36,10 @@ PACKAGES.forEach(packageName => { } done(); }); - }); - }); -QUEUE.start((err) => { - +QUEUE.start(err => { if (err) { console.log('Error publishing ionic-native. ', err); } else if (failedPackages.length > 0) { @@ -51,8 +48,4 @@ QUEUE.start((err) => { } else { console.log('Done publishing ionic-native!'); } - - - }); - diff --git a/scripts/ci-tests.js b/scripts/ci-tests.js index d4ff8eea9..076cb78c4 100644 --- a/scripts/ci-tests.js +++ b/scripts/ci-tests.js @@ -9,37 +9,41 @@ exec(`git branch | grep \\* | cut -d ' ' -f2`) const branch = output.stdout.trim(); if (branch !== 'master') { - console.log('Merging master branch in ...'); // not on master branch // let's test the changes that were made return exec(`git merge origin master`); } }) - .then((output) => { + .then(output => { if (output && output.stderr) { return Promise.reject(output.stderr); } console.log('Checking for differences ...'); - return exec(`git diff --name-status origin master`) + return exec(`git diff --name-status origin master`); }) - .then((output) => { + .then(output => { if (output && output.stderr) { return Promise.reject(output.stderr); } diff = output.stdout; diff = diff.replace(/A\s+/g, ''); - diff = diff.match(/src\/@ionic-native\/plugins\/([a-zA-Z0-9\-]+)\/index\.ts/g); + diff = diff.match( + /src\/@ionic-native\/plugins\/([a-zA-Z0-9\-]+)\/index\.ts/g + ); if (!diff) process.exit(); - console.log(`${ diff.length } plugins were modified. We will now build them to verify they still work.`); + console.log( + `${ + diff.length + } plugins were modified. We will now build them to verify they still work.` + ); return exec('npm run build:core --silent'); }) - .then((output) => { - + .then(output => { if (output && output.stderr) { return Promise.reject(output.stderr); } @@ -47,11 +51,13 @@ exec(`git branch | grep \\* | cut -d ' ' -f2`) console.log('Built core library successfully ...'); console.log('Building plugins ...'); - diff = diff.map(text => text.replace('src/@ionic-native/plugins/', '').replace('/index.ts', '')); + diff = diff.map(text => + text.replace('src/@ionic-native/plugins/', '').replace('/index.ts', '') + ); return exec(`npm run build:modules ${diff.join(' ')} --silent`); }) - .then((output) => { + .then(output => { if (output && output.stderr) { console.log(output.stderr); process.exit(1); diff --git a/src/@ionic-native/core/decorators.spec.ts b/src/@ionic-native/core/decorators.spec.ts index b8a8e97a2..9c39b155e 100644 --- a/src/@ionic-native/core/decorators.spec.ts +++ b/src/@ionic-native/core/decorators.spec.ts @@ -2,14 +2,7 @@ import 'core-js'; import { Observable } from 'rxjs/Observable'; -import { - Cordova, - CordovaCheck, - CordovaInstance, - CordovaProperty, - InstanceProperty, - Plugin -} from './decorators'; +import { Cordova, CordovaCheck, CordovaInstance, CordovaProperty, InstanceProperty, Plugin } from './decorators'; import { IonicNativePlugin } from './ionic-native-plugin'; import { ERR_CORDOVA_NOT_AVAILABLE, ERR_PLUGIN_NOT_INSTALLED } from './plugin'; diff --git a/src/@ionic-native/core/decorators.ts b/src/@ionic-native/core/decorators.ts index 444783bd7..3ac89b8b7 100644 --- a/src/@ionic-native/core/decorators.ts +++ b/src/@ionic-native/core/decorators.ts @@ -1,14 +1,7 @@ +import { Observable } from 'rxjs/Observable'; import { _throw } from 'rxjs/observable/throw'; -import { Observable } from 'rxjs/Observable'; - -import { - checkAvailability, - instanceAvailability, - overrideFunction, - wrap, - wrapInstance -} from './plugin'; +import { checkAvailability, instanceAvailability, overrideFunction, wrap, wrapInstance } from './plugin'; import { getPlugin, getPromise } from './util'; export interface PluginConfig {