chore(build): refactor

This commit is contained in:
Daniel 2018-08-16 22:23:03 +02:00
parent ff784a4377
commit ea6746d134
6 changed files with 51 additions and 78 deletions

View File

@ -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');
}
});

View File

@ -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);
};

View File

@ -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!');
}
});

View File

@ -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);

View File

@ -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';

View File

@ -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 {