This repository has been archived by the owner on Mar 11, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
/
framework7-vue-build.js
63 lines (52 loc) · 1.9 KB
/
framework7-vue-build.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
var gulp = require('gulp'),
path = require('path'),
rollup = require('rollup-stream'),
buble = require('rollup-plugin-buble'),
vue = require('rollup-plugin-vue2'),
source = require('vinyl-source-stream'),
buffer = require('vinyl-buffer'),
sourcemaps = require('gulp-sourcemaps'),
rename = require('gulp-rename'),
fs = require('fs'),
to = require('to-case');
const ensureDirectoryExistence = (filePath) => {
var dirname = path.dirname(filePath);
if (fs.existsSync(dirname)) {
return true;
}
ensureDirectoryExistence(dirname);
fs.mkdirSync(dirname);
};
export default function(cb) {
const paths = [
'./node_modules/framework7-vue/src/components/',
'./node_modules/framework7-vue/src/mixins/'
];
const components = [];
const imports = [];
paths.forEach(path => {
const files = fs.readdirSync(path);
files.filter(file => file.indexOf('.vue') != -1).forEach(file => {
const componentName = to.pascal(`vue-${file.replace('.vue', '')}${(path.indexOf('mixins') !== -1) ? '-mixin' : ''}`);
imports.push(`import ${componentName} from '${'.' + path + file}'`);
components.push(componentName);
});
});
const index = `${imports.join('\n')}\n\nexport {\n\t${components.join(',\n\t')}\n}`;
ensureDirectoryExistence('./framework7-vue/index.js');
fs.writeFileSync('./framework7-vue/index.js', index);
rollup({
entry: './framework7-vue/index.js',
plugins: [vue(), buble()],
format: 'es',
moduleName: 'Framework7Vue',
useStrict: false,
sourceMap: true
})
.pipe(source('framework7-vue.js', './framework7-vue'))
.pipe(buffer())
.pipe(sourcemaps.init({loadMaps: true}))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('./framework7-vue/'))
.on('end', cb);
};