-
Notifications
You must be signed in to change notification settings - Fork 28
/
gulpfile.ts
executable file
·157 lines (147 loc) · 3.87 KB
/
gulpfile.ts
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import path from 'path';
import { task, series, src, dest, parallel } from 'gulp';
import del from 'del';
import gulpTs from 'gulp-typescript';
import { outputFileSync } from 'fs-extra';
import through2 from 'through2';
import GitHub from '@octokit/rest';
import spawn from 'cross-spawn';
import { transformComptLess } from 'alleria/lib/gulp';
import transformSvelte from './scripts/transformSvelte';
import buildWebpack, { buildUmdConfig } from './scripts/buildWebpack';
import createConfig from './webpack.config';
import route from './site/route';
const cwd = process.cwd();
const libDir = path.join(cwd, './lib');
const esDir = path.join(cwd, './es');
const distDir = path.join(cwd, './dist');
task('compile-res', () =>
src([
'components/**/*.@(png|svg)',
'components/**/*.less',
'!components/*/demo/*',
])
.pipe(transformComptLess({ plugins: require('./postcss.config').plugins }))
.pipe(dest(esDir))
.pipe(dest(libDir)),
);
task('compile-ts', () =>
src(['components/**/*.ts', '!components/*/__tests__/*'])
.pipe(
gulpTs.createProject('tsconfig.json', {
module: 'es6',
declaration: true,
})(),
)
.pipe(
through2.obj(async function(file, encoding, next) {
if (file.isBuffer()) {
file.contents = Buffer.from(
file.contents
.toString()
.replace(/\.svelte(['|"])/g, (ext, char) => char),
);
}
next(null, file);
}),
)
.pipe(dest(esDir))
.pipe(
gulpTs.createProject('tsconfig.json', {
module: 'commonjs',
allowJs: true,
})(),
)
.pipe(dest(libDir)),
);
task('compile-ts-helpers', () =>
src(['scripts/helpers/svelte-*.ts'])
.pipe(
gulpTs.createProject('tsconfig.json', {
module: 'commonjs',
declaration: false,
})(),
)
.pipe(dest('./helpers')),
);
task(
'compile-svelte',
parallel([
() =>
src(['components/**/*.svelte'])
.pipe(transformSvelte('esm'))
.pipe(dest(esDir)),
() =>
src(['components/**/*.svelte'])
.pipe(transformSvelte('esm'))
.pipe(
gulpTs.createProject('tsconfig.json', {
module: 'commonjs',
declaration: false,
allowJs: true,
})(),
)
.pipe(dest(libDir)),
]),
);
task('compile-build', () => buildWebpack(buildUmdConfig));
task(function buildSitefile() {
return buildWebpack(createConfig({}, { ssr: true }));
});
task(function generate(cb) {
route.forEach(url => {
const { html, head } = require('./_ssr_site/app.js').default.render({
url,
});
outputFileSync(
path.join(cwd, `_site/${url}/index.html`),
`
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="An enterprise-class UI design language and Sevlte implementation with a set of high-quality Sevlte components, one of best Sevlte UI library for enterprises">
${head}
<link href="/app.css" rel="stylesheet"></head>
<body>
<div id="app">${html}</div>
<script type="text/javascript" src="/app.js"></script>
</body>
</html>
`,
);
});
cb();
});
task(
'site',
series(() => del(['./_site', './_ssr_site']), 'buildSitefile', 'generate'),
);
task(
'compile-release',
series(
() => del([libDir, esDir, distDir, './helpers']),
parallel([
'compile-res',
'compile-ts',
'compile-ts-helpers',
'compile-svelte',
'compile-build',
]),
),
);
task(
'pub-with-ci',
series([
'compile-release',
cb => {
spawn.sync('npm', ['publish'], {
stdio: 'inherit',
});
cb();
},
]),
);