-
Notifications
You must be signed in to change notification settings - Fork 1
/
rollup.config.js
143 lines (115 loc) · 3.04 KB
/
rollup.config.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
/**
* rollup import files from js
*/
import styles from 'rollup-plugin-styles';
import url from '@rollup/plugin-url';
import files from 'rollup-plugin-import-file';
import html from 'rollup-plugin-html';
import yaml from '@rollup/plugin-yaml';
/**
*
*/
import color from 'ansi-colors';
import { babel } from '@rollup/plugin-babel';
import scenesToJson from 'scenes-to-json';
import chokidar from 'chokidar';
import fse from 'fs-extra';
import YAML from 'yaml';
import watch from "rollup-plugin-watch";
const config = YAML.parse(fse.readFileSync('./config.yaml', 'utf8'))
import packageConfig from './package.json'
const printVersion = () => {
const str = `${color.gray('v'+packageConfig.version)} ${color.magenta(config.src)}`
return str
}
const production = false;
export default {
input: `${config.src}/main.js`,
output: {
file: `public/js/app.js`,
name: 'app',
format: 'iife',
sourcemap: false
},
plugins: [
yaml(),
html(),
styles(),
url({
fileName: '[hash][extname]',
destDir: `./public/assets`
}),
files({
output: `public/assets`,
extensions: /\.(waw|ogg|mp3)$/,
hash: false,
}),
babel({
babelHelpers: 'bundled',
presets: ['@babel/preset-env'],
plugins: [
["babel-plugin-root-import", { "rootPathSuffix": `${config.src}`}]
]
}),
// watch
watch({ dir: `${config.src}/plugins` }),
],
watch: [
`${config.src}/main.js`,
`${config.src}/plugins.js`,
]
};
/**
* socket
*/
const express = require('express');
const app = express();
const http = require('http').Server(app);
const io = require('socket.io')(http);
const port = config.port||9000;
/**
* Собираем yaml - сцены
*/
const buildScenes = () => {
const src = `${config.src}/scenes`;
const dist = `./public/scenes`;
scenesToJson(src, dist, (err, sceneName, labelName)=>{
console.clear()
if(err){
console.log( color.red(err.reason) );
console.log( color.cyan(sceneName+'/'+ labelName) );
console.log( color.magenta(`line ${ err.mark.line} column ${err.mark.column}`) );
console.log( color.gray( err.mark.snippet) );
io.emit('yaml-error', err, sceneName, labelName);
}
else{
console.log(printVersion(), color.green( '[ Scenes has build ]' ) )
io.emit('yaml-error', null);
}
})
}
chokidar.watch(`${config.src}/scenes`).on('change', (event, path) => {
buildScenes()
})
buildScenes()
/**
* copyStatic
*/
const copyStatic = () => {
fse.copy(`${config.src}/static`, 'public')
}
copyStatic()
chokidar.watch(`${config.src}/static`).on('change', (event, path) => {
copyStatic()
io.emit('yaml-error', null)
})
/**
* http-server
*/
app.use(express.static('public'));
app.get('/', (req, res) => {
res.sendFile(__dirname + 'public/index.html');
})
http.listen(port, () => {
console.log(`http://localhost:${port}/`);
});