forked from fullcalendar/fullcalendar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.locales.js
104 lines (91 loc) · 2.77 KB
/
rollup.locales.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
const path = require('path')
const globby = require('globby')
const sucrase = require('@rollup/plugin-sucrase')
const { externalizeRelative } = require('./scripts/lib/new-rollup')
/*
needs locales-all to run first
compiles from *SRC* files.
we use sucrase to transpile the ts files.
normally we wouldn't use sucrase because it produces JS that's too advanced for the browsers we want to support,
but the locale files are simple so it'll be fine.
*/
let srcLocaleFiles = globby.sync('packages/core/src/locales/*.ts')
let bundleDirs = globby.sync('packages?(-premium)/bundle', { onlyDirectories: true })
let sucraseInstance = sucrase({
transforms: ['typescript']
})
module.exports = [
// locales-all.js, for CORE
{
input: 'packages/core/src/locales-all.ts',
output: {
format: 'cjs',
exports: 'named',
file: 'packages/core/locales-all.js'
},
plugins: [
externalizeRelative(), // resulting bundle will import the individual locales
sucraseInstance
]
},
// locales-all.js, for BUNDLES
{
input: 'packages/core/src/locales-all.ts',
output: bundleDirs.map((bundleDir) => ({
format: 'iife',
name: 'FullCalendar', // for bundleWrapLocalesAll
file: path.join(bundleDir, 'locales-all.js')
})).concat({
format: 'iife',
name: 'FullCalendar', // for bundleWrapLocalesAll
file: path.join('packages/core/locales-all.global.js') // FOR CORE
}),
plugins: [
sucraseInstance,
bundleWrapLocalesAll()
]
},
// locales/*.js, for CORE
...srcLocaleFiles.map((srcLocaleFile) => ({
input: srcLocaleFile,
output: {
format: 'cjs',
exports: 'named',
file: path.join('packages/core/locales', path.basename(srcLocaleFile, '.ts') + '.js')
},
plugins: [
sucraseInstance
]
})),
// locales/*.js, for BUNDLES
...srcLocaleFiles.map((srcLocaleFile) => ({
input: srcLocaleFile,
output: bundleDirs.map((bundleDir) => ({
format: 'iife',
name: 'FullCalendar', // for bundleWrapLocalesAll
file: path.join(bundleDir, 'locales', path.basename(srcLocaleFile, '.ts') + '.js')
})).concat({
format: 'iife',
name: 'FullCalendar', // for bundleWrapLocalesAll
file: path.join('packages/core/locales', path.basename(srcLocaleFile, '.ts') + '.global.js') // FOR CORE
}),
plugins: [
sucraseInstance,
bundleWrapLocalesEach()
]
}))
]
function bundleWrapLocalesAll() {
return {
renderChunk(code) {
return code.replace(/^var FullCalendar = \(/, '[].push.apply(FullCalendar.globalLocales, ') // needs to be by-reference. can't reassign
}
}
}
function bundleWrapLocalesEach() {
return {
renderChunk(code) {
return code.replace(/^var FullCalendar = /, 'FullCalendar.globalLocales.push')
}
}
}