-
Notifications
You must be signed in to change notification settings - Fork 3
/
gulpfile.js
155 lines (140 loc) · 3.45 KB
/
gulpfile.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
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
import gulp from 'gulp';
import path from 'path';
import yargs from 'yargs';
import fs from 'fs-extra';
import webpack from 'webpack';
import WebpackDevServer from 'webpack-dev-server';
import * as localeLoader from '@ringcentral-integration/locale-loader';
// import { supportedBrands } from './src/brands';
import getWebpackConfig from './src/lib/getWebpackConfig';
require('dotenv').config();
const rcSDKConfig = {
clientId: process.env.RINGCENTRAL_CLIENT_ID,
clientSecret: process.env.RINGCENTRAL_CLIENT_SECRET,
server: process.env.RINGCENTRAL_SERVER,
};
const evAgentConfig = {
localTesting: false,
isSecureSocket: true,
allowMultiSocket: true,
authHost: process.env.ENGAGE_VOICE_AUTH_SERVER,
clientAppType: "RCX_Embeddable",
clientAppVersion: "0.2.0",
componentName: "EAG",
isI18nEnabled: false,
};
const authConfig = {
redirectUri: process.env.AUTH_REDIRECT_URI,
};
const localeSettings = {
supportedLocales: [
'en-US',
'en-GB',
'en-AU',
'fr-FR',
'fr-CA',
'de-DE',
'it-IT',
'es-ES',
'es-419',
'ja-JP',
'pt-BR',
'zh-CN',
'zh-TW',
'zh-HK',
],
sourceLocale: 'en-US',
};
const environments = ['dev', 'prod'];
const { argv } = yargs
.alias({
hash: 'build-hash',
env: 'build-type',
exportType: 'export-type',
hostingUrl: 'hosting-url',
})
.default('exportType', 'diff')
.array('brand')
.default('brand', ['rc'])
.default('env', 'dev')
.default('port', 8080)
.coerce('env', (e) => (environments.indexOf(e) > -1 ? e : 'dev'));
const { env, buildHash, port, brand, exportType, hostingUrl } = argv;
const buildFolder = path.resolve(__dirname, './build');
function clean() {
return Promise.all(
brand.reduce(
(all, brandName) => all.concat([fs.remove(path.resolve(buildFolder, brandName))]),
[],
),
);
}
function compile({ brandName = 'rc', buildPath }) {
const config = getWebpackConfig({
env,
brand: brandName,
buildPath,
buildHash: env === 'prod' ? null : buildHash,
hostingUrl,
sdkConfig: rcSDKConfig,
agentConfig: evAgentConfig,
authConfig,
});
return new Promise((resolve, reject) => {
webpack(config, (err, stats) => {
if (err) {
reject(err);
return;
}
if (stats.hasErrors()) {
return reject(new Error(stats.compilation.errors.join('\n')))
}
resolve();
});
});
}
export async function build() {
await clean();
await Promise.all(
brand.reduce((all, brandName) => all.concat([compile({
brandName,
buildPath: path.resolve(buildFolder, brandName)
})]), []),
);
}
export async function devServer() {
const config = getWebpackConfig({
env,
brand: brand[0],
buildPath: path.resolve(buildFolder, brand[0]),
buildHash: null,
hostingUrl: 'http://localhost:8080',
sdkConfig: rcSDKConfig,
agentConfig: evAgentConfig,
authConfig,
});
const compiler = webpack(config);
const server = new WebpackDevServer({
static: {
directory: path.resolve(__dirname, './'),
},
devMiddleware: {
publicPath: '/',
},
port,
hot: false,
webSocketServer: false,
}, compiler);
await server.start();
console.log(`Brand: ${brand}: server listening to ${port}...`);
}
/* Locale */
export async function exportLocale() {
return localeLoader.exportLocale({
...localeSettings,
exportType,
});
}
export async function importLocale() {
return localeLoader.importLocale(localeSettings);
}