Skip to content

Commit e921b1d

Browse files
Merge pull request #13 from Flutterwave/vue2-ts
Extend package to support Typescript on Vue 2.
2 parents 1fb84c3 + 0291e36 commit e921b1d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+14073
-3803
lines changed

.gitignore

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
.DS_Store
2-
node_modules
2+
node_modules/
3+
/dist/
34

45
# local env files
56
.env.local
67
.env.*.local
7-
todo.md
88

99
# Log files
1010
npm-debug.log*
1111
yarn-debug.log*
1212
yarn-error.log*
13-
pnpm-debug.log*
1413

1514
# Editor directories and files
1615
.idea
@@ -19,4 +18,4 @@ pnpm-debug.log*
1918
*.ntvs*
2019
*.njsproj
2120
*.sln
22-
*.sw?
21+
*.sw*

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<img title="Flutterwave" height="200" src="https://flutterwave.com/images/logo/full.svg" width="50%"/>
33
</p>
44

5-
# Flutterwave Vue.JS v3 Library
5+
# Flutterwave Vue.JS (Vue2) Library
66
![Publish Vue.js Package](https://github.com/Flutterwave/Flutterwave-Vue-v3/workflows/Publish%20Vue.js%20Package/badge.svg)
77
![npm](https://img.shields.io/npm/v/flutterwave-vue-v3)
88
![npm](https://img.shields.io/npm/dt/flutterwave-vue-v3)
@@ -21,7 +21,7 @@
2121
<a id="about"></a>
2222
## About
2323

24-
Flutterwave official Vue library to accept payment via Card, USSD, QrCode etc.
24+
Flutterwave official Vue(v2) library to accept payment via Card, USSD, QrCode etc with support for Typescript.
2525

2626
<a id="getting-started"></a>
2727

@@ -34,7 +34,7 @@ See [references](#references) for links to dashboard and API documentation.
3434
### Prerequisites
3535

3636
```
37-
Vue version >= 2
37+
Vue version = 2.x.x
3838
Flutterwave version 3 API Public keys
3939
```
4040

@@ -54,6 +54,8 @@ $ yarn add flutterwave-vue-v3
5454

5555
## Usage
5656

57+
* For Typescript project sample, please see the project in the example directory of the project repository.
58+
5759
* Import the Flutterwave Library in the 'main.js' file.
5860

5961
* Add the Flutterwave plugin to your app passing in your Flutterwave Public Key (optional)

babel.config.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
const devPresets = ['@vue/babel-preset-app'];
2-
const buildPresets = ['@babel/preset-env'];
2+
const buildPresets = [
3+
[
4+
'@babel/preset-env',
5+
// Config for @babel/preset-env
6+
{
7+
// Example: Always transpile optional chaining/nullish coalescing
8+
// include: [
9+
// /(optional-chaining|nullish-coalescing)/
10+
// ],
11+
},
12+
],
13+
'@babel/preset-typescript',
14+
];
315
module.exports = {
416
presets: (process.env.NODE_ENV === 'development' ? devPresets : buildPresets),
517
};

build/rollup.config.js

Lines changed: 42 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@ import path from 'path';
44
import vue from 'rollup-plugin-vue';
55
import alias from '@rollup/plugin-alias';
66
import commonjs from '@rollup/plugin-commonjs';
7+
import resolve from '@rollup/plugin-node-resolve';
78
import replace from '@rollup/plugin-replace';
8-
import babel from 'rollup-plugin-babel';
9+
import babel from '@rollup/plugin-babel';
910
import { terser } from 'rollup-plugin-terser';
11+
import ttypescript from 'ttypescript';
12+
import typescript from 'rollup-plugin-typescript2';
1013
import minimist from 'minimist';
1114

1215
// Get browserslist config and remove ie from es build targets
@@ -15,34 +18,46 @@ const esbrowserslist = fs.readFileSync('./.browserslistrc')
1518
.split('\n')
1619
.filter((entry) => entry && entry.substring(0, 2) !== 'ie');
1720

21+
// Extract babel preset-env config, to combine with esbrowserslist
22+
const babelPresetEnvConfig = require('../babel.config')
23+
.presets.filter((entry) => entry[0] === '@babel/preset-env')[0][1];
24+
1825
const argv = minimist(process.argv.slice(2));
1926

2027
const projectRoot = path.resolve(__dirname, '..');
2128

2229
const baseConfig = {
23-
input: 'src/entry.js',
30+
input: 'src/entry.ts',
2431
plugins: {
2532
preVue: [
2633
alias({
27-
resolve: ['.js', '.jsx', '.ts', '.tsx', '.vue'],
28-
entries: {
29-
'@': path.resolve(projectRoot, 'src'),
30-
},
34+
entries: [
35+
{
36+
find: '@',
37+
replacement: `${path.resolve(projectRoot, 'src')}`,
38+
},
39+
],
3140
}),
3241
],
3342
replace: {
3443
'process.env.NODE_ENV': JSON.stringify('production'),
35-
'process.env.ES_BUILD': JSON.stringify('false'),
3644
},
3745
vue: {
3846
css: true,
3947
template: {
4048
isProduction: true,
4149
},
4250
},
51+
postVue: [
52+
resolve({
53+
extensions: ['.js', '.jsx', '.ts', '.tsx', '.vue'],
54+
}),
55+
commonjs(),
56+
],
4357
babel: {
4458
exclude: 'node_modules/**',
4559
extensions: ['.js', '.jsx', '.ts', '.tsx', '.vue'],
60+
babelHelpers: 'bundled',
4661
},
4762
},
4863
};
@@ -68,31 +83,37 @@ const buildFormats = [];
6883
if (!argv.format || argv.format === 'es') {
6984
const esConfig = {
7085
...baseConfig,
86+
input: 'src/entry.esm.ts',
7187
external,
7288
output: {
73-
file: 'dist/flutterwave-vue-v3.esm.js',
89+
file: 'dist/flw-ts.esm.js',
7490
format: 'esm',
7591
exports: 'named',
7692
},
7793
plugins: [
78-
replace({
79-
...baseConfig.plugins.replace,
80-
'process.env.ES_BUILD': JSON.stringify('true'),
81-
}),
94+
replace(baseConfig.plugins.replace),
8295
...baseConfig.plugins.preVue,
8396
vue(baseConfig.plugins.vue),
97+
...baseConfig.plugins.postVue,
98+
// Only use typescript for declarations - babel will
99+
// do actual js transformations
100+
typescript({
101+
typescript: ttypescript,
102+
useTsconfigDeclarationDir: true,
103+
emitDeclarationOnly: true,
104+
}),
84105
babel({
85106
...baseConfig.plugins.babel,
86107
presets: [
87108
[
88109
'@babel/preset-env',
89110
{
111+
...babelPresetEnvConfig,
90112
targets: esbrowserslist,
91113
},
92114
],
93115
],
94116
}),
95-
commonjs(),
96117
],
97118
};
98119
buildFormats.push(esConfig);
@@ -104,10 +125,10 @@ if (!argv.format || argv.format === 'cjs') {
104125
external,
105126
output: {
106127
compact: true,
107-
file: 'dist/flutterwave-vue-v3.ssr.js',
128+
file: 'dist/flw-ts.ssr.js',
108129
format: 'cjs',
109-
name: 'FlutterwaveVueV3',
110-
exports: 'named',
130+
name: 'FlwTs',
131+
exports: 'auto',
111132
globals,
112133
},
113134
plugins: [
@@ -120,8 +141,8 @@ if (!argv.format || argv.format === 'cjs') {
120141
optimizeSSR: true,
121142
},
122143
}),
144+
...baseConfig.plugins.postVue,
123145
babel(baseConfig.plugins.babel),
124-
commonjs(),
125146
],
126147
};
127148
buildFormats.push(umdConfig);
@@ -133,18 +154,18 @@ if (!argv.format || argv.format === 'iife') {
133154
external,
134155
output: {
135156
compact: true,
136-
file: 'dist/flutterwave-vue-v3.min.js',
157+
file: 'dist/flw-ts.min.js',
137158
format: 'iife',
138-
name: 'FlutterwaveVueV3',
139-
exports: 'named',
159+
name: 'FlwTs',
160+
exports: 'auto',
140161
globals,
141162
},
142163
plugins: [
143164
replace(baseConfig.plugins.replace),
144165
...baseConfig.plugins.preVue,
145166
vue(baseConfig.plugins.vue),
167+
...baseConfig.plugins.postVue,
146168
babel(baseConfig.plugins.babel),
147-
commonjs(),
148169
terser({
149170
output: {
150171
ecma: 5,

dev/serve.js

Lines changed: 0 additions & 13 deletions
This file was deleted.

dev/serve.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import Vue, { VNode } from "vue";
2+
import Dev from "./serve.vue";
3+
// To register individual components where they are used (serve.vue) instead of using the
4+
// library as a whole, comment/remove this import and it's corresponding "Vue.use" call
5+
import Flutterwave from "@/entry.esm";
6+
Vue.use(Flutterwave, {
7+
publicKey: "FLWPUBK_TEST-4550165677fdcf951548729e3ff6b950-X",
8+
});
9+
10+
Vue.config.productionTip = false;
11+
12+
new Vue({
13+
render: (h): VNode => h(Dev),
14+
}).$mount("#app");

dev/serve.vue

Lines changed: 31 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,67 @@
11
<script>
2-
import Vue from 'vue';
3-
import { FlutterwavePayButton } from '@/entry';
2+
import Vue from "vue";
3+
import { FlutterwavePayButton } from "@/entry";
44
55
export default Vue.extend({
6-
name: 'ServeDev',
6+
name: "ServeDev",
77
components: {
88
FlutterwavePayButton,
99
},
10-
data(){
10+
data() {
1111
return {
1212
paymentData: {
1313
tx_ref: this.generateReference(),
1414
amount: 10,
15-
redirect_url: '',
15+
redirect_url: "",
1616
meta: {
17-
'counsumer_id': '7898',
18-
'consumer_mac': 'kjs9s8ss7dd'
17+
counsumer_id: "7898",
18+
consumer_mac: "kjs9s8ss7dd",
1919
},
2020
customer: {
21-
name: 'Demo Customer Name',
22-
email: 'customer@mail.com',
23-
phone_number: '0818450***44'
24-
} ,
21+
name: "Demo Customer Name",
22+
email: "customer@mail.com",
23+
phone_number: "0818450***44",
24+
},
2525
customizations: {
26-
title: 'Customization Title',
27-
description: 'Customization Description',
28-
logo: 'https://flutterwave.com/images/logo-colored.svg'
26+
title: "Customization Title",
27+
description: "Customization Description",
28+
logo: "https://flutterwave.com/images/logo-colored.svg",
2929
},
3030
callback: this.makePaymentCallback,
31-
onclose: this.closeModalCallback
32-
}
33-
}
34-
} ,
31+
onclose: this.closeModalCallback,
32+
},
33+
};
34+
},
3535
methods: {
3636
makePaymentCallback(response) {
37-
console.log("Pay", response)
38-
this.closePaymentModal(5)
37+
console.log("Pay", response);
38+
this.closePaymentModal(5);
3939
},
4040
asyncPay() {
41-
this.asyncPayWithFlutterwave(this.paymentData).then(
42-
(response) => {
43-
console.log(response)
44-
this.closePaymentModal(5)
45-
}
46-
)
41+
this.asyncPayWithFlutterwave(this.paymentData).then((response) => {
42+
console.log(response);
43+
this.closePaymentModal(5);
44+
});
4745
},
4846
closeModalCallback() {
49-
console.log('payment is closed');
47+
console.log("payment is closed");
5048
},
5149
generateReference() {
52-
let date = new Date()
50+
let date = new Date();
5351
return date.getTime().toString();
54-
}
55-
}
52+
},
53+
},
5654
});
5755
</script>
5856

5957

6058
<template>
6159
<div>
62-
<flutterwave-pay-button v-bind="paymentData"> Pay With Flw Pay button</flutterwave-pay-button>
63-
60+
<flutterwave-pay-button v-bind="paymentData">
61+
Pay With Flw Pay button</flutterwave-pay-button
62+
>
6463

6564
<button @click="asyncPay(paymentData)">Pay With Promise</button>
66-
67-
6865
</div>
6966
</template>
7067

0 commit comments

Comments
 (0)