2021-09-17 00:26:18 -04:00
|
|
|
import loconfig from '../loconfig.json';
|
2022-02-08 14:40:00 -05:00
|
|
|
import concatFiles, { developmentConcatFilesArgs } from './tasks/concats.js';
|
2021-09-21 17:33:32 -04:00
|
|
|
import compileScripts, { developmentScriptsArgs } from './tasks/scripts.js';
|
|
|
|
|
import compileStyles, { developmentStylesArgs } from './tasks/styles.js' ;
|
|
|
|
|
import compileSVGs, { developmentSVGsArgs } from './tasks/svgs.js';
|
2022-03-22 16:08:29 -04:00
|
|
|
import resolve from './utils/template.js';
|
2021-09-16 13:55:29 -04:00
|
|
|
import server from 'browser-sync';
|
2021-09-20 17:29:41 -04:00
|
|
|
import { join } from 'node:path';
|
2020-11-27 16:01:54 -05:00
|
|
|
|
2021-09-17 00:26:18 -04:00
|
|
|
const { paths, tasks } = loconfig;
|
|
|
|
|
|
2021-12-03 11:55:35 -05:00
|
|
|
// Convert view(s) to an array
|
|
|
|
|
switch (typeof paths.views) {
|
|
|
|
|
case 'string':
|
|
|
|
|
paths.views = [ paths.views ];
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'object':
|
|
|
|
|
if (paths.views == null) {
|
|
|
|
|
paths.views = [];
|
|
|
|
|
} else if (!Array.isArray(paths.views)) {
|
|
|
|
|
paths.views = Object.values(paths.views);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-16 14:01:21 -04:00
|
|
|
const serverConfig = {
|
2020-11-27 16:01:54 -05:00
|
|
|
open: false,
|
|
|
|
|
notify: false
|
2021-06-28 21:33:10 -04:00
|
|
|
};
|
|
|
|
|
|
2021-12-03 11:52:27 -05:00
|
|
|
// Resolve the URI for the Browsersync server
|
2021-09-16 13:54:49 -04:00
|
|
|
if (typeof paths.url === 'string' && paths.url.length > 0) {
|
2021-06-28 21:33:10 -04:00
|
|
|
// Use proxy
|
2021-09-16 13:55:29 -04:00
|
|
|
serverConfig.proxy = paths.url;
|
2021-06-28 21:33:10 -04:00
|
|
|
} else {
|
|
|
|
|
// Use base directory
|
2021-09-16 13:55:29 -04:00
|
|
|
serverConfig.server = {
|
|
|
|
|
baseDir: paths.dest
|
|
|
|
|
};
|
2021-06-28 21:33:10 -04:00
|
|
|
}
|
|
|
|
|
|
2021-09-16 14:01:21 -04:00
|
|
|
// Start the Browsersync server
|
2021-09-16 13:55:29 -04:00
|
|
|
server.init(serverConfig);
|
2020-11-27 16:01:54 -05:00
|
|
|
|
2021-09-17 00:26:18 -04:00
|
|
|
// Build scripts, compile styles, concat files,
|
|
|
|
|
// and generate spritesheets on first hit
|
2022-02-08 14:40:00 -05:00
|
|
|
concatFiles(...developmentConcatFilesArgs);
|
2021-09-21 17:33:32 -04:00
|
|
|
compileScripts(...developmentScriptsArgs);
|
|
|
|
|
compileStyles(...developmentStylesArgs);
|
|
|
|
|
compileSVGs(...developmentSVGsArgs);
|
2020-11-27 16:15:36 -05:00
|
|
|
|
2021-12-03 11:52:27 -05:00
|
|
|
// Reload on any changes to views or processed files
|
2021-09-16 13:55:29 -04:00
|
|
|
server.watch(
|
2020-11-27 16:01:54 -05:00
|
|
|
[
|
2021-12-03 11:55:35 -05:00
|
|
|
...paths.views,
|
2021-09-20 17:29:41 -04:00
|
|
|
join(paths.scripts.dest, '*.js'),
|
|
|
|
|
join(paths.styles.dest, '*.css'),
|
|
|
|
|
join(paths.svgs.dest, '*.svg'),
|
2020-11-27 16:01:54 -05:00
|
|
|
]
|
2021-09-16 13:55:29 -04:00
|
|
|
).on('change', server.reload);
|
2020-11-27 16:01:54 -05:00
|
|
|
|
2021-12-03 11:52:27 -05:00
|
|
|
// Watch source scripts
|
2021-09-16 13:55:29 -04:00
|
|
|
server.watch(
|
2020-11-27 16:01:54 -05:00
|
|
|
[
|
2021-09-20 17:29:41 -04:00
|
|
|
join(paths.scripts.src, '**/*.js'),
|
2020-11-27 16:01:54 -05:00
|
|
|
]
|
|
|
|
|
).on('change', () => {
|
2021-09-21 17:33:32 -04:00
|
|
|
compileScripts(...developmentScriptsArgs);
|
2020-11-27 16:01:54 -05:00
|
|
|
});
|
|
|
|
|
|
2021-12-03 11:52:27 -05:00
|
|
|
// Watch source concats
|
2021-09-16 13:55:29 -04:00
|
|
|
server.watch(
|
2022-03-22 16:08:29 -04:00
|
|
|
resolve(
|
|
|
|
|
tasks.concats.reduce(
|
|
|
|
|
(patterns, { includes }) => patterns.concat(includes),
|
|
|
|
|
[]
|
|
|
|
|
)
|
|
|
|
|
)
|
2020-11-27 16:01:54 -05:00
|
|
|
).on('change', () => {
|
2022-02-08 14:40:00 -05:00
|
|
|
concatFiles(...developmentConcatFilesArgs);
|
2020-11-27 16:01:54 -05:00
|
|
|
});
|
|
|
|
|
|
2021-12-03 11:52:27 -05:00
|
|
|
// Watch source styles
|
2021-09-16 13:55:29 -04:00
|
|
|
server.watch(
|
2020-11-27 16:01:54 -05:00
|
|
|
[
|
2021-09-20 17:29:41 -04:00
|
|
|
join(paths.styles.src, '**/*.scss'),
|
2020-11-27 16:01:54 -05:00
|
|
|
]
|
|
|
|
|
).on('change', () => {
|
2021-09-21 17:33:32 -04:00
|
|
|
compileStyles(...developmentStylesArgs);
|
2020-11-27 16:01:54 -05:00
|
|
|
});
|
|
|
|
|
|
2021-12-03 11:52:27 -05:00
|
|
|
// Watch source SVGs
|
2021-09-16 13:55:29 -04:00
|
|
|
server.watch(
|
2020-11-27 16:01:54 -05:00
|
|
|
[
|
2021-09-20 17:29:41 -04:00
|
|
|
join(paths.svgs.src, '*.svg'),
|
2020-11-27 16:01:54 -05:00
|
|
|
]
|
|
|
|
|
).on('change', () => {
|
2021-09-21 17:33:32 -04:00
|
|
|
compileSVGs(...developmentSVGsArgs);
|
2020-11-27 16:01:54 -05:00
|
|
|
});
|